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

bug when serializing RectanglePixelRegion (probably any PixelRegion) to CRTF #471

Open
dmehring opened this issue Jul 19, 2022 · 1 comment
Labels
bug io.crtf CASA region file format

Comments

@dmehring
Copy link

We have a developer trying to use this package. He has run up an issue trying to serialize a RectanglePixelRegion to CRTF

from astropy.coordinates import SkyCoord
from astropy import units as u
from regions import PixCoord
from regions import RectanglePixelRegion
region_pix = RectanglePixelRegion(center=PixCoord(x=42, y=43),
                                  width=3, height=4,
                                  angle=5 * u.deg)
region_pix.serialize(format='crtf')

fails with UnitConversionError: '' (dimensionless) and 'deg' (angle) are not convertible

The issue appears to arise at return serializer(regions, **kwargs) in serialize() in core/registry.py.
The issue is that kwargs is empty but _serialize_crtf(regions, coordsys='fk5', fmt='.6f', radunit='deg') which is called has a default unit of 'deg' which gets used in this case, even though it appears that the unit that should be used for the x value is empty/dimensionless.

jrhosk added a commit to casangi/casagui that referenced this issue Jul 26, 2022
… is used to convert the input mask discitonary into an astropy region in either pixel or world cooridates. Currently supported mask shapes are 'rect' and 'polygon'. For mor info see: https://astropy-regions.readthedocs.io/en/stable/shapes.html. In the future, this function needs to support return of 'crtf' format for use with tclean. Currently this is nort supported due to a bug in the pixel version of astropy regions (astropy/regions#471). A bug ticket has been opened.
@larrybradley
Copy link
Member

Thanks, @dmehring. Yes, this is a bug in the API design and implementation of the CRTF serializer. It's on my radar to refactor the CRTF I/O functions. In the meantime, the workaround is to explicitly set the output coordinate frame to 'image', e.g,

from astropy.coordinates import SkyCoord
from astropy import units as u
from regions import PixCoord
from regions import RectanglePixelRegion
region_pix = RectanglePixelRegion(center=PixCoord(x=42, y=43),
                                  width=3, height=4,
                                  angle=5 * u.deg)
region_pix.serialize(format='crtf', coordsys='image')

@larrybradley larrybradley added bug io.crtf CASA region file format labels Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug io.crtf CASA region file format
Projects
None yet
Development

No branches or pull requests

2 participants