adjtomo/pyatoa

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

Closed this issue · 0 comments

bch0w commented

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.

# Determine if synthetics start before the origintime
if self.event is not None:
self.stats.time_offset_sec = (self.st_syn[0].stats.starttime -
self.event.preferred_origin().time
)
logger.debug(f"time offset is {self.stats.time_offset_sec}s")
else:
self.stats.time_offset_sec = 0

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().

pyatoa/pyatoa/utils/read.py

Lines 105 to 108 in fd33b8f

stats = {"network": net, "station": sta, "location": location,
"channel": cha, "starttime": origintime, "npts": len(data),
"delta": delta, "mseed": {"dataquality": 'D'},
"time_offset": times[0], "format": fmt

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")