-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added in functionality for calibrations via json * Adjusted interpolation scheme to use pandas > 2.0.0 * Calibration changes the answers for kaslo tests
- Loading branch information
1 parent
1f74680
commit 4e71e24
Showing
9 changed files
with
188 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from enum import Enum | ||
import json | ||
from pathlib import Path | ||
from .logging import setup_log | ||
import logging | ||
from dataclasses import dataclass | ||
from typing import List | ||
setup_log() | ||
|
||
LOG = logging.getLogger('study_lyte.calibrations') | ||
|
||
|
||
@dataclass() | ||
class Calibration: | ||
"""Small class to make accessing calibration data a bit more convenient""" | ||
serial: str | ||
calibration: dict[str, List[float]] | ||
|
||
|
||
class Calibrations: | ||
""" | ||
Class to read in a json containing calibrations, keyed by serial number and | ||
valued by dictionary of sensor names containing cal values | ||
""" | ||
def __init__(self, filename:Path): | ||
with open(filename, mode='r') as fp: | ||
self._info = json.load(fp) | ||
|
||
def from_serial(self, serial:str) -> Calibration: | ||
""" Build data object from the calibration result """ | ||
cal = self._info.get(serial) | ||
if cal is None: | ||
LOG.warning(f"No Calibration found for serial {serial}, using default") | ||
cal = self._info['default'] | ||
serial = 'UNKNOWN' | ||
|
||
else: | ||
LOG.info(f"Calibration found ({serial})!") | ||
|
||
result = Calibration(serial=serial, calibration=cal) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"252813070A020004":{"Sensor1":[0, 0, -10, 409], | ||
"comment": "Test"}, | ||
|
||
"default":{"Sensor1":[0, 0, -1, 4096], | ||
"comment": "default"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from os.path import join | ||
from pathlib import Path | ||
from study_lyte.calibrations import Calibrations | ||
|
||
|
||
class TestCalibrations: | ||
@pytest.fixture(scope='function') | ||
def calibration_json(self, data_dir): | ||
return Path(join(data_dir, 'calibrations.json')) | ||
|
||
@pytest.fixture(scope='function') | ||
def calibrations(self, calibration_json): | ||
return Calibrations(calibration_json) | ||
|
||
@pytest.mark.parametrize("serial, expected", [ | ||
("252813070A020004", -10), | ||
("NONSENSE", -1), | ||
]) | ||
def test_attributes(self, calibrations, serial, expected): | ||
"""""" | ||
result = calibrations.from_serial(serial) | ||
assert result.calibration['Sensor1'][2] == expected | ||
|
||
|
Oops, something went wrong.