llx = m.group(1)
            lly = m.group(2)

            off[nc][nw]  = (xbin*(int(llx)-1)+1,ybin*(int(lly)-1)+1)
            data[nc][nw] = image[ny*nw:ny*(nw+1),0:nx/2]
        if target is None and 'object' in phead:
            target = phead['object']
        elif target != phead['object']:
            print 'WARNING: OBJECT clash in',fname
        if expose is None:
            expose = phead['exptime']
        elif expose != phead['exptime']:
            print 'WARNING: EXPTIME clash in ' + fname + ':',expose,'vs',phead['exptime'],'(new vs old)'
        if utc is None:
            mjd = int(phead['julian']-2400000.5)
            utc = subs.hms2d(phead['shopen'])
        elif utc != subs.hms2d(phead['shopen']) or mjd != int(phead['julian']-2400000.5):
            print 'WARNING: time clash in ' + fname + ':',subs.hms2d(phead['shopen']),int(phead['julian']-2400000.5),\
                'vs',utc,mjd,'(new vs old)'
        hdulist.close()
        
    # create headers
    head = subs.Odict()
    if target is not None:
        head['Object'] = {'value' : target, 'comment' : 'The target name', 'type' : ucm.ITYPE_STRING}
    if utc is not None and expose is not None:
        utc += expose/2./3600.
        if utc >= 24.:
            utc -= 24.
            mjd += 1
        head['UT_date'] = {'value' : (mjd, utc), 'comment' : 'UTC at exposure mid-point', 'type' : ucm.ITYPE_TIME}
Beispiel #2
0
def get_from_dss(ra, dec, size, fname=None, prec=1, survey='POSS2BLUE',
                 clobber=True):
    """
    Gets a FITS file from the DSS. Arguments::

    ra     : (string)
           ra (hh mm ss.ss)

    dec    : (string)
           dec (+/-dd mm ss.ss)

    fname  : (string)
           name of output (including .fits.gz). If not specified it will be
           constructed from the RA and Dec.

    prec   : (int)
           used to construct fname if not specified. See precision parameter of
           trm.subs.d2hms to understand this.

    size   : (float)
           field size (arcmin)

    Returns fname

    fname    -- the name of the FITS file created.
    """
    if not survey in SURVEYS:
        raise Exception('get_from_dss: survey name = ' +
                        survey + ' is invalid.')

    rad  = subs.hms2d(ra)
    decd = subs.hms2d(dec)
    if rad < 0. or rad >= 24 or decd < -90. or decd > +90.:
        raise Exception('get_from_dss: position out of range ra,dec = '
                        + ra + ' ' + dec)

    if fname is None:
        ras   = ra[:ra.find('.')].replace(' ','')
        decs  = dec[:dec.find('.')].replace(' ','')
        fname = ras + decs + '.fits.gz'
    elif not fname.endswith('.fits.gz'):
        raise Exception('get_from_dss: filename = ' + fname +
                        ' does not end with .fits.gz')

    if clobber or not os.path.exists(fname):

        # URL at STScI
        url = 'http://stdatu.stsci.edu/cgi-bin/dss_search'

        # encode the request string.
        data = urllib.urlencode({'v' : SURVEYS[survey], 'r': ra,
                                 'd' : dec, 'e' : 'J2000', \
                                 'h' : size, 'w' : size, 'f' : 'fits', \
                                 'c' : 'gz', 's' : 'on'})

        # get FITS data
        results = urllib2.urlopen(url, data)
        with open(fname, 'w') as f:
            f.write(results.read())

    return fname
        xmls = [os.path.join(dpath,x) for x in os.listdir(dpath) \
                    if xml_re.match(x) is not None]
        xmls.sort()
        first = True
        expose = 0.
        for xml in xmls:
            try:
                run = Ultra.Run(xml, nlog, times, targets, telescope, ndir,
                                rdir, sskip, True)

                # update targets to reduce simbad lookups
                if run.simbad:
                    if run.id in targets:
                        targets[run.id]['match'].append((run.target, True))
                    else:
                        targets[run.id] = {'ra' : subs.hms2d(run.ra), \
                                               'dec' : subs.hms2d(run.dec),
                                           'match' : [(run.target, True),]}
                elif run.id is None:
                    sskip.append(run.target)

                if run.ra is not None and run.dec is not None:
                    rah, decd, csys = subs.str2radec(run.ra + ' ' + run.dec)
                    entries.append(
                        {'ra' : rah, 'dec' : decd, 'run' : run.run,
                         'night' : run.night,
                         'num' : run.number, 'target' : run.target.strip(),
                         'id' : run.id.strip(),
                         'expose' : 0. if run.expose is None else \
                             float(run.expose)/60.,
                         'comment' : run.comment.strip()})