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

Improving the "Put variable dimensions and attributes back tutorial" tutorial #62

Open
jypeter opened this issue Nov 27, 2020 · 0 comments

Comments

@jypeter
Copy link
Member

jypeter commented Nov 27, 2020

I've had a quick look at the cdms2 tutorials in the Jupyter-notebooks Tutorials page, and it sometimes seem that tutorials could be simpler, just by using existing cdms2 functions! :-)

The notebook I'm talking about uses

# now put back dimensions on it
fft_s = MV2.array(fft_s)
fft_s.setAxisList(s.getAxisList())

# Dimensions are back
print(fft_s.getAxisIds())

['time', 'latitude', 'longitude']

Put Attributes On It

# now puts the attributes on it
for a in s.attributes:
    setattr(fft_s,a,getattr(s,a))
fft_s.info()

I think that this could be replaced by a single call to the cdms2 functions that exists for this very purpose. As a bonus, I'm showing how users can easily add a new attribute to a variable

fft_s = cdms2.createVariable(fft_s, axes=s.getAxisList(), attributes=s.attributes, id='clt_fft')
fft_s.history = 'Created from clt in ' + f.id
fft_s.info()

You should add a link to the createVariable function documentation. That's another problem. Even knowing the name of the function I was looking for, it took me a lot of time to find the right page! In the end I had to navigate to the appropriate page from the TOC, because the Search result is unfortunately just unusable....

Note: I'm not a big fan of variables that are identified by a single character, especially for tutorials that are supposed to teach good habits to beginners. If somebody updates this tutorial, you can probably replace f with file_in and s with var_in, or something similar

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

1 participant