Skip to content

Commit

Permalink
Fix various bugs and adds features to code (#60)
Browse files Browse the repository at this point in the history
* renamed specfem station writing function, and added an ordering component

* bumping version in setup and changing url and author

* small mt typo change

* added an example config that gathers a small amount of data for testing/dev purposes

* added a new kwarg 'order_stations_list_by' which sets the order of the output stations list, related to #36

* bugfix typo parameter call

* bugfix rotating was not actually rotating streams in place for arbitrary components ->ENZ

* bugfix fixed rotation testing, which was not actually evaluating as expected. some confusion about editing streams and inventories in place which was not actually happening. Fixed and now rotate test works as expected

* added 12Z test data for rotating 12Z -> ENZ which works now, added test to cover this case

* moved 2012 central alaska IU gather script (which gathers 12Z component) into examples

* bugfix pysep was not setting log level properly from the config file. now in the load() function, config log level is allowed to override logger level

* changed config examples dir name to test, to be used as a test bed for checking specific data gathering features such as data gap removal

* bugfix #57, reading event origin time from sac header was shifting times unexpectedly
  • Loading branch information
bch0w authored Dec 8, 2022
1 parent 55eb77d commit 12bee5c
Show file tree
Hide file tree
Showing 11 changed files with 2,131 additions and 55 deletions.
3 changes: 3 additions & 0 deletions pysep/configs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ The below information describes each of the category directories.
Quantification (MTUQ) workshop to demonstrate code capabilities.
- denali_nodal: Events recorded by the PASSCAL Denali Fault nodal deployment
- misc_events: One-off events with no overarching category
- test: test data collection that exhibits certain traits that are useful for
checking rejection criteria etc. Check comments at top of file to show
what the file is used for
46 changes: 46 additions & 0 deletions pysep/configs/test/check_rotate_12Z.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Testing IU Rotation Error - PySEP Issue #37
# IU.COLA raw stream returns 12Z which gets rotated appropriately
event_tag: null
config_file: null
client: IRIS
client_debug: false
timeout: 600
taup_model: ak135
event_selection: default
origin_time: '2012-04-11T09:21:57.444'
seconds_before_event: 20
seconds_after_event: 20
event_latitude: 64.9222
event_longitude: -148.9461
event_depth_km: 160.00
event_magnitude: 3.8
networks: 'IU'
stations: 'COLA'
channels: 'BH?,HH?'
locations: '*'
reference_time: null
seconds_before_ref: 100
seconds_after_ref: 600
phase_list: null
mindistance: 0
maxdistance: 200.0
minazimuth: 0
maxazimuth: 360
minlatitude: null
maxlatitude: null
minlongitude: null
maxlongitude: null
demean: true
detrend: true
taper_percentage: 0
rotate:
- ENZ
- RTZ
remove_response: true
output_unit: VEL
water_level: 60
pre_filt: default
scale_factor: 1.0
resample_freq: 50
remove_clipped: false
log_level: DEBUG
47 changes: 47 additions & 0 deletions pysep/configs/test/test_remove_data_gaps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Testing Data gap removal
# FIB has data gaps, should be removed from final data retrieval
event_tag: 2009-04-07T201255_SOUTHERN_ALASKA
config_file: null
client: IRIS
client_debug: false
timeout: 600
taup_model: ak135
event_selection: default
origin_time: '2009-04-07T20:12:55.351000Z'
seconds_before_event: 20
seconds_after_event: 20
event_latitude: 61.4542
event_longitude: -149.7428
event_depth_km: 33.033
event_magnitude: 4.6
networks: AK
stations: 'FIB,SWD'
channels: BH?
locations: '*'
reference_time: '2009-04-07T20:12:55.351000Z'
seconds_before_ref: 100
seconds_after_ref: 300
phase_list: null
mindistance: 0
maxdistance: 300.0
minazimuth: 0
maxazimuth: 360
minlatitude: null
maxlatitude: null
minlongitude: null
maxlongitude: null
demean: true
detrend: true
taper_percentage: 0
rotate:
- ENZ
- RTZ
remove_response: true
output_unit: VEL
water_level: 60
pre_filt: default
scale_factor: 1.0
resample_freq: 50
remove_clipped: false
log_level: DEBUG

40 changes: 28 additions & 12 deletions pysep/pysep.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ def __init__(self, config_file=None, event_selection="default",
"""
Define a default set of parameters
TODO
* removed resample_TF, was this used?
* load config FIRST and then set defaults, make all defaults None?
:type client: str
:param client: ObsPy FDSN client to query data from, e.g., IRIS, LLNL,
NCEDC or any FDSN clients accepted by ObsPy
Expand Down Expand Up @@ -269,6 +265,10 @@ def __init__(self, config_file=None, event_selection="default",
else:
logger.disabled = True

# Allow User to throw in general kwargs. This allows things to be
# more general, but also may obscure some parameters.
self.kwargs = kwargs

def check(self):
"""
Check input parameter validity against expected Pysep behavior
Expand Down Expand Up @@ -448,6 +448,13 @@ def load(self, config_file=None, overwrite_event=True):
logger.debug(f"{key}: {old_val} -> {val}")
setattr(self, key, val)

# Reset log level based on the config file
if self.log_level is not None:
logger.debug(f"`log_level` set to {self.log_level}")
logger.setLevel(self.log_level)
else:
logger.disabled = True

def get_event(self):
"""
Exposed API for grabbing event metadata depending on the
Expand Down Expand Up @@ -890,8 +897,8 @@ def rotate_streams(self):
# important as some IRIS data will be in ZNE but not be aligned
# https://github.com/obspy/obspy/issues/2056
_st.rotate(method="->ZNE", inventory=self.inv,
components=["ZNE"])
st_out += st_zne
components=["ZNE", "Z12", "123"])
st_out += _st
if "UVW" in self.rotate:
logger.info("rotating to components UVW")
st_uvw = rotate_to_uvw(st_out)
Expand All @@ -908,9 +915,12 @@ def rotate_streams(self):
_st.rotate(method="NE->RT") # in place rot.
if hasattr(_st[0].stats, "back_azimuth"):
logger.debug(f"{sta}: BAz={_st[0].stats.back_azimuth}")
st_out += st_rtz

st_out = format_sac_headers_post_rotation(st_out)
st_out += _st

try:
st_out = format_sac_headers_post_rotation(st_out)
except AttributeError as e:
logger.warning(f"cannot format SAC headers after rotating {e}")

return st_out

Expand Down Expand Up @@ -957,6 +967,9 @@ def write(self, write_files=None, _return_filenames=False,
:type stream_fid: optional name for saved ObsPy Stream miniseed object,
defaults to 'stream.ms'
"""
# Collect kwargs for writing
order_stations_list_by = kwargs.get("order_stations_list_by", None)

# This is defined here so that all these filenames are in one place,
# but really this set is just required by check(), not by write()
_acceptable_files = {"weights_az", "weights_dist", "weights_code",
Expand Down Expand Up @@ -995,7 +1008,10 @@ def write(self, write_files=None, _return_filenames=False,
stations_fid or "stations_list.txt")
logger.info("writing stations file")
logger.debug(fid)
write_pysep_stations_file(self.inv, self.event, fid)
write_pysep_stations_file(
self.inv, self.event, fid,
order_stations_list_by=order_stations_list_by
)

if "inv" in write_files or "all" in write_files:
fid = os.path.join(self.output_dir, inv_fid or f"inv.xml")
Expand Down Expand Up @@ -1199,7 +1215,7 @@ def run(self, event=None, inv=None, st=None, **kwargs):
self.st = quality_check_waveforms_after_processing(self.st)

# Generate outputs for user consumption
self.write(**kwargs)
self.write(**{**kwargs, **self.kwargs})
self.plot()


Expand Down Expand Up @@ -1239,7 +1255,7 @@ def parse_args():
"filled in by the User")
parser.add_argument("-l", "--list", default=False, action="store_true",
help="list out avaialable `preset` config options")
parser.add_argument("-L", "--log_level", default="INFO", type=str,
parser.add_argument("-L", "--log_level", default="DEBUG", type=str,
nargs="?", help="verbosity of logging: 'WARNING', "
"'INFO', 'DEBUG'")
parser.add_argument("--legacy_naming", default=False, action="store_true",
Expand Down
Loading

0 comments on commit 12bee5c

Please sign in to comment.