__all__ = ['DaqChannel'] import json, logging from dataclasses import dataclass, field from typing import List import numpy as np from dataclasses_json import dataclass_json from ..lasp_common import Qty, SIQtys @dataclass_json @dataclass(eq=False) class DaqChannel: channel_enabled: bool channel_name: str = 'Unnamed channel' sensitivity: float = 1.0 range_index: int = 0 ACCoupling_enabled: bool = False IEPE_enabled: bool = False channel_metadata: str = '' def __post_init__(self): # logging.debug(f'__post_init__({self.channel_name})') self._qty = SIQtys.default() # Whether a digital high-pass filter should be used on input data. # Negative means disabled. A positive number corresponds to the cut-on # frequency of the installed highpass filter. self._highpass = -1.0 try: meta = json.loads(self.channel_metadata) if 'qty' in meta: # The quantity itself is stored as a JSON string, in the JSON # object called channel_metadata. self._qty = Qty.from_json(meta['qty']) if 'highpass' in meta: self._highpass = meta['highpass'] except json.JSONDecodeError: logging.debug(f'No JSON data found in DaqChannel {self.channel_name}') @property def qty(self): return self._qty @qty.setter def qty(self, newqty): self._qty = newqty self._store('qty', newqty.to_json()) @property def highpass(self): return self._highpass @highpass.setter def highpass(self, newvalue: float): newvalue = float(newvalue) self._highpass = newvalue self._store('highpass', newvalue) def _store(self, name, val): try: meta = json.loads(self.channel_metadata) except json.JSONDecodeError: meta = {} meta[name] = val self.channel_metadata = json.dumps(meta) def __eq__(self, other): """ We overwrite the default equal-check as the floating point values cannot be exactly checked due to conversion from/to JSON """ return (self.channel_enabled == other.channel_enabled and self.channel_name == other.channel_name and self.range_index == other.range_index and self.ACCoupling_enabled == other.ACCoupling_enabled and self.IEPE_enabled == other.IEPE_enabled and self.channel_metadata == other.channel_metadata and np.isclose(self.highpass,other.highpass))