Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script showing how to use raw=True before calling matplotlib function #14

Open
jypeter opened this issue May 21, 2019 · 2 comments
Open

Comments

@jypeter
Copy link
Member

jypeter commented May 21, 2019

Once again, I had to convert an MV2 array to numpy.ma array before calling matplotlib, using the possibly under-documented raw=1 feature (CDAT/cdms#338)

I was lucky to remember that trick, because it was either that or deal with a quite obscure and unrelated matplotlib traceback

>>> type(pr_rmin)
<class 'cdms2.tvariable.TransientVariable'>

>>> diff_plot.plot(x_lats, pr_rmin)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/share/unix_files/cdat/miniconda3/envs/cdatm_py2/lib/python2.7/site-packages/matplotlib/__init__.py", line 1867, in inner
    return func(ax, *args, **kwargs)
  File "/home/share/unix_files/cdat/miniconda3/envs/cdatm_py2/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 1528, in plot
    for line in self._get_lines(*args, **kwargs):
  File "/home/share/unix_files/cdat/miniconda3/envs/cdatm_py2/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 406, in _grab_next_args
    for seg in self._plot_args(this, kwargs):
  File "/home/share/unix_files/cdat/miniconda3/envs/cdatm_py2/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 391, in _plot_args
    ncx, ncy = x.shape[1], y.shape[1]
IndexError: tuple index out of range

>>> diff_plot.plot(x_lats, pr_rmin(raw=True))
[<matplotlib.lines.Line2D object at 0x2b038d6eb210>]

Or maybe there is an easy fix in the cdms2 (masked) variables to make them compatible with matplotlib?

Anyway it's probably easy and useful to create a short notebook to illustrate this

@doutriaux1
Copy link
Contributor

@jypeter what about numpy_var = cdmsvar.asma() if masked or numpy_var = cdms_var.filled(-999) if no missing needed.

@jypeter
Copy link
Member Author

jypeter commented Jun 4, 2019

asma() sounds nice, but there is little documentation for it. I searched the cdms2 documentation and the only useful ref I found was in cdms2.tvariable module which may not be a place that an end user is likely to visit

As a matter of fact, I had never been on that page! Should there be some kind of link to this from 2.3. Cdms Module ?

And maybe asma should also be documented in 2.3. Cdms Module

I have extracted below a page from my old 2007 CDAT tutorial. It's in French (@dnadeau4 that's for you!), but it shows how the different data objects from files/python/Numeric/CDAT relate to each other, and which functions you can use to go from one type of data to the other. Maybe there could be a similar (and updated!) Data Overview Page (a good DOPe) on the CDAT site? Showing that asma can be used to go from and MV2 var to a numpy.ma var

MiscDataObjectsByJYP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants