Skip to content
Snippets Groups Projects

Add sncl_mode and scale_factor options to controller:

All threads resolved!
+ 53
30
@@ -12,6 +12,7 @@ from obspy import Stream, UTCDateTime, Trace, read, read_inventory
@@ -12,6 +12,7 @@ from obspy import Stream, UTCDateTime, Trace, read, read_inventory
from obspy.clients.fdsn.header import FDSNNoDataException
from obspy.clients.fdsn.header import FDSNNoDataException
from obspy.clients.iris import Client
from obspy.clients.iris import Client
from obspy.clients.fdsn import Client as FDSNClient
from obspy.clients.fdsn import Client as FDSNClient
 
from obspy.clients import neic
from .. import ChannelConverter, TimeseriesUtility
from .. import ChannelConverter, TimeseriesUtility
from ..geomag_types import DataInterval, DataType
from ..geomag_types import DataInterval, DataType
@@ -68,13 +69,14 @@ class FDSNFactory(TimeseriesFactory):
@@ -68,13 +69,14 @@ class FDSNFactory(TimeseriesFactory):
Notes
Notes
-----
-----
This is designed to read from the FDSN Client, but it
This is designed to read from the FDSN Client and EDGE if data is less than 1 day old
currently only writes to an edge.
"""
"""
def __init__(
def __init__(
self,
self,
base_url: str = "http://service.iris.edu",
fdsn_url: str = "http://service.iris.edu",
 
host: Optional[str] = "edgecwb.usgs.gov",
 
port: Optional[int] = 2061,
tag: str = "GeomagAlg",
tag: str = "GeomagAlg",
observatory: Optional[str] = None,
observatory: Optional[str] = None,
network: str = "NT",
network: str = "NT",
@@ -89,7 +91,9 @@ class FDSNFactory(TimeseriesFactory):
@@ -89,7 +91,9 @@ class FDSNFactory(TimeseriesFactory):
] = None, # Accepts "remove_sensitivity" or "remove_response"
] = None, # Accepts "remove_sensitivity" or "remove_response"
):
):
TimeseriesFactory.__init__(self, observatory, channels, type, interval)
TimeseriesFactory.__init__(self, observatory, channels, type, interval)
self.Client = FDSNClient(base_url)
self.Client = FDSNClient(fdsn_url)
 
self.port = port # Need to add this paramter for later logic
 
self.host = host
self.remove_sensitivity = remove_sensitivity
self.remove_sensitivity = remove_sensitivity
self.tag = tag
self.tag = tag
self.interval = interval
self.interval = interval
@@ -182,7 +186,6 @@ class FDSNFactory(TimeseriesFactory):
@@ -182,7 +186,6 @@ class FDSNFactory(TimeseriesFactory):
# # restore stdout
# # restore stdout
# sys.stdout = original_stdout
# sys.stdout = original_stdout
self._post_process(timeseries, starttime, endtime, channels)
self._post_process(timeseries, starttime, endtime, channels)
return timeseries
return timeseries
def _get_timeseries(
def _get_timeseries(
@@ -229,36 +232,69 @@ class FDSNFactory(TimeseriesFactory):
@@ -229,36 +232,69 @@ class FDSNFactory(TimeseriesFactory):
network=self.network,
network=self.network,
location=self.locationCode,
location=self.locationCode,
)
)
# 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 work assuming the metadata is reported correctly.
# Channel that require rotations
# Channel that require rotations
channel_rotations = ["X", "Y", "Z"]
channel_rotations = ["X", "Y", "Z"]
try:
try:
data = self.Client.get_waveforms(
# Create Inventory Object for rotations and attach response
 
inv = self.Client.get_stations(
network=sncl.network,
network=sncl.network,
station=sncl.station,
station=sncl.station,
location=sncl.location,
location=sncl.location, # Use location if necessary
channel=sncl.channel,
channel=sncl.channel, # Request *F1, *F2, and *FZ
starttime=starttime,
starttime=starttime,
endtime=endtime + half_delta,
endtime=endtime,
attach_response=True,
level="response",
)
)
 
 
# Determine whether to use FDSN Client or request data from EDGE
 
oldest_neic_utc = UTCDateTime.now() - (
 
86_400 * 60
 
) # `date` ensures a midnight boundary
 
if starttime >= oldest_neic_utc:
 
 
# use NEIC Client instead
 
neic_client = neic.Client(self.host, self.port)
 
 
neic_channel = [ch.strip() for ch in sncl.channel.split(",")]
 
data = Stream()
 
 
for single_channel in neic_channel:
 
data += neic_client.get_waveforms(
 
network=sncl.network,
 
station=sncl.station,
 
location=sncl.location,
 
channel=single_channel,
 
starttime=starttime,
 
endtime=endtime + half_delta,
 
)
 
 
else:
 
 
data = self.Client.get_waveforms(
 
network=sncl.network,
 
station=sncl.station,
 
location=sncl.location,
 
channel=sncl.channel,
 
starttime=starttime,
 
endtime=endtime + half_delta,
 
)
 
 
# Attach the channel response. This must be done before the _calibarate_sensitivity_and_response function is called
 
data.attach_response(inv)
 
# Perfrom calibrations to properly remove response/sensitivity
# Perfrom calibrations to properly remove response/sensitivity
data = self._calibrate_sensitivty_and_response(data)
data = self._calibrate_sensitivty_and_response(data)
if channel in channel_rotations:
if channel in channel_rotations:
data = self._rotate_and_return_requested_channel(
data = self._rotate_and_return_requested_channel(
data, sncl, starttime, endtime, channel
data, sncl, inv, starttime, endtime, channel
)
)
except FDSNNoDataException:
except FDSNNoDataException:
data = Stream()
data = Stream()
print(
print(
@@ -368,6 +404,7 @@ class FDSNFactory(TimeseriesFactory):
@@ -368,6 +404,7 @@ class FDSNFactory(TimeseriesFactory):
self,
self,
data: Stream,
data: Stream,
sncl,
sncl,
 
inv,
starttime: UTCDateTime,
starttime: UTCDateTime,
endtime: UTCDateTime,
endtime: UTCDateTime,
requested_channel: str,
requested_channel: str,
@@ -377,20 +414,6 @@ class FDSNFactory(TimeseriesFactory):
@@ -377,20 +414,6 @@ class FDSNFactory(TimeseriesFactory):
Channels are mapped as follows: 'X' -> '*F2', 'Y' -> '*F1', 'Z' -> '*FZ'.
Channels are mapped as follows: 'X' -> '*F2', 'Y' -> '*F1', 'Z' -> '*FZ'.
"""
"""
# Initialize FDSN client and get the necessary data
FDSN = self.Client
# Determine if the requested channel is X, Y, or
inv = FDSN.get_stations(
network=sncl.network,
station=sncl.station,
location=sncl.location, # Use location if necessary
channel=sncl.channel, # Request *F1, *F2, and *FZ
starttime=starttime,
endtime=endtime,
level="response",
)
# Rotate the stream to ZNE
# Rotate the stream to ZNE
data.rotate(method="->ZNE", inventory=inv)
data.rotate(method="->ZNE", inventory=inv)
Loading