Skip to content

Commit

Permalink
Merge pull request #46 from kabilar/main
Browse files Browse the repository at this point in the history
Remove `Mask` quality metrics table
  • Loading branch information
kushalbakshi authored May 18, 2023
2 parents 02ddd49 + e541892 commit 321365b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 62 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.

## [0.3.0] - 2023-05-15
## [0.3.0] - 2023-05-17

+ Add - Quality metrics
+ Update - README and docs to reflect new structure across all Elements
Expand Down
67 changes: 6 additions & 61 deletions element_miniscope/miniscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,24 +1181,6 @@ class ProcessingQualityMetrics(dj.Computed):
-> Fluorescence
"""

class Mask(dj.Part):
"""Quality metrics used to evaluate the masks.
Attributes:
Fluorescence (foreign key): Primary key from Fluorescence.
Segmentation.Mask (foreign key): Primary key from Segmentation.Mask.
mask_area (float): Mask area in square micrometer.
roundness (float): Roundness between 0 and 1. Values closer to 1 are rounder.
"""

definition = """
-> master
-> Segmentation.Mask
---
mask_area=null: float # Mask area in square micrometer.
roundness: float # Roundness between 0 and 1. Values closer to 1 are rounder.
"""

class Trace(dj.Part):
"""Quality metrics used to evaluate the fluorescence traces.
Expand All @@ -1221,61 +1203,24 @@ def make(self, key):
"""Populate the ProcessingQualityMetrics table and its part tables."""
from scipy.stats import skew

(
mask_xpixs,
mask_ypixs,
mask_weights,
fluorescence,
fluo_channels,
mask_ids,
mask_npix,
px_height,
px_width,
um_height,
um_width,
) = (Segmentation.Mask * RecordingInfo * Fluorescence.Trace & key).fetch(
"mask_xpix",
"mask_ypix",
"mask_weights",
"fluorescence",
"fluo_channel",
"mask",
"mask_npix",
"px_height",
"px_width",
"um_height",
"um_width",
)

norm_mean = lambda x: x.mean() / x.max()
roundnesses = [
norm_mean(np.linalg.eigvals(np.cov(x, y, aweights=w)))
for x, y, w in zip(mask_xpixs, mask_ypixs, mask_weights)
]
(fluorescence, fluorescence_channels, mask_ids,) = (
Segmentation.Mask * RecordingInfo * Fluorescence.Trace & key
).fetch("fluorescence", "fluorescence_channel", "mask")

fluorescence = np.stack(fluorescence)

self.insert1(key)

self.Mask.insert(
dict(key, mask=mask_id, mask_area=mask_area, roundness=roundness)
for mask_id, mask_area, roundness in zip(
mask_ids,
mask_npix * (um_height / px_height) * (um_width / px_width),
roundnesses,
)
)

self.Trace.insert(
dict(
key,
fluo_channel=fluo_channel,
fluorescence_channel=fluorescence_channel,
mask=mask_id,
skewness=skewness,
variance=variance,
)
for fluo_channel, mask_id, skewness, variance in zip(
fluo_channels,
for fluorescence_channel, mask_id, skewness, variance in zip(
fluorescence_channels,
mask_ids,
skew(fluorescence, axis=1),
fluorescence.std(axis=1),
Expand Down

0 comments on commit 321365b

Please sign in to comment.