Example #1
0
def cutout(member, object_name, image, ra, dec, radius, ra_rate, dec_rate):

    global vos_dir

    if member == 'none':
        vos_dir = '{}/nofamily'.format(_VOS_PATH)   #Planned to sort stamps on VOS into groups, but this didn't happen and so currently everything will be saved to /hasfamily
    else:
        vos_dir = '{}/hasfamily'.format(_VOS_PATH)

    radius = radius * units.deg

    expnum = image.strip('p')  # only use processed images
    target = storage.get_uri(expnum)
    coord = SkyCoord(unit="deg", ra=ra, dec=dec)

    hdulist = storage.ra_dec_cutout(target, coord, radius)

    hdulist[0].header['OBJNUM'] = (object_name,'object')    #Put image info into header for later use
    hdulist[0].header['RA'] = (ra,'degrees')
    hdulist[0].header['DEC'] = (dec,'degrees')
    hdulist[0].header['RARATE'] = (ra_rate,'arcsec/hr')
    hdulist[0].header['DECRATE'] = (dec_rate,'arcsec/hr')

    postage_stamp_filename = "{}_{}_{:8f}_{:8f}.fits".format(object_name, image, float(ra), float(dec))

    print postage_stamp_filename

    hdulist.writeto("{}/{}".format(_STAMPS_DIR, postage_stamp_filename), output_verify='warn', clobber=True)
    del hdulist

    try:
        storage.copy('{}/{}'.format(_STAMPS_DIR, postage_stamp_filename),
                     '{}/{}'.format(vos_dir, postage_stamp_filename))
    except Exception, e:
        print e
Example #2
0
 def test_get_cutout(self):
     uri = "vos:jkavelaars/2001_QT297/FORS2.2013-06-15T08:18:06.831/FORS2.2013-06-15T08:18:06.831.fits"
     ra = 340.20001892 * units.degree
     dec = -6.82226166 * units.degree
     coo = SkyCoord(ra, dec)
     radius = 10.0 * units.arcminute
     hdulist = storage.ra_dec_cutout(uri, coo, radius)
     self.assertIsInstance(hdulist, fits.HDUList)
     self.assertTrue(len(hdulist) > 1)
     for hdu in hdulist[1:]:
         self.assertTrue(hdu.header.get("XOFFSET", False) is not False)
Example #3
0
 def test_get_cutout(self):
     uri = "vos:jkavelaars/2001_QT297/FORS2.2013-06-15T08:18:06.831/FORS2.2013-06-15T08:18:06.831.fits"
     ra = 340.20001892 * units.degree
     dec = -6.82226166 * units.degree
     coo = SkyCoord(ra, dec)
     radius = 10.0 * units.arcminute
     hdulist = storage.ra_dec_cutout(uri, coo, radius)
     self.assertIsInstance(hdulist, fits.HDUList)
     self.assertTrue(len(hdulist) > 1)
     for hdu in hdulist[1:]:
         self.assertTrue(hdu.header.get("XOFFSET", False) is not False)
Example #4
0
def cutout(obj, obj_dir, radius):

    cutout_listing = storage.listdir(obj_dir, force=True)
    for obs in obj.mpc_observations:
        if obs.null_observation:
            logging.debug('skipping: {}'.format(obs))
            continue
        if obs.date > parameters.SURVEY_START:
            # can't make postage stamps of earlier linkages
            # can't parse for an obs.comment's exposure number if no
            # obs.comment exists
            try:
                parts = storage.frame2expnum(obs.comment.frame)
            except Exception as ex:
                logging.warning(f"Skipping: {obs}")
                logging.debug(f"Failed to map comment.frame to expnum: {ex}")
                continue
            uri = storage.get_uri(parts['expnum'], version=parts['version'])
            sky_coord = obs.coordinate
            # Using the WCS rather than the X/Y
            # (X/Y can be unreliable over the whole survey)
            postage_stamp_filename = f"{obj.provisional_name}_" \
                                     f"{obs.date.mjd:11.5f}_" \
                                     f"{obs.coordinate.ra.degree:09.5f}_" \
                                     f"{obs.coordinate.dec.degeee:09.5f}.fits"

            if postage_stamp_filename in cutout_listing:
                # skipping existing cutouts
                continue 

            # ast_header = storage._get_sghead(parts['expnum'])
            while True:
              try:
                hdulist = storage.ra_dec_cutout(uri, sky_coord, radius, update_wcs=True)

                with open(postage_stamp_filename, 'w') as tmp_file:
                    hdulist.writeto(tmp_file, overwrite=True, output_verify='fix+ignore')
                    storage.copy(postage_stamp_filename, obj_dir + "/" + postage_stamp_filename)
                os.unlink \
                        (postage_stamp_filename)  # easier not to have them hanging around
              except OSError as e:  # occasionally the node is not found: report and move on for later cleanup
                logging.error("OSError: -> " +str(e))
              except Exception as e:
                logging.error("Exception: -> " +str(e))
                continue
              break
Example #5
0
def cutout(obj, obj_dir, radius):

    cutout_listing = storage.listdir(obj_dir, force=True)
    for obs in obj.mpc_observations:
        if obs.null_observation:
            logging.debug('skipping: {}'.format(obs))
            continue
        if obs.date > parameters.SURVEY_START:  # can't make postage stamps of earlier linkages
            # can't parse for an obs.comment's exposure number if no obs.comment exists
            try:
                parts = storage.frame2expnum(obs.comment.frame)
            except Exception as ex:
                logging.error("Skipping: {}\nFailed to map comment.frame to expnum: {}".format(obs, ex))
                continue
            uri = storage.get_uri(parts['expnum'], version=parts['version'])
            sky_coord = obs.coordinate  # Using the WCS rather than the X/Y (X/Y can be unreliable over the whole survey)
            postage_stamp_filename = "{}_{:11.5f}_{:09.5f}_{:+09.5f}.fits".format(obj.provisional_name,
                                                                                  obs.date.mjd,
                                                                                  obs.coordinate.ra.degree,
                                                                                  obs.coordinate.dec.degree)

            if postage_stamp_filename in cutout_listing:
               # skipping existing cutouts
                continue 

            # ast_header = storage._get_sghead(parts['expnum'])
            while True:
              try:
                hdulist = storage.ra_dec_cutout(uri, sky_coord, radius, update_wcs=True)

                with open(postage_stamp_filename, 'w') as tmp_file:
                    hdulist.writeto(tmp_file, overwrite=True, output_verify='fix+ignore')
                    storage.copy(postage_stamp_filename, obj_dir + "/" + postage_stamp_filename)
                os.unlink(postage_stamp_filename)  # easier not to have them hanging around
              except OSError as e:  # occasionally the node is not found: report and move on for later cleanup
                logging.error("OSError: ->"+str(e))
              except Exception as e:
                logging.error("Exception: ->"+str(e))
                continue
              break
Example #6
0
def cutout(obj, obj_dir, radius):
    print(len([n for n in obj.mpc_observations if not n.null_observation]))
    for obs in obj.mpc_observations:
        print('starting analysis of {}'.format(str(obs)))
        if obs.null_observation:
            print('skipping')
            continue
        if obs.date > parameters.SURVEY_START:  # can't make postage stamps of earlier linkages
            # can't parse for an obs.comment's exposure number if no obs.comment exists
            try:
                expnum = obs.comment.frame.split('p')[0].strip(' ')  # only want calibrated images
            except AttributeError, e:
                print('No comment in this MPC line!')
                continue
            if not expnum.isdigit():
                print('expnum {} parsed from comment line invalid. Check comment parsing.\n{}'.format(
                    expnum, str(obs.comment))
                )
                continue
            uri = storage.get_uri(expnum)
            sky_coord = obs.coordinate  # Using the WCS rather than the X/Y (X/Y can be unreliable over the whole survey)
            print('Trying {} on {} on {}...'.format(obj.provisional_name, obs.date, expnum))
            try:
                hdulist = storage.ra_dec_cutout(uri, sky_coord, radius)
                # if not 'ASTLEVEL' in hdulist[1].header:   # FIXME: activate once all headers are retro-fitted with ASTLEVEL
                #     logging.info('Cutout invalid for use. Skipping inclusion.\n')
                #     continue
                postage_stamp_filename = "{}_{:11.5f}_{:09.5f}_{:+09.5f}.fits".format(obj.provisional_name,
                                                                                      obs.date.mjd,
                                                                                      obs.coordinate.ra.degree,
                                                                                      obs.coordinate.dec.degree)
                print("{}".format(postage_stamp_filename))

                with open(postage_stamp_filename, 'w') as tmp_file:
                    hdulist.writeto(tmp_file, clobber=True)
                    storage.copy(postage_stamp_filename, obj_dir + "/" + postage_stamp_filename)
                os.unlink(postage_stamp_filename)  # easier not to have them hanging around
            except OSError, e:  # occasionally the node is not found: report and move on for later cleanup
                print e
                continue