obspy.io.mseed.util.get_start_and_end_time

get_start_and_end_time(file_or_file_object)[source]

Returns the start and end time of a MiniSEED file or file-like object.

Parameters:file_or_file_object (str or file) MiniSEED file name or open file-like object containing a MiniSEED record.
Returns:tuple (start time of first record, end time of last record)

This method will return the start time of the first record and the end time of the last record. Keep in mind that it will not return the correct result if the records in the MiniSEED file do not have a chronological ordering.

The returned end time is the time of the last data sample and not the time that the last sample covers.

Example

>>> from obspy.core.util import get_example_file
>>> filename = get_example_file(
...     "BW.BGLD.__.EHE.D.2008.001.first_10_records")
>>> get_start_and_end_time(filename)  
    (UTCDateTime(2007, 12, 31, 23, 59, 59, 915000),
    UTCDateTime(2008, 1, 1, 0, 0, 20, 510000))

It also works with an open file pointer. The file pointer itself will not be changed.

>>> f = open(filename, 'rb')
>>> get_start_and_end_time(f)  
    (UTCDateTime(2007, 12, 31, 23, 59, 59, 915000),
    UTCDateTime(2008, 1, 1, 0, 0, 20, 510000))

And also with a MiniSEED file stored in a BytesIO

>>> import io
>>> file_object = io.BytesIO(f.read())
>>> get_start_and_end_time(file_object)  
    (UTCDateTime(2007, 12, 31, 23, 59, 59, 915000),
    UTCDateTime(2008, 1, 1, 0, 0, 20, 510000))
>>> file_object.close()

If the file pointer does not point to the first record, the start time will refer to the record it points to.

>>> _ = f.seek(512)
>>> get_start_and_end_time(f)  
    (UTCDateTime(2008, 1, 1, 0, 0, 1, 975000),
    UTCDateTime(2008, 1, 1, 0, 0, 20, 510000))

The same is valid for a file-like object.

>>> file_object = io.BytesIO(f.read())
>>> get_start_and_end_time(file_object)  
    (UTCDateTime(2008, 1, 1, 0, 0, 1, 975000),
    UTCDateTime(2008, 1, 1, 0, 0, 20, 510000))
>>> f.close()