Flim

A collection of functions releavant to fluorescence lifetime imaging decay plotting and analysis.

Most used functions are the regionprops_omi and rectangular_to_phasor_point to compute g and s from a decay

Functions:

bin_image(image, bin_factor)

This function takes in an lifetime image and bins the decays of its histogram given a bin factor.

draw_universal_semicircle(...[, title, ...])

Draws the universal semicircle with the given frequency and returns the plt figure to draw over.

estimate_and_shift_irf(decay, irf_decay[, debug])

Estimates shift given a decay and an IRF.

ideal_sample_phasor(f, lifetime)

Generates a phasor for a specific lifetime at a given frequency.

lifetime_to_phasor(f, timebins, counts)

Time to frequency domain transformation

phasor_calculator(f, time, decays, IRF)

Given an array of decay(s) the rectangular g, s and phasors angle and magnitude will be computed and returned.

phasor_calibration(f, lifetime, timebins, counts)

Phasor Plot Calibration

phasor_to_rectangular(angle, magnitude)

Gets x and y position of phasor in rectangular coordinates

rectangular_to_phasor(g, s)

Takes an array(image) of g and s points and converts them to angle and magnitude phasor arrays

regionprops_omi(image_id, label_image[, ...])

Takes in labels image as well as nadh and fad images from SPCImage to return mean and stdev of each parameter per roi.

cell_analysis_tools.flim.bin_image(image, bin_factor)[source]

This function takes in an lifetime image and bins the decays of its histogram given a bin factor. A bin of 2 will reduce the size of the image by 2. It will do so by forming a kernel of bin_factor x bin_factor and sum of those decays into a resulting pixel

Parameters:
  • image (ndarray) – image to bin, must be a 3d array of shape (x,y,t)

  • bin_factor (int) – pixel radius(including diagonals) of bins to create. Must be EVEN.

Returns:

binned_image – new image with binned pixels

Return type:

ndarray

before and after binning function
cell_analysis_tools.flim.draw_universal_semicircle(laser_angular_frequency, title='Phasor Plot', suptitle='', debug=False)[source]

Draws the universal semicircle with the given frequency and returns the plt figure to draw over.

Parameters:
  • figure (matplotlib figure object) – figure object to draw semicircle over

  • laser_angular_frequency (int) – rep rate or laser angular frequency, affects position of labeled points

Return type:

plt.figure object to plot your points over this figure

Image of universal semicircle at 80Mhz'' Image of universal semicircle at 100Mhz''
cell_analysis_tools.flim.estimate_and_shift_irf(decay, irf_decay, debug=False)[source]

Estimates shift given a decay and an IRF.

Parameters:
  • decay (ndarray) – 1D array containing decay curve

  • irf_decay (ndarray) – 1D array containing IRF

  • debug (bool) – Optional flag to display intermediate calculations

Returns:

  • irf_decay_shifted (ndarray) – Shifted IRF as a 1d array

  • shift (int) – value IRF was shifted by

Note

IRF and decay should NOT have low SNR or gradient function will produce incorrect alignment

Image of the estimated placement of IRF for a decay
cell_analysis_tools.flim.ideal_sample_phasor(f, lifetime)[source]

Generates a phasor for a specific lifetime at a given frequency.

Parameters:
  • f (int) – laser rep rate

  • lifetime (float) – lifetime of desired single exponential sample

Returns:

  • angle (float) – angle of ideal sample

  • magnitude (float) – magnitude of ideal sample

>>print("Input is 80Mhz phasor at @ 2ns lifetime")
>>angle, magnitude = ideal_sample_phasor(f=80e6, lifetime=2e-9)
>>print(f"{angle=:.3f} rad | {magnitude=:.3f}")
angle=0.788 rad | magnitude=0.705
cell_analysis_tools.flim.lifetime_to_phasor(f, timebins, counts)[source]

Time to frequency domain transformation

Parameters:
  • f (int) – laser repetition angular frequency

  • timebins (ndarray) – numpy array of timebins

  • counts (ndarray) – photon counts of the histogram()

Returns:

  • angle (float) – angle in radians

  • magnitude (float) – magnitude of phasor

cell_analysis_tools.flim.phasor_calculator(f, time, decays, IRF)[source]

Given an array of decay(s) the rectangular g, s and phasors angle and magnitude will be computed and returned.

Parameters:
  • f (float) – Laser repetition rate.

  • time (np.ndarray) – array of timebins.

  • decays (np.ndarray) – Single decay or array of decays to compute phasor points for. Single decay should have the shape (x,),(x,t) and shape (x,y,t) for an array

  • IRF (np.ndarray) – 1D array capturing irf decay.

Returns:

  • m (float) – magnidue of phasor.

  • phi (float) – angle of phasor.

  • g (float) – g coordinate (x-axis).

  • s (float) – s coordinate (y-axis).

Note

  • You cannot compare two images directly due to them having different decay shift values between images, affeting g,s,m and phi locations

  • For proper lifetime values, background subtraction is needed by taking ~ the last 1 or 1/2 ns timebins of decay)

Image of a lifetime image as a phasor plot
cell_analysis_tools.flim.phasor_calibration(f, lifetime, timebins, counts)[source]

Phasor Plot Calibration

Parameters:
  • f (int) – laser repetition angular frequency

  • lifetime (int) – lifetime of known sample in ns (single exponential decay)

  • timebins (int) – timebins of samples

  • counts (int) – photon counts of histogram

Returns:

  • angle_offset {float} (difference in angle between known sample and actual)

  • magnitude_offset {float} (difference in magnitude between known sample and actual)

Note

If no timebins or histograms passed then returns angle and phase of decay passed in.

cell_analysis_tools.flim.phasor_to_rectangular(angle, magnitude)[source]

Gets x and y position of phasor in rectangular coordinates

Parameters:
  • angle (float) – phasor angle in radians

  • magnitude (float) – phasor magnitude

Returns:

  • g (float) – x axis coordinate

  • s (float) – y axis coordinate

cell_analysis_tools.flim.rectangular_to_phasor(g, s)[source]

Takes an array(image) of g and s points and converts them to angle and magnitude phasor arrays

Parameters:
  • g (float) – array of g coordinates (x-coordinates)

  • s (float) – array of s coordinates (y-coordinates)

Returns:

PhasorArray object – lifetime_angles_array - array of angles for each pixel lifetime_magnitudes_array - array of magnitudes for each pixel

Return type:

float

cell_analysis_tools.flim.regionprops_omi(image_id: str, label_image: ndarray, im_nadh_intensity: ndarray | None = None, im_nadh_a1: ndarray | None = None, im_nadh_a2: ndarray | None = None, im_nadh_t1: ndarray | None = None, im_nadh_t2: ndarray | None = None, im_fad_intensity: ndarray | None = None, im_fad_a1: ndarray | None = None, im_fad_a2: ndarray | None = None, im_fad_t1: ndarray | None = None, im_fad_t2: ndarray | None = None, im_nadh_chi: ndarray | None = None, im_fad_chi: ndarray | None = None, other_props: list | None = None) dict[source]

Takes in labels image as well as nadh and fad images from SPCImage to return mean and stdev of each parameter per roi.

Parameters:
  • label_image (ndarray) – labeled mask image.

  • im_nadh_intensity (ndarray) – nadh intensity image.

  • im_nadh_a1 (ndarray) – nadh alpha1 image.

  • im_nadh_a2 (ndarray) – nadh alpha2 image .

  • im_nadh_t1 (ndarray) – nadh tau 1 lifetime, short .

  • im_nadh_t2 (ndarray) – nadh tau 2 lifetime, long.

  • im_fad_intensity (ndarray) – nadh intensity image.

  • im_fad_a1 (ndarray) – fad alpha 1 image.

  • im_fad_a2 (ndarray) – fad alpha 2 image.

  • im_fad_t1 (ndarray) – fad tau 1 lifetime, long.

  • im_fad_t2 (ndarray) – fad tau 2 lifetime, short.

  • other_props (list) – string list of additional parameters to compute on the binary mask see skimage regionprops for list of attributes

Note

See https://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.regionprops for a list of additiona properties you can compute

Returns:

dictionary of mean and standard deviations of omi parameters for each region.

Return type:

dict