def save_pointings(self):
        """Print the currently defined FOVs"""
        i = 0
        if self.pointing_format.get() in ['GEMINI ET', 'CFHT ET', 'CFHT API']:
            logging.info('Beginning table pointing save.')
            for pointing in self.pointings:
                name = pointing["label"]["text"]
                camera = pointing["camera"]
                ccds = numpy.radians(camera.geometry)
                polygons = []
                for ccd in ccds:
                    polygon = Polygon.Polygon(((ccd[0], ccd[1]),
                                               (ccd[0], ccd[3]),
                                               (ccd[2], ccd[3]),
                                               (ccd[2], ccd[1]),
                                               (ccd[0], ccd[1])))
                    polygons.append(polygon)
                et = EphemTarget(name, ephem_format=self.pointing_format.get())
                # determine the mean motion of target KBOs in this field.
                field_kbos = []
                center_ra = 0
                center_dec = 0

                pointing_date = mpc.Time(self.date.get(), scale='utc')
                start_date = mpc.Time(self.date.get(), scale='utc') - TimeDelta(8.1*units.day)
                end_date = start_date + TimeDelta(17*units.day)
                time_step = TimeDelta(3.0*units.hour)

                # Compute the mean position of KBOs in the field on current date.
                for kbo_name, kbo in self.kbos.items():
                    if kbo_name in Neptune or kbo_name in tracking_termination:
                        print 'skipping', kbo_name
                        continue
                    kbo.predict(pointing_date)
                    ra = kbo.coordinate.ra
                    dec = kbo.coordinate.dec
                    if kbo_name in name:
                        print "{} matches pointing {} by name, adding to field.".format(kbo_name, name)
                        field_kbos.append(kbo)
                        center_ra += ra.radian
                        center_dec += dec.radian
                    else:
                        for polygon in polygons:
                            if polygon.isInside(ra.radian, dec.radian):
                                print "{} inside pointing {} polygon, adding to field.".format(kbo_name, name)
                                field_kbos.append(kbo)
                                center_ra += ra.radian
                                center_dec += dec.radian

                # logging.critical("KBOs in field {0}: {1}".format(name, ', '.join([n.name for n in field_kbos])))

                today = start_date
                while today < end_date:
                    today += time_step
                    mean_motion = (0, 0)
                    max_mag = 0.0
                    if len(field_kbos) > 0:
                        current_ra = 0
                        current_dec = 0
                        for kbo in field_kbos:
                            kbo.predict(today)
                            max_mag = max(max_mag, kbo.mag)
                            current_ra += kbo.coordinate.ra.radian
                            current_dec += kbo.coordinate.dec.radian
                        mean_motion = ((current_ra - center_ra) / len(field_kbos),
                                       (current_dec - center_dec) / len(field_kbos))
                    ra = pointing['camera'].coordinate.ra.radian + mean_motion[0]
                    dec = pointing['camera'].coordinate.dec.radian + mean_motion[1]
                    cc = SkyCoord(ra=ra,
                                  dec=dec,
                                  unit=(units.radian, units.radian),
                                  obstime=today)
                    dt = pointing_date - today
                    cc.dra = (mean_motion[0] * units.radian / dt.to(units.hour)).to(units.arcsec/units.hour).value*math.cos(dec)
                    cc.ddec = (mean_motion[1] * units.radian / dt.to(units.hour)).to(units.arcsec/units.hour).value
                    cc.mag = max_mag
                    et.append(cc)

                et.save()
            return

        f = tkFileDialog.asksaveasfile()
        if self.pointing_format.get() == 'Subaru':
            for pointing in self.pointings:
                (sra, sdec) = str(pointing["camera"]).split()
                ra = sra.replace(":", "")
                dec = sdec.replace(":", "")
                name = pointing["label"]["text"]
                f.write("""{}=OBJECT="{}" RA={} DEC={} EQUINOX=2000.0 INSROT_PA=90\n""".format(name,
                                                                                               name,
                                                                                               ra,
                                                                                               dec))
            return
        if self.pointing_format.get() == 'CFHT PH':
            f.write("""<?xml version = "1.0"?>
<!DOCTYPE ASTRO SYSTEM "http://vizier.u-strasbg.fr/xml/astrores.dtd">
<ASTRO ID="v0.8" xmlns:ASTRO="http://vizier.u-strasbg.fr/doc/astrores.htx">
<TABLE ID="Table">
<NAME>Fixed Targets</NAME>
<TITLE>Fixed Targets for CFHT QSO</TITLE>
<!-- Definition of each field -->
<FIELD name="NAME" datatype="A" width="20">
   <DESCRIPTION>Name of target</DESCRIPTION>
</FIELD>
<FIELD name="RA" ref="" datatype="A" width="11" unit="&quot;h:m:s&quot;">
   <DESCRIPTION>Right ascension of target</DESCRIPTION>
</FIELD>     
<FIELD name="DEC" ref="" datatype="A" width="11" unit="&quot;d:m:s&quot;">
   <DESCRIPTION>Declination of target</DESCRIPTION>
</FIELD>     
<FIELD name="EPOCH" datatype="F" width="6">
    <DESCRIPTION>Epoch of coordinates</DESCRIPTION>
</FIELD>     
<FIELD name="POINT" datatype="A" width="5">
<DESCRIPTION>Pointing name</DESCRIPTION>
</FIELD>     
<!-- Data table --> 
<DATA><CSV headlines="4" colsep="|"><![CDATA[
NAME                |RA         |DEC        |EPOCH |POINT|
                    |hh:mm:ss.ss|+dd:mm:ss.s|      |     |
12345678901234567890|12345678901|12345678901|123456|12345|
--------------------|-----------|-----------|------|-----|\n""")
        if self.pointing_format.get() == 'Palomar':
            f.write("index\n")
        for pointing in self.pointings:
            i = i + 1
            name = pointing["label"]["text"]
            (sra, sdec) = str(pointing["camera"]).split()
            ra = sra.split(":")
            dec = sdec.split(":")
            dec[0] = str(int(dec[0]))
            if int(dec[0]) >= 0:
                dec[0] = '+' + dec[0]
            if self.pointing_format.get() == 'Palomar':
                f.write("%5d %16s %2s %2s %4s %3s %2s %4s 2000\n" % (i, name,
                                                                     ra[0].zfill(2),
                                                                     ra[1].zfill(2),
                                                                     ra[2].zfill(2),
                                                                     dec[0].zfill(3),
                                                                     dec[1].zfill(2),
                                                                     dec[2].zfill(2)))
            elif self.pointing_format.get() == 'CFHT PH':
                # f.write("%f %f\n" % (pointing["camera"].ra,pointing["camera"].dec))
                f.write("%-20s|%11s|%11s|%6.1f|%-5d|\n" % (name, sra, sdec, 2000.0, 1))
            elif self.pointing_format.get() == 'KPNO/CTIO':
                str1 = sra.replace(":", " ")
                str2 = sdec.replace(":", " ")
                f.write("%16s %16s %16s 2000\n" % ( name, str1, str2))
            elif self.pointing_format.get() == 'SSim':
                ra = []
                dec = []
                for ccd in pointing["camera"].geometry:
                    ra.append(ccd[0])
                    ra.append(ccd[2])
                    dec.append(ccd[1])
                    dec.append(ccd[3])

                dra = math.degrees(math.fabs(max(ra) - min(ra)))
                ddec = math.degrees(math.fabs(max(dec) - min(dec)))
                f.write("%f %f %16s %16s DATE 1.00 1.00 500 FILE\n" % (dra, ddec, sra, sdec ))
        if self.pointing_format.get() == 'CFHT PH':
            f.write("""]]</CSV></DATA>
</TABLE>
</ASTRO>
""")
        f.close()
def save_pointings ( self ) : i = 0 if self . pointing_format . get ( ) in [ 'GEMINI ET' , 'CFHT ET' , 'CFHT API' ] : logging . info ( 'Beginning table pointing save.' ) for pointing in self . pointings : name = pointing [ "label" ] [ "text" ] camera = pointing [ "camera" ] ccds = numpy . radians ( camera . geometry ) polygons = [ ] for ccd in ccds : polygon = Polygon . Polygon ( ( ( ccd [ 0 ] , ccd [ 1 ] ) , ( ccd [ 0 ] , ccd [ 3 ] ) , ( ccd [ 2 ] , ccd [ 3 ] ) , ( ccd [ 2 ] , ccd [ 1 ] ) , ( ccd [ 0 ] , ccd [ 1 ] ) ) ) polygons . append ( polygon ) et = EphemTarget ( name , ephem_format = self . pointing_format . get ( ) ) field_kbos = [ ] center_ra = 0 center_dec = 0 pointing_date = mpc . Time ( self . date . get ( ) , scale = 'utc' ) start_date = mpc . Time ( self . date . get ( ) , scale = 'utc' ) - TimeDelta ( 8.1 * units . day ) end_date = start_date + TimeDelta ( 17 * units . day ) time_step = TimeDelta ( 3.0 * units . hour ) for kbo_name , kbo in self . kbos . items ( ) : if kbo_name in Neptune or kbo_name in tracking_termination : print 'skipping' , kbo_name continue kbo . predict ( pointing_date ) ra = kbo . coordinate . ra dec = kbo . coordinate . dec if kbo_name in name : print "{} matches pointing {} by name, adding to field." . format ( kbo_name , name ) field_kbos . append ( kbo ) center_ra += ra . radian center_dec += dec . radian else : for polygon in polygons : if polygon . isInside ( ra . radian , dec . radian ) : print "{} inside pointing {} polygon, adding to field." . format ( kbo_name , name ) field_kbos . append ( kbo ) center_ra += ra . radian center_dec += dec . radian today = start_date while today < end_date : today += time_step mean_motion = ( 0 , 0 ) max_mag = 0.0 if len ( field_kbos ) > 0 : current_ra = 0 current_dec = 0 for kbo in field_kbos : kbo . predict ( today ) max_mag = max ( max_mag , kbo . mag ) current_ra += kbo . coordinate . ra . radian current_dec += kbo . coordinate . dec . radian mean_motion = ( ( current_ra - center_ra ) / len ( field_kbos ) , ( current_dec - center_dec ) / len ( field_kbos ) ) ra = pointing [ 'camera' ] . coordinate . ra . radian + mean_motion [ 0 ] dec = pointing [ 'camera' ] . coordinate . dec . radian + mean_motion [ 1 ] cc = SkyCoord ( ra = ra , dec = dec , unit = ( units . radian , units . radian ) , obstime = today ) dt = pointing_date - today cc . dra = ( mean_motion [ 0 ] * units . radian / dt . to ( units . hour ) ) . to ( units . arcsec / units . hour ) . value * math . cos ( dec ) cc . ddec = ( mean_motion [ 1 ] * units . radian / dt . to ( units . hour ) ) . to ( units . arcsec / units . hour ) . value cc . mag = max_mag et . append ( cc ) et . save ( ) return f = tkFileDialog . asksaveasfile ( ) if self . pointing_format . get ( ) == 'Subaru' : for pointing in self . pointings : ( sra , sdec ) = str ( pointing [ "camera" ] ) . split ( ) ra = sra . replace ( ":" , "" ) dec = sdec . replace ( ":" , "" ) name = pointing [ "label" ] [ "text" ] f . write ( """{}=OBJECT="{}" RA={} DEC={} EQUINOX=2000.0 INSROT_PA=90\n""" . format ( name , name , ra , dec ) ) return if self . pointing_format . get ( ) == 'CFHT PH' : f . write ( """<?xml version = "1.0"?>
<!DOCTYPE ASTRO SYSTEM "http://vizier.u-strasbg.fr/xml/astrores.dtd">
<ASTRO ID="v0.8" xmlns:ASTRO="http://vizier.u-strasbg.fr/doc/astrores.htx">
<TABLE ID="Table">
<NAME>Fixed Targets</NAME>
<TITLE>Fixed Targets for CFHT QSO</TITLE>
<!-- Definition of each field -->
<FIELD name="NAME" datatype="A" width="20">
   <DESCRIPTION>Name of target</DESCRIPTION>
</FIELD>
<FIELD name="RA" ref="" datatype="A" width="11" unit="&quot;h:m:s&quot;">
   <DESCRIPTION>Right ascension of target</DESCRIPTION>
</FIELD>     
<FIELD name="DEC" ref="" datatype="A" width="11" unit="&quot;d:m:s&quot;">
   <DESCRIPTION>Declination of target</DESCRIPTION>
</FIELD>     
<FIELD name="EPOCH" datatype="F" width="6">
    <DESCRIPTION>Epoch of coordinates</DESCRIPTION>
</FIELD>     
<FIELD name="POINT" datatype="A" width="5">
<DESCRIPTION>Pointing name</DESCRIPTION>
</FIELD>     
<!-- Data table --> 
<DATA><CSV headlines="4" colsep="|"><![CDATA[
NAME                |RA         |DEC        |EPOCH |POINT|
                    |hh:mm:ss.ss|+dd:mm:ss.s|      |     |
12345678901234567890|12345678901|12345678901|123456|12345|
--------------------|-----------|-----------|------|-----|\n""" ) if self . pointing_format . get ( ) == 'Palomar' : f . write ( "index\n" ) for pointing in self . pointings : i = i + 1 name = pointing [ "label" ] [ "text" ] ( sra , sdec ) = str ( pointing [ "camera" ] ) . split ( ) ra = sra . split ( ":" ) dec = sdec . split ( ":" ) dec [ 0 ] = str ( int ( dec [ 0 ] ) ) if int ( dec [ 0 ] ) >= 0 : dec [ 0 ] = '+' + dec [ 0 ] if self . pointing_format . get ( ) == 'Palomar' : f . write ( "%5d %16s %2s %2s %4s %3s %2s %4s 2000\n" % ( i , name , ra [ 0 ] . zfill ( 2 ) , ra [ 1 ] . zfill ( 2 ) , ra [ 2 ] . zfill ( 2 ) , dec [ 0 ] . zfill ( 3 ) , dec [ 1 ] . zfill ( 2 ) , dec [ 2 ] . zfill ( 2 ) ) ) elif self . pointing_format . get ( ) == 'CFHT PH' : f . write ( "%-20s|%11s|%11s|%6.1f|%-5d|\n" % ( name , sra , sdec , 2000.0 , 1 ) ) elif self . pointing_format . get ( ) == 'KPNO/CTIO' : str1 = sra . replace ( ":" , " " ) str2 = sdec . replace ( ":" , " " ) f . write ( "%16s %16s %16s 2000\n" % ( name , str1 , str2 ) ) elif self . pointing_format . get ( ) == 'SSim' : ra = [ ] dec = [ ] for ccd in pointing [ "camera" ] . geometry : ra . append ( ccd [ 0 ] ) ra . append ( ccd [ 2 ] ) dec . append ( ccd [ 1 ] ) dec . append ( ccd [ 3 ] ) dra = math . degrees ( math . fabs ( max ( ra ) - min ( ra ) ) ) ddec = math . degrees ( math . fabs ( max ( dec ) - min ( dec ) ) ) f . write ( "%f %f %16s %16s DATE 1.00 1.00 500 FILE\n" % ( dra , ddec , sra , sdec ) ) if self . pointing_format . get ( ) == 'CFHT PH' : f . write ( """]]</CSV></DATA>
</TABLE>
</ASTRO>
""" ) f . close ( )
Print the currently defined FOVs