diff --git a/CHANGELOG b/CHANGELOG index ec1f87d8..15378421 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ - enh: cythonize downsample_grid (~10x speed-up) - enh: got rid of for-loop in map_indices_parent2child (~100x speed-up) - enh: slight improvement of managing manual indices in hierarchy children + - enh: added dtype properties for contour and trace events - ref: new submodule for hierarchy format 0.56.3 - fix: regression missing check for basin availability diff --git a/dclab/rtdc_dataset/fmt_hdf5/events.py b/dclab/rtdc_dataset/fmt_hdf5/events.py index 27fbb2e8..9b0c95d9 100644 --- a/dclab/rtdc_dataset/fmt_hdf5/events.py +++ b/dclab/rtdc_dataset/fmt_hdf5/events.py @@ -41,6 +41,10 @@ def __len__(self): self._length = len(self.h5group) return self._length + @property + def dtype(self): + return self.h5group["0"].dtype + @property def shape(self): return len(self), np.nan, 2 diff --git a/dclab/rtdc_dataset/fmt_hierarchy/events.py b/dclab/rtdc_dataset/fmt_hierarchy/events.py index 0fa15100..580527a8 100644 --- a/dclab/rtdc_dataset/fmt_hierarchy/events.py +++ b/dclab/rtdc_dataset/fmt_hierarchy/events.py @@ -24,6 +24,10 @@ def __getitem__(self, idx): hp = self.child.hparent return hp["contour"][pidx] + @property + def dtype(self): + return self.child.hparent["contour"].dtype + class ChildNDArray(ChildBase): def __init__(self, child, feat): @@ -113,6 +117,11 @@ def __getitem__(self, idx): hp = self.child.hparent return hp["trace"][self.flname][pidx] + @property + def dtype(self): + hp = self.child.hparent + return hp["trace"][self.flname].dtype + @property def shape(self): hp = self.child.hparent diff --git a/tests/test_rtdc_fmt_hierarchy.py b/tests/test_rtdc_fmt_hierarchy.py index 08249e5b..a4d5c3ce 100644 --- a/tests/test_rtdc_fmt_hierarchy.py +++ b/tests/test_rtdc_fmt_hierarchy.py @@ -88,12 +88,33 @@ def test_hierarchy_logs(): assert ch.logs["dclab-compress"][0] == "{" +@pytest.mark.filterwarnings( + "ignore::dclab.rtdc_dataset.config.WrongConfigurationTypeWarning") +def test_dtype_contour(): + ds = new_dataset(retrieve_data("fmt-hdf5_mask-contour_2018.zip")) + assert ds["contour"].dtype == np.uint16 + ds2 = new_dataset(ds) + assert ds2["contour"].dtype == np.uint16 + + @pytest.mark.filterwarnings( "ignore::dclab.rtdc_dataset.config.WrongConfigurationTypeWarning") def test_dtype_mask_image(): ds = new_dataset(retrieve_data("fmt-hdf5_image-bg_2020.zip")) assert ds["mask"].dtype == bool assert ds["image"].dtype == np.uint8 + ds2 = new_dataset(ds) + assert ds2["mask"].dtype == bool + assert ds2["image"].dtype == np.uint8 + + +@pytest.mark.filterwarnings( + "ignore::dclab.rtdc_dataset.config.WrongConfigurationTypeWarning") +def test_dtype_trace(): + ds = new_dataset(retrieve_data("fmt-hdf5_fl-no-contour_2019.zip")) + assert ds["trace"]["fl1_raw"].dtype == np.int16 + ds2 = new_dataset(ds) + assert ds2["trace"]["fl1_raw"].dtype == np.int16 @pytest.mark.filterwarnings(