Skip to content

Commit

Permalink
Merge pull request #226 from keflavich/crtf_for_casa
Browse files Browse the repository at this point in the history
Change CRTF writer to match CASA implementation
  • Loading branch information
keflavich committed Dec 3, 2018
2 parents 19405f6 + 317e6e6 commit 4eacdfe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
16 changes: 13 additions & 3 deletions regions/io/core.py
Expand Up @@ -154,17 +154,22 @@ def to_crtf(self, coordsys='fk5', fmt='.6f', radunit='deg'):

for key, val in crtf_strings.items():
crtf_strings[key] = val.replace("FMT", fmt).replace("RAD",
radunitstr)
radunitstr)

output += 'global coord={}\n'.format(coordsys)
# CASA does not support global coordinate specification, even though the
# documentation for the specification explicitly states that it does.
# output += 'global coord={}\n'.format(coordsys)

for shape in self:

shape.check_crtf()
shape.meta = to_crtf_meta(shape.meta)

# if unspecified, include is True.
include = "-" if shape.include in (False, '-') else "+"
# Despite the specification, CASA does *not* support a preceding
# "+". If you want a region included, leave the opening character
# blank.
include = "-" if shape.include in (False, '-') else ""
include += "ann " if shape.meta.get('type', 'reg') == 'ann' else ""

if shape.meta.get('label', "") != "":
Expand All @@ -175,6 +180,11 @@ def to_crtf(self, coordsys='fk5', fmt='.6f', radunit='deg'):
'coord', 'text', 'range', 'corr',
'type', 'text'))

# the first item should be the coordinates, since CASA cannot
# recognize a region without an inline coordinate specification
# It can be, but does not need to be, comma-separated at the start
meta_str = "coord={0}, ".format(coordsys.upper()) + meta_str

if 'comment' in shape.meta:
meta_str += ", " + shape.meta['comment']
if 'range' in shape.meta:
Expand Down
15 changes: 7 additions & 8 deletions regions/io/crtf/tests/data/CRTFgeneraloutput.crtf
@@ -1,9 +1,8 @@
#CRTF
global coord=fk4
+ann circle[[273.100deg, -23.183deg], 0.001deg], frame=BARY, color=blue, corr=[I, Q]
+rotbox[[180.392deg, 12.392deg], [0.050deg, 0.017deg], 12.000deg], frame=BARY, color=blue, range=[-1240.0km/s, 1240.0km/s], corr=[I, Q]
+annulus[[267.763deg, -45.297deg], [0.100deg, 4.120deg]], frame=BARY, label='My label here', color=red, corr=[I, Q, U, V]
-ellipse[[12.000deg, 45.000deg], [0.250deg, 1.340deg], 2578.310deg], frame=BARY, label='Removed this', color=green, range=[1.42GHz, 1.421GHz], corr=[Q]
+symbol[[31.470deg, 11.905deg], D], frame=BARY, color=blue, linewidth=2, symsize=2, corr=[I, Q]
+text[[31.470deg, 11.905deg], 'my text'], frame=BARY, color=blue, linewidth=2, corr=[I, Q]
+rotbox[[2.000deg, 3.000deg], [2.000deg, 2.000deg], 0.000deg], frame=BARY, corr=[I, Q], color=blue
ann circle[[273.100deg, -23.183deg], 0.001deg], coord=FK4, frame=BARY, color=blue, corr=[I, Q]
rotbox[[180.392deg, 12.392deg], [0.050deg, 0.017deg], 12.000deg], coord=FK4, frame=BARY, color=blue, range=[-1240.0km/s, 1240.0km/s], corr=[I, Q]
annulus[[267.763deg, -45.297deg], [0.100deg, 4.120deg]], coord=FK4, label='My label here', frame=BARY, color=red, corr=[I, Q, U, V]
-ellipse[[12.000deg, 45.000deg], [0.250deg, 1.340deg], 2578.310deg], coord=FK4, label='Removed this', frame=BARY, color=green, range=[1.42GHz, 1.421GHz], corr=[Q]
symbol[[31.470deg, 11.905deg], D], coord=FK4, frame=BARY, color=blue, linewidth=2, symsize=2, corr=[I, Q]
text[[31.470deg, 11.905deg], 'my text'], coord=FK4, frame=BARY, color=blue, linewidth=2, corr=[I, Q]
rotbox[[2.000deg, 3.000deg], [2.000deg, 2.000deg], 0.000deg], coord=FK4, frame=BARY, color=blue, corr=[I, Q]
2 changes: 1 addition & 1 deletion regions/io/ds9/read.py
Expand Up @@ -26,7 +26,7 @@
regex_global = re.compile("^#? *(-?)([a-zA-Z0-9]+)")

# Regular expression to extract meta attributes
regex_meta = re.compile("([a-zA-Z]+)(=)({.*?}|\'.*?\'|\".*?\"|[0-9\s]+\s?|[^=\s]+\s?[0-9]*)\s?")
regex_meta = re.compile(r"([a-zA-Z]+)(=)({.*?}|\'.*?\'|\".*?\"|[0-9\s]+\s?|[^=\s]+\s?[0-9]*)\s?")

# Regular expression to strip parenthesis
regex_paren = re.compile("[()]")
Expand Down

0 comments on commit 4eacdfe

Please sign in to comment.