obspy.io.mseed.util.spread_time_over_file

spread_time_over_file(input_file, output_file, timeshift)[source]

Takes a MiniSEED file and a time shift and changes each record to gradually spread the given time shift across all of the blockettes. The intended use is to correct apparent gaps or overlaps less than a sample interval in continuous data that could arise due to hardware (clock drift) or software (rounding errors in time calculations during data management).

The same could be achieved by reading the MiniSEED file with ObsPy, modifying the sample times 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 work correctly only if all records have the same record length; this 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 cumulative time shift to be progressively applied in units of 0.0001 s. Use an integer number, e.g. 10 for a total cumulative time shift of one millisecond.

It is strongly recommended to not work directly on the original data to avoid data loss in case anything goes wrong. 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 header by I*timeshift/(N-1), where N is the number of blockettes in the file and I is the blockette number (starting with zero). Thus the start time of the file will be unchanged, but the end time will be later or earlier. 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.