diff --git a/geomagio/edge/FDSNFactory.py b/geomagio/edge/FDSNFactory.py index fc27f1052d760073915826947d498833964527a2..d06b79241034b9d6397bc7e90497f263b23acdf5 100644 --- a/geomagio/edge/FDSNFactory.py +++ b/geomagio/edge/FDSNFactory.py @@ -228,10 +228,18 @@ class FDSNFactory(TimeseriesFactory): network=self.network, location=self.locationCode, ) + print("the channel reported to SCNL is ", channel) # geomag-algorithms *should* treat starttime/endtime as inclusive everywhere; # according to its author, EdgeCWB is inclusive of starttime, but exclusive of # endtime, to satisfy seismic standards/requirements, to precision delta/2; half_delta = TimeseriesUtility.get_delta_from_interval(interval) / 2 + + # Rotate the trace into a right handed coordinate frame. + # This will worrk assuming the metadata is reported correctly. + + # Channel that require rotations + channel_rotations = ["X", "Y", "Z"] + try: data = self.Client.get_waveforms( network=sncl.network, @@ -244,8 +252,13 @@ class FDSNFactory(TimeseriesFactory): ) except FDSNNoDataException: data = Stream() - data.merge() + + if channel in channel_rotations: + print("The rotation function has been called for channel", channel) + data = self._rotate_and_return_requested_channel( + data, sncl, starttime, endtime, channel + ) if data.count() == 0 and add_empty_channels: data += self._get_empty_trace( starttime=starttime, @@ -262,12 +275,6 @@ class FDSNFactory(TimeseriesFactory): trace=data[0], starttime=starttime, endtime=endtime ) - # Rotate the trace into a right handed coordinate frame. - # This will worrk assuming the metadata is reported correctly. - data = self._rotate_and_return_requested_channel( - sncl, starttime, endtime, channel - ) - self._set_metadata(data, observatory, channel, type, interval) return data @@ -339,62 +346,45 @@ class FDSNFactory(TimeseriesFactory): ) def _rotate_and_return_requested_channel( - self, sncl, starttime: UTCDateTime, endtime: UTCDateTime, requested_channel: str + self, + data: Stream, + sncl, + starttime: UTCDateTime, + endtime: UTCDateTime, + requested_channel: str, ) -> Stream: """ - Retrieves the necessary LF channels, rotates them to ZNE, and returns the requested channel. - Channels are mapped as follows: 'X' -> 'LF2', 'Y' -> 'LF1', 'Z' -> 'LFZ'. + Retrieves the necessary *F channels, rotates them to ZNE, and returns the requested channel. + Channels are mapped as follows: 'X' -> '*F2', 'Y' -> '*F1', 'Z' -> '*FZ'. """ - # Mapping X, Y, Z to LF channels - channel_map = {"X": "LF2", "Y": "LF1", "Z": "LFZ"} + # Initialize FDSN client and get the necessary data FDSN = self.Client # Determine if the requested channel is X, Y, or Z - if requested_channel in channel_map: - # Pull the LF* channels needed for rotation - lf_channels = ["LF1", "LF2", "LFZ"] - - inv = FDSN.get_stations( - network=sncl.network, - station=sncl.station, - location=sncl.location, # Use location if necessary - channel=",".join(lf_channels), # Request LF1, LF2, and LFZ - starttime=starttime, - endtime=endtime, - level="response", - ) - # # Get the waveform data for LF* channels - st = FDSN.get_waveforms( - network=sncl.network, - station=sncl.station, - location=sncl.location, - channel="LF*", - starttime=starttime, - endtime=endtime, - ) + # Pull the LF* channels needed for rotation + f_channels = ["?F1", "?F2", "?FZ"] + + inv = FDSN.get_stations( + network=sncl.network, + station=sncl.station, + location=sncl.location, # Use location if necessary + channel=",".join(f_channels), # Request *F1, *F2, and *FZ + starttime=starttime, + endtime=endtime, + level="response", + ) - # Rotate the stream to ZNE - st.rotate(method="->ZNE", inventory=inv) - print(st) + # Rotate the stream to ZNE + data.rotate(method="->ZNE", inventory=inv) + print(data) - # Now return only the requested channel (mapped to Z, N, or E) - if requested_channel == "X": - return st.select(channel="LFN") # N after rotation - elif requested_channel == "Y": - return st.select(channel="LFE") # E after rotation - elif requested_channel == "Z": - return st.select(channel="LFZ") # Z remains Z - print(st) + # # Now return only the requested channel (mapped to Z, N, or E) + # if requested_channel == "X": + # return data.select(channel="?FN") # N after rotation + # elif requested_channel == "Y": + # return data.select(channel="?FE") # E after rotation + # elif requested_channel == "Z": + # return data.select(channel="?FZ") # Z remains Z - else: - # If the requested channel is not X, Y, or Z, just retrieve and return that specific channel - st = FDSN.get_waveforms( - network=sncl.network, - station=sncl.station, - location=sncl.location, - channel=sncl.channel, - starttime=starttime, - endtime=endtime, - ) - return st + return data