|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# SPDX-License-Identifier: CECILL-2.1 |
| 3 | +""" |
| 4 | +Augment event with velocity info and event name. |
| 5 | +
|
| 6 | +:copyright: |
| 7 | + 2012 Claudio Satriano <satriano@ipgp.fr> |
| 8 | +
|
| 9 | + 2013-2014 Claudio Satriano <satriano@ipgp.fr>, |
| 10 | + Emanuela Matrullo <matrullo@geologie.ens.fr> |
| 11 | +
|
| 12 | + 2015-2024 Claudio Satriano <satriano@ipgp.fr>, |
| 13 | + Sophie Lambotte <sophie.lambotte@unistra.fr> |
| 14 | +:license: |
| 15 | + CeCILL Free Software License Agreement v2.1 |
| 16 | + (http://www.cecill.info/licences.en.html) |
| 17 | +""" |
| 18 | +import logging |
| 19 | +from ..setup import config, ssp_exit |
| 20 | +from ..ssp_util import MediumProperties |
| 21 | +logger = logging.getLogger(__name__.rsplit('.', maxsplit=1)[-1]) |
| 22 | + |
| 23 | + |
| 24 | +def _hypo_vel(hypo): |
| 25 | + """ |
| 26 | + Compute velocity at hypocenter. |
| 27 | +
|
| 28 | + :param hypo: Hypocenter object |
| 29 | + :type hypo: :class:`sourcespec.ssp_event.Hypocenter` |
| 30 | + """ |
| 31 | + medium_properties = MediumProperties( |
| 32 | + hypo.longitude, hypo.latitude, hypo.depth.value_in_km) |
| 33 | + hypo.vp = medium_properties.get(mproperty='vp', where='source') |
| 34 | + hypo.vs = medium_properties.get(mproperty='vs', where='source') |
| 35 | + hypo.rho = medium_properties.get(mproperty='rho', where='source') |
| 36 | + depth_string = medium_properties.to_string( |
| 37 | + 'source depth', hypo.depth.value_in_km) |
| 38 | + vp_string = medium_properties.to_string('vp_source', hypo.vp) |
| 39 | + vs_string = medium_properties.to_string('vs_source', hypo.vs) |
| 40 | + rho_string = medium_properties.to_string('rho_source', hypo.rho) |
| 41 | + logger.info(f'{depth_string}, {vp_string}, {vs_string}, {rho_string}') |
| 42 | + |
| 43 | + |
| 44 | +def augment_event(ssp_event): |
| 45 | + """ |
| 46 | + Add velocity info to hypocenter |
| 47 | + and add event name from/to config.options |
| 48 | +
|
| 49 | + The augmented event is stored in config.event |
| 50 | +
|
| 51 | + :param ssp_event: Evento to be augmented |
| 52 | + :type ssp_event: :class:`sourcespec.ssp_event.SSPEvent` |
| 53 | + """ |
| 54 | + # add velocity info to hypocenter |
| 55 | + try: |
| 56 | + _hypo_vel(ssp_event.hypocenter) |
| 57 | + except Exception as e: |
| 58 | + logger.error( |
| 59 | + f'Unable to compute velocity at hypocenter: {e}\n') |
| 60 | + ssp_exit(1) |
| 61 | + if config.options.evname is not None: |
| 62 | + # add evname from command line, if any, overriding the one in ssp_event |
| 63 | + ssp_event.name = config.options.evname |
| 64 | + else: |
| 65 | + # add evname from ssp_event, if any, to config file |
| 66 | + config.options.evname = ssp_event.name |
| 67 | + # add event to config file |
| 68 | + config.event = ssp_event |
0 commit comments