Skip to content

Commit

Permalink
Merge d61d87f into db84b63
Browse files Browse the repository at this point in the history
  • Loading branch information
JonahDW committed May 14, 2020
2 parents db84b63 + d61d87f commit c3d3682
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/crtf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Serialisation is done using the `~regions.crtf_objects_to_string` function
>>> from regions import crtf_objects_to_string
>>> crtf_objects_to_string(regions, coordsys='galactic')
'#CRTF\ncircle[[144.559169deg, -14.923593deg], 3.000000deg], coord=GALACTIC, color=green\n'
'#CRTFv0\nglobal coord=galactic\ncircle[[144.559169deg, -14.923593deg], 3.000000deg], color=green\n'
There's also `~regions.write_crtf` and `~regions.read_crtf` which write to and
read from a file in addition to doing the region serialisation and parsing.
Expand Down
20 changes: 8 additions & 12 deletions regions/io/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ class RegionConversionError(ValueError):
coordsys_mapping = {'DS9': {x: x for x in valid_coordsys['DS9']},
'CRTF': {x: x for x in valid_coordsys['CRTF']}
}
coordsys_mapping['CRTF']['geocentrictrueecliptic'] = 'ecliptic'
coordsys_mapping['CRTF']['fk5'] = 'j2000'
coordsys_mapping['CRTF']['fk4'] = 'b1950'
coordsys_mapping['CRTF']['supergalactic'] = 'supergal'
# Coordinate frame names must be uppercase following the CASA CRTF syntax
coordsys_mapping['CRTF']['geocentrictrueecliptic'] = 'ECLIPTIC'
coordsys_mapping['CRTF']['fk5'] = 'J2000'
coordsys_mapping['CRTF']['fk4'] = 'B1950'
coordsys_mapping['CRTF']['supergalactic'] = 'SUPERGAL'

coordsys_mapping['DS9']['geocentrictrueecliptic'] = 'ecliptic'
coordsys_mapping['DS9']['geocentrictrueecliptic'] = 'ECLIPTIC'


class ShapeList(list):
Expand Down Expand Up @@ -137,7 +138,7 @@ def to_crtf(self, coordsys='fk5', fmt='.6f', radunit='deg'):
'line': '{0}line[[{1:FMT}deg, {2:FMT}deg], [{3:FMT}deg, {4:FMT}deg]]'
}

output = '#CRTF\n'
output = '#CRTFv0\n'

if radunit == 'arcsec':
# what's this for?
Expand All @@ -156,7 +157,7 @@ def to_crtf(self, coordsys='fk5', fmt='.6f', radunit='deg'):

# 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)
output += 'global coord={}\n'.format(coordsys_mapping['CRTF'][coordsys])

for shape in self:

Expand All @@ -178,11 +179,6 @@ def to_crtf(self, coordsys='fk5', fmt='.6f', radunit='deg'):
'coord', 'text', 'range', 'corr',
'type'))

# 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={}, ".format(coordsys.upper()) + meta_str

if 'comment' in shape.meta:
meta_str += ", " + shape.meta['comment']
if 'range' in shape.meta:
Expand Down
2 changes: 1 addition & 1 deletion regions/io/crtf/tests/data/CRTFgeneral.crtf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#CRTF0
#CRTFv0
global coord=B1950, frame=BARY, corr=[I, Q], color=blue

# A simple circle region:
Expand Down
17 changes: 9 additions & 8 deletions regions/io/crtf/tests/data/CRTFgeneraloutput.crtf
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#CRTF
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]
#CRTFv0
global coord=B1950
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]], label='My label here', frame=BARY, color=red, corr=[I, Q, U, V]
-ellipse[[12.000deg, 45.000deg], [0.250deg, 1.340deg], 2578.310deg], label='Removed this', frame=BARY, 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, color=blue, corr=[I, Q]
5 changes: 3 additions & 2 deletions regions/io/crtf/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def crtf_objects_to_string(regions, coordsys='fk5', fmt='.6f', radunit='deg'):
>>> from regions import CircleSkyRegion, crtf_objects_to_string
>>> reg_sky = CircleSkyRegion(SkyCoord(1 * u.deg, 2 * u.deg), 5 * u.deg)
>>> print(crtf_objects_to_string([reg_sky]))
#CRTF
circle[[1.000007deg, 2.000002deg], 5.000000deg], coord=FK5,
#CRTFv0
global coord=J2000
circle[[1.000007deg, 2.000002deg], 5.000000deg]
"""
shapelist = to_shape_list(regions, coordsys)
Expand Down

0 comments on commit c3d3682

Please sign in to comment.