From 83cf9de1440cc5a23865320082eedc91d5dbd46c Mon Sep 17 00:00:00 2001 From: Doug Boulware Date: Tue, 19 Mar 2024 12:13:58 -0600 Subject: [PATCH] Fix tests. --- .../acquire_stepped_freq_tdomain_iq.py | 5 ++- .../actions/interfaces/measurement_action.py | 39 ++++++++++++------- .../tests/test_sensor_calibration.py | 2 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py index bfb06d55..199473d3 100644 --- a/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py +++ b/scos_actions/actions/acquire_stepped_freq_tdomain_iq.py @@ -119,7 +119,10 @@ def __call__(self, sensor: Sensor, schedule_entry: dict, task_id: int): sigan_settings=sigan_settings, ) sensor_cal = self.sensor.sensor_calibration_data - if sensor_cal is not None: + if ( + sensor_cal is not None + and measurement_result["applied_calibration"] is not None + ): capture_segment.sensor_calibration = self.get_calibration( measurement_result ) diff --git a/scos_actions/actions/interfaces/measurement_action.py b/scos_actions/actions/interfaces/measurement_action.py index ee429e48..e3081c7f 100644 --- a/scos_actions/actions/interfaces/measurement_action.py +++ b/scos_actions/actions/interfaces/measurement_action.py @@ -52,26 +52,37 @@ def create_capture_segment( sensor_cal = self.sensor.sensor_calibration_data # Rename compression point keys if they exist # then set calibration metadata if it exists - if sensor_cal is not None: + if ( + sensor_cal is not None + and measurement_result["applied_calibration"] is not None + ): capture_segment.sensor_calibration = self.get_calibration( measurement_result ) return capture_segment def get_calibration(self, measurement_result: dict) -> ntia_sensor.Calibration: - cal_meta = ntia_sensor.Calibration( - datetime=self.sensor.sensor_calibration_data["datetime"], - gain=round(measurement_result["applied_calibration"]["gain"], 3), - 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" - ] + cal_meta = None + if ( + self.sensor.sensor_calibration_data + is measurement_result["applied_calibration"] + is not None + ): + cal_meta = ntia_sensor.Calibration( + datetime=self.sensor.sensor_calibration_data["datetime"], + gain=round(measurement_result["applied_calibration"]["gain"], 3), + 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" + ] return cal_meta def create_metadata( diff --git a/scos_actions/calibration/tests/test_sensor_calibration.py b/scos_actions/calibration/tests/test_sensor_calibration.py index 01d70854..3e3006f5 100644 --- a/scos_actions/calibration/tests/test_sensor_calibration.py +++ b/scos_actions/calibration/tests/test_sensor_calibration.py @@ -280,7 +280,7 @@ def test_get_calibration_dict_within_range(self): _ = cal.get_calibration_dict({"sample_rate": 100.0, "frequency": 250.0}) assert e_info.value.args[0] == ( f"Could not locate calibration data at 250.0" - + f"\nAttempted lookup using key '250.0' and 250.0" + + f"\nAttempted lookup using key '250.0'" + f"\nUsing calibration data: {cal.calibration_data['100.0']}" )