Skip to content

Commit

Permalink
Merge cdbfd69 into 6caed8c
Browse files Browse the repository at this point in the history
  • Loading branch information
keflavich committed Mar 26, 2019
2 parents 6caed8c + cdbfd69 commit db235e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion regions/core/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ class RegionMeta(Meta):
valid_keys = ['label', 'include', 'frame', 'range', 'veltype',
'restfreq', 'tag', 'comment', 'line', 'name',
'select', 'highlite', 'fixed', 'edit', 'move', 'rotate',
'delete', 'source', 'background', 'corr', 'type'
'delete', 'source', 'background', 'corr', 'type',
'text'
]

key_mapping = {}
Expand Down
7 changes: 5 additions & 2 deletions regions/io/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def to_crtf(self, coordsys='fk5', fmt='.6f', radunit='deg'):
shape.meta.items() if
key not in ('include', 'comment', 'symbol',
'coord', 'text', 'range', 'corr',
'type', 'text'))
'type'))

# the first item should be the coordinates, since CASA cannot
# recognize a region without an inline coordinate specification
Expand Down Expand Up @@ -613,7 +613,10 @@ def to_region(self):
reg.visual = RegionVisual()
reg.meta = RegionMeta()

label = self.meta.pop('text', self.meta.get('label', ""))
# both 'text' and 'label' should be set to the same value, where we
# default to the 'text' value since that is the one used by ds9 regions
label = self.meta.get('text',
self.meta.get('label', ""))
if label != '':
reg.meta['label'] = label
for key in self.meta:
Expand Down
17 changes: 17 additions & 0 deletions regions/io/ds9/tests/test_ds9_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,20 @@ def test_expicit_formatting_directives():
reg_str_explicit = 'fk5\ncircle(1h20m30s, 2d3m7s, 2d)'
coord = DS9Parser(reg_str_explicit).shapes[0].coord
assert_quantity_allclose(u.Quantity(coord), u.Quantity(valid_coord))

def test_text_metadata():
"""
Regression test for issue #233: make sure that text metadata is parsed and
stored appropriately.
"""

reg_str = 'image\ncircle(1.5, 2, 2) # text={this_is_text}'
parsed_reg = DS9Parser(reg_str)

assert len(parsed_reg.shapes) == 1
assert parsed_reg.shapes[0].meta['text'] == 'this_is_text'

regs = parsed_reg.shapes.to_regions()

assert regs[0].meta['label'] == 'this_is_text'
assert regs[0].meta['text'] == 'this_is_text'

0 comments on commit db235e9

Please sign in to comment.