-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
""" | ||
This is a test to confirm that mth5's decimation method returns the same default values as aurora's prototype decimate. | ||
TODO: add tests from aurora issue #363 in this module | ||
""" | ||
|
||
from aurora.pipelines.time_series_helpers import prototype_decimate | ||
from aurora.test_utils.synthetic.make_processing_configs import ( | ||
create_test_run_config, | ||
) | ||
from loguru import logger | ||
from mth5.data.make_mth5_from_asc import create_test1_h5 | ||
from mth5.mth5 import MTH5 | ||
from mth5.helpers import close_open_files | ||
from mtpy.processing import RunSummary, KernelDataset # mtpy-v2 | ||
|
||
import numpy as np | ||
|
||
|
||
def test_decimation_methods_agree(): | ||
""" | ||
Get some synthetic time series and check that the decimation results are | ||
equal to calling the mth5 built-in run_xrts.sps_filters.decimate. | ||
TODO: More testing could be added for downsamplings that are not integer factors. | ||
""" | ||
close_open_files() | ||
mth5_path = create_test1_h5() | ||
mth5_paths = [ | ||
mth5_path, | ||
] | ||
|
||
run_summary = RunSummary() | ||
run_summary.from_mth5s(mth5_paths) | ||
tfk_dataset = KernelDataset() | ||
station_id = "test1" | ||
run_id = "001" | ||
tfk_dataset.from_run_summary(run_summary, station_id) | ||
|
||
processing_config = create_test_run_config(station_id, tfk_dataset) | ||
|
||
mth5_obj = MTH5(file_version="0.1.0") | ||
mth5_obj.open_mth5(mth5_path, mode="a") | ||
decimated_ts = {} | ||
|
||
for dec_level_id, dec_config in enumerate(processing_config.decimations): | ||
decimated_ts[dec_level_id] = {} | ||
if dec_level_id == 0: | ||
run_obj = mth5_obj.get_run(station_id, run_id, survey=None) | ||
run_ts = run_obj.to_runts(start=None, end=None) | ||
run_xrts = run_ts.dataset | ||
decimated_ts[dec_level_id]["run_xrts"] = run_xrts | ||
current_sample_rate = run_obj.metadata.sample_rate | ||
|
||
if dec_level_id > 0: | ||
run_xrts = decimated_ts[dec_level_id - 1]["run_xrts"] | ||
target_sample_rate = current_sample_rate / (dec_config.decimation.factor) | ||
|
||
decimated_1 = prototype_decimate(dec_config.decimation, run_xrts) | ||
decimated_2 = run_xrts.sps_filters.decimate( | ||
target_sample_rate=target_sample_rate | ||
) | ||
|
||
difference = decimated_2 - decimated_1 | ||
logger.info(len(difference.time)) | ||
assert np.isclose(difference.to_array(), 0).all() | ||
|
||
logger.info("prototype decimate aurora method agrees with mth5 decimate") | ||
decimated_ts[dec_level_id]["run_xrts"] = decimated_1 | ||
current_sample_rate = target_sample_rate | ||
return | ||
|
||
|
||
def main(): | ||
test_decimation_methods_agree() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |