Skip to content

Commit

Permalink
Add a test to test_fourier_coefficients
Browse files Browse the repository at this point in the history
- Now checking that the FCs are detected by TFK after build
  • Loading branch information
kkappler committed Oct 5, 2024
1 parent a00d733 commit 66f6905
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
23 changes: 18 additions & 5 deletions aurora/test_utils/synthetic/make_processing_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
synthetic_test_paths = SyntheticTestPaths()
CONFIG_PATH = synthetic_test_paths.config_path
MTH5_PATH = synthetic_test_paths.mth5_path
SUPPORTED_TEST_CASE_IDS = [
"test1",
"test2",
"test1r2",
"test2r1",
"test1_tfk",
"test1r2_tfk",
]


def create_test_run_config(
Expand All @@ -30,7 +38,7 @@ def create_test_run_config(
Parameters
----------
test_case_id: string
Must be in ["test1", "test2", "test1r2", "test2r1", "test1_tfk", "test1r2_tfk"]
Must be in SUPPORTED_TEST_CASE_IDS
kernel_dataset: aurora.transfer_function.kernel_dataset.KernelDataset
Description of the dataset to process
matlab_or_fortran: str
Expand Down Expand Up @@ -126,6 +134,8 @@ def create_test_run_config(
decimation.window.num_samples = num_samples_window
decimation.window.overlap = num_samples_overlap
decimation.regression.max_redescending_iterations = 2
if test_case_id == "test2":
decimation.window.type = "boxcar"

if save == "json":
filename = CONFIG_PATH.joinpath(p.json_fn())
Expand All @@ -149,10 +159,13 @@ def make_processing_config_and_kernel_dataset(
Parameters
----------
station_id
remote_id
mth5s
channel_nomenclature
config_keyword: str
Must be in SUPPORTED_TEST_CASE_IDS
station_id: str
The name of the station to proces
remote_id: str
mth5s: Union[list, tuple]
channel_nomenclature: Optional[str]
Returns
-------
Expand Down
24 changes: 24 additions & 0 deletions tests/synthetic/test_fourier_coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def setUpClass(self):
mth5_path_3,
mth5_path_12rr,
]
self.mth5_path_2 = mth5_path_2

def test_123(self):
"""
Expand Down Expand Up @@ -138,12 +139,35 @@ def test_fc_decimations_creator(self):
def test_create_then_use_stored_fcs_for_processing(self):
""""""
from test_processing import process_synthetic_2
from aurora.test_utils.synthetic.make_processing_configs import (
make_processing_config_and_kernel_dataset,
)
from aurora.pipelines.transfer_function_kernel import TransferFunctionKernel

z_file_path_1 = AURORA_RESULTS_PATH.joinpath("test2.zss")
z_file_path_2 = AURORA_RESULTS_PATH.joinpath("test2_from_stored_fc.zss")
tf1 = process_synthetic_2(
force_make_mth5=True, z_file_path=z_file_path_1, save_fc=True
)
tfk_dataset, processing_config = make_processing_config_and_kernel_dataset(
config_keyword="test2",
station_id="test2",
remote_id=None,
mth5s=[
self.mth5_path_2,
],
channel_nomenclature="default",
)

# Intialize a TF kernel to check for FCs
tfk = TransferFunctionKernel(dataset=tfk_dataset, config=processing_config)
tfk.make_processing_summary()
tfk.check_if_fcs_already_exist()
assert (
tfk.dataset_df.fc.all()
) # assert fcs True in dataframe -- i.e. they were detected.

# Now reprocess with the FCs
tf2 = process_synthetic_2(force_make_mth5=False, z_file_path=z_file_path_2)
assert tf1 == tf2

Expand Down
5 changes: 2 additions & 3 deletions tests/synthetic/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,8 @@ def process_synthetic_2(
for decimation_level in processing_config.decimations:
if save_fc:
decimation_level.save_fcs = True
decimation_level.save_fcs_type = "h5"
decimation_level.window.type = "boxcar"
# decimation_level.save_fcs_type = "csv"
decimation_level.save_fcs_type = "h5" # h5 instead of "csv"

tfc = process_mth5(
processing_config,
tfk_dataset=tfk_dataset,
Expand Down

0 comments on commit 66f6905

Please sign in to comment.