Skip to content
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

Add support for custom coordinate frames in WCSAxes specifically in transform_coord_meta_from_wcs #16347

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

samaloney
Copy link

@samaloney samaloney commented Apr 26, 2024

Description

This pull request adds support for externally created customs coordinate frames to WCSAxes by altering how transform_coord_meta_from_wcs operates.

  • Creating a new variable CUSTOM_UCD_COORD_META_MAPPING which could be extended by external packages.
  • Move existing custom frame to this new variable

If this approach is ok then the custom sunpy frame could be moved into the sunpy repo.

I didn't add a new test as while there is new code the current tests cover it I think.

In an external package I could register new CTYPE to UCD and UCD to coord meta data mappings.

MYFRAME_CTYPE_TO_UCD1 = {
    "SXLT": "custom:pos.myframe.lat",
    "SXLN": "custom:pos.myframe.lon",
    "SXRZ": "custom:pos.myframe.z"
}
astropy.wcs.wcsapi.fitswcs.CTYPE_TO_UCD1_CUSTOM.update(MYFRAME_CTYPE_TO_UCD1)


MYFAME_UCD_COORD_META_MAPPING = {
    "custom:pos.myframe.lon": {
        "coord_wrap": 180.0 * u.deg,
        "format_unit": u.arcsec,
        "coord_type": "longitude",
    },

astropy.visualization.wcsaxes.wcsapi.CUSTOM_UCD_COORD_META_MAPPING.update(MYFAME_UCD_COORD_META_MAPPING)

Fixes #16339

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

Copy link

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to Astropy 👋 and congratulations on your first pull request! 🎉

A project member will respond to you as soon as possible; in the meantime, please have a look over the Checklist for Contributed Code and make sure you've addressed as many of the questions there as possible.

If you feel that this pull request has not been responded to in a timely manner, please send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail feedback@astropy.org.

Copy link

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

Copy link
Contributor

@neutrinoceros neutrinoceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution ! I'll leave it to wcsaxes maintainers to discuss whether this approach is acceptable or not, but here's a quick technical review.
Even though the code might be covered already, I believe a test would also be needed to demonstrate the new feature (and to make sure we don't break it in the future).
You'll also need to provide a change log entry (see docs/changes/README.md). Thanks !

astropy/visualization/wcsaxes/wcsapi.py Show resolved Hide resolved
@pllim pllim added this to the v7.0.0 milestone Apr 26, 2024
@samaloney samaloney changed the title Add support for custom frames in WCSAxes specifically transform_coord_meta_from_wcs Add support for custom coordinate frames in WCSAxes specifically transform_coord_meta_from_wcs Apr 26, 2024
@samaloney samaloney changed the title Add support for custom coordinate frames in WCSAxes specifically transform_coord_meta_from_wcs Add support for custom coordinate frames in WCSAxes specifically in transform_coord_meta_from_wcs Apr 26, 2024
samaloney and others added 2 commits April 26, 2024 15:44
Co-authored-by: Clément Robert <cr52@protonmail.com>
@samaloney samaloney force-pushed the feat-wcsaxes-custom-ucd branch 2 times, most recently from a3b1be7 to c28b372 Compare April 27, 2024 15:58
@samaloney samaloney marked this pull request as ready for review May 6, 2024 20:16
Copy link
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good! Just one comment below.


astropy.visualization.wcsaxes.wcsapi.CUSTOM_UCD_COORD_META_MAPPING.update(
myframe_mapping
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid having this be the API to register custom mappings, and instead write a context manager similar to custom_ctype_to_ucd_mapping to make sure the changes are temporary and cleaned up after use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also have the benefit of allowing this functionality to be documented via the API docs even if we don't add something to the main narrative docs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great thanks for the feedback, I've taken a first crack at adding a context manager similar custom_ctype_to_ucd_mapping.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I don't think we should keep the test of modifying the dictionary, we should just be testing the context manager.

Copy link
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Just a few small comments.


astropy.visualization.wcsaxes.wcsapi.CUSTOM_UCD_COORD_META_MAPPING.update(
myframe_mapping
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I don't think we should keep the test of modifying the dictionary, we should just be testing the context manager.

self.mapping = {}
for k, v in mapping.items():
if k in CUSTOM_UCD_COORD_META_MAPPING:
raise ValueError(f"UCD metadata mapping {k} already exists.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we might want to allow existing entries to be overriden, but if this is too much work we could always keep as-is for now and consider it a future improvement to allow overriding.

ax.coords
assert ax.coords["eggs"].coord_type == "longitude"
assert ax.coords["eggs"].coord_wrap == 360 * u.deg
assert ax.coords["eggs"].get_format_unit() == u.arcsec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good if possible to add a test of two nested custom_ucd_wcscoord_mapping calls to make sure both apply at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom mapping from UCD to WSCAxes properties for custom coordinate frames
4 participants