adjtomo / pyatoa

Python's Adjoint Tomography Operations Assistant (Pyatoa): a misfit assessment toolbox for full waveform tomography
GNU General Public License v3.0
20 stars 8 forks source link

'time_offset' not set properly when `Event` attribute is NoneType #14

Closed bch0w closed 2 years ago

bch0w commented 2 years ago

The time offset value is very important for writing adjoint sources, as it correctly sets the start time of the adjoint source (used when USER_T0 is set in SPECFEM, which sets time before event origin time).

Currently Pyatoa can only grab time offset information by taking the different between Trace.stats.starttime and Event.preferred_origin().time. However if not Event object is given, which may be the case for synthetic-inversions, or if not Event metadata is available, then time offset is incorrectly set to 0.

https://github.com/adjtomo/pyatoa/blob/fd33b8f48a005f29d6502c26fbb2fc3d73c9efc4/pyatoa/core/manager.py#L663-L670

To fix this we need to add another option which grabs time offset information from the synthetic waveforms Trace.stats.time_offset which should be set correctly by Pyatoa.utils.read.read_sem().

https://github.com/adjtomo/pyatoa/blob/fd33b8f48a005f29d6502c26fbb2fc3d73c9efc4/pyatoa/utils/read.py#L105-L108

This should take precedence over the Event option, and a log message should be posted if time offset is guessed at 0. Fix should look something like:

        if hasattr(self.st_syn[0].stats, "time_offset"):
            self.stats.time_offset_sec = self.st_syn[0].stats.time_offset
        elif self.event is not None:
            self.stats.time_offset_sec = (self.st_syn[0].stats.starttime -
                                          self.event.preferred_origin().time
                                          )
        else:
            logger.warning("cannot find information relating to time offset, setting 0")
            self.stats.time_offset_sec = 0
        logger.info(f"time offset is {self.stats.time_offset_sec}s")