Code reference¶

Module level aliases¶

For user convenience, the following objects are available at the module level.

class nanite.Indentation
class nanite.IndentationGroup
class nanite.IndentationRater

alias of nanite.rate.IndentationRater

class nanite.QMap

alias of nanite.qmap.QMap

nanite.load_group()

Force-indentation data¶

class nanite.indent.Indentation(idnt_data)[source]

Force-indentation

Parameters: idnt_data (nanite.read.IndentationData) – Object holding the experimental data
apply_preprocessing(preprocessing=None)[source]

Perform curve preprocessing steps

Parameters: preprocessing (list) – A list of preprocessing method names that are stored in the IndentationPreprocessor class. If set to None, self.preprocessing will be used.
compute_emodulus_mindelta(callback=None)[source]

Elastic modulus in dependency of maximum indentation

The fitting interval is varied such that the maximum indentation depth ranges from the lowest tip position to the estimated contact point. For each interval, the current model is fitted and the elastic modulus is extracted.

Parameters: callback (callable) – A method that is called with the emoduli and indentations as the computation proceeds every five steps. emoduli, indentations – The fitted elastic moduli at the corresponding maximal indentation depths. 1d ndarrays

Notes

The information about emodulus and mindelta is also stored in self.fit_properties with the keys “optimal_fit_E_array” and “optimal_fit_delta_array”, if self.fit_model is called with the argument search_optimal_fit set to True.

estimate_contact_point_index()[source]

Estimate the contact point

Contact point (CP) estimation involves a preprocessing step where the force data are transformed into gradient space (to account for a slope in the approach curve) and a subsequent analysis with two different methods to determine when the gradient changes significantly enough to qualify for a CP. Of those two methods, the one which yields the smallest index (measured from the beginning of the approach curve) is returned. If one of the methods fail, then a fit function with a constant and linear part is used to determine the CP.

Preprocessing:

1. Compute the rolling average of the force (Otherwise the gradient would be too wild)
2. Compute the gradient (Converting to gradient space gets rid of linear contributions in the approach part)
3. Compute the rolling average of the gradient (Makes the curve to analyze more smooth so that the methods below don’t hit the alarm too early)

Method 1: baseline deviation

1. Obtain the baseline (initial 10% of the gradient curve)
2. Compute average and maximum deviation of the baseline
3. The CP is the index of the curve where it exceeds twice of the maximum deviation

1. Apply a median filter to the approach curve
3. Cut off trailing 10 points from the gradient (noise)
4. The CP is the index of the gradient curve when the sign changes, measured from the point of maximal indentation.

If one of the methods fail, then a combined constant+linear function (max(constant, linear) is fitted to the gradient to determine the contact point. If that fails as well, then the CP defaults to the center of the entire approach curve.

Changed in version 1.6.0: Add the gradient preprocessing step to circumvent issues with tilted baselines. This feature does not significantly affect fitting results.

Changed in version 1.6.1: Added max(constant, linear) fit when the other methods fail.

estimate_optimal_mindelta()[source]

Estimate the optimal indentation depth

This is a convenience function that wraps around compute_emodulus_mindelta and IndentationFitter.compute_opt_mindelta.

export(path, fmt='tab')[source]

Saves the current data as tab separated values

fit_model(**kwargs)[source]

Fit the approach-retract data to a model function

Parameters: model_key (str) – A key referring to a model in nanite.model.models_available params_initial (instance of lmfit.Parameters or dict) – Parameters for fitting. If not given, default parameters are used. range_x (tuple of 2) – The range for fitting, see range_type below. range_type (str) – One of: absolute: Set the absolute fitting range in values given by the x_axis. relative cp: In some cases it is desired to be able to fit a model only up until a certain indentation depth (tip position) measured from the contact point. Since the contact point is a fit parameter as well, this requires a two-pass fitting. preprocessing (list of str) – Preprocessing segment (str) – One of “approach” or “retract”. weight_cp (float) – Weight the contact point region which shows artifacts that are difficult to model with e.g. Hertz. optimal_fit_edelta (bool) – Search for the optimal fit by varying the maximal indentation depth and determining a plateau in the resulting Young’s modulus (fitting parameter “E”).
get_ancillary_parameters(model_key=None)[source]

Compute ancillary parameters for the current model

get_initial_fit_parameters(model_key=None, common_ancillaries=True, model_ancillaries=True)[source]

Return the initial fit parameters

If there are not initial fit parameters set in self.fit_properties, then they are computed.

Parameters: model_key (str) – Optionally set a model key. This will override the “model_key” key in self.fit_properties. global_ancillaries (bool) – Guess global ancillaries such as the contact point. model_ancillaries (bool) – Guess model-related ancillaries

Notes

global_ancillaries and model_ancillaries only have an effect if self.fit_properties[“params_initial”] is set.

get_rating_parameters()[source]

Return current rating parameters

rate_quality(regressor='Extra Trees', training_set='zef18', names=None, lda=None)[source]

Compute the quality of the obtained curve

Uses heuristic approaches to rate a curve.

Parameters: regressor (str) – The regressor name used for rating. training_set (str) – A label for a training set shipped with nanite or a path to a training set. rating – A value between 0 and 10 where 0 is the lowest rating. If no fit has been performed, a rating of -1 is returned. float

Notes

The rating is cached based on the fitting hash (see IndentationFitter._hash).

reset()[source]

Resets all data operations

data = None

All data as afmformats.AFMForceDistance

fit_properties

Fitting results, see Indentation.fit_model())

preprocessing = None

Default preprocessing steps steps, see Indentation.apply_preprocessing().

Groups¶

class nanite.group.IndentationGroup(path=None, callback=None)[source]

Group of Indentation

Parameters: path (str) – The path to the data file. The data format is determined using the extension of the file and the data is loaded with the correct method. callback (callable or None) – A method that accepts a float between 0 and 1 to externally track the process of loading the data.
append(item)[source]

Append an indentation dataset

Parameters: item (nanite.indent.Indentation) – Force-indentation dataset
get_enum(enum)[source]

Return the indentation curve with this enum value

Raises: ValueError if multiple curves with the same enum value exist. KeyErrir if the enum value is not found
index(item)[source]
subgroup_with_path(path)[source]

Return a subgroup with measurements matching path

nanite.group.load_group(path, callback=None)[source]

Parameters: path (path-like) – Path to experimental data callback (callable or None) – Callback function for tracking loading progress group – Indentation group with force-distance data nanite.IndetationGroup

nanite.read.get_data_paths(path)[source]

Obtain a list of data files

Parameters: path (str or pathlib.Path) – Path to a data file or a directory containing data files. paths – All supported data files found in path. If path is a file, [pathlib.Path(path)] is returned. If path has an unsupported extion, an empty list is returned. list of pathlib.Path
nanite.read.get_data_paths_enum(path, skip_errors=False)[source]
nanite.read.load_data(path, callback=None)[source]

Load data and return list of afmformats.AFMForceDistance

Preprocessing¶

exception nanite.preproc.CannotSplitWarning[source]
class nanite.preproc.IndentationPreprocessor[source]
static apply(apret, preproc_names)[source]

Perform force-distance preprocessing steps

Parameters: apret (nanite.Indentation) – The afm data to preprocess preproc_names (list) – A list of names for static methods in IndentationPreprocessor that will be applied (in the order given).

Notes

This method is usually called from within the Indentation class instance. If you are using this class directly and apply it more than once, you might need to call apret.reset() before preprocessing a second time.

static available()[source]

List available preprocessor names

static compute_tip_position(apret)[source]

Compute the tip-sample separation

This computation correctly reproduces the column “Vertical Tip Position” as it is exported by the JPK analysis software with the checked option “Use Unsmoothed Height”.

static correct_force_offset(apret)[source]

Correct the force offset with an average baseline value

static correct_split_approach_retract(apret)[source]

Split the approach and retract curves (farthest point method)

Approach and retract curves are defined by the microscope. When the direction of piezo movement is flipped, the force at the sample tip is still increasing. This can be either due to a time lag in the AFM system or due to a residual force acting on the sample due to the bent cantilever.

To repair this time lag, we append parts of the retract curve to the approach curve, such that the curves are split at the minimum height.

static correct_tip_offset(apret)[source]

Correct the offset of the tip position

An estimate of the tip position is used to compute the contact point.

static smooth_height(apret)[source]

Smoothen height data

For the columns “height (measured)” and “tip position”, and for the approach and retract data separately, this method adds the columns “height (measured, smoothed)” and “tip position (smoothed)” to self.data.

nanite.preproc.available_preprocessors = ['compute_tip_position', 'correct_force_offset', 'correct_split_approach_retract', 'correct_tip_offset', 'smooth_height']

Available preprocessors

Modeling¶

Methods and constants¶

exception nanite.model.ModelIncompleteError[source]
nanite.model.get_anc_parm_keys(model_key)[source]

Return the key names of a model’s ancillary parameters

nanite.model.get_anc_parms(idnt, model_key)[source]

Compute ancillary parameters for a force-distance dataset

Ancillary parameters include parameters that:

• are unrelated to fitting: They may just be important parameters to the user.
• require the entire dataset: They cannot be extracted during fitting, because they require more than just the approach xor retract curve to compute (e.g. hysteresis, jump of retract curve at maximum indentation). They may, additionally, depend on initial fit parameters set by the user.
• require a fit: They are dependent on fitting parameters but are not required during fitting.

Notes

If an ancillary parameter name matches that of a fitting parameter, then it is assumed that it can be used for fitting. Please see nanite.indent.Indentation.get_initial_fit_parameters() and nanite.fit.guess_initial_parameters().

Ancillary parameters are set to np.nan if they cannot be computed.

Parameters: idnt (nanite.indent.Indentation) – The force-distance data for which to compute the ancillary parameters model_key (str) – Name of the model ancillaries – key-value dictionary of ancillary parameters collections.OrderedDict
nanite.model.get_init_parms(model_key)[source]

Get initial fit parameters for a model

nanite.model.get_model_by_name(name)[source]

Convenience function to obtain a model by name instead of by key

nanite.model.get_parm_name(model_key, parm_key)[source]

Return parameter label

Parameters: model_key (str) – The model key (e.g. “hertz_cone”) parm_key (str) – The parameter key (e.g. “E”) parm_name – The parameter label (e.g. “Young’s Modulus”) str
nanite.model.get_parm_unit(model_key, parm_key)[source]

Return parameter unit

Parameters: model_key (str) – The model key (e.g. “hertz_cone”) parm_key (str) – The parameter key (e.g. “E”) parm_unit – The parameter unit (e.g. “Pa”) str
nanite.model.register_model(module, module_name)[source]

Register a fitting model

nanite.model.ANCILLARY_COMMON = {'max_indent': ('Maximum indentation', 'm')}

Common ancillary parameters

Models¶

Each model is implemented as a submodule in nanite.model. For instance nanite.model.model_hertz_parabolic. Each of these modules implements the following functions (which are not listed for each model in the subsections below):

nanite.model.model_submodule.get_parameter_defaults()

Return the default parameters of the model.

nanite.model.model_submodule.model()

Wrap the actual model for fitting.

nanite.model.model_submodule.residual()

Compute the residuals during fitting.

In addition, each submodule contains the following attributes:

nanite.model.model_submodule.model_doc

The doc-string of the model function.

nanite.model.model_submodule.model_key

The model key used in the command line interface and during scripting.

nanite.model.model_submodule.model_name

The name of the model.

nanite.model.model_submodule.parameter_keys

Parameter keywords of the model for higher-level applications.

nanite.model.model_submodule.parameter_names

Parameter names of the model for higher-level applications.

nanite.model.model_submodule.parameter_units

Parameter units for higher-level applications.

conical indenter (Hertz)¶

 model key hertz_cone model name conical indenter (Hertz) model location nanite.model.model_conical_indenter
nanite.model.model_conical_indenter.hertz_conical(E, delta, alpha, nu, contact_point=0, baseline=0)[source]

Hertz model for a conical indenter

$F = \frac{2\tan\alpha}{\pi} \frac{E}{1-\nu^2} \delta^2$
Parameters: E (float) – Young’s modulus [N/m²] delta (1d ndarray) – Indentation [m] alpha (float) – Half cone angle [degrees] nu (float) – Poisson’s ratio contact_point (float) – Indentation offset [m] baseline (float) – Force offset [N] negindent (bool) – If True, will assume that the indentation value(s) given by delta are negative and must be mutlitplied by -1. F – Force [N] float

Notes

These approximations are made by the Hertz model:

• The sample is isotropic.
• The sample is a linear elastic solid.
• The sample is extended infinitely in one half space.
• The indenter is not deformable.
• There are no additional interactions between sample and indenter.

• infinitely sharp probe

References

Love (1939) [Love1939]

parabolic indenter (Hertz)¶

 model key hertz_para model name parabolic indenter (Hertz) model location nanite.model.model_hertz_paraboloidal
nanite.model.model_hertz_paraboloidal.hertz_paraboloidal(E, delta, R, nu, contact_point=0, baseline=0)[source]

Hertz model for a paraboloidal indenter

$F = \frac{4}{3} \frac{E}{1-\nu^2} \sqrt{R} \delta^{3/2}$
Parameters: E (float) – Young’s modulus [N/m²] delta (1d ndarray) – Indentation [m] R (float) – Tip radius [m] nu (float) – Poisson’s ratio contact_point (float) – Indentation offset [m] baseline (float) – Force offset [N] negindent (bool) – If True, will assume that the indentation value(s) given by delta are negative and must be mutlitplied by -1. F – Force [N] float

Notes

$F = \frac{4}{3} \frac{E}{1-\nu^2} \sqrt{2k} \delta^{3/2},$

where $$k$$ is defined by the paraboloid equation

$\rho^2 = 4kz.$

These approximations are made by the Hertz model:

• The sample is isotropic.
• The sample is a linear elastic solid.
• The sample is extended infinitely in one half space.
• The indenter is not deformable.
• There are no additional interactions between sample and indenter.

• radius of spherical cell is larger than the indentation

References

Sneddon (1965) [Sneddon1965]

pyramidal indenter, three-sided (Hertz)¶

 model key hertz_pyr3s model name pyramidal indenter, three-sided (Hertz) model location nanite.model.model_hertz_three_sided_pyramid
nanite.model.model_hertz_three_sided_pyramid.hertz_three_sided_pyramid(E, delta, alpha, nu, contact_point=0, baseline=0)[source]

Hertz model for three sided pyramidal indenter

$F = 0.887 \tan\alpha \cdot \frac{E}{1-\nu^2} \delta^2$
Parameters: E (float) – Young’s modulus [N/m²] delta (1d ndarray) – Indentation [m] alpha (float) – Inclination angle of the pyramidal face [degrees] nu (float) – Poisson’s ratio contact_point (float) – Indentation offset [m] baseline (float) – Force offset [N] negindent (bool) – If True, will assume that the indentation value(s) given by delta are negative and must be mutlitplied by -1. F – Force [N] float

Notes

These approximations are made by the Hertz model:

• The sample is isotropic.
• The sample is a linear elastic solid.
• The sample is extended infinitely in one half space.
• The indenter is not deformable.
• There are no additional interactions between sample and indenter.
• The inclination angle of the pyramidal face (in radians) must be close to zero.

References

Bilodeau et al. 1992 [Bilodeau:1992]

spherical indenter (Sneddon)¶

 model key sneddon_spher model name spherical indenter (Sneddon) model location nanite.model.model_sneddon_spherical
nanite.model.model_sneddon_spherical.delta_of_a()

Compute indentation from contact area radius (wrapper)

nanite.model.model_sneddon_spherical.get_a()

Compute the contact area radius (wrapper)

nanite.model.model_sneddon_spherical.hertz_spherical()

Hertz model for Spherical indenter - modified by Sneddon

$\begin{split}F &= \frac{E}{1-\nu^2} \left( \frac{R^2+a^2}{2} \ln \! \left( \frac{R+a}{R-a}\right) -aR \right)\\ \delta &= \frac{a}{2} \ln \! \left(\frac{R+a}{R-a}\right)\end{split}$

($$a$$ is the radius of the circular contact area between bead and sample.)

Parameters: E (float) – Young’s modulus [N/m²] delta (1d ndarray) – Indentation [m] R (float) – Tip radius [m] nu (float) – Poisson’s ratio contact_point (float) – Indentation offset [m] baseline (float) – Force offset [N] negindent (bool) – If True, will assume that the indentation value(s) given by delta are negative and must be multiplied by -1. F – Force [N] float

Notes

These approximations are made by the Hertz model:

• The sample is isotropic.
• The sample is a linear elastic solid.
• The sample is extended infinitely in one half space.
• The indenter is not deformable.
• There are no additional interactions between sample and indenter.

• no surface forces

References

Sneddon (1965) [Sneddon1965]

spherical indenter (Sneddon, approximative)¶

 model key sneddon_spher_approx model name spherical indenter (Sneddon, approximative) model location nanite.model.model_sneddon_spherical_approximation
nanite.model.model_sneddon_spherical_approximation.hertz_sneddon_spherical_approx(E, delta, R, nu, contact_point=0, baseline=0)[source]

Hertz model for Spherical indenter - approximation

$F = \frac{4}{3} \frac{E}{1-\nu^2} \sqrt{R} \delta^{3/2} \left(1 - \frac{1}{10} \frac{\delta}{R} - \frac{1}{840} \left(\frac{\delta}{R}\right)^2 + \frac{11}{15120} \left(\frac{\delta}{R}\right)^3 + \frac{1357}{6652800} \left(\frac{\delta}{R}\right)^4 \right)$
Parameters: E (float) – Young’s modulus [N/m²] delta (1d ndarray) – Indentation [m] R (float) – Tip radius [m] nu (float) – Poisson’s ratio contact_point (float) – Indentation offset [m] baseline (float) – Force offset [N] negindent (bool) – If True, will assume that the indentation value(s) given by delta are negative and must be mutlitplied by -1. F – Force [N] float

Notes

These approximations are made by the Hertz model:

• The sample is isotropic.
• The sample is a linear elastic solid.
• The sample is extended infinitely in one half space.
• The indenter is not deformable.
• There are no additional interactions between sample and indenter.

• no surface forces

References

Sneddon (1965) [Sneddon1965], Dobler (personal communication, 2018) [Dobler]

Fitting¶

exception nanite.fit.FitDataError[source]
exception nanite.fit.FitKeyError[source]
exception nanite.fit.FitWarning[source]
class nanite.fit.FitProperties[source]

Fit property manager class

Provide convenient access to fit properties as a dictionary and dynamically manage resets due to new initial parameters.

Dynamic properties include:

• set “params_initial” to None if the “model_key” changes
• remove all keys except those in FP_DEFAULT if a key that is in FP_DEFAULT changes (All other keys are considered to be obsolete fitting results).

• “segment_bool”: bool
False for “approach” and True for “retract”
reset()[source]
restore(props)[source]

update the dictionary without removing any keys

class nanite.fit.IndentationFitter(idnt, **kwargs)[source]

Fit force-distance curves

Parameters: idnt (nanite.indent.Indentation) – The dataset to fit model_key (str) – A key referring to a model in nanite.model.models_available params_initial (instance of lmfit.Parameters) – Parameters for fitting. If not given, default parameters are used. range_x (tuple of 2) – The range for fitting, see range_type below. range_type (str) – One of: absolute: Set the absolute fitting range in values given by the x_axis. relative cp: In some cases it is desired to be able to fit a model only up until a certain indentation depth (tip position) measured from the contact point. Since the contact point is a fit parameter as well, this requires a two-pass fitting. preprocessing (list of str) – Preprocessing segment (str) – One of “approach” or “retract”. weight_cp (float) – Weight the contact point region which shows artifacts that are difficult to model with e.g. Hertz. optimal_fit_edelta (bool) – Search for the optimal fit by varying the maximal indentation depth and determining a plateau in the resulting Young’s modulus (fitting parameter “E”). optimal_fit_num_samples (int) – Number of samples to use for searching the optimal fit
compute_emodulus_vs_mindelta(callback=None)[source]

Compute elastic modulus vs. minimal indentation curve

static compute_opt_mindelta(emoduli, indentations)[source]

Determine the plateau of an emodulus-indentation curve

The following procedure is performed:

1. Smooth the emodulus data with a Butterworth filter
2. Label sequences that have similar values by binning into ten regions between the min and max.
3. Ignore sequences with emodulus that is smaller than the binning size.
4. Determine the longest sequence.
fit()[source]

Fit the approach-retract data to a model function

get_initial_parameters(idnt=None, model_key='hertz_para')[source]

Get initial fit parameters for a specific model

nanite.fit.guess_initial_parameters(idnt=None, model_key='hertz_para', common_ancillaries=True, model_ancillaries=True)[source]

Guess initial fitting parameters

Parameters: idnt (nanite.indent.Indentation) – The dataset to use for guessing initial fitting parameters using ancillary parameters model_key (str) – The model key common_ancillaries (bool) – Guess global ancillary parameters (such as contact point) model_ancillaries (bool) – Use model-related ancillary parameters
nanite.fit.obj2str(obj)[source]

String representation of an object for hashing

Rating¶

Features¶

class nanite.rate.features.IndentationFeatures(dataset=None)[source]
static compute_features(idnt, which_type='all', names=None, ret_names=False)[source]

Compute the features for a data set

Parameters: idnt (nanite.Indentation) – A dataset to rate names (list of str) – The names of the rating methods to use, e.g. [“rate_apr_bumps”, “rate_apr_mon_incr”]. If None (default), all available rating methods are used.

Notes

names may include features that are excluded by which_type. E.g. if a “bool” feature is in names but which_type is “float”, then the “bool” feature will be silently ignored.

feat_bin_apr_spikes_count()[source]

spikes during IDT

Sudden spikes in indentation curve

feat_bin_cp_position()[source]

CP outside of data range

Contact point position outside of range

feat_bin_size()[source]

dataset too small

Number of points in indentation curve

feat_con_apr_flatness()[source]

flatness of APR residuals

fraction of the positive-gradient residuals in the approach part

feat_con_apr_size()[source]

relative APR size

length of the approach part relative to the indentation part

feat_con_apr_sum()[source]

residuals of APR

absolute sum of the residuals in the approach part

feat_con_bln_slope()[source]

slope of BLN

slope obtained from a linear least-squares fit to the baseline

feat_con_bln_variation()[source]

variation in BLN

comparison of the forces at the beginning and at the end of the baseline

feat_con_cp_curvature()[source]

curvature at CP

curvature of the force-distance data at the contact point

feat_con_cp_magnitude()[source]

residuals at CP

mean value of the residuals around the contact point

feat_con_idt_maxima_75perc()[source]

maxima in IDT residuals

sum of the indentation residuals’ maxima in three intervals in-between 25% and 100% relative to the maximum indentation

feat_con_idt_monotony()[source]

monotony of IDT

change of the gradient in the indentation part

feat_con_idt_spike_area()[source]

area of IDT spikes

area of spikes appearing in the indentation part

feat_con_idt_sum()[source]

overall IDT residuals

sum of the residuals in the indentation part

feat_con_idt_sum_75perc()[source]

residuals in 75% IDT

sum of the residuals in the indentation part in-between 25% and 100% relative to the maximum indentation

classmethod get_feature_funcs(which_type='all', names=None)[source]

Return functions that compute features from a dataset

Parameters: names (list of str) – The names of the rating methods to use, e.g. [“rate_apr_bumps”, “rate_apr_mon_incr”]. If None (default), all available rating methods are returned. which_type (str) – Which features to return: [“all”, “bool”, “float”]. raters – Each item in the list consists contains the name of the rating method and the corresponding rating method. list of tuples (name, callable)
classmethod get_feature_names(which_type='all', names=None, ret_indices=False)[source]

Get features names

Parameters: which_type (str or list of str) – Return only features that are of a certain type. See VALID_FEATURE_TYPES for valid strings. names (list of str) – Return only features that are in this list. ret_indices (bool) – If True, also return the internal feature indices. name_list – List of feature names (callables of this class) list of str
contact_point
datafit_apr
datares_apr
dataset = None

current dataset from which features are computed

datax_apr
datay_apr
has_contact_point
is_fitted
is_valid
meta
nanite.rate.features.VALID_FEATURE_TYPES = ['all', 'binary', 'continuous']

Valid keyword arguments for feature types

Rater¶

class nanite.rate.rater.IndentationRater(regressor=None, scale=None, lda=None, training_set=None, names=None, weight=True, sample_weight=None, *args, **kwargs)[source]

Rate quality

Parameters: regressor (sciki-learn RegressorMixin) – The regressor used for rating scale (bool) – If True, apply a Standard Scaler. If a regressor based on decision trees is used, the Standard Scaler is not used by default, otherwise it is. lda (bool) – If True, apply a Linear Discriminant Analysis (LDA). If a regressor based on a decision tree is used, LDA is not used by default, otherwise it is. training_set (tuple of (X, y)) – The training set (samples, response) names (list of str) – Feature names to use weight (bool) – Weight the input samples by the number of occurrences or with sample_weight. For tree-based classifiers, set this to True to avoid bias. sample_weight (list-like) – The sample weights. If set to None sample weights are computed from the training set. *args (list) – Positional arguments for IndentationFeatures **kwargs – Keyword arguments for IndentationFeatures

sklearn.preprocessing.StandardScaler
Standard scaler
sklearn.discriminant_analysis.LinearDiscriminantAnalysis
Linear discriminant analysis
nanite.rate.regressors.reg_trees
List of regressors that are identified as tree-based
static compute_sample_weight(X, y)[source]

Weight samples according to occurrence in y

static get_training_set_path(label='zef18')[source]

Return the path to a training set shipped with nanite

Training sets are stored in the nanite.rate module path with ts_ prepended to label.

classmethod load_training_set(path=None, names=None, which_type=['continuous'], remove_nan=True, ret_names=False)[source]

Load a training set from a directory

By default, only the “continuous” features are imported. The “binary” features are not needed for training; they are used to sort out new force-distance data.

rate(samples=None, datasets=None)[source]

Perform rating step

Parameters: samples (1d or 2d ndarray (cast to 2d ndarray) or None) – Measured samples, if set to None, dataset must be given. dataset (list of nanite.Indentation) – Full, fitted measurement ratings – Resulting ratings list
names = None

feature names used by the regressor pipeline

pipeline = None

sklearn pipeline with transforms (and regressor if given)

nanite.rate.rater.get_available_training_sets()[source]

List of internal training sets

nanite.rate.rater.get_rater(regressor, training_set='zef18', names=None, lda=None, **reg_kwargs)[source]

Convenience method to get a rater

Parameters: regressor (str or RegressorMixin) – If a string, must be in reg_names. training_set (str or pathlib.Path or tuple (X, y)) – A string label representing a training set shipped with nanite, the path to a training set, or a tuple representing the training set (samples, response) for use with sklearn. irater – The rating instance. nanite.IndentationRater

Regressors¶

scikit-learn regressors and their keyword arguments

nanite.rate.regressors.reg_names = ['AdaBoost', 'Decision Tree', 'Extra Trees', 'Gradient Tree Boosting', 'Random Forest', 'SVR (RBF kernel)', 'SVR (linear kernel)']

List of available default regressor names

nanite.rate.regressors.reg_trees = ['AdaBoostRegressor', 'DecisionTreeRegressor', 'ExtraTreesRegressor', 'GradientBoostingRegressor', 'RandomForestRegressor']

List of tree-based regressor class names (used for keyword defaults in IndentationRater)

Manager¶

class nanite.rate.io.RateManager(path, verbose=0)[source]

Manage user-defined rates

export_training_set(path)[source]
get_cross_validation_score(regressor, training_set=None, n_splits=20, random_state=42)[source]

Regressor cross-validation scoring

Cross-validation is used to identify regressors that over-fit the train set by splitting the train set into multiple learn/test sets and quantifying the regressor performance for each split.

Parameters: regressor (str or RegressorMixin) – If a string, must be in reg_names. training_set (X, y) – If given, do not use self.samples

Notes

A skimage.model_selection.KFold cross validator is used in combination with the mean squared error score.

Cross-validation score is computed from samples that are filtered with the binary features and only from samples that do not contain any nan values.

get_rates(which='user', training_set='zef18')[source]
which: str
Which rating to return: “user” or a regressor name
get_training_set(which_type='all', prefilter_binary=False, remove_nans=False, transform=False)[source]

Return (X, y) training set

datasets
path = None

Path to the manual ratings (directory or .h5 file)

ratings
samples

The individual sample ratings computed by afmlib

verbose = None

verbosity level

nanite.rate.io.hdf5_rated(h5path, indent)[source]

Test whether an indentation has already been rated

Returns: is_rated, rating, comment
nanite.rate.io.load(path, meta_only=False, verbose=0)[source]

Notes

The .fit_properties attribute of each Indentation instance is overridden by a simple dictionary, so its functionalities are not available anymore.

nanite.rate.io.load_hdf5(path, meta_only=False)[source]
nanite.rate.io.save_hdf5(h5path, indent, user_rate, user_name, user_comment, h5mode='a')[source]

Store all relevant data of a user rating into an hdf5 file

Parameters: h5path (str) – Path to HDF5 rating container where data will be stored indent (nanite.Indentation) – The experimental data processed and fitted with nanite user_rate (float) – Rating given by the user user_name (str) – Name of the rating user
nanite.rate.io.hash_file[source]

Compute sha256 hex-hash of a file

Parameters: path (str or pathlib.Path) – path to the file blocksize (int) – block size read from the file hex – The first six characters of the hash str

Quantitative maps¶

exception nanite.qmap.DataMissingWarning[source]
class nanite.qmap.QMap(path_or_dataset, callback=None)[source]

Quantitative force spectroscopy map handling

Parameters: path_or_dataset (str or nanite.IndentationGroup) – The path to the data file. The data format is determined using the extension of the file and the data is loaded with the correct method. callback (callable or None) – A method that accepts a float between 0 and 1 to externally track the process of loading the data.
feat_data_min_height_measured_um(idnt)[source]
feat_fit_contact_point(idnt)[source]
feat_fit_youngs_modulus(idnt)[source]
feat_meta_rating(idnt)[source]
feat_meta_scan_order(idnt)[source]
get_qmap(feature, qmap_only=False)[source]

Return the quantitative map for a feature

Parameters: feature (str) – Feature to compute map for (see QMap.features) qmap_only – Only return the quantitative map data, not the coordinates x, y (1d ndarray) – Only returned if qmap_only is False; Pixel grid coordinates along x and y qmap (2d ndarray) – Quantitative map
extent

extent (x1, x2, y1, y2) [µm]

features = None

Available features (see nanite.qmap.available_features)

get_coords[source]

Get the qmap coordinates for each curve in QMap.ds

Parameters: which (str) – “px” for pixels or “um” for microns.
group = None

Indentation data (instance of nanite.IndentationGroup)

shape

shape of the map [px]

nanite.qmap.available_features = ['data min height', 'fit contact point', "fit young's modulus", 'meta rating', 'meta scan order']

Available features for quantitative maps