Skip to content

Commit

Permalink
Merge 0e316ab into 23e0208
Browse files Browse the repository at this point in the history
  • Loading branch information
krischer committed Aug 23, 2016
2 parents 23e0208 + 0e316ab commit 8fe1162
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
@@ -1,6 +1,7 @@
1.0.3:
- obspy.io.mseed:
* ObsPy can now also read (Mini)SEED files with noise records. (see #1495)
* ObsPy can now read records with a data-offset of zero. (see #1509)
- obspy.io.sac:
* `SACTrace.lpspol` and `lcalda` are `True` and `False` by default, when
created via `SACTrace.from_obspy_trace` with a `Trace` that has no SAC
Expand Down
3 changes: 2 additions & 1 deletion obspy/io/mseed/scripts/recordanalyzer.py
Expand Up @@ -217,7 +217,8 @@ def _get_blockettes(self):
cur_blkt_offset = self.fixed_header['First blockette']
# Loop until the beginning of the data is reached.
while True:
if cur_blkt_offset >= self.fixed_header['Beginning of data']:
if len(self.blockettes) == \
self.fixed_header["Number of blockettes that follow"]:
break
# Seek to the offset.
self.file.seek(self.record_offset + cur_blkt_offset, 0)
Expand Down
7 changes: 5 additions & 2 deletions obspy/io/mseed/src/obspy-readbuffer.c
Expand Up @@ -416,8 +416,11 @@ readMSEEDBuffer (char *mseed, int buflen, Selections *selections, flag
}
}

// Actually unpack the data if the flag is not set.
if (unpack_data != 0) {
// Actually unpack the data if the flag is not set and if the data
// offset is valid.
if ((unpack_data != 0) && (msr->fsdh->data_offset > 48) &&
(msr->fsdh->data_offset < msr->reclen) &&
(msr->samplecnt > 0)) {
retval = msr_unpack_data (msr, swapflag, verbose);
}

Expand Down
Binary file not shown.
53 changes: 53 additions & 0 deletions obspy/io/mseed/tests/test_mseed_special_issues.py
Expand Up @@ -815,6 +815,59 @@ def test_read_file_with_various_noise_records(self):
np.testing.assert_allclose(st[0].data, st[2].data)
np.testing.assert_allclose(st[0].data, st[3].data)

def test_mseed_zero_data_offset(self):
"""
Tests that a data offset of zero in the fixed header does not
confuse ObsPy.
The file contains three records: a normal one, followed by one with
a data-offset of zero, followed by another normal one.
This currently results in three returned traces:
* CH.PANIX..LHZ |
2016-08-21T01:41:19.000000Z - 2016-08-21T01:45:30.000000Z |
1.0 Hz, 252 samples
* CH.PANIX..LHZ |
2016-08-21T01:43:37.000000Z - 2016-08-21T01:43:37.000000Z |
1.0 Hz, 0 samples
* CH.PANIX..LHZ |
2016-08-21T01:45:31.000000Z - 2016-08-21T01:49:52.000000Z |
1.0 Hz, 262 samples
"""
file = os.path.join(self.path, "data", "bizarre",
"mseed_data_offset_0.mseed")
st = read(file)

self.assertEqual(len(st), 3)

tr = st[0]
self.assertEqual(tr.id, "CH.PANIX..LHZ")
self.assertEqual(tr.stats.starttime,
UTCDateTime("2016-08-21T01:41:19.000000Z"))
self.assertEqual(tr.stats.endtime,
UTCDateTime("2016-08-21T01:45:30.000000Z"))
self.assertEqual(tr.stats.npts, len(tr.data))
self.assertEqual(tr.stats.npts, 252)

tr = st[1]
self.assertEqual(tr.id, "CH.PANIX..LHZ")
self.assertEqual(tr.stats.starttime,
UTCDateTime("2016-08-21T01:43:37.000000Z"))
self.assertEqual(tr.stats.endtime,
UTCDateTime("2016-08-21T01:43:37.000000Z"))
self.assertEqual(tr.stats.npts, len(tr.data))
self.assertEqual(tr.stats.npts, 0)

tr = st[2]
self.assertEqual(tr.id, "CH.PANIX..LHZ")
self.assertEqual(tr.stats.starttime,
UTCDateTime("2016-08-21T01:45:31.000000Z"))
self.assertEqual(tr.stats.endtime,
UTCDateTime("2016-08-21T01:49:52.000000Z"))
self.assertEqual(tr.stats.npts, len(tr.data))
self.assertEqual(tr.stats.npts, 262)


def suite():
return unittest.makeSuite(MSEEDSpecialIssueTestCase, 'test')
Expand Down
90 changes: 90 additions & 0 deletions obspy/io/mseed/tests/test_recordanalyzer.py
Expand Up @@ -103,6 +103,96 @@ def test_second_record(self):
self.assertEqual(expected.encode('utf-8'),
out.stdout)

def test_record_with_data_offset_zero(self):
"""
The test file has a middle record which has data offset zero. Make
sure it can be read, as well as the following record.
"""
filename = os.path.join(os.path.dirname(__file__), 'data', 'bizarre',
'mseed_data_offset_0.mseed')

with CatchOutput() as out:
obspy_recordanalyzer(['-n', '1', filename])

expected = '''FILE: %s
Record Number: 1
Record Offset: 512 byte
Header Endianness: Big Endian
FIXED SECTION OF DATA HEADER
Sequence number: 1
Data header/quality indicator: D
Station identifier code: PANIX
Location identifier:
Channel identifier: LHZ
Network code: CH
Record start time: 2016-08-21T01:43:37.000000Z
Number of samples: 0
Sample rate factor: 1
Sample rate multiplier: 1
Activity flags: 4
I/O and clock flags: 0
Data quality flags: 0
Number of blockettes that follow: 2
Time correction: 0
Beginning of data: 0
First blockette: 48
BLOCKETTES
1000: Encoding Format: 11
Word Order: 1
Data Record Length: 9
201: NOT YET IMPLEMENTED
CALCULATED VALUES
Corrected Starttime: 2016-08-21T01:43:37.000000Z
''' % (filename,) # noqa
self.assertEqual(expected.encode('utf-8'),
out.stdout)

with CatchOutput() as out:
obspy_recordanalyzer(['-n', '2', filename])

expected = '''FILE: %s
Record Number: 2
Record Offset: 1024 byte
Header Endianness: Big Endian
FIXED SECTION OF DATA HEADER
Sequence number: 189
Data header/quality indicator: D
Station identifier code: PANIX
Location identifier:
Channel identifier: LHZ
Network code: CH
Record start time: 2016-08-21T01:45:31.000000Z
Number of samples: 262
Sample rate factor: 1
Sample rate multiplier: 1
Activity flags: 68
I/O and clock flags: 32
Data quality flags: 0
Number of blockettes that follow: 2
Time correction: 0
Beginning of data: 64
First blockette: 48
BLOCKETTES
1000: Encoding Format: 11
Word Order: 1
Data Record Length: 9
1001: Timing quality: 100
mu_sec: 0
Frame count: 7
CALCULATED VALUES
Corrected Starttime: 2016-08-21T01:45:31.000000Z
''' % (filename,) # noqa
self.assertEqual(expected.encode('utf-8'),
out.stdout)


def suite():
return unittest.makeSuite(RecordAnalyserTestCase, 'test')
Expand Down

0 comments on commit 8fe1162

Please sign in to comment.