CDAT / vcs-js

3 stars 3 forks source link

Function to get variable info #38

Closed James-Crean closed 6 years ago

James-Crean commented 6 years ago

We need a method to get detailed info from a given variable. Something with a call signature like: getVariableInfo(path) that would return an object for vCDAT to display.

danlipsa commented 6 years ago

@James-Crean take a look at vcs-js/demo/demo.js printVariables(filename). This calls a vcs.variables(filename) a vcs-js function that returns an object describing all variables in a file.

James-Crean commented 6 years ago

Sorry, my description was incorrect. What I am actually looking for is file info. Specifically, I am looking for a function that will return the output of .attributes, .variables, .axes, etc. on a file opened with cdms.

import cdms2

f = cdms2.open("a/file/path.nc")
f.attributes
f.variables

The goal is to be able to take the return value of such a function and display it in vcdat. This way the user can get a detailed view of the file they are going to plot from.

Some of this information is indeed provided by the .variables() function, but there is other information worth looking at that is not specific to the variables. (Model, experiment, forcing, title, etc. )

James-Crean commented 6 years ago

Here is an example from the old cdat gui.

*** Description of Slab clt ***
id: clt
shape: (120, 46, 72)
filename: /export/crean2/clt.nc
missing_value: None
comments: YONU_AMIP1
grid_name: YONU4X5
grid_type: gaussian
time_statistic: average
long_name: Total cloudiness
units: %
Grid has Python id 0x25bb210.
Gridtype: gaussian
Grid shape: (46, 72)
Order: yx
** Dimension 1 **
   id: time
   Designated a time axis.
   units:  months since 1979-1-1 0
   Length: 120
   First:  0.0
   Last:   119.0
   Python id:  0x25bb110
** Dimension 2 **
   id: latitude
   Designated a latitude axis.
   units:  degrees_north
   Length: 46
   First:  -90.0
   Last:   90.0
   Other axis attributes:
      long_name: Latitude
   Python id:  0x25bb150
** Dimension 3 **
   id: longitude
   Designated a longitude axis.
   units:  degrees_east
   Length: 72
   First:  -180.0
   Last:   175.0
   Other axis attributes:
      long_name: Longitude
   Python id:  0x25bb0d0
*** End of description for clt ***
doutriaux1 commented 6 years ago

@James-Crean @scottwittenburg good news the info function takes a device as input (defaulted to stdout), so you can intercept it into a string easily. See: https://github.com/CDAT/cdms/blob/v3.0/Lib/avariable.py#L123

scottwittenburg commented 6 years ago

@James-Crean regarding the api you might like to see in vcs-js. Do you want something where you specify the filename and the variable and get back the info string:

vcs.getFileInfo('clt.nc', 'clt')

// returns
'*** Description of Slab clt ***...'

Or do you want to ask for the info for the whole file and get back a dictionary mapping variable names to these info strings:

vcs.getFileInfo('clt.nc')

// returns
{
  'clt': '*** Description of Slab clt ***...',
  'u': '*** Description of Slab u ***...',
  'v': '*** Description of Slab v ***...'
}

Or maybe something else altogether?

James-Crean commented 6 years ago

Both options would be nice, but if i had to choose one, I would say the second one. It would give me a bit more flexibility at the cost of a negligible difference in load time.

scottwittenburg commented 6 years ago

Ok @James-Crean you should have both options. Check out #43, and see the tests I added for how you can achieve either option.

James-Crean commented 6 years ago

Thanks Scott! Fixed in #43