From cc0c08392f2670bd83cd16bc62b31008328d444d Mon Sep 17 00:00:00 2001 From: SaraPido Date: Wed, 8 May 2024 18:36:01 +0000 Subject: [PATCH 1/6] band rms --- sigpro/aggregations/frequency/band.py | 38 +++++++++++++++++++ sigpro/basic_primitives.py | 19 ++++++++++ .../aggregations/frequency/band/band_rms.json | 37 ++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 sigpro/primitives/sigpro/aggregations/frequency/band/band_rms.json diff --git a/sigpro/aggregations/frequency/band.py b/sigpro/aggregations/frequency/band.py index bad8f3b..465c010 100644 --- a/sigpro/aggregations/frequency/band.py +++ b/sigpro/aggregations/frequency/band.py @@ -4,6 +4,7 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency): + """Compute the mean values for a specific band. Filter between a high and low band and compute the mean value for this specific band. @@ -22,9 +23,46 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency): float: Mean value for the given band. """ + lower_frequency_than = frequency_values <= max_frequency higher_frequency_than = frequency_values >= min_frequency selected_idx = np.where(higher_frequency_than & lower_frequency_than) selected_values = amplitude_values[selected_idx] return np.mean(selected_values) + + + +def band_rms(amplitude_values, frequency_values, min_frequency, max_frequency): + + """Compute the rms values for a specific band. + + Filter between a high and low band (inclusive) and compute the rms value for this + specific band. + + Args: + amplitude_values (np.ndarray): + A numpy array with the signal values. + frequency_values (np.ndarray): + A numpy array with the frequency values. + min_frequency (int or float): + Band minimum. + max_frequency (int or float): + Band maximum. + + Returns: + float: + rms value for the given band. + """ + + lower_frequency_than = frequency_values <= max_frequency + higher_frequency_than = frequency_values >= min_frequency + + selected_idx = np.ravel(np.where(np.ravel(higher_frequency_than & lower_frequency_than))) + + selected_idx = [int(x) for x in selected_idx] + + selected_values = np.array(amplitude_values)[selected_idx] + + return np.sqrt(np.mean(np.square(selected_values))) + diff --git a/sigpro/basic_primitives.py b/sigpro/basic_primitives.py index 347d375..3dc77d4 100644 --- a/sigpro/basic_primitives.py +++ b/sigpro/basic_primitives.py @@ -177,3 +177,22 @@ def __init__(self, min_frequency, max_frequency): 'min_frequency': min_frequency, 'max_frequency': max_frequency}) self.set_fixed_hyperparameters({'min_frequency': {'type': 'float'}, 'max_frequency': {'type': 'float'}}) + +class BandRMS(primitive.FrequencyAggregation): + """ + BandMean primitive class. + + Filters between a high and low band and compute the mean value for this specific band. + + Args: + min_frequency (int or float): + Band minimum. + max_frequency (int or float): + Band maximum. + """ + + def __init__(self, min_frequency, max_frequency): + super().__init__('sigpro.aggregations.frequency.band.band_rms', init_params={ + 'min_frequency': min_frequency, 'max_frequency': max_frequency}) + self.set_fixed_hyperparameters({'min_frequency': {'type': 'float'}, + 'max_frequency': {'type': 'float'}}) diff --git a/sigpro/primitives/sigpro/aggregations/frequency/band/band_rms.json b/sigpro/primitives/sigpro/aggregations/frequency/band/band_rms.json new file mode 100644 index 0000000..74b2101 --- /dev/null +++ b/sigpro/primitives/sigpro/aggregations/frequency/band/band_rms.json @@ -0,0 +1,37 @@ +{ + "name": "sigpro.aggregations.frequency.band.band_rms", + "primitive": "sigpro.aggregations.frequency.band.band_rms", + "classifiers": { + "type": "aggregation", + "subtype": "frequency" + }, + "produce": { + "args": [ + { + "name": "amplitude_values", + "type": "numpy.ndarray" + }, + { + "name": "frequency_values", + "type": "numpy.ndarray" + } + ], + "output": [ + { + "name": "value", + "type": "float" + } + ] + }, + "hyperparameters": { + "fixed": { + "min_frequency": { + "type": "float" + }, + "max_frequency": { + "type": "float" + } + }, + "tunable": {} + } +} \ No newline at end of file From 93b8d61fd780f96c6db595184d2f13347e93f14d Mon Sep 17 00:00:00 2001 From: SaraPido Date: Wed, 8 May 2024 18:49:28 +0000 Subject: [PATCH 2/6] fix lint errors --- sigpro/aggregations/frequency/band.py | 6 +----- sigpro/basic_primitives.py | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/sigpro/aggregations/frequency/band.py b/sigpro/aggregations/frequency/band.py index 465c010..40c10fb 100644 --- a/sigpro/aggregations/frequency/band.py +++ b/sigpro/aggregations/frequency/band.py @@ -4,7 +4,6 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency): - """Compute the mean values for a specific band. Filter between a high and low band and compute the mean value for this specific band. @@ -23,7 +22,7 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency): float: Mean value for the given band. """ - + lower_frequency_than = frequency_values <= max_frequency higher_frequency_than = frequency_values >= min_frequency selected_idx = np.where(higher_frequency_than & lower_frequency_than) @@ -32,9 +31,7 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency): return np.mean(selected_values) - def band_rms(amplitude_values, frequency_values, min_frequency, max_frequency): - """Compute the rms values for a specific band. Filter between a high and low band (inclusive) and compute the rms value for this @@ -65,4 +62,3 @@ def band_rms(amplitude_values, frequency_values, min_frequency, max_frequency): selected_values = np.array(amplitude_values)[selected_idx] return np.sqrt(np.mean(np.square(selected_values))) - diff --git a/sigpro/basic_primitives.py b/sigpro/basic_primitives.py index 3dc77d4..9e9a7d6 100644 --- a/sigpro/basic_primitives.py +++ b/sigpro/basic_primitives.py @@ -178,6 +178,7 @@ def __init__(self, min_frequency, max_frequency): self.set_fixed_hyperparameters({'min_frequency': {'type': 'float'}, 'max_frequency': {'type': 'float'}}) + class BandRMS(primitive.FrequencyAggregation): """ BandMean primitive class. From a9a23c539d925a429ec37a2f3c020ab8d8f23f09 Mon Sep 17 00:00:00 2001 From: SaraPido Date: Wed, 8 May 2024 19:24:51 +0000 Subject: [PATCH 3/6] fix lint errors --- sigpro/aggregations/frequency/band.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sigpro/aggregations/frequency/band.py b/sigpro/aggregations/frequency/band.py index 40c10fb..f4d219c 100644 --- a/sigpro/aggregations/frequency/band.py +++ b/sigpro/aggregations/frequency/band.py @@ -5,7 +5,6 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency): """Compute the mean values for a specific band. - Filter between a high and low band and compute the mean value for this specific band. Args: @@ -33,7 +32,6 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency): def band_rms(amplitude_values, frequency_values, min_frequency, max_frequency): """Compute the rms values for a specific band. - Filter between a high and low band (inclusive) and compute the rms value for this specific band. From 4989221b53b21c405d970d670d7ee8370c5ac5cf Mon Sep 17 00:00:00 2001 From: SaraPido Date: Wed, 8 May 2024 19:28:36 +0000 Subject: [PATCH 4/6] fix lint errors --- sigpro/aggregations/frequency/band.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sigpro/aggregations/frequency/band.py b/sigpro/aggregations/frequency/band.py index f4d219c..5539188 100644 --- a/sigpro/aggregations/frequency/band.py +++ b/sigpro/aggregations/frequency/band.py @@ -4,7 +4,9 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency): - """Compute the mean values for a specific band. + """ + Compute the mean values for a specific band. + Filter between a high and low band and compute the mean value for this specific band. Args: @@ -31,7 +33,9 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency): def band_rms(amplitude_values, frequency_values, min_frequency, max_frequency): - """Compute the rms values for a specific band. + """ + Compute the rms values for a specific band. + Filter between a high and low band (inclusive) and compute the rms value for this specific band. From 0b231de36fad1b23251ee22f4f715927e3f81dc6 Mon Sep 17 00:00:00 2001 From: SaraPido Date: Wed, 8 May 2024 19:31:54 +0000 Subject: [PATCH 5/6] fix lint errors --- sigpro/aggregations/frequency/band.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sigpro/aggregations/frequency/band.py b/sigpro/aggregations/frequency/band.py index 5539188..83122a0 100644 --- a/sigpro/aggregations/frequency/band.py +++ b/sigpro/aggregations/frequency/band.py @@ -4,8 +4,7 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency): - """ - Compute the mean values for a specific band. + """Compute the mean values for a specific band. Filter between a high and low band and compute the mean value for this specific band. @@ -23,7 +22,6 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency): float: Mean value for the given band. """ - lower_frequency_than = frequency_values <= max_frequency higher_frequency_than = frequency_values >= min_frequency selected_idx = np.where(higher_frequency_than & lower_frequency_than) @@ -53,7 +51,6 @@ def band_rms(amplitude_values, frequency_values, min_frequency, max_frequency): float: rms value for the given band. """ - lower_frequency_than = frequency_values <= max_frequency higher_frequency_than = frequency_values >= min_frequency From 3e232aa41b2e78ac3837a78b263a78580dd3d93d Mon Sep 17 00:00:00 2001 From: SaraPido Date: Wed, 15 May 2024 18:59:16 +0000 Subject: [PATCH 6/6] fix band rms docstring and change band rms code --- sigpro/aggregations/frequency/band.py | 7 ++----- sigpro/basic_primitives.py | 5 +++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/sigpro/aggregations/frequency/band.py b/sigpro/aggregations/frequency/band.py index 83122a0..4fc983d 100644 --- a/sigpro/aggregations/frequency/band.py +++ b/sigpro/aggregations/frequency/band.py @@ -54,10 +54,7 @@ def band_rms(amplitude_values, frequency_values, min_frequency, max_frequency): lower_frequency_than = frequency_values <= max_frequency higher_frequency_than = frequency_values >= min_frequency - selected_idx = np.ravel(np.where(np.ravel(higher_frequency_than & lower_frequency_than))) - - selected_idx = [int(x) for x in selected_idx] - - selected_values = np.array(amplitude_values)[selected_idx] + selected_idx = np.ravel(np.where(higher_frequency_than & lower_frequency_than)) + selected_values = amplitude_values[selected_idx] return np.sqrt(np.mean(np.square(selected_values))) diff --git a/sigpro/basic_primitives.py b/sigpro/basic_primitives.py index 9e9a7d6..66c0ad1 100644 --- a/sigpro/basic_primitives.py +++ b/sigpro/basic_primitives.py @@ -181,9 +181,10 @@ def __init__(self, min_frequency, max_frequency): class BandRMS(primitive.FrequencyAggregation): """ - BandMean primitive class. + BandRMS primitive class. - Filters between a high and low band and compute the mean value for this specific band. + Filter between a high and low band (inclusive) and compute the rms value for this + specific band. Args: min_frequency (int or float):