Skip to content

run_id #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 18, 2022
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Earthquake source parameters from S-wave displacement spectra
- Write SourceSpec version and run complete time to SQLite file
- Write author and agency info (if specified) to output files, figures and
HTML report
- Command line option `--run-id` to provide a string identifying the
current run (see pull request [#6][])

- Improvements:
- Use travel time (from NonLinLoc grid, "iasp91" model or `vs_tt`) to compute
Expand Down Expand Up @@ -90,7 +92,7 @@ Note that v1.5 is no more compatible with Python 2!
parameter, named `clip_max_percent`)
- Check for trace clipping only in the processing window
- Use histogram of samples to detect clipping
- Fix for wrong component used for 'SV' spectra (#3)
- Fix for wrong component used for 'SV' spectra (see issue [#3][])
- Inversion:
- New config option: `Mw_0_variability`. Allowed variability around `Mw_0`
during the main inversion. Previously hardcoded to 0.1
Expand Down Expand Up @@ -303,3 +305,7 @@ Extended and generalized for the CRL application.
## v0.1 - 2012-01-17

Initial Python port.


[#3]: https://github.com/SeismicSource/sourcespec/issues/3
[#6]: https://github.com/SeismicSource/sourcespec/issues/6
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Emanuela Matrullo
Agnès Chounet
Tony Alfredo Stabile
Sophie Lambotte
Kris Vanneste
6 changes: 6 additions & 0 deletions sourcespec/html_report_template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ <h2>Event Summary</h2>
<th scope="row">Event ID:</th>
<td>{EVENTID}</td>
</tr>
{RUNID_COMMENT_BEGIN}
<tr>
<th scope="row">Run ID:</th>
<td>{RUNID}</td>
</tr>
{RUNID_COMMENT_END}
<tr>
<th scope="row">Longitude:</th>
<td>{EVENT_LONGITUDE} °E</td>
Expand Down
14 changes: 14 additions & 0 deletions sourcespec/ssp_html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def html_report(config, sourcepar):
# Output files and maps
hypo = config.hypo
evid = hypo.evid
run_id = config.options.run_id
config_file = '{}.ssp.conf'.format(evid)
out_file = '{}.ssp.out'.format(evid)
log_file = '{}.ssp.log'.format(evid)
Expand Down Expand Up @@ -364,6 +365,7 @@ def html_report(config, sourcepar):
'{AUTHOR}': author,
'{AGENCY}': agency,
'{EVENTID}': evid,
'{RUNID}': run_id,
'{EVENT_LONGITUDE}': '{:8.3f}'.format(hypo.longitude),
'{EVENT_LATITUDE}': '{:7.3f}'.format(hypo.latitude),
'{EVENT_DEPTH}': '{:5.1f}'.format(hypo.depth),
Expand Down Expand Up @@ -425,6 +427,18 @@ def html_report(config, sourcepar):
'{STATION_TABLE_ROWS}': station_table_rows,
}

# Only show Run ID if it is not empty
if run_id:
run_id_comment_begin = ''
run_id_comment_end = ''
else:
run_id_comment_begin = '<!--'
run_id_comment_end = '-->'
replacements.update({
'{RUNID_COMMENT_BEGIN}': run_id_comment_begin,
'{RUNID_COMMENT_END}': run_id_comment_end
})

# Misfit plots (when using grid search)
if os.path.exists(os.path.join(config.options.outdir, 'misfit')):
misfit_plot_comment_begin = ''
Expand Down
20 changes: 12 additions & 8 deletions sourcespec/ssp_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,12 @@ def _write_parfile(config, sourcepar):
parfile.write('\n*** Run completed on: {} {}'.format(now, timezone))
config.end_of_run = now
config.end_of_run_tz = timezone
if config.options.run_id:
parfile.write('\n*** Run ID: {}'.format(config.options.run_id))
_write_author_and_agency_to_parfile(config, parfile)

parfile.close()

logger.info('Output written to file: ' + parfilename)


Expand All @@ -284,6 +287,7 @@ def _write_db(config, sourcepar):

hypo = config.hypo
evid = hypo.evid
runid = config.options.run_id

# Open SQLite database
conn = sqlite3.connect(database_file, timeout=60)
Expand All @@ -292,7 +296,7 @@ def _write_db(config, sourcepar):
# Init Station table
c.execute(
'create table if not exists Stations '
'(stid, evid,'
'(stid, evid, runid,'
'Mo, Mo_err_minus, Mo_err_plus,'
'Mw, Mw_err_minus, Mw_err_plus,'
'fc, fc_err_minus, fc_err_plus,'
Expand All @@ -308,11 +312,11 @@ def _write_db(config, sourcepar):
nobs += 1
par = stationpar[statId]
# Remove existing line, if present
t = (statId, evid)
c.execute('delete from Stations where stid=? and evid=?;', t)
t = (statId, evid, runid)
c.execute('delete from Stations where stid=? and evid=? and runid=?;', t)
# Insert new line
t = (
statId, evid,
statId, evid, runid,
par['Mo'], *par['Mo_err'],
par['Mw'], *par['Mw_err'],
par['fc'], *par['fc_err'],
Expand All @@ -335,7 +339,7 @@ def _write_db(config, sourcepar):
# Init Event table
c.execute(
'create table if not exists Events '
'(evid, orig_time, lon, lat, depth, nobs,'
'(evid, runid, orig_time, lon, lat, depth, nobs,'
'Mo, Mo_err_minus, Mo_err_plus,'
'Mo_wavg, Mo_wavg_err_minus, Mo_wavg_err_plus,'
'Mw, Mw_err, Mw_wavg, Mw_wavg_err,'
Expand All @@ -361,10 +365,10 @@ def _write_db(config, sourcepar):
run_completed = '{} {}'.format(config.end_of_run, config.end_of_run_tz)
ssp_version = get_versions()['version']
# Remove event from Event table, if present
t = (evid, )
c.execute('delete from Events where evid=?;', t)
t = (evid, runid)
c.execute('delete from Events where evid=? and runid=?;', t)
t = (
evid,
evid, runid,
str(hypo.origin_time),
float(hypo.longitude), float(hypo.latitude), float(hypo.depth),
nobs,
Expand Down
6 changes: 6 additions & 0 deletions sourcespec/ssp_parse_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ def _update_parser(parser, progname):
help='save output to OUTDIR (default: sspec_out)',
metavar='OUTDIR'
)
parser.add_argument(
'-r', '--run_id', dest='run_id',
action='store', default='',
help='string identifying current run (default: "")',
metavar='RUN_ID'
)
elif progname == 'source_model':
parser.add_argument(
'-f', '--fmin', dest='fmin', action='store',
Expand Down
7 changes: 5 additions & 2 deletions sourcespec/ssp_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,17 @@ def save_config(config):


def move_outdir(config):
"""Move outdir to a new dir named from evid."""
"""Move outdir to a new dir named from evid (and optional run_id)."""
try:
evid = config.hypo.evid
except Exception:
return
src = config.options.outdir
run_id = config.options.run_id
path = os.path.normpath(config.options.outdir).split(os.sep)
dst = os.path.join(*path[:-1], evid)
dst = os.path.join(*path[:-1], str(evid))
if run_id:
dst += '_' + run_id
# Create destination
if not os.path.exists(dst):
os.makedirs(dst)
Expand Down