Skip to content

Commit

Permalink
Option to save spectra to an HDF5 file in the output directory
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodsf committed Mar 27, 2024
1 parent af154b3 commit 671b1d2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/file_formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions sourcespec/config_files/configspec.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion sourcespec/source_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions sourcespec/ssp_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')

0 comments on commit 671b1d2

Please sign in to comment.