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

Support for unit equivalencies when changing units on WCSAxes #16478

Open
wtbarnes opened this issue May 21, 2024 · 0 comments
Open

Support for unit equivalencies when changing units on WCSAxes #16478

wtbarnes opened this issue May 21, 2024 · 0 comments

Comments

@wtbarnes
Copy link

wtbarnes commented May 21, 2024

What is the problem this feature will solve?

When plotting with WCSAxes, it is currently possible to change the unit of the axis using set_format_unit. However, this function does not support equivalencies, e.g. if I have an axis in nm, I cannot convert to Hz. This feature would allow you to pass an equivalency to set_format_unit such that you could apply an equivalency when formatting the units of an axis.

Describe the desired outcome

The desired outcome would be that an axis could be converted to a compatible unit under the selected equivalency, e.g. for a wavelength axis, I could change the axis to Hz under the spectral equivalency.

Additional context

As an example, here's a MWE that currently does not work because there is no way to pass an equivalency to set_format_unit,

import astropy.units as u
import astropy.wcs
import matplotlib.pyplot as plt
import numpy as np

wave_wcs = astropy.wcs.WCS(header={
    'CDELT1': 1,
    'CRVAL1': 1,
    'CRPIX1': 1,
    'CUNIT1': 'Angstrom',
    'CTYPE1': 'WAVE',
})

fig = plt.figure()
ax = fig.add_subplot(projection=wave_wcs)
ax.plot(np.arange(10))
ax.coords[0].set_format_unit('Hertz')

Ideally, one would be able to pass in an equivalency to set_format_unit as so,

ax.coords[0].set_format_unit('Hertz', equivalencies=u.spectral())

I'll also note that the version of this problem I'm presenting here is actually the easy case, where you're converting from one non-angle axis to another. This problem is further complicated when talking about converting from an angle to a non-angle, e.g. applying an equivalency that allows to convert between m and degrees. This is because there are separate formatters implemented for axes with coord type "scalar" and coord type "longitude" or "latitude".

@wtbarnes wtbarnes changed the title Support for unit equivalencies when changing units on `WCSAxes Support for unit equivalencies when changing units on WCSAxes May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants