From 671b1d2a3ba43de63230fe71a498c7b028e5a940 Mon Sep 17 00:00:00 2001 From: Claudio Satriano Date: Wed, 27 Mar 2024 16:12:13 +0100 Subject: [PATCH] Option to save spectra to an HDF5 file in the output directory --- CHANGELOG.md | 2 ++ README.md | 1 + docs/file_formats.rst | 1 + sourcespec/config_files/configspec.conf | 3 +++ sourcespec/source_spec.py | 3 ++- sourcespec/ssp_output.py | 13 +++++++++++++ 6 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dc1275f..912ffc7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ previous versions. You will need to upgrade your old database manually or using - New HDF5 and TEXT file formats to store spectra - Station residuals are now saved in an HDF5 spectrum file, instead of a pickle file +- New config file option `save_spectra` to save the spectra to an HDF5 file + in the output directory - Changes in the YAML output file: - `bsd` (Brune stress drop) parameter renamed to `ssd` (static stress drop) - Store in the `event_info` section the values of vp, vs and rho close to diff --git a/README.md b/README.md index 4e3e0caf..c66df1f4 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,7 @@ The SourceSpec main code, `source_spec` will produce the following output files for [reproducibility]) - `EVID.ssp.conf`: the input config file (for [reproducibility]) - `EVID.residuals.hdf5`: station residuals in [HDF5] format +- `EVID.spectra.hdf5`: (optional) spectra in [HDF5] format - `EVID.ssp.h`: hypocenter file in [HYPO71] format with the estimated moment magnitude (only if an input HYPO71 file is provided) - `EVID.xml`: updated [QuakeML] file with the results of the SourceSpec diff --git a/docs/file_formats.rst b/docs/file_formats.rst index 487460c8..ed72b0c8 100644 --- a/docs/file_formats.rst +++ b/docs/file_formats.rst @@ -91,6 +91,7 @@ output files (``EVID`` is replaced by the actual event ID): arguments, for `reproducibility`_) - ``EVID.ssp.conf``: the input config file (for `reproducibility`_) - ``EVID.residuals.hdf5``: station residuals in `HDF5`_ format +- ``EVID.spectra.hdf5``: (optional) spectra in `HDF5`_ format - ``EVID.ssp.h``: hypocenter file in `HYPO71`_ format with the estimated moment magnitude (only if an input HYPO71 file is provided) - ``EVID.xml``: updated `QuakeML`_ file with the results of the SourceSpec diff --git a/sourcespec/config_files/configspec.conf b/sourcespec/config_files/configspec.conf index 2b7a1253..41da86e0 100644 --- a/sourcespec/config_files/configspec.conf +++ b/sourcespec/config_files/configspec.conf @@ -216,6 +216,9 @@ freq1_broadb = float(min=0, default=0.5) freq2_broadb = float(min=0, default=30.0) freq1_disp = float(min=0, default=0.5) freq2_disp = float(min=0, default=30.0) + +# Save the spectra to an HDF5 file in the output directory +save_spectra = boolean(default=False) # -------- SPECTRUM PARAMETERS diff --git a/sourcespec/source_spec.py b/sourcespec/source_spec.py index fa768e36..e4804c1a 100644 --- a/sourcespec/source_spec.py +++ b/sourcespec/source_spec.py @@ -73,8 +73,9 @@ def main(): compute_summary_statistics(config, sspec_output) # Save output - from sourcespec.ssp_output import write_output + from sourcespec.ssp_output import write_output, save_spectra write_output(config, sspec_output) + save_spectra(config, spec_st) # Save residuals from sourcespec.ssp_residuals import spectral_residuals diff --git a/sourcespec/ssp_output.py b/sourcespec/ssp_output.py index bd5843f1..70eadee9 100644 --- a/sourcespec/ssp_output.py +++ b/sourcespec/ssp_output.py @@ -431,3 +431,16 @@ def write_output(config, sspec_output): _write_hypo71(config, sspec_output) # Write to quakeml file, if requested write_qml(config, sspec_output) + + +def save_spectra(config, spec_st): + """Save spectra to file.""" + if not config.save_spectra: + return + outfile = os.path.join( + config.options.outdir, + f'{config.event.event_id}.spectra.hdf5' + ) + spec_st.sort() + spec_st.write(outfile) + logger.info(f'Spectra saved to: {outfile}')