From 6d5c70ec32069e72afadcb27d8db9d80d6340b77 Mon Sep 17 00:00:00 2001 From: Albert Kottke Date: Mon, 1 Aug 2022 13:55:38 -0700 Subject: [PATCH 01/11] Change to use global configuration. --- gmprocess/subcommands/base.py | 1 + gmprocess/subcommands/compute_station_metrics.py | 2 +- gmprocess/subcommands/compute_waveform_metrics.py | 2 +- gmprocess/subcommands/export_metric_tables.py | 2 +- gmprocess/subcommands/export_shakemap.py | 3 +-- gmprocess/subcommands/generate_report.py | 2 +- gmprocess/subcommands/process_waveforms.py | 9 ++++----- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/gmprocess/subcommands/base.py b/gmprocess/subcommands/base.py index 0d75c1a71..8d239184e 100644 --- a/gmprocess/subcommands/base.py +++ b/gmprocess/subcommands/base.py @@ -46,6 +46,7 @@ def open_workspace(self, eventid): return eventid self.workspace = ws.StreamWorkspace.open(workname) + self.gmrecords.conf = self._get_config() def close_workspace(self): """Close workspace.""" diff --git a/gmprocess/subcommands/compute_station_metrics.py b/gmprocess/subcommands/compute_station_metrics.py index b2c157c9d..e06af359f 100644 --- a/gmprocess/subcommands/compute_station_metrics.py +++ b/gmprocess/subcommands/compute_station_metrics.py @@ -77,7 +77,7 @@ def _event_station_metrics(self, event): ds = self.workspace.dataset self._get_labels() - config = self._get_config() + config = self.gmrecords.conf if not hasattr(self, "vs30_grids"): vs30_grids = None diff --git a/gmprocess/subcommands/compute_waveform_metrics.py b/gmprocess/subcommands/compute_waveform_metrics.py index 556af9345..c914696ca 100644 --- a/gmprocess/subcommands/compute_waveform_metrics.py +++ b/gmprocess/subcommands/compute_waveform_metrics.py @@ -67,7 +67,7 @@ def _compute_event_waveform_metrics(self, event): ds = self.workspace.dataset station_list = ds.waveforms.list() self._get_labels() - config = self._get_config() + config = self.gmrecords.conf summaries = [] metricpaths = [] diff --git a/gmprocess/subcommands/export_metric_tables.py b/gmprocess/subcommands/export_metric_tables.py index 6afd0fddc..e477c69f4 100644 --- a/gmprocess/subcommands/export_metric_tables.py +++ b/gmprocess/subcommands/export_metric_tables.py @@ -56,7 +56,7 @@ def main(self, gmrecords): self.workspace = ws.StreamWorkspace.open(workname) self._get_labels() - config = self._get_config() + config = self.gmrecords.conf event_table, imc_tables, readmes = self.workspace.getTables( self.gmrecords.args.label, config diff --git a/gmprocess/subcommands/export_shakemap.py b/gmprocess/subcommands/export_shakemap.py index 576a1554c..7cf1b4a53 100644 --- a/gmprocess/subcommands/export_shakemap.py +++ b/gmprocess/subcommands/export_shakemap.py @@ -66,7 +66,6 @@ def main(self, gmrecords): self.workspace = ws.StreamWorkspace.open(workname) self._get_labels() - config = self._get_config() expanded_imts = self.gmrecords.args.expand_imts jsonfile, stationfile, _ = sm_utils.create_json( @@ -74,7 +73,7 @@ def main(self, gmrecords): event, event_dir, self.gmrecords.args.label, - config=config, + config=self.gmrecords.conf, expanded_imts=expanded_imts, ) diff --git a/gmprocess/subcommands/generate_report.py b/gmprocess/subcommands/generate_report.py index 62903da0c..5ce8d44f3 100644 --- a/gmprocess/subcommands/generate_report.py +++ b/gmprocess/subcommands/generate_report.py @@ -44,6 +44,7 @@ def main(self, gmrecords): logging.info(f"Running subcommand '{self.command_name}'") self.gmrecords = gmrecords + config = self.gmrecords.conf self._check_arguments() self._get_events() @@ -55,7 +56,6 @@ def main(self, gmrecords): logging.info(f"Generating summary report for event {event.id}...") - config = self._get_config() build_conf = config["build_report"] if build_conf["enabled"]: report_format = build_conf["format"] diff --git a/gmprocess/subcommands/process_waveforms.py b/gmprocess/subcommands/process_waveforms.py index bd07ba6fd..d6b0534c0 100644 --- a/gmprocess/subcommands/process_waveforms.py +++ b/gmprocess/subcommands/process_waveforms.py @@ -82,12 +82,11 @@ def _process_event(self, event): for station_id in station_list: # Cannot parallelize IO to ASDF file - config = self._get_config() raw_streams = self.workspace.getStreams( event.id, stations=[station_id], labels=["unprocessed"], - config=config, + config=self.gmrecords.conf, ) if self.gmrecords.args.reprocess: # Don't use "processed_streams" variable name because that is what is @@ -98,7 +97,7 @@ def _process_event(self, event): event.id, stations=[station_id], labels=[self.process_tag], - config=config, + config=self.gmrecords.conf, ) logging.debug(old_streams.describe()) else: @@ -119,14 +118,14 @@ def _process_event(self, event): processing.process_streams, raw_streams, event, - config, + self.gmrecords.conf, old_streams, ) futures.append(future) else: processed_streams.append( processing.process_streams( - raw_streams, event, config, old_streams + raw_streams, event, self.gmrecords.conf, old_streams ) ) From 5be5b47bf4360389a880ae00b3ad071b9244ad03 Mon Sep 17 00:00:00 2001 From: Albert Kottke Date: Mon, 1 Aug 2022 16:21:54 -0700 Subject: [PATCH 02/11] Change to the class method that loads the configuration as well. --- gmprocess/subcommands/compute_station_metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gmprocess/subcommands/compute_station_metrics.py b/gmprocess/subcommands/compute_station_metrics.py index e06af359f..7d62f6019 100644 --- a/gmprocess/subcommands/compute_station_metrics.py +++ b/gmprocess/subcommands/compute_station_metrics.py @@ -73,7 +73,7 @@ def _event_station_metrics(self, event): logging.info("Continuing to next event.") return event.id - self.workspace = ws.StreamWorkspace.open(workname) + self.open_workspace(event.id) ds = self.workspace.dataset self._get_labels() From c464c7969067c64dac82fed773159c9c6326349c Mon Sep 17 00:00:00 2001 From: Albert Kottke Date: Mon, 1 Aug 2022 21:32:32 -0700 Subject: [PATCH 03/11] Cleaned up workspace loading to use class methods. --- gmprocess/subcommands/base.py | 14 ++++++++ .../subcommands/compute_station_metrics.py | 17 ++-------- .../subcommands/compute_waveform_metrics.py | 15 ++------- .../subcommands/export_failure_tables.py | 16 +++------- .../subcommands/export_provenance_tables.py | 32 +++++++------------ gmprocess/subcommands/export_shakemap.py | 14 ++------ .../subcommands/generate_station_maps.py | 17 +++------- 7 files changed, 40 insertions(+), 85 deletions(-) diff --git a/gmprocess/subcommands/base.py b/gmprocess/subcommands/base.py index 8d239184e..d1f4e0728 100644 --- a/gmprocess/subcommands/base.py +++ b/gmprocess/subcommands/base.py @@ -33,8 +33,15 @@ def __init__(self): """Dictionary instance variable to track files created by module.""" self.files_created = {} + self.workspace = None + def open_workspace(self, eventid): """Open workspace, add as attribute.""" + + if self.workspace is not None: + # Close previous workspace + self.workspace.close() + event_dir = os.path.join(self.gmrecords.data_path, eventid) workname = os.path.join(event_dir, const.WORKSPACE_NAME) if not os.path.isfile(workname): @@ -48,6 +55,13 @@ def open_workspace(self, eventid): self.workspace = ws.StreamWorkspace.open(workname) self.gmrecords.conf = self._get_config() + return self.workspace.dataset + + def event_dir(self, event_id): + return os.path.normpath( + os.path.join(self.gmrecords.data_path, event_id) + ) + def close_workspace(self): """Close workspace.""" self.workspace.close() diff --git a/gmprocess/subcommands/compute_station_metrics.py b/gmprocess/subcommands/compute_station_metrics.py index 7d62f6019..e88552298 100644 --- a/gmprocess/subcommands/compute_station_metrics.py +++ b/gmprocess/subcommands/compute_station_metrics.py @@ -61,22 +61,9 @@ def main(self, gmrecords): def _event_station_metrics(self, event): self.eventid = event.id logging.info(f"Computing station metrics for event {self.eventid}...") - event_dir = os.path.join(self.gmrecords.data_path, self.eventid) - workname = os.path.normpath( - os.path.join(event_dir, utils.constants.WORKSPACE_NAME) - ) - if not os.path.isfile(workname): - logging.info( - "No workspace file found for event %s. Please run " - "subcommand 'assemble' to generate workspace file." % self.eventid - ) - logging.info("Continuing to next event.") - return event.id - self.open_workspace(event.id) - ds = self.workspace.dataset + ds = self.open_workspace(event.id) self._get_labels() - config = self.gmrecords.conf if not hasattr(self, "vs30_grids"): @@ -95,7 +82,7 @@ def _event_station_metrics(self, event): self.workspace.close() return event.id - rupture_file = rupt_utils.get_rupture_file(event_dir) + rupture_file = rupt_utils.get_rupture_file(self.event_dir(self.eventid)) origin = rupt.origin.Origin( { "id": self.eventid, diff --git a/gmprocess/subcommands/compute_waveform_metrics.py b/gmprocess/subcommands/compute_waveform_metrics.py index c914696ca..86980a638 100644 --- a/gmprocess/subcommands/compute_waveform_metrics.py +++ b/gmprocess/subcommands/compute_waveform_metrics.py @@ -53,22 +53,13 @@ def main(self, gmrecords): def _compute_event_waveform_metrics(self, event): self.eventid = event.id logging.info(f"Computing waveform metrics for event {self.eventid}...") - event_dir = os.path.join(self.gmrecords.data_path, self.eventid) - workname = os.path.normpath(os.path.join(event_dir, const.WORKSPACE_NAME)) - if not os.path.isfile(workname): - logging.info( - "No workspace file found for event %s. Please run " - "subcommand 'assemble' to generate workspace file." % self.eventid - ) - logging.info("Continuing to next event.") - return event.id - self.workspace = ws.StreamWorkspace.open(workname) - ds = self.workspace.dataset - station_list = ds.waveforms.list() + ds = self.open_workspace(event.id) self._get_labels() config = self.gmrecords.conf + station_list = ds.waveforms.list() + summaries = [] metricpaths = [] if self.gmrecords.args.num_processes > 0: diff --git a/gmprocess/subcommands/export_failure_tables.py b/gmprocess/subcommands/export_failure_tables.py index 485fb6bfe..84fde044f 100644 --- a/gmprocess/subcommands/export_failure_tables.py +++ b/gmprocess/subcommands/export_failure_tables.py @@ -59,19 +59,11 @@ def main(self, gmrecords): for event in self.events: self.eventid = event.id logging.info(f"Creating failure tables for event {self.eventid}...") - event_dir = os.path.join(self.gmrecords.data_path, self.eventid) - workname = os.path.normpath(os.path.join(event_dir, const.WORKSPACE_NAME)) - if not os.path.isfile(workname): - logging.info( - "No workspace file found for event %s. Please run " - "subcommand 'assemble' to generate workspace file." % self.eventid - ) - logging.info("Continuing to next event.") - continue - self.workspace = ws.StreamWorkspace.open(workname) + self.open_workspace(event.id) + self._get_labels() + self._get_pstreams() - self.workspace.close() if not (hasattr(self, "pstreams") and len(self.pstreams) > 0): logging.info( @@ -84,7 +76,7 @@ def main(self, gmrecords): base_file_name = os.path.normpath( os.path.join( - event_dir, + self.event_dir(event.id), "%s_%s_failure_reasons_%s" % ( gmrecords.project, diff --git a/gmprocess/subcommands/export_provenance_tables.py b/gmprocess/subcommands/export_provenance_tables.py index f0f18d43a..35b21c4c8 100644 --- a/gmprocess/subcommands/export_provenance_tables.py +++ b/gmprocess/subcommands/export_provenance_tables.py @@ -41,41 +41,31 @@ def main(self, gmrecords): for event in self.events: self.eventid = event.id logging.info(f"Creating provenance tables for event {self.eventid}...") - event_dir = os.path.normpath( - os.path.join(gmrecords.data_path, self.eventid) - ) - workname = os.path.join(event_dir, const.WORKSPACE_NAME) - if not os.path.isfile(workname): - logging.info( - "No workspace file found for event %s. Please run " - "subcommand 'assemble' to generate workspace file." % self.eventid - ) - logging.info("Continuing to next event.") - continue - self.workspace = ws.StreamWorkspace.open(workname) + self.open_workspace(event.id) self._get_pstreams() if not (hasattr(self, "pstreams") and len(self.pstreams) > 0): logging.info( "No processed waveforms available. No provenance tables created." ) - self.workspace.close() continue provdata = self.workspace.getProvenance( self.eventid, labels=self.gmrecords.args.label ) - self.workspace.close() - basename = f"{gmrecords.project}_{gmrecords.args.label}_provenance" + basename = os.path.join( + self.event_dir(event.id), + f"{gmrecords.project}_{gmrecords.args.label}_provenance" + ) if gmrecords.args.output_format == "csv": - csvfile = os.path.join(event_dir, f"{basename}.csv") - self.append_file("Provenance", csvfile) - provdata.to_csv(csvfile, index=False) + fname = basename + '.csv' + self.append_file("Provenance", fname) + provdata.to_csv(fname, index=False) else: - excelfile = os.path.join(event_dir, f"{basename}.xlsx") - self.append_file("Provenance", excelfile) - provdata.to_excel(excelfile, index=False) + fname = basename + '.xslx' + self.append_file("Provenance", fname) + provdata.to_excel(fname, index=False) self._summarize_files_created() diff --git a/gmprocess/subcommands/export_shakemap.py b/gmprocess/subcommands/export_shakemap.py index 7cf1b4a53..9329145bc 100644 --- a/gmprocess/subcommands/export_shakemap.py +++ b/gmprocess/subcommands/export_shakemap.py @@ -54,24 +54,14 @@ def main(self, gmrecords): self.eventid = event.id logging.info(f"Creating shakemap files for event {self.eventid}...") - event_dir = os.path.normpath(os.path.join(gmrecords.data_path, event.id)) - workname = os.path.join(event_dir, const.WORKSPACE_NAME) - if not os.path.isfile(workname): - logging.info( - "No workspace file found for event %s. Please run " - "subcommand 'assemble' to generate workspace file." % event.id - ) - logging.info("Continuing to next event.") - continue - - self.workspace = ws.StreamWorkspace.open(workname) + self.open_workspace(event.id) self._get_labels() expanded_imts = self.gmrecords.args.expand_imts jsonfile, stationfile, _ = sm_utils.create_json( self.workspace, event, - event_dir, + self.event_dir(event.id), self.gmrecords.args.label, config=self.gmrecords.conf, expanded_imts=expanded_imts, diff --git a/gmprocess/subcommands/generate_station_maps.py b/gmprocess/subcommands/generate_station_maps.py index 0a793a52d..d4f653813 100644 --- a/gmprocess/subcommands/generate_station_maps.py +++ b/gmprocess/subcommands/generate_station_maps.py @@ -41,25 +41,15 @@ def main(self, gmrecords): self._get_events() for event in self.events: - event_dir = os.path.join(self.gmrecords.data_path, event.id) - workname = os.path.join(event_dir, const.WORKSPACE_NAME) - if not os.path.isfile(workname): - logging.info( - "No workspace file found for event %s. Please run " - "subcommand 'assemble' to generate workspace file." % event.id - ) - logging.info("Continuing to next event.") - return False + ds = self.open_workspace(event.id) - self.workspace = ws.StreamWorkspace.open(workname) - ds = self.workspace.dataset station_list = ds.waveforms.list() if len(station_list) == 0: logging.info("No processed waveforms available. No report generated.") return False self._get_labels() - config = self.workspace.config + config = self.gmrecords.config logging.info(f"Generating station maps for event {event.id}...") pstreams = [] @@ -76,7 +66,8 @@ def main(self, gmrecords): for stream in streams: pstreams.append(stream) - mapfile = report_utils.draw_stations_map(pstreams, event, event_dir) + mapfile = report_utils.draw_stations_map( + pstreams, event, self.event_dir(event.id)) self.append_file("Station map", mapfile) self._summarize_files_created() From ad146cfa7bf64af5cdeb6caa91fbc703deb21e25 Mon Sep 17 00:00:00 2001 From: Albert Kottke Date: Mon, 1 Aug 2022 21:46:50 -0700 Subject: [PATCH 04/11] Close workspace with method and at exit. --- gmprocess/subcommands/base.py | 15 ++++++++++----- gmprocess/subcommands/compute_station_metrics.py | 2 -- gmprocess/subcommands/compute_waveform_metrics.py | 1 - gmprocess/subcommands/export_metric_tables.py | 12 +----------- gmprocess/subcommands/export_shakemap.py | 1 - gmprocess/subcommands/generate_report.py | 2 -- 6 files changed, 11 insertions(+), 22 deletions(-) diff --git a/gmprocess/subcommands/base.py b/gmprocess/subcommands/base.py index d1f4e0728..63a8e5422 100644 --- a/gmprocess/subcommands/base.py +++ b/gmprocess/subcommands/base.py @@ -1,10 +1,12 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import atexit +import logging import os import sys + from abc import ABC, abstractmethod -import logging from gmprocess.subcommands.lazy_loader import LazyLoader @@ -35,12 +37,13 @@ def __init__(self): self.workspace = None + # Make sure we close the workspace on exit + atexit.register(self.close_workspace) + def open_workspace(self, eventid): """Open workspace, add as attribute.""" - if self.workspace is not None: - # Close previous workspace - self.workspace.close() + self.close_workspace() event_dir = os.path.join(self.gmrecords.data_path, eventid) workname = os.path.join(event_dir, const.WORKSPACE_NAME) @@ -64,7 +67,9 @@ def event_dir(self, event_id): def close_workspace(self): """Close workspace.""" - self.workspace.close() + if self.workspace is not None: + logging.debug("Closing the workspace.") + self.workspace.close() @property @abstractmethod diff --git a/gmprocess/subcommands/compute_station_metrics.py b/gmprocess/subcommands/compute_station_metrics.py index e88552298..2805c54c7 100644 --- a/gmprocess/subcommands/compute_station_metrics.py +++ b/gmprocess/subcommands/compute_station_metrics.py @@ -79,7 +79,6 @@ def _event_station_metrics(self, event): station_list = ds.waveforms.list() if not len(station_list): - self.workspace.close() return event.id rupture_file = rupt_utils.get_rupture_file(self.event_dir(self.eventid)) @@ -244,7 +243,6 @@ def _event_station_metrics(self, event): "with tag '%s'." % self.gmrecords.args.label ) - self.workspace.close() return event.id def _get_ps2ff_splines(self): diff --git a/gmprocess/subcommands/compute_waveform_metrics.py b/gmprocess/subcommands/compute_waveform_metrics.py index 86980a638..3b567382c 100644 --- a/gmprocess/subcommands/compute_waveform_metrics.py +++ b/gmprocess/subcommands/compute_waveform_metrics.py @@ -139,5 +139,4 @@ def _compute_event_waveform_metrics(self, event): overwrite=self.gmrecords.args.overwrite, ) - self.workspace.close() return event.id diff --git a/gmprocess/subcommands/export_metric_tables.py b/gmprocess/subcommands/export_metric_tables.py index e477c69f4..d6209dec9 100644 --- a/gmprocess/subcommands/export_metric_tables.py +++ b/gmprocess/subcommands/export_metric_tables.py @@ -44,17 +44,8 @@ def main(self, gmrecords): for event in self.events: self.eventid = event.id logging.info(f"Creating tables for event {self.eventid}...") - event_dir = os.path.join(gmrecords.data_path, self.eventid) - workname = os.path.normpath(os.path.join(event_dir, const.WORKSPACE_NAME)) - if not os.path.isfile(workname): - logging.info( - "No workspace file found for event %s. Please run " - "subcommand 'assemble' to generate workspace file." % self.eventid - ) - logging.info("Continuing to next event.") - continue - self.workspace = ws.StreamWorkspace.open(workname) + self.open_workspace(event.id) self._get_labels() config = self.gmrecords.conf @@ -72,7 +63,6 @@ def main(self, gmrecords): snr_table, snr_readme = self.workspace.getSNRTable( self.eventid, self.gmrecords.args.label, config ) - self.workspace.close() outdir = gmrecords.data_path diff --git a/gmprocess/subcommands/export_shakemap.py b/gmprocess/subcommands/export_shakemap.py index 9329145bc..22808e4fd 100644 --- a/gmprocess/subcommands/export_shakemap.py +++ b/gmprocess/subcommands/export_shakemap.py @@ -67,7 +67,6 @@ def main(self, gmrecords): expanded_imts=expanded_imts, ) - self.workspace.close() if jsonfile is not None: self.append_file("shakemap", jsonfile) if stationfile is not None: diff --git a/gmprocess/subcommands/generate_report.py b/gmprocess/subcommands/generate_report.py index 5ce8d44f3..bae100807 100644 --- a/gmprocess/subcommands/generate_report.py +++ b/gmprocess/subcommands/generate_report.py @@ -145,6 +145,4 @@ def generate_diagnostic_plots(self, event): plot.plot_moveout(pstreams, event.latitude, event.longitude, file=moveoutfile) self.append_file("Moveout plot", moveoutfile) - self.workspace.close() - return pstreams From bb65f3809a21052bab64d443833f6cfa758fb29d Mon Sep 17 00:00:00 2001 From: Albert Kottke Date: Mon, 1 Aug 2022 22:09:37 -0700 Subject: [PATCH 05/11] Fixed closing of workspace. --- gmprocess/subcommands/base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gmprocess/subcommands/base.py b/gmprocess/subcommands/base.py index 63a8e5422..fcdc2fbb1 100644 --- a/gmprocess/subcommands/base.py +++ b/gmprocess/subcommands/base.py @@ -67,9 +67,12 @@ def event_dir(self, event_id): def close_workspace(self): """Close workspace.""" - if self.workspace is not None: + try: logging.debug("Closing the workspace.") self.workspace.close() + except AttributeError: + # Not dataset to close + pass @property @abstractmethod From 68017b5c5e3de0f35bbbcf0cf2225a7b7514b01e Mon Sep 17 00:00:00 2001 From: Albert Kottke Date: Tue, 2 Aug 2022 10:03:14 -0700 Subject: [PATCH 06/11] Cleaned up workspace loading to use class methods. --- gmprocess/subcommands/generate_report.py | 27 ++++++++---------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/gmprocess/subcommands/generate_report.py b/gmprocess/subcommands/generate_report.py index bae100807..a4f550adc 100644 --- a/gmprocess/subcommands/generate_report.py +++ b/gmprocess/subcommands/generate_report.py @@ -44,12 +44,14 @@ def main(self, gmrecords): logging.info(f"Running subcommand '{self.command_name}'") self.gmrecords = gmrecords - config = self.gmrecords.conf + self._check_arguments() self._get_events() for event in self.events: - event_dir = os.path.join(self.gmrecords.data_path, event.id) + self.open_workspace(event.id) + config = self.gmrecords.conf + pstreams = self.generate_diagnostic_plots(event) if pstreams is None: return @@ -62,7 +64,7 @@ def main(self, gmrecords): if report_format == "latex": report_file, success = report.build_report_latex( pstreams, - event_dir, + self.event_dir(event.id), event, prefix=f"{gmrecords.project}_{gmrecords.args.label}", config=config, @@ -77,18 +79,6 @@ def main(self, gmrecords): self._summarize_files_created() def generate_diagnostic_plots(self, event): - event_dir = os.path.join(self.gmrecords.data_path, event.id) - workname = os.path.join(event_dir, const.WORKSPACE_NAME) - if not os.path.isfile(workname): - logging.info( - "No workspace file found for event %s. Please run " - "subcommand 'assemble' to generate workspace file." % event.id - ) - logging.info("Continuing to next event.") - return False - - self.workspace = ws.StreamWorkspace.open(workname) - config = self._get_config() ds = self.workspace.dataset station_list = ds.waveforms.list() if len(station_list) == 0: @@ -103,6 +93,7 @@ def generate_diagnostic_plots(self, event): ) logging.info(f"Creating diagnostic plots for event {event.id}...") + event_dir = self.event_dir(event.id) plot_dir = os.path.join(event_dir, "plots") if not os.path.isdir(plot_dir): os.makedirs(plot_dir) @@ -114,7 +105,7 @@ def generate_diagnostic_plots(self, event): event.id, stations=[station_id], labels=[self.gmrecords.args.label], - config=config, + config=self.gmrecords.conf, ) if not len(streams): logging.info("No matching streams found. Cannot generate report.") @@ -128,12 +119,12 @@ def generate_diagnostic_plots(self, event): stream, plot_dir, event, - config=config, + config=self.gmrecords.conf, ) futures.append(future) else: results.append( - plot.summary_plots(stream, plot_dir, event, config=config) + plot.summary_plots(stream, plot_dir, event, config=self.gmrecords.conf) ) if self.gmrecords.args.num_processes > 0: From 957e88da93d51b5e98ccf96b51e91c71fd9d0f56 Mon Sep 17 00:00:00 2001 From: Albert Kottke Date: Mon, 15 Aug 2022 13:05:37 -0700 Subject: [PATCH 07/11] index on main: 68017b5c Cleaned up workspace loading to use class methods. From a4cdf3eca03accd5cdebe3de2f0cf2a69c51edde Mon Sep 17 00:00:00 2001 From: Albert Kottke Date: Thu, 18 Aug 2022 10:54:17 -0700 Subject: [PATCH 08/11] Add fill values to distance metrics. --- gmprocess/subcommands/compute_station_metrics.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gmprocess/subcommands/compute_station_metrics.py b/gmprocess/subcommands/compute_station_metrics.py index 2805c54c7..1064892fe 100644 --- a/gmprocess/subcommands/compute_station_metrics.py +++ b/gmprocess/subcommands/compute_station_metrics.py @@ -277,6 +277,11 @@ def _get_ps2ff_splines(self): kind="linear", copy=False, assume_sorted=True, + bounds_error=False, + fill_value=( + (Rjb_hat[0], Rjb_var[0]), + (Rjb_hat[-1], Rjb_var[-1]) + ) ) self.rrup_spline = spint.interp1d( repi, @@ -284,4 +289,9 @@ def _get_ps2ff_splines(self): kind="linear", copy=False, assume_sorted=True, + bounds_error=False, + fill_value=( + (Rrup_hat[0], Rrup_var[0]), + (Rrup_hat[-1], Rrup_var[-1]) + ) ) From 374aa0ee1de16ddbadb6fbbbe2629cb698755a8f Mon Sep 17 00:00:00 2001 From: Albert Kottke Date: Thu, 18 Aug 2022 11:02:53 -0700 Subject: [PATCH 09/11] Update config in workspace if not present. --- gmprocess/subcommands/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gmprocess/subcommands/base.py b/gmprocess/subcommands/base.py index fcdc2fbb1..181155bb3 100644 --- a/gmprocess/subcommands/base.py +++ b/gmprocess/subcommands/base.py @@ -224,4 +224,7 @@ def _get_config(self): config = self.workspace.config else: config = confmod.get_config() + # Update the config in the workspace + self.workspace.setConfig(config) + return config From 465eaba2a65482d405c6d26c2f7b03be508c1fac Mon Sep 17 00:00:00 2001 From: Albert Kottke Date: Thu, 18 Aug 2022 11:17:34 -0700 Subject: [PATCH 10/11] Fixed call to addconfig. --- gmprocess/subcommands/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gmprocess/subcommands/base.py b/gmprocess/subcommands/base.py index 181155bb3..1a8a572fc 100644 --- a/gmprocess/subcommands/base.py +++ b/gmprocess/subcommands/base.py @@ -225,6 +225,6 @@ def _get_config(self): else: config = confmod.get_config() # Update the config in the workspace - self.workspace.setConfig(config) + self.workspace.addConfig(config=config) return config From 7fb4831f2675176cea95d2e67df3e0c32673b2ab Mon Sep 17 00:00:00 2001 From: Albert Kottke Date: Thu, 18 Aug 2022 12:47:04 -0700 Subject: [PATCH 11/11] Load configuration from file. --- gmprocess/subcommands/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gmprocess/subcommands/base.py b/gmprocess/subcommands/base.py index 1a8a572fc..da4a57c00 100644 --- a/gmprocess/subcommands/base.py +++ b/gmprocess/subcommands/base.py @@ -221,9 +221,11 @@ def _get_labels(self): def _get_config(self): if hasattr(self, "workspace") and hasattr(self.workspace, "config"): + logging.info('Loading config from workspace.') config = self.workspace.config else: - config = confmod.get_config() + logging.info('Loading config from file.') + config = confmod.get_config(config_path=self.gmrecords.conf_path) # Update the config in the workspace self.workspace.addConfig(config=config)