GeneralSpikingFeatures

GeneralSpikingFeatures implements the preprocessing of voltage traces, and locate spikes in the voltage traces, but does not implement any features in itself. The preprocess() method changes the input given to the feature functions, and as such each spiking feature function has the following input arguments:

  1. The time array returned by the model simulation.
  2. An Spikes object (spikes) which contain the spikes found in the model output.
  3. An info dictionary with info["stimulus_start"] and info["stimulus_end"] set.

API Reference

class uncertainpy.features.GeneralSpikingFeatures(new_features=None, features_to_run=u'all', interpolate=None, threshold=-30, end_threshold=-10, extended_spikes=False, trim=True, normalize=False, min_amplitude=0, min_duration=0, labels={}, logger_level=u'info')[source]

Class for calculating spikes of a model, works with single neuron models and voltage traces.

Parameters:
  • new_features ({None, callable, list of callables}) – The new features to add. The feature functions have the requirements stated in reference_feature. If None, no features are added. Default is None.

  • features_to_run ({“all”, None, str, list of feature names}, optional) – Which features to calculate uncertainties for. If "all", the uncertainties are calculated for all implemented and assigned features. If None, or an empty list [], no features are calculated. If str, only that feature is calculated. If list of feature names, all the listed features are calculated. Default is "all".

  • new_utility_methods ({None, list}, optional) – A list of new utility methods. All methods in this class that is not in the list of utility methods, is considered to be a feature. Default is None.

  • interpolate ({None, “all”, str, list of feature names}, optional) – Which features are irregular, meaning they have a varying number of time points between evaluations. An interpolation is performed on each irregular feature to create regular results. If "all", all features are interpolated. If None, or an empty list, no features are interpolated. If str, only that feature is interpolated. If list of feature names, all listed features are interpolated. Default is None.

  • threshold ({float, int, “auto”}, optional) – The threshold where the model result is considered to have a spike. If “auto” the threshold is set to the standard variation of the result. Default is -30.

  • end_threshold ({int, float}, optional) – The end threshold for a spike relative to the threshold. Generally negative values give the best results. Default is -10.

  • extended_spikes (bool, optional) – If the found spikes should be extended further out than the threshold cuttoff. If True the spikes is considered to start and end where the derivative equals 0.5. Default is False.

  • trim (bool, optional) – If the spikes should be trimmed back from the termination threshold, so each spike is equal the threshold at both ends. Default is True.

  • normalize (bool, optional) – If the voltage traceshould be normalized before the spikes are found. If normalize is used threshold must be between [0, 1], and the end_threshold a similar relative value. Default is False.

  • min_amplitude ({int, float}, optional) – Minimum height for what should be considered a spike. Default is 0.

  • min_duration ({int, float}, optional) – Minimum duration for what should be considered a spike. Default is 0.

  • labels (dictionary, optional) – A dictionary with key as the feature name and the value as a list of labels for each axis. The number of elements in the list corresponds to the dimension of the feature. Example:

    new_labels = {"0d_feature": ["x-axis"],
                  "1d_feature": ["x-axis", "y-axis"],
                  "2d_feature": ["x-axis", "y-axis", "z-axis"]
                 }
    
  • logger_level ({“info”, “debug”, “warning”, “error”, “critical”, None}, optional) – Set the threshold for the logging level. Logging messages less severe than this level is ignored. If None, no logging is performed. Default logger level is “info”.

Variables:
  • spikes (Spikes object) – A Spikes object that contain all spikes.
  • threshold ({float, int, "auto"}, optional) – The threshold where the model result is considered to have a spike. If “auto” the threshold is set to the standard variation of the result. Default is -30.
  • end_threshold ({int, float}, optional) – The end threshold for a spike relative to the threshold. Default is -10.
  • extended_spikes (bool) – If the found spikes should be extended further out than the threshold cuttoff.
  • trim (bool) – If the spikes should be trimmed back from the termination threshold, so each spike is equal the threshold at both ends.
  • normalize (bool) – If the voltage traceshould be normalized before the spikes are found. If normalize is used threshold must be between [0, 1], and the end_threshold a similar relative value.
  • min_amplitude ({int, float}, optional) – Minimum height for what should be considered a spike. Default is 0.
  • min_duration ({int, float}, optional) – Minimum duration for what should be considered a spike. Default is 0.
  • features_to_run (list) – Which features to calculate uncertainties for.
  • interpolate (list) – A list of irregular features to be interpolated.
  • utility_methods (list) – A list of all utility methods implemented. All methods in this class that is not in the list of utility methods is considered to be a feature.
  • labels (dictionary) – Labels for the axes of each feature, used when plotting.

See also

uncertainpy.features.Features.reference_feature
reference_feature showing the requirements of a feature function.
uncertainpy.features.Spikes
Class for finding spikes in the model result.
add_features(new_features, labels={})

Add new features.

Parameters:
  • new_features ({callable, list of callables}) – The new features to add. The feature functions have the requirements stated in reference_feature.

  • labels (dictionary, optional) – A dictionary with the labels for the new features. The keys are the feature function names and the values are a list of labels for each axis. The number of elements in the list corresponds to the dimension of the feature. Example:

    new_labels = {"0d_feature": ["x-axis"],
                  "1d_feature": ["x-axis", "y-axis"],
                  "2d_feature": ["x-axis", "y-axis", "z-axis"]
                 }
    
Raises:

TypeError – Raises a TypeError if new_features is not callable or list of callables.

Notes

The features added are not added to features_to_run. features_to_run must be set manually afterwards.

See also

uncertainpy.features.Features.reference_feature()
reference_feature showing the requirements of a feature function.
calculate_all_features(*model_results)

Calculate all implemented features.

Parameters:*model_results – Variable length argument list. Is the values that model.run() returns. By default it contains time and values, and then any number of optional info values.
Returns:results – A dictionary where the keys are the feature names and the values are a dictionary with the time values time and feature results on values, on the form {"time": t, "values": U}.
Return type:dictionary
Raises:TypeError – If feature_name is a utility method.

Notes

Checks that the feature returns two values.

See also

uncertainpy.features.Features.calculate_feature()
Method for calculating a single feature.
calculate_feature(feature_name, *preprocess_results)

Calculate feature with feature_name.

Parameters:
  • feature_name (str) – Name of feature to calculate.
  • *preprocess_results – The values returned by preprocess. These values are sent as input arguments to each feature. By default preprocess returns the values that model.run() returns, which contains time and values, and then any number of optional info values. The implemented features require that info is a single dictionary with the information stored as key-value pairs. Certain features require specific keys to be present.
Returns:

  • time ({None, numpy.nan, array_like}) – Time values, or equivalent, of the feature, if no time values returns None or numpy.nan.
  • values (array_like) – The feature results, values must either be regular (have the same number of points for different paramaters) or be able to be interpolated.

Raises:

TypeError – If feature_name is a utility method.

See also

uncertainpy.models.Model.run()
The model run method
calculate_features(*model_results)

Calculate all features in features_to_run.

Parameters:*model_results – Variable length argument list. Is the values that model.run() returns. By default it contains time and values, and then any number of optional info values.
Returns:results – A dictionary where the keys are the feature names and the values are a dictionary with the time values time and feature results on values, on the form {"time": time, "values": values}.
Return type:dictionary
Raises:TypeError – If feature_name is a utility method.

Notes

Checks that the feature returns two values.

See also

uncertainpy.features.Features.calculate_feature()
Method for calculating a single feature.
calculate_spikes(time, values, threshold=-30, end_threshold=-10, extended_spikes=False, trim=True, normalize=False, min_amplitude=0, min_duration=0)[source]

Calculating spikes of a model result, works with single neuron models and voltage traces.

Parameters:
  • time ({None, numpy.nan, array_like}) – Time values of the model. If no time values it is None or numpy.nan.
  • values (array_like) – Result of the model.
  • threshold ({float, int, “auto”}, optional) – The threshold where the model result is considered to have a spike. If “auto” the threshold is set to the standard variation of the result. Default is -30.
  • end_threshold ({int, float}, optional) – The end threshold for a spike relative to the threshold. Default is -10.
  • extended_spikes (bool, optional) – If the found spikes should be extended further out than the threshold cuttoff. If True the spikes is considered to start and end where the derivative equals 0.5. Default is False.
  • trim (bool, optional) – If the spikes should be trimmed back from the termination threshold, so each spike is equal the threshold at both ends. Default is True.
  • normalize (bool, optional) – If the voltage traceshould be normalized before the spikes are found. If normalize is used threshold must be between [0, 1], and the end_threshold a similar relative value. Default is False.
  • min_amplitude ({int, float}, optional) – Minimum height for what should be considered a spike. Default is 0.
  • min_duration ({int, float}, optional) – Minimum duration for what should be considered a spike. Default is 0.
Returns:

  • time ({None, numpy.nan, array_like}) – Time values of the model. If no time values it returns None or numpy.nan.
  • values (Spikes) – The spikes found in the model results.

See also

uncertainpy.features.Features.reference_feature()
reference_feature showing the requirements of a feature function.
uncertainpy.features.Spikes()
Class for finding spikes in the model result.
features_to_run

Which features to calculate uncertainties for.

Parameters:new_features_to_run ({“all”, None, str, list of feature names}) – Which features to calculate uncertainties for. If "all", the uncertainties are calculated for all implemented and assigned features. If None, or an empty list , no features are calculated. If str, only that feature is calculated. If list of feature names, all listed features are calculated. Default is "all".
Returns:A list of features to calculate uncertainties for.
Return type:list
implemented_features()

Return a list of all callable methods in feature, that are not utility methods, does not starts with “_” and not a method of a general python object.

Returns:A list of all callable methods in feature, that are not utility methods.
Return type:list
interpolate

Features that require an interpolation.

Which features are interpolated, meaning they have a varying number of time points between evaluations. An interpolation is performed on each interpolated feature to create regular results.

Parameters:new_interpolate ({None, “all”, str, list of feature names}) – If "all", all features are interpolated. If None, or an empty list, no features are interpolated. If str, only that feature is interpolated. If list of feature names, all listed features are interpolated. Default is None.
Returns:A list of irregular features to be interpolated.
Return type:list
labels

Labels for the axes of each feature, used when plotting.

Parameters:

new_labels (dictionary) – A dictionary with key as the feature name and the value as a list of labels for each axis. The number of elements in the list corresponds to the dimension of the feature. Example:

new_labels = {"0d_feature": ["x-axis"],
              "1d_feature": ["x-axis", "y-axis"],
              "2d_feature": ["x-axis", "y-axis", "z-axis"]
             }
preprocess(time, values, info)[source]

Calculating spikes from the model result.

Parameters:
  • time ({None, numpy.nan, array_like}) – Time values of the model. If no time values it is None or numpy.nan.
  • values (array_like) – Result of the model.
  • info (dictionary) – A dictionary with info[“stimulus_start”] and info[“stimulus_end”].
Returns:

  • time ({None, numpy.nan, array_like}) – Time values of the model. If no time values it returns None or numpy.nan.
  • values (Spikes) – The spikes found in the model results.
  • info (dictionary) – A dictionary with info[“stimulus_start”] and info[“stimulus_end”].

Notes

Also sets self.values = values, so features have access to self.values if necessary.

See also

uncertainpy.models.Model.run()
The model run method
uncertainpy.features.Spikes()
Class for finding spikes in the model result.
reference_feature(time, spikes, info)[source]

An example of an GeneralSpikingFeature. The feature functions have the following requirements, and the input arguments must either be returned by Model.run or SpikingFeatures.preprocess.

Parameters:
  • time ({None, numpy.nan, array_like}) – Time values of the model. If no time values it is None or numpy.nan.
  • spikes (Spikes) – Spikes found in the model result.
  • info (dictionary) – A dictionary with info[“stimulus_start”] and info[“stimulus_end”] set.
Returns:

  • time ({None, numpy.nan, array_like}) – Time values, or equivalent, of the feature, if no time values return None or numpy.nan.
  • values (array_like) – The feature results, values. Returns None if there are no feature results and that evaluation are disregarded.

See also

uncertainpy.features.GeneralSpikingFeatures.preprocess()
The GeneralSpikingFeatures preprocess method.
uncertainpy.models.Model.run()
The model run method
validate(feature_name, *feature_result)

Validate the results from calculate_feature.

This method ensures each returns time, values.

Parameters:
  • model_results – Any type of model results returned by run.
  • feature_name (str) – Name of the feature, to create better error messages.
Raises:
  • ValueError – If the model result does not fit the requirements.
  • TypeError – If the model result does not fit the requirements.

Notes

Tries to verify that at least, time and values are returned from run. model_result should follow the format: return time, values, info_1, info_2, .... Where:

  • time_feature : {None, numpy.nan, array_like}

    Time values, or equivalent, of the feature, if no time values return None or numpy.nan.

  • values : {None, numpy.nan, array_like}

    The feature results, values must either be regular (have the same number of points for different paramaters) or be able to be interpolated. If there are no feature results return None or numpy.nan instead of values and that evaluation are disregarded.