From 1b7e22e4f0d0a2fe2198a981dcaee01ea96936a7 Mon Sep 17 00:00:00 2001
From: spencer <swilbur@usgs.gov>
Date: Tue, 26 Dec 2023 12:36:56 -0700
Subject: [PATCH] Resolved comments regarding previous merge request.

---
 geomagio/edge/IRISFactory.py | 43 +++++++++++++++---------------------
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/geomagio/edge/IRISFactory.py b/geomagio/edge/IRISFactory.py
index a9b01b1b..64bd54b9 100644
--- a/geomagio/edge/IRISFactory.py
+++ b/geomagio/edge/IRISFactory.py
@@ -151,23 +151,20 @@ class IRISFactory(MiniSeedFactory):
             TimeseriesUtility.pad_and_trim_trace(
                 trace=data[0], starttime=starttime, endtime=endtime
             )
-        # Beneath is necessary code to correct the azimuth reported for the LF1(H) and LF2(E) Channels for a Stream Object.
-        azimuth = self._get_azimuth_from_orientations(data[0], starttime)
+        # Beneath is necessary code to check the reported azimuth 
+        # for the LF1 (E or Y) and LF2 (H or X) channels and determine if intstrument axes have been reversed.
+        azi, dip = self._get_orientations(data[0], starttime)
 
         # Checks Azimuth for LF2 channel
-        if 270 > azimuth[0] and azimuth[0] > 90.0 and data[0].stats.channel == "LF2":
+        if 270 > azi and azi > 90.0 and data[0].stats.channel == "LF2":
             data[0].data *= -1
 
         # Checks Azimuth for LF1 channel
-        elif azimuth[0] > 180 and azimuth[0] < 360 and data[0].stats.channel == "LF1":
+        elif azi > 180 and azi < 360 and data[0].stats.channel == "LF1":
             data[0].data *= -1
 
-        # Checks Azimuth for LFZ channel
-        elif azimuth[0] != 0 and data[0].stats.channel == "LFZ":
-            data[0].data *= 0
-
         # Checks Dip for LFZ channel
-        elif azimuth[1] > 0 and azimuth[1] < 180 and data[0].stats.channel == "LFZ":
+        elif dip > 0 and dip < 180 and data[0].stats.channel == "LFZ":
             data[0].data *= -1
 
         self._set_metadata(data, observatory, channel, type, interval)
@@ -228,7 +225,7 @@ class IRISFactory(MiniSeedFactory):
 
     ###################################
 
-    def _get_azimuth_from_orientations(
+    def _get_orientations(
         self, trace: Trace, starttime: UTCDateTime
     ) -> tuple[float, float]:
         # Retrieve station orientation information using FDSN for each trace
@@ -241,8 +238,7 @@ class IRISFactory(MiniSeedFactory):
             network=trace.stats.network,
             location=trace.stats.location,
         )
-        print(sncl)
-        # station = trace.stats.station
+       
 
         FDSN = FDSNClient("IRIS")
         inv = FDSN.get_stations(
@@ -252,23 +248,20 @@ class IRISFactory(MiniSeedFactory):
             level="channel",
         )
 
-        if inv:
-            # Construct the channel code using the current trace's information
-            channel_code = (
-                f"{sncl.network}.{sncl.station}.{sncl.location}.{sncl.channel}"
-            )
 
-            # Get orientation for the constructed channel code and time
-            print(channel_code)
-            orient = inv.get_orientation(channel_code, starttime)
+        # Construct the channel code using the current trace's information
+        channel_code = (
+            f"{sncl.network}.{sncl.station}.{sncl.location}.{sncl.channel}"
+        )
+
+        # Get orientation for the constructed channel code and time
+        orient = inv.get_orientation(channel_code, starttime)
 
-            if orient:
-                # Return the azimuth from orientation
 
-                azimuth = orient["azimuth"]
-                dip = orient["dip"]
+        azimuth = orient["azimuth"]
+        dip = orient["dip"]
 
             # Return both azimuth and dip
-            return azimuth, dip
+        return azimuth, dip
 
         return 0.0  # Default azimuth if metadata is not available
-- 
GitLab