Skip to content

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

Merged
astrofrog merged 17 commits into
astropy:mainfrom
samaloney:feat-wcsaxes-custom-ucd
Oct 25, 2024
Merged

astrofrog merged 17 commits into
astropy:mainfrom
samaloney:feat-wcsaxes-custom-ucd

Conversation

@samaloney

@samaloney samaloney commented Apr 26, 2024 •

Copy link
Copy Markdown
Contributor

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.

@github-actions

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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 [email protected].

@github-actions

Copy link
Copy Markdown
Contributor

👋 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?

@neutrinoceros neutrinoceros left a comment

Copy link
Copy Markdown
Contributor

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 !

Comment thread astropy/visualization/wcsaxes/wcsapi.py 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
samaloney force-pushed the feat-wcsaxes-custom-ucd branch 3 times, most recently from c28b372 to e326827 Compare April 27, 2024 16:26
@samaloney
samaloney marked this pull request as ready for review May 6, 2024 20:16

@astrofrog astrofrog left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given there's no way to stop someone editing the dictionary shouldn't we keep a test for it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd vote against it; we shouldn't be testing for implementation details.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the dictionary isn't meant to be accessed directly maybe we should make it private to make it explicit?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I removed it, I don't think we need to make it private

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do think there is utility in people directly accessing the dict if packages like sunpy write their own coordinate frames they could add to the dict without the context manager to improve the plotting of those frames.

@astrofrog astrofrog left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

Comment thread astropy/visualization/wcsaxes/wcsapi.py Outdated
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
Copy Markdown
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Patched in opt-in support for overwriting (with a kwarg)

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
Copy Markdown
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Added

@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Oct 12, 2024
@github-actions

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@Cadair
Cadair force-pushed the feat-wcsaxes-custom-ucd branch from 1fc34ce to 410c7b8 Compare October 24, 2024 12:00
@Cadair
Cadair requested a review from astrofrog October 24, 2024 12:29
@Cadair Cadair removed the Close? Tell stale bot that this issue/PR is stale label Oct 24, 2024
Comment thread astropy/visualization/wcsaxes/wcsapi.py Resolved

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd vote against it; we shouldn't be testing for implementation details.

@astrofrog astrofrog left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems good overall but just a small note on the changelog entry - and in addition I though wcscoord in the context manager name was a bit strange, what about using custom_ucd_coord_meta_mapping as the context manager name?

@astrofrog

Copy link
Copy Markdown
Member

@Cadair - I pushed the changes I suggested in case you agree with them

@Cadair

Cadair commented Oct 25, 2024

Copy link
Copy Markdown
Member

Lgtm thanks

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

5 participants