Skip to content

Commit da66454

Browse files
added a few flim convenience functions
1 parent 040be2a commit da66454

File tree

5 files changed

+56
-12
lines changed

5 files changed

+56
-12
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
CIBW_TEST_COMMAND: >
3333
cd {package} &&
3434
pytest tests
35+
3536
DROPBOX_SECRET: ${{ secrets.DROPBOX_SECRET }}
3637
DROPBOX_APP_KEY: ${{ secrets.DROPBOX_APP_KEY }}
3738
DROPBOX_REFRESH_TOKEN: ${{ secrets.DROPBOX_REFRESH_TOKEN }}

siffpy/core/flim/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Union
99
from siffpy.core.flim.flimparams import FLIMParams, Exp, Irf # noqa: F401
1010
from siffpy.core.flim.multi_pulse import MultiPulseFLIMParams, MultiIrf, FractionalIrf # noqa: F401
11-
from siffpy.core.flim.flimunits import FlimUnits, convert_flimunits # noqa: F401
11+
from siffpy.core.flim.flimunits import FlimUnits, convert_flimunits, FlimUnitsLike # noqa: F401
1212

1313
import numpy as np
1414

siffpy/core/flim/flimparams.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,21 @@ def T_O(self)->float:
388388
""" Back-compatibility """
389389
return self.tau_offset
390390

391+
@property
392+
def offsets(self) -> List[Tuple[float, float]]:
393+
"""
394+
All offsets in a list format paired with their
395+
corresponding weights. For a single IRF, this is
396+
a weight of 1, but if there are multiple laser pulses
397+
the weights will sum to one.
398+
399+
# Returns
400+
401+
- `offsets : List[Tuple[float, float]]`
402+
[(offset, weight), ...]
403+
"""
404+
return [(self.tau_offset, 1)]
405+
391406
@property
392407
def noise(self)->float:
393408
"""

siffpy/core/flim/multi_pulse.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55
from typing import (
66
Any, Union, List, Tuple, Dict, Optional,
7-
TYPE_CHECKING, Callable
7+
TYPE_CHECKING, Callable, Iterator,
88
)
99

1010
import numpy as np
@@ -235,7 +235,7 @@ def __setitem__(self, index:int, value:FractionalIrf):
235235
"""
236236
self.irfs[index] = value
237237

238-
def __iter__(self):
238+
def __iter__(self) -> Iterator[FractionalIrf]:
239239
"""
240240
Iterates over the IRFs
241241
"""
@@ -270,6 +270,13 @@ def __init__(
270270
arg for arg in args if isinstance(arg, MultiIrf)
271271
)
272272

273+
@property
274+
def offsets(self) -> List[Tuple[float, float]]:
275+
return [
276+
(irf.tau_offset, irf.frac)
277+
for irf in self.irfs
278+
]
279+
273280
@property
274281
def irfs(self)->MultiIrf:
275282
"""

siffpy/core/siffreader.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
## Should I move some import statements to function definitions
99
from siffpy.core import io, timetools
10-
from siffpy.core.flim import FLIMParams, FlimUnits, default_flimparams
10+
from siffpy.core.flim import FLIMParams, FlimUnits, default_flimparams, FlimUnitsLike
1111
from siffpy.core.utils.event_stamp import EventStamp
1212

1313
#from siffpy.core.utils import ImParams
@@ -1464,6 +1464,7 @@ def get_frames_flim(
14641464
registration_dict : Optional[Dict] = None,
14651465
confidence_metric : str = 'chi_sq',
14661466
method : Union[str, FlimMethod] = FlimMethod.EMPIRICAL,
1467+
units : 'FlimUnitsLike' = 'nanoseconds',
14671468
) -> FlimTrace:
14681469
"""
14691470
Returns a FlimTrace object of dimensions
@@ -1498,15 +1499,17 @@ def get_frames_flim(
14981499
confidence_metric=confidence_metric
14991500
)
15001501

1501-
return FlimTrace(
1502+
ft = FlimTrace(
15021503
lifetime,
15031504
intensity = intensity,
15041505
#confidence= np.array(flim_arrays[2]),
15051506
FLIMParams = params,
15061507
method = method.value,
1507-
units = 'countbins',
15081508
)
15091509

1510+
ft.convert_units(units)
1511+
return ft
1512+
15101513
def _get_frames_flim_srm(
15111514
self,
15121515
params : FLIMParams,
@@ -1574,6 +1577,7 @@ def sum_mask_flim(
15741577
registration_dict : Optional[dict] = None,
15751578
return_framewise : bool = False,
15761579
flim_method : Union[str, FlimMethod] = FlimMethod.EMPIRICAL,
1580+
units : 'FlimUnitsLike' = 'nanoseconds',
15771581
)->FlimTrace:
15781582
"""
15791583
Computes the empirical lifetime within an ROI over timesteps.
@@ -1621,6 +1625,9 @@ def sum_mask_flim(
16211625
* `flim_method` : Union[str, FlimMethod]
16221626
The method to use for the FLIM analysis. Default is 'empirical'.
16231627
Options are any of the `FlimMethod` enum values (`siffpy.siffmath.flim.FlimMethod`).
1628+
1629+
* `units` : FlimUnitsLike
1630+
The units to return the FLIM data in. Default is 'nanoseconds'.
16241631
16251632
# Returns
16261633
@@ -1689,7 +1696,7 @@ def sum_mask_flim(
16891696
)
16901697

16911698
if return_framewise:
1692-
return FlimTrace(
1699+
ft = FlimTrace(
16931700
summed_flim_data,
16941701
intensity = summed_intensity_data,
16951702
FLIMParams = params,
@@ -1698,7 +1705,10 @@ def sum_mask_flim(
16981705
units = FlimUnits.COUNTBINS,
16991706
)
17001707

1701-
return FlimTrace(
1708+
ft.convert_units(units)
1709+
return ft
1710+
1711+
ft = FlimTrace(
17021712
summed_flim_data,
17031713
intensity = summed_intensity_data,
17041714
FLIMParams = params,
@@ -1708,6 +1718,9 @@ def sum_mask_flim(
17081718
).reshape(
17091719
(-1, mask.shape[0] if mask.ndim > 2 else 1)
17101720
).sum(axis=1)
1721+
1722+
ft.convert_units(units)
1723+
return ft
17111724

17121725
def _sum_mask_flim_srm(
17131726
self,
@@ -1816,6 +1829,7 @@ def sum_masks_flim(
18161829
registration_dict : Optional[dict] = None,
18171830
return_framewise : bool = False,
18181831
flim_method : Union[str, FlimMethod] = FlimMethod.EMPIRICAL,
1832+
units : 'FlimUnitsLike' = 'nanoseconds',
18191833
)->FlimTrace:
18201834
"""
18211835
Computes the empirical lifetime within a set of ROIs over timesteps.
@@ -1852,6 +1866,9 @@ def sum_masks_flim(
18521866
* `flim_method` : Union[str, FlimMethod]
18531867
The method to use for the FLIM analysis. Default is 'empirical'.
18541868
Options are any of the `FlimMethod` enum values (`siffpy.siffmath.flim.FlimMethod`).
1869+
1870+
* `units` : FlimUnitsLike
1871+
The units to return the FLIM data in. Default is 'nanoseconds'.
18551872
18561873
# Returns
18571874
@@ -1930,7 +1947,7 @@ def sum_masks_flim(
19301947
)
19311948

19321949
if return_framewise:
1933-
return FlimTrace(
1950+
ft = FlimTrace(
19341951
flim_summed,
19351952
intensity = intensity_summed,
19361953
FLIMParams = params,
@@ -1939,9 +1956,12 @@ def sum_masks_flim(
19391956
units = FlimUnits.COUNTBINS,
19401957
)
19411958

1959+
ft.convert_units(units)
1960+
return ft
1961+
19421962
# Reshape AFTER making a `FlimTrace`
19431963
# or else things won't be added correctly.
1944-
return FlimTrace(
1964+
ft = FlimTrace(
19451965
flim_summed,
19461966
intensity = intensity_summed,
19471967
FLIMParams = params,
@@ -1952,8 +1972,9 @@ def sum_masks_flim(
19521972
(masks.shape[0], -1, masks.shape[1] if masks.ndim > 3 else 1)
19531973
).sum(axis=2)
19541974

1955-
raise NotImplementedError("Not yet implemented using corrosiff backend")
1956-
1975+
ft = ft.convert_units(units)
1976+
return ft
1977+
19571978
def _sum_masks_flim_srm(
19581979
self,
19591980
params : FLIMParams,

0 commit comments

Comments
 (0)