Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #702 from cbworden/select
Browse files Browse the repository at this point in the history
Changed name of model_zc.conf to model_select.conf; added comment to top
  • Loading branch information
emthompson-usgs authored Jul 20, 2018
2 parents 2c23f29 + d50cd31 commit 9de66a0
Show file tree
Hide file tree
Showing 25 changed files with 241 additions and 118 deletions.
6 changes: 3 additions & 3 deletions shakemap/coremods/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AssembleModule(CoreModule):
dependencies = [('event.xml', True), ('*_dat.xml', False),
('*_fault.txt', False), ('rupture.json', False),
('source.txt', False), ('model.conf', False),
('model_zc.conf', False)]
('model_select.conf', False)]
configs = ['gmpe_sets.conf', 'model.conf', 'modules.conf']

def __init__(self, eventid, comment=None):
Expand Down Expand Up @@ -125,10 +125,10 @@ def execute(self):

#
# this is the event specific model.conf (may not be present)
# prefer model.conf to model_zc.conf
# prefer model.conf to model_select.conf
#
event_config_file = os.path.join(datadir, 'model.conf')
event_config_zc_file = os.path.join(datadir, 'model_zc.conf')
event_config_zc_file = os.path.join(datadir, 'model_select.conf')
if os.path.isfile(event_config_file):
event_config = ConfigObj(event_config_file,
configspec=spec_file)
Expand Down
6 changes: 3 additions & 3 deletions shakemap/coremods/augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ def execute(self):
shake_config.merge(extent_config)
#
# this is the event specific model.conf (may not be present)
# prefer model.conf to model_zc.conf
# prefer model.conf to model_select.conf
#
event_config_file = os.path.join(datadir, 'model.conf')
event_config_zc_file = os.path.join(datadir, 'model_zc.conf')
event_config_zc_file = os.path.join(datadir, 'model_select.conf')
if os.path.isfile(event_config_file):
self.logger.debug('Found an event specific model.conf file.')
event_config = ConfigObj(event_config_file,
configspec=spec_file)
shake_config.merge(event_config)
elif os.path.isfile(event_config_zc_file):
self.logger.debug('Found an event specific model_zc file.')
self.logger.debug('Found an event specific model_select file.')
event_config = ConfigObj(event_config_zc_file,
configspec=spec_file)
shake_config.merge(event_config)
Expand Down
2 changes: 1 addition & 1 deletion shakemap/coremods/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CoreModule(ABC):
# directory (and must therefore be prefixed with 'products/' if they
# are found in the products directory); configs are assumed to be
# found in the profile's config directory (and, thus, event-specific
# configs like model_zc.conf should be listed in dependencies, not
# configs like model_select.conf should be listed in dependencies, not
# configs.
#
# targets should be regexp strings, e.g.:
Expand Down
32 changes: 24 additions & 8 deletions shakemap/coremods/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os.path
import shutil
from collections import OrderedDict
import textwrap

# third party imports
from configobj import ConfigObj
Expand All @@ -20,19 +21,19 @@

class SelectModule(CoreModule):
"""
select - Parse STREC output, make a GMPE set, create model_zc.conf.
select - Parse STREC output, make a GMPE set, create model_select.conf.
"""

command_name = 'select'
targets = [r'model_zc\.conf']
targets = [r'model_select\.conf']
dependencies = [('event.xml', True), ('source.text', False)]
configs = ['select.conf']

def execute(self):
'''
Parses the output of STREC in accordance with the
configuration file, creates a new GMPE set specific to the event,
and writes model_zc.conf in the event's 'current' directory.
and writes model_select.conf in the event's 'current' directory.
Configuration file: select.conf
Expand Down Expand Up @@ -91,22 +92,31 @@ def execute(self):
# ---------------------------------------------------------------------
# Get the default weighting for this event
# ---------------------------------------------------------------------
gmpe_list, weight_list, strec_results = get_weights(org, config)
gmmdict, strec_results = get_weights(org, config)

# ---------------------------------------------------------------------
# Create ConfigObj object for output to model_zc.conf
# Create ConfigObj object for output to model_select.conf
# ---------------------------------------------------------------------
zc_file = os.path.join(datadir, 'model_zc.conf')
zc_file = os.path.join(datadir, 'model_select.conf')
zc_conf = ConfigObj(indent_type=' ')
zc_conf.filename = zc_file
zc_conf.initial_comment = textwrap.wrap(
"This file (model_select.conf) is generated automatically by the "
"'select' coremod. It will be completely overwritten the next "
"time select is run. To preserve these settings, or to modify "
"them, copy this file to a file called 'model.conf' in the "
"event's current directory. That event-specific model.conf will "
"be used and model_select.conf will be ignored. (To avoid "
"confusion, you should probably delete this comment section "
"from your event-specific model.conf.)", width=75)
#
# Add the new gmpe set to the object
#
gmpe_set = 'gmpe_' + str(self._eventid) + '_custom'
zc_conf['gmpe_sets'] = OrderedDict([
(gmpe_set, OrderedDict([
('gmpes', list(gmpe_list)),
('weights', list(weight_list)),
('gmpes', list(gmmdict['gmpelist'])),
('weights', list(gmmdict['weightlist'])),
('weights_large_dist', 'None'),
('dist_cutoff', 'nan'),
('site_gmpes', 'None'),
Expand All @@ -120,5 +130,11 @@ def execute(self):
('gmpe', gmpe_set),
('mechanism', strec_results['FocalMechanism'])
])
if gmmdict['ipe']:
zc_conf['modeling']['ipe'] = gmmdict['ipe']
if gmmdict['gmice']:
zc_conf['modeling']['gmice'] = gmmdict['gmice']
if gmmdict['ccf']:
zc_conf['modeling']['ccf'] = gmmdict['ccf']

zc_conf.write()
19 changes: 16 additions & 3 deletions shakemap/data/select.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,27 @@
gmpe = active_crustal_nshmp2014, active_crustal_deep
min_depth = -Inf, 30
max_depth = 30, Inf
ipe = VirtualIPE
gmice = WGRW12
ccf = LB13
[[scr]]
horizontal_buffer = 100
vertical_buffer = 5
gmpe = stable_continental_nshmp2014_rlme, stable_continental_deep
min_depth = -Inf, 50
max_depth = 50, Inf
ipe = VirtualIPE
gmice = AK07
ccf = LB13
[[subduction]]
horizontal_buffer = 100
vertical_buffer = 5
gmpe = subduction_crustal, subduction_interface_nshmp2014, subduction_slab_nshmp2014
min_depth = -Inf, 15, 70
max_depth = 15, 70, Inf
ipe = VirtualIPE
gmice = WGRW12
ccf = LB13
[[[crustal]]]
gmpe = subduction_crustal
[[[interface]]]
Expand All @@ -51,6 +60,9 @@
gmpe = volcanic
min_depth = -Inf
max_depth = Inf
ipe = VirtualIPE
gmice = WGRW12
ccf = LB13

##############################################################################
# Layers will be preferred in the order given here regardless of
Expand All @@ -63,13 +75,13 @@
# [[[scr]]]
# horizontal_buffer = 50
# vertical_buffer = 5
# gmpe = AB06
# gmpe = AB06_set
# min_depth = 0
# max_depth = 999
# [[[acr]]]
# horizontal_buffer = 50
# vertical_buffer = 5
# gmpe = CY14
# gmpe = CY14_set
# min_depth = 0
# max_depth = 999
##############################################################################
Expand All @@ -81,7 +93,8 @@
# In the path, the string <INSTALL_DIR> will be replaced with the current
# profile's install directory. layer_dir may be 'None' in which case no
# geographic layers will be used.
layer_dir = <INSTALL_DIR>/data/layers
# layer_dir = <INSTALL_DIR>/data/layers
layer_dir = None
[[induced]]
horizontal_buffer = 50
[[[scr]]]
Expand Down
4 changes: 2 additions & 2 deletions shakemap/utils/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ def __buildDependencyTree(self, cmd, root=None):
fp_exists = len(glob.glob(fp[0]))
# If a file is optional and does not exist, we don't want to
# force the system to make it. (E.g., we don't want to force
# 'select' to run if model_zc.conf isn't already there -- that's
# the user's choice.
# 'select' to run if model_select.conf isn't already there --
# that's the user's choice.
if fp[1] == 0 and not fp_exists:
continue
parent_cmd = self.__findCmd(fp[0])
Expand Down
6 changes: 4 additions & 2 deletions shakemap/utils/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def validate_config(mydict, install_path):
elif key in ('x1', 'x2', 'p1', 'p2', 'p_kagan_default',
'default_slab_depth'):
mydict[key] = float(mydict[key])
elif key in ('ipe', 'gmice', 'ccf'):
pass
else:
raise ValidateError('Invalid entry in config: "%s"' % (key))
return
Expand Down Expand Up @@ -163,7 +165,7 @@ def update_config_regions(lat, lon, config):
inside_layer_name = None
if 'layers' in config and 'layer_dir' in config['layers']:
layer_dir = config['layers']['layer_dir']
if layer_dir and layer_dir != 'None':
if layer_dir:
geo_layers = get_layer_distances(lon, lat, layer_dir)
else:
geo_layers = {}
Expand All @@ -187,5 +189,5 @@ def update_config_regions(lat, lon, config):
for region, rdict in layer_config.items():
if region == 'horizontal_buffer':
continue
config['tectonic_regions'][region] = rdict
config['tectonic_regions'][region].update(rdict)
return config
41 changes: 39 additions & 2 deletions shakemap/utils/probs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,42 @@ def get_weights(origin, config):
weightlist = np.array(weightlist)
logging.debug('gmpelist: %s' % gmpelist)
logging.debug('weightlist: %s' % weightlist)
return gmpelist, weightlist, strec_results
gmmdict = {'gmpelist': gmpelist,
'weightlist': weightlist}
#
# Here we get the region-specific ipe, gmice, and ccf. If they are
# not specified in the config, we use None, and let the value
# fall back to whatever is specified in the system config.
#
if strec_results['TectonicRegion'] == 'Active':
gmmdict['ipe'] = config['tectonic_regions']['acr'].get(
'ipe', None)
gmmdict['gmice'] = config['tectonic_regions']['acr'].get(
'gmice', None)
gmmdict['ccf'] = config['tectonic_regions']['acr'].get(
'ccf', None)
elif strec_results['TectonicRegion'] == 'Stable':
gmmdict['ipe'] = config['tectonic_regions']['scr'].get(
'ipe', None)
gmmdict['gmice'] = config['tectonic_regions']['scr'].get(
'gmice', None)
gmmdict['ccf'] = config['tectonic_regions']['scr'].get(
'ccf', None)
elif strec_results['TectonicRegion'] == 'Subduction':
gmmdict['ipe'] = config['tectonic_regions']['subduction'].get(
'ipe', None)
gmmdict['gmice'] = config['tectonic_regions']['subduction'].get(
'gmice', None)
gmmdict['ccf'] = config['tectonic_regions']['subduction'].get(
'ccf', None)
elif strec_results['TectonicRegion'] == 'Volcanic':
gmmdict['ipe'] = config['tectonic_regions']['volcanic'].get(
'ipe', None)
gmmdict['gmice'] = config['tectonic_regions']['volcanic'].get(
'gmice', None)
gmmdict['ccf'] = config['tectonic_regions']['volcanic'].get(
'ccf', None)
return gmmdict, strec_results


def get_probs(origin, config):
Expand All @@ -90,7 +125,8 @@ def get_probs(origin, config):
type.
Returns:
dict: Probabilities for each earthquake type, with fields:
(dict, dict):
Probabilities for each earthquake type, with fields:
- acr Probability that the earthquake is in an active region.
- acr_X Probability that the earthquake is in a depth layer of
ACR, starting from the top.
Expand All @@ -108,6 +144,7 @@ def get_probs(origin, config):
- interface Probability that the earthquake is on the interface.
- intraslab Probability that the earthquake is in the slab below
interface.
STREC results
"""
selector = SubductionSelector()
Expand Down
26 changes: 20 additions & 6 deletions tests/data/install/config/select.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,27 @@
gmpe = active_crustal_nshmp2014, active_crustal_deep
min_depth = -Inf, 30
max_depth = 30, Inf
ipe = VirtualIPE
gmice = WGRW12
ccf = LB13
[[scr]]
horizontal_buffer = 100
vertical_buffer = 5
gmpe = stable_continental_nshmp2014_rlme, stable_continental_deep
min_depth = -Inf, 50
max_depth = 50, Inf
ipe = VirtualIPE
gmice = AK07
ccf = LB13
[[subduction]]
horizontal_buffer = 100
vertical_buffer = 5
gmpe = subduction_crustal, subduction_interface_nshmp2014, subduction_slab_nshmp2014
min_depth = -Inf, 15, 70
max_depth = 15, 70, Inf
ipe = VirtualIPE
gmice = WGRW12
ccf = LB13
[[[crustal]]]
gmpe = subduction_crustal
[[[interface]]]
Expand All @@ -48,9 +57,13 @@
[[volcanic]]
horizontal_buffer = 10
vertical_buffer = 5
gmpe = active_crustal_nshmp2014, active_crustal_deep
min_depth = -Inf, 30
max_depth = 30, Inf
gmpe = volcanic
min_depth = -Inf
max_depth = Inf
ipe = VirtualIPE
gmice = WGRW12
ccf = LB13

##############################################################################
# Layers will be preferred in the order given here regardless of
# their order in the STREC output
Expand All @@ -62,13 +75,13 @@
# [[[scr]]]
# horizontal_buffer = 50
# vertical_buffer = 5
# gmpe = AB06
# gmpe = AB06_set
# min_depth = 0
# max_depth = 999
# [[[acr]]]
# horizontal_buffer = 50
# vertical_buffer = 5
# gmpe = CY14
# gmpe = CY14_set
# min_depth = 0
# max_depth = 999
##############################################################################
Expand All @@ -80,7 +93,8 @@
# In the path, the string <INSTALL_DIR> will be replaced with the current
# profile's install directory. layer_dir may be 'None' in which case no
# geographic layers will be used.
layer_dir = <INSTALL_DIR>/layers
layer_dir = <INSTALL_DIR>/data/layers
# layer_dir = None
[[induced]]
horizontal_buffer = 50
[[[scr]]]
Expand Down
Loading

0 comments on commit 9de66a0

Please sign in to comment.