-
-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an apply method to apply functions to elements #3474
Conversation
This is now working as I would like it to, the main problem now is that I've had to modify the default behavior slightly to get what we want since simply setting the specs to ViewableElement isn't quite the semantics we need. The difference between |
9cb5b59
to
6c72a30
Compare
I dunno if this PR is ready yet but one thing I would like to see before merging is a concrete example of how to use Alternatively (or probably more sensibly) some examples in the documentation. |
b017ab4
to
f816192
Compare
Here is a little example of from scipy import ndimage
def image(freq=0):
xs, ys = np.mgrid[-1:1:0.05, -1:1:0.05]*freq
return hv.Image(np.sin(xs)*np.cos(ys))
dmap = hv.DynamicMap(image, kdims=('freq', 'Frequency')).redim.range(freq=(1, 10))
# Define an operation which applies gaussian filtering
def filter(obj, sigma, mode):
return obj.clone(ndimage.gaussian_filter(obj.data, sigma, mode=mode))
# Define panel widgets which will control the function sigma and mode arguments
sigma = pn.widgets.FloatSlider(name='Sigma', start=1, end=10)
mode = pn.widgets.Select(name='Mode', value='mirror', options=['reflect', 'constant', 'mirror', 'nearest', 'wrap'])
# Map widget parameters to function arguments
filtered = dmap.apply(filter, sigma=sigma.param.value, mode=mode.param.value)
# Make a panel layout
hv_panel = pn.panel(filtered)
pn.Row(hv_panel[0], pn.Column(hv_panel[1], sigma, mode)) and here is a little example using param instances in operations: import colorcet as ct
class Example(param.Parameterized):
cmap = param.Selector(default=ct.bgy, objects={'bgy': ct.bgy, 'rainbow': ct.rainbow})
example = Example()
points = hv.Points(np.random.randn(10000000, 2))
pn.Row(datashade(points, cmap=example.param.cmap), example.param) |
Tests are failing because the unpickling doesn't seem to be working:
I tested it locally without issues, so don't quite know what's up with that. |
I'm very happy with that API and I reviewed the code earlier. Happy to merge when the tests pass. |
That all looks great, though I'm not sure this is really a |
Okay I'm actually much happier with this, I'll work on a few more tests but it's working again, now with the |
Does the example above still work, after replacing |
I'll push another fix shortly but yes, that should work. |
I've just pushed a few fixes and a bunch more tests, so this should be ready to merge now. |
Let's ignore the Windows failure for now, it's some regression in the latest dask 1.1.3 release which I'll have to look into independently. |
The suggestion for updating |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR implements the outcome of our API discussion to provide a more convenient API than
hv.util.Dynamic
. The main changes are twofold:.apply
now defaults to ViewableElement for its spec keyword, which means it behaves exactly like an Operation.apply
, which make it behave likehv.util.Dynamic
, i.e. it provides support for chaining dynamic operations, but also making existing objects become dynamic if there is a stream or parameter dependency declared.