Skip to content

Commit

Permalink
Merge pull request #649 from catalystneuro/modify_filter_empty_traces
Browse files Browse the repository at this point in the history
Modify the filtering of traces to also filter out traces with empty values
  • Loading branch information
CodyCBakerPhD authored Nov 21, 2023
2 parents 21e1d19 + 869374a commit be00782
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Added Pydantic data models of `BackendConfiguration` for both HDF5 and Zarr datasets (container/mapper of all the `DatasetConfiguration`s for a particular file). [PR #568](https://github.com/catalystneuro/neuroconv/pull/568)
* Changed the metadata schema for `Fluorescence` and `DfOverF` where the traces metadata can be provided as a dict instead of a list of dicts.
The name of the plane segmentation is used to determine which traces to add to the `Fluorescence` and `DfOverF` containers. [PR #632](https://github.com/catalystneuro/neuroconv/pull/632)
* Modify the filtering of traces to also filter out traces with empty values. [PR #649](https://github.com/catalystneuro/neuroconv/pull/649)

### Fixes
* Fixed GenericDataChunkIterator (in hdmf.py) in the case where the number of dimensions is 1 and the size in bytes is greater than the threshold of 1 GB. [PR #638](https://github.com/catalystneuro/neuroconv/pull/638)
Expand Down
4 changes: 3 additions & 1 deletion src/neuroconv/tools/roiextractors/roiextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,9 @@ def add_fluorescence_traces(
traces_to_add = segmentation_extractor.get_traces_dict()

# Filter empty data
traces_to_add = {trace_name: trace for trace_name, trace in traces_to_add.items() if trace is not None}
traces_to_add = {
trace_name: trace for trace_name, trace in traces_to_add.items() if trace is not None and trace.size != 0
}
# Filter all zero data
# traces_to_add = {
# trace_name: trace for trace_name, trace in traces_to_add.items() if any(x != 0 for x in np.ravel(trace))
Expand Down
17 changes: 17 additions & 0 deletions tests/test_ophys/test_tools_roiextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,23 @@ def test_add_fluorescence_one_of_the_traces_is_none(self):

self.assertEqual(len(roi_response_series), 2)

def test_add_fluorescence_one_of_the_traces_is_empty(self):
"""Test that roi response series with empty values are not added to the nwbfile."""

self.segmentation_extractor._roi_response_deconvolved = np.empty((self.num_frames, 0))

add_fluorescence_traces(
segmentation_extractor=self.segmentation_extractor,
nwbfile=self.nwbfile,
metadata=self.metadata,
)

ophys = get_module(self.nwbfile, "ophys")
roi_response_series = ophys.get(self.fluorescence_name).roi_response_series

assert "Deconvolved" not in roi_response_series
self.assertEqual(len(roi_response_series), 2)

def test_add_fluorescence_one_of_the_traces_is_all_zeros(self):
"""Test that roi response series with all zero values are not added to the
nwbfile."""
Expand Down

0 comments on commit be00782

Please sign in to comment.