API Reference¶
This part of the documentation details the complete BioSPPy
API.
Packages¶
Modules¶
biosppy.clustering¶
This module provides various unsupervised machine learning (clustering) algorithms.
copyright: |
|
---|---|
license: | BSD 3-clause, see LICENSE for more details. |
-
biosppy.clustering.
centroid_templates
(data=None, clusters=None, ntemplates=1)[source]¶ Template selection based on cluster centroids.
Parameters: - data (array) – An m by n array of m data samples in an n-dimensional space.
- clusters (dict) – Dictionary with the sample indices (rows from ‘data’) for each cluster.
- ntemplates (int, optional) – Number of templates to extract; if more than 1, k-means is used to obtain more templates.
Returns: templates (array) – Selected templates from the input data.
-
biosppy.clustering.
coassoc_partition
(coassoc=None, k=0, linkage='average')[source]¶ Extract the consensus partition from a co-association matrix using hierarchical agglomerative methods.
Parameters: - coassoc (array) – Co-association matrix.
- k (int, optional) – Number of clusters to extract; if 0 uses the life-time criterion.
- linkage (str, optional) – Linkage criterion for final partition extraction; one of ‘average’, ‘complete’, ‘single’, or ‘weighted’.
Returns: clusters (dict) – Dictionary with the sample indices (rows from ‘data’) for each found cluster; outliers have key -1; clusters are assigned integer keys starting at 0.
-
biosppy.clustering.
consensus
(data=None, k=0, linkage='average', fcn=None, grid=None)[source]¶ Perform clustering based in an ensemble of partitions.
Parameters: - data (array) – An m by n array of m data samples in an n-dimensional space.
- k (int, optional) – Number of clusters to extract; if 0 uses the life-time criterion.
- linkage (str, optional) – Linkage criterion for final partition extraction; one of ‘average’, ‘centroid’, ‘complete’, ‘median’, ‘single’, ‘ward’, or ‘weighted’.
- fcn (function) – A clustering function.
- grid (dict, list, optional) – A (list of) dictionary with parameters for each run of the clustering method (see sklearn.model_selection.ParameterGrid).
Returns: clusters (dict) – Dictionary with the sample indices (rows from ‘data’) for each found cluster; outliers have key -1; clusters are assigned integer keys starting at 0.
-
biosppy.clustering.
consensus_kmeans
(data=None, k=0, linkage='average', nensemble=100, kmin=None, kmax=None)[source]¶ Perform clustering based on an ensemble of k-means partitions.
Parameters: - data (array) – An m by n array of m data samples in an n-dimensional space.
- k (int, optional) – Number of clusters to extract; if 0 uses the life-time criterion.
- linkage (str, optional) – Linkage criterion for final partition extraction; one of ‘average’, ‘centroid’, ‘complete’, ‘median’, ‘single’, ‘ward’, or ‘weighted’.
- nensemble (int, optional) – Number of partitions in the ensemble.
- kmin (int, optional) – Minimum k for the k-means partitions; defaults to
.
- kmax (int, optional) – Maximum k for the k-means partitions; defaults to
.
Returns: clusters (dict) – Dictionary with the sample indices (rows from ‘data’) for each found cluster; outliers have key -1; clusters are assigned integer keys starting at 0.
-
biosppy.clustering.
create_coassoc
(ensemble=None, N=None)[source]¶ Create the co-association matrix from a clustering ensemble.
Parameters: - ensemble (list) – Clustering ensemble partitions.
- N (int) – Number of data samples.
Returns: coassoc (array) – Co-association matrix.
-
biosppy.clustering.
create_ensemble
(data=None, fcn=None, grid=None)[source]¶ Create an ensemble of partitions of the data using the given clustering method.
Parameters: - data (array) – An m by n array of m data samples in an n-dimensional space.
- fcn (function) – A clustering function.
- grid (dict, list, optional) – A (list of) dictionary with parameters for each run of the clustering method (see sklearn.model_selection.ParameterGrid).
Returns: ensemble (list) – Obtained ensemble partitions.
-
biosppy.clustering.
dbscan
(data=None, min_samples=5, eps=0.5, metric='euclidean', metric_args=None)[source]¶ Perform clustering using the DBSCAN algorithm [EKSX96].
The algorithm works by grouping data points that are closely packed together (with many nearby neighbors), marking as outliers points that lie in low-density regions.
Parameters: - data (array) – An m by n array of m data samples in an n-dimensional space.
- min_samples (int, optional) – Minimum number of samples in a cluster.
- eps (float, optional) – Maximum distance between two samples in the same cluster.
- metric (str, optional) – Distance metric (see scipy.spatial.distance).
- metric_args (dict, optional) – Additional keyword arguments to pass to the distance function.
Returns: clusters (dict) – Dictionary with the sample indices (rows from ‘data’) for each found cluster; outliers have key -1; clusters are assigned integer keys starting at 0.
References
[EKSX96] M. Ester, H. P. Kriegel, J. Sander, and X. Xu, “A Density-Based Algorithm for Discovering Clusters in Large Spatial Databases with Noise”, Proceedings of the 2nd International Conf. on Knowledge Discovery and Data Mining, pp. 226-231, 1996.
-
biosppy.clustering.
hierarchical
(data=None, k=0, linkage='average', metric='euclidean', metric_args=None)[source]¶ Perform clustering using hierarchical agglomerative algorithms.
Parameters: - data (array) – An m by n array of m data samples in an n-dimensional space.
- k (int, optional) – Number of clusters to extract; if 0 uses the life-time criterion.
- linkage (str, optional) – Linkage criterion; one of ‘average’, ‘centroid’, ‘complete’, ‘median’, ‘single’, ‘ward’, or ‘weighted’.
- metric (str, optional) – Distance metric (see ‘biosppy.metrics’).
- metric_args (dict, optional) – Additional keyword arguments to pass to the distance function.
Returns: clusters (dict) – Dictionary with the sample indices (rows from ‘data’) for each found cluster; outliers have key -1; clusters are assigned integer keys starting at 0.
Raises: TypeError
– If ‘metric’ is not a string.ValueError
– When the ‘linkage’ is unknown.ValueError
– When ‘metric’ is not ‘euclidean’ when using ‘centroid’, ‘median’, or ‘ward’ linkage.ValueError
– When ‘k’ is larger than the number of data samples.
-
biosppy.clustering.
kmeans
(data=None, k=None, init='random', max_iter=300, n_init=10, tol=0.0001)[source]¶ Perform clustering using the k-means algorithm.
Parameters: - data (array) – An m by n array of m data samples in an n-dimensional space.
- k (int) – Number of clusters to extract.
- init (str, array, optional) – If string, one of ‘random’ or ‘k-means++’; if array, it should be of shape (n_clusters, n_features), specifying the initial centers.
- max_iter (int, optional) – Maximum number of iterations.
- n_init (int, optional) – Number of initializations.
- tol (float, optional) – Relative tolerance to declare convergence.
Returns: clusters (dict) – Dictionary with the sample indices (rows from ‘data’) for each found cluster; outliers have key -1; clusters are assigned integer keys starting at 0.
-
biosppy.clustering.
mdist_templates
(data=None, clusters=None, ntemplates=1, metric='euclidean', metric_args=None)[source]¶ Template selection based on the MDIST method [UlRJ04].
Extends the original method with the option of also providing a data clustering, in which case the MDIST criterion is applied for each cluster [LCSF14].
Parameters: - data (array) – An m by n array of m data samples in an n-dimensional space.
- clusters (dict, optional) – Dictionary with the sample indices (rows from data) for each cluster.
- ntemplates (int, optional) – Number of templates to extract.
- metric (str, optional) – Distance metric (see scipy.spatial.distance).
- metric_args (dict, optional) – Additional keyword arguments to pass to the distance function.
Returns: templates (array) – Selected templates from the input data.
References
[UlRJ04] U. Uludag, A. Ross, A. Jain, “Biometric template selection and update: a case study in fingerprints”, Pattern Recognition 37, 2004 [LCSF14] A. Lourenco, C. Carreiras, H. Silva, A. Fred, “ECG biometrics: A template selection approach”, 2014 IEEE International Symposium on Medical Measurements and Applications (MeMeA), 2014
-
biosppy.clustering.
outliers_dbscan
(data=None, min_samples=5, eps=0.5, metric='euclidean', metric_args=None)[source]¶ Perform outlier removal using the DBSCAN algorithm.
Parameters: - data (array) – An m by n array of m data samples in an n-dimensional space.
- min_samples (int, optional) – Minimum number of samples in a cluster.
- eps (float, optional) – Maximum distance between two samples in the same cluster.
- metric (str, optional) – Distance metric (see scipy.spatial.distance).
- metric_args (dict, optional) – Additional keyword arguments to pass to the distance function.
Returns: - clusters (dict) – Dictionary with the sample indices (rows from ‘data’) for the outliers (key -1) and the normal (key 0) groups.
- templates (dict) – Elements from ‘data’ for the outliers (key -1) and the normal (key 0) groups.
-
biosppy.clustering.
outliers_dmean
(data=None, alpha=0.5, beta=1.5, metric='euclidean', metric_args=None, max_idx=None)[source]¶ Perform outlier removal using the DMEAN algorithm [LCSF13].
- A sample is considered valid if it cumulatively verifies:
- distance to average template smaller than a (data derived) threshold ‘T’;
- sample minimum greater than a (data derived) threshold ‘M’;
- sample maximum smaller than a (data derived) threshold ‘N’;
- position of the sample maximum is the same as the given index [optional].
For a set of
samples:
Parameters: - data (array) – An m by n array of m data samples in an n-dimensional space.
- alpha (float, optional) – Parameter for the distance threshold.
- beta (float, optional) – Parameter for the maximum and minimum thresholds.
- metric (str, optional) – Distance metric (see scipy.spatial.distance).
- metric_args (dict, optional) – Additional keyword arguments to pass to the distance function.
- max_idx (int, optional) – Index of the expected maximum.
Returns: - clusters (dict) – Dictionary with the sample indices (rows from ‘data’) for the outliers (key -1) and the normal (key 0) groups.
- templates (dict) – Elements from ‘data’ for the outliers (key -1) and the normal (key 0) groups.
References
[LCSF13] A. Lourenco, H. Silva, C. Carreiras, A. Fred, “Outlier Detection in Non-intrusive ECG Biometric System”, Image Analysis and Recognition, vol. 7950, pp. 43-52, 2013
biosppy.metrics¶
This module provides pairwise distance computation methods.
copyright: |
|
---|---|
license: | BSD 3-clause, see LICENSE for more details. |
-
biosppy.metrics.
cdist
(XA, XB, metric='euclidean', p=2, V=None, VI=None, w=None)[source]¶ Computes distance between each pair of the two collections of inputs.
Wraps scipy.spatial.distance.cdist.
Parameters: - XA (array) – An
by
array of
original observations in an
-dimensional space.
- XB (array) – An
by
array of
original observations in an
-dimensional space.
- metric (str, function, optional) – The distance metric to use; the distance can be ‘braycurtis’, ‘canberra’, ‘chebyshev’, ‘cityblock’, ‘correlation’, ‘cosine’, ‘dice’, ‘euclidean’, ‘hamming’, ‘jaccard’, ‘kulsinski’, ‘mahalanobis’, ‘matching’, ‘minkowski’, ‘pcosine’, ‘rogerstanimoto’, ‘russellrao’, ‘seuclidean’, ‘sokalmichener’, ‘sokalsneath’, ‘sqeuclidean’, ‘yule’.
- p (float, optional) – The p-norm to apply (for Minkowski, weighted and unweighted).
- w (array, optional) – The weight vector (for weighted Minkowski).
- V (array, optional) – The variance vector (for standardized Euclidean).
- VI (array, optional) – The inverse of the covariance matrix (for Mahalanobis).
Returns: Y (array) – An
by
distance matrix is returned. For each
and
, the metric
dist(u=XA[i], v=XB[j])
is computed and stored in theth entry.
- XA (array) – An
-
biosppy.metrics.
pcosine
(u, v)[source]¶ Computes the Cosine distance (positive space) between 1-D arrays.
The Cosine distance (positive space) between u and v is defined as
where
is the dot product of
and
.
Parameters: - u (array) – Input array.
- v (array) – Input array.
Returns: cosine (float) – Cosine distance between u and v.
-
biosppy.metrics.
pdist
(X, metric='euclidean', p=2, w=None, V=None, VI=None)[source]¶ Pairwise distances between observations in n-dimensional space.
Wraps scipy.spatial.distance.pdist.
Parameters: - X (array) – An m by n array of m original observations in an n-dimensional space.
- metric (str, function, optional) – The distance metric to use; the distance can be ‘braycurtis’, ‘canberra’, ‘chebyshev’, ‘cityblock’, ‘correlation’, ‘cosine’, ‘dice’, ‘euclidean’, ‘hamming’, ‘jaccard’, ‘kulsinski’, ‘mahalanobis’, ‘matching’, ‘minkowski’, ‘pcosine’, ‘rogerstanimoto’, ‘russellrao’, ‘seuclidean’, ‘sokalmichener’, ‘sokalsneath’, ‘sqeuclidean’, ‘yule’.
- p (float, optional) – The p-norm to apply (for Minkowski, weighted and unweighted).
- w (array, optional) – The weight vector (for weighted Minkowski).
- V (array, optional) – The variance vector (for standardized Euclidean).
- VI (array, optional) – The inverse of the covariance matrix (for Mahalanobis).
Returns: Y (array) – Returns a condensed distance matrix Y. For each
and
(where
), the metric
dist(u=X[i], v=X[j])
is computed and stored in entryij
.
-
biosppy.metrics.
squareform
(X, force='no', checks=True)[source]¶ Converts a vector-form distance vector to a square-form distance matrix, and vice-versa.
Wraps scipy.spatial.distance.squareform.
Parameters: - X (array) – Either a condensed or redundant distance matrix.
- force (str, optional) – As with MATLAB(TM), if force is equal to ‘tovector’ or ‘tomatrix’, the input will be treated as a distance matrix or distance vector respectively.
- checks (bool, optional) – If checks is set to False, no checks will be made for matrix
symmetry nor zero diagonals. This is useful if it is known that
X - X.T1
is small anddiag(X)
is close to zero. These values are ignored any way so they do not disrupt the squareform transformation.
Returns: Y (array) – If a condensed distance matrix is passed, a redundant one is returned, or if a redundant one is passed, a condensed distance matrix is returned.
biosppy.plotting¶
This module provides utilities to plot data.
copyright: |
|
---|---|
license: | BSD 3-clause, see LICENSE for more details. |
-
biosppy.plotting.
plot_abp
(ts=None, raw=None, filtered=None, onsets=None, heart_rate_ts=None, heart_rate=None, path=None, show=False)[source]¶ Create a summary plot from the output of signals.abp.abp.
Parameters: - ts (array) – Signal time axis reference (seconds).
- raw (array) – Raw ABP signal.
- filtered (array) – Filtered ABP signal.
- onsets (array) – Indices of ABP pulse onsets.
- heart_rate_ts (array) – Heart rate time axis reference (seconds).
- heart_rate (array) – Instantaneous heart rate (bpm).
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
-
biosppy.plotting.
plot_acc
(ts=None, raw=None, vm=None, sm=None, path=None, show=False)[source]¶ Create a summary plot from the output of signals.acc.acc.
Parameters: - ts (array) – Signal time axis reference (seconds).
- raw (array) – Raw ACC signal.
- vm (array) – Vector Magnitude feature of the signal.
- sm (array) – Signal Magnitude feature of the signal
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
-
biosppy.plotting.
plot_bcg
(ts=None, raw=None, filtered=None, jpeaks=None, templates_ts=None, templates=None, heart_rate_ts=None, heart_rate=None, path=None, show=False)[source]¶ Create a summary plot from the output of signals.bcg.bcg.
Parameters: - ts (array) – Signal time axis reference (seconds).
- raw (array) – Raw ECG signal.
- filtered (array) – Filtered ECG signal.
- ipeaks (array) – I-peak location indices.
- templates_ts (array) – Templates time axis reference (seconds).
- templates (array) – Extracted heartbeat templates.
- heart_rate_ts (array) – Heart rate time axis reference (seconds).
- heart_rate (array) – Instantaneous heart rate (bpm).
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
-
biosppy.plotting.
plot_biometrics
(assessment=None, eer_idx=None, path=None, show=False)[source]¶ Create a summary plot of a biometrics test run.
Parameters: - assessment (dict) – Classification assessment results.
- eer_idx (int, optional) – Classifier reference index for the Equal Error Rate.
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
-
biosppy.plotting.
plot_bvp
(ts=None, raw=None, filtered=None, onsets=None, heart_rate_ts=None, heart_rate=None, path=None, show=False)[source]¶ Create a summary plot from the output of signals.bvp.bvp.
Parameters: - ts (array) – Signal time axis reference (seconds).
- raw (array) – Raw BVP signal.
- filtered (array) – Filtered BVP signal.
- onsets (array) – Indices of BVP pulse onsets.
- heart_rate_ts (array) – Heart rate time axis reference (seconds).
- heart_rate (array) – Instantaneous heart rate (bpm).
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
-
biosppy.plotting.
plot_clustering
(data=None, clusters=None, path=None, show=False)[source]¶ Create a summary plot of a data clustering.
Parameters: - data (array) – An m by n array of m data samples in an n-dimensional space.
- clusters (dict) – Dictionary with the sample indices (rows from data) for each cluster.
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
-
biosppy.plotting.
plot_ecg
(ts=None, raw=None, filtered=None, rpeaks=None, templates_ts=None, templates=None, heart_rate_ts=None, heart_rate=None, path=None, show=False)[source]¶ Create a summary plot from the output of signals.ecg.ecg.
Parameters: - ts (array) – Signal time axis reference (seconds).
- raw (array) – Raw ECG signal.
- filtered (array) – Filtered ECG signal.
- rpeaks (array) – R-peak location indices.
- templates_ts (array) – Templates time axis reference (seconds).
- templates (array) – Extracted heartbeat templates.
- heart_rate_ts (array) – Heart rate time axis reference (seconds).
- heart_rate (array) – Instantaneous heart rate (bpm).
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
-
biosppy.plotting.
plot_eda
(ts=None, raw=None, filtered=None, onsets=None, peaks=None, amplitudes=None, path=None, show=False)[source]¶ Create a summary plot from the output of signals.eda.eda.
Parameters: - ts (array) – Signal time axis reference (seconds).
- raw (array) – Raw EDA signal.
- filtered (array) – Filtered EDA signal.
- onsets (array) – Indices of SCR pulse onsets.
- peaks (array) – Indices of the SCR peaks.
- amplitudes (array) – SCR pulse amplitudes.
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
-
biosppy.plotting.
plot_eeg
(ts=None, raw=None, filtered=None, labels=None, features_ts=None, theta=None, alpha_low=None, alpha_high=None, beta=None, gamma=None, plf_pairs=None, plf=None, path=None, show=False)[source]¶ Create a summary plot from the output of signals.eeg.eeg.
Parameters: - ts (array) – Signal time axis reference (seconds).
- raw (array) – Raw EEG signal.
- filtered (array) – Filtered EEG signal.
- labels (list) – Channel labels.
- features_ts (array) – Features time axis reference (seconds).
- theta (array) – Average power in the 4 to 8 Hz frequency band; each column is one EEG channel.
- alpha_low (array) – Average power in the 8 to 10 Hz frequency band; each column is one EEG channel.
- alpha_high (array) – Average power in the 10 to 13 Hz frequency band; each column is one EEG channel.
- beta (array) – Average power in the 13 to 25 Hz frequency band; each column is one EEG channel.
- gamma (array) – Average power in the 25 to 40 Hz frequency band; each column is one EEG channel.
- plf_pairs (list) – PLF pair indices.
- plf (array) – PLF matrix; each column is a channel pair.
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
-
biosppy.plotting.
plot_emg
(ts=None, sampling_rate=None, raw=None, filtered=None, onsets=None, processed=None, path=None, show=False)[source]¶ Create a summary plot from the output of signals.emg.emg.
Parameters: - ts (array) – Signal time axis reference (seconds).
- sampling_rate (int, float) – Sampling frequency (Hz).
- raw (array) – Raw EMG signal.
- filtered (array) – Filtered EMG signal.
- onsets (array) – Indices of EMG pulse onsets.
- processed (array, optional) – Processed EMG signal according to the chosen onset detector.
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
-
biosppy.plotting.
plot_filter
(ftype='FIR', band='lowpass', order=None, frequency=None, sampling_rate=1000.0, path=None, show=True, **kwargs)[source]¶ Plot the frequency response of the filter specified with the given parameters.
Parameters: - ftype (str) –
- Filter type:
- Finite Impulse Response filter (‘FIR’);
- Butterworth filter (‘butter’);
- Chebyshev filters (‘cheby1’, ‘cheby2’);
- Elliptic filter (‘ellip’);
- Bessel filter (‘bessel’).
- band (str) –
- Band type:
- Low-pass filter (‘lowpass’);
- High-pass filter (‘highpass’);
- Band-pass filter (‘bandpass’);
- Band-stop filter (‘bandstop’).
- order (int) – Order of the filter.
- frequency (int, float, list, array) –
- Cutoff frequencies; format depends on type of band:
- ’lowpass’ or ‘bandpass’: single frequency;
- ’bandpass’ or ‘bandstop’: pair of frequencies.
- sampling_rate (int, float, optional) – Sampling frequency (Hz).
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
- **kwargs (dict, optional) – Additional keyword arguments are passed to the underlying scipy.signal function.
- ftype (str) –
-
biosppy.plotting.
plot_pcg
(ts=None, raw=None, filtered=None, peaks=None, heart_sounds=None, heart_rate_ts=None, inst_heart_rate=None, path=None, show=False)[source]¶ Create a summary plot from the output of signals.pcg.pcg. :param ts: Signal time axis reference (seconds). :type ts: array :param raw: Raw PCG signal. :type raw: array :param filtered: Filtered PCG signal. :type filtered: array :param peaks: Peak location indices. :type peaks: array :param heart_sounds: Classification of peaks as S1 or S2 :type heart_sounds: array :param heart_rate_ts: Heart rate time axis reference (seconds). :type heart_rate_ts: array :param inst_heart_rate: Instantaneous heart rate (bpm). :type inst_heart_rate: array :param path: If provided, the plot will be saved to the specified file. :type path: str, optional :param show: If True, show the plot immediately. :type show: bool, optional
-
biosppy.plotting.
plot_ppg
(ts=None, raw=None, filtered=None, onsets=None, heart_rate_ts=None, heart_rate=None, path=None, show=False)[source]¶ Create a summary plot from the output of signals.ppg.ppg.
Parameters: - ts (array) – Signal time axis reference (seconds).
- raw (array) – Raw PPG signal.
- filtered (array) – Filtered PPG signal.
- onsets (array) – Indices of PPG pulse onsets.
- heart_rate_ts (array) – Heart rate time axis reference (seconds).
- heart_rate (array) – Instantaneous heart rate (bpm).
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
-
biosppy.plotting.
plot_resp
(ts=None, raw=None, filtered=None, zeros=None, resp_rate_ts=None, resp_rate=None, path=None, show=False)[source]¶ Create a summary plot from the output of signals.ppg.ppg.
Parameters: - ts (array) – Signal time axis reference (seconds).
- raw (array) – Raw Resp signal.
- filtered (array) – Filtered Resp signal.
- zeros (array) – Indices of Respiration zero crossings.
- resp_rate_ts (array) – Respiration rate time axis reference (seconds).
- resp_rate (array) – Instantaneous respiration rate (Hz).
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
-
biosppy.plotting.
plot_spectrum
(signal=None, sampling_rate=1000.0, path=None, show=True)[source]¶ Plot the power spectrum of a signal (one-sided).
Parameters: - signal (array) – Input signal.
- sampling_rate (int, float, optional) – Sampling frequency (Hz).
- path (str, optional) – If provided, the plot will be saved to the specified file.
- show (bool, optional) – If True, show the plot immediately.
biosppy.timing¶
This module provides simple methods to measure computation times.
copyright: |
|
---|---|
license: | BSD 3-clause, see LICENSE for more details. |
-
biosppy.timing.
clear
(name=None)[source]¶ Clear the clock.
Parameters: name (str, optional) – Name of the clock; if None, uses the default name.
biosppy.utils¶
This module provides several frequently used functions and hacks.
copyright: |
|
---|---|
license: | BSD 3-clause, see LICENSE for more details. |
-
class
biosppy.utils.
ReturnTuple
(values, names=None)[source]¶ Bases:
tuple
A named tuple to use as a hybrid tuple-dict return object.
Parameters: - values (iterable) – Return values.
- names (iterable, optional) – Names for return values.
Raises: ValueError
– If the number of values differs from the number of names.ValueError
– If any of the items in names: * contain non-alphanumeric characters; * are Python keywords; * start with a number; * are duplicates.
-
biosppy.utils.
fileparts
(path)[source]¶ split a file path into its directory, name, and extension.
Parameters: path (str) – Input file path. Returns: - dirname (str) – File directory.
- fname (str) – File name.
- ext (str) – File extension.
Notes
- Removes the dot (‘.’) from the extension.
-
biosppy.utils.
fullfile
(*args)[source]¶ Join one or more file path components, assuming the last is the extension.
Parameters: *args (list, optional) – Components to concatenate. Returns: fpath (str) – The concatenated file path.
-
biosppy.utils.
highestAveragesAllocator
(votes, k, divisor='dHondt', check=False)[source]¶ Allocate k seats proportionally using the Highest Averages Method.
Parameters: - votes (list) – Number of votes for each class/party/cardinal.
- k (int) – Total number o seats to allocate.
- divisor (str, optional) – Divisor method; one of ‘dHondt’, ‘Huntington-Hill’, ‘Sainte-Lague’, ‘Imperiali’, or ‘Danish’.
- check (bool, optional) – If True, limits the number of seats to the total number of votes.
Returns: seats (list) – Number of seats for each class/party/cardinal.
-
biosppy.utils.
normpath
(path)[source]¶ Normalize a path.
Parameters: path (str) – The path to normalize. Returns: npath (str) – The normalized path.
-
biosppy.utils.
random_fraction
(indx, fraction, sort=True)[source]¶ Select a random fraction of an input list of elements.
Parameters: - indx (list, array) – Elements to partition.
- fraction (int, float) – Fraction to select.
- sort (bool, optional) – If True, output lists will be sorted.
Returns: - use (list, array) – Selected elements.
- unuse (list, array) – Remaining elements.
-
biosppy.utils.
remainderAllocator
(votes, k, reverse=True, check=False)[source]¶ Allocate k seats proportionally using the Remainder Method.
Also known as Hare-Niemeyer Method. Uses the Hare quota.
Parameters: - votes (list) – Number of votes for each class/party/cardinal.
- k (int) – Total number o seats to allocate.
- reverse (bool, optional) – If True, allocates remaining seats largest quota first.
- check (bool, optional) – If True, limits the number of seats to the total number of votes.
Returns: seats (list) – Number of seats for each class/party/cardinal.
-
biosppy.utils.
walktree
(top=None, spec=None)[source]¶ Iterator to recursively descend a directory and return all files matching the spec.
Parameters: - top (str, optional) – Starting directory; if None, defaults to the current working directoty.
- spec (str, optional) –
Regular expression to match the desired files; if None, matches all files; typical patterns:
- r’.txt$’ - matches files with ‘.txt’ extension;
- r’^File_’ - matches files starting with ‘File_’
- r’^File_.+.txt$’ - matches files starting with ‘File_’ and ending with the ‘.txt’ extension.
Yields: fpath (str) – Absolute file path.
Notes
- Partial matches are also selected.