-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from wtbarnes/test-refactoring
- Loading branch information
Showing
9 changed files
with
144 additions
and
267 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
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 |
---|---|---|
@@ -1,61 +1,34 @@ | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
import pytest | ||
from astropy.utils.data import get_pkg_data_path | ||
from sunpy.map import Map | ||
|
||
from xrtpy.image_correction.remove_lightleak import remove_lightleak | ||
|
||
|
||
def get_IDL_data_file(): | ||
""" | ||
The XRT composite fits file that been lightleak corrected in | ||
IDL have been rename to begin with "ll" referring to lightleak. | ||
""" | ||
directory = ( | ||
Path(__file__).parent.absolute() | ||
/ "data" | ||
/ "light_leak_testing_data_files" | ||
/ "IDL_lightleak_corrected_data_test_files" | ||
data_dir = Path( | ||
get_pkg_data_path( | ||
"data/light_leak_testing_data_files", package="xrtpy.image_correction.tests" | ||
) | ||
data_files = directory.glob("ll_comp_XRT*.fits") | ||
return sorted(data_files) | ||
|
||
|
||
IDL_filenames = get_IDL_data_file() | ||
|
||
|
||
def get_composite_data_files(): | ||
""" | ||
The XRT composite fits file are no corrected in IDL. | ||
These files will be corrected using XRTpy. | ||
""" | ||
directory = ( | ||
Path(__file__).parent.absolute() | ||
/ "data" | ||
/ "light_leak_testing_data_files" | ||
/ "xrtpy_lightleak_data_test_files" | ||
) | ||
data_file = directory.glob("comp_XRT*.fits") | ||
return sorted(data_file) | ||
|
||
|
||
composite_filenames = get_composite_data_files() | ||
|
||
# Using zip as an iterator to pair the data files together. Trouble-free method to use in pytest-parametrize | ||
data_files = list(zip(IDL_filenames, composite_filenames, strict=False)) | ||
|
||
|
||
@pytest.mark.parametrize(("idlfile", "compfile"), data_files) | ||
def test_lightleak(idlfile, compfile, allclose): | ||
) | ||
composite_filenames = sorted( | ||
(data_dir / "xrtpy_lightleak_data_test_files").glob("comp_XRT*.fits") | ||
) | ||
IDL_filenames = sorted( | ||
(data_dir / "IDL_lightleak_corrected_data_test_files").glob("ll_comp_XRT*.fits") | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("idlfile", "compfile"), list(zip(IDL_filenames, composite_filenames, strict=True)) | ||
) | ||
def test_lightleak(idlfile, compfile): | ||
IDL_map = Map(idlfile) | ||
input_map = Map(compfile) | ||
|
||
ll_removed_map_xrtpy = remove_lightleak(input_map) | ||
|
||
if input_map.data.shape == (2048, 2048): | ||
# Because of rebinning for full resolution images, the match is worse | ||
# between IDL created images and XRTpy ones. IDL's method of rebinning | ||
# is different from that used by sunpy. | ||
assert allclose(ll_removed_map_xrtpy.data, IDL_map.data, atol=0.75) | ||
else: | ||
assert allclose(ll_removed_map_xrtpy.data, IDL_map.data, atol=1e-5) | ||
# Because of rebinning for full resolution images, the match is worse | ||
# between IDL created images and XRTpy ones. IDL's method of rebinning | ||
# is different from that used by sunpy. | ||
atol = 0.75 if input_map.data.shape == (2048, 2048) else 1e-5 | ||
assert np.allclose(ll_removed_map_xrtpy.data, IDL_map.data, atol=atol) |
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
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
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
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
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
Oops, something went wrong.