@@ -192,10 +192,12 @@ def open(
192192 self ._time_axis_epoch = None
193193
194194 #self.events = io.find_events(self.im_params, self.get_frames_metadata())
195- flim_params = io .load_flim_params (filename )
196- if any (flim_params ):
197- self ._flim_params = flim_params
198- #print("Finished opening and reading file")
195+ try :
196+ flim_params = io .load_flim_params (filename )
197+ if any (flim_params ):
198+ self ._flim_params = flim_params
199+ except Exception as e :
200+ print (f"Failed to load FLIM parameters with error: { e } " )
199201
200202 def close (self ) -> None :
201203 """ Closes opened file """
@@ -518,16 +520,16 @@ def sec_to_frames(self, seconds : float, base : str = 'volume')->int:
518520
519521 # Arguments
520522
521- * seconds : float
522- Time in seconds to convert
523+ * ` seconds` : * float*
524+ * Time in seconds to convert
523525
524- * base : str
525- Base to convert to. Can be 'volume' or 'frame'. Defaults to 'volume'.
526+ * ` base` : * str*
527+ * Base to convert to. Can be 'volume' or 'frame'. Defaults to 'volume'.
526528
527529 # Returns
528530
529- * frames : int
530- Number of frames that time represents.
531+ * ` frames` : * int*
532+ * Number of frames that time represents.
531533
532534 # Example
533535
@@ -544,7 +546,7 @@ def sec_to_frames(self, seconds : float, base : str = 'volume')->int:
544546 >> 10
545547 ```
546548 """
547-
549+ base = base . lower ()
548550 if base == 'volume' :
549551 return int (seconds / self .dt_volume )
550552 if base == 'frame' :
@@ -558,6 +560,20 @@ def get_frames_metadata(self, frames : Optional[List[int]] = None) -> List[io.Fr
558560 return [io .FrameMetaData (meta_dict )
559561 for meta_dict in io .frame_metadata_to_dict (self .siffio .get_frame_metadata (frames = frames ))
560562 ]
563+
564+ def epoch_time_to_volume_index (self , epoch_time : int ) -> int :
565+ """
566+ Returns the index of the volume containing the epoch time provided.
567+ """
568+ return np .searchsorted (self .t_axis (reference_time = 'epoch' ), epoch_time )
569+
570+ def epoch_time_to_frame_index (self , epoch_time : int , correct_flyback : bool = False ) -> int :
571+ """
572+ Returns the index of the frame containing the epoch time provided. Note:
573+ by default frames are numbered by _frame triggers_,
574+ meaning they include flyback frames in their indexing!
575+ """
576+ return np .searchsorted (self .get_time (reference_time = 'epoch' ), epoch_time )
561577
562578 def epoch_to_frame_time (self , epoch_time : int ) -> float :
563579 """ Converts epoch time to frame time for this experiment (returned in seconds) """
@@ -1326,11 +1342,6 @@ def get_frames_flim(
13261342
13271343 method = FlimMethod (method )
13281344
1329- if method != FlimMethod .EMPIRICAL :
1330- raise NotImplementedError (
1331- "Only empirical lifetime method is implemented in `siffio` backend so far"
1332- )
1333-
13341345 registration_dict = self .registration_dict if (
13351346 registration_dict is None
13361347 and hasattr (self , 'registration_dict' )
@@ -1354,8 +1365,6 @@ def get_frames_flim(
13541365 method = method .value ,
13551366 units = 'countbins' ,
13561367 )
1357-
1358-
13591368
13601369 def _get_frames_flim_srm (
13611370 self ,
@@ -1382,10 +1391,6 @@ def _get_frames_flim_srm(
13821391 frames = list (range (self .im_params .num_frames ))
13831392
13841393 method = FlimMethod (method )
1385- if method != FlimMethod .EMPIRICAL :
1386- raise NotImplementedError (
1387- "Only empirical lifetime method is implemented in `SiffIO` backend so far"
1388- )
13891394
13901395 registration_dict = self .registration_dict if (
13911396 registration_dict is None
@@ -1471,6 +1476,10 @@ def sum_mask_flim(
14711476 * `return_framewise` : bool
14721477 If True, does not sum across timepoints, and returns a flat array
14731478 corresponding to the frames.
1479+
1480+ * `flim_method` : Union[str, FlimMethod]
1481+ The method to use for the FLIM analysis. Default is 'empirical'.
1482+ Options are any of the `FlimMethod` enum values (`siffpy.siffmath.flim.FlimMethod`).
14741483
14751484 # Returns
14761485
@@ -1501,10 +1510,6 @@ def sum_mask_flim(
15011510 )
15021511
15031512 flim_method = FlimMethod (flim_method )
1504- if flim_method != FlimMethod .EMPIRICAL :
1505- raise NotImplementedError (
1506- "Only empirical lifetime method is implemented in `siffio` backend so far"
1507- )
15081513
15091514 timepoint_end = (
15101515 self .im_params .num_timepoints
@@ -1545,7 +1550,7 @@ def sum_mask_flim(
15451550 summed_flim_data ,
15461551 intensity = summed_intensity_data ,
15471552 FLIMParams = params ,
1548- method = 'empirical lifetime' ,
1553+ method = flim_method . value ,
15491554 info_string = "ROI" ,
15501555 units = FlimUnits .COUNTBINS ,
15511556 )
@@ -1554,7 +1559,7 @@ def sum_mask_flim(
15541559 summed_flim_data ,
15551560 intensity = summed_intensity_data ,
15561561 FLIMParams = params ,
1557- method = 'empirical lifetime' ,
1562+ method = flim_method . value ,
15581563 info_string = "ROI" ,
15591564 units = FlimUnits .COUNTBINS ,
15601565 ).reshape (
@@ -1701,6 +1706,25 @@ def sum_masks_flim(
17011706 If True, returns a flat array of all frames, rather than summing across
17021707 timepoints.
17031708
1709+ * `flim_method` : Union[str, FlimMethod]
1710+ The method to use for the FLIM analysis. Default is 'empirical'.
1711+ Options are any of the `FlimMethod` enum values (`siffpy.siffmath.flim.FlimMethod`).
1712+
1713+ # Returns
1714+
1715+ * FlimTrace
1716+ TODO :DOCUMENT
1717+
1718+ # Example
1719+
1720+ TODO
1721+ ```python
1722+
1723+ from siffpy import SiffReader
1724+ reader = SiffReader('example.siff')
1725+
1726+ ```
1727+
17041728 """
17051729 if self .backend == 'siffreadermodule' :
17061730 return self ._sum_masks_flim_srm (
@@ -1715,10 +1739,10 @@ def sum_masks_flim(
17151739 )
17161740
17171741 flim_method = FlimMethod (flim_method )
1718- if flim_method != FlimMethod .EMPIRICAL :
1719- raise NotImplementedError (
1720- "Only empirical lifetime method is implemented in `siffio` backend so far"
1721- )
1742+ # if flim_method != FlimMethod.EMPIRICAL:
1743+ # raise NotImplementedError(
1744+ # "Only empirical lifetime method is implemented in `siffio` backend so far"
1745+ # )
17221746
17231747 if isinstance (masks , list ):
17241748 masks = np .array (masks ).squeeze ()
@@ -1765,7 +1789,7 @@ def sum_masks_flim(
17651789 flim_summed ,
17661790 intensity = intensity_summed ,
17671791 FLIMParams = params ,
1768- method = 'empirical lifetime' ,
1792+ method = flim_method . value ,
17691793 info_string = "Multi-ROIs" ,
17701794 units = FlimUnits .COUNTBINS ,
17711795 )
@@ -1776,7 +1800,7 @@ def sum_masks_flim(
17761800 flim_summed ,
17771801 intensity = intensity_summed ,
17781802 FLIMParams = params ,
1779- method = 'empirical lifetime' ,
1803+ method = flim_method . value ,
17801804 info_string = "Multi-ROIs" ,
17811805 units = FlimUnits .COUNTBINS ,
17821806 ).reshape (
@@ -1985,4 +2009,6 @@ def _rinfo_safe_convert(registration_info : Union[RegistrationInfo, Dict]) -> Di
19852009 if isinstance (registration_info , RegistrationInfo ):
19862010 return registration_info .yx_shifts
19872011 if isinstance (registration_info , dict ) and 'yx_shifts' in registration_info :
1988- return registration_info ['yx_shifts' ]
2012+ return registration_info ['yx_shifts' ]
2013+ if isinstance (registration_info , dict ):
2014+ return registration_info
0 commit comments