diff --git a/lemi2seed/lemi_metadata.py b/lemi2seed/lemi_metadata.py index 313accabdfb2f32dade1d603c57b02a179b6d293..43180652660a68d289489e956545bd2c3bee9870 100644 --- a/lemi2seed/lemi_metadata.py +++ b/lemi2seed/lemi_metadata.py @@ -117,7 +117,7 @@ class LemiMetadata(): "file!".format(filename)) return sheet_type - def init_run_md_props(self) -> List[Run]: + def init_run_props(self) -> List[Run]: """ Instantiate Run data class object and initialize non-user defined properties. @@ -133,7 +133,7 @@ class LemiMetadata(): runs.append(run) return runs - def init_cha_md_props(self, cha_type: str, run_id: str) -> DCS_SUB_EMA: + def init_cha_props(self, cha_type: str, run_id: str) -> DCS_SUB_EMA: """ Create instances of Elec, Mag or Aux data class and initialize properties inherited from the BaseSta and BaseChannel @@ -194,7 +194,7 @@ class LemiMetadata(): if isinstance(mprop, list): if cat == 'Run': if not mprop: - mprop = self.init_run_md_props() + mprop = self.init_run_props() for ind, dc in enumerate(mprop): key = f'Run_{self.run_list[ind]}' output[cat][key] = LemiMetadata.dc2dict(dc) @@ -202,7 +202,7 @@ class LemiMetadata(): for run_id in self.run_list: chas = self.filter_cha('elec', run_id) if not chas: - cha = self.init_cha_md_props('elec', run_id) + cha = self.init_cha_props('elec', run_id) chas = [LemiMetadata.update_cha_num(cha, f'E{ind + 1}') # type: ignore for ind in range(NUM_E_CHA_MAX)] # type: ignore for ind in range(NUM_E_CHA_MAX): @@ -212,7 +212,7 @@ class LemiMetadata(): for run_id in self.run_list: chas = self.filter_cha('mag', run_id) if not chas: - dc = self.init_cha_md_props('mag', run_id) + dc = self.init_cha_props('mag', run_id) else: dc = chas[0] key = f'Run_{run_id}_Mag' @@ -354,7 +354,7 @@ class LemiMetadata(): else: cat.md_missing.discard(key) - def populate_net_md_props(self, md_fields_n: Dict) -> None: + def populate_net_props(self, md_fields_n: Dict) -> None: """ Populate properties of Network data class based on user inputs from the field sheets and/or GUI. @@ -362,7 +362,7 @@ class LemiMetadata(): self.populate(self.net, md_fields_n) LemiMetadata.flag_md_missing(self.net) - def populate_sta_md_props(self, md_fields_s: Dict) -> None: + def populate_sta_props(self, md_fields_s: Dict) -> None: """ Populate properties of Sta data class based on user inputs from the field sheets and/or GUI. @@ -371,13 +371,13 @@ class LemiMetadata(): self.sta.run_list = ', '.join(self.run_list) LemiMetadata.flag_md_missing(self.sta) - def populate_run_md_props(self, md_fields_r: Dict) -> None: + def populate_run_props(self, md_fields_r: Dict) -> None: """ Populate properties of run data class based on user inputs from the field sheets and/or GUI. """ if not self.run: - self.run.extend(self.init_run_md_props()) + self.run.extend(self.init_run_props()) for ind, run in enumerate(self.run): run_id = self.run_list[ind] name = f'Run_{run_id}' @@ -486,7 +486,7 @@ class LemiMetadata(): elec = [c for c in self.elec if c.run_id == run_id and c.cha_num == key] elec[0].loc_code = e_loc.get(key, '') - def populate_elec_md_props(self, md_fields_e: Dict, num_e_pairs: Optional[Dict] = None) -> Tuple[Dict, Dict]: + def populate_elec_props(self, md_fields_e: Dict, num_e_pairs: Optional[Dict] = None) -> Tuple[Dict, Dict]: """ Populate properties of Elec data class based on user inputs from the field sheets and/or GUI. @@ -498,7 +498,7 @@ class LemiMetadata(): if not e_comps: continue if not self.filter_cha('elec', run_id): - cha = self.init_cha_md_props('elec', run_id) + cha = self.init_cha_props('elec', run_id) self.elec.extend([LemiMetadata.update_cha_num(cha, f'E{i+1}') # type: ignore for i in range(NUM_E_CHA_MAX)]) # type: ignore num_e_pairs_run = (int(num_e_pairs.get(run_id) or len(e_comps)) @@ -541,7 +541,7 @@ class LemiMetadata(): tmp.cha_name = CHA_NAMING_CONV[tmp.comp] return tmp - def populate_mag_md_props(self, md_fields_m: Dict) -> None: + def populate_mag_props(self, md_fields_m: Dict) -> None: """ Populate properties of Mag data class based on user inputs from the field sheets and/or GUI. @@ -552,7 +552,7 @@ class LemiMetadata(): if not m_comps: continue if not self.filter_cha('mag', run_id): - cha = self.init_cha_md_props('mag', run_id) + cha = self.init_cha_props('mag', run_id) # Use deepcopy here so that any changes made to the copy object # do not reflect in the original object. self.mag.extend([copy.deepcopy(cha) for i in range(len(CHA_TYPES['mag']))]) # type: ignore @@ -567,14 +567,14 @@ class LemiMetadata(): comp = CHA_TYPES['mag'][ind] self.mag[cha_ind] = LemiMetadata.update_comp_cha_name(cha, comp) # type: ignore - def populate_aux_md_props(self) -> None: + def populate_aux_props(self) -> None: """ Populate properties of Aux data class based on user inputs from the field sheets and/or GUI. """ for ind_run, run_id in enumerate(self.run_list): if not self.filter_cha('aux', run_id): - cha = self.init_cha_md_props('aux', run_id) + cha = self.init_cha_props('aux', run_id) # Use deepcopy here so that any changes made to the copy object # do not reflect in the original object. self.aux.extend([copy.deepcopy(cha) for i in range(len(CHA_TYPES['aux']))]) # type: ignore @@ -588,14 +588,14 @@ class LemiMetadata(): comp = CHA_TYPES['aux'][ind] self.aux[cha_ind] = LemiMetadata.update_comp_cha_name(cha, comp) # type: ignore - def populate_md_props(self, md_fields: Dict) -> None: + def populate_props(self, md_fields: Dict) -> None: """ Populate metadata properties based on user inputs from the field sheets and/or GUI. """ for cat in self.cats: md_fields_ = md_fields.get(cat) - populate_method = f'populate_{cat.lower()}_md_props' + populate_method = f'populate_{cat.lower()}_props' if md_fields_: methodcaller(populate_method, md_fields_)(self) else: diff --git a/tests/test_lemi_metadata.py b/tests/test_lemi_metadata.py index 1a4859b04899f0aeca99b92192da07dfa428cc25..759379c8cbe25f7da8bbe9488c188aa1ce4a75e2 100644 --- a/tests/test_lemi_metadata.py +++ b/tests/test_lemi_metadata.py @@ -147,9 +147,9 @@ class TestLemiMetadata(unittest.TestCase): """Test basic functionality of from_field_sheets""" self.assertDictEqual(self.md.from_field_sheets, self.md_fields) - def test_populate_net_md_props(self): - """Test basic functionality of populate_net_md_props.""" - self.md.populate_net_md_props(self.md_fields['Net']) + def test_populate_net_props(self): + """Test basic functionality of populate_net_props.""" + self.md.populate_net_props(self.md_fields['Net']) self.assertSetEqual(self.md.net.md_missing, {'geo_name', 'start', 'project', 'name'}) self.assertSetEqual(self.md.net.md_invalid, {'start'}) @@ -158,9 +158,9 @@ class TestLemiMetadata(unittest.TestCase): self.assertEqual(getattr(self.md.net, key), val) self.assertIsNone(self.md.net.start) - def test_populate_sta_md_props(self): - """Test basic functionality of populate_sta_md_props.""" - self.md.populate_sta_md_props(self.md_fields['Sta']) + def test_populate_sta_props(self): + """Test basic functionality of populate_sta_props.""" + self.md.populate_sta_props(self.md_fields['Sta']) self.assertSetEqual(self.md.sta.md_missing, {'end', 'elev', 'lon', 'start', 'geo_name'}) self.assertSetEqual(self.md.sta.md_invalid, {'elev', 'lon', 'start'}) @@ -171,8 +171,8 @@ class TestLemiMetadata(unittest.TestCase): self.assertIsNone(self.md.sta.elev) self.assertIsNone(self.md.sta.start) - def test_init_run_md_props(self): - """Test basic functionality of init_run_md_props.""" + def test_init_run_props(self): + """Test basic functionality of init_run_props.""" time_period_starts = [UTCDateTime(2020, 9, 30, 21, 5), UTCDateTime(2020, 9, 30, 21, 12), UTCDateTime(2020, 9, 30, 21, 14), @@ -181,15 +181,15 @@ class TestLemiMetadata(unittest.TestCase): UTCDateTime(2020, 9, 30, 21, 13, 45), UTCDateTime(2020, 9, 30, 21, 27, 59), UTCDateTime(2020, 10, 1, 0, 5, 59)] - self.md.init_run_md_props() + self.md.init_run_props() for ind, run in enumerate(self.md.run): self.assertEqual(run.start, time_period_starts[ind]) self.assertEqual(run.end, time_period_ends[ind]) self.assertEqual(run.resource_id, 'mt.run.id:' + self.md.run_list[ind]) - def test_populate_run_md_props(self): - """Test basic functionality of populate_run_md_props.""" - self.md.populate_run_md_props(self.md_fields['Run']) + def test_populate_run_props(self): + """Test basic functionality of populate_run_props.""" + self.md.populate_run_props(self.md_fields['Run']) self.assertEqual(self.md.run[0].comps_rec, 'E1, E2, E3, E4, Hx, Hy, Hz') self.assertEqual(self.md.run[0].datalogger_sn, 110) self.assertSetEqual(self.md.run[0].md_missing, set()) @@ -200,45 +200,45 @@ class TestLemiMetadata(unittest.TestCase): self.assertSetEqual(run.md_missing, {'datalogger_sn', 'comps_rec'}) self.assertSetEqual(run.md_invalid, {'datalogger_sn', 'comps_rec'}) - def test_init_cha_md_props_elec(self): - """Test basic functionality of init_cha_md_props.""" - cha = self.md.init_cha_md_props('elec', 'a') + def test_init_cha_props_elec(self): + """Test basic functionality of init_cha_props.""" + cha = self.md.init_cha_props('elec', 'a') self.assertIsInstance(cha, Elec) self.assertEqual(cha.elev, round(self.md.data_stats['elev'], 3)) self.assertEqual(cha.lat, round(self.md.data_stats['lat'], 3)) self.assertEqual(cha.lon, round(self.md.data_stats['lon'], 3)) self.assertEqual(cha.run_id, 'a') - def test_init_cha_md_props_mag(self): - """Test basic functionality of init_cha_md_props.""" - cha = self.md.init_cha_md_props('mag', 'a') + def test_init_cha_props_mag(self): + """Test basic functionality of init_cha_props.""" + cha = self.md.init_cha_props('mag', 'a') self.assertIsInstance(cha, Mag) self.assertEqual(cha.elev, round(self.md.data_stats['elev'], 3)) self.assertEqual(cha.lat, round(self.md.data_stats['lat'], 3)) self.assertEqual(cha.lon, round(self.md.data_stats['lon'], 3)) self.assertEqual(cha.run_id, 'a') - def test_init_cha_md_props_aux(self): - """Test basic functionality of init_cha_md_props.""" - cha = self.md.init_cha_md_props('aux', 'a') + def test_init_cha_props_aux(self): + """Test basic functionality of init_cha_props.""" + cha = self.md.init_cha_props('aux', 'a') self.assertIsInstance(cha, Aux) self.assertEqual(cha.elev, round(self.md.data_stats['elev'], 3)) self.assertEqual(cha.lat, round(self.md.data_stats['lat'], 3)) self.assertEqual(cha.lon, round(self.md.data_stats['lon'], 3)) self.assertEqual(cha.run_id, 'a') - def test_populate_elec_md_props_one_run_set(self): - """Test basic functionality of populate_elec_md_props.""" - self.md.populate_run_md_props(self.md_fields['Run']) - self.md.populate_elec_md_props(self.md_fields['Elec']) + def test_populate_elec_props_one_run_set(self): + """Test basic functionality of populate_elec_props.""" + self.md.populate_run_props(self.md_fields['Run']) + self.md.populate_elec_props(self.md_fields['Elec']) file_ = self.path2md.joinpath('electric_metadata_properties_1.pkl') with open(file_, 'rb') as fin: expected = pickle.load(fin) self.assertListEqual(self.md.elec, expected) - def test_populate_elec_md_props_two_runs_set(self): - """Test basic functionality of populate_elec_md_props.""" - self.md.populate_run_md_props(self.md_fields['Run']) + def test_populate_elec_props_two_runs_set(self): + """Test basic functionality of populate_elec_props.""" + self.md.populate_run_props(self.md_fields['Run']) self.md.run[1].comps_rec = 'E1, E2, Hx, Hy, Hz' specs = 'Borin STELTH 4 - Silver-Silver Chloride' self.md_fields['Elec']['Run_b_Elec_Pair_1']['cha_num'] = 'E1' @@ -247,37 +247,37 @@ class TestLemiMetadata(unittest.TestCase): self.md_fields['Elec']['Run_b_Elec_Pair_4']['cha_num'] = 'E4' self.md_fields['Elec']['Run_b_Elec_Pair_1']['inst_specs'] = specs self.md_fields['Elec']['Run_b_Elec_Pair_2']['inst_specs'] = specs - self.md.populate_elec_md_props(self.md_fields['Elec']) + self.md.populate_elec_props(self.md_fields['Elec']) file_ = self.path2md.joinpath('electric_metadata_properties_2.pkl') with open(file_, 'rb') as fin: expected = pickle.load(fin) self.assertListEqual(self.md.elec, expected) - def test_populate_mag_md_props_one_run_set(self): - """Test basic functionality of populate_mag_md_props.""" - self.md.populate_run_md_props(self.md_fields['Run']) - self.md.populate_mag_md_props(self.md_fields['Mag']) + def test_populate_mag_props_one_run_set(self): + """Test basic functionality of populate_mag_props.""" + self.md.populate_run_props(self.md_fields['Run']) + self.md.populate_mag_props(self.md_fields['Mag']) file_ = self.path2md.joinpath('magnetic_metadata_properties_1.pkl') with open(file_, 'rb') as fin: expected = pickle.load(fin) self.assertListEqual(self.md.mag, expected) - def test_populate_mag_md_props_two_runs_set(self): - """Test basic functionality of populate_mag_md_props.""" - self.md.populate_run_md_props(self.md_fields['Run']) + def test_populate_mag_props_two_runs_set(self): + """Test basic functionality of populate_mag_props.""" + self.md.populate_run_props(self.md_fields['Run']) self.md.run[1].comps_rec = 'E1, E2, Hx, Hy, Hz' specs = 'LEMI-039' self.md_fields['Mag']['Run_b_Mag']['inst_specs'] = specs - self.md.populate_mag_md_props(self.md_fields['Mag']) + self.md.populate_mag_props(self.md_fields['Mag']) file_ = self.path2md.joinpath('magnetic_metadata_properties_2.pkl') with open(file_, 'rb') as fin: expected = pickle.load(fin) self.assertListEqual(self.md.mag, expected) - def test_populate_aux_md_props_one_run_set(self): - """Test basic functionality of populate_aux_md_props.""" - self.md.populate_run_md_props(self.md_fields['Run']) - self.md.populate_aux_md_props() + def test_populate_aux_props_one_run_set(self): + """Test basic functionality of populate_aux_props.""" + self.md.populate_run_props(self.md_fields['Run']) + self.md.populate_aux_props() file_ = self.path2md.joinpath('auxiliary_metadata_properties.pkl') with open(file_, 'rb') as fin: expected = pickle.load(fin) @@ -290,7 +290,7 @@ class TestLemiMetadata(unittest.TestCase): def test_filter_cha_cha_populated_for_given_run(self): """Test basic functionality of filter_cha.""" cha_names = ['LEH', 'LKH', 'LKF', 'GNS', 'GST', 'LCE'] - self.md.populate_md_props(self.md_fields) + self.md.populate_props(self.md_fields) cha_filtered = self.md.filter_cha('aux', 'a') self.assertEqual(len(cha_filtered), 6) for ind, cha in enumerate(cha_filtered): @@ -302,7 +302,7 @@ class TestLemiMetadata(unittest.TestCase): def test_get_cha_inds_cha_populated_for_given_run(self): """Test basic functionality of get_cha_inds.""" - self.md.populate_md_props(self.md_fields) + self.md.populate_props(self.md_fields) cha_inds = self.md.get_cha_inds('aux', 'a') self.assertListEqual(cha_inds, [0, 1, 2, 3, 4, 5]) @@ -311,7 +311,7 @@ class TestLemiMetadata(unittest.TestCase): type_ = 'E' cha_type = 'electric field' run_id = 'b' - self.md.populate_run_md_props(self.md_fields['Run']) + self.md.populate_run_props(self.md_fields['Run']) with self.assertLogs(logger, level='WARNING') as cmd: self.md.get_comps_rec(type_, run_id) msg = (f"No {cha_type} data recorded for run '{run_id}'. If you " @@ -325,7 +325,7 @@ class TestLemiMetadata(unittest.TestCase): type_ = 'E' cha_type = 'electric field' run_id = 'b' - self.md.populate_run_md_props(self.md_fields['Run']) + self.md.populate_run_props(self.md_fields['Run']) self.md.run[1].comps_rec = 'Hx, Hy, Hz' with self.assertLogs(logger, level='WARNING') as cmd: self.md.get_comps_rec(type_, run_id) @@ -339,7 +339,7 @@ class TestLemiMetadata(unittest.TestCase): """Test basic functionality of get_comps_rec.""" type_ = 'E' run_id = 'a' - self.md.populate_run_md_props(self.md_fields['Run']) + self.md.populate_run_props(self.md_fields['Run']) comps = self.md.get_comps_rec(type_, run_id) self.assertEqual(comps, ['E1', 'E2', 'E3', 'E4']) @@ -348,7 +348,7 @@ class TestLemiMetadata(unittest.TestCase): type_ = 'H' cha_type = 'magnetic field' run_id = 'b' - self.md.populate_run_md_props(self.md_fields['Run']) + self.md.populate_run_props(self.md_fields['Run']) self.md.run[1].comps_rec = 'Hx, Hy' with self.assertLogs(logger, level='WARNING') as cmd: self.md.get_comps_rec(type_, run_id) @@ -362,7 +362,7 @@ class TestLemiMetadata(unittest.TestCase): """Test basic functionality of get_comps_rec.""" type_ = 'H' run_id = 'a' - self.md.populate_run_md_props(self.md_fields['Run']) + self.md.populate_run_props(self.md_fields['Run']) comps = self.md.get_comps_rec(type_, run_id) self.assertEqual(comps, ['Hx', 'Hy', 'Hz']) @@ -370,7 +370,7 @@ class TestLemiMetadata(unittest.TestCase): """Test basic functionality of match_num_e_pairs.""" comps = ['E1', 'E2', 'E3', 'E4'] run_id = 'a' - self.md.populate_md_props(self.md_fields) + self.md.populate_props(self.md_fields) with self.assertLogs(logger, level='ERROR') as cmd: self.md.match_num_e_pairs(comps, run_id, 2) msg = (f"Invalid number of electrode pairs (run '{run_id}')! The " @@ -388,7 +388,7 @@ class TestLemiMetadata(unittest.TestCase): """Test basic functionality of match_comps_rec.""" comps = ['E1', 'E2'] run_id = 'a' - self.md.populate_md_props(self.md_fields) + self.md.populate_props(self.md_fields) with self.assertLogs(logger, level='ERROR') as cmd: self.md.match_comps_rec(self.md.elec, comps, run_id) msg = (f"Invalid electric channel numbers (run '{run_id}')! The " @@ -400,14 +400,14 @@ class TestLemiMetadata(unittest.TestCase): def test_update_cha_num(self): """Test basic functionality of update_cha_num.""" - cha = self.md.init_cha_md_props('elec', 'a') + cha = self.md.init_cha_props('elec', 'a') self.assertIsNone(cha.cha_num) updated_cha = LemiMetadata.update_cha_num(cha, 'E1') self.assertEqual(updated_cha.cha_num, 'E1') def test_update_comp_cha_name(self): """Test basic functionality of update_comp_cha_name.""" - cha = self.md.init_cha_md_props('mag', 'a') + cha = self.md.init_cha_props('mag', 'a') self.assertIsNone(cha.cha_name) self.assertIsNone(cha.comp) updated_cha = LemiMetadata.update_comp_cha_name(cha, 'Hx') @@ -417,12 +417,12 @@ class TestLemiMetadata(unittest.TestCase): def test_get_e_infos(self): """Test basic functionality of get_e_infos.""" comps = ['Ex', 'Ey', 'Ex', 'Ey', 'Ex', 'Ey'] - self.md.populate_run_md_props(self.md_fields['Run']) + self.md.populate_run_props(self.md_fields['Run']) self.md.run[1].comps_rec = 'E1, E2, Hx, Hy, Hz' - cha = self.md.init_cha_md_props('elec', 'a') + cha = self.md.init_cha_props('elec', 'a') self.md.elec.extend([self.md.update_cha_num(cha, f'E{i+1}') for i in range(4)]) - cha = self.md.init_cha_md_props('elec', 'b') + cha = self.md.init_cha_props('elec', 'b') self.md.elec.extend([self.md.update_cha_num(cha, f'E{i+1}') for i in range(2)]) for ind, elec in enumerate(self.md.elec): @@ -436,8 +436,8 @@ class TestLemiMetadata(unittest.TestCase): """Test basic functionality of update_location.""" comps = ['Ex', 'Ey', 'Ex', 'Ey'] location_codes = ['00', '00', '01', '01'] - self.md.populate_run_md_props(self.md_fields['Run']) - cha = self.md.init_cha_md_props('elec', 'a') + self.md.populate_run_props(self.md_fields['Run']) + cha = self.md.init_cha_props('elec', 'a') self.md.elec.extend([self.md.update_cha_num(cha, f'E{i+1}') for i in range(4)]) for ind, elec in enumerate(self.md.elec): elec.comp = comps[ind] @@ -461,7 +461,7 @@ class TestLemiMetadata(unittest.TestCase): def test_dc2dict(self): """Test basic functionality of dc2dict.""" - cha = self.md.init_cha_md_props('elec', 'a') + cha = self.md.init_cha_props('elec', 'a') self.assertDictEqual(self.md.dc2dict(cha), {'elev': 2201.725, 'lat': 34.048, @@ -493,7 +493,7 @@ class TestLemiMetadata(unittest.TestCase): def test_for_gui_md_populated(self): """Test basic functionality of for_gui.""" - self.md.populate_md_props(self.md_fields) + self.md.populate_props(self.md_fields) file_ = self.path2md.joinpath('gui_metadata_populated.pkl') with open(file_, 'rb') as fin: expected = pickle.load(fin) @@ -519,7 +519,7 @@ class TestLemiMetadata(unittest.TestCase): def test_update_azimuth_tilt(self): """Test basic functionality of update_azimuth_tilt.""" - self.md.populate_md_props(self.md_fields) + self.md.populate_props(self.md_fields) self.md.update_azimuth_tilt() for cha in self.md.filter_cha('mag', 'a'): if cha.comp == 'Hx':