Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move sigan agnostic default calibration file to scos-sensor and enable calibrations with default cal file. #106

Merged
merged 18 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ed0ee2c
Use default gain of 0 and update calibration handling to allow no cal…
dboulware Dec 7, 2023
06b7cfd
Increment version to 7.1.0
dboulware Dec 7, 2023
4fd7152
Set gain to 0 and noise figure to None in default calibration data. A…
dboulware Dec 11, 2023
37b61d2
remove unnecessary length check of cal params.
dboulware Dec 11, 2023
b754cf7
Correct type hints in get_sensor_calibration and git_sigan_calibratio…
dboulware Dec 18, 2023
b548321
run pre-commit.
dboulware Dec 18, 2023
534b0ac
Import the name of the default calibration file from scos-sensor.
dboulware Dec 18, 2023
8480a37
Keep SIGAN_CALIBRATION_FILE and SENSOR_CALIBRATION_FILE as strings.
dboulware Dec 18, 2023
90fb5db
Merge branch 'master' of https://github.com/NTIA/scos-actions
dboulware Jan 3, 2024
1a9a29b
typo fix.
dboulware Jan 3, 2024
0489f1f
Set sensor/sigan_calibration_data to empty dict when recomputing cal …
dboulware Jan 3, 2024
c9ee0be
use path in check for default cal file.
dboulware Jan 3, 2024
9f10d5d
set calibration parameters in calibration update if there are none.
dboulware Jan 3, 2024
bb2c35f
update cal only with sensor parameters.
dboulware Jan 3, 2024
15e7b2d
Raise exception if attempting to calibrate without iir filter with de…
dboulware Jan 3, 2024
d47d763
default default cal flags to False.
dboulware Jan 3, 2024
fd5eaa5
Fix checking if sensor and sigan cal files are set.
dboulware Jan 5, 2024
a24940c
Merge branch 'master' of https://github.com/NTIA/scos-actions
dboulware Jan 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion scos_actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__version__ = "7.1.0"

12 changes: 8 additions & 4 deletions scos_actions/actions/calibrate_y_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

from scos_actions import utils
from scos_actions.actions.interfaces.action import Action
from scos_actions.calibration import sensor_calibration
from scos_actions.calibration import sensor_calibration, default_sensor_calibration
from scos_actions.hardware.mocks.mock_gps import MockGPS
from scos_actions.hardware.sigan_iface import SIGAN_SETTINGS_KEYS
from scos_actions.settings import SENSOR_CALIBRATION_FILE
Expand Down Expand Up @@ -253,7 +253,7 @@ def calibrate(self, params):
assert (
sample_rate == noise_off_measurement_result["sample_rate"]
), "Sample rate mismatch"

sigan_params = {k: v for k, v in params.items() if k in SIGAN_SETTINGS_KEYS}
# Apply IIR filtering to both captures if configured
if self.iir_apply:
# Estimate of IIR filter ENBW does NOT account for passband ripple in sensor transfer function!
Expand All @@ -262,9 +262,13 @@ def calibrate(self, params):
noise_on_data = sosfilt(self.iir_sos, noise_on_measurement_result["data"])
noise_off_data = sosfilt(self.iir_sos, noise_off_measurement_result["data"])
else:
if default_sensor_calibration:
raise Exception(
"Calibrations without IIR filter cannot be performed with default calibration."
)

logger.debug("Skipping IIR filtering")
# Get ENBW from sensor calibration
sigan_params = {k: v for k, v in params.items() if k in SIGAN_SETTINGS_KEYS}
assert set(sensor_calibration.calibration_parameters) <= set(
sigan_params.keys()
), f"Action parameters do not include all required calibration parameters"
Expand All @@ -289,7 +293,7 @@ def calibrate(self, params):

# Update sensor calibration with results
sensor_calibration.update(
params,
sigan_params,
utils.get_datetime_str_now(),
gain,
noise_figure,
Expand Down
59 changes: 51 additions & 8 deletions scos_actions/calibration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import logging
from pathlib import Path
from os import path

from scos_actions.calibration.calibration import Calibration, load_from_json
from scos_actions.settings import SENSOR_CALIBRATION_FILE, SIGAN_CALIBRATION_FILE
from scos_actions.settings import (
DEFAULT_CALIBRATION_FILE,
SENSOR_CALIBRATION_FILE,
SIGAN_CALIBRATION_FILE,
)

logger = logging.getLogger(__name__)


def get_sigan_calibration(sigan_cal_file: Path) -> Calibration:
def get_sigan_calibration(sigan_cal_file: str) -> Calibration:
"""
Load signal analyzer calibration data from file.

Expand All @@ -23,7 +27,7 @@ def get_sigan_calibration(sigan_cal_file: Path) -> Calibration:
return sigan_cal


def get_sensor_calibration(sensor_cal_file: Path) -> Calibration:
def get_sensor_calibration(sensor_cal_file: str) -> Calibration:
"""
Load sensor calibration data from file.

Expand All @@ -39,9 +43,48 @@ def get_sensor_calibration(sensor_cal_file: Path) -> Calibration:
return sensor_cal


logger.debug(f"Loading sensor cal file: {SENSOR_CALIBRATION_FILE}")
sensor_calibration = get_sensor_calibration(SENSOR_CALIBRATION_FILE)
logger.debug(f"Loading sigan cal file: {SIGAN_CALIBRATION_FILE}")
sigan_calibration = get_sigan_calibration(SIGAN_CALIBRATION_FILE)
def check_for_default_calibration(cal_file_path: str, cal_type: str) -> bool:
default_cal = False
if cal_file_path == DEFAULT_CALIBRATION_FILE:
default_cal = True
logger.warning(
f"***************LOADING DEFAULT {cal_type} CALIBRATION***************"
)
return default_cal


sensor_calibration = None
if SENSOR_CALIBRATION_FILE is None or SENSOR_CALIBRATION_FILE == "":
logger.warning(
"No sensor calibration file specified. Not loading calibration file."
)
elif not path.exists(SENSOR_CALIBRATION_FILE):
logger.warning(
SENSOR_CALIBRATION_FILE
+ " does not exist. Not loading sensor calibration file."
)
else:
logger.debug(f"Loading sensor cal file: {SENSOR_CALIBRATION_FILE}")
default_sensor_calibration = check_for_default_calibration(
SENSOR_CALIBRATION_FILE, "Sensor"
)
sensor_calibration = get_sensor_calibration(SENSOR_CALIBRATION_FILE)

sigan_calibration = None
default_sensor_calibration = False
default_sigan_calibration = False
if SIGAN_CALIBRATION_FILE is None or SIGAN_CALIBRATION_FILE == "":
logger.warning("No sigan calibration file specified. Not loading calibration file.")
elif not path.exists(SIGAN_CALIBRATION_FILE):
logger.warning(
SIGAN_CALIBRATION_FILE + " does not exist. Not loading sigan calibration file."
)
else:
logger.debug(f"Loading sigan cal file: {SIGAN_CALIBRATION_FILE}")
default_sigan_calibration = check_for_default_calibration(
SIGAN_CALIBRATION_FILE, "Sigan"
)
sigan_calibration = get_sigan_calibration(SIGAN_CALIBRATION_FILE)

if sensor_calibration:
logger.debug(f"Last sensor cal: {sensor_calibration.last_calibration_datetime}")
9 changes: 5 additions & 4 deletions scos_actions/calibration/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ def get_calibration_dict(self, cal_params: List[Union[float, int, bool]]) -> dic
then the input to this method could be ``["15360000.0", "40"]``.
:return: The calibration data corresponding to the input parameter values.
"""
# Check if the sample rate was calibrated

cal_data = self.calibration_data
# raise Exception(self)
for i, setting_value in enumerate(cal_params):
setting = self.calibration_parameters[i]
logger.debug(f"Looking up calibration for {setting} at {setting_value}")
cal_data = filter_by_parameter(cal_data, setting_value)
logger.debug(f"Got calibration data: {cal_data}")

return cal_data

def update(
Expand Down Expand Up @@ -77,9 +77,10 @@ def update(
"""
cal_data = self.calibration_data
self.last_calibration_datetime = calibration_datetime_str

if len(self.calibration_parameters) == 0:
self.calibration_parameters = list(params.keys())
# Ensure all required calibration parameters were used
if not set(params.keys()) >= set(self.calibration_parameters):
elif not set(params.keys()) >= set(self.calibration_parameters):
raise Exception(
"Not enough parameters specified to update calibration.\n"
+ f"Required parameters are {self.calibration_parameters}"
Expand Down
6 changes: 0 additions & 6 deletions scos_actions/calibration/tests/test_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,6 @@ def test_update(self):
assert cal_from_file.calibration_data["100.0"]["200.0"]["gain"] == 30.0
assert cal_from_file.calibration_data["100.0"]["200.0"]["noise_figure"] == 5.0

def test_default_sensor_cal(self):
assert sensor_calibration is not None

def test_default_sigan_cal_location(self):
assert sigan_calibration is not None

def test_filter_by_paramter_integer(self):
calibrations = {"200.0": {"some_cal_data"}, 300.0: {"more cal data"}}
filtered_data = filter_by_parameter(calibrations, 200)
Expand Down
98 changes: 0 additions & 98 deletions scos_actions/configs/sensor_calibration_example.json

This file was deleted.

98 changes: 0 additions & 98 deletions scos_actions/configs/sigan_calibration_example.json

This file was deleted.

Loading