change_point

Module for handling analysis of change points and creation of consequent levels.

Based on ‘Detection of Intensity Change Points in Time-Resolved Single-Molecule Measurements’ from Watkins nad Yang, J. Phys. Chem. B 2005, 109, 617-628 (http://pubs.acs.org/doi/abs/10.1021/jp0467548)

Joshua Botha University of Pretoria 2019

Module Contents

Classes

ParticleMicrotimesSubset

A container for a custom list that accesses a subset of a H5 dataset

ChangePoints

Contains all the attributes to describe the found change points in an analysed particles.

Err

Level

Defines the start, end and intensity of a single level.

TauData

Loads and stores the tau_a and tau_b files from text files for

ChangePointAnalysis

Perform analysis of particle abstimes data to resolve change points.

Functions

main()

Tests ChangePoints init

Attributes

__docformat__

logger

change_point.__docformat__ = "'NumPy'"[source]
change_point.logger = "'change_point'"[source]
class change_point.ParticleMicrotimesSubset(particle: smsh5.Particle, start_ind: int, end_ind: int)[source]

A container for a custom list that accesses a subset of a H5 dataset

property _micro_dataset[source]
_particle[source]
_start_ind[source]
_end_ind[source]
__len__()[source]
_get_ind(ind) int[source]
__getitem__(i)[source]
__iter__()[source]
__repr__()[source]
__eq__(other)[source]
class change_point.ChangePoints(particle, confidence=None, run_levels: bool = None)[source]

Contains all the attributes to describe the found change points in an analysed particles.

property has_levels[source]
property levels: List[Level][source]
property num_levels[source]
property level_ints[source]
property level_dwelltimes[source]
property cpa_has_run[source]
property confidence[source]
property cpt_inds[source]
property num_cpts[source]
property conf_regions[source]
bursts_deleted = 'None'[source]
_particle[source]
uuid[source]
_cpa[source]
has_burst = 'False'[source]
burst_levels = 'None'[source]
run_cpa(all_sums: generate_sums.CPSums, confidence=None, run_levels=None, end_time_s=None)[source]

Run change point analysis.

Performs the change point analysis on the parent particle object with the confidence

either provided as an argument here or in the __init__ method.

Parameters:
  • confidence (Confidence level with which to resolve the change points with.) – Must be 0.99, 0.95, 0.90 or 0.69.

  • run_levels (If true the change point analysis will be used to add a list of levels to the) – parent particle object by running its add_levels method.

  • end_time_s

calc_mean_std()[source]
check_burst()[source]
remove_bursts()[source]
restore_bursts()[source]
class change_point.Err(lower: float, upper: float)[source]
lower[source]
upper[source]
sum[source]
class change_point.Level(particle: smsh5.Particle, particle_ind: int, level_inds: Tuple[int, int], int_p_s: float = None, group_ind: int = None)[source]

Defines the start, end and intensity of a single level.

property abs_times[source]
property times_s[source]
property dwell_time_s[source]
_particle[source]
particle_ind[source]
level_inds[source]
num_photons[source]
times_ns[source]
dwell_time_ns[source]
microtimes[source]
group_ind = 'None'[source]
histogram = 'None'[source]
class change_point.TauData(confidence=None)[source]

Loads and stores the tau_a and tau_b files from text files for specific confidence and stores as attributes.

get_tau_a(num_data_points=None)[source]

Get tau_a value for n = num_data_points.

Retrieve the a tau data for the given number of data points.

Parameters:

num_data_points – Number of data points that the tau data is needed for. Note, only use values up to and smaller than 1000 for accuracy.

Returns:

tau_a value

Return type:

float

get_tau_b(num_data_points=None)[source]

Get tau_a value for n = num_data_points.

Retrieve the a tau data for the given number of data points.

Parameters:

num_data_points – Number of data points that the tau data is needed for. Note, only use values up to and smaller than 1000 for accuracy.

Returns:

tau_a value

Return type:

float

class change_point.ChangePointAnalysis(particle: smsh5.Particle = None, confidence=None)[source]

Perform analysis of particle abstimes data to resolve change points.

property _abstimes[source]
property _microtimes[source]
property level_ints[source]
property level_dwelltimes[source]
_particle = 'None'[source]
has_run = 'False'[source]
end_at_photon = 'None'[source]
num_photons[source]
confidence = 'None'[source]
cpt_inds[source]
conf_regions = '[]'[source]
_finding = 'False'[source]
found_cpts = 'False'[source]
num_cpts = 'None'[source]
has_levels = 'False'[source]
levels = 'None'[source]
num_levels = 'None'[source]
_i = 'None'[source]
settings[source]
load_settings()[source]
reset(confidence: float = None)[source]
__weighted_likelihood_ratio(all_sums: generate_sums.CPSums, seg_inds=None) Tuple[bool, int | None][source]

Calculates the Weighted & Standardised Likelihood ratio and detects the possible change point.

Based on ‘Detection of Intensity Change Points in Time-Resolved Single-Molecule Measurements’ from Watkins nad Yang, J. Phys. Chem. B 2005, 109, 617-628 (http://pubs.acs.org/doi/abs/10.1021/jp0467548)

If the possible change point is greater than the tau_a value for the corresponding confidence interval and number of data points the detected change points, it’s confidence region (as defined by tau_b), and the corresponding uncertainty in time is added to this instance of ChangePointAnalysis.

Parameters:

seg_inds ((int, int), optional) – Segment indexes (start, end).

Returns:

  • cpt_found (bool) – True if a change point was detected.

  • cpt (int, Optional) – The index of the change point, if one was detected.

_next_seg_ind(prev_seg_inds: Tuple[int, int] = None, side: str = None, rights_cpt: int = None) Tuple[int, int][source]

Calculates the next segments indexes.

Uses the indexes of the previous segment, as well as the latest change point to calculate the index values of the next segment.

See code2flow.com for flow diagram of if statements. https://code2flow.com/svLn85

Parameters:
  • prev_seg_inds ((int, int)) – Contains the start and end of the previous segment (start, end)

  • side (str, Optional) – If a change point was detected in the previous segment choose left or right of it. Possible values are ‘left’ or ‘right’.

  • rights_cpt (int, Optional) – The index of the change point for the right leg (the next_seg_start if side = ‘left’).

Returns:

next_seg – The next segments indexes.

Return type:

(int, int)

_find_all_cpts(all_sums: generate_sums.CPSums, _seg_inds: Tuple[int, int] = None, _side: str = None, _right_cpt: int = None)[source]

Find all change points in particle.

Recursive function that finds all change points that meets the confidence criteria.

Note

The first call doesn’t need to be called with any parameters.

Note

The top level assigns the number of detected change points to the .num_cpts attribute of this instance of ChangePointAnalysis.

Parameters:
  • _right_cpt (int, Optional) – The index of the change point for the right leg (the next_seg_start if side = ‘left’).

  • _seg_inds ((int, int), Optional) – The index of the segment that is to be searched. Calculated by _next_seg_ind method.

  • _side (str, Optional) – Determines current segment is left or right of a previously detected change point. Valid values are ‘left’ or ‘right’.

define_levels(remove_prev: bool = None) None[source]

Creates a list of levels as defined by the detected change points.

Uses the detected change points to create a list of Level instances that contain attributes that define each resolved level.

This method populate the .levels attribute of the parent particle instance by using its add_levels method.

Parameters:

remove_prev (bool, Optional) – If true, previous levels will be removed.

run_cpa(all_sums: generate_sums.CPSums, confidence=None, end_time_s=None)[source]

Runs the change point analysis.

If the ChangePointAnalysis wasn’t initialised with a confidence interval, or if the analysis is to be rerun with a new confidence interval, this method starts said analysis.

Parameters:
  • end_time_s (float) – Time at which to end analysis. If not provided the whole trace will be used.

  • confidence (float) – Confidence interval. Valid values are 0.99, 0.95, 0.90 and 0.69.

Returns:

  • num_cpts (int) – Number of change points detected

  • cpt_inds (ndarray) – Indexes of change points

  • conf_regions (list(tuple(int, int))) – Index region corresponding to confidence interval

  • dt_uncertainty (ndarray) – Array of uncertainty in time corresonding to confidence interval

change_point.main()[source]

Tests ChangePoints init