Skip to content

Commit

Permalink
removed parameters 'log_level' and 'legacy_naming' from the default c…
Browse files Browse the repository at this point in the history
…onfig writing function, remade the template config, added new test to check the example config files are still in order and removed some unncessary parameters from example configs
  • Loading branch information
bch0w committed Nov 20, 2023
1 parent 7a11b63 commit 8428d7d
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ remove_insufficient_length: true
remove_masked_data: true
fill_data_gaps: false
gap_fraction: 1.0
log_level: DEBUG
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ remove_insufficient_length: true
remove_masked_data: true
fill_data_gaps: false
gap_fraction: 1.0
log_level: DEBUG
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ remove_insufficient_length: true
remove_masked_data: true
fill_data_gaps: false
gap_fraction: 1.0
log_level: DEBUG
1 change: 0 additions & 1 deletion pysep/configs/misc_events/2016-01-24T103037_INISKIN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ remove_insufficient_length: true
remove_masked_data: true
fill_data_gaps: false
gap_fraction: 1.0
log_level: DEBUG
58 changes: 29 additions & 29 deletions pysep/configs/template_config.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
# PYSEP Config file - Template v0.1.0
# PySEP Template config v0.5.0
event_tag: null
config_file: null
client: IRIS
client_debug: false
timeout: 600
taup_model: ak135
use_mass_download: false
event_selection: default
origin_time: 2009-04-07T20:12:55.351
origin_time: null
seconds_before_event: 20
seconds_after_event: 20
event_latitude: 61.45420
event_longitude: -149.7428
event_depth_km: 33.033
event_magnitude: 4.6
networks: 'AK,YV,AV,AT,XZ,PN'
event_latitude: null
event_longitude: null
event_depth_km: null
event_magnitude: null
networks: '*'
stations: '*'
channels: 'BH?'
channels: '*'
locations: '*'
reference_time: null
seconds_before_ref: 100
seconds_after_ref: 300
phase_list: null
llnl_db_path: /store/raw/LLNL/UCRL-MI-222502/westernus.wfdisc
min_dist: 0
max_dist: 300.0
min_az: 0
max_az: 360
min_lat: null
max_lat: null
min_lon: null
max_lon: null
phase_list:
- ttall
mindistance_km: 0
maxdistance_km: 20000.0
minazimuth: 0
maxazimuth: 360
minlatitude: null
maxlatitude: null
minlongitude: null
maxlongitude: null
demean: true
detrend: true
taper_percentage: 0
taper_percentage: 0.0
rotate: null
remove_response: true
output_unit: VEL
water_level: 60
pre_filt: default
scale_factor: 100.0
resample_freq: 50
remove_clipped: false
output_dir: ./
write_files: !!set
all: null
plot_files: !!set
all: null
log_level: DEBUG
event_tag: null
scale_factor: 1
resample_freq: null
remove_clipped: true
remove_insufficient_length: true
remove_masked_data: true
fill_data_gaps: false
gap_fraction: 1.0
6 changes: 2 additions & 4 deletions pysep/pysep.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,6 @@ def load(self, config_file=None, overwrite_event=True):
logger.debug(f"{key}: {old_val} -> {val}")
setattr(self, key, val)
else:
import pdb;pdb.set_trace()
logger.warning(f"config parameter '{key}' not explicitely "
f"used by PySEP. adding to kwargs")
self.kwargs[key] = val
Expand Down Expand Up @@ -1681,10 +1680,9 @@ def write_config(self, fid=None, overwrite=False):
if not key.startswith("_")}
# Internal attributes that don't need to go into the written config
attr_remove_list = ["st", "st_raw", "event", "inv", "c", "write_files",
"plot_files", "output_dir", "station_ids", "kwargs"]
"plot_files", "output_dir", "station_ids", "kwargs",
"llnl_db_path", "log_level", "legacy_naming"]

if self.client.upper() != "LLNL":
attr_remove_list.append("llnl_db_path") # not important unless LLNL
for key in attr_remove_list:
del(dict_out[key])
# Write times in as strings not UTCDateTime
Expand Down
29 changes: 29 additions & 0 deletions pysep/tests/test_pysep.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""
Test the general functionality of Pysep
"""
from re import L
import pytest
import os
import yaml
from glob import glob
from pysep import Pysep, logger


Expand Down Expand Up @@ -75,3 +79,28 @@ def test_curtail_stations(test_pysep):

assert(nsta_pre_curtail - nsta_post_curtail == 6)


def test_config_files_have_correct_parameters(tmpdir, test_pysep):
"""
Check that all the config files have the correct parameters based on what
PySEP writes to ensure that the config files are up to date with codebase
"""
# Write a config file from the Pysep instance and read in the yaml file
fid = os.path.join(tmpdir, "test_config.yaml")
test_pysep.write_config(fid=fid)
config = set(yaml.safe_load(open(fid)).keys())

# Get the directory containing the example config files
config_dir = "../configs/"

# Iterate over all the yaml files in the directory
for dir_ in glob(os.path.join(config_dir, "*")):
if not os.path.isdir(dir_):
continue
for fid in glob(os.path.join(dir_, "*")):
if not fid.endswith(".yaml"):
continue
with open(fid, "r") as f:
config_check = set(yaml.safe_load(f).keys())
assert(config.issubset(config_check)), \
f"Config file {fid} does not have the correct parameters"

0 comments on commit 8428d7d

Please sign in to comment.