Skip to content

Commit f0e6d29

Browse files
committed
Overhaul of where stuff lives to get dict to store stuff in docs
1 parent 536758e commit f0e6d29

File tree

5 files changed

+39
-23
lines changed

5 files changed

+39
-23
lines changed

sunkit_image/coalignment/interface.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@
1111
from sunpy.util.exceptions import SunpyUserWarning
1212

1313
__all__ = [
14-
"REGISTERED_METHODS",
1514
"AffineParams",
1615
"coalign",
17-
"register_coalignment_method",
1816
]
1917

20-
# Global Dictionary to store the registered methods and their names
21-
REGISTERED_METHODS = {}
22-
2318

2419
class AffineParams(NamedTuple):
2520
"""
@@ -38,21 +33,7 @@ class AffineParams(NamedTuple):
3833
translation: tuple[float, float]
3934

4035

41-
def register_coalignment_method(name):
42-
"""
43-
Registers a coalignment method to be used by the coalignment interface.
44-
45-
Parameters
46-
----------
47-
name : str
48-
The name of the coalignment method.
49-
"""
50-
51-
def decorator(func):
52-
REGISTERED_METHODS[name] = func
53-
return func
5436

55-
return decorator
5637

5738

5839
def _update_fits_wcs_metadata(target_map, reference_map, affine_params):
@@ -193,8 +174,9 @@ def coalign(target_map, reference_map, method='match_template', **kwargs):
193174
return _update_fits_wcs_metadata(target_map, reference_map, affine_params)
194175

195176

177+
from sunkit_image.coalignment.register import REGISTERED_METHODS # isort:skip # NOQA: E402
196178
# Generate the string with allowable coalignment-function names for use in docstrings
197179
_coalignment_function_names = ", ".join([f"``'{name}'``" for name in REGISTERED_METHODS])
198180
# Insert into the docstring for coalign. We cannot use the add_common_docstring decorator
199181
# due to what would be a circular loop in definitions.
200-
coalign.__doc__ = coalign.__doc__.format(coalignment_function_names=_coalignment_function_names) # TYPE: IGNORE
182+
coalign.__doc__ = coalign.__doc__.format(coalignment_function_names=_coalignment_function_names) # type: ignore

sunkit_image/coalignment/match_template.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from sunpy import log
55

6-
from sunkit_image.coalignment.interface import AffineParams, register_coalignment_method
6+
from sunkit_image.coalignment.register import register_coalignment_method
77

88
__all__ = ["match_template_coalign"]
99

@@ -110,6 +110,8 @@ def match_template_coalign(target_array, reference_array, **kwargs):
110110
- translation : `tuple`
111111
A tuple containing the x and y translation values.
112112
"""
113+
from sunkit_image.coalignment.interface import AffineParams # NOQA: PLC0415
114+
113115
corr = match_template(np.float64(reference_array), np.float64(target_array), **kwargs)
114116
# TODO: Work out what is going on
115117
if corr.ndim != target_array.ndim:

sunkit_image/coalignment/phase_cross_correlation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from sunpy import log
55

6-
from sunkit_image.coalignment.interface import AffineParams, register_coalignment_method
6+
from sunkit_image.coalignment.register import register_coalignment_method
77

88
__all__ = ["phase_cross_correlation_coalign"]
99

@@ -36,6 +36,8 @@ def phase_cross_correlation_coalign(target_array, reference_array, **kwargs):
3636
- translation : `tuple`
3737
A tuple containing the x and y translation values.
3838
"""
39+
from sunkit_image.coalignment.interface import AffineParams # NOQA: PLC0415
40+
3941
if target_array.shape != reference_array.shape:
4042
raise ValueError("Input and target arrays must be the same shape.")
4143
shift, _, _ = phase_cross_correlation(reference_array, target_array, **kwargs)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
__all__ = [
2+
"REGISTERED_METHODS",
3+
"register_coalignment_method",
4+
]
5+
6+
# Global Dictionary to store the registered methods and their names
7+
REGISTERED_METHODS = {}
8+
9+
def register_coalignment_method(name):
10+
"""
11+
Registers a coalignment method to be used by the coalignment interface.
12+
13+
Parameters
14+
----------
15+
name : str
16+
The name of the coalignment method.
17+
"""
18+
19+
def decorator(func):
20+
REGISTERED_METHODS[name] = func
21+
return func
22+
23+
return decorator

sunkit_image/coalignment/tests/test_interface.py renamed to sunkit_image/coalignment/tests/test_register.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from sunkit_image.coalignment.interface import REGISTERED_METHODS, register_coalignment_method
1+
from sunkit_image.coalignment import coalign
2+
from sunkit_image.coalignment.register import REGISTERED_METHODS, register_coalignment_method
23

34

45
def test_register_coalignment_method():
@@ -9,3 +10,9 @@ def test_func():
910
assert "test_method" in REGISTERED_METHODS
1011
assert REGISTERED_METHODS["test_method"] == test_func
1112
assert test_func() == "Test function"
13+
14+
15+
def test_coalignment_method_in_docstring():
16+
assert (
17+
"phase_cross_correlation" in coalign.__doc__
18+
)

0 commit comments

Comments
 (0)