Code reference

definitions

Naming conventions

dclab.definitions.CFG_ANALYSIS = {'calculation': [['emodulus model', <function lcstr at 0x7fc831f4eea0>, 'Model for computing elastic moduli'], ['emodulus medium', <class 'str'>, 'Medium used (e.g. CellCarrierB, water)'], ['emodulus temperature', <class 'float'>, 'Chip temperature [°C]'], ['emodulus viscosity', <class 'float'>, "Viscosity [Pa*s] if 'medium' unknown"], ['crosstalk fl21', <class 'float'>, 'Fluorescence crosstalk, channel 2 to 1'], ['crosstalk fl31', <class 'float'>, 'Fluorescence crosstalk, channel 3 to 1'], ['crosstalk fl12', <class 'float'>, 'Fluorescence crosstalk, channel 1 to 2'], ['crosstalk fl32', <class 'float'>, 'Fluorescence crosstalk, channel 3 to 1'], ['crosstalk fl31', <class 'float'>, 'Fluorescence crosstalk, channel 1 to 3'], ['crosstalk fl32', <class 'float'>, 'Fluorescence crosstalk, channel 2 to 3']], 'filtering': [['hierarchy parent', <class 'str'>, 'Hierarchy parent of the data set'], ['remove invalid events', <function fbool at 0x7fc831f4ed08>, 'Remove events with inf/nan values'], ['enable filters', <function fbool at 0x7fc831f4ed08>, 'Enable filtering'], ['limit events', <function fint at 0x7fc831f4ed90>, 'Upper limit for number of filtered events'], ['polygon filters', <function fintlist at 0x7fc831f4ee18>, 'Polygon filter indices']]}

All configuration keywords editable by the user

downsampling

Content-based downsampling of ndarrays

dclab.downsampling.downsample_rand(a, samples, remove_invalid=True, retidx=False)[source]

Downsampling by randomly removing points

Parameters:
  • a (1d ndarray) – The input array to downsample
  • samples (int) – The desired number of samples
  • remove_invalid (bool) – Remove nan and inf values before downsampling
  • retidx (bool) – Also return a boolean array that corresponds to the downsampled indices in a.
Returns:

  • dsa, dsb (1d ndarrays of shape (samples,)) – The pseudo-randomly downsampled arrays a and b
  • [idx] (1d boolean array with same shape as a) – A boolean array such that a[idx] == dsa is all true

features

Basic methods for event feature computation

isoelastics

Isoelastics management

class dclab.isoelastics.Isoelastics(paths=[])[source]
add(isoel, col1, col2, channel_width, flow_rate, viscosity, method)[source]

Add isoelastics

Parameters:
  • isoel (list of ndarrays) – Each list item resembles one isoelastic line stored as an array of shape (N,3). The last column contains the emodulus data.
  • col1 (str) – Name of the first feature of all isoelastics (e.g. isoel[0][:,0])
  • col2 (str) – Name of the second feature of all isoelastics (e.g. isoel[0][:,1])
  • channel_width (float) – Channel width in µm
  • flow_rate (float) – Flow rate through the channel in µl/s
  • viscosity (float) – Viscosity of the medium in mPa*s
  • method (str) – The method used to compute the isoelastics (must be one of VALID_METHODS).

Notes

The following isoelastics are automatically added for user convenience: - isoelastics with col1 and col2 interchanged - isoelastics for circularity if deformation was given

static add_px_err(isoel, col1, col2, px_um, inplace=False)[source]

Undo pixelation correction

Isoelasticity lines are already corrected for pixelation effects as described in

Mapping of Deformation to Apparent Young’s Modulus in Real-Time Deformability Cytometry Christoph Herold, arXiv:1704.00572 [cond-mat.soft] (2017) https://arxiv.org/abs/1704.00572.

If the isoealsticity lines are displayed with deformation data that are not corrected, then the lines must be “un”-corrected, i.e. the pixelation error must be added to the lines to match the experimental data.

Parameters:
  • isoel (list of 2d ndarrays of shape (N, 3)) – Each item in the list corresponds to one isoelasticity line. The first column is defined by col1, the second by col2, and the third column is the emodulus.
  • col2 (col1,) – Define the fist to columns of each isoelasticity line. One of [“area_um”, “circ”, “deform”]
  • px_um (float) – Pixel size [µm]
static check_col12(col1, col2)[source]
static convert(isoel, col1, col2, channel_width_in, channel_width_out, flow_rate_in, flow_rate_out, viscosity_in, viscosity_out, inplace=False)[source]

Convert isoelastics in area_um-deform space

Parameters:
  • isoel (list of 2d ndarrays of shape (N, 3)) – Each item in the list corresponds to one isoelasticity line. The first column is defined by col1, the second by col2, and the third column is the emodulus.
  • col2 (col1,) – Define the fist to columns of each isoelasticity line. One of [“area_um”, “circ”, “deform”]
  • channel_width_in (float) – Original channel width [µm]
  • channel_width_out (float) – Target channel width [µm]
  • flow_rate_in (float) – Original flow rate [µl/s]
  • flow_rate_in – Target flow rate [µl/s]
  • viscosity_in (float) – Original viscosity [mPa*s]
  • viscosity_out (float) – Target viscosity [mPa*s]

Notes

If only the positions of the isoelastics are of interest and not the value of the elastic modulus, then it is sufficient to supply values for the channel width and set the values for flow rate and viscosity to a constant (e.g. 1).

See also

dclab.features.emodulus.convert()
conversion method used
get(col1, col2, method, channel_width, flow_rate=None, viscosity=None, add_px_err=False, px_um=None)[source]

Get isoelastics

Parameters:
  • col1 (str) – Name of the first feature of all isoelastics (e.g. isoel[0][:,0])
  • col2 (str) – Name of the second feature of all isoelastics (e.g. isoel[0][:,1])
  • method (str) – The method used to compute the isoelastics (must be one of VALID_METHODS).
  • channel_width (float) – Channel width in µm
  • flow_rate (float or None) – Flow rate through the channel in µl/s. If set to None, the flow rate of the imported data will be used (only do this if you do not need the correct values for elastic moduli).
  • viscosity (float or None) – Viscosity of the medium in mPa*s. If set to None, the flow rate of the imported data will be used (only do this if you do not need the correct values for elastic moduli).
  • add_px_err (bool) – If True, add pixelation errors according to C. Herold (2017), https://arxiv.org/abs/1704.00572
  • px_um (float) – Pixel size [µm], used for pixelation error computation

See also

dclab.features.emodulus.convert()
conversion in-between channel sizes and viscosities
dclab.features.emodulus.corrpix_deform_delta()
pixelation error that is applied to the deformation data
load_data(path)[source]

Load isoelastics from a text file

The text file is loaded with numpy.loadtxt and must have three columns, representing the two data columns and the elastic modulus with units defined in definitions.py. The file header must have a section defining meta data of the content like so:

# […] # # - column 1: area_um # - column 2: deform # - column 3: emodulus # - channel width [um]: 20 # - flow rate [ul/s]: 0.04 # - viscosity [mPa*s]: 15 # - method: analytical # # […]
Parameters:path (str) – Path to a isoelastics text file
class dclab.isoelastics.IsoelasticsDict[source]
dclab.isoelastics.get_default()[source]

Return default isoelasticity lines

kde_methods

Kernel Density Estimation methods

dclab.kde_methods.get_bad_vals(x, y)[source]
dclab.kde_methods.ignore_nan_inf(kde_method)[source]

Ignores nans and infs from the input data

Invalid positions in the resulting density are set to nan.

dclab.kde_methods.kde_gauss(events_x, events_y, xout=None, yout=None, *args, **kwargs)[source]

Gaussian Kernel Density Estimation

Parameters:
  • events_y (events_x,) – The input points for kernel density estimation. Input is flattened automatically.
  • yout (xout,) – The coordinates at which the KDE should be computed. If set to none, input coordinates are used.
Returns:

density – The KDE for the points in (xout, yout)

Return type:

ndarray, same shape as xout

See also

scipy.stats.gaussian_kde

Notes

This is a wrapped version that ignores nan and inf values.

dclab.kde_methods.kde_histogram(events_x, events_y, xout=None, yout=None, *args, **kwargs)[source]

Histogram-based Kernel Density Estimation

Parameters:
  • events_y (events_x,) – The input points for kernel density estimation. Input is flattened automatically.
  • yout (xout,) – The coordinates at which the KDE should be computed. If set to none, input coordinates are used.
  • bins (tuple (binsx, binsy)) – The number of bins to use for the histogram.
Returns:

density – The KDE for the points in (xout, yout)

Return type:

ndarray, same shape as xout

See also

numpy.histogram2d scipy.interpolate.RectBivariateSpline

Notes

This is a wrapped version that ignores nan and inf values.

dclab.kde_methods.kde_none(events_x, events_y, xout=None, yout=None)[source]

No Kernel Density Estimation

Parameters:
  • events_y (events_x,) – The input points for kernel density estimation. Input is flattened automatically.
  • yout (xout,) – The coordinates at which the KDE should be computed. If set to none, input coordinates are used.
Returns:

density – The KDE for the points in (xout, yout)

Return type:

ndarray, same shape as xout

Notes

This method is a convenience method that always returns ones in the shape that the other methods in this module produce.

dclab.kde_methods.kde_multivariate(events_x, events_y, xout=None, yout=None, *args, **kwargs)[source]

Multivariate Kernel Density Estimation

Parameters:
  • events_y (events_x,) – The input points for kernel density estimation. Input is flattened automatically.
  • bw (tuple (bwx, bwy) or None) – The bandwith for kernel density estimation.
  • yout (xout,) – The coordinates at which the KDE should be computed. If set to none, input coordinates are used.
Returns:

density – The KDE for the points in (xout, yout)

Return type:

ndarray, same shape as xout

See also

statsmodels.nonparametric.kernel_density.KDEMultivariate

Notes

This is a wrapped version that ignores nan and inf values.

polygon_filter

PolygonFilter classes and methods

exception dclab.polygon_filter.FilterIdExistsWarning[source]
class dclab.polygon_filter.PolygonFilter(axes=None, points=None, inverted=False, name=None, filename=None, fileid=0, unique_id=None)[source]

An object for filtering RTDC data based on a polygonial area

instances = []
static clear_all_filters()[source]

Remove all filters and reset instance counter

copy(invert=False)[source]

Return a copy of the current instance

Parameters:invert (bool) – The copy will be inverted w.r.t. the original
filter(datax, datay)[source]

Filter a set of datax and datay according to self.points

static get_instance_from_id(unique_id)[source]

Get an instance of the PolygonFilter using a unique id

static import_all(path)[source]

Import all polygons from a .poly file.

Returns a list of the imported polygon filters

static instace_exists(unique_id)[source]

Determine whether an instance with this unique id exists

static point_in_poly(x, y, poly)[source]

Determine whether a point is within a polygon area

Parameters:
  • y (x,) – The coordinates of the point
  • poly (list-like) – The polygon (PolygonFilter.points)
Returns:

insideTrue, if point is inside.

Return type:

bool

static remove(unique_id)[source]

Remove a polygon filter from PolygonFilter.instances

save(polyfile, ret_fobj=False)[source]

Save all data to a text file (appends data if file exists).

Polyfile can be either a path to a file or a file object that was opened with the write “w” parameter. By using the file object, multiple instances of this class can write their data.

If ret_fobj is True, then the file object will not be closed and returned.

static save_all(polyfile)[source]

Save all polygon filters

exception dclab.polygon_filter.PolygonFilterError[source]
dclab.polygon_filter.get_polygon_filter_names()[source]

Get the names of all polygon filters in the order of creation

rtdc_dataset

statistics

Statistics computation for RT-DC dataset instances

exception dclab.statistics.BadMethodWarning[source]
class dclab.statistics.Statistics(name, method, req_feature=False)[source]
available_methods = {'%-gated': <dclab.statistics.Statistics object at 0x7fc831db92b0>, 'Events': <dclab.statistics.Statistics object at 0x7fc831d38b70>, 'Flow rate': <dclab.statistics.Statistics object at 0x7fc831db9358>, 'Mean': <dclab.statistics.Statistics object at 0x7fc831d57160>, 'Median': <dclab.statistics.Statistics object at 0x7fc831d57cf8>, 'Mode': <dclab.statistics.Statistics object at 0x7fc831e1d160>, 'SD': <dclab.statistics.Statistics object at 0x7fc831d38f98>}
get_feature(rtdc_ds, axis)[source]
get_data(kwargs)[source]
dclab.statistics.flow_rate(mm)[source]
dclab.statistics.get_statistics(rtdc_ds, methods=None, features=None)[source]
Parameters:
  • rtdc_ds (instance of dclab.rtdc_dataset.RTDCBase.) – The data set for which to compute the statistics.
  • methods (list of str or None) – The methods wih which to compute the statistics. The list of available methods is given with dclab.statistics.Statistics.available_methods.keys() If set to None, statistics for all methods are computed.
  • features (list of str) – Feature name identifiers are defined in dclab.definitions.scalar_feature_names. If set to None, statistics for all axes are computed.
Returns:

  • header (list of str) – The header (feature + method names) of the computed statistics.
  • values (list of float) – The computed statistics.

dclab.statistics.mode(data)[source]

Compute an intelligent value for the mode

The most common value in experimental is not very useful if there are a lot of digits after the comma. This method approaches this issue by rounding to bin size that is determined by the Freedman–Diaconis rule.

Parameters:data (1d ndarray) – The data for which the mode should be computed.
Returns:mode – The mode computed with the Freedman-Diaconis rule.
Return type:float