pysep icon indicating copy to clipboard operation
pysep copied to clipboard

rearrange sac header writer

Open casarotti opened this issue 11 months ago • 1 comments

I think there is a problem with the SAC header construction.

here

pysep/pysep/pysep.py

Line 1862 in 92c4c62

self.st = append_sac_headers(self.st, self.event, self.inv)

pysep constructs the SAC header (before the trim), which means that it calculates the B value from the stream start time here

pysep/pysep/pysep.py

Line 1868 in 92c4c62

self.st = self.preprocess()

pysep calls the preprocess routine and trims the waves, setting the new stream start time. Then it writes the SAC files (with the new start time and the previously defined header).

When the SAC file is read back, OBSPY takes into account the start time (defined by the trim) and the B value, and adjusts nzsec, nzmsec. which will be used later to create the origin time.

So the origin time is modified in the sac files

I modified pysep.py moving the preprocess (where the trim occurs) before the sac header.

the proprocess routine assumed that a sac header was already written but only to write the scale_factor value, so I move this writing out of the routine after the sac header construction

casarotti avatar Feb 03 '25 17:02 casarotti

Thank you @casarotti! Great catch on the incorrect SAC header construction, indeed b and e were not constructed correctly, both because of the trimming but also because e did not account for b. I just added two comments on making the changes slightly more explicit if you wouldn't mind implementing. Happy to merge after that.

bch0w avatar Feb 10 '25 20:02 bch0w

merging this in and will make the suggested modifications in devel branch, thanks @casarotti for the PR!

bch0w avatar Jun 05 '25 22:06 bch0w