Skip to content

CDMS2/MV2.newaxis doesn't work #1722

@durack1

Description

@durack1

The numpy.newaxis function should add a new (singleton) axis to an existing variable as per the docs:

>>> type(intTo)
<class 'cdms2.tvariable.TransientVariable'>
>>> intTo_NP = np.array(intTo)
>>> type(intTo_NP)
<type 'numpy.ndarray'>
>>> intTo_NP.shape
(384, 320)
>>> intTo_NP_expanded = intTo_NP[np.newaxis]
>>> intTo_NP_expanded.shape
(1, 384, 320)

But it doesn't seem to work for cdms2/MV2:

>>> intTo.shape
(384, 320)
>>> intTo_expanded = intTo[mv.newaxis]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/uvcdat/2.4.0rc1/lib/python2.7/site-packages/cdms2/avariable.py", line 1401, in __getitem__
    speclist = self._process_specs(key, {})
  File "/usr/local/uvcdat/2.4.0rc1/lib/python2.7/site-packages/cdms2/avariable.py", line 1169, in _process_specs
    raise CDMSError, 'Sorry, you cannot use NewAxis in this context ' + str(specs)
cdms2.error.CDMSError: Sorry, you cannot use NewAxis in this context (None, slice(None, None, None))

It's likely that the plans @dnadeau4 has for cdms2 updates (better wrapping all the existing numpy functions) will solve this, but thought it useful to document.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions