Unfortunately there seems to be a bug in the software of one of our digitizer that resulted in a timestamp 2025-366 (year-julday) for the the first day of this year. Trying to read this file using obspy fails with the error
...
File "/usr/local/lib/python3.9/dist-packages/obspy/core/utcdatetime.py", line 432, in __init__
raise ValueError(msg)
ValueError: 'julday' out of bounds for year 2025: 366
Which of course is correct behaviour. Question though is if it is possible somehow then, using obspy, to read in the file and correct the date (we have no reasons to believe that the timing is bad, only the date seems erroneous) so that the corrected file can be written.
If, not, info on what other software to use will be appreciated.
That’s an alternative but I was sort of hopping that there was a quick way out of this.
But looking at the peace of code you cite, isn’t that a bug we are looking at (the if condition at line 672) since for leap years 366 is a valid day number every leap year?
@cpaitor it is relatively simple to fix fixed headers in MSEED files, so you could “repair” your file manually.
e.g.
from struct import unpack
data = open("my_file.mseed", "rb"), read()
print(unpack('>2H', data[20:24]))
Now what you can do is go through your file and put back together the byte data as is and just replace those 2x2 bytes that encode year and day-of-year with the fixed ones and write back to a repaired file.
Usually MSEED files will be quite well behaved, so just hopping around with record length (512, 2048, …) should be fine and for every record you could add a quick check by just doing a obspy.read(io.BytesIO(data[x:x+record_length]), 'MSEED') and see if it makes sense.