Exemplo n.º 1
0
    def test_main3(self):

        with open("test_list", "w") as f:
            # need to use relative path '../miniseed/0407HHN.ms' because
            # das_t's 'raw_file_name_s will be chopped off if the path's
            # length is greater than 32
            f.write("../miniseed/0407HHN.ms")
        # first need to run obspytoph5
        testargs = ['obspytoph5', '-n', 'master.ph5', '-f', 'test_list']
        with patch.object(sys, 'argv', testargs):
            obspytoph5.main()
        self.assertTrue(os.path.isfile('master.ph5'))
        self.assertTrue(os.path.isfile('miniPH5_00001.ph5'))

        self.ph5_object = initialize_ex('master.ph5', '.', False)
        node = self.ph5_object.ph5_g_receivers.getdas_g('5553')
        self.ph5_object.ph5_g_receivers.setcurrent(node)
        ret, das_keys = self.ph5_object.ph5_g_receivers.read_das()
        keys = [
            'array_name_SOH_a', 'array_name_data_a', 'array_name_event_a',
            'array_name_log_a', 'channel_number_i', 'event_number_i',
            'raw_file_name_s', 'receiver_table_n_i', 'response_table_n_i',
            'sample_count_i', 'sample_rate_i', 'sample_rate_multiplier_i',
            'stream_number_i', 'time/ascii_s', 'time/epoch_l',
            'time/micro_seconds_i', 'time/type_s', 'time_table_n_i'
        ]
        self.assertEqual(keys, das_keys)
        self.assertEqual('../miniseed/0407HHN.ms', ret[0]['raw_file_name_s'])
Exemplo n.º 2
0
    def test_update_external_references(self):
        self.ph5object = seg2toph5.EX = \
            initialize_ex('master.ph5', '.', True)
        keys = ['external_file_name_s', 'hdf5_path_s', 'serial_number_s']
        INDEX_T_DAS_rows = \
            [{'external_file_name_s': './miniPH5_00001.ph5',
              'hdf5_path_s': '/Experiment_g/Receivers_g/Das_g_0000SV01'}]
        seg2toph5.INDEX_T_DAS = seg2toph5.Rows_Keys(INDEX_T_DAS_rows, keys)

        INDEX_T_MAP_rows = \
            [{'external_file_name_s': './miniPH5_00001.ph5',
              'hdf5_path_s': '/Experiment_g/Maps_g/Das_g_0000SV01'}]
        seg2toph5.INDEX_T_MAP = seg2toph5.Rows_Keys(INDEX_T_MAP_rows, keys)

        seg2toph5.update_external_references()

        # check if external links are created
        node = self.ph5object.ph5.get_node("/Experiment_g/Receivers_g/")
        target = 'miniPH5_00001.ph5:/Experiment_g/Receivers_g/Das_g_0000SV01'
        for n in self.ph5object.ph5.list_nodes(node):
            if hasattr(n, 'target'):
                self.assertEqual(n.target, target)
                break

        node = self.ph5object.ph5.get_node("/Experiment_g/Maps_g/")
        target = 'miniPH5_00001.ph5:/Experiment_g/Maps_g/Das_g_0000SV01'
        for n in self.ph5object.ph5.list_nodes(node):
            if hasattr(n, 'target'):
                self.assertEqual(n.target, target)
                break
Exemplo n.º 3
0
 def setUp(self):
     super(TestObspytoPH5, self).setUp()
     self.station_xml_path = os.path.join(
         self.home, 'ph5/test_data/metadata/station.xml')
     self.ph5_object = initialize_ex('master.ph5', self.tmpdir, True)
     self.obs = obspytoph5.ObspytoPH5(self.ph5_object, self.tmpdir, 1, 1)
     self.obs.verbose = True
     self.ph5_object.ph5flush()
     self.ph5_object.ph5_g_sorts.update_local_table_nodes()
Exemplo n.º 4
0
 def test_main(self):
     testargs = [
         'mstoph5', '-n', 'master.ph5', '-r',
         os.path.join(self.datapath, '05743.SS..GHZ.148')
     ]
     with patch.object(sys, 'argv', testargs):
         obspytoph5.main()
     self.ph5_object = initialize_ex('master.ph5', self.tmpdir, False)
     data_node = self.ph5_object.ph5.get_node(
         '/Experiment_g/Receivers_g/Das_g_05743', 'Data_a_00001', 'Array')
     data = data_node.read()
     self.assertIsInstance(data[0], numpy.float32)
Exemplo n.º 5
0
    def test_test_to_ph5(self):
        self.ph5_object = initialize_ex('master.ph5', self.tmpdir, True)
        self.obs = obspytoph5.ObspytoPH5(self.ph5_object, self.tmpdir, 1, 1)

        entry = os.path.join(self.datapath, '05743.SS..GHZ.148')
        message, index_t = self.obs.toph5((entry, 'MSEED'))

        if len(self.obs.time_t) > 0:
            for entry in self.obs.time_t:
                self.obs.ph5.ph5_g_receivers.populateTime_t_(entry)
        for entry in index_t:
            self.obs.ph5.ph5_g_receivers.populateIndex_t(entry)
        self.obs.update_external_references(index_t)
        data_node = self.ph5_object.ph5.get_node(
            '/Experiment_g/Receivers_g/Das_g_05743', 'Data_a_00001', 'Array')
        data = data_node.read()
        self.assertIsInstance(data[0], numpy.float32)
Exemplo n.º 6
0
    def test_main(self):
        # add fcnt data of the same das in the same array but with different
        # deploytime
        segd_dir = os.path.join(self.home, "ph5/test_data/segd/")
        # create list file
        list_file = open('fcnt_list', "w")
        fileList = os.listdir(segd_dir)
        s = ""
        for f in fileList:
            if f.endswith(".fcnt") and f.startswith("1111"):
                s += segd_dir + f + "\n"
        list_file.write(s)
        list_file.close()

        # add segD to ph5
        testargs = ['segdtoph5', '-n', 'master', '-f', 'fcnt_list']
        with patch.object(sys, 'argv', testargs):
            segd2ph5.main()

        # check that all deploy times are in array_t
        self.EX = tabletokef.EX = initialize_ex('master.ph5', '.', False)
        tabletokef.ARRAY_T = {}
        tabletokef.read_sort_table()
        tabletokef.read_sort_arrays()
        self.assertEqual(len(tabletokef.ARRAY_T), 1)
        self.assertEqual(tabletokef.ARRAY_T.keys()[0], "Array_t_001")
        self.assertEqual(len(tabletokef.ARRAY_T['Array_t_001'].rows), 9)
        # id_s 1111 SHOULD have 3 different times,
        # each has 3 rows for 3 channels
        time_count = {}
        for s in tabletokef.ARRAY_T['Array_t_001'].rows:
            if s['id_s'] == '1111':
                d = s['deploy_time/epoch_l']
                if d not in time_count.keys():
                    time_count[d] = 0
                time_count[d] += 1

        self.assertDictEqual(time_count, {
            1561831393: 3,
            1563634018: 3,
            1567269236: 3
        })
Exemplo n.º 7
0
    def test_main(self):
        testargs = ['metadatatoph5', '-n', 'master.ph5', '-f',
                    os.path.join(self.home,
                                 'ph5/test_data/metadata/station.xml')]
        with patch.object(sys, 'argv', testargs):
            metadatatoph5.main()
        self.assertTrue(os.path.isfile('master.ph5'))

        self.ph5_object = initialize_ex('master.ph5', '.', False)
        array_names = self.ph5_object.ph5_g_sorts.names()
        self.assertEqual(
            ['Array_t_001', 'Array_t_002', 'Array_t_003'], array_names)
        ret, keys = self.ph5_object.ph5_g_sorts.read_arrays('Array_t_001')
        key = ['id_s', 'location/X/value_d', 'location/X/units_s',
               'location/Y/value_d', 'location/Y/units_s',
               'location/Z/value_d', 'location/Z/units_s',
               'location/coordinate_system_s', 'location/projection_s',
               'location/ellipsoid_s', 'location/description_s',
               'deploy_time/ascii_s', 'deploy_time/epoch_l',
               'deploy_time/micro_seconds_i', 'deploy_time/type_s',
               'pickup_time/ascii_s', 'pickup_time/epoch_l',
               'pickup_time/micro_seconds_i', 'pickup_time/type_s',
               'das/serial_number_s', 'das/model_s', 'das/manufacturer_s',
               'das/notes_s', 'sensor/serial_number_s', 'sensor/model_s',
               'sensor/manufacturer_s', 'sensor/notes_s', 'description_s',
               'seed_band_code_s', 'sample_rate_i',
               'sample_rate_multiplier_i',
               'seed_instrument_code_s', 'seed_orientation_code_s',
               'seed_location_code_s', 'seed_station_name_s',
               'channel_number_i', 'receiver_table_n_i', 'response_table_n_i']
        self.assertEqual(key, keys)
        self.assertEqual(1, len(ret))
        self.assertEqual('5553', ret[0]['das/serial_number_s'])
        self.assertEqual('H', ret[0]['seed_instrument_code_s'])
        self.assertEqual('H', ret[0]['seed_band_code_s'])
        self.assertEqual('N', ret[0]['seed_orientation_code_s'])
        self.ph5_object.ph5close()
Exemplo n.º 8
0
 def setUp(self):
     super(TestMetadatatoPH5, self).setUp()
     self.ph5_object = initialize_ex('master.ph5', self.tmpdir, True)
     self.metadata = metadatatoph5.MetadatatoPH5(
         self.ph5_object)
Exemplo n.º 9
0
 def setUp(self):
     super(TestSegDtoPH5, self).setUp()
     # initiate ph5
     self.EX = segd2ph5.EX = initialize_ex('master.ph5', '.', True)