CDAT / vcs-js

3 stars 3 forks source link

Error when plotting variables with dimensions specified #34

Closed James-Crean closed 6 years ago

James-Crean commented 6 years ago

Plotting variables works fine so long as the latitude/logitude/time/etc are not changed.

When plotting a variable with dimensions other than the default the following error occurs:

exception: "CDMSError("Specification not acceptable: <type 'unicode'>, latitude",)"

Here is the relevant stack trace:

"Traceback (most recent call last):
  File "/Users/crean2/anaconda2/envs/nightly/lib/python2.7/site-packages/wslink/websocket.py", line 274, in onMessage
    results = func(obj, *args, **kwargs)
  File "build/bdist.macosx-10.9-x86_64/egg/vcs_server/Visualizer.py", line 35, in plot
    var = var.subRegion(**kargs)
  File "/Users/crean2/anaconda2/envs/nightly/lib/python2.7/site-packages/cdms2/avariable.py", line 767, in subRegion
    speclist = self._process_specs(specs, keys)
  File "/Users/crean2/anaconda2/envs/nightly/lib/python2.7/site-packages/cdms2/avariable.py", line 1262, in _process_specs
    i = self.getAxisIndex(k)
  File "/Users/crean2/anaconda2/envs/nightly/lib/python2.7/site-packages/cdms2/avariable.py", line 383, in getAxisIndex
    if axisMatches(self.getAxis(i), axis_spec):
  File "/Users/crean2/anaconda2/envs/nightly/lib/python2.7/site-packages/cdms2/axis.py", line 2577, in axisMatches
    str(type(specification)) + ', ' + str(specification))
CDMSError: Specification not acceptable: <type 'unicode'>, latitude
"
James-Crean commented 6 years ago

Cdms2 will return this error if an axis name/key is unicode rather than an ascii string.

Works: {'latitude': [0,1]} Errors: {u'latitude': [0,1]}

I tested a simple fix myself that replaces the following code block in Visualizer.py:

if ('subRegion' in op):
    kargs = op['subRegion']
    var = var.subRegion(**kargs)

with this:

if ('subRegion' in op):
    kargs = op['subRegion']
    fixed_kargs = {}
    for key in kargs.keys():
        fixed_kargs[str(key)] = kargs[key]
    var = var.subRegion(**fixed_kargs)

And subsetting began to work again.

doutriaux1 commented 6 years ago

@James-Crean can you file an issue for this on cdms repo? thx.

scottwittenburg commented 6 years ago

Hi @James-Crean and @doutriaux1 , I'm just checking if there's some action you want me to take here?

In the absence of some over-arching policy regarding character encodings, I'm not sure what to do on the web end. If we try and "clean" (by forcing everything to ascii strings) all the data that comes from people's different browsers, we could probably prevent this particular error, but then I think we will have ruled out the use of any other languages on the front end.

I'm not sure, but the right approach might be to formalize our notion of character encoding for a session, and then make sure the backend can handle that as long as it know what that encoding is.

James-Crean commented 6 years ago

No worries Scott. We found that this is actually an issue with cdms, so vcs-js doesn't need to worry about the encodings. I'll closer this issue since there is nothing to be done here