22
22
from datetime import datetime
23
23
from tzlocal import get_localzone
24
24
import numpy as np
25
+ from .config import config
25
26
from .ssp_qml_output import write_qml
26
27
from .ssp_sqlite_output import write_sqlite
27
28
from ._version import get_versions
28
29
logger = logging .getLogger (__name__ .rsplit ('.' , maxsplit = 1 )[- 1 ])
29
30
30
31
31
- def _write_author_and_agency_to_parfile (config , parfile ):
32
+ def _write_author_and_agency_to_parfile (parfile ):
32
33
author_str = empty_author_str = '\n *** Author:'
33
34
if config .author_name is not None :
34
35
author_str += f' { config .author_name } '
@@ -65,7 +66,7 @@ def _value_error_str(value, error, fmt):
65
66
return s
66
67
67
68
68
- def _write_parfile (config , sspec_output ):
69
+ def _write_parfile (sspec_output ):
69
70
"""
70
71
Write station source parameters to file.
71
72
@@ -286,13 +287,23 @@ def _write_parfile(config, sspec_output):
286
287
f'{ config .end_of_run_tz } ' )
287
288
if config .options .run_id :
288
289
parfile .write (f'\n *** Run ID: { config .options .run_id } ' )
289
- _write_author_and_agency_to_parfile (config , parfile )
290
+ _write_author_and_agency_to_parfile (parfile )
290
291
291
292
logger .info (f'Output written to file: { parfilename } ' )
292
293
293
294
294
295
def _dict2yaml (dict_like , level = 0 ):
295
- """Serialize a dict-like object into YAML format."""
296
+ """
297
+ Serialize a dict-like object into YAML format.
298
+
299
+ :param dict_like: Dict-like object to serialize.
300
+ :type dict_like: dict
301
+ :param level: Indentation level.
302
+ :type level: int
303
+
304
+ :return: YAML-formatted string.
305
+ :rtype: str
306
+ """
296
307
if not isinstance (dict_like , Mapping ):
297
308
raise TypeError ('dict_like must be a dict-like object' )
298
309
comments = dict_like .get ('_comments' , {})
@@ -329,8 +340,13 @@ def _dict2yaml(dict_like, level=0):
329
340
return lines
330
341
331
342
332
- def _write_yaml (config , sspec_output ):
333
- """Write sspec output in a YAML file."""
343
+ def _write_yaml (sspec_output ):
344
+ """
345
+ Write sspec output in a YAML file.
346
+
347
+ :param sspec_output: Output of the spectral inversion.
348
+ :type sspec_output: :class:`~sourcespec.ssp_data_types.SourceSpecOutput`
349
+ """
334
350
if not os .path .exists (config .options .outdir ):
335
351
os .makedirs (config .options .outdir )
336
352
evid = config .event .event_id
@@ -346,7 +362,13 @@ def _write_yaml(config, sspec_output):
346
362
logger .info (f'Output written to file: { yamlfilename } ' )
347
363
348
364
349
- def _write_hypo71 (config , sspec_output ):
365
+ def _write_hypo71 (sspec_output ):
366
+ """
367
+ Write source parameters to hypo71 file.
368
+
369
+ :param sspec_output: Output of the spectral inversion.
370
+ :type sspec_output: :class:`~sourcespec.ssp_data_types.SourceSpecOutput`
371
+ """
350
372
if not config .options .hypo_file :
351
373
return
352
374
if config .hypo_file_format != 'hypo71' :
@@ -376,7 +398,7 @@ def _write_hypo71(config, sspec_output):
376
398
logger .info (f'Hypo file written to: { hypo_file_out } ' )
377
399
378
400
379
- def _make_symlinks (config ):
401
+ def _make_symlinks ():
380
402
"""Make symlinks to input files into output directory."""
381
403
# Windows does not support symlinks
382
404
if os .name == 'nt' :
@@ -406,8 +428,13 @@ def _make_symlinks(config):
406
428
os .symlink (filename , linkname )
407
429
408
430
409
- def write_output (config , sspec_output ):
410
- """Write results into different formats."""
431
+ def write_output (sspec_output ):
432
+ """
433
+ Write results into different formats.
434
+
435
+ :param sspec_output: Output of the spectral inversion.
436
+ :type sspec_output: :class:`~sourcespec.ssp_data_types.SourceSpecOutput`
437
+ """
411
438
# Add run info to output object
412
439
run_info = sspec_output .run_info
413
440
run_info .SourceSpec_version = get_versions ()['version' ]
@@ -423,21 +450,26 @@ def write_output(config, sspec_output):
423
450
run_info .agency_short_name = config .agency_short_name
424
451
run_info .agency_url = config .agency_url
425
452
# Symlink input files into output directory
426
- _make_symlinks (config )
453
+ _make_symlinks ()
427
454
# Write to parfile (deprecated)
428
- _write_parfile (config , sspec_output )
455
+ _write_parfile (sspec_output )
429
456
# Write to YAML file
430
- _write_yaml (config , sspec_output )
457
+ _write_yaml (sspec_output )
431
458
# Write to SQLite database, if requested
432
- write_sqlite (config , sspec_output )
459
+ write_sqlite (sspec_output )
433
460
# Write to hypo file, if requested
434
- _write_hypo71 (config , sspec_output )
461
+ _write_hypo71 (sspec_output )
435
462
# Write to quakeml file, if requested
436
- write_qml (config , sspec_output )
463
+ write_qml (sspec_output )
464
+
437
465
466
+ def save_spectra (spec_st ):
467
+ """
468
+ Save spectra to file.
438
469
439
- def save_spectra (config , spec_st ):
440
- """Save spectra to file."""
470
+ :param spec_st: Stream of spectra.
471
+ :type spec_st: :class:`~sourcespec.spectrum.SpectrumStream`
472
+ """
441
473
if not config .save_spectra :
442
474
return
443
475
outfile = os .path .join (
0 commit comments