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

feat: adding Identity PSF modality #78

Merged
merged 7 commits into from
Sep 28, 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
3 changes: 2 additions & 1 deletion src/microsim/schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .backend import BackendName, DeviceName, NumpyAPI
from .detectors import Camera, CameraCCD, CameraCMOS, CameraEMCCD
from .lens import ObjectiveLens
from .modality import Confocal, Modality, Widefield
from .modality import Confocal, Identity, Modality, Widefield
from .optical_config import (
Bandpass,
LightSource,
Expand Down Expand Up @@ -33,6 +33,7 @@
"ExtentScaleSpace",
"Fluorophore",
"FluorophoreDistribution",
"Identity",
"SpectrumFilter",
"Longpass",
"MatsLines",
Expand Down
6 changes: 3 additions & 3 deletions src/microsim/schema/modality/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ._simple import Confocal, Widefield
from ._simple import Confocal, Identity, Widefield

Modality = Confocal | Widefield
Modality = Confocal | Widefield | Identity

__all__ = ["Modality", "Confocal", "Widefield"]
__all__ = ["Identity", "Modality", "Confocal", "Widefield"]
42 changes: 42 additions & 0 deletions src/microsim/schema/modality/_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,48 @@ class Widefield(_PSFModality):
type: Literal["widefield"] = "widefield"


class Identity(_PSFModality):
"""Optical modality in which PSF is not applied.

The idea is to use this modality when the ground truth flurophore distribution is
generated from a light micorscope image, i.e., the PSF convolution is already
applied on the image. This is useful primarily when you are more interested in the
spectral properties (fluorophores, filters, bleedthrough, etc.) than the spatial
properties (PSF, modality, etc.) in the simulation.
"""

def render(
self,
truth: xrDataArray, # (F, Z, Y, X)
em_rates: xrDataArray, # (C, F, W)
*args: Any,
**kwargs: Any,
) -> xrDataArray:
"""Render a 3D image of the truth for F fluorophores, in C channels.

In this case we don't apply the PSF convolution, as the truth is assumed to be
already convolved with the PSF. Therefore, we simply compute the emission flux
for each fluorophore and each channel.
"""
em_image = em_rates.sum(Axis.W) * truth
return DataArray(
em_image,
dims=[Axis.C, Axis.F, Axis.Z, Axis.Y, Axis.X],
coords={
Axis.C: em_rates.coords[Axis.C],
Axis.F: truth.coords[Axis.F],
Axis.Z: truth.coords[Axis.Z],
Axis.Y: truth.coords[Axis.Y],
Axis.X: truth.coords[Axis.X],
},
attrs={
"space": truth.attrs["space"],
"objective": "",
"units": "photons",
},
)


def bin_spectrum(
spectrum: xrDataArray,
bins: int | np.ndarray = 3,
Expand Down