Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roi_measure modified to generate more ROI statistics #15

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Most functionality is demonstrated in Jupyter notebook format in ./demo
---

### Updates
Release 1.1.0 - *roi_measure* modified to generate more ROI statistics
Release 1.0.3 - Add exception handling for some zero/negative inputs.
Release 1.0.2 - Changed AIF interpolation method to linear to further reduce oscillations.
Release 1.0.1 - Changed AIF interpolation method to avoid oscillations. Added demo notebook on interpolation.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "sepal"
version = "1.0.3"
version = "1.1.0"
description = "Quantitative MRI processing"
readme = "README.md"
authors = [{ name = "Michael Thrippleton", email = "[email protected]" }]
Expand Down
21 changes: 14 additions & 7 deletions src/sepal/utils/imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def roi_measure(image, mask_image):
mask_image (str, ndarray): Mask image.

Returns:
dict{'mean': mean, 'median': median, 'sd': sd}
mean, median and sd (float, ndarray): statistics for masked
dict{'mean': mean, 'median': median, 'sd': sd, 'min': min, 'max': max, 'pct25': pct25, 'pct75': pct75}
mean, median, sd, min, max, 25th percentile and 75th percentile (float, ndarray): statistics for masked
voxels. For input data with one more dimension than the mask
image (e.g. a time series), a 1D array of floats is returned.
"""
Expand All @@ -95,9 +95,16 @@ def roi_measure(image, mask_image):

# measure statistics for masked voxels
masked_voxels = data_2d[mask_1d == 1, :]
stats = [(np.nanmean(m_d), np.nanmedian(m_d), np.nanstd(m_d))
stats = [(np.nanmean(m_d), np.nanmedian(m_d), np.nanstd(m_d), np.nanmin(m_d), np.nanmax(m_d),
np.percentile(m_d, 25), np.percentile(m_d, 75))
for m_d in masked_voxels.transpose()]
mean, median, sd = zip(*stats)

return {'mean': np.squeeze(mean), 'median': np.squeeze(median),
'sd': np.squeeze(sd)}
mean, median, sd, mini, maxi, pct25, pct75 = zip(*stats)

return {'mean': np.squeeze(mean),
'median': np.squeeze(median),
'sd': np.squeeze(sd),
'min': np.squeeze(mini),
'max': np.squeeze(maxi),
'pct25': np.squeeze(pct25),
'pct75': np.squeeze(pct75)
}