Skip to content
Snippets Groups Projects
Commit f4a550dc authored by Wernle, Alexandra Nicole's avatar Wernle, Alexandra Nicole
Browse files

Cleaning up Instrument class with descriptions and deleting unnecessary attributes.

parent a8bc9c91
No related branches found
No related tags found
1 merge request!290New Instrument class and Observatory class edits
from pydantic import BaseModel, Field, validator
from obspy import UTCDateTime
from pydantic import BaseModel, Field
class Instrument(BaseModel):
"""Class for Instrument metadata.
Attributes
----------
serial: serial number of instrument.
model: model number of instrument.
description: description of instrument.
"""
serial: str = None
start_time: UTCDateTime = None
end_time: UTCDateTime = None
model: str = None
broken: bool
description: str = None
@validator("end_time", pre=False, always=False)
def validate_end_time(cls, end_time, values):
start_time = values.get("start_time")
if start_time and end_time and end_time < start_time:
raise ValueError("End time cannot be earlier than start time")
return end_time
# TODO: add Offsets to Observatory.py or keep here?
class Offsets(Instrument):
observatory: str
u_offset_offset: int = Field(..., description="U offset in nT")
v_offset: int = Field(..., description="V offset in nT")
w_offset: int = Field(..., description="W offset in nT")
"""This class is used to store nT offsets. Typically used for FGE offsets.
Attributes
----------
u_offset: U channel offset in nT.
v_offset: V channel offset in nT.
w_offset: W channel offset in nT.
"""
u_offset: float = Field(..., description="U offset in nT")
v_offset: float = Field(..., description="V offset in nT")
w_offset: float = Field(..., description="W offset in nT")
class Electronics(Instrument):
"""This class contains sensor electronics information.
Attributes
----------
type: type of electronics.
resistance: resistance in kOhm.
temperature_scale: temperature scale in V/K.
u_bin: U channel bin number in nT/bin.
v_bin: V channel bin number in nT/bin.
w_bin: W channel bin number in nT/bin.
"""
type: str
resistance: float = None # kOhm
temperature_scale: float = None # V/K
u_bin: int = None # nT/bin
v_bin: int = None # nT/bin
w_bin: int = None # nT/bin
resistance: float = None
temperature_scale: float = None
u_bin: int = Field(..., description=" U nT/bin")
v_bin: int = Field(..., description=" V nT/bin")
w_bin: int = Field(..., description=" W nT/bin")
class Sensor(Instrument):
"""This class contains sensor type and calibration information.
Attributes
----------
type: type of sensor.
u_constant: U channel constant in nT/mA.
v_constant: V channel constant in nT/mA.
w_constant: W channel constant in nT/mA.
"""
type: str
u_constant: int = Field(..., description="U constant in nT/mA")
v_constant: int = Field(..., description="V constant in nT/mA")
w_constant: int = Field(..., description="W constant in nT/mA")
u_constant: float = Field(..., description="U constant in nT/mA")
v_constant: float = Field(..., description="V constant in nT/mA")
w_constant: float = Field(..., description="W constant in nT/mA")
class DataLogger(Instrument):
"""This class contains datalogger information.
Attributes
----------
type: type of datalogger.
"""
type: str
class Digitizer(Instrument):
"""This class contains digitizer type and factors. Typically these are from CompactRIO modules.
Attributes
----------
type: type of digitizer.
u_scale: U channel scale in counts/V.
u_offset: U channel offset in counts.
v_scale: V channel scale in counts/V.
v_offset: V channel offset in counts.
w_scale: W channel scale in counts/V.
w_offset: W channel offset in counts.
"""
type: str
u_scale: int = Field(..., description="U scale in counts/V")
u_offset: int = Field(..., description="U offset in counts")
v_scale: int = Field(..., description="V scale in counts/V")
v_offset: int = Field(..., description="V offset in counts")
w_scale: int = Field(..., description="W scale in counts/V")
w_offset: int = Field(..., description="W offset in counts")
class Active_Instruments(BaseModel):
"""This class is meant to contain active instruments for a particular observatory.
It is often referred to as a "bucket".
Attributes
----------
offsets: offsets metadata.
electronics: electronics metadata.
sensor: sensor metadata.
data_logger: dataLogger metadata.
digitizer: digitizer metadata.
"""
offsets: Offsets
electronics: Electronics
sensor: Sensor
......@@ -65,11 +128,7 @@ class Active_Instruments(BaseModel):
if __name__ == "__main__":
instrument_data = {
"offsets": {
"observatory": "BOU",
"start_time": UTCDateTime("2023-10-27T16:20:00.000Z"),
"end_time": None,
"model": None,
"broken": False,
"description": "Observatory offsets",
"u_offset": 12620, # nT
"v_offset": 0, # nT
......@@ -77,10 +136,7 @@ if __name__ == "__main__":
},
"electronics": {
"serial": "E0568",
"start_time": UTCDateTime("2023-10-27T16:20:00.000Z"),
"end_time": None,
"model": "K2",
"broken": True,
"description": "FGE electronics box",
"type": "FGE Electronics",
"resistance": 18.6, # kOhm
......@@ -91,10 +147,7 @@ if __name__ == "__main__":
},
"sensor": {
"serial": "S0443",
"start_time": UTCDateTime("2023-10-27T16:20:00.000Z"),
"end_time": None,
"model": None,
"broken": False,
"description": "sensor constants combine with electronics resistance to give scale values",
"type": "FGE",
"u_constant": 37062, # nT/mA
......@@ -103,19 +156,13 @@ if __name__ == "__main__":
},
"data_logger": {
"serial": "S0443",
"start_time": UTCDateTime("2023-10-27T16:20:00.000Z"),
"end_time": None,
"model": None,
"broken": False,
"description": None,
"type": "ObsRIO Chassis",
},
"digitizer": {
"serial": "1EA7C53",
"start_time": UTCDateTime("2023-10-27T16:20:00.000Z"),
"end_time": None,
"model": None,
"broken": False,
"description": None,
"type": "ObsRIO Module",
"u_scale": 37062, # counts/V
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment