diff --git a/core/processes/peaks.py b/core/processes/peaks.py new file mode 100644 index 0000000000000000000000000000000000000000..15ddf950ea1ebb16a6a46177474dbec14489e1f3 --- /dev/null +++ b/core/processes/peaks.py @@ -0,0 +1,44 @@ +from scipy.signal import argrelmax, argrelmin +from postprocessor.core.processes.base import ParametersABC, ProcessABC + + +class PeaksParameters(ParametersABC): + """ + Parameters + type : str {minima, maxima, "all"}. Determines which type of peaks to identify + order : int Parameter to pass to scipy.signal.argrelextrema indicating + how many points to use for comparison. + """ + + def __init__(self, type): + self.type = type + + @classmethod + def default(cls): + return cls.from_dict({"type": "minima", "order": 3}) + + +class Peaks(ProcessABC): + """ + Identifies a signal sharply dropping. + """ + + def __init__(self, parameters: PeaksParameters): + super().__init__(parameters) + + def run(self, signal: pd.DataFrame): + """ + Returns a boolean dataframe with the same shape as the + original signal but with peaks as true values. + """ + peaks_mat = np.zeros_like(signal, dtype=bool) + + comparator = np.less if self.parameters.type is "minima" else np.greater + peaks_ids = argrelextrema(new_df, comparator=comparator, order=order) + peaks_mat[peak_ids] = True + + return pd.DataFrame( + peaks_mat, + index=signal.index, + columns=signal.columns, + ) diff --git a/core/processes/savgol.py b/core/processes/savgol.py index 79fcdcaa9b3bc99ed585a250367a9ba2baf13d7c..b006c42202139221db68dd4f77df3b67a51612d0 100644 --- a/core/processes/savgol.py +++ b/core/processes/savgol.py @@ -25,7 +25,6 @@ class Savgol(ProcessABC): """ Apply Savitzky-Golay filter (works with NaNs, but it might return NaN regions). - """ def __init__(self, parameters: SavgolParameters): @@ -38,7 +37,7 @@ class Savgol(ProcessABC): return signal.apply(savgol_on_srs, 1) @staticmethod - def non_uniform_savgol(x, y, window, polynom): + def non_uniform_savgol(x, y, window: int, polynom: int): """ Applies a Savitzky-Golay filter to y with non-uniform spacing as defined in x diff --git a/core/processes/template.py b/core/processes/template.py new file mode 100644 index 0000000000000000000000000000000000000000..075f21b2a91993958829a09636c20acb7ccce412 --- /dev/null +++ b/core/processes/template.py @@ -0,0 +1,29 @@ +from postprocessor.core.processes.base import ParametersABC, ProcessABC +from postprocessor.core.functions.tracks import clean_tracks, merge_tracks, join_tracks + + +class ParametersTemplate(ParametersABC): + """ + Parameters + """ + + def __init__( + self, + ): + super().__init__() + + @classmethod + def default(cls): + return cls.from_dict({}) + + +class ProcessTemplate(ProcessABC): + """ + Template for process class. + """ + + def __init__(self, parameters: ParametersTemplate): + super().__init__(parameters) + + def run(self): + pass