Code reference¶
definitions¶
Naming conventions
downsampling¶
Contentbased downsampling of ndarrays

dclab.downsampling.
downsample_rand
(a, samples, remove_invalid=True, retidx=False)[source]¶ Downsampling by randomly removing points
Parameters: Returns:  dsa, dsb (1d ndarrays of shape (samples,)) – The pseudorandomly 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 RealTime Deformability Cytometry Christoph Herold, arXiv:1704.00572 [condmat.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
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_umdeform 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 inbetween 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

kde_methods¶
Kernel Density Estimation methods

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]¶ Histogrambased 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: 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

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
= []¶

copy
(invert=False)[source]¶ Return a copy of the current instance
Parameters: invert (bool) – The copy will be inverted w.r.t. the original

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
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 (listlike) – The polygon (PolygonFilter.points)
Returns: inside – True, if point is inside.
Return type:

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.

rtdc_dataset¶
statistics¶
Statistics computation for RTDC dataset instances

class
dclab.statistics.
Statistics
(name, method, req_feature=False)[source]¶ 
available_methods
= {'Median': <dclab.statistics.Statistics object>, '%gated': <dclab.statistics.Statistics object>, 'SD': <dclab.statistics.Statistics object>, 'Events': <dclab.statistics.Statistics object>, 'Mode': <dclab.statistics.Statistics object>, 'Mean': <dclab.statistics.Statistics object>, 'Flow rate': <dclab.statistics.Statistics object>}¶


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.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 FreedmanDiaconis rule. Return type: float