Skip to content
Snippets Groups Projects
Commit 8d7291a1 authored by Wilbur, Spencer Franklin's avatar Wilbur, Spencer Franklin
Browse files

REsolved comments made by Josh. The rotation function is now sampling...

REsolved comments made by Josh. The rotation function is now sampling frequency agnostic, while also relying on the original stream created under get_timeseries.
parent 86a7d20c
No related branches found
No related tags found
1 merge request!335FDSN 3D Rotation
...@@ -228,10 +228,18 @@ class FDSNFactory(TimeseriesFactory): ...@@ -228,10 +228,18 @@ class FDSNFactory(TimeseriesFactory):
network=self.network, network=self.network,
location=self.locationCode, location=self.locationCode,
) )
print("the channel reported to SCNL is ", channel)
# geomag-algorithms *should* treat starttime/endtime as inclusive everywhere; # geomag-algorithms *should* treat starttime/endtime as inclusive everywhere;
# according to its author, EdgeCWB is inclusive of starttime, but exclusive of # according to its author, EdgeCWB is inclusive of starttime, but exclusive of
# endtime, to satisfy seismic standards/requirements, to precision delta/2; # endtime, to satisfy seismic standards/requirements, to precision delta/2;
half_delta = TimeseriesUtility.get_delta_from_interval(interval) / 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: try:
data = self.Client.get_waveforms( data = self.Client.get_waveforms(
network=sncl.network, network=sncl.network,
...@@ -244,8 +252,13 @@ class FDSNFactory(TimeseriesFactory): ...@@ -244,8 +252,13 @@ class FDSNFactory(TimeseriesFactory):
) )
except FDSNNoDataException: except FDSNNoDataException:
data = Stream() data = Stream()
data.merge() 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: if data.count() == 0 and add_empty_channels:
data += self._get_empty_trace( data += self._get_empty_trace(
starttime=starttime, starttime=starttime,
...@@ -262,12 +275,6 @@ class FDSNFactory(TimeseriesFactory): ...@@ -262,12 +275,6 @@ class FDSNFactory(TimeseriesFactory):
trace=data[0], starttime=starttime, endtime=endtime 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) self._set_metadata(data, observatory, channel, type, interval)
return data return data
...@@ -339,62 +346,45 @@ class FDSNFactory(TimeseriesFactory): ...@@ -339,62 +346,45 @@ class FDSNFactory(TimeseriesFactory):
) )
def _rotate_and_return_requested_channel( 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: ) -> Stream:
""" """
Retrieves the necessary LF channels, rotates them to ZNE, and returns the requested channel. Retrieves the necessary *F channels, rotates them to ZNE, and returns the requested channel.
Channels are mapped as follows: 'X' -> 'LF2', 'Y' -> 'LF1', 'Z' -> 'LFZ'. 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 # Initialize FDSN client and get the necessary data
FDSN = self.Client FDSN = self.Client
# Determine if the requested channel is X, Y, or Z # 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 # Pull the LF* channels needed for rotation
st = FDSN.get_waveforms( f_channels = ["?F1", "?F2", "?FZ"]
network=sncl.network,
station=sncl.station, inv = FDSN.get_stations(
location=sncl.location, network=sncl.network,
channel="LF*", station=sncl.station,
starttime=starttime, location=sncl.location, # Use location if necessary
endtime=endtime, channel=",".join(f_channels), # Request *F1, *F2, and *FZ
) starttime=starttime,
endtime=endtime,
level="response",
)
# Rotate the stream to ZNE # Rotate the stream to ZNE
st.rotate(method="->ZNE", inventory=inv) data.rotate(method="->ZNE", inventory=inv)
print(st) print(data)
# Now return only the requested channel (mapped to Z, N, or E) # # Now return only the requested channel (mapped to Z, N, or E)
if requested_channel == "X": # if requested_channel == "X":
return st.select(channel="LFN") # N after rotation # return data.select(channel="?FN") # N after rotation
elif requested_channel == "Y": # elif requested_channel == "Y":
return st.select(channel="LFE") # E after rotation # return data.select(channel="?FE") # E after rotation
elif requested_channel == "Z": # elif requested_channel == "Z":
return st.select(channel="LFZ") # Z remains Z # return data.select(channel="?FZ") # Z remains Z
print(st)
else: return data
# 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
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