From f4a550dca1bf47853f01390bb80e53b36fde08cd Mon Sep 17 00:00:00 2001
From: Alex Wernle <awernle@usgs.gov>
Date: Tue, 12 Mar 2024 16:17:52 -0600
Subject: [PATCH] Cleaning up Instrument class with descriptions and deleting
 unnecessary attributes.

---
 geomagio/metadata/Instrument/Instrument.py | 129 ++++++++++++++-------
 1 file changed, 88 insertions(+), 41 deletions(-)

diff --git a/geomagio/metadata/Instrument/Instrument.py b/geomagio/metadata/Instrument/Instrument.py
index 9c98e58c..356ba032 100644
--- a/geomagio/metadata/Instrument/Instrument.py
+++ b/geomagio/metadata/Instrument/Instrument.py
@@ -1,59 +1,122 @@
-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
-- 
GitLab