astropy / regions

Astropy package for region handling
https://astropy-regions.readthedocs.io
BSD 3-Clause "New" or "Revised" License
61 stars 54 forks source link

Incorrect meta properties after serialize/parse using fits format #400

Closed registerrier closed 2 years ago

registerrier commented 3 years ago

With regions v0.5, some meta properties of regions are not correctly handled by Regions.serialize/Regions.parse with fits format.

See the following example:

>>>from regions import Regions
>>>regions_str = '# Region file format: DS9\nimage\ncircle(147.10,254.17,3.1) # color=green\n'

>>>regions = Regions.parse(regions_str, format='ds9')
>>>print(regions[0].meta)
{'include': True}
>>>table = regions.serialize(format="fits")
>>>regions = Regions.parse(data=table, format="fits")
>>>print(regions[0].meta)
{'tag': '1', 'include': False}

The include meta entry should be set to True.

larrybradley commented 3 years ago

This appears to always have been the behavior. For example, these are the equivalent commands using regions v0.4:

>>> from regions import DS9Parser
>>> regions_str = '# Region file format: DS9\nimage\ncircle(147.10,254.17,3.1) # color=green\n'
>>> parser = DS9Parser(regions_str)
>>> regions = parser.shapes.to_regions()
>>> print(regions[0].meta)
{'include': True}

>>> from regions import fits_region_objects_to_table
>>> from regions import FITSRegionParser
>>> table = fits_region_objects_to_table(regions)
>>> parser = FITSRegionParser(table)
>>> regions = parser.shapes.to_regions()
>>> print(regions[0].meta)
{'tag': '1', 'include': False}

I need to check how the include metadata flag is used in FITS region format specification. Note that there is not a one-to-one correspondence of all the meta features of the three different region file formats. Because of this, the serialization step may need to drop unsupported region metadata. In those cases, we should warn the user.

registerrier commented 3 years ago

As far as I know, in the FITS regions specification document, the exclude flag is handled by adding a ! character at the beginning of the SHAPE string.

larrybradley commented 2 years ago

I've fixed this in #444. Parsed FITS regions will now have "include = 0" in their metadata if the shape is prefixed with '!'. Shapes without '!' will not have include in their metadata.