intake / xrviz

Interactive visualisation interface for Xarrays
https://xrviz.readthedocs.io
BSD 3-Clause "New" or "Revised" License
105 stars 21 forks source link

Allow passing of cartopy_crs #47

Open rsignell-usgs opened 4 years ago

rsignell-usgs commented 4 years ago

It would be nice to allow xrviz to handle a metpy-generated cartopy_crs passed as part of the initial_params for xrviz. hvplot handles it just fine, but using it in the initial_params returns TypeError: getattr(): attribute name must be string. See:

https://nbviewer.jupyter.org/gist/rsignell-usgs/56d8ff54708a95b45bb46f55a0677ab0

martindurant commented 4 years ago

cc @hdsingh

hdsingh commented 4 years ago

As of now initial_params's values are only in the form of strings and not the form of custom objects such as cartopy.crs. It is a good idea to also allow passing the values for projection options directly in the form of these objects. Values in the form of string will also be allowed.

I will look into this issue after 11Oct (exams now).

hdsingh commented 4 years ago

@rsignell-usgs (for now you can directly pass it in the form of string such as "LambertConformal"). Initially our idea was to pass the initial params with a YAML file, so only values in the form of strings were allowed.

hdsingh commented 4 years ago

This is how I think it could be done:

import cartopy.crs as ccrs
crs = ccrs.LambertConformal(central_longitude=40.,
                            central_latitude=60.,
                            globe=ccrs.Globe(ellipse='WGS84',
                                             semimajor_axis=None,
                                             ))

Lets say this is the crs object parsed by metpy. If we want to pass just the name of this object it could be done by crs.__class__.__name__. However, this object can't be passed directly to hvplot because we also need to display its properties in the crs params. So the values of default parametes (along with globe's parameters) need to be extracted from this object, for display in crs params. This could be done with the help of keys/values from crs.proj4_params. This data has to be converted to dictionary and is to be passed to crs.value textbox for display.

martindurant commented 4 years ago

However, this object can't be passed directly to hvplot

well, it could, but would be an alternate code path. This could be very OK, you can use the passed-in CRS object or you can set your own parameters. Extracting out the parameters from a passed-on object and populating the fields would only ever be on a best-attempt basis, because there are many options we cannot surface in the interface.

martindurant commented 4 years ago

In summary, I think this is a reasonable request that we can allow, when someone makes the effort to implement it.