obspy.io.mseed.util.shift_time_of_file

shift_time_of_file(input_file, output_file, timeshift)[source]

Takes a MiniSEED file and shifts the time of every record by the given amount.

The same could be achieved by reading the MiniSEED file with ObsPy, modifying the starttime and writing it again. The problem with this approach is that some record specific flags and special blockettes might not be conserved. This function directly operates on the file and simply changes some header fields, not touching the rest, thus preserving it.

Will only work correctly if all records have the same record length which usually should be the case.

All times are in 0.0001 seconds, that is in 1/10000 seconds. NOT ms but one order of magnitude smaller! This is due to the way time corrections are stored in the MiniSEED format.

Parameters:
  • input_file (str) The input filename.
  • output_file (str) The output filename.
  • timeshift (int) The time-shift to be applied in 0.0001, e.g. 1E-4 seconds. Use an integer number.

Please do NOT use identical input and output files because if something goes wrong, your data WILL be corrupted/destroyed. Also always check the resulting output file.

Technical details

The function will loop over every record and change the “Time correction” field in the fixed section of the MiniSEED data header by the specified amount. Unfortunately a further flag (bit 1 in the “Activity flags” field) determines whether or not the time correction has already been applied to the record start time. If it has not, all is fine and changing the “Time correction” field is enough. Otherwise the actual time also needs to be changed.

One further detail: If bit 1 in the “Activity flags” field is 1 (True) and the “Time correction” field is 0, then the bit will be set to 0 and only the time correction will be changed thus avoiding the need to change the record start time which is preferable.