aboutsummaryrefslogtreecommitdiff
path: root/qolab/hardware
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2024-07-14 01:18:45 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2024-07-14 01:18:45 -0400
commit09390c29e814641e4ad697a54ae4c424a486488c (patch)
tree02a5f0393322adab9cf130bb0701def0a4e087bd /qolab/hardware
parent02db46aab7500f59177fc07270a90a934e10f85c (diff)
downloadqolab-09390c29e814641e4ad697a54ae4c424a486488c.tar.gz
qolab-09390c29e814641e4ad697a54ae4c424a486488c.zip
black formatter
Diffstat (limited to 'qolab/hardware')
-rw-r--r--qolab/hardware/basic.py83
1 files changed, 42 insertions, 41 deletions
diff --git a/qolab/hardware/basic.py b/qolab/hardware/basic.py
index baeb961..1e9e920 100644
--- a/qolab/hardware/basic.py
+++ b/qolab/hardware/basic.py
@@ -3,6 +3,7 @@ import time
from qolab.file_utils import get_next_data_file
from qolab.tsdb import tsdb_append_metric_for_class_setter_or_getter
+
class BasicInstrument:
"""This is the most basic instrument class.
@@ -45,55 +46,54 @@ class BasicInstrument:
>>> config['FnamePrefix'] = 'basicInstrument'
>>> config['SavePath'] = './data'
"""
+
def __init__(self, config={}, device_nickname=None, tsdb_ingester=None):
self.config = {}
- self.config['Device type'] = 'Basic Instrument'
- self.config['Device model'] = 'Model is unset'
- self.config['DeviceId'] = None
- self.config['DeviceNickname'] = device_nickname; # to separate similar instruments
- self.config['FnamePrefix'] = 'basicInstrument'
- self.config['SavePath'] = './data'
+ self.config["Device type"] = "Basic Instrument"
+ self.config["Device model"] = "Model is unset"
+ self.config["DeviceId"] = None
+ self.config["DeviceNickname"] = device_nickname
+ # to separate similar instruments
+ self.config["FnamePrefix"] = "basicInstrument"
+ self.config["SavePath"] = "./data"
for k, v in config.items():
- self.config[k]=v
+ self.config[k] = v
self.tsdb_ingester = tsdb_ingester
# deviceProperties must have 'get' and preferably 'set' methods available,
# i.e. 'SampleRate' needs getSampleRate() and love to have setSampleRate(value)
# they will be used to obtain config and set device according to it
# self.deviceProperties = {'SampleRate', 'TimePerDiv', 'TrigDelay', };
- self.deviceProperties = {'TimeStamp'}
+ self.deviceProperties = {"TimeStamp"}
def __repr__(self):
- s = ''
- s += f'{self.__class__.__name__}('
- s += 'config={'
- cstr=[]
+ s = ""
+ s += f"{self.__class__.__name__}("
+ s += "config={"
+ cstr = []
for k, v in self.config.items():
if v is not None:
- cstr.append(
- f"'{k}'"
- ': '
- f"'{v}'")
- s += ', '.join(cstr)
- s += '}'
+ cstr.append(f"'{k}'" ": " f"'{v}'")
+ s += ", ".join(cstr)
+ s += "}"
if self.tsdb_ingester is not None:
- s += f', tsdb_ingester={self.tsdb_ingester}'
- s += ')'
- return(s)
+ s += f", tsdb_ingester={self.tsdb_ingester}"
+ s += ")"
+ return s
def tsdb_append(f):
return tsdb_append_metric_for_class_setter_or_getter()(f)
def getChannelsConfig(self):
chconfig = {}
- if not hasattr(self, 'numberOfChannels'):
+ if not hasattr(self, "numberOfChannels"):
return chconfig
- for chNum in range(1, self.numberOfChannels+1):
+ for chNum in range(1, self.numberOfChannels + 1):
chNconfig = {}
for p in self.channelProperties:
- getter = f'getChan{p}'
- if not hasattr(self, getter):
- print(f'warning no getter for {p}, i.e. {getter} is missing')
+ getter = f"getChan{p}"
+ if not hasattr(self, getter):
+ print(f"warning no getter for {p}, i.e. {getter} is missing")
continue
res = getattr(self, getter)(chNum)
chNconfig[p] = res
@@ -107,25 +107,25 @@ class BasicInstrument:
if hasattr(self, p) or hasattr(type(self), p):
dconfig[p] = getattr(self, p)
continue
- getter = f'get{p}'
- if not hasattr(self, getter):
- print(f'warning no getter for {p}, i.e. {getter} is missing')
+ getter = f"get{p}"
+ if not hasattr(self, getter):
+ print(f"warning no getter for {p}, i.e. {getter} is missing")
continue
res = getattr(self, getter)()
dconfig[p] = res
- config['DeviceConfig'] = dconfig
- if not hasattr(self, 'numberOfChannels'):
+ config["DeviceConfig"] = dconfig
+ if not hasattr(self, "numberOfChannels"):
return config
- config['ChannelsConfig']=self.getChannelsConfig();
+ config["ChannelsConfig"] = self.getChannelsConfig()
return config
def setConfig(self, cfg):
new_config = cfg.copy()
- device_config = new_config.pop('DeviceConfig')
+ device_config = new_config.pop("DeviceConfig")
self.config.update(new_config)
for p, v in device_config.items():
- setter = f'set{p}'
- if hasattr(self, setter):
+ setter = f"set{p}"
+ if hasattr(self, setter):
# we have something like setProperty
getattr(self, setter)(v)
continue
@@ -133,19 +133,20 @@ class BasicInstrument:
# we have attribute Property
setattr(self, p, v)
continue
- print(f'warning: both {setter} and attribute {p} are missing, skipping {p}')
+ print(f"warning: both {setter} and attribute {p} are missing, skipping {p}")
# self.deviceProperties.add(p)
# setattr(self, p, v)
def getTimeStamp(self):
- return time.strftime("%Y/%m/%d %H:%M:%S")
+ return time.strftime("%Y/%m/%d %H:%M:%S")
def getHeader(self):
header = yaml.dump(self.getConfig(), default_flow_style=False, sort_keys=False)
- header = header.split('\n')
+ header = header.split("\n")
return header
- def getNextDataFile(self, extension='dat'):
- fname = get_next_data_file(self.config['FnamePrefix'], self.config['SavePath'], extension=extension)
+ def getNextDataFile(self, extension="dat"):
+ fname = get_next_data_file(
+ self.config["FnamePrefix"], self.config["SavePath"], extension=extension
+ )
return fname
-