Skip to content

Commit c6e9218

Browse files
committed
Added ssp_clear_state function.
Clear state from possible previous run at beginning of ssp_run function.
1 parent 029158b commit c6e9218

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

sourcespec2/source_spec.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,45 @@
1717
"""
1818

1919

20+
def ssp_clear_state(clear_config=False, clear_options=True):
21+
"""
22+
Clear state from a previous run.
23+
Some submodules contain global variables caching information
24+
about the current run, which need to be cleared before
25+
launching a new run.
26+
27+
:param clear_config: whether to clear global config as well
28+
:type clear_config: bool
29+
:param clear_options: whether to clear options in global config
30+
:type clear_options: bool
31+
"""
32+
from .setup import logging
33+
logging.OLDLOGFILE = None
34+
# Not sure if we should reset LOGGER?
35+
#logging.LOGGER = None
36+
37+
from . import ssp_wave_arrival
38+
ssp_wave_arrival.add_arrival_to_trace.pick_cache = dict()
39+
ssp_wave_arrival.add_arrival_to_trace.travel_time_cache = dict()
40+
ssp_wave_arrival.add_arrival_to_trace.angle_cache = dict()
41+
42+
from . import ssp_plot_traces
43+
ssp_plot_traces.SAVED_FIGURE_CODES = []
44+
ssp_plot_traces.BBOX = None
45+
46+
from . import ssp_plot_spectra
47+
ssp_plot_spectra.SAVED_FIGURE_CODES = []
48+
ssp_plot_spectra.BBOX = None
49+
50+
from .setup import config
51+
if clear_config:
52+
# This clears the entire config, which is not what we want
53+
#config.clear()
54+
config.__init__()
55+
elif clear_options:
56+
config.options.clear()
57+
58+
2059
def ssp_run(st, inventory, ssp_event, picks, allow_exit=False):
2160
"""
2261
Run source_spec as function with collected traces, station inventory,
@@ -50,6 +89,9 @@ def ssp_run(st, inventory, ssp_event, picks, allow_exit=False):
5089
if not allow_exit:
5190
ssp_exit.SSP_EXIT_CALLED = True
5291

92+
# Clear state from possible previous run
93+
ssp_clear_state(clear_config=False, clear_options=False)
94+
5395
# Create output folder if required, save config and setup logging
5496
from .setup import get_outdir_path, save_config, setup_logging
5597
if getattr(config.options, 'outdir', None):

0 commit comments

Comments
 (0)