Skip to content

Commit

Permalink
Use the global config object in ssp_util.py
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodsf committed Jul 10, 2024
1 parent dcf9219 commit 413b293
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion sourcespec2/ssp_build_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def _displacement_to_moment(stats):
lon = stats.coords.longitude
lat = stats.coords.latitude
depth = -stats.coords.elevation
medium_properties = MediumProperties(lon, lat, depth, config)
medium_properties = MediumProperties(lon, lat, depth)
depth_string = medium_properties.to_string('station depth', depth)
v_name = f'v{phase.lower()}'
v_source = config.event.hypocenter[v_name]
Expand Down
2 changes: 1 addition & 1 deletion sourcespec2/ssp_read_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def _hypo_vel(hypo):
:type hypo: :class:`sourcespec.ssp_event.Hypocenter`
"""
medium_properties = MediumProperties(
hypo.longitude, hypo.latitude, hypo.depth.value_in_km, config)
hypo.longitude, hypo.latitude, hypo.depth.value_in_km)
hypo.vp = medium_properties.get(mproperty='vp', where='source')
hypo.vs = medium_properties.get(mproperty='vs', where='source')
hypo.rho = medium_properties.get(mproperty='rho', where='source')
Expand Down
27 changes: 11 additions & 16 deletions sourcespec2/ssp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from obspy.signal.invsim import cosine_taper as _cos_taper
from obspy.geodetics import gps2dist_azimuth, kilometers2degrees
from obspy.taup import TauPyModel
from .config import config
model = TauPyModel(model='iasp91')
v_model = model.model.s_mod.v_mod
logger = logging.getLogger(__name__.rsplit('.', maxsplit=1)[-1])
Expand Down Expand Up @@ -64,15 +65,12 @@ class MediumProperties():
:type lat: float
:param depth_in_km: Depth (km).
:type depth_in_km: float
:param config: Configuration object.
:type config: :class:`~sourcespec.config.Config`
"""

def __init__(self, lon, lat, depth_in_km, config):
def __init__(self, lon, lat, depth_in_km):
self.lon = lon
self.lat = lat
self.depth_in_km = depth_in_km
self.config = config

def get_from_config_param_source(self, mproperty):
"""
Expand All @@ -86,13 +84,13 @@ def get_from_config_param_source(self, mproperty):
"""
if mproperty not in ['vp', 'vs', 'rho']:
raise ValueError(f'Invalid property: {mproperty}')
values = self.config[f'{mproperty}_source']
values = config[f'{mproperty}_source']
if values is None:
return None
if self.config.layer_top_depths is None:
if config.layer_top_depths is None:
return values[0]
values = np.array(values)
depths = np.array(self.config.layer_top_depths)
depths = np.array(config.layer_top_depths)
try:
# find the last value that is smaller than the source depth
value = values[depths <= self.depth_in_km][-1]
Expand All @@ -112,10 +110,9 @@ def get_from_config_param_station(self, mproperty):
"""
if mproperty not in ['vp', 'vs', 'rho']:
raise ValueError(f'Invalid property: {mproperty}')
value = self.config[f'{mproperty}_stations']
value = config[f'{mproperty}_stations']
if value is None:
value = self.get_from_config_param_source(
mproperty)
value = self.get_from_config_param_source(mproperty)
return value

def get_vel_from_NLL(self, wave):
Expand All @@ -131,7 +128,7 @@ def get_vel_from_NLL(self, wave):
# pylint: disable=import-outside-toplevel
from nllgrid import NLLGrid
grdfile = f'*.{wave}.mod.hdr'
grdfile = os.path.join(self.config.NLL_model_dir, grdfile)
grdfile = os.path.join(config.NLL_model_dir, grdfile)
try:
grdfile = glob(grdfile)[0]
except IndexError as e:
Expand Down Expand Up @@ -206,7 +203,7 @@ def get(self, mproperty, where):
else:
raise ValueError(f'Invalid location: {where}')
if (
self.config.NLL_model_dir is not None and
config.NLL_model_dir is not None and
mproperty in ['vp', 'vs']
):
wave = 'P' if mproperty == 'vp' else 'S'
Expand Down Expand Up @@ -372,10 +369,8 @@ def geom_spread_teleseismic(
# Don't need to specify coordinates, since we use a spherically symmetric
# Earth; don't need to specify a config object, since we use the global
# model (iasp91)
medium_properties_source = MediumProperties(
0, 0, source_depth_in_km, None)
medium_properties_station = MediumProperties(
0, 0, station_depth_in_km, None)
medium_properties_source = MediumProperties(0, 0, source_depth_in_km)
medium_properties_station = MediumProperties(0, 0, station_depth_in_km)
if phase == 'P':
v_source = medium_properties_source.get_from_taup('vp')
v_station = medium_properties_station.get_from_taup('vp')
Expand Down

0 comments on commit 413b293

Please sign in to comment.