diff --git a/CHANGELOG b/CHANGELOG index dd95730..1134ca7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -51,6 +51,8 @@ - fix: segmenters more than two levels below `Segmenter` (e.g. a subclass of `SegmentThresh`) were not found by `get_segmenters`, so their pipeline identifier could not be resolved + - fix: `detect_flickering` raised a `TypeError` for `HDF5Data` + instances, although the docstring allowed them - docs: comment on intended behavior of `fill_holes` (mask post-processing), Haralick texture features, and the sparsemed background assignment after cleansing diff --git a/dcnum/read/detect_flicker.py b/dcnum/read/detect_flicker.py index d5ba230..0e85b06 100644 --- a/dcnum/read/detect_flicker.py +++ b/dcnum/read/detect_flicker.py @@ -24,8 +24,8 @@ def detect_flickering(image_data: np.ndarray | HDF5Data, Parameters ---------- image_data: - sliceable object (e.g. numpy array or HDF5Data) containing - image data. + sliceable object (e.g. numpy array or image cache) containing + image data or HDF5Data instance (the "image" feature is used) roi_height: int height of the ROI in pixels for which to search for flickering; the entire width of the image is used @@ -38,7 +38,9 @@ def detect_flickering(image_data: np.ndarray | HDF5Data, max_frames: int maximum number of frames to include in the flickering analysis """ - # slice event axis first in case we have and HDF5Data instance + if isinstance(image_data, HDF5Data): + image_data = image_data.image + # slice event axis first in case we have an image cache roi_data = image_data[:max_frames][:, :roi_height, :] roi_median = np.median(roi_data, axis=(1, 2)) roi_offset = roi_median - np.median(roi_median) diff --git a/tests/test_read_detect_flicker.py b/tests/test_read_detect_flicker.py index f4adc36..1aa8484 100644 --- a/tests/test_read_detect_flicker.py +++ b/tests/test_read_detect_flicker.py @@ -47,6 +47,9 @@ def test_detect_flicker_hdf5data_instance(): assert len(hd) == 1000 assert not detect_flickering(hd.image) assert detect_flickering(hd.image, brightness_threshold=1) + # HDF5Data instance (dcnum 0.31.2 raised a TypeError) + assert not detect_flickering(hd) + assert detect_flickering(hd, brightness_threshold=1) def test_detect_flicker_none():