intake / intake-gsoc-gui

Panel GUI project for GSOC
3 stars 3 forks source link

Discussion for `set/reset_coords` in the XrViz Interface #20

Closed hdsingh closed 5 years ago

hdsingh commented 5 years ago

We can plot data coordinates now as well !

It turned out to be simple:

data = datafile.great_lakes()
ds = data.set_coords(['lat','lon'])
sel = data.lat
sel.hvplot.quadmesh()

This gives error: ValueError: cannot create a Dataset from a DataArray with the same name as one of its coordinates. So all I have done is change the name of selection.

sel = data.lat
sel = sel.to_dataset(name=f'{sel.name}_')
sel.hvplot.quadmesh()

This shows the plot!

@rsignell-usgs @martindurant Now it does not matter whether a variable is coordinate or not. We can plot any variable provided it is not 1D. This behaviour is similar to Panoply, where we are able to plot all the multi-dimensional variables.

Earlier we wanted to haveset/reset coordinates method within the interface so that we can plot the variables which are coordinates (by resetting them as normal variables). If we have this method now, it will do nothing, except showing '📈' in front of a variable's name (to indicate that it is a coordinate). Panoply doesn't have any such method. So is there any need for it now?

martindurant commented 5 years ago

Are you suggesting it would be enough to show the number of dimensions of each variable in the selection widget? This sounds like "method 2" from our discussion: let's say you choose variable "u" in our example dataset, what do you expect to be available in the fields selection x and y widgets? How does the content of widget y change, depending on the user's selection in widget x? It would be good to write out some of the scenarios (which will make tests, later!).

hdsingh commented 5 years ago

I am suggesting that for a particular variabe selected, we should only display its dimensions. For u, its dims will be displayed i.e. time,sigma, ny, nx in the x,y selection. We should not display variables coodinates along with variables dims (lat and lon if we have done set_coord).

The reason I am saying this is because : data[var].hvplot.quadmesh(**graph_opts) considers only var coordinates to create a plot, also it is results in errors for anything other than lat and lon. While data[var].sel method considers only var dims. There is no method which can handle the creation of plot by both var coord and var dim. So displaying only var dims are sufficient in x and y.

How does the content of widget y change, depending on the user's selection in widget x?

Both the options need to be unique. So if the user selects the option which is already value of y, then y's value will change to one of remaining unselected options.

martindurant commented 5 years ago

For u, its dims will be displayed i.e. time,sigma, ny, nx in the x,y selection.

No, this is not acceptable, I'm afraid. Given a dataset like we are using here, the user must be able to select whether they want a plot of pairs of dimensions such as:

Some combinations, like lat, time may not be possible to plot. This must be achievable using only actions within the interface.

There are two scenarios I can think of to make this happen:

hdsingh commented 5 years ago

I think I just figured out how this could be done.

I am stating the condition here once again, just to explain properly:
In a combination of x,y (such as nx,ny) both the selections need to be of same category i.e. :

This has been explained for great_lakes dataset but applies generally.

Here are the following conditions/rules I have in mind for field selectors:

  1. A coordinate would be displayed in x Select only if it has been set_coord by the user, or present by default as coord in the data.
  2. A coordinate would be removed from the options of x and y, once it is reset_coord by the user.
  3. A coordinate would be displayed in options only if it is multi-dimensional. (not 1d and not empty, since we can't plot those, were the cause behind errors what we called inconsistent coords)
  4. In the x Select widget both var dims and var coords will be displayed as options. However y Select will have either only dims or only coords, depending upon what user selected in x. This is important because only two coords or two dims together form a possible combination. So we can't have (coord,dim) or (dim,coord) as combination in the selection.

Given a dataset like we are using here, the user must be able to select whether they want a plot of pairs of dimensions such as

  • nx, ny
  • ny, time

I may not have been able to clearly state myself earlier. However this is exactly happening now in Pull Request #3

  • lat, lon

This functionality to plot a variable with respect to coords would be added with set/reset_coord method in next PR as explained above.

There are two scenarios I can think of to make this happen:

I am suggesting to go with 1st one (explicit coordinate selection input of some sort), where the user decides which variables he wants to have as coords and set/reset them as required.

  • upon selection of a field in x, do we try to eliminate impossible selections for y

Yes, we will eliminate impossible selections for y.

do we allow the user to choose and surface the resulting error when a bad choice is made?

Even here also we have to trust the user to make sensible choices for setting coordinates. This is the only possible place where a user may go wrong. For example: if the user sets temp as coordinate and then tries to create a plot for u by combination of (temp,lat) as (x,y) it will result in error. For this, I think it would be OK to trust the user. We can surface the resulting error when a bad choice is made in setting the coords. However this error message would be displayed only when user tries to plot and not while he tries to set_coord.

@rsignell-usgs @martindurant What do you think about this?

martindurant commented 5 years ago

OK, well go for it with scenario 1. My requirement is that the "set_coord" operation not be required before passing the dataset into xrviz, that the selection is done within the interface. It could happen in the variable select panel,. the field select panel, or have a section of its own. You probably want one of these: https://panel.pyviz.org/reference/widgets/CrossSelector.html

hdsingh commented 5 years ago

User can select and set any variable as a coordinate. The user can also have aggregation for a variable along a dimension, even when x and y Select has coord as options.

Screenshot from 2019-06-24 08-31-26