kujaku11 / mth5

Exchangeable and archivable format for magnetotelluric time series to better serve the community through FAIR principles.
https://mth5.readthedocs.io/en/latest/index.html
MIT License
16 stars 6 forks source link

mth5_type not written to mth5 channel dataset #223

Closed kkappler closed 2 months ago

kkappler commented 4 months ago

Very weird edge case behaviour I encountered this week. I build an mth5, everything is fine.

I try to access the data to decimate it, and cannot get my electric channels. The data are there and I can access the dataset by directly talking to the the hdf5_dataset["ex"][:], but cannot get_channel.

Error is KeyError: "Can't open attribute (can't locate attribute: 'mth5_type')"

Its a long story, but there maybe a simple fix which is to edit channel_dataset.py, around Line 134, from:

        if not "mth5_type" in list(self.hdf5_dataset.attrs.keys()):
            self.write_metadata()

to

        if not "mth5_type" in list(self.hdf5_dataset.attrs.keys()):
            self.hdf5_dataset.attrs["mth5_type"] = self._class_name
            self.write_metadata()

I'll see if passes tests, if so will request review

FWIW:

decimation.augment_mth5_with_decimation_levels( augment_mth5_with_decimation_levels _add_decimation_level( wrapper_decorator result = call_function(func, *args, *kwargs) result = func(args, **kwargs) _add_decimation_level runts = run_obj.to_runts() # SLOW File "C:\Users\KarlKappler\anaconda3\envs\my_env\lib\site-packages\mth5\groups\run.py", line 605, in to_runts ch_obj = self.get_channel(channel) File "C:\Users\KarlKappler\anaconda3\envs\my_env\lib\site-packages\mth5\groups\run.py", line 520, in get_channel if ch_dataset.attrs["mth5_type"].lower() in ["electric"]: File "h5py_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "C:\Users\KarlKappler\anaconda3\envs\my_env\lib\site-packages\h5py_hl\attrs.py", line 56, in getitem attr = h5a.open(self._id, self._e(name)) File "h5py_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "h5py\h5a.pyx", line 80, in h5py.h5a.open KeyError: "Can't open attribute (can't locate attribute: 'mth5_type')"

kkappler commented 4 months ago

A few comments for reference about context when this error was encountered.