Skip to content

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

Open
@jypeter

Description

@jypeter

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions