Skip to content

Instantly share code, notes, and snippets.

@saimn
Created February 19, 2016 13:45
Show Gist options
  • Save saimn/58e12de6c1fcb0318a7a to your computer and use it in GitHub Desktop.
Save saimn/58e12de6c1fcb0318a7a to your computer and use it in GitHub Desktop.
import pyregion
from astropy.table import Table
from pyregion.parser_helper import Shape
def table_to_region(table, outfile, racol='ra', deccol='dec', color='green'):
if isinstance(table, (str, unicode)):
table = Table.read(table)
if isinstance(color, (str, unicode)):
color = [color] * len(table)
regions = []
for i, r in enumerate(table):
s = Shape('point', None)
s.coord_list = [r[racol], r[deccol]]
s.coord_format = 'fk5'
s.attr = ([], {'width': '5', 'point': 'cross',
'font': '"helvetica 16 normal roman"'})
s.comment = 'color={} text={}'.format(color[i], r['type'])
regions.append(s)
regions = pyregion.ShapeList(regions)
regions.write(outfile)
if __name__ == "__main__":
t = Table.read('Centering.dat', format='ascii')
colors = dict(CEN='green', VIS='magenta', BKG='cyan')
colors = [colors[c] for c in t['type']]
table_to_region(t, 'test.reg', color=colors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment