-
-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Coalignment API #207
Open
Deus1704
wants to merge
77
commits into
sunpy:main
Choose a base branch
from
Deus1704:new_coalignment_api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
New Coalignment API #207
Changes from 73 commits
Commits
Show all changes
77 commits
Select commit
Hold shift + click to select a range
bb4876a
a better approach to dev
Deus1704 08a0ff9
added decorator and incorporated suggestions
Deus1704 e02eb28
Merge branch 'main' into new_coalignment_api
Deus1704 f25076b
updated the docstring
Deus1704 98c384e
added tests for majority of all funcs
Deus1704 47e1256
adds how to guide
Deus1704 73373fc
temporary de-referencing funcs and methods
Deus1704 125e78a
fix doc tree
Deus1704 53fd4d5
added refs again
Deus1704 4150115
Apply suggestions from code review
Deus1704 0ac31ab
code review and fixing minor mistakes
Deus1704 ffe357b
changed doc to ref
Deus1704 adc8bcb
Update ref
Deus1704 bc6d2e1
better linking
Deus1704 31d62fa
Merge remote-tracking branch 'upstream/main' into new_coalignment_api
Deus1704 5d67806
updated the api, now returns the map with updated metadata
Deus1704 89f6d99
updated the how_to_guide
Deus1704 963e476
docstring fix
Deus1704 ba8ec82
first try at replacing old coalign
Deus1704 fcf9eae
removing old coalignment completely, refs fixed, old example removed
Deus1704 7dba720
fix the issue of method not being registered
Deus1704 93a477b
fix the pixel pair issue
Deus1704 177173d
Apply suggestions from code review & testing bot
Deus1704 466f8e8
Merge remote-tracking branch 'upstream/main' into new_coalignment_api
Deus1704 b7ac50c
fix the order of the reference and target maps
Deus1704 573d1e3
calm down pre-commit
Deus1704 0cee8f1
Merge remote-tracking branch 'upstream/main' into new_coalignment_api
Deus1704 81b7fcb
fixed the method & added examples and tests
Deus1704 587833b
adding the eis file
Deus1704 9d6ab7f
Apply suggestions from code review
Deus1704 ff7b1b2
Merge remote-tracking branch 'upstream/main' into new_coalignment_api
Deus1704 6f0bc9d
made changes based on suggestions
Deus1704 7eb84b1
pre-commit
Deus1704 cfb93ea
Update docs/how_to_guide/using_the_coalignment_interface.rst
Deus1704 3079671
rename all please
Deus1704 8ed4173
renamed coalignment to coalign, made example plot better, removed nam…
Deus1704 f8d1f5a
here too
Deus1704 eb94a1b
Merge branch 'main' into new_coalignment_api
Deus1704 64e07ad
minor fix
Deus1704 6173e57
marked remote test
Deus1704 8e0508d
testing by including the source
Deus1704 d02b986
fixed the rst
Deus1704 1146039
Merge branch 'main' into new_coalignment_api
Deus1704 b4e54de
updated the handling of cdelt values
Deus1704 7c64024
fixed the plot bloc
Deus1704 9ceadbc
added the figure test case1/2 and clean up
Deus1704 a0e5c6e
fixed the warning list
Deus1704 40713b7
fix refs and clean
Deus1704 17998be
adding fixture
Deus1704 6255c17
trying to suppress warnings
Deus1704 df21cd6
major changes; confirm affine, fixed test case, removed a guide
Deus1704 2db2b09
added a note
Deus1704 2cabfa4
slightly changed the map observation and fig hash
Deus1704 2634cc8
fixed refs
Deus1704 49793d0
trying to fix fig hash
Deus1704 2784fd4
fixed online test, added few more tests, updated coalignment.rst
Deus1704 b8ae410
trying automodule
Deus1704 491acbf
docstring fix
Deus1704 c87a192
fix the online fail by suppressing Astropy Warning
Deus1704 fcf2ea2
one last try
Deus1704 44c5c4c
might need a better way
Deus1704 4e86bd7
for 6.1.2
Deus1704 a6c1f85
final try
Deus1704 2688e52
added the comprehensive changelog
Deus1704 374cf3e
fixed the changelog
Deus1704 a775b27
Apply suggestions from code review
Deus1704 7d130bf
fix the test fails and internalized funcs
Deus1704 33b9428
added the url for eis raster
Deus1704 2aa5e72
forgot
Deus1704 8f26dcb
clean up old raster and few lint fixes
Deus1704 c6f36c4
added a check for astropy version
Deus1704 8b4696f
Merge branch 'main' of github.com:sunpy/sunkit-image into pr/207
nabobalis 5884fc6
Nabil review
nabobalis 1be344f
Apply suggestions from code review
nabobalis da81f44
Addressed comments from Albert
nabobalis 88c4c85
Merge branch 'main' of github.com:sunpy/sunkit-image into pr/207
nabobalis 1b02285
fix import
nabobalis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ default.extend-ignore-identifiers-re = [ | |
"iy", | ||
"BA", | ||
] | ||
|
||
[default.extend-words] | ||
eis = "eis" |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
**New Coalignment API in sunkit_image.coalignment** | ||
|
||
The new coalignment API, developed as part of GSoC 2024, addresses the need for a more precise and flexible approach to image coalignment within the `sunkit_image.coalignment` module. | ||
As solar imaging data continues to grow in complexity, the existing coalignment methods from ``sunpy.image.coalignment`` and ``sunpy.physics.solar_rotation`` were found to be scattered and lacked a unified interface, leading to confusion and redundant code. | ||
nabobalis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
**New Features:** | ||
|
||
- **Coalignment Interface** (`sunkit_image.coalignment.interface`): | ||
|
||
- ``coalign`` function: A high-level function for image coalignment with a specified method. Default method: :func:`~sunkit_image.coalignment.match_template.match_template_coalign`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
- ``AffineParams`` NamedTuple: Stores and passes affine transformation parameters. | ||
|
||
- **Template Matching Coalignment** (`sunkit_image.coalignment.match_template`): | ||
|
||
- ``match_template_coalign`` function: A coalignment method that uses template matching. | ||
|
||
- **Decorator Utility** (`sunkit_image.coalignment.decorators`): | ||
|
||
- ``register_coalignment_method`` decorator: Enables easy registration of coalignment methods. | ||
- Global Registry: Maintains a dictionary of registered coalignment methods. | ||
|
||
**Enhancements:** | ||
|
||
- Improved Metadata Handling: Updates WCS metadata based on affine transformation parameters. | ||
- User Warnings: Alerts users to significant spatial or temporal separations between maps. | ||
|
||
**Documentation:** | ||
|
||
- All functions are well-documented in the API reference. | ||
|
||
**Examples** | ||
|
||
- Please find the examples related to the :ref:`adding of coalignment method <sunkit-image-how-to-guide-add-a-new-coalignment-method>` and using a coalignment method here :ref:`sphx_glr_generated_gallery_aligning_aia_with_eis_maps.py` |
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 +1,17 @@ | ||
Coalignment Package | ||
******************* | ||
|
||
`sunkit_image.coalignment` provides routines to perform coalignment of solar images. | ||
|
||
The main entry point is the `~sunkit_image.coalignment.coalign` function, which accepts a reference map, a target map, and a specified method for coalignment. | ||
This method returns a new map with updated metadata reflecting the applied affine transformations, such as scaling, rotation, and translation. | ||
|
||
The module supports various transformation methods registered via the `~sunkit_image.coalignment.decorators.register_coalignment_method` decorator, allowing for flexible coalignment strategies based on the specific needs of the data. | ||
|
||
.. automodapi:: sunkit_image.coalignment | ||
|
||
.. automodapi:: sunkit_image.coalignment.interface | ||
|
||
.. automodapi:: sunkit_image.coalignment.match_template | ||
|
||
.. automodapi:: sunkit_image.coalignment.decorators |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
.. _sunkit-image-how-to-guide-add-a-new-coalignment-method: | ||
|
||
**************************** | ||
Add a New Coalignment Method | ||
**************************** | ||
|
||
If you want to register a new coalignment method that can be used by :func:`~sunkit_image.coalignment.coalign`, you can use :func:`~sunkit_image.coalignment.decorators.register_coalignment_method`: | ||
|
||
.. code-block:: python | ||
|
||
from sunkit_image.coalignment.decorators import register_coalignment_method | ||
from sunkit_image.coalignment.interface import AffineParams | ||
|
||
@register_coalignment_method("my_coalign") | ||
def my_coalignment_method(input_array, template_array): | ||
nabobalis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Your coalignment code goes here | ||
# This should encompass calculating the shifts, | ||
# handling NaN values appropriately. | ||
# Return the shifts in an affine style, such as the scale, rotation and translation. | ||
return AffineParams(scale, rotation, translation) | ||
|
||
Decorator Parameters | ||
==================== | ||
|
||
Currently the decorator takes one parameter: | ||
|
||
- ``name``: The name of your custom coalignment method, which in the above example is "my_coalign". | ||
|
||
Function Requirements | ||
===================== | ||
|
||
Your coalignment function should: | ||
|
||
1. **Take Input Parameters**: | ||
|
||
- ``input_array``: The 2D array to be coaligned. | ||
- ``target_array``: The 2D array to align to. | ||
|
||
2. **Compute Shifts**: Calculate the shifts in the x and y directions needed to align ``input_array`` with ``target_array``. | ||
|
||
3. **Determine Affine Parameters**: Decide the values of the affine parameters - translation, scale and rotation. | ||
|
||
4. **Return**: Use the ``AffineParams`` named tuple included or provide your own that exposes the three parameters as attributes. | ||
|
||
Handling NaNs and Infs | ||
====================== | ||
|
||
Proper handling of these values is expected to be included in the registered methods. | ||
The :func:`~sunkit_image.coalignment.coalign` function does not change any problematic values. | ||
|
||
Checking if the Method is Registered | ||
==================================== | ||
|
||
To check if your method is registered, you can check if it is present in the registered methods dictionary ``REGISTERED_METHODS`` using the following code: | ||
|
||
.. code-block:: python | ||
|
||
from sunkit_image.coalignment.decorators import REGISTERED_METHODS | ||
print(REGISTERED_METHODS) |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.. _sunkit-image-how-to-reference: | ||
|
||
************* | ||
How To Guide | ||
************* | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
adding_a_coalignment_method |
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ sunkit-image | |
:maxdepth: 1 | ||
|
||
code_ref/index | ||
how_to_guide/index | ||
|
||
.. grid-item-card:: Other info | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
""" | ||
===================== | ||
Coaligning EIS to AIA | ||
===================== | ||
|
||
This example shows how to EIS data to AIA using cross-correlation which is implemented as the "match_template" method. | ||
""" | ||
# sphinx_gallery_thumbnail_number = 2 # NOQA: ERA001 | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
import astropy.units as u | ||
from astropy.visualization import AsinhStretch, ImageNormalize | ||
|
||
import sunpy.map | ||
from sunpy.net import Fido | ||
from sunpy.net import attrs as a | ||
|
||
from sunkit_image.coalignment import coalign | ||
|
||
################################################################################### | ||
# Firstly, let us acquire the IS and AIA data we need for this example. | ||
nabobalis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# For this example, we will use the IS data from the sunpy data repository. | ||
# This is a preprocessed IS raster data. | ||
|
||
|
||
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") | ||
|
||
fig = plt.figure() | ||
|
||
ax = fig.add_subplot(111, projection=eis_map) | ||
eis_map.plot(axes=ax, aspect=eis_map.meta['cdelt2'] / eis_map.meta['cdelt1'], | ||
cmap='Blues_r', norm=ImageNormalize(stretch=AsinhStretch())) | ||
|
||
################################################################################### | ||
# Lets find the AIA image that we want to use as a reference. | ||
# We want to be using an image near the "date_average" of the IS raster. | ||
|
||
query = Fido.search(a.Time(start=eis_map.meta["date_beg"], near=eis_map.meta["date_avg"], end=eis_map.meta["date_end"]), a.Instrument('aia'), a.Wavelength(193*u.angstrom)) | ||
aia_file = Fido.fetch(query) | ||
aia_map = sunpy.map.Map(aia_file) | ||
|
||
#################################################################################### | ||
# Before coaligning the images, we first downsample the AIA image to the same plate | ||
# scale as the IS image. This is not done automatically. | ||
|
||
nx = (aia_map.scale.axis1 * aia_map.dimensions.x) / eis_map.scale.axis1 | ||
ny = (aia_map.scale.axis2 * aia_map.dimensions.y) / eis_map.scale.axis2 | ||
|
||
aia_downsampled = aia_map.resample(u.Quantity([nx, ny])) | ||
|
||
#################################################################################### | ||
# Now we can coalign IS to AIA using cross-correlation. For this we would be using the | ||
# "match_template" method. For details of the implementation refer to the | ||
# documentation of `~sunkit_image.coalignment.match_template.match_template_coalign`. | ||
|
||
coaligned_eis_map = coalign(aia_downsampled, eis_map) | ||
|
||
#################################################################################### | ||
# To check now effective this has been, we will plot the IS data and | ||
# overlap the bright regions from AIA before and after the coalignment. | ||
|
||
levels = [800] * aia_map.unit | ||
|
||
fig = plt.figure(figsize=(15, 7.5)) | ||
|
||
# Before coalignment | ||
ax = fig.add_subplot(121, projection=eis_map) | ||
eis_map.plot(axes=ax, title='Before coalignment', | ||
aspect=coaligned_eis_map.meta['cdelt2'] / coaligned_eis_map.meta['cdelt1'], | ||
cmap='Blues_r', norm=ImageNormalize(stretch=AsinhStretch())) | ||
aia_map.draw_contours(levels, axes=ax) | ||
|
||
# After coalignment | ||
ax = fig.add_subplot(122, projection=coaligned_eis_map) | ||
coaligned_eis_map.plot(axes=ax, title='After coalignment', | ||
aspect=coaligned_eis_map.meta['cdelt2'] / coaligned_eis_map.meta['cdelt1'], | ||
cmap='Blues_r', norm=ImageNormalize(stretch=AsinhStretch())) | ||
aia_map.draw_contours(levels, axes=ax) | ||
|
||
fig.tight_layout() | ||
|
||
plt.show() |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole changelog entry should be simplified significantly (i.e., probably down to just a few lines). The changelog is not where narrative should go.