photonscore.flim

photonscore.flim

flim.convolve

Convolution of an instrument-response function with a multi-exponential decay.

convolve

def convolve(
    irf: np.ndarray,
    irf_shift: float,
    tau: float | np.ndarray,
    tau_ref: float | None = None,
    channels: int | None = None,
) -> np.ndarray

Convolve irf with one or more exponential decays.

Arguments

  • irf (np.ndarray): Instrument-response function as a 1-D NumPy array.
  • irf_shift (float): Sub-channel shift applied to the IRF before convolution.
  • tau (float | np.ndarray): Exponential decay constant(s). Scalar or sequence — when a sequence is passed, the result is one decay per element.
  • tau_ref (float | None): Optional reference / IRF lifetime to deconvolve from tau (set to None or 0 to skip).
  • channels (int | None): Length of the output. Defaults to len(irf).

Returns: np.ndarray NumPy array of the convolved decay(s).

flim.exp_tail

exp_tail

def exp_tail(tau, channels)

flim.gaussian_decay

Synthetic Gaussian-IRF / single-exponential decay generator.

gaussian_decay

def gaussian_decay(
    mu: float,
    fwhm: float,
    tau: float,
    channels: int = 1000,
) -> np.ndarray

Generate the decay produced by convolving a Gaussian IRF with a single exponential.

Arguments

  • mu (float): Centre of the Gaussian instrument response, in channels.
  • fwhm (float): Full-width at half-maximum of the IRF, in channels.
  • tau (float): Exponential decay constant, in channels.
  • channels (int): Length of the output array.

Returns: np.ndarray NumPy array of length channels — the unit-normalised decay.

flim.gaussian_irf

Synthetic Gaussian instrument-response function.

gaussian_irf

def gaussian_irf(
    mu: float,
    fwhm: float,
    channels: int = 1000,
) -> np.ndarray

Generate a unit-area Gaussian IRF.

Arguments

  • mu (float): Centre of the Gaussian, in channels.
  • fwhm (float): Full-width at half-maximum, in channels.
  • channels (int): Length of the output array.

Returns: np.ndarray NumPy array of length channels.

flim.info

Summary statistics of a Photonscore data file (.photons / D7).

Info

class Info(filename, duration, total_counts)

Lightweight description of a Photonscore data file.

Attributes

  • filename: Path to the file.
  • duration: Acquisition duration in seconds.
  • total_counts: Total number of photons recorded.

info

def info(path)

Open path and return an Info summary.

Reads the photon coordinate streams to find the total count and the millisecond marker stream to derive the duration.

flim.read

ReadData

class ReadData(x, y, dt)

intensity

def intensity(pixels = 512)

decay

def decay()

sort

def sort(pixels = 512)

total_counts

property

total_counts

read

def read(path, seconds = None, events = None)

flim.sort

Sort photons into a 2-D image of decay histograms.

Each pixel of the resulting image holds a delta-t histogram of the photons that fell into it. From this SortResult you can derive an intensity image (SortResult.intensity) and per-pixel arrival-time statistics (SortResult.mean, SortResult.median).

SortResult

class SortResult(counts: np.ndarray, dt: np.ndarray)

Per-pixel decay histograms returned by sort.

Attributes

  • counts: 3-D NumPy array of shape (x_bins, y_bins, dt_bins).
  • dt: Bin edges of the delta-t axis (NumPy 1-D array).

mean

def mean(dt_range: tuple[int, int] | None = None) -> np.ndarray

Per-pixel mean arrival time within dt_range (default: full range).

median

def median(dt_range: tuple[int, int] | None = None) -> np.ndarray

Per-pixel median arrival time within dt_range.

intensity

def intensity(dt_range: tuple[int, int] | None = None) -> np.ndarray

Per-pixel photon count within dt_range.

sort

def sort(
    x: np.ndarray,
    x_min: float,
    x_max: float,
    x_bins: int,
    y: np.ndarray,
    *args: object,
) -> SortResult

Sort photons into a 2-D grid of decay histograms.

Two calling conventions are supported:

  • sort(x, x_min, x_max, x_bins, y, dt) — uses the same range and bin count for the y-axis as for the x-axis.
  • sort(x, x_min, x_max, x_bins, y, y_min, y_max, y_bins, dt) — explicit y-axis range and bin count.

Arguments

  • x (np.ndarray): Per-photon x-coordinates.
  • x_min (float): Lower bound of the x-axis.
  • x_max (float): Upper bound of the x-axis.
  • x_bins (int): Number of x-axis bins.
  • y (np.ndarray): Per-photon y-coordinates.
  • *args (object): (dt,) or (y_min, y_max, y_bins, dt).

Returns: SortResult class:SortResult — wraps the per-pixel decay histograms.

flim.iwtau

Intensity-weighted lifetime (iwtau) colourisation.

Maps a pair of (count, lifetime) images into RGB colours through a pre-computed palette. Used to render FLIM previews where the hue encodes lifetime and the brightness encodes photon count.

iwtau_tau_range

def iwtau_tau_range(tau: np.ndarray) -> list[float]

Suggest a reasonable lifetime range for iwtau from a tau image.

Returns the 10th- and 90th-percentile of strictly positive entries in tau — these values usually correspond to the bulk of the lifetime distribution and produce a stable colour mapping.

iwtau_n_range

def iwtau_n_range(n: np.ndarray) -> list[float]

Suggest an intensity range from a count image.

Lower bound is 0, upper bound is 0.9 * max(n).

iwtau

def iwtau(
    n: np.ndarray,
    tau: np.ndarray,
    pal: np.ndarray,
    n_range: list[float] | None = None,
    tau_range: list[float] | None = None,
) -> np.ndarray

Render an intensity-weighted lifetime RGB image.

Arguments

  • n (np.ndarray): Count image (2-D NumPy array).
  • tau (np.ndarray): Lifetime image, same shape as n.
  • pal (np.ndarray): Palette of shape (n_bins, tau_bins, 3) — RGB lookup indexed by clipped count and lifetime.
  • n_range (list[float] | None): Clip range for n. Defaults to iwtau_n_range(n).
  • tau_range (list[float] | None): Clip range for tau. Defaults to iwtau_tau_range(tau).

Returns: np.ndarray RGB image of shape (*n.shape, 3).