Skip to content

Commit 536758e

Browse files
committed
Tweaks from Nabil
1 parent b910153 commit 536758e

File tree

11 files changed

+50
-67
lines changed

11 files changed

+50
-67
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: "v0.13.3"
3+
rev: "v0.14.0"
44
hooks:
55
- id: ruff
66
args: ["--fix", "--unsafe-fixes"]
@@ -30,8 +30,8 @@ repos:
3030
hooks:
3131
- id: codespell
3232
args: [ "--write-changes" ]
33-
- repo: https://github.com/crate-ci/typos
34-
rev: v1
33+
- repo: https://github.com/adhtruong/mirrors-typos
34+
rev: v1.38.0
3535
hooks:
3636
- id: typos
3737
- repo: https://github.com/pre-commit/mirrors-mypy

changelog/290.breaking.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Increased the minimum required versions:
55
- sunpy 7.0.0 (from 6.0.0)
66
- NumPy 1.26.0 (from 1.23.5)
77
- Astropy 6.1.0 (from 5.3.0)
8-
- SciPy 1.11.0 (from 1.10.1)
8+
- SciPy 1.12.0 (from 1.10.1)

docs/code_ref/coalignment.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The module supports various transformation methods registered via the `~sunkit_i
1111
.. automodapi:: sunkit_image.coalignment
1212

1313
.. automodapi:: sunkit_image.coalignment.interface
14+
:skip: coalign
1415

1516
.. automodapi:: sunkit_image.coalignment.match_template
1617

examples/aligning_aia_with_eis_maps.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,19 @@
66
This example shows how to coalign EIS rasters to AIA images in order correct for the pointing
77
uncertainty in EIS.
88
"""
9-
# sphinx_gallery_thumbnail_number = 2
10-
11-
129
import matplotlib.pyplot as plt
1310

1411
import astropy.units as u
1512
from astropy.visualization import AsinhStretch, ImageNormalize
1613

1714
import sunpy.map
18-
from sunpy.net import Fido
19-
from sunpy.net import attrs as a
2015

2116
from sunkit_image.coalignment import coalign
2217

2318
###################################################################################
2419
# For this example, we will use a preprocessed EIS raster image of the Fe XII
25-
# 195.119 Å line. This raster image was prepared using the `eispac <https://eispac.readthedocs.io/en/latest/>`_ package.
26-
20+
# 195.119 Å line.
21+
# This raster image was prepared using the `eispac <https://eispac.readthedocs.io/en/latest/>`__ package.
2722

2823
eis_map = sunpy.map.Map("https://github.com/sunpy/data/raw/main/sunkit-image/eis_20140108_095727.fe_12_195_119.2c-0.int.fits")
2924

@@ -33,13 +28,17 @@
3328
# 193 Å channel of AIA as it sees plasma at approximately the same temperature as
3429
# the 195.119 Å line in our EIS raster.
3530

36-
query = Fido.search(
37-
a.Time(start=eis_map.date-1*u.minute, near=eis_map.date, end=eis_map.date+1*u.minute),
38-
a.Instrument.aia,
39-
a.Wavelength(193*u.angstrom)
40-
)
41-
aia_file = Fido.fetch(query, site='NSO')
42-
aia_map = sunpy.map.Map(aia_file)
31+
# Below is the Fido query to search and download the AIA data.
32+
# from sunpy.net import Fido
33+
# from sunpy.net import attrs as a
34+
# query = Fido.search(
35+
# a.Time(start=eis_map.date-1*u.minute, near=eis_map.date, end=eis_map.date+1*u.minute),
36+
# a.Instrument.aia,
37+
# a.Wavelength(193*u.angstrom)
38+
# )
39+
# aia_file = Fido.fetch(query, site='NSO')
40+
# For now though we have stored this file on Github so we can download it directly.
41+
aia_map = sunpy.map.Map("https://github.com/sunpy/data/raw/refs/heads/main/sunkit-image/aia.lev1.193A_2014_01_08T09_57_30.84Z.image_lev1.fits")
4342

4443
####################################################################################
4544
# Before coaligning the images, we first resample the AIA image to the same plate

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies = [
3434
"astropy>=6.1.0",
3535
"numpy>=1.26.0",
3636
"matplotlib>=3.8.0",
37-
"scipy>=1.11.0",
37+
"scipy>=1.12.0",
3838
"scikit-image>=0.20.0",
3939
"sunpy[map]>=7.0.0",
4040
]
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Need to register the the coalignment functions
2-
import sunkit_image.coalignment.match_template
3-
import sunkit_image.coalignment.phase_cross_correlation
2+
from sunkit_image.coalignment.match_template import match_template_coalign # isort:skip
3+
from sunkit_image.coalignment.phase_cross_correlation import phase_cross_correlation_coalign # isort:skip
4+
45
from sunkit_image.coalignment.interface import coalign
56

67
__all__ = ["coalign"]

sunkit_image/coalignment/interface.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ def _update_fits_wcs_metadata(target_map, reference_map, affine_params):
9191
new_reference_coordinate.Tx - target_map.reference_coordinate.Tx,
9292
new_reference_coordinate.Ty - target_map.reference_coordinate.Ty,
9393
)
94-
# TODO: Support metadata updates to PCij/CDij and CDELT for non-unity scaling and
95-
# rotation in the affine transform
9694

9795

9896
def _warn_user_of_separation(target_map, reference_map):
@@ -199,4 +197,4 @@ def coalign(target_map, reference_map, method='match_template', **kwargs):
199197
_coalignment_function_names = ", ".join([f"``'{name}'``" for name in REGISTERED_METHODS])
200198
# Insert into the docstring for coalign. We cannot use the add_common_docstring decorator
201199
# due to what would be a circular loop in definitions.
202-
coalign.__doc__ = coalign.__doc__.format(coalignment_function_names=_coalignment_function_names) # type: ignore
200+
coalign.__doc__ = coalign.__doc__.format(coalignment_function_names=_coalignment_function_names) # TYPE: IGNORE

sunkit_image/coalignment/phase_cross_correlation.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ def phase_cross_correlation_coalign(target_array, reference_array, **kwargs):
3838
"""
3939
if target_array.shape != reference_array.shape:
4040
raise ValueError("Input and target arrays must be the same shape.")
41-
if "upsample_factor" not in kwargs:
42-
kwargs["upsample_factor"] = 20
4341
shift, _, _ = phase_cross_correlation(reference_array, target_array, **kwargs)
4442
# Shift has axis ordering which is consistent with the axis order of the input arrays, so y, x
45-
# These are negative based on the example provided in the scikit-image documentation
43+
# See the example here:
4644
# https://scikit-image.org/docs/stable/auto_examples/registration/plot_register_translation.html
47-
x_shift, y_shift = -shift[1], -shift[0]
45+
x_shift, y_shift = shift[1], shift[0]
4846
log.debug(f"Phase cross correlation shift: x: {x_shift}, y: {y_shift}")
4947
# Particularly for this method, there is no change in the rotation or scaling,
5048
# hence the hardcoded values of scale to 1.0 & rotation to identity matrix

sunkit_image/coalignment/tests/test_coalignment.py

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@
77
from astropy.io import fits
88

99
import sunpy.map
10-
from sunpy.net import Fido
11-
from sunpy.net import attrs as a
1210

1311
from sunkit_image.coalignment import coalign
14-
from sunkit_image.coalignment.interface import (
15-
REGISTERED_METHODS,
16-
AffineParams,
17-
_update_fits_wcs_metadata,
18-
register_coalignment_method,
19-
)
12+
from sunkit_image.coalignment.interface import AffineParams, _update_fits_wcs_metadata
2013
from sunkit_image.tests.helpers import figure_test
2114

2215

@@ -28,16 +21,12 @@ def eis_test_map():
2821

2922

3023
@pytest.fixture()
31-
def aia193_test_map(eis_test_map):
32-
query = Fido.search(
33-
a.Time(start=eis_test_map.date-1*u.minute,
34-
end=eis_test_map.date+1*u.minute,
35-
near=eis_test_map.date),
36-
a.Instrument.aia,
37-
a.Wavelength(193*u.angstrom),
38-
)
39-
file = Fido.fetch(query, site='NSO')
40-
return sunpy.map.Map(file)
24+
def aia193_test_map():
25+
# This is matched to the EIS observation time
26+
url = "https://github.com/sunpy/data/raw/refs/heads/main/sunkit-image/aia.lev1.193A_2014_01_08T09_57_30.84Z.image_lev1.fits"
27+
with fits.open(url) as hdul:
28+
hdul.verify('silentfix')
29+
return sunpy.map.Map(hdul[1].data, hdul[1].header)
4130

4231

4332
@pytest.mark.remote_data()
@@ -116,32 +105,18 @@ def test_coalignment_figure(incorrect_pointing_cutout_map, cutout_map, aia171_te
116105
return fig
117106

118107

119-
def test_register_coalignment_method():
120-
@register_coalignment_method("test_method")
121-
def test_func():
122-
return "Test function"
123-
124-
assert "test_method" in REGISTERED_METHODS
125-
assert REGISTERED_METHODS["test_method"] == test_func
126-
assert test_func() == "Test function"
127-
128-
129108
def test_unsupported_affine_parameters(incorrect_pointing_cutout_map, aia171_test_map):
130109
affine_rot = AffineParams(
131110
scale=[1,1],
132111
rotation_matrix=2*np.eye(2),
133112
translation=[0,0],
134113
)
135114
with pytest.raises(NotImplementedError, match=r"Changes to the rotation metadata are currently not supported."):
136-
_ = _update_fits_wcs_metadata(incorrect_pointing_cutout_map,
137-
aia171_test_map,
138-
affine_rot)
115+
_update_fits_wcs_metadata(incorrect_pointing_cutout_map, aia171_test_map, affine_rot)
139116
affine_scale = AffineParams(
140117
scale=[2,3],
141118
rotation_matrix=np.eye(2),
142119
translation=[0,0],
143120
)
144121
with pytest.raises(NotImplementedError, match=r"Changes to the pixel scale metadata are currently not supported."):
145-
_ = _update_fits_wcs_metadata(incorrect_pointing_cutout_map,
146-
aia171_test_map,
147-
affine_scale)
122+
_update_fits_wcs_metadata(incorrect_pointing_cutout_map, aia171_test_map, affine_scale)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from sunkit_image.coalignment.interface import REGISTERED_METHODS, register_coalignment_method
2+
3+
4+
def test_register_coalignment_method():
5+
@register_coalignment_method("test_method")
6+
def test_func():
7+
return "Test function"
8+
9+
assert "test_method" in REGISTERED_METHODS
10+
assert REGISTERED_METHODS["test_method"] == test_func
11+
assert test_func() == "Test function"

0 commit comments

Comments
 (0)