'time_offset' not set properly when `Event` attribute is NoneType
Closed this issue · 0 comments
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.
Lines 663 to 670 in fd33b8f
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()
.
Lines 105 to 108 in fd33b8f
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")