Traces API
This section contains code for the various Trace type Python objects
used to make handling these types of data simpler, especially the FLIMTrace
- class siffpy.siffmath.fluorescence.traces.FluorescenceTrace(input_array: FluorescenceArrayLike, method: str = None, normalized: bool = False, F: ndarray | None = None, F0: ndarray | None = None, max_val: ndarray | None = inf, min_val: ndarray | None = array(0.), angle: ndarray | None = None, info_string: str | None = None)
Extends the numpy array to provide extra attributes that might be useful for parsing the trace data. Behaves like a normal numpy array. Modeled after the RealisticInfoArray example provided at https://numpy.org/doc/stable/user/basics.subclassing.html#simple-example-adding-an-extra-attribute-to-ndarray
- FluorescenceTrace(
input_array, method : str = None, normalized : bool = False, F : np.ndarray = None, F0 : np.ndarray = np.ndarray(None), #time_axis : np.ndarray = np.ndarray(None), max_val : np.ndarray = np.inf, min_val : np.ndarray = 0.0, angle : float = None, info_string : str = None
)
- classmethod load(path: PathLike) FluorescenceTrace
Load a .flim_hdf file and create a FlimArray class from it.
- class siffpy.siffmath.fluorescence.traces.FluorescenceVector(input_array: FluorescenceVectorLike)
Constructed if a FluorescenceTrace is made out of an iterable of FluorescenceTraces.
A special type of FluorescenceTrace that keeps track of the fact that each of its major dimension is supposed to be its own FluorescenceTrace object.
- class siffpy.siffmath.flim.traces.FlimTrace(input_array: FlimArrayLike, intensity: FluorescenceArrayLike | None = None, confidence: ndarray | None = None, FLIMParams: FLIMParams | None = None, method: str | FlimMethod | None = None, angle: float | None = None, units: FlimUnitsLike = FlimUnits.UNKNOWN, nocast: bool = False, max_arrival_time: int | None = None, info_string: str = '')
Subclasses numpy arrays and adds extra attributes that might be useful for FLIM timeseries and tracking the relationship between the lifetime and intensity measures. Useful to avoid sacrificing the benefits of numpy while still treating FLIM data appropriately. Raw lifetime data can be accessed with the property “lifetime” to avoid all of the actual FLIM-like math assurances. Fluorescence data can be returned as a FluorescenceTrace with the property fluorescence.
Most numpy functions will actually operate on the INTENSITY array, altering the FlimTrace core array only if those operations make sense.
The intensity data _will_ be cast to an array of FLOATS to make computation much faster. If you do not want to cast to floats, use the nocast kwarg in the constructor.
Modeled after the RealisticInfoArray example provided at https://numpy.org/doc/stable/user/basics.subclassing.html#simple-example-adding-an-extra-attribute-to-ndarray
- convert_method(to: FlimMethod, flim_params: FLIMParams | None = None)
Converts between a phasor and a empirical lifetime trace using the provided FLIMParams object. If the FLIMParams object is not provided, the FLIMParams attribute of the FlimTrace is used.
If the method is already the same as the method provided, this function does nothing.
## Example
```python from siffpy import default_flim_params # Convert a phasor trace to an empirical lifetime trace empirical_trace = phasor_trace.convert_method(
‘empirical lifetime’, flim_params = default_flimparams()
)
- convert_units(units: FlimUnitsLike)
Converts units in place
- classmethod excludes_func(*np_functions)
Excludes a function from being used on a FlimTrace object
- classmethod excludes_ufunc(np_ufunction, method)
Excludes a ufunction from being used on a FlimTrace object
- property fluorescence: FluorescenceTrace
Returns the intensity array of a FlimTrace as a FluorescenceTrace
- classmethod implements_func(*np_functions)
Register an __array_function__ implementation for FlimTrace objects.
- classmethod implements_ufunc(np_ufunction, method)
Register an __array_ufunction__ implementation for FlimTrace objects.
- property lifetime: ndarray
Returns a pointer to the FLIM data of a FlimArray as a regular numpy array. I think this might be dangerous but… leaving it as a copy means all the ‘intuitive’ code one might write becomes very slow because it makes copy after copy after copy…
- classmethod load(path: PathLike) FlimTrace
Load a .flim_hdf file and create a FlimArray class from it.
- mean(axis=None, dtype=None, out=None, keepdims=False, *, where=True)
Returns the average of the array elements along given axis.
Refer to numpy.mean for full documentation.
See Also
numpy.mean : equivalent function
- ravel([order])
Return a flattened array.
Refer to numpy.ravel for full documentation.
See Also
numpy.ravel : equivalent function
ndarray.flat : a flat iterator on the array.
- reshape(shape, /, *, order='C')
Returns an array containing the same data with a new shape.
Refer to numpy.reshape for full documentation.
See Also
numpy.reshape : equivalent function
Notes
Unlike the free function numpy.reshape, this method on ndarray allows the elements of the shape parameter to be passed in as separate arguments. For example,
a.reshape(10, 11)is equivalent toa.reshape((10, 11)).
- set_units(units: FlimUnitsLike)
Allows setting of units even if the units are unknown. Basically a forced version of convert_units
- sort(*args, sortby='flim', **kwargs)
Sortby argument must be either ‘flim’ or ‘intensity’
- squeeze(axis=None)
Remove axes of length one from a.
Refer to numpy.squeeze for full documentation.
See Also
numpy.squeeze : equivalent function
- subtract_noise(max_arrival_time: float, units: FlimUnitsLike | None = None, n_photons: int | None | ndarray = None, rotate_by_offset: bool = False)
Either subtracts the noise from the FLIMParams fit or subtracts an external value of photons from the intensity and lifetime data (determined by the n_photons parameter).
Mode 1: n_photons is None:
If the current FLIMParams attribute has a noise parameter that may be influencing the lifetime value, this subtracts out the estimated noise from each array entry by presuming the noise value corresponds to that fraction of photons originated from a source of uniformly distributed arrival times.
If self.`FLIMParams` is None and n_photons is None, this function does nothing. Otherwise, it modifies the `intensity and lifetime attributes in place then adjusts the noise value of the current FLIMParams attribute to 0. Because this _mutates_ the FLIMParams object, this makes a copy so that it does not affect other arrays pointing to the same object.
The subtraction does the following:
intensity : Multiplies by (1-noise) if n_photons is None.
lifetime : Subtracts max_arrival_time/2 * noise
Mode 2: n_photons is not None:
Subtracts a fixed number of photons from the intensity and lifetime data (this can either be an array of the same shape as the current array, or a single integer for all time points). This is useful for subtracting a time-varying background signal (e.g. projector noise that turns on mid-experiment) from the data.
## Arguments
max_arrival_time : float
In the same units as the current lifetime if units is None
units : FlimUnitsLike | None
Specifies the units of max_arrival_time. If None, they are presumed to be the same as the FlimTrace.
- sum(axis=None, dtype=None, out=None, keepdims=False, initial=0, where=True)
Return the sum of the array elements over the given axis.
Refer to numpy.sum for full documentation.
See Also
numpy.sum : equivalent function
- to_alpha(threshold: int, scale: float) ndarray
Returns an array that can be used an as alpha channel for imshow (i.e. 0 to 1 scaled by intensity of the array). Operation is (intensity - threshold) * scale, clipped to 0 and 1.
- transpose(*axes)
Returns a view of the array with axes transposed.
Refer to numpy.transpose for full documentation.
Parameters
axes : None, tuple of ints, or n ints
None or no argument: reverses the order of the axes.
tuple of ints: i in the j-th place in the tuple means that the array’s i-th axis becomes the transposed array’s j-th axis.
n ints: same as an n-tuple of the same ints (this form is intended simply as a “convenience” alternative to the tuple form).
Returns
- pndarray
View of the array with its axes suitably permuted.
See Also
transpose : Equivalent function. ndarray.T : Array property returning the array transposed. ndarray.reshape : Give a new shape to an array without changing its data.
Examples
>>> a = np.array([[1, 2], [3, 4]]) >>> a array([[1, 2], [3, 4]]) >>> a.transpose() array([[1, 3], [2, 4]]) >>> a.transpose((1, 0)) array([[1, 3], [2, 4]]) >>> a.transpose(1, 0) array([[1, 3], [2, 4]])
>>> a = np.array([1, 2, 3, 4]) >>> a array([1, 2, 3, 4]) >>> a.transpose() array([1, 2, 3, 4])