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):
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
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