|
5 | 5 | import astropy.units as u |
6 | 6 | from astropy.coordinates import SkyCoord |
7 | 7 | from astropy.io import fits |
| 8 | +from astropy.tests.helper import assert_quantity_allclose |
8 | 9 |
|
9 | 10 | import sunpy.map |
| 11 | +from sunpy.map.maputils import all_coordinates_from_map, coordinate_is_on_solar_disk |
10 | 12 | from sunpy.util.exceptions import SunpyUserWarning |
11 | 13 |
|
12 | 14 | from sunkit_image.coalignment import coalign |
@@ -70,50 +72,63 @@ def test_coalignment_eis_aia(eis_test_map, aia193_test_map): |
70 | 72 | aia193_test_downsampled_map = aia193_test_map.resample(u.Quantity([nx, ny])) |
71 | 73 | coaligned_eis_map = coalign(eis_test_map, aia193_test_downsampled_map, method='match_template') |
72 | 74 | # Check that correction is as expected based on known pointing offset |
73 | | - assert u.allclose( |
| 75 | + assert_quantity_allclose( |
74 | 76 | eis_test_map.reference_coordinate.separation(coaligned_eis_map.reference_coordinate), |
75 | 77 | 5.95935177*u.arcsec, |
76 | 78 | ) |
77 | 79 |
|
78 | 80 |
|
79 | 81 | def test_coalignment_match_template_full_map(incorrect_pointing_map_and_shift, aia171_test_map): |
80 | 82 | incorrect_pointing_map, pointing_shift = incorrect_pointing_map_and_shift |
81 | | - fixed_map = coalign(incorrect_pointing_map, aia171_test_map) |
| 83 | + # Crop out the array that is outside the solar disk to have something to align to |
| 84 | + hpc_coords = all_coordinates_from_map(incorrect_pointing_map) |
| 85 | + mask = coordinate_is_on_solar_disk(hpc_coords) |
| 86 | + masked_map = sunpy.map.Map(np.abs(incorrect_pointing_map.data*mask), incorrect_pointing_map.meta) |
| 87 | + # We have to pad the input map because otherwise match_template cannot find a good match |
| 88 | + fixed_map = coalign(masked_map, aia171_test_map, pad_input=True) |
82 | 89 | # The actual shifts applied by coalignment should be equal to the expected shifts |
83 | | - u.allclose( |
84 | | - np.fabs(incorrect_pointing_map.reference_coordinate.Tx-fixed_map.reference_coordinate.Tx), |
| 90 | + assert_quantity_allclose( |
| 91 | + (incorrect_pointing_map.reference_coordinate.Tx-fixed_map.reference_coordinate.Tx), |
85 | 92 | pointing_shift[0], |
| 93 | + # Not as precise for full map |
| 94 | + atol=0.6*u.arcsec, |
86 | 95 | ) |
87 | | - u.allclose( |
88 | | - np.fabs(incorrect_pointing_map.reference_coordinate.Ty-fixed_map.reference_coordinate.Ty), |
| 96 | + assert_quantity_allclose( |
| 97 | + (incorrect_pointing_map.reference_coordinate.Ty-fixed_map.reference_coordinate.Ty), |
89 | 98 | pointing_shift[1], |
| 99 | + # Not as precise for full map |
| 100 | + atol=0.6*u.arcsec, |
90 | 101 | ) |
91 | 102 |
|
92 | 103 |
|
93 | 104 | def test_coalignment_match_template_cutout(incorrect_pointing_cutout_map_and_shift, aia171_test_map): |
94 | 105 | incorrect_pointing_cutout_map, pointing_shift = incorrect_pointing_cutout_map_and_shift |
95 | 106 | fixed_cutout_map = coalign(incorrect_pointing_cutout_map, aia171_test_map) |
96 | 107 | # The actual shifts applied by coalignment should be equal to the expected shifts |
97 | | - u.allclose( |
98 | | - np.fabs(incorrect_pointing_cutout_map.reference_coordinate.Tx-fixed_cutout_map.reference_coordinate.Tx), |
| 108 | + assert_quantity_allclose( |
| 109 | + (incorrect_pointing_cutout_map.reference_coordinate.Tx-fixed_cutout_map.reference_coordinate.Tx), |
99 | 110 | pointing_shift[0], |
| 111 | + # For example, a shift is 25 arcsec but the returned shift is 24.9 arcsec |
| 112 | + atol=0.1*u.arcsec, |
100 | 113 | ) |
101 | | - u.allclose( |
102 | | - np.fabs(incorrect_pointing_cutout_map.reference_coordinate.Ty-fixed_cutout_map.reference_coordinate.Ty), |
| 114 | + assert_quantity_allclose( |
| 115 | + (incorrect_pointing_cutout_map.reference_coordinate.Ty-fixed_cutout_map.reference_coordinate.Ty), |
103 | 116 | pointing_shift[1], |
| 117 | + # For example, a shift is 25 arcsec but the returned shift is 24.9 arcsec |
| 118 | + atol=0.1*u.arcsec, |
104 | 119 | ) |
105 | 120 |
|
106 | 121 |
|
107 | 122 | def test_coalign_phase_cross_correlation(incorrect_pointing_map_and_shift, aia171_test_map): |
108 | 123 | incorrect_pointing_map, pointing_shift = incorrect_pointing_map_and_shift |
109 | 124 | fixed_map = coalign(incorrect_pointing_map, aia171_test_map, method='phase_cross_correlation') |
110 | 125 | # The actual shifts applied by coalignment should be equal to the expected shifts |
111 | | - u.allclose( |
112 | | - np.fabs(incorrect_pointing_map.reference_coordinate.Tx-fixed_map.reference_coordinate.Tx), |
| 126 | + assert_quantity_allclose( |
| 127 | + (incorrect_pointing_map.reference_coordinate.Tx-fixed_map.reference_coordinate.Tx), |
113 | 128 | pointing_shift[0], |
114 | 129 | ) |
115 | | - u.allclose( |
116 | | - np.fabs(incorrect_pointing_map.reference_coordinate.Ty-fixed_map.reference_coordinate.Ty), |
| 130 | + assert_quantity_allclose( |
| 131 | + (incorrect_pointing_map.reference_coordinate.Ty-fixed_map.reference_coordinate.Ty), |
117 | 132 | pointing_shift[1], |
118 | 133 | ) |
119 | 134 |
|
@@ -158,10 +173,10 @@ def test_warnings_coalign(incorrect_shifted_once_map, aia171_test_map): |
158 | 173 | time_shift_meta = incorrect_shifted_once_map.meta.copy() |
159 | 174 | time_shift_meta['DATE-OBS'] = '2014-01-08T09:57:30.84' |
160 | 175 | time_shift = sunpy.map.Map(incorrect_shifted_once_map.data, time_shift_meta) |
161 | | - with pytest.warns(SunpyUserWarning, match=r"The time difference between the reference and target maps in time is large."): |
162 | | - with pytest.raises(ValueError, match=r"attempt to get argmax of an empty sequence"): |
| 176 | + with pytest.warns(SunpyUserWarning, match=r"The difference in observation times of the reference and target maps is large."): |
| 177 | + with pytest.raises(ValueError, match=r"match_template returned an array with fewer than two values,"): |
163 | 178 | coalign(time_shift, aia171_test_map) |
164 | 179 |
|
165 | 180 | resampled_map = incorrect_shifted_once_map.resample([100,100]*u.pix) |
166 | | - with pytest.warns(SunpyUserWarning, match=r"There is a plate scale difference between the reference and target maps."): |
| 181 | + with pytest.warns(SunpyUserWarning, match=r"The reference and target maps have different plate scales."): |
167 | 182 | coalign(resampled_map, aia171_test_map) |
0 commit comments