def setUp(self): super(TestPH5toStationXMLParser_multideploy, self).setUp() kef_to_ph5(self.tmpdir, 'master.ph5', os.path.join(self.home, "ph5/test_data/metadata"), ["array_multi_deploy.kef", "experiment.kef"]) self.ph5sxml, self.mng, self.parser = getParser( self.tmpdir, 'master.ph5', 'NETWORK')
def test_main_created_time_format(self): # array_multideploy.kef: same station different deploy times # => check if network time cover all or only the first 1 kef_to_ph5(self.tmpdir, 'master.ph5', os.path.join(self.home, "ph5/test_data/metadata"), ["array_multi_deploy.kef", "experiment.kef", "response_t.kef"]) testargs = ['ph5tostationxml', '-n', 'master', '--level', 'network', '-f', 'stationxml'] try: from obspy.io.stationxml.core import _format_time as fmt except ImportError: fmt = UTCDateTime.__str__ with patch.object(sys, 'argv', testargs): with OutputCapture() as out: ph5tostationxml.main() output = out.captured.strip().split("\n") timestr = output[6].split('>')[1].split('<')[0] time = UTCDateTime(timestr) convstr = fmt(time) self.assertIn('T', timestr) self.assertEqual(timestr, convstr)
def test_main_location(self): args = ['initialize_ph5', '-n', 'master.ph5'] with patch.object(sys, 'argv', args): with OutputCapture(): initialize_ph5.main() # array_latlon_err.kef: station 1111-1117 # out of range on 1111,1112 # no unit for Y (latitude): 1114 # no value for Z: 1115 kef_to_ph5(self.tmpdir, 'master.ph5', os.path.join(self.home, "ph5/test_data/metadata"), ["array_latlon_err.kef", "experiment.kef", "response_t.kef"]) # load response testargs = ['resp_load', '-n', 'master', '-a', '1', '-i', os.path.join(self.home, 'ph5/test_data/metadata/input.csv')] with patch.object(sys, 'argv', testargs): with OutputCapture() as out: resp_load.main() # There are errors in ph5 so there is no stationxml created testargs = ['ph5tostationxml', '-n', 'master', '--level', 'CHANNEL', '-f', 'text'] with patch.object(sys, 'argv', testargs): with OutputCapture() as out: ph5tostationxml.main() output = out.captured.strip().split("\n") self.assertEqual(len(output), 1) # use flag --stationxml_on_error to create stationxml on error testargs += ['--stationxml_on_error'] with patch.object(sys, 'argv', testargs): with OutputCapture() as out: ph5tostationxml.main() output = out.captured.strip().split("\n") self.assertEqual(len(output), 6) self.assertEqual(output[1].split("|")[1], '1113') self.assertEqual(output[2].split("|")[1], '1114') self.assertEqual(output[3].split("|")[1], '1115') self.assertEqual(output[4].split("|")[1], '1116') self.assertEqual(output[5].split("|")[1], '1117') # excess box intersection on 1113, 1114 # excess radius intersection on 1116, 1117 testargs = ['ph5tostationxml', '-n', 'master', '--level', 'CHANNEL', '-f', 'text', '--minlat', '34', '--maxlat', '40', '--minlon', '-111', '--maxlon', '-105', '--latitude', '36', '--longitude', '-107', '--minradius', '0', '--maxradius', '3', '--stationxml_on_error'] with patch.object(sys, 'argv', testargs): with OutputCapture() as out: ph5tostationxml.main() output = out.captured.strip().split("\n") self.assertEqual(len(output), 2) self.assertEqual(output[1].split("|")[1], '1115')
def setUp(self): super(TestPh5Validate_main_detect_data, self).setUp() kef_to_ph5( self.tmpdir, 'master.ph5', os.path.join(self.home, 'ph5/test_data'), ['rt125a/das_t_12183.kef', 'metadata/array_t_9_validate.kef'], das_sn_list=['12183'])
def test_read_networks(self): kef_to_ph5(self.tmpdir, 'master.ph5', '', []) self.ph5sxml, self.mng, self.parser = getParser( '.', 'master.ph5', "NETWORK") with LogCapture() as log: ret = self.parser.read_networks() self.assertIsNone(ret) self.assertEqual(log.records[0].msg, 'No experiment_t in ./master.ph5')
def test_read_networks(self): kef_to_ph5(self.tmpdir, 'master.ph5', '', []) self.ph5sxml, self.mng, self.parser = getParser( '.', 'master.ph5', "NETWORK") with self.assertRaises(ph5tostationxml.PH5toStationXMLError) as contxt: self.parser.read_networks() self.assertEqual( contxt.exception.message, 'No experiment_t in ./master.ph5') self.mng.ph5.close()
def setUp(self): super(TestPh5Validate, self).setUp() kef_to_ph5( self.tmpdir, 'master.ph5', os.path.join(self.home, 'ph5/test_data'), ['rt125a/das_t_12183.kef', 'metadata/array_t_9_validate.kef'], das_sn_list=['12183']) self.ph5_object = ph5api.PH5(path=self.tmpdir, nickname='master.ph5') self.ph5validate = ph5validate.PH5Validate( self.ph5_object, self.tmpdir, "WARNING", outfile="ph5_validate.log")
def test_main(self): # array_multideploy: same station different deploy times # => check if network time cover all or only the first 1 kef_to_ph5(self.tmpdir, 'master.ph5', os.path.join(self.home, "ph5/test_data/metadata"), ["array_multi_deploy.kef", "experiment.kef"]) testargs = [ 'ph5tostationxml', '-n', 'master', '--level', 'network', '-f', 'text' ] with patch.object(sys, 'argv', testargs): with OutputCapture() as out: ph5tostationxml.main() output = out.captured.strip().split("\n") self.assertEqual( output[1], "AA|PH5 TEST SET|2019-06-29T18:08:33|" "2019-09-28T14:29:39|1")
def test_main(self): kef_to_ph5( self.tmpdir, 'master.ph5', os.path.join(self.home, 'ph5/test_data'), ['rt125a/das_t_12183.kef', 'metadata/array_t_9_validate.kef'], das_sn_list=['12183']) testargs = ['ph5_validate', '-n', 'master.ph5', '-p', self.tmpdir, '-l', 'WARNING'] with patch.object(sys, 'argv', testargs): with OutputCapture(): ph5validate.main() with open('ph5_validate.log') as f: all_logs = f.read().split("-=-=-=-=-=-=-=-=-\n") self.assertEqual( all_logs[2], 'ERROR: Experiment_t does not exist. ' 'run experiment_t_gen to create table\n') self.assertEqual( all_logs[3], 'Station 9001 Channel 1\n1 error, 3 warning, 0 info\n') self.assertEqual( all_logs[4], 'ERROR: No Response table found. Have you run resp_load yet?\n' 'WARNING: No station description found.\n' 'WARNING: Data exists before deploy time: 7 seconds.\n' 'WARNING: Station 9001 [1550849950, 1550850034] is repeated ' '2 time(s)\n') self.assertEqual( all_logs[5], 'Station 9002 Channel 1\n1 error, 2 warning, 0 info\n') self.assertEqual( all_logs[6], 'ERROR: No Response table found. Have you run resp_load yet?\n' 'WARNING: No station description found.\n' 'WARNING: Data exists after pickup time: 36 seconds.\n') self.assertEqual( all_logs[7], 'Station 9003 Channel 1\n1 error, 2 warning, 0 info\n') self.assertEqual( all_logs[8], 'ERROR: No Response table found. Have you run resp_load yet?\n' 'WARNING: No station description found.\n' 'WARNING: Data exists after pickup time: 2 seconds.\n')
def setUp(self): super(TestPH5toStationXMLParser_location, self).setUp() kef_to_ph5(self.tmpdir, 'master.ph5', os.path.join(self.home, "ph5/test_data/metadata"), ["array_latlon_err.kef", "experiment.kef", "response_t.kef"]) self.ph5sxml, self.mng, self.parser = getParser( self.tmpdir, 'master.ph5', "NETWORK", 34, 40, -111, -105, 36, -107, 0, 3) # errors and warnings in array_latlon_err.kef self.errmsgs = ["array 001, station 1111, channel 1: " "Channel latitude -107.0 not in range [-90,90]", "array 001, station 1112, channel 1: " "Channel longitude 182.0 not in range [-180,180]"] self.warnmsgs = ["array 001, station 1114, channel 1: " "No Station location/Y/units_s value found.", "array 001, station 1115, channel 1: " "Channel elevation seems to be 0. Is this correct???"]
def setUp(self): super(TestPH5toStationXMLParser_latlon, self).setUp() kef_to_ph5(self.tmpdir, 'master.ph5', os.path.join(self.home, "ph5/test_data/metadata"), ["array_latlon_err.kef", "experiment.kef"]) self.ph5sxml, self.mng, self.parser = getParser( self.tmpdir, 'master.ph5', "NETWORK", 34, 40, -111, -105, 36, -107, 0, 3) # errors in array_latlon_err.kef self.err_dict = { '1111': [ "Channel latitude -107.0 not in range [-90,90]", box_intersection_err(-107.0, 34, 40, 100.0, -111, -105), radial_intersection_err(-107.0, 100.0, 0, 3, 36, -107) ], '1112': [ "Channel longitude 182.0 not in range [-180,180]", box_intersection_err(35.0, 34, 40, 182.0, -111, -105), radial_intersection_err(35.0, 182.0, 0, 3, 36, -107) ], '1113': [ box_intersection_err(70.0, 34, 40, 100.0, -111, -105), radial_intersection_err(70.0, 100.0, 0, 3, 36, -107) ], '1114': [ box_intersection_err(35.0, 34, 40, 100.0, -111, -105), radial_intersection_err(35.0, 100.0, 0, 3, 36, -107) ], '1116': [radial_intersection_err(35.0, -111.0, 0, 3, 36, -107)], '1117': [radial_intersection_err(40.0, -106.0, 0, 3, 36, -107)] } self.errmsgs = [] for st_id in sorted(self.err_dict.keys()): self.errmsgs += combine_header(st_id, self.err_dict[st_id])