From 99ecc9f198a27520ae0db11583844ee8263ff010 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 5 Feb 2024 09:20:19 -0700 Subject: [PATCH 01/44] only update test actions if using scos-actions mock sigan --- scos_actions/discover/__init__.py | 20 +++++++++++--------- scos_actions/settings.py | 4 ++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/scos_actions/discover/__init__.py b/scos_actions/discover/__init__.py index 84ba8e6e..0d8eeb64 100644 --- a/scos_actions/discover/__init__.py +++ b/scos_actions/discover/__init__.py @@ -3,16 +3,10 @@ from scos_actions.actions.monitor_sigan import MonitorSignalAnalyzer from scos_actions.actions.sync_gps import SyncGps from scos_actions.discover.yaml import load_from_yaml -from scos_actions.settings import ACTION_DEFINITIONS_DIR +from scos_actions.settings import ACTION_DEFINITIONS_DIR, SIGAN_MODULE, SIGAN_CLASS actions = {"logger": Logger()} -test_actions = { - "test_sync_gps": SyncGps(parameters={"name": "test_sync_gps"}), - "test_monitor_sigan": MonitorSignalAnalyzer( - parameters={"name": "test_monitor_sigan"} - ), - "logger": Logger(), -} +test_actions = {} def init( @@ -31,4 +25,12 @@ def init( yaml_actions, yaml_test_actions = init() actions.update(yaml_actions) -test_actions.update(yaml_test_actions) +if SIGAN_MODULE == "scos_actions.hardware.mocks.mock_sigan" and SIGAN_CLASS == "MockSignalAnalyzer": + test_actions.update({ + "test_sync_gps": SyncGps(parameters={"name": "test_sync_gps"}), + "test_monitor_sigan": MonitorSignalAnalyzer( + parameters={"name": "test_monitor_sigan"} + ), + "logger": Logger() + }) + test_actions.update(yaml_test_actions) diff --git a/scos_actions/settings.py b/scos_actions/settings.py index fa63aaa1..bc7e9a93 100644 --- a/scos_actions/settings.py +++ b/scos_actions/settings.py @@ -27,6 +27,10 @@ logger.debug(f"scos-actions: RUNNING_TESTS:{RUNNING_TESTS}") FQDN = env("FQDN", None) logger.debug(f"scos-actions: FQDN:{FQDN}") +SIGAN_MODULE = env.str("SIGAN_MODULE", default="scos_actions.hardware.mocks.mock_sigan") +logger.debug(f"scos-actions: SIGAN_MODULE:{SIGAN_MODULE}") +SIGAN_CLASS = env.str("SIGAN_CLASS", default="MockSignalAnalyzer") +logger.debug(f"scos-actions: SIGAN_CLASS:{SIGAN_CLASS}") SIGAN_POWER_SWITCH = env("SIGAN_POWER_SWITCH", default=None) logger.debug(f"scos-actions: SIGAN_POWER_SWITCH:{SIGAN_POWER_SWITCH}") SIGAN_POWER_CYCLE_STATES = env("SIGAN_POWER_CYCLE_STATES", default=None) From d13baeec738bdd0e8a4eb625063e641fe3cb6097 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Tue, 6 Feb 2024 09:05:12 -0700 Subject: [PATCH 02/44] change configure preselector logic --- scos_actions/actions/interfaces/action.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/scos_actions/actions/interfaces/action.py b/scos_actions/actions/interfaces/action.py index 496723dd..7d64fd98 100644 --- a/scos_actions/actions/interfaces/action.py +++ b/scos_actions/actions/interfaces/action.py @@ -61,15 +61,16 @@ def configure_sigan(self, params: dict): def configure_preselector(self, params: dict): preselector = self.sensor.preselector - if self.PRESELECTOR_PATH_KEY in params: - path = params[self.PRESELECTOR_PATH_KEY] - logger.debug(f"Setting preselector RF path: {path}") - preselector.set_state(path) - elif self.sensor.has_configurable_preselector: - # Require the RF path to be specified if the sensor has a preselector. - raise ParameterException( - f"No {self.PRESELECTOR_PATH_KEY} value specified in the YAML config." - ) + if self.sensor.has_configurable_preselector: + if self.PRESELECTOR_PATH_KEY in params: + path = params[self.PRESELECTOR_PATH_KEY] + logger.debug(f"Setting preselector RF path: {path}") + preselector.set_state(path) + else: + # Require the RF path to be specified if the sensor has a preselector. + raise ParameterException( + f"No {self.PRESELECTOR_PATH_KEY} value specified in the YAML config." + ) else: # No preselector in use, so do not require an RF path pass From 9829efcbc77a05ec44b479c1a7b059a118f9aa1f Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Tue, 6 Feb 2024 09:48:20 -0700 Subject: [PATCH 03/44] configurable cal adjust for data product --- scos_actions/actions/acquire_sea_data_product.py | 12 ++++++++---- .../configs/actions/test_nasctn_sea_data_product.yml | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index 3409699a..618d9f5d 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -626,14 +626,18 @@ def capture_iq(self, params: dict) -> dict: nskip = utils.get_parameter(NUM_SKIP, params) num_samples = int(params[SAMPLE_RATE] * duration_ms * 1e-3) # Collect IQ data + cal_adjust = True + if "calibration_adjust" in params: + cal_adjust = params["calibration_adjust"] measurement_result = self.sensor.signal_analyzer.acquire_time_domain_samples( - num_samples, nskip + num_samples, nskip, cal_adjust=cal_adjust ) # Store some metadata with the IQ measurement_result.update(params) - measurement_result[ - "sensor_cal" - ] = self.sensor.signal_analyzer.sensor_calibration_data + if cal_adjust: + measurement_result[ + "sensor_cal" + ] = self.sensor.signal_analyzer.sensor_calibration_data toc = perf_counter() logger.debug( f"IQ Capture ({duration_ms} ms @ {(params[FREQUENCY]/1e6):.1f} MHz) completed in {toc-tic:.2f} s." diff --git a/scos_actions/configs/actions/test_nasctn_sea_data_product.yml b/scos_actions/configs/actions/test_nasctn_sea_data_product.yml index fca3a521..6eaea7ca 100644 --- a/scos_actions/configs/actions/test_nasctn_sea_data_product.yml +++ b/scos_actions/configs/actions/test_nasctn_sea_data_product.yml @@ -1,6 +1,7 @@ nasctn_sea_data_product: name: test_nasctn_sea_data_product rf_path: antenna + calibration_adjust: False # IIR filter settings iir_apply: True iir_gpass_dB: 0.1 # Max passband ripple below unity gain From 835e649976addd69182c4a688eb632c93c3044b9 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Tue, 6 Feb 2024 10:00:49 -0700 Subject: [PATCH 04/44] debug log messages --- scos_actions/actions/acquire_sea_data_product.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index 618d9f5d..83a36235 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -627,8 +627,11 @@ def capture_iq(self, params: dict) -> dict: num_samples = int(params[SAMPLE_RATE] * duration_ms * 1e-3) # Collect IQ data cal_adjust = True + for key, value in params.items(): + logger.debug(f"param {key}={value}") if "calibration_adjust" in params: cal_adjust = params["calibration_adjust"] + logger.debug(f"cal_adjust={cal_adjust}") measurement_result = self.sensor.signal_analyzer.acquire_time_domain_samples( num_samples, nskip, cal_adjust=cal_adjust ) From db5ae40db19e77889e640145c4a627a6f3f286ae Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Tue, 6 Feb 2024 10:52:56 -0700 Subject: [PATCH 05/44] only add sensor cal to capture if sensor cal in result --- scos_actions/actions/acquire_sea_data_product.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index 83a36235..7748342c 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -1128,19 +1128,20 @@ def create_capture_segment( datetime=measurement_result["capture_time"], duration=measurement_result[DURATION_MS], overload=measurement_result["overload"], - sensor_calibration=ntia_sensor.Calibration( - datetime=measurement_result["sensor_cal"]["datetime"], - gain=round(measurement_result["sensor_cal"]["gain"], 3), - noise_figure=round(measurement_result["sensor_cal"]["noise_figure"], 3), - temperature=round(measurement_result["sensor_cal"]["temperature"], 1), - reference=DATA_REFERENCE_POINT, - ), sigan_settings=ntia_sensor.SiganSettings( reference_level=self.sensor.signal_analyzer.reference_level, attenuation=self.sensor.signal_analyzer.attenuation, preamp_enable=self.sensor.signal_analyzer.preamp_enable, ), ) + if "sensor_cal" in measurement_result: + capture_segment.sensor_calibration=ntia_sensor.Calibration( + datetime=measurement_result["sensor_cal"]["datetime"], + gain=round(measurement_result["sensor_cal"]["gain"], 3), + noise_figure=round(measurement_result["sensor_cal"]["noise_figure"], 3), + temperature=round(measurement_result["sensor_cal"]["temperature"], 1), + reference=DATA_REFERENCE_POINT, + ), self.sigmf_builder.add_capture(capture_segment) def get_sigmf_builder( From d9e6f887dac8dec74c3afc6e28bdaeef9a243c4e Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Tue, 6 Feb 2024 11:07:25 -0700 Subject: [PATCH 06/44] only set cal datetime if cal_adjust --- scos_actions/actions/acquire_single_freq_tdomain_iq.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scos_actions/actions/acquire_single_freq_tdomain_iq.py b/scos_actions/actions/acquire_single_freq_tdomain_iq.py index 0eb55655..60559d7a 100644 --- a/scos_actions/actions/acquire_single_freq_tdomain_iq.py +++ b/scos_actions/actions/acquire_single_freq_tdomain_iq.py @@ -89,9 +89,10 @@ def execute(self, schedule_entry: dict, task_id: int) -> dict: measurement_result.update(self.parameters) measurement_result["end_time"] = end_time measurement_result["task_id"] = task_id - measurement_result[ - "calibration_datetime" - ] = self.sensor.signal_analyzer.sensor_calibration_data["datetime"] + if self.cal_adjust: + measurement_result[ + "calibration_datetime" + ] = self.sensor.signal_analyzer.sensor_calibration_data["datetime"] measurement_result["classification"] = self.classification sigan_settings = self.get_sigan_settings(measurement_result) logger.debug(f"sigan settings:{sigan_settings}") From 002ec32f20e26a2f9e32636822571951a172dc9e Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Fri, 9 Feb 2024 14:41:47 -0700 Subject: [PATCH 07/44] check for cal data before gettting cal datetime, memory debug --- scos_actions/actions/acquire_single_freq_fft.py | 7 ++++--- scos_actions/actions/acquire_stepped_freq_tdomain_iq.py | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/scos_actions/actions/acquire_single_freq_fft.py b/scos_actions/actions/acquire_single_freq_fft.py index aa6f16ba..494d6406 100644 --- a/scos_actions/actions/acquire_single_freq_fft.py +++ b/scos_actions/actions/acquire_single_freq_fft.py @@ -177,9 +177,10 @@ def execute(self, schedule_entry: dict, task_id: int) -> dict: # Save measurement results measurement_result["data"] = m4s_result measurement_result.update(self.parameters) - measurement_result[ - "calibration_datetime" - ] = self.sensor.signal_analyzer.sensor_calibration_data["datetime"] + if self.sensor.signal_analyzer.sensor_calibration_data: + measurement_result[ + "calibration_datetime" + ] = self.sensor.signal_analyzer.sensor_calibration_data["datetime"] measurement_result["task_id"] = task_id measurement_result["classification"] = self.classification diff --git a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py index 495be7e2..228ebd07 100644 --- a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py +++ b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py @@ -38,6 +38,7 @@ import logging import numpy as np +import tracemalloc from scos_actions.actions.acquire_single_freq_tdomain_iq import ( CAL_ADJUST, DURATION_MS, @@ -89,6 +90,7 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): self._sensor = sensor self.test_required_components() saved_samples = 0 + last_snapshot = None for recording_id, measurement_params in enumerate( self.iterable_params, start=1 @@ -143,6 +145,13 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): metadata=self.sigmf_builder.metadata, ) saved_samples += num_samples + snapshot = tracemalloc.take_snapshot() + if last_snapshot: + stats = snapshot.compare_to(last_snapshot, 'lineno') + logger.debug("memory snapshot comparison") + for stat in stats[:10]: + logger.debug(stat) + last_snapshot = snapshot @property def description(self): From e070087b3adf3d4a3cb501efa649a36cdbcfdddf Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Fri, 9 Feb 2024 14:47:56 -0700 Subject: [PATCH 08/44] memory debug --- scos_actions/actions/acquire_stepped_freq_tdomain_iq.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py index 228ebd07..d710dbf2 100644 --- a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py +++ b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py @@ -91,6 +91,7 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): self.test_required_components() saved_samples = 0 last_snapshot = None + tracemalloc.start() for recording_id, measurement_params in enumerate( self.iterable_params, start=1 From c0543762f682ca1b53191892ed716b99e7f1b9fe Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Fri, 9 Feb 2024 15:13:47 -0700 Subject: [PATCH 09/44] log messages for debug --- .../actions/acquire_stepped_freq_tdomain_iq.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py index d710dbf2..7e1359dd 100644 --- a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py +++ b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py @@ -104,6 +104,7 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): sample_rate = self.sensor.signal_analyzer.sample_rate num_samples = int(sample_rate * duration_ms * 1e-3) measurement_result = super().acquire_data(num_samples, nskip, cal_adjust) + logger.debug("Acquired measurement_result") measurement_result.update(measurement_params) end_time = utils.get_datetime_str_now() measurement_result["end_time"] = end_time @@ -138,14 +139,8 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): ) measurement_result["capture_segment"] = capture_segment + logger.debug("Creating metadata for measurement result") self.create_metadata(measurement_result, recording_id) - measurement_action_completed.send( - sender=self.__class__, - task_id=task_id, - data=measurement_result["data"], - metadata=self.sigmf_builder.metadata, - ) - saved_samples += num_samples snapshot = tracemalloc.take_snapshot() if last_snapshot: stats = snapshot.compare_to(last_snapshot, 'lineno') @@ -153,6 +148,15 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): for stat in stats[:10]: logger.debug(stat) last_snapshot = snapshot + logger.debug("sending measurement result to handler") + measurement_action_completed.send( + sender=self.__class__, + task_id=task_id, + data=measurement_result["data"], + metadata=self.sigmf_builder.metadata, + ) + saved_samples += num_samples + @property def description(self): From ea2eefec44ab7ae4fd142a21a3d49e05e777cb4a Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Fri, 9 Feb 2024 15:26:40 -0700 Subject: [PATCH 10/44] comment out debug --- .../actions/acquire_stepped_freq_tdomain_iq.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py index 7e1359dd..e859e5b7 100644 --- a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py +++ b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py @@ -90,8 +90,8 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): self._sensor = sensor self.test_required_components() saved_samples = 0 - last_snapshot = None - tracemalloc.start() + #last_snapshot = None + #tracemalloc.start() for recording_id, measurement_params in enumerate( self.iterable_params, start=1 @@ -141,13 +141,13 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): logger.debug("Creating metadata for measurement result") self.create_metadata(measurement_result, recording_id) - snapshot = tracemalloc.take_snapshot() - if last_snapshot: - stats = snapshot.compare_to(last_snapshot, 'lineno') - logger.debug("memory snapshot comparison") - for stat in stats[:10]: - logger.debug(stat) - last_snapshot = snapshot + # snapshot = tracemalloc.take_snapshot() + # if last_snapshot: + # stats = snapshot.compare_to(last_snapshot, 'lineno') + # logger.debug("memory snapshot comparison") + # for stat in stats[:10]: + # logger.debug(stat) + # last_snapshot = snapshot logger.debug("sending measurement result to handler") measurement_action_completed.send( sender=self.__class__, From 7f79201cf6aba93b379b451fbd2174728d930f47 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Fri, 16 Feb 2024 15:49:30 -0700 Subject: [PATCH 11/44] remove debug code --- .../actions/acquire_stepped_freq_tdomain_iq.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py index e859e5b7..f115fdf5 100644 --- a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py +++ b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py @@ -38,7 +38,6 @@ import logging import numpy as np -import tracemalloc from scos_actions.actions.acquire_single_freq_tdomain_iq import ( CAL_ADJUST, DURATION_MS, @@ -90,8 +89,6 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): self._sensor = sensor self.test_required_components() saved_samples = 0 - #last_snapshot = None - #tracemalloc.start() for recording_id, measurement_params in enumerate( self.iterable_params, start=1 @@ -141,13 +138,6 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): logger.debug("Creating metadata for measurement result") self.create_metadata(measurement_result, recording_id) - # snapshot = tracemalloc.take_snapshot() - # if last_snapshot: - # stats = snapshot.compare_to(last_snapshot, 'lineno') - # logger.debug("memory snapshot comparison") - # for stat in stats[:10]: - # logger.debug(stat) - # last_snapshot = snapshot logger.debug("sending measurement result to handler") measurement_action_completed.send( sender=self.__class__, @@ -156,7 +146,6 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): metadata=self.sigmf_builder.metadata, ) saved_samples += num_samples - @property def description(self): From 322d096d28b593b5a5c0f398397a37d7d57df502 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Tue, 20 Feb 2024 09:18:44 -0700 Subject: [PATCH 12/44] use cal adjust in sea data product action, don't get cal datetime if not cal_adjust, remove debug messages --- scos_actions/actions/acquire_sea_data_product.py | 7 ++++--- scos_actions/actions/acquire_single_freq_fft.py | 2 +- scos_actions/actions/acquire_stepped_freq_tdomain_iq.py | 3 --- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index 7748342c..bb01ffd9 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -102,6 +102,7 @@ DURATION_MS = "duration_ms" NUM_SKIP = "nskip" PFP_FRAME_PERIOD_MS = "pfp_frame_period_ms" +CAL_ADJUST = "calibration_adjust" # Constants DATA_TYPE = np.half @@ -161,6 +162,7 @@ def __init__( - 10.0 * np.log10(sample_rate_Hz * fft_size) # PSD scaling + 20.0 * np.log10(window_ecf) # Window energy correction ) + self.cal_adjust = True def run(self, iq: ray.ObjectRef) -> np.ndarray: """ @@ -629,8 +631,7 @@ def capture_iq(self, params: dict) -> dict: cal_adjust = True for key, value in params.items(): logger.debug(f"param {key}={value}") - if "calibration_adjust" in params: - cal_adjust = params["calibration_adjust"] + self.cal_adjust = utils.get_parameter(CAL_ADJUST, params) logger.debug(f"cal_adjust={cal_adjust}") measurement_result = self.sensor.signal_analyzer.acquire_time_domain_samples( num_samples, nskip, cal_adjust=cal_adjust @@ -1134,7 +1135,7 @@ def create_capture_segment( preamp_enable=self.sensor.signal_analyzer.preamp_enable, ), ) - if "sensor_cal" in measurement_result: + if self.cal_adjust: capture_segment.sensor_calibration=ntia_sensor.Calibration( datetime=measurement_result["sensor_cal"]["datetime"], gain=round(measurement_result["sensor_cal"]["gain"], 3), diff --git a/scos_actions/actions/acquire_single_freq_fft.py b/scos_actions/actions/acquire_single_freq_fft.py index 494d6406..7c7d8fd4 100644 --- a/scos_actions/actions/acquire_single_freq_fft.py +++ b/scos_actions/actions/acquire_single_freq_fft.py @@ -177,7 +177,7 @@ def execute(self, schedule_entry: dict, task_id: int) -> dict: # Save measurement results measurement_result["data"] = m4s_result measurement_result.update(self.parameters) - if self.sensor.signal_analyzer.sensor_calibration_data: + if self.cal_adjust: measurement_result[ "calibration_datetime" ] = self.sensor.signal_analyzer.sensor_calibration_data["datetime"] diff --git a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py index f115fdf5..495be7e2 100644 --- a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py +++ b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py @@ -101,7 +101,6 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): sample_rate = self.sensor.signal_analyzer.sample_rate num_samples = int(sample_rate * duration_ms * 1e-3) measurement_result = super().acquire_data(num_samples, nskip, cal_adjust) - logger.debug("Acquired measurement_result") measurement_result.update(measurement_params) end_time = utils.get_datetime_str_now() measurement_result["end_time"] = end_time @@ -136,9 +135,7 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): ) measurement_result["capture_segment"] = capture_segment - logger.debug("Creating metadata for measurement result") self.create_metadata(measurement_result, recording_id) - logger.debug("sending measurement result to handler") measurement_action_completed.send( sender=self.__class__, task_id=task_id, From 08d72e0623c2a281ab22e1184d3488fa3ccdda76 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Tue, 27 Feb 2024 10:56:34 -0700 Subject: [PATCH 13/44] fix cal_adjust bugs --- scos_actions/actions/acquire_sea_data_product.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index bb01ffd9..03b5c784 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -628,17 +628,17 @@ def capture_iq(self, params: dict) -> dict: nskip = utils.get_parameter(NUM_SKIP, params) num_samples = int(params[SAMPLE_RATE] * duration_ms * 1e-3) # Collect IQ data - cal_adjust = True + self.cal_adjust = True for key, value in params.items(): logger.debug(f"param {key}={value}") self.cal_adjust = utils.get_parameter(CAL_ADJUST, params) - logger.debug(f"cal_adjust={cal_adjust}") + logger.debug(f"cal_adjust={self.cal_adjust}") measurement_result = self.sensor.signal_analyzer.acquire_time_domain_samples( - num_samples, nskip, cal_adjust=cal_adjust + num_samples, nskip, cal_adjust=self.cal_adjust ) # Store some metadata with the IQ measurement_result.update(params) - if cal_adjust: + if self.cal_adjust: measurement_result[ "sensor_cal" ] = self.sensor.signal_analyzer.sensor_calibration_data From b36f36d2799d58b2990c1f47b5927cc1a9a5faff Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Wed, 28 Feb 2024 09:58:31 -0700 Subject: [PATCH 14/44] add constructor to mock gps to match actual gps --- scos_actions/hardware/mocks/mock_gps.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scos_actions/hardware/mocks/mock_gps.py b/scos_actions/hardware/mocks/mock_gps.py index 4c05a6ff..203919c7 100644 --- a/scos_actions/hardware/mocks/mock_gps.py +++ b/scos_actions/hardware/mocks/mock_gps.py @@ -7,6 +7,9 @@ class MockGPS(GPSInterface): + def __init__(self, sigan): + self.sigan = sigan + def get_location(timeout_s=1): logger.warning("Using mock GPS!") return 39.995118, -105.261572, 1651.0 From bda63dbcdf6c8259c9fa9f39823f5ceeaa423e89 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Wed, 28 Feb 2024 10:13:20 -0700 Subject: [PATCH 15/44] fix tests --- scos_actions/actions/tests/test_sync_gps.py | 3 ++- scos_actions/discover/tests/test_yaml.py | 2 +- scos_actions/hardware/tests/test_sensor.py | 8 +++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/scos_actions/actions/tests/test_sync_gps.py b/scos_actions/actions/tests/test_sync_gps.py index ed7b2691..71c3cd4c 100644 --- a/scos_actions/actions/tests/test_sync_gps.py +++ b/scos_actions/actions/tests/test_sync_gps.py @@ -30,8 +30,9 @@ def callback(sender, **kwargs): location_action_completed.connect(callback) action = test_actions["test_sync_gps"] + sigan = MockSignalAnalyzer() sensor = Sensor( - signal_analyzer=MockSignalAnalyzer(), capabilities={}, gps=MockGPS() + signal_analyzer=sigan, capabilities={}, gps=MockGPS(sigan) ) if sys.platform == "linux": action(sensor, SYNC_GPS, 1) diff --git a/scos_actions/discover/tests/test_yaml.py b/scos_actions/discover/tests/test_yaml.py index 473b39dd..953f5e3f 100644 --- a/scos_actions/discover/tests/test_yaml.py +++ b/scos_actions/discover/tests/test_yaml.py @@ -25,7 +25,7 @@ """ sigan = MockSignalAnalyzer() -gps = MockGPS() +gps = MockGPS(sigan) def test_load_from_yaml_existing(): diff --git a/scos_actions/hardware/tests/test_sensor.py b/scos_actions/hardware/tests/test_sensor.py index 216d626a..50b3338f 100644 --- a/scos_actions/hardware/tests/test_sensor.py +++ b/scos_actions/hardware/tests/test_sensor.py @@ -7,8 +7,9 @@ def test_sensor(): + sigan = MockSignalAnalyzer() sensor = Sensor( - signal_analyzer=MockSignalAnalyzer(), capabilities={}, gps=MockGPS() + signal_analyzer=sigan, capabilities={}, gps=MockGPS(sigan) ) assert sensor is not None assert sensor.signal_analyzer is not None @@ -23,8 +24,9 @@ def test_set_get_preselector(): def test_set_get_gps(): - gps = MockGPS() - sensor = Sensor(signal_analyzer=MockSignalAnalyzer(), capabilities={}) + sigan = MockSignalAnalyzer() + gps = MockGPS(sigan) + sensor = Sensor(signal_analyzer=sigan, capabilities={}) sensor.gps = gps assert sensor.gps == gps From 062e6ced01defb6ca6b5c576346a87f117b40237 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Wed, 28 Feb 2024 10:49:47 -0700 Subject: [PATCH 16/44] autoformat code, always add logger to test actions --- .../actions/acquire_sea_data_product.py | 20 ++++++++++------ .../actions/acquire_single_freq_fft.py | 1 + .../actions/acquire_single_freq_tdomain_iq.py | 4 ++-- .../acquire_stepped_freq_tdomain_iq.py | 4 ++-- scos_actions/actions/calibrate_y_factor.py | 4 ++-- .../actions/interfaces/measurement_action.py | 1 + scos_actions/actions/tests/test_sync_gps.py | 4 +--- scos_actions/discover/__init__.py | 24 +++++++++++-------- scos_actions/hardware/mocks/mock_gps.py | 2 +- scos_actions/hardware/sigan_iface.py | 1 + scos_actions/hardware/tests/test_sensor.py | 4 +--- scos_actions/signal_processing/calibration.py | 1 + 12 files changed, 40 insertions(+), 30 deletions(-) diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index 03b5c784..8b6fdba6 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -1136,13 +1136,19 @@ def create_capture_segment( ), ) if self.cal_adjust: - capture_segment.sensor_calibration=ntia_sensor.Calibration( - datetime=measurement_result["sensor_cal"]["datetime"], - gain=round(measurement_result["sensor_cal"]["gain"], 3), - noise_figure=round(measurement_result["sensor_cal"]["noise_figure"], 3), - temperature=round(measurement_result["sensor_cal"]["temperature"], 1), - reference=DATA_REFERENCE_POINT, - ), + capture_segment.sensor_calibration = ( + ntia_sensor.Calibration( + datetime=measurement_result["sensor_cal"]["datetime"], + gain=round(measurement_result["sensor_cal"]["gain"], 3), + noise_figure=round( + measurement_result["sensor_cal"]["noise_figure"], 3 + ), + temperature=round( + measurement_result["sensor_cal"]["temperature"], 1 + ), + reference=DATA_REFERENCE_POINT, + ), + ) self.sigmf_builder.add_capture(capture_segment) def get_sigmf_builder( diff --git a/scos_actions/actions/acquire_single_freq_fft.py b/scos_actions/actions/acquire_single_freq_fft.py index 7c7d8fd4..d1ec2aba 100644 --- a/scos_actions/actions/acquire_single_freq_fft.py +++ b/scos_actions/actions/acquire_single_freq_fft.py @@ -89,6 +89,7 @@ import logging from numpy import float32, ndarray + from scos_actions.actions.interfaces.measurement_action import MeasurementAction from scos_actions.hardware.mocks.mock_gps import MockGPS from scos_actions.metadata.structs import ntia_algorithm diff --git a/scos_actions/actions/acquire_single_freq_tdomain_iq.py b/scos_actions/actions/acquire_single_freq_tdomain_iq.py index 60559d7a..a6d2cf2e 100644 --- a/scos_actions/actions/acquire_single_freq_tdomain_iq.py +++ b/scos_actions/actions/acquire_single_freq_tdomain_iq.py @@ -34,12 +34,12 @@ import logging from numpy import complex64 + +from scos_actions import utils from scos_actions.actions.interfaces.measurement_action import MeasurementAction from scos_actions.hardware.mocks.mock_gps import MockGPS from scos_actions.utils import get_parameter -from scos_actions import utils - logger = logging.getLogger(__name__) # Define parameter keys diff --git a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py index 495be7e2..39575f8b 100644 --- a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py +++ b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py @@ -38,6 +38,8 @@ import logging import numpy as np + +from scos_actions import utils from scos_actions.actions.acquire_single_freq_tdomain_iq import ( CAL_ADJUST, DURATION_MS, @@ -51,8 +53,6 @@ from scos_actions.signals import measurement_action_completed from scos_actions.utils import get_parameter -from scos_actions import utils - logger = logging.getLogger(__name__) diff --git a/scos_actions/actions/calibrate_y_factor.py b/scos_actions/actions/calibrate_y_factor.py index d26bb743..15cf9fd9 100644 --- a/scos_actions/actions/calibrate_y_factor.py +++ b/scos_actions/actions/calibrate_y_factor.py @@ -75,6 +75,8 @@ import numpy as np from scipy.constants import Boltzmann from scipy.signal import sosfilt + +from scos_actions import utils from scos_actions.actions.interfaces.action import Action from scos_actions.hardware.sensor import Sensor from scos_actions.hardware.sigan_iface import SIGAN_SETTINGS_KEYS @@ -92,8 +94,6 @@ from scos_actions.signals import trigger_api_restart from scos_actions.utils import ParameterException, get_parameter -from scos_actions import utils - logger = logging.getLogger(__name__) # Define parameter keys diff --git a/scos_actions/actions/interfaces/measurement_action.py b/scos_actions/actions/interfaces/measurement_action.py index f0b06e54..88a0a239 100644 --- a/scos_actions/actions/interfaces/measurement_action.py +++ b/scos_actions/actions/interfaces/measurement_action.py @@ -3,6 +3,7 @@ from typing import Optional import numpy as np + from scos_actions.actions.interfaces.action import Action from scos_actions.hardware.sensor import Sensor from scos_actions.metadata.structs import ntia_sensor diff --git a/scos_actions/actions/tests/test_sync_gps.py b/scos_actions/actions/tests/test_sync_gps.py index 71c3cd4c..024dbcee 100644 --- a/scos_actions/actions/tests/test_sync_gps.py +++ b/scos_actions/actions/tests/test_sync_gps.py @@ -31,9 +31,7 @@ def callback(sender, **kwargs): location_action_completed.connect(callback) action = test_actions["test_sync_gps"] sigan = MockSignalAnalyzer() - sensor = Sensor( - signal_analyzer=sigan, capabilities={}, gps=MockGPS(sigan) - ) + sensor = Sensor(signal_analyzer=sigan, capabilities={}, gps=MockGPS(sigan)) if sys.platform == "linux": action(sensor, SYNC_GPS, 1) assert _latitude diff --git a/scos_actions/discover/__init__.py b/scos_actions/discover/__init__.py index 0d8eeb64..48c38c76 100644 --- a/scos_actions/discover/__init__.py +++ b/scos_actions/discover/__init__.py @@ -3,10 +3,10 @@ from scos_actions.actions.monitor_sigan import MonitorSignalAnalyzer from scos_actions.actions.sync_gps import SyncGps from scos_actions.discover.yaml import load_from_yaml -from scos_actions.settings import ACTION_DEFINITIONS_DIR, SIGAN_MODULE, SIGAN_CLASS +from scos_actions.settings import ACTION_DEFINITIONS_DIR, SIGAN_CLASS, SIGAN_MODULE actions = {"logger": Logger()} -test_actions = {} +test_actions = {"logger": Logger()} def init( @@ -25,12 +25,16 @@ def init( yaml_actions, yaml_test_actions = init() actions.update(yaml_actions) -if SIGAN_MODULE == "scos_actions.hardware.mocks.mock_sigan" and SIGAN_CLASS == "MockSignalAnalyzer": - test_actions.update({ - "test_sync_gps": SyncGps(parameters={"name": "test_sync_gps"}), - "test_monitor_sigan": MonitorSignalAnalyzer( - parameters={"name": "test_monitor_sigan"} - ), - "logger": Logger() - }) +if ( + SIGAN_MODULE == "scos_actions.hardware.mocks.mock_sigan" + and SIGAN_CLASS == "MockSignalAnalyzer" +): + test_actions.update( + { + "test_sync_gps": SyncGps(parameters={"name": "test_sync_gps"}), + "test_monitor_sigan": MonitorSignalAnalyzer( + parameters={"name": "test_monitor_sigan"} + ), + } + ) test_actions.update(yaml_test_actions) diff --git a/scos_actions/hardware/mocks/mock_gps.py b/scos_actions/hardware/mocks/mock_gps.py index 203919c7..e794dd0b 100644 --- a/scos_actions/hardware/mocks/mock_gps.py +++ b/scos_actions/hardware/mocks/mock_gps.py @@ -9,7 +9,7 @@ class MockGPS(GPSInterface): def __init__(self, sigan): self.sigan = sigan - + def get_location(timeout_s=1): logger.warning("Using mock GPS!") return 39.995118, -105.261572, 1651.0 diff --git a/scos_actions/hardware/sigan_iface.py b/scos_actions/hardware/sigan_iface.py index 7ed01d45..3b211113 100644 --- a/scos_actions/hardware/sigan_iface.py +++ b/scos_actions/hardware/sigan_iface.py @@ -4,6 +4,7 @@ from typing import Dict, Optional from its_preselector.web_relay import WebRelay + from scos_actions.calibration.calibration import Calibration from scos_actions.hardware.utils import power_cycle_sigan from scos_actions.utils import convert_string_to_millisecond_iso_format diff --git a/scos_actions/hardware/tests/test_sensor.py b/scos_actions/hardware/tests/test_sensor.py index 50b3338f..ccf1b749 100644 --- a/scos_actions/hardware/tests/test_sensor.py +++ b/scos_actions/hardware/tests/test_sensor.py @@ -8,9 +8,7 @@ def test_sensor(): sigan = MockSignalAnalyzer() - sensor = Sensor( - signal_analyzer=sigan, capabilities={}, gps=MockGPS(sigan) - ) + sensor = Sensor(signal_analyzer=sigan, capabilities={}, gps=MockGPS(sigan)) assert sensor is not None assert sensor.signal_analyzer is not None assert sensor.gps is not None diff --git a/scos_actions/signal_processing/calibration.py b/scos_actions/signal_processing/calibration.py index 41ef5d71..785685d3 100644 --- a/scos_actions/signal_processing/calibration.py +++ b/scos_actions/signal_processing/calibration.py @@ -4,6 +4,7 @@ import numpy as np from its_preselector.preselector import Preselector from scipy.constants import Boltzmann + from scos_actions.signal_processing.unit_conversion import ( convert_celsius_to_fahrenheit, convert_celsius_to_kelvins, From 3eaf79e320085b22552442137f67467a365aae49 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Thu, 29 Feb 2024 09:29:39 -0700 Subject: [PATCH 17/44] use test data product action from scos-tekrsa --- ...oduct.yml => test_SEA_CBRS_Measure_Baseline.yml} | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) rename scos_actions/configs/actions/{test_nasctn_sea_data_product.yml => test_SEA_CBRS_Measure_Baseline.yml} (74%) diff --git a/scos_actions/configs/actions/test_nasctn_sea_data_product.yml b/scos_actions/configs/actions/test_SEA_CBRS_Measure_Baseline.yml similarity index 74% rename from scos_actions/configs/actions/test_nasctn_sea_data_product.yml rename to scos_actions/configs/actions/test_SEA_CBRS_Measure_Baseline.yml index 6eaea7ca..8fc5d5c6 100644 --- a/scos_actions/configs/actions/test_nasctn_sea_data_product.yml +++ b/scos_actions/configs/actions/test_SEA_CBRS_Measure_Baseline.yml @@ -1,27 +1,22 @@ nasctn_sea_data_product: - name: test_nasctn_sea_data_product + name: test_SEA_CBRS_Measure_Baseline rf_path: antenna calibration_adjust: False # IIR filter settings - iir_apply: True iir_gpass_dB: 0.1 # Max passband ripple below unity gain iir_gstop_dB: 40 # Minimum stopband attenuation iir_pb_edge_Hz: 5e6 # Passband edge frequency iir_sb_edge_Hz: 5.008e6 # Stopband edge frequency -# Mean/Max FFT settings - fft_size: 175 +# FFT settings nffts: 320e3 - fft_window_type: flattop # See scipy.signal.get_window for supported input # PFP frame pfp_frame_period_ms: 10 # APD downsampling settings - apd_bin_size_dB: 0.5 # Set to 0 or negative for no downsampling - apd_min_bin_dBm: -180 + apd_bin_size_dB: 1.0 # Set to 0 or negative for no downsampling apd_max_bin_dBm: -30 + apd_min_bin_dBm: -180 # Time domain power statistics settings td_bin_size_ms: 10 -# Round all power results to X decimal places - round_to_places: 2 # Sigan Settings preamp_enable: True reference_level: -25 From a70ce1bed5cec1cbf98f317ea6003cfd12ba10e7 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Thu, 29 Feb 2024 11:09:51 -0700 Subject: [PATCH 18/44] fix bug in multi freq IQ action, small change to mock sigan recompute_sensor_calibration_data --- scos_actions/actions/acquire_stepped_freq_tdomain_iq.py | 6 +++--- scos_actions/hardware/mocks/mock_sigan.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py index 39575f8b..cfd53a11 100644 --- a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py +++ b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py @@ -130,9 +130,9 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): sensor_cal["compression_point"] = sensor_cal.pop( "1db_compression_point" ) - capture_segment.sensor_calibration = ntia_sensor.Calibration( - **sensor_cal - ) + capture_segment.sensor_calibration = ntia_sensor.Calibration( + **sensor_cal + ) measurement_result["capture_segment"] = capture_segment self.create_metadata(measurement_result, recording_id) diff --git a/scos_actions/hardware/mocks/mock_sigan.py b/scos_actions/hardware/mocks/mock_sigan.py index 49687574..0553ba25 100644 --- a/scos_actions/hardware/mocks/mock_sigan.py +++ b/scos_actions/hardware/mocks/mock_sigan.py @@ -212,7 +212,7 @@ def update_calibration(self, params): def recompute_sensor_calibration_data(self, cal_args: list) -> None: if self.sensor_calibration is not None: self.sensor_calibration_data.update( - self._sensor_calibration.get_calibration_dict(cal_args) + self.sensor_calibration.get_calibration_dict(cal_args) ) else: logger.warning("Sensor calibration does not exist.") From 0d26e5baca06a1d8e054052e91e83be866aef839 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 4 Mar 2024 11:22:42 -0700 Subject: [PATCH 19/44] remove "calibration_datetime" from metadata, replaced by Calibration object in capture --- scos_actions/actions/acquire_single_freq_fft.py | 4 ---- scos_actions/actions/acquire_single_freq_tdomain_iq.py | 4 ---- scos_actions/actions/interfaces/measurement_action.py | 6 ------ scos_actions/metadata/sigmf_builder.py | 5 ----- 4 files changed, 19 deletions(-) diff --git a/scos_actions/actions/acquire_single_freq_fft.py b/scos_actions/actions/acquire_single_freq_fft.py index d1ec2aba..61769662 100644 --- a/scos_actions/actions/acquire_single_freq_fft.py +++ b/scos_actions/actions/acquire_single_freq_fft.py @@ -178,10 +178,6 @@ def execute(self, schedule_entry: dict, task_id: int) -> dict: # Save measurement results measurement_result["data"] = m4s_result measurement_result.update(self.parameters) - if self.cal_adjust: - measurement_result[ - "calibration_datetime" - ] = self.sensor.signal_analyzer.sensor_calibration_data["datetime"] measurement_result["task_id"] = task_id measurement_result["classification"] = self.classification diff --git a/scos_actions/actions/acquire_single_freq_tdomain_iq.py b/scos_actions/actions/acquire_single_freq_tdomain_iq.py index a6d2cf2e..8f359531 100644 --- a/scos_actions/actions/acquire_single_freq_tdomain_iq.py +++ b/scos_actions/actions/acquire_single_freq_tdomain_iq.py @@ -89,10 +89,6 @@ def execute(self, schedule_entry: dict, task_id: int) -> dict: measurement_result.update(self.parameters) measurement_result["end_time"] = end_time measurement_result["task_id"] = task_id - if self.cal_adjust: - measurement_result[ - "calibration_datetime" - ] = self.sensor.signal_analyzer.sensor_calibration_data["datetime"] measurement_result["classification"] = self.classification sigan_settings = self.get_sigan_settings(measurement_result) logger.debug(f"sigan settings:{sigan_settings}") diff --git a/scos_actions/actions/interfaces/measurement_action.py b/scos_actions/actions/interfaces/measurement_action.py index 88a0a239..62f8fedd 100644 --- a/scos_actions/actions/interfaces/measurement_action.py +++ b/scos_actions/actions/interfaces/measurement_action.py @@ -104,12 +104,6 @@ def create_metadata( self.sigmf_builder.set_classification(measurement_result["classification"]) except KeyError: logger.warning(warning_str.format("classification")) - try: - self.sigmf_builder.set_last_calibration_time( - measurement_result["calibration_datetime"] - ) - except KeyError: - logger.warning(warning_str.format("calibration_datetime")) try: cap = measurement_result["capture_segment"] logger.debug(f"Adding capture:{cap}") diff --git a/scos_actions/metadata/sigmf_builder.py b/scos_actions/metadata/sigmf_builder.py index 2a838d82..e9f6b2fd 100644 --- a/scos_actions/metadata/sigmf_builder.py +++ b/scos_actions/metadata/sigmf_builder.py @@ -426,11 +426,6 @@ def add_annotation(self, start_index, length, annotation_md): start_index=start_index, length=length, metadata=annotation_md ) - def set_last_calibration_time(self, last_cal_time): - self.sigmf_md.set_global_field( - "ntia-sensor:calibration_datetime", last_cal_time - ) - def add_to_global(self, key, value): self.sigmf_md.set_global_field(key, value) From 569680257655f7ce0759bdc316cb6ac51b9a6d78 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 4 Mar 2024 14:19:15 -0700 Subject: [PATCH 20/44] fix m4s graph name --- scos_actions/actions/acquire_single_freq_fft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scos_actions/actions/acquire_single_freq_fft.py b/scos_actions/actions/acquire_single_freq_fft.py index 61769662..8f1ce402 100644 --- a/scos_actions/actions/acquire_single_freq_fft.py +++ b/scos_actions/actions/acquire_single_freq_fft.py @@ -259,7 +259,7 @@ def create_metadata(self, measurement_result: dict, recording: int = None) -> No self.fft_size, measurement_result["sample_rate"], self.frequency_Hz ) m4s_graph = ntia_algorithm.Graph( - name="M4S Detector Result", + name="power_spectral_density", series=[det.value for det in self.fft_detector], length=self.fft_size, x_units="Hz", From a683cf8488b1686d6466ee1c3d29e368c36d4517 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 4 Mar 2024 14:46:41 -0700 Subject: [PATCH 21/44] revert previous change --- scos_actions/actions/acquire_single_freq_fft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scos_actions/actions/acquire_single_freq_fft.py b/scos_actions/actions/acquire_single_freq_fft.py index 8f1ce402..61769662 100644 --- a/scos_actions/actions/acquire_single_freq_fft.py +++ b/scos_actions/actions/acquire_single_freq_fft.py @@ -259,7 +259,7 @@ def create_metadata(self, measurement_result: dict, recording: int = None) -> No self.fft_size, measurement_result["sample_rate"], self.frequency_Hz ) m4s_graph = ntia_algorithm.Graph( - name="power_spectral_density", + name="M4S Detector Result", series=[det.value for det in self.fft_detector], length=self.fft_size, x_units="Hz", From 74cac2647222a0986d6434cbae553be365184eb6 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Tue, 5 Mar 2024 15:21:05 -0700 Subject: [PATCH 22/44] autoformat, fix format problem --- .pre-commit-config.yaml | 6 +++--- sample_debug.py | 1 + scos_actions/actions/acquire_sea_data_product.py | 12 +++++------- scos_actions/hardware/mocks/mock_sigan.py | 1 + .../signal_processing/tests/test_calibration.py | 1 + scos_actions/signal_processing/tests/test_fft.py | 1 + .../signal_processing/tests/test_filtering.py | 1 + .../signal_processing/tests/test_power_analysis.py | 1 + .../signal_processing/tests/test_unit_conversion.py | 1 + 9 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9618961d..12ef9bfc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + rev: v3.15.1 hooks: - id: pyupgrade args: ["--py38-plus"] @@ -30,12 +30,12 @@ repos: types: [file, python] args: ["--profile", "black", "--filter-files", "--gitignore"] - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.2.0 hooks: - id: black types: [file, python] - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.38.0 + rev: v0.39.0 hooks: - id: markdownlint types: [file, markdown] diff --git a/sample_debug.py b/sample_debug.py index cc04ae29..3cf415fe 100644 --- a/sample_debug.py +++ b/sample_debug.py @@ -2,6 +2,7 @@ This is a sample file showing how an action be created and called for debugging purposes using a mock signal analyzer. """ + import json from scos_actions.actions.acquire_single_freq_fft import SingleFrequencyFftAcquisition diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index 8b6fdba6..7468922f 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -639,9 +639,9 @@ def capture_iq(self, params: dict) -> dict: # Store some metadata with the IQ measurement_result.update(params) if self.cal_adjust: - measurement_result[ - "sensor_cal" - ] = self.sensor.signal_analyzer.sensor_calibration_data + measurement_result["sensor_cal"] = ( + self.sensor.signal_analyzer.sensor_calibration_data + ) toc = perf_counter() logger.debug( f"IQ Capture ({duration_ms} ms @ {(params[FREQUENCY]/1e6):.1f} MHz) completed in {toc-tic:.2f} s." @@ -1136,8 +1136,7 @@ def create_capture_segment( ), ) if self.cal_adjust: - capture_segment.sensor_calibration = ( - ntia_sensor.Calibration( + capture_segment.sensor_calibration = ntia_sensor.Calibration( datetime=measurement_result["sensor_cal"]["datetime"], gain=round(measurement_result["sensor_cal"]["gain"], 3), noise_figure=round( @@ -1147,8 +1146,7 @@ def create_capture_segment( measurement_result["sensor_cal"]["temperature"], 1 ), reference=DATA_REFERENCE_POINT, - ), - ) + ) self.sigmf_builder.add_capture(capture_segment) def get_sigmf_builder( diff --git a/scos_actions/hardware/mocks/mock_sigan.py b/scos_actions/hardware/mocks/mock_sigan.py index 0553ba25..7b8b96f4 100644 --- a/scos_actions/hardware/mocks/mock_sigan.py +++ b/scos_actions/hardware/mocks/mock_sigan.py @@ -1,4 +1,5 @@ """Mock a signal analyzer for testing.""" + import logging from collections import namedtuple from typing import Optional diff --git a/scos_actions/signal_processing/tests/test_calibration.py b/scos_actions/signal_processing/tests/test_calibration.py index c47a2a37..6b29b472 100644 --- a/scos_actions/signal_processing/tests/test_calibration.py +++ b/scos_actions/signal_processing/tests/test_calibration.py @@ -1,6 +1,7 @@ """ Unit test for scos_actions.signal_processing.calibration """ + import numpy as np from scipy.constants import Boltzmann diff --git a/scos_actions/signal_processing/tests/test_fft.py b/scos_actions/signal_processing/tests/test_fft.py index a848340f..1ea7458c 100644 --- a/scos_actions/signal_processing/tests/test_fft.py +++ b/scos_actions/signal_processing/tests/test_fft.py @@ -1,6 +1,7 @@ """ Unit test for scos_actions.signal_processing.fft """ + import numpy as np import pytest from scipy.signal import get_window diff --git a/scos_actions/signal_processing/tests/test_filtering.py b/scos_actions/signal_processing/tests/test_filtering.py index d33c37c6..0df7b845 100644 --- a/scos_actions/signal_processing/tests/test_filtering.py +++ b/scos_actions/signal_processing/tests/test_filtering.py @@ -5,6 +5,7 @@ tests mostly exist to ensure that tests will fail if substantial changes are made to the wrappers. """ + import numpy as np import pytest from scipy.signal import ellip, ellipord, firwin, kaiserord, sos2zpk, sosfreqz diff --git a/scos_actions/signal_processing/tests/test_power_analysis.py b/scos_actions/signal_processing/tests/test_power_analysis.py index 42e2db75..02aaf454 100644 --- a/scos_actions/signal_processing/tests/test_power_analysis.py +++ b/scos_actions/signal_processing/tests/test_power_analysis.py @@ -1,6 +1,7 @@ """ Unit test for scos_actions.signal_processing.power_analysis """ + from enum import EnumMeta import numpy as np diff --git a/scos_actions/signal_processing/tests/test_unit_conversion.py b/scos_actions/signal_processing/tests/test_unit_conversion.py index 4da61f86..fe404472 100644 --- a/scos_actions/signal_processing/tests/test_unit_conversion.py +++ b/scos_actions/signal_processing/tests/test_unit_conversion.py @@ -1,6 +1,7 @@ """ Unit test for scos_actions.signal_processing.unit_conversion """ + import numpy as np import pytest From adb5383fabb3765835fc19d2ca00ce6dcd7921a4 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Tue, 5 Mar 2024 15:41:36 -0700 Subject: [PATCH 23/44] update formatting to prevent bad autoformat --- scos_actions/actions/acquire_sea_data_product.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index 7468922f..6c8dc6fe 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -1137,16 +1137,12 @@ def create_capture_segment( ) if self.cal_adjust: capture_segment.sensor_calibration = ntia_sensor.Calibration( - datetime=measurement_result["sensor_cal"]["datetime"], - gain=round(measurement_result["sensor_cal"]["gain"], 3), - noise_figure=round( - measurement_result["sensor_cal"]["noise_figure"], 3 - ), - temperature=round( - measurement_result["sensor_cal"]["temperature"], 1 - ), - reference=DATA_REFERENCE_POINT, - ) + datetime=measurement_result["sensor_cal"]["datetime"], + gain=round(measurement_result["sensor_cal"]["gain"], 3), + noise_figure=round(measurement_result["sensor_cal"]["noise_figure"], 3), + temperature=round(measurement_result["sensor_cal"]["temperature"], 1), + reference=DATA_REFERENCE_POINT, + ) self.sigmf_builder.add_capture(capture_segment) def get_sigmf_builder( From ab657a9551fff17b827e56a28cd3832383e07514 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Fri, 8 Mar 2024 15:45:51 -0700 Subject: [PATCH 24/44] fix m4s action duration in metadata --- scos_actions/actions/acquire_single_freq_fft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scos_actions/actions/acquire_single_freq_fft.py b/scos_actions/actions/acquire_single_freq_fft.py index 61769662..9b6a2b76 100644 --- a/scos_actions/actions/acquire_single_freq_fft.py +++ b/scos_actions/actions/acquire_single_freq_fft.py @@ -188,7 +188,7 @@ def execute(self, schedule_entry: dict, task_id: int) -> dict: sample_start=0, start_time=measurement_result["capture_time"], center_frequency_Hz=self.frequency_Hz, - duration_ms=int(self.num_samples / sample_rate_Hz), + duration_ms=int((self.num_samples / sample_rate_Hz)*1000), overload=measurement_result["overload"], sigan_settings=sigan_settings, ) From c56da5634c8e2cfaa0e8f45c42c181abb8f37916 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Fri, 8 Mar 2024 15:47:45 -0700 Subject: [PATCH 25/44] add plugin_name property to sigan iface --- scos_actions/actions/acquire_sea_data_product.py | 2 +- scos_actions/hardware/mocks/mock_sigan.py | 6 ++++++ scos_actions/hardware/sigan_iface.py | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index 52c62c1e..1b68bdbc 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -794,7 +794,7 @@ def capture_diagnostics( "scos_sensor_version": SCOS_SENSOR_GIT_TAG, "scos_actions_version": SCOS_ACTIONS_VERSION, "scos_sigan_plugin": ntia_diagnostics.ScosPlugin( - name="scos_tekrsa", version=self.sensor.signal_analyzer.plugin_version + name=self.sensor.signal_analyzer.plugin_name, version=self.sensor.signal_analyzer.plugin_version ), "preselector_api_version": PRESELECTOR_API_VERSION, "sigan_firmware_version": self.sensor.signal_analyzer.firmware_version, diff --git a/scos_actions/hardware/mocks/mock_sigan.py b/scos_actions/hardware/mocks/mock_sigan.py index 7b8b96f4..8774f48b 100644 --- a/scos_actions/hardware/mocks/mock_sigan.py +++ b/scos_actions/hardware/mocks/mock_sigan.py @@ -7,6 +7,7 @@ import numpy as np from scos_actions import __version__ as SCOS_ACTIONS_VERSION +from scos_actions import __package__ as SCOS_ACTIONS_NAME from scos_actions.calibration.calibration import Calibration from scos_actions.hardware.sigan_iface import SignalAnalyzerInterface from scos_actions.utils import get_datetime_str_now @@ -65,6 +66,7 @@ def __init__( self._capture_time = None self._is_available = True self._plugin_version = SCOS_ACTIONS_VERSION + self._plugin_name = SCOS_ACTIONS_NAME self._firmware_version = "1.2.3" self._api_version = "v1.2.3" @@ -84,6 +86,10 @@ def is_available(self): @property def plugin_version(self): return self._plugin_version + + @property + def plugin_name(self) -> str: + return self._plugin_name @property def firmware_version(self): diff --git a/scos_actions/hardware/sigan_iface.py b/scos_actions/hardware/sigan_iface.py index 3b211113..0b2f1d05 100644 --- a/scos_actions/hardware/sigan_iface.py +++ b/scos_actions/hardware/sigan_iface.py @@ -56,6 +56,12 @@ def plugin_version(self) -> str: """Returns the version of the SCOS plugin defining this interface.""" pass + @property + @abstractmethod + def plugin_name(self) -> str: + """Returns the name of the SCOS plugin defining this interface.""" + pass + @property def firmware_version(self) -> str: """Returns the version of the signal analyzer firmware.""" From 01c2764d98d6f3c926cf08d0fc25f4aaf8081d4c Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 11 Mar 2024 09:49:55 -0600 Subject: [PATCH 26/44] add docstring --- scos_actions/hardware/mocks/mock_sigan.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scos_actions/hardware/mocks/mock_sigan.py b/scos_actions/hardware/mocks/mock_sigan.py index 8774f48b..5857a1b3 100644 --- a/scos_actions/hardware/mocks/mock_sigan.py +++ b/scos_actions/hardware/mocks/mock_sigan.py @@ -89,6 +89,7 @@ def plugin_version(self): @property def plugin_name(self) -> str: + """Returns the current package name of scos-actions.""" return self._plugin_name @property From 9c0718a2589054ab5b53e38932683b83a924a299 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 11 Mar 2024 12:26:32 -0600 Subject: [PATCH 27/44] round to convert to int for m4s duration --- scos_actions/actions/acquire_single_freq_fft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scos_actions/actions/acquire_single_freq_fft.py b/scos_actions/actions/acquire_single_freq_fft.py index 9b6a2b76..1408b2df 100644 --- a/scos_actions/actions/acquire_single_freq_fft.py +++ b/scos_actions/actions/acquire_single_freq_fft.py @@ -188,7 +188,7 @@ def execute(self, schedule_entry: dict, task_id: int) -> dict: sample_start=0, start_time=measurement_result["capture_time"], center_frequency_Hz=self.frequency_Hz, - duration_ms=int((self.num_samples / sample_rate_Hz)*1000), + duration_ms=round((self.num_samples / sample_rate_Hz)*1000), overload=measurement_result["overload"], sigan_settings=sigan_settings, ) From 9e600f85b2071f8fc0d71889227c3e9902c9bf0d Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 11 Mar 2024 13:38:39 -0600 Subject: [PATCH 28/44] increment version, autoformat --- scos_actions/__init__.py | 2 +- scos_actions/actions/acquire_sea_data_product.py | 3 ++- scos_actions/actions/acquire_single_freq_fft.py | 2 +- scos_actions/hardware/mocks/mock_sigan.py | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/scos_actions/__init__.py b/scos_actions/__init__.py index 9e17e009..6dcf770e 100644 --- a/scos_actions/__init__.py +++ b/scos_actions/__init__.py @@ -1 +1 @@ -__version__ = "8.0.1" +__version__ = "9.0.0" diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index 1b68bdbc..ecc00785 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -794,7 +794,8 @@ def capture_diagnostics( "scos_sensor_version": SCOS_SENSOR_GIT_TAG, "scos_actions_version": SCOS_ACTIONS_VERSION, "scos_sigan_plugin": ntia_diagnostics.ScosPlugin( - name=self.sensor.signal_analyzer.plugin_name, version=self.sensor.signal_analyzer.plugin_version + name=self.sensor.signal_analyzer.plugin_name, + version=self.sensor.signal_analyzer.plugin_version, ), "preselector_api_version": PRESELECTOR_API_VERSION, "sigan_firmware_version": self.sensor.signal_analyzer.firmware_version, diff --git a/scos_actions/actions/acquire_single_freq_fft.py b/scos_actions/actions/acquire_single_freq_fft.py index 1408b2df..daccf9d6 100644 --- a/scos_actions/actions/acquire_single_freq_fft.py +++ b/scos_actions/actions/acquire_single_freq_fft.py @@ -188,7 +188,7 @@ def execute(self, schedule_entry: dict, task_id: int) -> dict: sample_start=0, start_time=measurement_result["capture_time"], center_frequency_Hz=self.frequency_Hz, - duration_ms=round((self.num_samples / sample_rate_Hz)*1000), + duration_ms=round((self.num_samples / sample_rate_Hz) * 1000), overload=measurement_result["overload"], sigan_settings=sigan_settings, ) diff --git a/scos_actions/hardware/mocks/mock_sigan.py b/scos_actions/hardware/mocks/mock_sigan.py index 5857a1b3..f102d03d 100644 --- a/scos_actions/hardware/mocks/mock_sigan.py +++ b/scos_actions/hardware/mocks/mock_sigan.py @@ -6,8 +6,8 @@ import numpy as np -from scos_actions import __version__ as SCOS_ACTIONS_VERSION from scos_actions import __package__ as SCOS_ACTIONS_NAME +from scos_actions import __version__ as SCOS_ACTIONS_VERSION from scos_actions.calibration.calibration import Calibration from scos_actions.hardware.sigan_iface import SignalAnalyzerInterface from scos_actions.utils import get_datetime_str_now @@ -86,7 +86,7 @@ def is_available(self): @property def plugin_version(self): return self._plugin_version - + @property def plugin_name(self) -> str: """Returns the current package name of scos-actions.""" From 91e3eff64bc3056dbab813453ca6b89a330884c0 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Wed, 27 Mar 2024 12:50:16 -0600 Subject: [PATCH 29/44] pass sigan for gps through method calls instead of constructor --- scos_actions/actions/sync_gps.py | 4 ++-- scos_actions/discover/tests/test_yaml.py | 2 +- scos_actions/hardware/gps_iface.py | 4 ++-- scos_actions/hardware/mocks/mock_gps.py | 6 ++---- scos_actions/hardware/tests/test_sensor.py | 2 +- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/scos_actions/actions/sync_gps.py b/scos_actions/actions/sync_gps.py index b0f88543..0fda2887 100644 --- a/scos_actions/actions/sync_gps.py +++ b/scos_actions/actions/sync_gps.py @@ -19,12 +19,12 @@ def __init__(self, parameters: dict): def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): logger.debug("Syncing to GPS") self.sensor = sensor - dt = self.sensor.gps.get_gps_time() + dt = self.sensor.gps.get_gps_time(self.sensor.signal_analyzer) date_cmd = ["date", "-s", "{:}".format(dt.strftime("%Y/%m/%d %H:%M:%S"))] subprocess.check_output(date_cmd, shell=True) logger.info(f"Set system time to GPS time {dt.ctime()}") - location = sensor.gps.get_location() + location = sensor.gps.get_location(self.sensor.signal_analyzer) if location is None: raise RuntimeError("Unable to synchronize to GPS") diff --git a/scos_actions/discover/tests/test_yaml.py b/scos_actions/discover/tests/test_yaml.py index 953f5e3f..473b39dd 100644 --- a/scos_actions/discover/tests/test_yaml.py +++ b/scos_actions/discover/tests/test_yaml.py @@ -25,7 +25,7 @@ """ sigan = MockSignalAnalyzer() -gps = MockGPS(sigan) +gps = MockGPS() def test_load_from_yaml_existing(): diff --git a/scos_actions/hardware/gps_iface.py b/scos_actions/hardware/gps_iface.py index 1b9da39b..37050df7 100644 --- a/scos_actions/hardware/gps_iface.py +++ b/scos_actions/hardware/gps_iface.py @@ -3,9 +3,9 @@ class GPSInterface(ABC): @abstractmethod - def get_location(self, timeout_s=1): + def get_location(self, sigan, timeout_s=1): pass @abstractmethod - def get_gps_time(self): + def get_gps_time(self, sigan): pass diff --git a/scos_actions/hardware/mocks/mock_gps.py b/scos_actions/hardware/mocks/mock_gps.py index e794dd0b..dbc4fb8c 100644 --- a/scos_actions/hardware/mocks/mock_gps.py +++ b/scos_actions/hardware/mocks/mock_gps.py @@ -7,13 +7,11 @@ class MockGPS(GPSInterface): - def __init__(self, sigan): - self.sigan = sigan - def get_location(timeout_s=1): + def get_location(self, sigan, timeout_s=1): logger.warning("Using mock GPS!") return 39.995118, -105.261572, 1651.0 - def get_gps_time(self): + def get_gps_time(self, sigan): logger.warning("Using mock GPS!") return datetime.now() diff --git a/scos_actions/hardware/tests/test_sensor.py b/scos_actions/hardware/tests/test_sensor.py index ccf1b749..597f88ce 100644 --- a/scos_actions/hardware/tests/test_sensor.py +++ b/scos_actions/hardware/tests/test_sensor.py @@ -23,7 +23,7 @@ def test_set_get_preselector(): def test_set_get_gps(): sigan = MockSignalAnalyzer() - gps = MockGPS(sigan) + gps = MockGPS() sensor = Sensor(signal_analyzer=sigan, capabilities={}) sensor.gps = gps assert sensor.gps == gps From d06098f81e0e690f628e852e9d032f118a3fbdcf Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Wed, 27 Mar 2024 12:52:34 -0600 Subject: [PATCH 30/44] check if CAL_ADJUST param exists, slight logging improvement --- scos_actions/actions/acquire_sea_data_product.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index ecc00785..4716e082 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -631,12 +631,14 @@ def capture_iq(self, params: dict) -> dict: duration_ms = utils.get_parameter(DURATION_MS, params) nskip = utils.get_parameter(NUM_SKIP, params) num_samples = int(params[SAMPLE_RATE] * duration_ms * 1e-3) - # Collect IQ data + if logger.getEffectiveLevel() == logging.DEBUG: + for key, value in params.items(): + logger.debug(f"param {key}={value}") self.cal_adjust = True - for key, value in params.items(): - logger.debug(f"param {key}={value}") - self.cal_adjust = utils.get_parameter(CAL_ADJUST, params) + if CAL_ADJUST in params: + self.cal_adjust = utils.get_parameter(CAL_ADJUST, params) logger.debug(f"cal_adjust={self.cal_adjust}") + # Collect IQ data measurement_result = self.sensor.signal_analyzer.acquire_time_domain_samples( num_samples, nskip, cal_adjust=self.cal_adjust ) From 3c3752413ef3bb5755cd1b4caad25ebeda180446 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Wed, 27 Mar 2024 13:50:35 -0600 Subject: [PATCH 31/44] fix error from merge --- scos_actions/hardware/mocks/mock_sigan.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scos_actions/hardware/mocks/mock_sigan.py b/scos_actions/hardware/mocks/mock_sigan.py index 018c1e30..104d9771 100644 --- a/scos_actions/hardware/mocks/mock_sigan.py +++ b/scos_actions/hardware/mocks/mock_sigan.py @@ -61,6 +61,10 @@ def is_available(self): @property def plugin_version(self): return self._plugin_version + + @property + def plugin_name(self): + return self._plugin_name @property def sample_rate(self): From 8d205e52706fb7be8d2268a35a18ab7e105614d7 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Thu, 4 Apr 2024 12:42:26 -0600 Subject: [PATCH 32/44] add rf_path to test actions --- scos_actions/configs/actions/test_multi_frequency_iq_action.yml | 1 + scos_actions/configs/actions/test_single_frequency_iq_action.yml | 1 + .../configs/actions/test_single_frequency_m4s_action.yml | 1 + scos_actions/configs/actions/test_survey_iq_action.yml | 1 + 4 files changed, 4 insertions(+) diff --git a/scos_actions/configs/actions/test_multi_frequency_iq_action.yml b/scos_actions/configs/actions/test_multi_frequency_iq_action.yml index 8074c921..b1d2a1ff 100644 --- a/scos_actions/configs/actions/test_multi_frequency_iq_action.yml +++ b/scos_actions/configs/actions/test_multi_frequency_iq_action.yml @@ -17,3 +17,4 @@ stepped_frequency_time_domain_iq: nskip: 15.36e4 calibration_adjust: False classification: UNCLASSIFIED + rf_path: antenna diff --git a/scos_actions/configs/actions/test_single_frequency_iq_action.yml b/scos_actions/configs/actions/test_single_frequency_iq_action.yml index 15908352..d8fa80f9 100644 --- a/scos_actions/configs/actions/test_single_frequency_iq_action.yml +++ b/scos_actions/configs/actions/test_single_frequency_iq_action.yml @@ -7,3 +7,4 @@ single_frequency_time_domain_iq: nskip: 15.36e4 calibration_adjust: False classification: UNCLASSIFIED + rf_path: antenna diff --git a/scos_actions/configs/actions/test_single_frequency_m4s_action.yml b/scos_actions/configs/actions/test_single_frequency_m4s_action.yml index 3220bf4d..f20312f6 100644 --- a/scos_actions/configs/actions/test_single_frequency_m4s_action.yml +++ b/scos_actions/configs/actions/test_single_frequency_m4s_action.yml @@ -8,3 +8,4 @@ single_frequency_fft: nskip: 15.36e4 calibration_adjust: False classification: UNCLASSIFIED + rf_path: antenna diff --git a/scos_actions/configs/actions/test_survey_iq_action.yml b/scos_actions/configs/actions/test_survey_iq_action.yml index f64540e1..fe16e7c6 100644 --- a/scos_actions/configs/actions/test_survey_iq_action.yml +++ b/scos_actions/configs/actions/test_survey_iq_action.yml @@ -27,3 +27,4 @@ stepped_frequency_time_domain_iq: - 10000 nskip: 15.36e4 calibration_adjust: False + rf_path: antenna From b43b9629b07f5830037646287e5cabf6f510c28c Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Thu, 4 Apr 2024 13:26:12 -0600 Subject: [PATCH 33/44] autoformat --- scos_actions/hardware/mocks/mock_sigan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scos_actions/hardware/mocks/mock_sigan.py b/scos_actions/hardware/mocks/mock_sigan.py index 104d9771..bb8d6a9f 100644 --- a/scos_actions/hardware/mocks/mock_sigan.py +++ b/scos_actions/hardware/mocks/mock_sigan.py @@ -61,7 +61,7 @@ def is_available(self): @property def plugin_version(self): return self._plugin_version - + @property def plugin_name(self): return self._plugin_name From 0a8621afd9d70a29ac8e77bc51bd91ffe3913bd6 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Thu, 4 Apr 2024 14:20:36 -0600 Subject: [PATCH 34/44] only check compression_point if cal_adjust --- scos_actions/actions/acquire_sea_data_product.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index 728b6b09..cec4d9dc 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -1171,10 +1171,10 @@ def create_capture_segment( ), reference=measurement_result["reference"], ) - if "compression_point" in measurement_result["applied_calibration"]: - capture_segment.sensor_calibration.compression_point = measurement_result[ - "applied_calibration" - ]["compression_point"] + if "compression_point" in measurement_result["applied_calibration"]: + capture_segment.sensor_calibration.compression_point = measurement_result[ + "applied_calibration" + ]["compression_point"] self.sigmf_builder.add_capture(capture_segment) def get_sigmf_builder( From a632242998ca0f34f039908c76a47272395c3389 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Thu, 4 Apr 2024 14:23:23 -0600 Subject: [PATCH 35/44] autoformat --- scos_actions/actions/acquire_sea_data_product.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scos_actions/actions/acquire_sea_data_product.py b/scos_actions/actions/acquire_sea_data_product.py index cec4d9dc..534b9ce8 100644 --- a/scos_actions/actions/acquire_sea_data_product.py +++ b/scos_actions/actions/acquire_sea_data_product.py @@ -1172,9 +1172,9 @@ def create_capture_segment( reference=measurement_result["reference"], ) if "compression_point" in measurement_result["applied_calibration"]: - capture_segment.sensor_calibration.compression_point = measurement_result[ - "applied_calibration" - ]["compression_point"] + capture_segment.sensor_calibration.compression_point = ( + measurement_result["applied_calibration"]["compression_point"] + ) self.sigmf_builder.add_capture(capture_segment) def get_sigmf_builder( From 93a32d0419bc311ee3660844d4c94cd5568fce84 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Fri, 5 Apr 2024 11:20:49 -0600 Subject: [PATCH 36/44] change GPS methods to use sensor, add type hints --- scos_actions/hardware/gps_iface.py | 6 ++++-- scos_actions/hardware/mocks/mock_gps.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scos_actions/hardware/gps_iface.py b/scos_actions/hardware/gps_iface.py index 37050df7..36b374dc 100644 --- a/scos_actions/hardware/gps_iface.py +++ b/scos_actions/hardware/gps_iface.py @@ -1,11 +1,13 @@ from abc import ABC, abstractmethod +from scos_actions.hardware.sensor import Sensor + class GPSInterface(ABC): @abstractmethod - def get_location(self, sigan, timeout_s=1): + def get_location(self, sensor : Sensor, timeout_s : float=1): pass @abstractmethod - def get_gps_time(self, sigan): + def get_gps_time(self, sensor : Sensor): pass diff --git a/scos_actions/hardware/mocks/mock_gps.py b/scos_actions/hardware/mocks/mock_gps.py index dbc4fb8c..769a7de1 100644 --- a/scos_actions/hardware/mocks/mock_gps.py +++ b/scos_actions/hardware/mocks/mock_gps.py @@ -8,10 +8,10 @@ class MockGPS(GPSInterface): - def get_location(self, sigan, timeout_s=1): + def get_location(self, sensor, timeout_s=1): logger.warning("Using mock GPS!") return 39.995118, -105.261572, 1651.0 - def get_gps_time(self, sigan): + def get_gps_time(self, sensor): logger.warning("Using mock GPS!") return datetime.now() From d31020241dc924b8eaf459fa854824d30a5f11e0 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Fri, 5 Apr 2024 12:33:45 -0600 Subject: [PATCH 37/44] fix circular import --- scos_actions/hardware/gps_iface.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scos_actions/hardware/gps_iface.py b/scos_actions/hardware/gps_iface.py index 36b374dc..ac220ef7 100644 --- a/scos_actions/hardware/gps_iface.py +++ b/scos_actions/hardware/gps_iface.py @@ -1,13 +1,13 @@ from abc import ABC, abstractmethod -from scos_actions.hardware.sensor import Sensor - class GPSInterface(ABC): @abstractmethod - def get_location(self, sensor : Sensor, timeout_s : float=1): + def get_location( + self, sensor: "scos_actions.hardware.sensor.Sensor", timeout_s: float = 1 + ): pass @abstractmethod - def get_gps_time(self, sensor : Sensor): + def get_gps_time(self, sensor: "scos_actions.hardware.sensor.Sensor"): pass From 876b6a665aa82da6e7c3a87b2efccda2ae7a1685 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Tue, 9 Apr 2024 13:11:08 -0600 Subject: [PATCH 38/44] move sensor overload check from scos-usrp to sensor class --- scos_actions/hardware/sensor.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/scos_actions/hardware/sensor.py b/scos_actions/hardware/sensor.py index 47198b93..52f41679 100644 --- a/scos_actions/hardware/sensor.py +++ b/scos_actions/hardware/sensor.py @@ -4,6 +4,7 @@ import logging from typing import Any, Dict, List, Optional +import numpy as np from its_preselector.preselector import Preselector from its_preselector.web_relay import WebRelay @@ -246,6 +247,26 @@ def recompute_calibration_data(self, params: dict) -> None: if not recomputed: logger.warning("Failed to recompute calibration data") + def check_sensor_overload(self, data) -> bool: + """Check for sensor overload in the measurement data.""" + measured_data = data.astype(np.complex64) + + time_domain_avg_power = 10 * np.log10(np.mean(np.abs(measured_data) ** 2)) + time_domain_avg_power += ( + 10 * np.log10(1 / (2 * 50)) + 30 + ) # Convert log(V^2) to dBm + # explicitly check is not None since 1db compression could be 0 + if self.sensor_calibration_data["compression_point"] is not None: + return bool( + time_domain_avg_power + > self.sensor_calibration_data["compression_point"] + ) + else: + logger.debug( + "Compression point is None, returning False for sensor overload." + ) + return False + def acquire_time_domain_samples( self, num_samples: int, @@ -288,6 +309,7 @@ def acquire_time_domain_samples( logger.debug("*************************************\n") max_retries = retries + sensor_overload = False # Acquire samples from signal analyzer if self.signal_analyzer is not None: while True: @@ -363,6 +385,15 @@ def acquire_time_domain_samples( measurement_result["applied_calibration"]["compression_point"] = ( self.sensor_calibration_data["compression_point"] ) + sensor_overload = self.check_sensor_overload( + measurement_result["data"] + ) + if sensor_overload: + logger.warning("Sensor overload occurred!") + # measurement_result["overload"] could be true based on sigan overload or sensor overload + measurement_result["overload"] = ( + measurement_result["overload"] or sensor_overload + ) applied_cal = measurement_result["applied_calibration"] logger.debug(f"Setting applied_calibration to: {applied_cal}") else: From 9f1b040f66b5a05a7e6c59c70aac20269ce10592 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Thu, 11 Apr 2024 09:22:58 -0600 Subject: [PATCH 39/44] remove clock_rate_lookup_by_sample_rate, remove unused import --- scos_actions/actions/calibrate_y_factor.py | 2 -- .../calibration/sensor_calibration.py | 8 ------- .../calibration/tests/test_calibration.py | 1 - .../tests/test_sensor_calibration.py | 22 ------------------- scos_actions/hardware/sensor.py | 1 - 5 files changed, 34 deletions(-) diff --git a/scos_actions/actions/calibrate_y_factor.py b/scos_actions/actions/calibrate_y_factor.py index 69fc5d5b..636596f0 100644 --- a/scos_actions/actions/calibrate_y_factor.py +++ b/scos_actions/actions/calibrate_y_factor.py @@ -231,14 +231,12 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): logger.debug(f"cal_params: {cal_params}") cal_data = dict() last_cal_datetime = get_datetime_str_now() - clock_rate_lookup_by_sample_rate = [] self.sensor.sensor_calibration = SensorCalibration( calibration_parameters=cal_params, calibration_data=cal_data, calibration_reference=onboard_cal_reference, file_path=Path(env("ONBOARD_CALIBRATION_FILE")), last_calibration_datetime=last_cal_datetime, - clock_rate_lookup_by_sample_rate=clock_rate_lookup_by_sample_rate, sensor_uid=sensor_uid, ) elif self.sensor.sensor_calibration.file_path == env( diff --git a/scos_actions/calibration/sensor_calibration.py b/scos_actions/calibration/sensor_calibration.py index 1ce985ee..e5c94759 100644 --- a/scos_actions/calibration/sensor_calibration.py +++ b/scos_actions/calibration/sensor_calibration.py @@ -25,16 +25,8 @@ class provides an implementation for the update method to allow calibration """ last_calibration_datetime: str - clock_rate_lookup_by_sample_rate: List[Dict[str, float]] sensor_uid: str - def get_clock_rate(self, sample_rate: Union[float, int]) -> Union[float, int]: - """Find the clock rate (Hz) using the given sample_rate (samples per second)""" - for mapping in self.clock_rate_lookup_by_sample_rate: - if mapping["sample_rate"] == sample_rate: - return mapping["clock_frequency"] - return sample_rate - def update( self, params: dict, diff --git a/scos_actions/calibration/tests/test_calibration.py b/scos_actions/calibration/tests/test_calibration.py index 20c160b8..9c74d9a1 100644 --- a/scos_actions/calibration/tests/test_calibration.py +++ b/scos_actions/calibration/tests/test_calibration.py @@ -103,7 +103,6 @@ def test_to_and_from_json(self, tmp_path: Path): "testing", tmp_path / "testing.json", "dt_str", - [], "uid", ) sensor_cal.to_json() diff --git a/scos_actions/calibration/tests/test_sensor_calibration.py b/scos_actions/calibration/tests/test_sensor_calibration.py index bd4c610c..f5e9f581 100644 --- a/scos_actions/calibration/tests/test_sensor_calibration.py +++ b/scos_actions/calibration/tests/test_sensor_calibration.py @@ -83,17 +83,6 @@ def setup_calibration_file(self, tmp_path: Path): cal_data["sensor_uid"] = "SAMPLE_CALIBRATION" cal_data["calibration_reference"] = "TESTING" - # Add SR/CF lookup table - cal_data["clock_rate_lookup_by_sample_rate"] = [] - for sr in self.sample_rates: - cr = sr - while cr <= 40e6: - cr *= 2 - cr /= 2 - cal_data["clock_rate_lookup_by_sample_rate"].append( - {"sample_rate": int(sr), "clock_frequency": int(cr)} - ) - # Create the JSON architecture for the calibration data cal_data["calibration_data"] = {} cal_data["calibration_parameters"] = ["sample_rate", "frequency", "gain"] @@ -151,7 +140,6 @@ def test_sensor_calibration_dataclass_fields(self): # Note: does not check field order assert fields == { "last_calibration_datetime": str, - "clock_rate_lookup_by_sample_rate": List[Dict[str, float]], "sensor_uid": str, } @@ -167,13 +155,6 @@ def test_field_validator(self): [], {}, False, Path(""), datetime.datetime.now(), [], "uid" ) - def test_get_clock_rate(self): - """Test the get_clock_rate method""" - # Test getting a clock rate by sample rate - assert self.sample_cal.get_clock_rate(10e6) == 40e6 - # If there isn't an entry, the sample rate should be returned - assert self.sample_cal.get_clock_rate(-999) == -999 - def test_get_calibration_dict_exact_match_lookup(self): calibration_datetime = get_datetime_str_now() calibration_params = ["sample_rate", "frequency"] @@ -187,7 +168,6 @@ def test_get_calibration_dict_exact_match_lookup(self): calibration_reference="testing", file_path=Path(""), last_calibration_datetime=calibration_datetime, - clock_rate_lookup_by_sample_rate=[], sensor_uid="TESTING", ) cal_data = cal.get_calibration_dict({"sample_rate": 100.0, "frequency": 200.0}) @@ -206,7 +186,6 @@ def test_get_calibration_dict_within_range(self): calibration_reference="testing", file_path=Path("test_calibration.json"), last_calibration_datetime=calibration_datetime, - clock_rate_lookup_by_sample_rate=[], sensor_uid="TESTING", ) @@ -234,7 +213,6 @@ def test_update(self): calibration_reference="testing", file_path=test_cal_path, last_calibration_datetime=calibration_datetime, - clock_rate_lookup_by_sample_rate=[], sensor_uid="TESTING", ) action_params = {"sample_rate": 100.0, "frequency": 200.0} diff --git a/scos_actions/hardware/sensor.py b/scos_actions/hardware/sensor.py index 52f41679..f4e1f6fb 100644 --- a/scos_actions/hardware/sensor.py +++ b/scos_actions/hardware/sensor.py @@ -9,7 +9,6 @@ from its_preselector.web_relay import WebRelay from scos_actions.calibration.differential_calibration import DifferentialCalibration -from scos_actions.calibration.interfaces.calibration import Calibration from scos_actions.calibration.sensor_calibration import SensorCalibration from scos_actions.hardware.gps_iface import GPSInterface from scos_actions.hardware.sigan_iface import SignalAnalyzerInterface From 6638bfd1fd798f0f3bf8fcde57a2ff6fbed81c8c Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Thu, 11 Apr 2024 12:21:45 -0600 Subject: [PATCH 40/44] only add temperature to cal metadata if it exists --- scos_actions/actions/interfaces/measurement_action.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scos_actions/actions/interfaces/measurement_action.py b/scos_actions/actions/interfaces/measurement_action.py index e7ad088a..1400937a 100644 --- a/scos_actions/actions/interfaces/measurement_action.py +++ b/scos_actions/actions/interfaces/measurement_action.py @@ -67,15 +67,16 @@ def get_calibration(self, measurement_result: dict) -> ntia_sensor.Calibration: noise_figure=round( measurement_result["applied_calibration"]["noise_figure"], 3 ), - temperature=round( - self.sensor.sensor_calibration_data["temperature"], 1 - ), reference=measurement_result["reference"], ) if "compression_point" in measurement_result["applied_calibration"]: cal_meta.compression_point = measurement_result["applied_calibration"][ "compression_point" ] + if "temperature" in self.sensor.sensor_calibration_data: + cal_meta.temperature = round( + self.sensor.sensor_calibration_data["temperature"], 1 + ) return cal_meta def create_metadata( From 8806decee954892c1375d50a5845a1a876bf420d Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Mon, 15 Apr 2024 10:30:38 -0600 Subject: [PATCH 41/44] only load yaml actions if using scos_actions mock sigan --- scos_actions/discover/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scos_actions/discover/__init__.py b/scos_actions/discover/__init__.py index 48c38c76..a3430161 100644 --- a/scos_actions/discover/__init__.py +++ b/scos_actions/discover/__init__.py @@ -23,12 +23,12 @@ def init( return yaml_actions, yaml_test_actions -yaml_actions, yaml_test_actions = init() -actions.update(yaml_actions) if ( SIGAN_MODULE == "scos_actions.hardware.mocks.mock_sigan" and SIGAN_CLASS == "MockSignalAnalyzer" ): + yaml_actions, yaml_test_actions = init() + actions.update(yaml_actions) test_actions.update( { "test_sync_gps": SyncGps(parameters={"name": "test_sync_gps"}), From a58f0eb487fcf0acd21652fdb5cf00202540f7d7 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Wed, 17 Apr 2024 14:07:00 -0600 Subject: [PATCH 42/44] change version to 10.0.0 --- scos_actions/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scos_actions/__init__.py b/scos_actions/__init__.py index 6dcf770e..9158871f 100644 --- a/scos_actions/__init__.py +++ b/scos_actions/__init__.py @@ -1 +1 @@ -__version__ = "9.0.0" +__version__ = "10.0.0" From a050817671a6b439196436fac6b40f662bc1a5a6 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Wed, 24 Apr 2024 09:26:53 -0600 Subject: [PATCH 43/44] fix bug in sync gps action --- scos_actions/actions/sync_gps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scos_actions/actions/sync_gps.py b/scos_actions/actions/sync_gps.py index 0fda2887..7163a12d 100644 --- a/scos_actions/actions/sync_gps.py +++ b/scos_actions/actions/sync_gps.py @@ -19,12 +19,12 @@ def __init__(self, parameters: dict): def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): logger.debug("Syncing to GPS") self.sensor = sensor - dt = self.sensor.gps.get_gps_time(self.sensor.signal_analyzer) + dt = self.sensor.gps.get_gps_time(self.sensor) date_cmd = ["date", "-s", "{:}".format(dt.strftime("%Y/%m/%d %H:%M:%S"))] subprocess.check_output(date_cmd, shell=True) logger.info(f"Set system time to GPS time {dt.ctime()}") - location = sensor.gps.get_location(self.sensor.signal_analyzer) + location = sensor.gps.get_location(self.sensor) if location is None: raise RuntimeError("Unable to synchronize to GPS") From 7c0454d925b9ee09990e1be598972c56dd8cb319 Mon Sep 17 00:00:00 2001 From: Justin Haze Date: Thu, 25 Apr 2024 13:37:45 -0600 Subject: [PATCH 44/44] Address feedback --- scos_actions/actions/logger.py | 34 ------------------------------- scos_actions/discover/__init__.py | 5 ++--- scos_actions/hardware/sensor.py | 13 ++++++------ scos_actions/settings.py | 14 ++++++++++--- 4 files changed, 19 insertions(+), 47 deletions(-) delete mode 100644 scos_actions/actions/logger.py diff --git a/scos_actions/actions/logger.py b/scos_actions/actions/logger.py deleted file mode 100644 index ae2c6e60..00000000 --- a/scos_actions/actions/logger.py +++ /dev/null @@ -1,34 +0,0 @@ -"""A simple example action that logs a message.""" - -import logging -from typing import Optional - -from scos_actions.actions.interfaces.action import Action -from scos_actions.hardware.sensor import Sensor - -logger = logging.getLogger(__name__) - -LOGLVL_INFO = 20 -LOGLVL_ERROR = 40 - - -class Logger(Action): - """Log the message "running test {name}/{tid}". - - This is useful for testing and debugging. - - `{name}` will be replaced with the parent schedule entry's name, and - `{tid}` will be replaced with the sequential task id. - - """ - - def __init__(self, loglvl=LOGLVL_INFO): - super().__init__(parameters={"name": "logger"}) - self.loglvl = loglvl - - def __call__(self, sensor: Optional[Sensor], schedule_entry: dict, task_id: int): - msg = "running test {name}/{tid}" - schedule_entry_name = schedule_entry["name"] - logger.log( - level=self.loglvl, msg=msg.format(name=schedule_entry_name, tid=task_id) - ) diff --git a/scos_actions/discover/__init__.py b/scos_actions/discover/__init__.py index a3430161..30e1cb29 100644 --- a/scos_actions/discover/__init__.py +++ b/scos_actions/discover/__init__.py @@ -1,12 +1,11 @@ from scos_actions.actions import action_classes -from scos_actions.actions.logger import Logger from scos_actions.actions.monitor_sigan import MonitorSignalAnalyzer from scos_actions.actions.sync_gps import SyncGps from scos_actions.discover.yaml import load_from_yaml from scos_actions.settings import ACTION_DEFINITIONS_DIR, SIGAN_CLASS, SIGAN_MODULE -actions = {"logger": Logger()} -test_actions = {"logger": Logger()} +actions = {} +test_actions = {} def init( diff --git a/scos_actions/hardware/sensor.py b/scos_actions/hardware/sensor.py index f4e1f6fb..6a9e9701 100644 --- a/scos_actions/hardware/sensor.py +++ b/scos_actions/hardware/sensor.py @@ -5,6 +5,7 @@ from typing import Any, Dict, List, Optional import numpy as np +from numpy.typing import ArrayLike from its_preselector.preselector import Preselector from its_preselector.web_relay import WebRelay @@ -246,16 +247,14 @@ def recompute_calibration_data(self, params: dict) -> None: if not recomputed: logger.warning("Failed to recompute calibration data") - def check_sensor_overload(self, data) -> bool: + def check_sensor_overload(self, data: ArrayLike) -> bool: """Check for sensor overload in the measurement data.""" - measured_data = data.astype(np.complex64) - - time_domain_avg_power = 10 * np.log10(np.mean(np.abs(measured_data) ** 2)) - time_domain_avg_power += ( - 10 * np.log10(1 / (2 * 50)) + 30 - ) # Convert log(V^2) to dBm # explicitly check is not None since 1db compression could be 0 if self.sensor_calibration_data["compression_point"] is not None: + time_domain_avg_power = 10 * np.log10(np.mean(np.abs(data) ** 2)) + time_domain_avg_power += ( + 10 * np.log10(1 / (2 * 50)) + 30 + ) # Convert log(V^2) to dBm return bool( time_domain_avg_power > self.sensor_calibration_data["compression_point"] diff --git a/scos_actions/settings.py b/scos_actions/settings.py index 158de256..eeca61ad 100644 --- a/scos_actions/settings.py +++ b/scos_actions/settings.py @@ -1,4 +1,6 @@ import logging +import sys +from os import path from pathlib import Path from environs import Env @@ -21,14 +23,20 @@ logger.debug(f"scos-actions: MOCK_SIGAN:{MOCK_SIGAN}") MOCK_SIGAN_RANDOM = env.bool("MOCK_SIGAN_RANDOM", default=False) logger.debug(f"scos-actions: MOCK_SIGAN_RANDOM:{MOCK_SIGAN_RANDOM}") -RUNNING_TESTS = env.bool("RUNNING_TESTS", False) +__cmd = path.split(sys.argv[0])[-1] +RUNNING_TESTS = env.bool("RUNNING_TESTS", "test" in __cmd) logger.debug(f"scos-actions: RUNNING_TESTS:{RUNNING_TESTS}") logger.debug(f"scos-actions: RUNNING_TESTS:{RUNNING_TESTS}") FQDN = env("FQDN", None) logger.debug(f"scos-actions: FQDN:{FQDN}") -SIGAN_MODULE = env.str("SIGAN_MODULE", default="scos_actions.hardware.mocks.mock_sigan") + +SIGAN_MODULE = env.str("SIGAN_MODULE", default=None) +if RUNNING_TESTS: + SIGAN_MODULE = "scos_actions.hardware.mocks.mock_sigan" logger.debug(f"scos-actions: SIGAN_MODULE:{SIGAN_MODULE}") -SIGAN_CLASS = env.str("SIGAN_CLASS", default="MockSignalAnalyzer") +SIGAN_CLASS = env.str("SIGAN_CLASS", default=None) +if RUNNING_TESTS: + SIGAN_CLASS = "MockSignalAnalyzer" logger.debug(f"scos-actions: SIGAN_CLASS:{SIGAN_CLASS}") SIGAN_POWER_SWITCH = env("SIGAN_POWER_SWITCH", default=None) logger.debug(f"scos-actions: SIGAN_POWER_SWITCH:{SIGAN_POWER_SWITCH}")