Parsing region comments
jmccormac01 opened this issue · 2 comments
jmccormac01 commented
Hi,
Is there a way to parse region comments that appear after the # symbol on each line? For example, if I put a label 10
on the region we get # text={10}
but I cannot see from the examples or docs that parsing this is possible.
Cheers
James
cdeil commented
Here's an example using pyregion
:
>>> import pyregion
>>> reg = pyregion.parse('icrs; circle 1 2 3 # text={10}')[0]
>>> print(reg.__dict__)
{'coord_list': [1.0, 2.0, 3.0], 'attr': ([], {'text': '10'}), 'params': [Number(1), Number(2), Number(3)], 'name': 'circle', 'continued': None, 'exclude': False, 'coord_format': 'icrs', 'comment': 'text={10}'}
Here's an example using the new regions package:
>>> import regions
>>> reg = regions.ds9_string_to_objects('icrs; circle 1 2 3 # text={10}')[0]
>>> print(reg.__dict__)
{'vizmeta': {'text': '{10}'}, 'meta': {'include': ''}, 'center': <ICRS Coordinate: (ra, dec) in deg
(1.0, 2.0)>, 'visual': {}, 'radius': <Quantity 3.0 deg>}
It looks like both packages give you access to the comment contents.
@jmccormac01 - Is this what you need or do you need it in some other format?
Anyone -- please make pull requests to improve the documentation of both packages!
cdeil commented
I'm closing this now.
@jmccormac01 - If you still have a question or feature request, please re-open file a new issue!