Skip to content

Commit

Permalink
enh: added dtype properties for contour and trace events
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jan 4, 2024
1 parent 6a6da58 commit 9c72ea9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions dclab/rtdc_dataset/fmt_hdf5/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions dclab/rtdc_dataset/fmt_hierarchy/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/test_rtdc_fmt_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9c72ea9

Please sign in to comment.