'Writes out a `ds9`_ style regions file. It can be loaded
directly by `ds9`_.
Parameters
filename : str, optional
Output file name - default is ``\'footprint.reg\'``
color : str, optional
Color to use when plotting the line.
width : int, optional
Width of the region line.
coordsys : str, optional
Coordinate system. If not specified (default), the ``radesys``
value is used. For all possible values, see
http://ds9.si.edu/doc/ref/region.html#RegionFileFormat'

def footprint_to_file(self, filename=u'footprint.reg', color=u'green', width=2, coordsys=None):

    comments = u'#    Region    file    format:    DS9    version    4.0    \n#    global    color=green    font="helvetica    12    bold    select=1    highlite=1    edit=1    move=1    delete=1    include=1    fixed=0    source\n'
    coordsys = (coordsys or self.wcs.radesys)
    if (coordsys not in (u'PHYSICAL', u'IMAGE', u'FK4', u'B1950', u'FK5', u'J2000', u'GALACTIC', u'ECLIPTIC', u'ICRS', u'LINEAR', u'AMPLIFIER', u'DETECTOR')):
        raise ValueError(u"Coordinate    system    '{}'    is    not    supported.    A    valid    one    can    be    given    with    the    'coordsys'    argument.".format(coordsys))
    with open(filename, mode=u'w') as f:
        f.write(comments)
        f.write(u'{}\n'.format(coordsys))
        f.write(u'polygon(')
        self.calc_footprint().tofile(f, sep=u',')
        f.write(u')    #    color={0},    width={1:d}    \n'.format(color, width))
