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 | None = None, angle: float | None = None, units: FlimUnitsLike = FlimUnits.UNKNOWN, nocast: bool = False, 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_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 to a.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

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])