holoviz-topics / EarthSim

Tools for working with and visualizing environmental simulations.
https://earthsim.holoviz.org
BSD 3-Clause "New" or "Revised" License
65 stars 21 forks source link

Adding `name` to parameters via earthsim.parameters causes silent failure #264

Closed kcpevey closed 5 years ago

kcpevey commented 5 years ago

From Issue #254 example code from @philippjfr , I modified to add mesh_opts as an example:

from earthsim import parameters
from holoviews.streams import Params

points = gv.operation.project_points(gv.Points((verts.x, verts.y), crs=ccrs.UTM(11)))

# Create a parameterized class to select between ERROR and Depth
results = parameters(display_result=param.ObjectSelector(default=internal_names[0], objects=internal_names))

# Define callback which returns TriMesh for specific time and ERROR/Depth
def time_mesh(time, display_result):
    depth_points = points.add_dimension(display_result, 0, dfs[time][display_result].values, vdim=True)
    return gv.TriMesh((tris, depth_points), label=label, crs=ccrs.GOOGLE_MERCATOR)

# Declare DynamicMap which varies by time and is linked to results class
meshes = hv.DynamicMap(time_mesh, kdims='Time', streams=[Params(results)]).redim.values(Time=sorted(dfs.keys()))

# Declare classes to control colormap and display range
cmap_opts = parameters(colormap=param.ObjectSelector(default=cc.rainbow, objects={'Rainbow': cc.rainbow,
                     'Fire': cc.fire,
                     'Gray': cc.gray,
                     'CoolWarm': cc.coolwarm}))
display_range = parameters(color_range=param.Range(default=(-0.3, 0.3), bounds=(-0.3, 0.3)))

class mesh_opts(param.Parameterized):
    mesh_type = param.ObjectSelector(default='Color Contour', objects=['Color Contour','Wireframe'])

# Define function which applies colormap and color_range
def apply_opts(obj, colormap, color_range):
    return obj.options(cmap=colormap).redim.range(**{obj.vdims[0].name: color_range})

# Apply the colormap and color range dynamically
dynamic = hv.util.Dynamic(rasterize(meshes), operation=apply_opts, streams=[Params(cmap_opts), Params(display_range)])

# Display everything as a Panel
hv_panel = pn.panel(dynamic)
right_column = pn.Column(hv_panel[1], cmap_opts(name=''), display_range, results, mesh_opts(name=''))
pn.Row(hv_panel[0], right_column)

Prior to this example, I was defining parameters and widgets similar to how I've specified the mesh_opts class. When this class gets visualized (with right_column) I will get a UUID type name unless I specify it as mesh_opts(name=''). However, with the new method in earthsim.parameters (as seen in cmap_opts above), the name is automatically generated without the UUID number.

The catch is that IF I specify cmap_opts(name='') like I've done above, it silently breaks the colormapping link to the widget. The map is displayed with the default color, but changing the widget value has no effect on the map. I get no errors or any indication that specifying name='' is not valid.

So in the above code, if you remove name='' it will work perfectly.

philippjfr commented 5 years ago

Thanks for the detailed report, I'll try to track that down asap.

kcpevey commented 5 years ago

As you can see in the image from the referenced issue, I now get the word 'Parameters' in bold above each widget. That's what I was removing with name=''. How would I remove it with the new method?

philippjfr commented 5 years ago

Once I tag a new panel release you'll be able to do: pn.panel(cmap_opts(), show_name=False).

philippjfr commented 5 years ago

The new approach should be preferred over setting name='' so I'll close.