smsh5
Module for handling SMS data from HDF5 files
Bertus van Heerden and Joshua Botha University of Pretoria 2018
Module Contents
Classes
Represents an entire HDF5 dataset |
|
Represents a particle in an H5dataset. |
|
Fake ChangePoints object for GlobalParticle. |
|
Particle-like object containing levels from all particles. |
|
Binned intensity trace. |
|
TCSPC histogram. |
|
Class containing all Histograms from Particle. |
|
Class containing raster scan data. |
|
Class containing spectral data. |
Attributes
- class smsh5.H5dataset(filename, sig_fb: processes.PassSigFeedback = None, prog_fb: processes.ProcessProgFeedback = None)[source]
Represents an entire HDF5 dataset
- Parameters:
filename (str) – HDF5 file path
sig_fb (PassSigFeedback, optional) – feedback queue for signals
prog_fb (ProcessProgFeedback, optional) – feedback queue for updating progress bar
- unload_file(should_close: bool = True, should_delete: bool = True)[source]
Remove file reference and close and/or delete the file.
- get_all_raster_scans(particle_names: List[str]) list[source]
Get all the raster scans from the file and handle appropriately.
Each raster scan has one or more particles associated with it. In the HDF5 file, this is manifested as having the same raster scan duplicated across particle objects. This function reads out all unique raster scans and assigns them each their particles. The return value is a map from particle numbers to ‘raster scan numbers - if there’s a raster scan for particles 1 and 2 and another one for particles 3-5, the map would be: [1, 1, 2, 2, 2]
- Parameters:
particle_names (list[str]) – list of particle names to read raster scan data from
- Returns:
map_particle_index – maps particle numbers to raster scan numbers.
- Return type:
list or None
- makehistograms(remove_zeros=True, startpoint=None, channel=True)[source]
Put the (micro) arrival times into histograms.
- bin_all_ints(binsize: float, sig_fb: processes.PassSigFeedback = None, prog_fb: processes.ProcessProgFeedback = None)[source]
Bin the absolute times into intensity traces.
- Parameters:
binsize (float) – Time bin size in ms
sig_fb (PassSigFeedback, optional) – feedback queue for signals
prog_fb (ProcessProgFeedback, optional) – feedback queue for updating progress bar
- class smsh5.Particle(name: str, dataset_ind: int, dataset: H5dataset, raster_scan_dataset_index: int = None, raster_scan: RasterScan = None, is_secondary_part: bool = False, prim_part: Particle = None, sec_part: Particle = None, tmin=None, tmax=None, channelwidth=None, is_global: bool = False)[source]
Represents a particle in an H5dataset.
- Parameters:
name (str) – The name of the particle
dataset_ind (H5dataset) – The index of the particle in the dataset
dataset (H5dataset) – The instance of the dataset to which this particle belongs
raster_scan_dataset_index (int) – The index of the raster scan connected to the particle
raster_scan (RasterScan) – The raster scan object this particle is connected to
is_secondary_part (bool) – Whether this is a “secondary particle” that contains the data from a second TCSCPC card
prim_part (Particle) – If this particle is a secondary particle, the corresponding primary particle
sec_part (Particle) – If this particle is a primary particle, the corresponding secondary particle
tmin (int, optional) – Minimum photon micro time in ns
tmax (int, optional) – Maximum photon micro time in ns
channelwidth (float, optional) – TCSPC histogram channelwidth in ns. Normally automatically determined.
is_global (bool = False) – TODO: What is this?
- property first_group_level_ind_in_roi[source]
Index of the first grouped level in the particle’s ROI.
- property last_group_level_ind_in_roi[source]
Index of the last grouped level in the particle’s ROI.
- property groups: List[grouping.Group][source]
The particle’s grouped levels.
- property group_levels: List[change_point.Level | grouping.GlobalLevel][source]
The particle’s grouped levels.
- property group_levels_roi: List[change_point.Level][source]
The particle’s grouped levels, from ROI.
- property global_particle: GlobalParticle[source]
The H5dataset’s global particle.
- levels2data(use_grouped: bool = None, use_roi: bool = False, use_global_groups: bool = False) Tuple[numpy.ndarray, numpy.ndarray][source]
Level plotting data.
Uses the Particle objects’ levels to generate two arrays for plotting the levels.
- Parameters:
use_grouped (bool, optional) – Whether to use grouped levels - if not provided, defaults to True if groups exist and false if they don’t.
use_global_groups (bool = False) – whether to use globally grouped levels
use_roi (bool = False) – whether to use ROI
- Returns:
ints, times – Intensities as a function of time for plotting.
- Return type:
Tuple[np.ndarray, np.ndarray]
- lifetimes2data(use_grouped: bool = None, use_roi: bool = False) Tuple[numpy.ndarray, numpy.ndarray][source]
Level lifetime plotting data.
Uses the Particle object’s levels to generate two arrays for plotting the level lifetimes.
- Parameters:
use_grouped (bool, optional) – Whether to use grouped levels - if not provided, defaults to True if groups exist and false if they don’t.
use_roi (bool = False) – Whether to use ROI.
- Returns:
lifetimes, times – Lifetime as a function of time for plotting.
- Return type:
Tuple[np.ndarray, np.ndarray]
- current2data(level_ind: int, use_roi: bool = False) Tuple[numpy.ndarray, numpy.ndarray][source]
Current level plotting data.
Uses the Particle object’s selected level to generate two arrays for plotting level.
- Parameters:
level_ind (int) – Index of the level to be plotted.
use_roi (bool = False) – Whether to use the ROI.
- Returns:
levels_data, times – Intensity as a function of time for plotting.
- Return type:
Tuple[np.ndarray, np.ndarray]
- current_group2data(group_ind: int) [numpy.ndarray, numpy.ndarray][source]
Current group plotting data.
Uses the Particle object’s selected group to generate two arrays for plotting the group.
- Parameters:
group_ind (int) – Index of the level to be plotted.
- Returns:
group_int, times – Intensity as a function of time for plotting.
- Return type:
Tuple[np.ndarray, np.ndarray]
- makehistograms(remove_zeros, startpoint, channel)[source]
Make all histograms - whole trace and levels.
- Parameters:
remove_zeros (bool) – Whether to remove zeros at the start of the decay.
startpoint (int) – Startpoint of the decay in number of time steps.
channel (bool) – Whether to use the hardware channelwidth TODO: remove this parameter including downstream as it is never used
- makehistogram(channel=True, add_roi: bool = False)[source]
Put the arrival times into a histogram.
- Parameters:
channel (bool = True) – Whether to use the hardware channelwidth.
add_roi (bool = True) – Whether to create the ROI Histogram as well.
- makelevelhists(channel: bool = True, force_cpts_levels: bool = False, force_group_levels: bool = False)[source]
Make level histograms.
- Parameters:
channel (bool = True) – Whether to use the hardware channelwidth.
force_cpts_levels (bool = False) – Use self.cpts.levels instead of self.levels.
force_group_levels (bool = False) – Use self.group_levels instead of self.levels.
- binints(binsize: int)[source]
Bin the absolute times into intensity trace.
- Parameters:
binsize (int) – Size of intensity trace time bins.
- trim_trace(min_level_dwell_time: float, min_level_int: int, reset_roi: bool = True)[source]
Trim the intensity trace.
This function trims the intensity trace to remove the photobleached end.
- Parameters:
min_level_dwell_time (float) – Minimum dwell time of bleached level for trimming.
min_level_int (int) – Minimum intensity to classify level as not bleached.
reset_roi (bool = True) – Whether to update the ROI to the trimmed area.
- class smsh5.FakeCpts(num_levels: int, levels: list)[source]
Fake ChangePoints object for GlobalParticle.
- Parameters:
num_levels (int) – number of intensity levels
levels (List[GlobalLevel]) – list of global levels
- class smsh5.GlobalParticle(particles: List[Particle], use_roi: bool = False)[source]
Particle-like object containing levels from all particles.
- Parameters:
particles (List[Particle]) – Particles to include in global particle.
use_roi (bool = False) – Whether to use ROI’s.
- class smsh5.Trace(particle: Particle, binsize: int)[source]
Binned intensity trace.
- Parameters:
particle (Particle) – The Particle which creates the Trace.
binsize (int) – Size of time bin in ms.
- class smsh5.Histogram(particle: Particle, level: change_point.Level | List[int] = None, start_point: float = None, channel: bool = True, trim_start: bool = False, is_for_roi: bool = False)[source]
TCSPC histogram.
This class represents histogrammed TCSPC arrival times (micro times) as well as multi-exponential fits thereof.
- Parameters:
particle (Particle) – The parent Particle of this object.
level (Level or List = None) – The possible parent level of this object.
start_point (float = None) – Start point for lifetime fit.
channel (bool = True) – Whether to use hardware channel width.
trim_start (bool = False) – Whether to trim zeros at the start of the histogram.
is_for_roi (bool = False) – Whether this histogram is from a trace ROI.
- setup(level: change_point.Level | List[int] = None, start_point: float = None, channel: bool = True, trim_start: bool = False, use_roi: bool = False)[source]
Set up the object.
This method can be called to re-do setup steps without reinitializing.
- Parameters:
level (Level or List = None) – The possible parent level of this object.
start_point (float = None) – Start point for lifetime fit.
channel (bool = True) – Whether to use hardware channel width.
trim_start (bool = False) – Whether to trim zeros at the start of the histogram.
use_roi (bool = False) – Whether this histogram is from a trace ROI.
- fit(numexp, tauparam, ampparam, shift, decaybg, irfbg, boundaries, addopt, irf, fwhm=None, normalize_amps=True, maximum_likelihood=False)[source]
Fit a multiexponential decay to the histogram.
This function mainly calls the relevant code from tcspcfit.
- Parameters:
numexp (int) – Number of exponentials in fit function (1-3).
tauparam (array_like) – Initial guess times (in ns). This is either in the format [tau1, tau2, …] or [[tau1, min1, max1, fix1], [tau2, …], …]. When the “fix” value is False, the min and max values are ignored.
ampparam (array_like) – Initial guess amplitude. Format [amp1, amp2, …] or [[amp1, fix1], [amp2, fix2], …]
shift (array_like) – Initial guess IRF shift. Either a float, or [shift, min, max, fix].
decaybg (float) – Background value for decay. Will be estimated if not given.
irfbg (float) – Background value for IRF. Will be estimated if not given.
boundaries (list) – Start and end of fitting range as well as options for automatic determination of the parameters as used by FluoFit.calculate_boundaries.
irf (ndarray) – Instrumental Response Function
fwhm (float = None) – Full-width at half maximum of simulated irf. IRF is not simulated if fwhm is None.
addopt (Dict = None) – Additional options for scipy.optimize.curve_fit (such as optimization parameters).
normalize_amps (bool = True) – Whether to use normalized lifetime amplitudes.
maximum_likelihood (bool = False) – Whether to use maximum likelihood fitting (otherwise use least squares).
- class smsh5.ParticleAllHists(particle: Particle)[source]
Class containing all Histograms from Particle.
- Parameters:
particle (Particle) – The parent particle of this object.
- fit_part_and_levels(channelwidth, start, end, fit_param: tcspcfit.FittingParameters)[source]
Fit all Histograms in this object.
- Parameters:
channelwidth (float) – TCSPC channelwidth (time step size) in ns.
start (int) – Fitting startpoint in number of time steps.
end (int) – Fitting endpoint in number of time steps.
fit_param (FittingParameters) – Object containing fit parameters.
- class smsh5.RasterScan(h5dataset: H5dataset, particle_num: int, h5dataset_index: int, particle_indexes: List[int])[source]
Class containing raster scan data.
A raster scan is a 2D intensity scan used to visualize particles before measurement.
- Parameters:
h5dataset (H5dataset) – The parent HDF5 dataset object.
particle_num (int) – Number of particles connected to this raster scan.
h5dataset_index (int) – Index of this raster scan in the dataset.
particle_indexes (List[int]) – Dataset indices of the particles in this raster scan.