Skip to content

Slicing WaveformModes does not work #63

@SSL32081

Description

@SSL32081

A simple slicing of a WaveformModes object would result in a KeyError, saying time_axis not found from self._metadata.

A MWE is here:

from nrcatalogtools import RITCatalog
rit_code = 'RIT:BBH:0001-n100-id3'
rit_catalog = RITCatalog.load(download=False)
h_rit = rit_catalog.get(rit_code)
print(h_rit[2])

I managed to trace this back to one line in the SXS WaveformModes object (line 119):

        obj, time_key = self._slice(key)

and because of this, doing the following will result in the same error:

from nrcatalogtools.waveform import WaveformModes
h_rit_viewed = h_rit.view(WaveformModes)
print(h_rit_viewed)

If I print out the __dict__ attribute before and after view(), the lists of attributes are indeed wildly different.
I suspect that it is how the WaveformModes are constructed that is not compatible with this view() method, but I have yet to find out why.

Here is an excerpt from the traceback:

File ~/.conda/envs/.../site-packages/sxs/time_series.py:463, in TimeSeries.__repr__(self)
    [461] def __repr__(self):
    [462]    r = repr(self.ndarray)
--> [463]     return f"{type(self).__name__}{r[max(0, r.find('(')):-1]}, time={self.time!r}, time_axis={self.time_axis})"

File ~/.conda/envs/.../site-packages/sxs/time_series.py:297, in TimeSeries.time_axis(self)
--> [297] return self._metadata["time_axis"]

KeyError: 'time_axis'

Before getting to this step, there was a little issue with the metadata, so I did a little fix in catalog.py

        if type(metadata) is not dict and hasattr(metadata, "to_dict"):
            metadata = metadata.to_dict()
# ↓  These are new ↓ 
        elif isinstance(metadata, dict):
            metadata = dict(metadata.items())

Finally, maybe this would be helpful; here are the versions of the packages I have:

numpy → 1.26.2
sxs → 2024.0.25
nrcatalogtools → latest master branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    UrgentHighest priority issue that might be breaking functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions