def test_read_picks_across_day_end(self): testing_path = os.path.join(self.testing_path, 'sfile_over_day') # raises "UserWarning: AIN in header, currently unsupported" with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) event = read_nordic(testing_path)[0] pick_times = [pick.time for pick in event.picks] for pick in event.picks: # Pick should come after origin time self.assertGreater(pick.time, event.origins[0].time) # All picks in this event are within 60s of origin time self.assertLessEqual((pick.time - event.origins[0].time), 60) # Make sure zero hours and 24 hour picks are handled the same. testing_path = os.path.join(self.testing_path, 'sfile_over_day_zeros') # raises "UserWarning: AIN in header, currently unsupported" with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) event_2 = read_nordic(testing_path)[0] for pick in event_2.picks: # Pick should come after origin time self.assertGreater(pick.time, event_2.origins[0].time) # All picks in this event are within 60s of origin time self.assertLessEqual((pick.time - event_2.origins[0].time), 60) # Each pick should be the same as one pick in the previous event self.assertTrue(pick.time in pick_times) self.assertEqual(event_2.origins[0].time, event.origins[0].time)
def test_read_extra_header(self): testing_path = os.path.join(self.testing_path, 'Sfile_extra_header') not_extra_header = os.path.join(self.testing_path, '01-0411-15L.S201309') test_event = read_nordic(testing_path)[0] header_event = read_nordic(not_extra_header)[0] self.assertEqual(test_event.origins[0].time, header_event.origins[0].time) self.assertEqual(test_event.origins[0].latitude, header_event.origins[0].latitude) self.assertEqual(test_event.origins[0].longitude, header_event.origins[0].longitude) self.assertEqual(test_event.origins[0].depth, header_event.origins[0].depth)
def test_read_moment(self): """Test the reading of seismic moment from the s-file.""" testing_path = os.path.join(self.testing_path, 'automag.out') event = read_nordic(testing_path)[0] mag = [m for m in event.magnitudes if m.magnitude_type == 'MW'] self.assertEqual(len(mag), 1) self.assertEqual(mag[0].mag, 0.7)
def test_read_many_events(self): testing_path = os.path.join(self.testing_path, 'select.out') # raises "UserWarning: AIN in header, currently unsupported" with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) catalog = read_nordic(testing_path) self.assertEqual(len(catalog), 50)
def test_read_extra_header(self): testing_path = os.path.join(self.testing_path, 'Sfile_extra_header') not_extra_header = os.path.join(self.testing_path, '01-0411-15L.S201309') # raises "UserWarning: AIN in header, currently unsupported" with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) test_event = read_nordic(testing_path)[0] header_event = read_nordic(not_extra_header)[0] self.assertEqual(test_event.origins[0].time, header_event.origins[0].time) self.assertEqual(test_event.origins[0].latitude, header_event.origins[0].latitude) self.assertEqual(test_event.origins[0].longitude, header_event.origins[0].longitude) self.assertEqual(test_event.origins[0].depth, header_event.origins[0].depth)
def test_round_len(self): testing_path = os.path.join(self.testing_path, 'round_len_undef.sfile') # raises "UserWarning: AIN in header, currently unsupported" with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) event = read_nordic(testing_path)[0] pick_string = nordpick(event) for pick in pick_string: self.assertEqual(len(pick), 80)
def test_inaccurate_picks(self): testing_path = os.path.join(self.testing_path, 'bad_picks.sfile') # raises "UserWarning: AIN in header, currently unsupported" with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) cat = read_nordic(testing_path) pick_string = nordpick(cat[0]) for pick in pick_string: self.assertEqual(len(pick), 80)
def test_read_empty_header(self): """ Function to check a known issue, empty header info S-file: Bug found \ by Dominic Evanzia. """ test_event = read_nordic(os.path.join(self.testing_path, 'Sfile_no_location'))[0] self.assertFalse(test_event.origins[0].latitude) self.assertFalse(test_event.origins[0].longitude) self.assertFalse(test_event.origins[0].depth)
def test_read_event(self): """ Test the wrapper. """ testing_path = os.path.join(self.testing_path, '01-0411-15L.S201309') # raises "UserWarning: AIN in header, currently unsupported" with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) event = read_nordic(testing_path)[0] self.assertEqual(len(event.origins), 1)
def test_read_picks_across_day_end(self): testing_path = os.path.join(self.testing_path, 'sfile_over_day') event = read_nordic(testing_path)[0] pick_times = [pick.time for pick in event.picks] for pick in event.picks: # Pick should come after origin time self.assertGreater(pick.time, event.origins[0].time) # All picks in this event are within 60s of origin time self.assertLessEqual((pick.time - event.origins[0].time), 60) # Make sure zero hours and 24 hour picks are handled the same. testing_path = os.path.join(self.testing_path, 'sfile_over_day_zeros') event_2 = read_nordic(testing_path)[0] for pick in event_2.picks: # Pick should come after origin time self.assertGreater(pick.time, event_2.origins[0].time) # All picks in this event are within 60s of origin time self.assertLessEqual((pick.time - event_2.origins[0].time), 60) # Each pick should be the same as one pick in the previous event self.assertTrue(pick.time in pick_times) self.assertEqual(event_2.origins[0].time, event.origins[0].time)
def test_read_moment(self): """ Test the reading of seismic moment from the s-file. """ testing_path = os.path.join(self.testing_path, 'automag.out') # raises "UserWarning: AIN in header, currently unsupported" with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) event = read_nordic(testing_path)[0] mag = [m for m in event.magnitudes if m.magnitude_type == 'MW'] self.assertEqual(len(mag), 1) self.assertEqual(mag[0].mag, 0.7)
def test_read_empty_header(self): """ Function to check a known issue, empty header info S-file: Bug found \ by Dominic Evanzia. """ # raises "UserWarning: AIN in header, currently unsupported" with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) test_event = read_nordic(os.path.join(self.testing_path, 'Sfile_no_location'))[0] self.assertFalse(test_event.origins[0].latitude) self.assertFalse(test_event.origins[0].longitude) self.assertFalse(test_event.origins[0].depth)
def test_read_write(self): """ Function to test the read and write capabilities of sfile_util. """ # Set-up a test event test_event = full_test_event() # Sort the magnitudes - they are sorted on writing and we need to check # like-for-like test_event.magnitudes.sort(key=lambda obj: obj['mag'], reverse=True) # Add the event to a catalogue which can be used for QuakeML testing test_cat = Catalog() test_cat += test_event # Check the read-write s-file functionality with TemporaryWorkingDirectory(): sfile = _write_nordic(test_cat[0], filename=None, userid='TEST', evtype='L', outdir='.', wavefiles='test', explosion=True, overwrite=True) self.assertEqual(readwavename(sfile), ['test']) read_cat = Catalog() # raises "UserWarning: AIN in header, currently unsupported" with warnings.catch_warnings(): warnings.simplefilter('ignore', UserWarning) read_cat += read_nordic(sfile) read_ev = read_cat[0] test_ev = test_cat[0] for read_pick, test_pick in zip(read_ev.picks, test_ev.picks): self.assertEqual(read_pick.time, test_pick.time) self.assertEqual(read_pick.backazimuth, test_pick.backazimuth) self.assertEqual(read_pick.onset, test_pick.onset) self.assertEqual(read_pick.phase_hint, test_pick.phase_hint) self.assertEqual(read_pick.polarity, test_pick.polarity) self.assertEqual(read_pick.waveform_id.station_code, test_pick.waveform_id.station_code) self.assertEqual(read_pick.waveform_id.channel_code[-1], test_pick.waveform_id.channel_code[-1]) # assert read_ev.origins[0].resource_id ==\ # test_ev.origins[0].resource_id self.assertEqual(read_ev.origins[0].time, test_ev.origins[0].time) # Note that time_residual_RMS is not a quakeML format self.assertEqual(read_ev.origins[0].longitude, test_ev.origins[0].longitude) self.assertEqual(read_ev.origins[0].latitude, test_ev.origins[0].latitude) self.assertEqual(read_ev.origins[0].depth, test_ev.origins[0].depth) self.assertEqual(read_ev.magnitudes[0].mag, test_ev.magnitudes[0].mag) self.assertEqual(read_ev.magnitudes[1].mag, test_ev.magnitudes[1].mag) self.assertEqual(read_ev.magnitudes[2].mag, test_ev.magnitudes[2].mag) self.assertEqual(read_ev.magnitudes[0].creation_info, test_ev.magnitudes[0].creation_info) self.assertEqual(read_ev.magnitudes[1].creation_info, test_ev.magnitudes[1].creation_info) self.assertEqual(read_ev.magnitudes[2].creation_info, test_ev.magnitudes[2].creation_info) self.assertEqual(read_ev.magnitudes[0].magnitude_type, test_ev.magnitudes[0].magnitude_type) self.assertEqual(read_ev.magnitudes[1].magnitude_type, test_ev.magnitudes[1].magnitude_type) self.assertEqual(read_ev.magnitudes[2].magnitude_type, test_ev.magnitudes[2].magnitude_type) self.assertEqual(read_ev.event_descriptions, test_ev.event_descriptions) # assert read_ev.amplitudes[0].resource_id ==\ # test_ev.amplitudes[0].resource_id self.assertEqual(read_ev.amplitudes[0].period, test_ev.amplitudes[0].period) self.assertEqual(read_ev.amplitudes[0].snr, test_ev.amplitudes[0].snr) self.assertEqual(read_ev.amplitudes[2].period, test_ev.amplitudes[2].period) self.assertEqual(read_ev.amplitudes[2].snr, test_ev.amplitudes[2].snr) # Check coda magnitude pick # Resource ids get overwritten because you can't have two the same in # memory # self.assertEqual(read_ev.amplitudes[1].resource_id, # test_ev.amplitudes[1].resource_id) self.assertEqual(read_ev.amplitudes[1].type, test_ev.amplitudes[1].type) self.assertEqual(read_ev.amplitudes[1].unit, test_ev.amplitudes[1].unit) self.assertEqual(read_ev.amplitudes[1].generic_amplitude, test_ev.amplitudes[1].generic_amplitude) # Resource ids get overwritten because you can't have two the same in # memory # self.assertEqual(read_ev.amplitudes[1].pick_id, # test_ev.amplitudes[1].pick_id) self.assertEqual(read_ev.amplitudes[1].waveform_id.station_code, test_ev.amplitudes[1].waveform_id.station_code) self.assertEqual(read_ev.amplitudes[1].waveform_id.channel_code, test_ev.amplitudes[1]. waveform_id.channel_code[0] + test_ev.amplitudes[1]. waveform_id.channel_code[-1]) self.assertEqual(read_ev.amplitudes[1].magnitude_hint, test_ev.amplitudes[1].magnitude_hint) # snr is not supported in s-file # self.assertEqual(read_ev.amplitudes[1].snr, # test_ev.amplitudes[1].snr) self.assertEqual(read_ev.amplitudes[1].category, test_ev.amplitudes[1].category)
def test_round_len(self): testing_path = os.path.join(self.testing_path, 'round_len_undef.sfile') event = read_nordic(testing_path)[0] pick_string = nordpick(event) for pick in pick_string: self.assertEqual(len(pick), 80)
def test_inaccurate_picks(self): testing_path = os.path.join(self.testing_path, 'bad_picks.sfile') cat = read_nordic(testing_path) pick_string = nordpick(cat[0]) for pick in pick_string: self.assertEqual(len(pick), 80)
def test_read_write(self): """ Function to test the read and write capabilities of sfile_util. """ # Set-up a test event test_event = full_test_event() # Add the event to a catalogue which can be used for QuakeML testing test_cat = Catalog() test_cat += test_event # Check the read-write s-file functionality sfile = _write_nordic(test_cat[0], filename=None, userid='TEST', evtype='L', outdir='.', wavefiles='test', explosion=True, overwrite=True) self.assertEqual(readwavename(sfile), ['test']) read_cat = Catalog() read_cat += read_nordic(sfile) os.remove(sfile) read_ev = read_cat[0] test_ev = test_cat[0] for read_pick, test_pick in zip(read_ev.picks, test_ev.picks): self.assertEqual(read_pick.time, test_pick.time) self.assertEqual(read_pick.backazimuth, test_pick.backazimuth) self.assertEqual(read_pick.onset, test_pick.onset) self.assertEqual(read_pick.phase_hint, test_pick.phase_hint) self.assertEqual(read_pick.polarity, test_pick.polarity) self.assertEqual(read_pick.waveform_id.station_code, test_pick.waveform_id.station_code) self.assertEqual(read_pick.waveform_id.channel_code[-1], test_pick.waveform_id.channel_code[-1]) # assert read_ev.origins[0].resource_id ==\ # test_ev.origins[0].resource_id self.assertEqual(read_ev.origins[0].time, test_ev.origins[0].time) # Note that time_residual_RMS is not a quakeML format self.assertEqual(read_ev.origins[0].longitude, test_ev.origins[0].longitude) self.assertEqual(read_ev.origins[0].latitude, test_ev.origins[0].latitude) self.assertEqual(read_ev.origins[0].depth, test_ev.origins[0].depth) self.assertEqual(read_ev.magnitudes[0].mag, test_ev.magnitudes[0].mag) self.assertEqual(read_ev.magnitudes[1].mag, test_ev.magnitudes[1].mag) self.assertEqual(read_ev.magnitudes[2].mag, test_ev.magnitudes[2].mag) self.assertEqual(read_ev.magnitudes[0].creation_info, test_ev.magnitudes[0].creation_info) self.assertEqual(read_ev.magnitudes[1].creation_info, test_ev.magnitudes[1].creation_info) self.assertEqual(read_ev.magnitudes[2].creation_info, test_ev.magnitudes[2].creation_info) self.assertEqual(read_ev.magnitudes[0].magnitude_type, test_ev.magnitudes[0].magnitude_type) self.assertEqual(read_ev.magnitudes[1].magnitude_type, test_ev.magnitudes[1].magnitude_type) self.assertEqual(read_ev.magnitudes[2].magnitude_type, test_ev.magnitudes[2].magnitude_type) self.assertEqual(read_ev.event_descriptions, test_ev.event_descriptions) # assert read_ev.amplitudes[0].resource_id ==\ # test_ev.amplitudes[0].resource_id self.assertEqual(read_ev.amplitudes[0].period, test_ev.amplitudes[0].period) self.assertEqual(read_ev.amplitudes[0].snr, test_ev.amplitudes[0].snr) # Check coda magnitude pick # Resource ids get overwritten because you can't have two the same in # memory # self.assertEqual(read_ev.amplitudes[1].resource_id, # test_ev.amplitudes[1].resource_id) self.assertEqual(read_ev.amplitudes[1].type, test_ev.amplitudes[1].type) self.assertEqual(read_ev.amplitudes[1].unit, test_ev.amplitudes[1].unit) self.assertEqual(read_ev.amplitudes[1].generic_amplitude, test_ev.amplitudes[1].generic_amplitude) # Resource ids get overwritten because you can't have two the same in # memory # self.assertEqual(read_ev.amplitudes[1].pick_id, # test_ev.amplitudes[1].pick_id) self.assertEqual(read_ev.amplitudes[1].waveform_id.station_code, test_ev.amplitudes[1].waveform_id.station_code) self.assertEqual(read_ev.amplitudes[1].waveform_id.channel_code, test_ev.amplitudes[1]. waveform_id.channel_code[0] + test_ev.amplitudes[1]. waveform_id.channel_code[-1]) self.assertEqual(read_ev.amplitudes[1].magnitude_hint, test_ev.amplitudes[1].magnitude_hint) # snr is not supported in s-file # self.assertEqual(read_ev.amplitudes[1].snr, # test_ev.amplitudes[1].snr) self.assertEqual(read_ev.amplitudes[1].category, test_ev.amplitudes[1].category)
def test_read_many_events(self): testing_path = os.path.join(self.testing_path, 'select.out') catalog = read_nordic(testing_path) self.assertEqual(len(catalog), 50)
def test_read_event(self): """Test the wrapper.""" testing_path = os.path.join(self.testing_path, '01-0411-15L.S201309') event = read_nordic(testing_path)[0] self.assertEqual(len(event.origins), 1)