intake / xrviz

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

Set reset coords #7

Closed hdsingh closed 5 years ago

hdsingh commented 5 years ago

@rsignell-usgs @martindurant I have implemented set/reset coords and plot generation according to our discussion here . There were few points, which I did a bit differently. I would soon add a detailed description of the functionality implemented in this dashboard. In the mean time, please have a look at the interface.

Screenshot from 2019-06-17 12-20-07

hdsingh commented 5 years ago

In case of DataArray, since there is only single variable, Set coord has not been implemented. For a DataSet, it has been implemented. In the Set Coords tab, Cross selector displays all the variables preset in the DataSet. User selects the variable from left side and move them to right side by >> button. After making selection, click on the Set Coords button, which converts the vars to coords. Reverse operation (coord to var) is also possible. We cannot reset the indexed_coords.

Each time user clicks on the Set Coord:

For each of dashboard,control,display,describe,fields,coord_setter, a method set_coords has been implemented which performs necessary updates required in that particular panel.

In the fields panel, x displays all the options (var_dims+non_indexed_coords), while y is selective.

If dims have been selected, data.var.sel method is used for plotting. If coord is selected, data.hvplot.quadmesh(x = 'coord1', y='coord2') method has been used.

Please have a look by playing around with the interface.

hdsingh commented 5 years ago

@martindurant @rsignell-usgs Please review the changes.

hdsingh commented 5 years ago

Screenshot from 2019-06-21 23-52-37

@rsignell-usgs @martindurant Unlike dims, in case of creating graph for a variable with respect to a coord, Aggregations would be empty. Also there doesn't seem any generalisable way to know beforehand, along what coords/vars index selectors would be generated. So is it fine if we are displaying both selector and player in the graph output?

rsignell-usgs commented 5 years ago

@hdsingh, I was just about to comment on this. If coords like lon and lat are selected, it seems that aggregation along other dimensions like sigma and time should still work.

2019-06-21_15-09-09

hdsingh commented 5 years ago

Yes, it seems that we can have aggregation for a variable along a dimension, even when x and y Select has coord as options. I will check and implement this. But in this case Aggregation options will not include Select and Animate as option because we don't know beforehand for sure, if that dim along which we are aggregating, would be present in the generated index selectors or not.

hdsingh commented 5 years ago

Screenshot from 2019-06-22 11-16-13

We can have aggregation for a variable along a dimension, when x and y Select has coord as options.

When a coord has been selected in x and y, we can only aggregate it along the dims which are not present in x or y. For example : Var: temp x: lat y: lon

So now we can't aggregate along dims nx and ny since they are already present in lat and lon. Only aggregation only along remaining dims: time and sigma is possible.

hdsingh commented 5 years ago

@rsignell-usgs @martindurant Everything is working as expected. Please have a look.

rsignell-usgs commented 5 years ago

With this latest commit, I'm getting:

(xrviz) C:\Users\rsignell\Documents\GitHub\xrviz\examples>python control_section.py
Traceback (most recent call last):
  File "control_section.py", line 7, in <module>
    dash = Dashboard(ds)
  File "c:\users\rsignell\documents\github\xrviz\xrviz\dashboard.py", line 34, in __init__
    self.control = Control(self.data)
AttributeError: 'Dashboard' object has no attribute 'data'
hdsingh commented 5 years ago

Now it is working. I will soon simplify the code using data = xr.Dataset({data.name: data}, attrs=data.attrs) as discussed above.

martindurant commented 5 years ago

With this latest commit

I will make a PR, perhaps after Wednesday's meeting, implementing Travis CI. We are probably starting to have enough functionality which is concrete that thorough testing is warranted.

rsignell-usgs commented 5 years ago

@hdsingh, when I select lon and lat as coordinates, I get x=lat, y=lon by default. Is it possible to get x=lon and y=lat as default, or is it impossible to tell what should go where?

2019-06-25_7-40-00

I understand that the user may choose to set whatever they want, but it would be nice to have sensible defaults if possible.

hdsingh commented 5 years ago

Yes correct defaults need to be set. I will look in detail how this could be done from this answer and will implement this in one of upcoming PRs. As of now options are being displayed according to their alphabetical order.

hdsingh commented 5 years ago

Now there is no separate handling for DataArrays due to conversion into Dataset while initialisation by data = xr.Dataset({data.name: data}, attrs=data.attrs).

hdsingh commented 5 years ago

@martindurant I have started writing tests. Please have a look and let me know if this looks fine. My aim here is to replicate the user behaviour and check if the interface is functioning as expected.

martindurant commented 5 years ago

Yes, these tests look like a good start. I expect they are all passing. I'll merge this now, so we can discuss next steps tomorrow.