Skip to content

Commit

Permalink
Raise exception if attempting to calibrate without iir filter with de…
Browse files Browse the repository at this point in the history
…fault cal file.
  • Loading branch information
dboulware committed Jan 3, 2024
1 parent bb2c35f commit 15e7b2d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion 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 @@ -262,6 +262,11 @@ 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
assert set(sensor_calibration.calibration_parameters) <= set(
Expand Down
13 changes: 10 additions & 3 deletions scos_actions/calibration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def get_sigan_calibration(sigan_cal_file: str) -> Calibration:
:return: The signal analyzer ``Calibration`` object.
"""
try:
check_for_default_calibration(sigan_cal_file, "Sigan")
sigan_cal = load_from_json(sigan_cal_file)
except Exception:
sigan_cal = None
Expand All @@ -37,19 +36,21 @@ def get_sensor_calibration(sensor_cal_file: str) -> Calibration:
:return: The sensor ``Calibration`` object.
"""
try:
check_for_default_calibration(sensor_cal_file, "Sensor")
sensor_cal = load_from_json(sensor_cal_file)
except Exception:
sensor_cal = None
logger.exception("Unable to load sensor calibration data, reverting to none")
return sensor_cal


def check_for_default_calibration(cal_file_path: str, cal_type: str):
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
Expand All @@ -62,6 +63,9 @@ def check_for_default_calibration(cal_file_path: str, cal_type: str):
)
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
Expand All @@ -73,6 +77,9 @@ def check_for_default_calibration(cal_file_path: str, cal_type: str):
)
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:
Expand Down
3 changes: 2 additions & 1 deletion scos_actions/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from os import path
from pathlib import Path

from django.conf import settings
Expand All @@ -12,7 +13,7 @@
ACTION_DEFINITIONS_DIR = CONFIG_DIR / "actions"

if not settings.configured or not hasattr(settings, "DEFAULT_CALIBRATION_FILE"):
DEFAULT_CALIBRATION_FILE = ""
DEFAULT_CALIBRATION_FILE = path.join(CONFIG_DIR, "default_calibration.json")
else:
DEFAULT_CALIBRATION_FILE = settings.DEFAULT_CALIBRATION_FILE

Expand Down

0 comments on commit 15e7b2d

Please sign in to comment.