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

Slicing WaveformModes does not work #63

Open
SSL32081 opened this issue Dec 18, 2024 · 2 comments · May be fixed by #64
Open

Slicing WaveformModes does not work #63

SSL32081 opened this issue Dec 18, 2024 · 2 comments · May be fixed by #64
Labels
Urgent Highest priority issue that might be breaking functionality

Comments

@SSL32081
Copy link

SSL32081 commented Dec 18, 2024

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
@SSL32081 SSL32081 linked a pull request Dec 18, 2024 that will close this issue
@SSL32081
Copy link
Author

It seems that this issue occurs because of the metadata and _metadata attributes in nrcatalogtools.waveform.WaveformModes do not match, and how sxs is dealing with them ends up results in a conflict.

I have created pull request (#64) to (hopefully) resolve this.

@prayush prayush added the Urgent Highest priority issue that might be breaking functionality label Dec 20, 2024
@vaishakp
Copy link
Collaborator

Strangely, this works for me on and off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Urgent Highest priority issue that might be breaking functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants