Xarray and Panel -selecting location on Map

Trying to create a simple dashboard showing the map data and a time series underneath, dashboard controls should allow selecting a dataset and run some simple analysis and show the results. Ran into a few hiccups and was wondering if anyone had solved them:

  1. When creating a time slider with xarray.dataarray.hvplot(), I can’t incorporate the results in a panel. The panel controls don’t work.
  2. Can’t get a time sliders from the Param class. I’ve been using the widgets class but lose all the advantages of Param.
  3. Is there a way to use the tools ‘tap’ to get the coordinates and show a timeseries for these coordinates?

Thank you

Deborah

2 Likes

Thanks for the interesting question @khider! Pinging @jbednar as our resident panel / holoviews expert.

@khider, for your points 1 and 2 above, could you link to a GitHub Gist or similar minimal working example which reproduces these issue(s)?

1 Like

Sorry for the late reply; I’ve been at the beach!

  1. I believe the controls normally do work when an hvplot is embedded in a panel, and it’s also possible to separate the controls from the plot if you need to lay them out separately. I’d have to see an example of what’s not working for you to see what to suggest.
  2. You can use the widgets argument to pn.Param (see Param — Panel 0.11.3 documentation) to specify a non-default widget, if you have one that you’d prefer to use instead of the default.
  3. Yes! examples.pyviz.org/landsat shows how to do that with a Hover tool, and it’s similar with a Tap tool.

I’d be happy to help go over these with you via zoom, especially if you’d be happy to release the result as a public example…

3 Likes

Thanks, let me try to work with the info you sent. But a consult call will be more than welcome.

I can make the resulting notebook public. The only problem might be to move the data. It’s currently on our (publicly accessible) server but one would have to download the data to use it.

1 Like

Example notebook with the problems here: GitHub - khider/xarray-visualization: Notebooks illustrating xarray-based visualizations.

1 Like

Thanks for the example notebook!

I’ll have a go reproducing the problems you have encountered (all the things described are reasonable and should work) and I’ll get back to you on Monday.

2 Likes

@khider, in case it’s useful we have a “HRRR Explorer” panel app that has some similarity with the use case you describe.

The notebook that created that app is in this reproducible notebooks repo.

Also see this simple click-and-get-time-series example.

1 Like

I have downloaded the example notebook and set up the environment. Based on the filename, I believe this is the dataset I need? NASA IT Security Warning Banner

I just want to make sure before I set up an Earthdata account to download the necessary data…

Sorry I though I put the link in the notebook. The data on our server is public.

Index of /files/raw-data/ and contained in the folders GLDAS_NOAH025_M2.0 and GLDAS_NOAH025_M2.1

Thanks! I can definitely reuse some of it!

1 Like

Just to say I now have the notebook running and I’m working through the issues you’ve raised.

  • Transparency slider is disables (Get an error when uncommenting surf_plot.opts that column object don’t support opts)

This is because the use of groupby='time' means that hvplot no longer returns a HoloViews object and instead returns a panel column with widgets for controlling the groupby, making it tricky to apply .opts to the underlying HoloViews object.

Anyway, I’ve managed to fix this issues (including the variable change problem) with this approach for your first visualization:

class GliderParams(param.Parameterized):
    '''Class containing the method for the map'''
    
    dataset = param.Selector(dataset_option.keys(), default = 'GLDAS v2.1', 
            label = 'Dataset')
    surface_var = param.Selector(surface_var_map.keys(), default = 'Temperature', label = 'Surface Field')
    alpha_slider = param.Magnitude(label='Transparency')
    
def surf_vec(dataset,alpha_slider,surface_var): 
        if dataset == 'GLDAS v2.0':
            surf_plot = v20_sel[surface_var_map[surface_var]].hvplot(alpha=alpha_slider, groupby='time',widget_location = 'bottom',cmap=var_select_map[surface_var])
        elif dataset == 'GLDAS v2.1':
            surf_plot = v21_sel[surface_var_map[surface_var]].hvplot(alpha=alpha_slider, groupby='time',widget_location = 'bottom',cmap=var_select_map[surface_var])               
        return surf_plot
    
gp = GliderParams()
pn.Row(pn.Param(gp, name=''), pn.bind(surf_vec, dataset=gp.param.dataset,
                                      alpha_slider=gp.param.alpha_slider, 
                                      surface_var=gp.param.surface_var))

Hope that is helpful! I’ll continue working through the notebook and thinking about how to address the remaining issues.

Thanks @jlstevens ; I’ve previously reported that as an issue on hvPlot: Consistent return type from .hvplot() · Issue #532 · holoviz/hvplot · GitHub.

You can also simplify the code a bit:

def surf_vec(dataset,alpha_slider,surface_var): 
        data = v20_sel if dataset == 'GLDAS v2.0' else v21_sel
        return data[surface_var_map[surface_var]].hvplot(alpha=alpha_slider, 
            groupby='time', widget_location = 'bottom',
            cmap=var_select_map[surface_var])               

Thank you both! Was able to get a little further in the panel today!

I’m also getting the following warning from:

result['precip'].hvplot(groupby='time',widget_location = 'bottom', ylim=[-60,90],coastline=True,crs=ccrs.PlateCarree(), projection=ccrs.PlateCarree(),features = ['borders'])    

WARNING:param.main: features option not found for image plot; similar options include: []

Is it linked to getting an image when using groupby?

Hi @khider ! I just wanted to check in with you and see if you managed to solve your issues here. Don’t hesitate to reach us, the Holoviz team, if need be :slight_smile:

2 Likes

Thank you! Yes I got somewhere. The last problem is that we’re on a server so quite slow. But the tech part for prototyping is working. I need to polish it and then will release it publicly.

Ok cool glad to here you’ve managed to get it working!