From 6def1bf6e6a20a4c3f50652002f23eb5f53fc1c2 Mon Sep 17 00:00:00 2001 From: Geoffrey Woollard Date: Tue, 10 Sep 2024 21:15:21 -0400 Subject: [PATCH] tests for masking and normalization --- ..._to_map_low_memory_nomask_nonormalize.yaml | 27 +++++++++ ..._config_map_to_map_nomask_nonormalize.yaml | 27 +++++++++ tests/test_map_to_map.py | 56 ++++++++++--------- 3 files changed, 85 insertions(+), 25 deletions(-) create mode 100644 tests/config_files/test_config_map_to_map_low_memory_nomask_nonormalize.yaml create mode 100644 tests/config_files/test_config_map_to_map_nomask_nonormalize.yaml diff --git a/tests/config_files/test_config_map_to_map_low_memory_nomask_nonormalize.yaml b/tests/config_files/test_config_map_to_map_low_memory_nomask_nonormalize.yaml new file mode 100644 index 0000000..13a1cf4 --- /dev/null +++ b/tests/config_files/test_config_map_to_map_low_memory_nomask_nonormalize.yaml @@ -0,0 +1,27 @@ +data: + n_pix: 16 + psize: 30.044 + submission: + fname: tests/data/dataset_2_submissions/submission_1000.pt + volume_key: volumes + metadata_key: populations + label_key: id + ground_truth: + volumes: tests/data/Ground_truth/test_maps_gt_flat_10.npy + metadata: tests/data/Ground_truth/test_metadata_10.csv + mask: + do: false + volume: tests/data/Ground_truth/test_mask_dilated_wide.mrc +analysis: + metrics: + - l2_low_memory + - corr_low_memory + - bioem_low_memory + - fsc_low_memory + - res_low_memory + chunk_size_submission: 80 + chunk_size_gt: 190 + normalize: + do: false + method: median_zscore +output: tests/results/test_map_to_map_distance_matrix_submission_0.pkl diff --git a/tests/config_files/test_config_map_to_map_nomask_nonormalize.yaml b/tests/config_files/test_config_map_to_map_nomask_nonormalize.yaml new file mode 100644 index 0000000..7856db4 --- /dev/null +++ b/tests/config_files/test_config_map_to_map_nomask_nonormalize.yaml @@ -0,0 +1,27 @@ +data: + n_pix: 16 + psize: 30.044 + submission: + fname: tests/data/dataset_2_submissions/submission_1000.pt + volume_key: volumes + metadata_key: populations + label_key: id + ground_truth: + volumes: tests/data/Ground_truth/test_maps_gt_flat_10.pt + metadata: tests/data/Ground_truth/test_metadata_10.csv + mask: + do: false + volume: tests/data/Ground_truth/test_mask_dilated_wide.mrc +analysis: + metrics: + - l2 + - corr + - bioem + - fsc + - res + chunk_size_submission: 80 + chunk_size_gt: 190 + normalize: + do: false + method: median_zscore +output: tests/results/test_map_to_map_distance_matrix_submission_0.pkl diff --git a/tests/test_map_to_map.py b/tests/test_map_to_map.py index ed91815..957a9b1 100644 --- a/tests/test_map_to_map.py +++ b/tests/test_map_to_map.py @@ -4,31 +4,37 @@ def test_run_map2map_pipeline(): - args = OmegaConf.create( - {"config": "tests/config_files/test_config_map_to_map.yaml"} - ) - results_dict = run_map2map_pipeline.main(args) + for config_fname, config_fname_low_memory in zip( + [ + "tests/config_files/test_config_map_to_map.yaml", + "tests/config_files/test_config_map_to_map.yaml", + ], + [ + "tests/config_files/test_config_map_to_map_low_memory.yaml", + "tests/config_files/test_config_map_to_map_low_memory.yaml", + ], + ): + args = OmegaConf.create({"config": config_fname}) + results_dict = run_map2map_pipeline.main(args) - args_low_memory = OmegaConf.create( - {"config": "tests/config_files/test_config_map_to_map_low_memory.yaml"} - ) - results_dict_low_memory = run_map2map_pipeline.main(args_low_memory) - for metric in ["fsc", "corr", "l2", "bioem"]: - if metric == "fsc": + args_low_memory = OmegaConf.create({"config": config_fname_low_memory}) + results_dict_low_memory = run_map2map_pipeline.main(args_low_memory) + for metric in ["fsc", "corr", "l2", "bioem"]: + if metric == "fsc": + np.allclose( + results_dict[metric]["computed_assets"]["fsc_matrix"], + results_dict_low_memory[metric + "_low_memory"]["computed_assets"][ + "fsc_matrix" + ], + ) + elif metric == "res": + np.allclose( + results_dict[metric]["computed_assets"]["fraction_nyquist"], + results_dict_low_memory[metric + "_low_memory"]["computed_assets"][ + "fraction_nyquist" + ], + ) np.allclose( - results_dict[metric]["computed_assets"]["fsc_matrix"], - results_dict_low_memory[metric + "_low_memory"]["computed_assets"][ - "fsc_matrix" - ], + results_dict[metric]["cost_matrix"].values, + results_dict_low_memory[metric + "_low_memory"]["cost_matrix"].values, ) - elif metric == "res": - np.allclose( - results_dict[metric]["computed_assets"]["fraction_nyquist"], - results_dict_low_memory[metric + "_low_memory"]["computed_assets"][ - "fraction_nyquist" - ], - ) - np.allclose( - results_dict[metric]["cost_matrix"].values, - results_dict_low_memory[metric + "_low_memory"]["cost_matrix"].values, - )