Skip to content

Commit

Permalink
Add check to the region filter in case the input dataset is all equal…
Browse files Browse the repository at this point in the history
… to 0 for the region of interest. (#74)
  • Loading branch information
drodarie authored Mar 19, 2024
1 parent 6e76e8c commit 7a119f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
9 changes: 4 additions & 5 deletions atlas_densities/densities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def normalize_intensity(
3D array, the normalized marker intensity array.
"""

outside_mean = np.mean(
marker_intensity[np.logical_and((annotation == region_id), (marker_intensity > 0.0))]
)
output_intensity = copy_array(marker_intensity, copy=copy)
output_intensity -= outside_mean * threshold_scale_factor
mask_low_filter = np.logical_and((annotation == region_id), (marker_intensity > 0.0))
if np.any(mask_low_filter):
outside_mean = np.mean(marker_intensity[mask_low_filter])
output_intensity -= outside_mean * threshold_scale_factor
output_intensity[output_intensity < 0.0] = 0.0
max_intensity = np.max(output_intensity)
if max_intensity > 0:
Expand Down Expand Up @@ -405,7 +405,6 @@ def materialize(node):


def get_group_ids(region_map: "RegionMap", config: dict, _skip_check=False) -> dict[str, set[int]]:

"""
Get AIBS structure ids for several region groups of interest.
Expand Down
14 changes: 14 additions & 0 deletions tests/densities/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ def test_normalize():
# In place modification
actual = tested.normalize_intensity(marker, annotation_raw, copy=False)
npt.assert_array_almost_equal(marker, expected)
# Test outside with no intensity
marker = np.array(
[
[
[0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 3.0, 5.0, 0.0],
[0.0, 0.0, 0.0, 0.0],
]
],
dtype=float,
)
actual = tested.normalize_intensity(marker, annotation_raw, copy=True)
npt.assert_array_almost_equal(marker / np.max(marker), actual)


def test_compensate_cell_overlap():
Expand Down

0 comments on commit 7a119f2

Please sign in to comment.