|
17 | 17 | """
|
18 | 18 |
|
19 | 19 |
|
| 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 | + |
20 | 59 | def ssp_run(st, inventory, ssp_event, picks, allow_exit=False):
|
21 | 60 | """
|
22 | 61 | 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):
|
50 | 89 | if not allow_exit:
|
51 | 90 | ssp_exit.SSP_EXIT_CALLED = True
|
52 | 91 |
|
| 92 | + # Clear state from possible previous run |
| 93 | + ssp_clear_state(clear_config=False, clear_options=False) |
| 94 | + |
53 | 95 | # Create output folder if required, save config and setup logging
|
54 | 96 | from .setup import get_outdir_path, save_config, setup_logging
|
55 | 97 | if getattr(config.options, 'outdir', None):
|
|
0 commit comments