|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | +Created on Thu Aug 15 16:09:12 2024 |
| 4 | +
|
| 5 | +@author: jpeacock |
| 6 | +""" |
| 7 | +# ============================================================================= |
| 8 | +# Imports |
| 9 | +# ============================================================================= |
| 10 | +import unittest |
| 11 | + |
| 12 | +from mth5.data.make_mth5_from_asc import MTH5_PATH, create_test12rr_h5 |
| 13 | +from mth5.utils.helpers import close_open_files |
| 14 | +from mth5.mth5 import MTH5 |
| 15 | + |
| 16 | +from mtpy.processing.run_summary import RunSummary |
| 17 | +from mtpy.processing.kernel_dataset import KernelDataset |
| 18 | +from mtpy import MT |
| 19 | + |
| 20 | +from aurora.config.config_creator import ConfigCreator |
| 21 | +from aurora.pipelines.process_mth5 import process_mth5 |
| 22 | +from mtpy.processing.aurora.process_aurora import AuroraProcessing |
| 23 | + |
| 24 | + |
| 25 | +# ============================================================================= |
| 26 | +class TestProcessSingleStationCompare(unittest.TestCase): |
| 27 | + @classmethod |
| 28 | + def setUpClass(self): |
| 29 | + self.mth5_path = MTH5_PATH.joinpath("test12rr.h5") |
| 30 | + if not self.mth5_path.exists(): |
| 31 | + self.mth5_path = create_test12rr_h5() |
| 32 | + |
| 33 | + # process with mtpy |
| 34 | + self.ap = AuroraProcessing() |
| 35 | + self.ap.local_station_id = "test1" |
| 36 | + self.ap.local_mth5_path = self.mth5_path |
| 37 | + self.processed = self.ap.process( |
| 38 | + sample_rates=1, merge=True, save_to_mth5=True |
| 39 | + ) |
| 40 | + self.mt_obj_new = self.processed[1]["tf"] |
| 41 | + |
| 42 | + # process with aurora infrastructure |
| 43 | + self.run_summary = RunSummary() |
| 44 | + self.run_summary.from_mth5s([self.mth5_path]) |
| 45 | + self.kernel_dataset = KernelDataset() |
| 46 | + self.kernel_dataset.from_run_summary(self.run_summary, "test1") |
| 47 | + cc = ConfigCreator() |
| 48 | + self.config = cc.create_from_kernel_dataset(self.kernel_dataset) |
| 49 | + ## need to set same config parameters |
| 50 | + self.ap._set_decimation_level_parameters( |
| 51 | + self.config, |
| 52 | + **self.ap.default_window_parameters["low"], |
| 53 | + ) |
| 54 | + |
| 55 | + self.tf_obj = process_mth5(self.config, self.kernel_dataset) |
| 56 | + self.tf_obj.tf_id = self.kernel_dataset.processing_id |
| 57 | + self.tf_obj.station_metadata.transfer_function.runs_processed = ( |
| 58 | + self.tf_obj.station_metadata.run_list |
| 59 | + ) |
| 60 | + self.mt_obj_legacy = MT(survey_metadata=self.tf_obj.survey_metadata) |
| 61 | + self.mt_obj_legacy._transfer_function = self.tf_obj._transfer_function |
| 62 | + |
| 63 | + self.mt_obj_legacy.survey_metadata.id = ( |
| 64 | + self.mt_obj_new.survey_metadata.id |
| 65 | + ) |
| 66 | + |
| 67 | + def test_tfs_equal(self): |
| 68 | + self.assertEqual(self.mt_obj_new, self.mt_obj_legacy) |
| 69 | + |
| 70 | + def test_tf_id(self): |
| 71 | + self.assertEqual(self.mt_obj_new.tf_id, self.ap.processing_id) |
| 72 | + |
| 73 | + def test_tf_in_mth5(self): |
| 74 | + with MTH5() as m: |
| 75 | + m.open_mth5(self.mth5_path) |
| 76 | + tf_df = m.tf_summary.to_dataframe() |
| 77 | + with self.subTest("station is in tf_summary"): |
| 78 | + self.assertIn("test1", tf_df.station.tolist()) |
| 79 | + with self.subTest("tf's are equal"): |
| 80 | + tf = m.get_transfer_function("test1", "test1_sr1") |
| 81 | + self.assertEqual(self.tf_obj, tf) |
| 82 | + |
| 83 | + def test_processed_dict(self): |
| 84 | + self.assertTrue(self.processed[1]["processed"]) |
| 85 | + |
| 86 | + @classmethod |
| 87 | + def tearDownClass(self): |
| 88 | + close_open_files() |
| 89 | + |
| 90 | + |
| 91 | +# ============================================================================= |
| 92 | +# run |
| 93 | +# ============================================================================= |
| 94 | +if __name__ in "__main__": |
| 95 | + unittest.main() |
0 commit comments