Ejemplo n.º 1
0
def find_objects_by_phot(family_name, aperture, thresh, imagetype):
    """
    For a given family name and object name, preforms photometry and identifies object in the image.
    If only a family name is given, does the same for all objects in that family
    """

    # get CADC authentification
    username = raw_input("CADC username: "******"CADC password: "******"\n {} --- Searching for asteroid {} in image {} ".format(row, table['Object'][row], table['Image'][row])

        expnum = (table['Image'][row]).strip('{}'.format(imagetype))
        if expnum in tkbad_list:
            print '-- Bad exposure'

        else:
            postage_stamp_filename = "{}_{}_{:8f}_{:8f}.fits".format(table['Object'][row], table['Image'][row],
                                                                     table['RA'][row], table['DEC'][row])

            if not storage.exists('{}/{}'.format(vos_dir, postage_stamp_filename)):
                print '-- Cutout not found, creating new cutout'
                get_stamps.cutout(username, password, family_name, table['Object'][row], table['Image'][row],
                                  table['RA'][row], table['DEC'][row], _RADIUS)
            if not storage.exists('{}/{}'.format(vos_dir, postage_stamp_filename)):
                with open('{}/{}/{}'.format(_OUTPUT_DIR, family_name, _OUTPUT_VOS_ERR), 'a') as outfile:
                    outfile.write('{} {}\n'.format(table['Object'][row], table['Image'][row]))
            else:
                success = False
                attempts = 0
                while (success is False) and (attempts < 3):
                    success = iterate_thru_images(family_name, str(table['Object'][row]), table['Image'][row], username,
                                                  password, aperture, thresh)
                    attempts += 1
                    if attempts == 3:
                        print ' >>>> Last attempt \n'
Ejemplo n.º 2
0
Archivo: ssos.py Proyecto: R136a1-/MOP
    def build_source_reading(self, expnum, ccd, X, Y):
        """
        Given the location of a source in the image, create a source reading.

        """

        image_uri = storage.dbimages_uri(expnum=expnum,
                                         ccd=None,
                                         version='p',
                                         ext='.fits',
                                         subdir=None)
        logger.debug('Trying to access {}'.format(image_uri))

        if not storage.exists(image_uri, force=False):
            logger.warning('Image not in dbimages? Trying subdir.')
            image_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=ccd,
                                             version='p')

        if not storage.exists(image_uri, force=False):
            logger.warning("Image doesn't exist in ccd subdir. %s" % image_uri)
            return None

        slice_rows=config.read("CUTOUTS.SINGLETS.SLICE_ROWS")
        slice_cols=config.read("CUTOUTS.SINGLETS.SLICE_COLS")

        if X == -9999 or Y == -9999  :
            logger.warning("Skipping {} as x/y not resolved.".format(image_uri))
            return None

        if not (-slice_cols/2. < X < 2048+slice_cols/2. and -slice_rows/2. < Y < 4600+slice_rows/2.0):
            logger.warning("Central location ({},{}) off image cutout.".format(X,Y))
            return None

        mopheader_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=ccd,
                                             version='p',
                                             ext='.mopheader')
        if not storage.exists(mopheader_uri, force=False):
            # ELEVATE! we need to know to go off and reprocess/include this image.
            logger.critical('Image exists but processing incomplete. Mopheader missing. {}'.format(image_uri))
            return None


        mopheader = get_mopheader(expnum, ccd)


        # Build astrom.Observation
        observation = astrom.Observation(expnum=str(expnum),
                                         ftype='p',
                                         ccdnum=str(ccd),
                                         fk="")

        observation.rawname = os.path.splitext(os.path.basename(image_uri))[0]+str(ccd).zfill(2)

        observation.header = mopheader

        return observation
Ejemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser(
        description='For a given set of fits images: preforms photometry, identifies a specific object, and returns \
                        the orbital elements of the object')
    parser.add_argument("--family", '-f',
                        action="store",
                        default='all',
                        help="Asteroid family name. Usually the asteroid number of the largest member.")
    parser.add_argument("--aperture", '-ap',
                        action='store',
                        default=10.0,
                        help='aperture (degree) of circle for photometry.')
    parser.add_argument("--thresh", '-t',
                        action='store',
                        default=3.,
                        help='threshold value for photometry (sigma above background).')
    parser.add_argument("--object", '-o',
                        action='store',
                        default=None,
                        help='The object to be identified.')
    parser.add_argument("--expnum", '-x',
                        action='store',
                        default=None,
                        help='The exposure that the object is in.')
    parser.add_argument('--type',
                        default='p',
                        choices=['o', 'p', 's'],
                        help="restrict type of image (unprocessed, reduced, calibrated)")

    args = parser.parse_args()

    if args.object is None:
        find_objects_by_phot(args.family, float(args.aperture), float(args.thresh), args.type)
    else:
        assert args.expnum.endswith('p') or args.expnum.endswith('o'), "Must include 'p' or 'o' in expnum"
        image_list_path = '{}/{}_{}'.format(_IMAGE_LISTS, args.family, _INPUT_FILE)
        table = pd.read_table(image_list_path, sep='\t', dtype={'Object': object, 'Image': object}, index_col=False)
        lines = table[(table.Object == args.object) & (table.Image == args.expnum)]
        print lines
        username = raw_input("CADC username: "******"CADC password: "******"{}_{}_{:8f}_{:8f}.fits".format(args.object, args.expnum, float(lines.RA.values[0]),
                                                                 float(lines.DEC.values[0]))
        if not storage.exists('{}/all/{}'.format(_VOS_DIR, postage_stamp_filename)):
            print '-- Cutout not found, creating new cutout'
            get_stamps.cutout(username, password, args.family, args.object, args.expnum, lines.RA.values[0],
                              lines.DEC.values[0], _RADIUS)
        assert storage.exists('{}/all/{}'.format(_VOS_DIR, postage_stamp_filename)), 'Error: Cutout not found'
        iterate_thru_images(args.family, args.object, args.expnum, username, password, float(args.aperture),
                            float(args.thresh))
Ejemplo n.º 4
0
    def from_source_reference(expnum, ccd, X, Y):
        """
        Given the location of a source in the image, create a source reading.
        """

        image_uri = storage.dbimages_uri(expnum=expnum,
                                         ccd=None,
                                         version='p',
                                         ext='.fits',
                                         subdir=None)
        logger.debug('Trying to access {}'.format(image_uri))

        if not storage.exists(image_uri, force=False):
            logger.warning('Image not in dbimages? Trying subdir.')
            image_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=ccd,
                                             version='p')

        if not storage.exists(image_uri, force=False):
            logger.warning("Image doesn't exist in ccd subdir. %s" % image_uri)
            return None

        if X == -9999 or Y == -9999 :
            logger.warning("Skipping {} as x/y not resolved.".format(image_uri))
            return None


        mopheader_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=ccd,
                                             version='p',
                                             ext='.mopheader')
        if not storage.exists(mopheader_uri, force=False):
            # ELEVATE! we need to know to go off and reprocess/include this image.
            logger.critical('Image exists but processing incomplete. Mopheader missing. {}'.format(image_uri))
            return None


        mopheader = storage.get_mopheader(expnum, ccd)

        # Build astrom.Observation
        observation = Observation(expnum=str(expnum),
                                         ftype='p',
                                         ccdnum=str(ccd),
                                         fk="")

        observation.rawname = os.path.splitext(os.path.basename(image_uri))[0]+str(ccd).zfill(2)

        observation.header = mopheader

        return observation
Ejemplo n.º 5
0
def fits_data(object_name, expnum, family_name):
    """
    Creates local copy of fits file from VOSpace
    """

    if family_name == 'none':
        vos_dir = '{}/none'.format(_VOS_DIR)
    else:
        vos_dir = '{}/all'.format(_VOS_DIR)

    assert storage.exists(vos_dir), 'Vos directory does not exist, or permissions have expired'
    for fits_file in client.listdir(vos_dir):  # images named with convention: object_expnum_RA_DEC.fits

        if fits_file.endswith('.fits'):
            objectname_file = fits_file.split('_')[0]
            expnum_file = fits_file.split('_')[1]
            if (expnum_file == expnum) and (objectname_file == object_name):
                file_path = '{}/{}'.format(_STAMPS_DIR, fits_file)
                storage.copy('{}/{}'.format(vos_dir, fits_file), file_path)

                with fits.open(file_path) as hdulist:
                    data = hdulist[0].data
                    header = hdulist[0].header

                os.unlink(file_path)
                return header, data, fits_file
Ejemplo n.º 6
0
def parse_ssois_return(ssois_return, object_name, imagetype, camera_filter='r.MP9601',
                       telescope_instrument='CFHT/MegaCam'):
    """
    Parse through objects in ssois query and filter out images of desired filter, type, exposure time, and instrument
    """

    assert camera_filter in ['r.MP9601', 'u.MP9301']

    ret_table = []
    good_table = 0

    table_reader = ascii.get_reader(Reader=ascii.Basic)
    table_reader.inconsistent_handler = _skip_missing_data
    table_reader.header.splitter.delimiter = '\t'
    table_reader.data.splitter.delimiter = '\t'
    table = table_reader.read(ssois_return)

    for row in table:
        # Excludes the OSSOS wallpaper.
        # note: 'Telescope_Insturment' is a typo in SSOIS's return format
        if not 'MegaCam' in row['Telescope_Insturment']:
            continue
        if not storage.exists(storage.get_uri(row['Image'][:-1])):  #Check if image of object exists in OSSOS observations
            continue
        if not str(row['Image_target']).startswith('WP'):
           good_table += 1
           ret_table.append(row)

    if good_table > 0:
        print " %d images found" % good_table

    return ret_table
Ejemplo n.º 7
0
def parse_ssois_return(ssois_return, object_name, imagetype, camera_filter='r.MP9601',
                       telescope_instrument='CFHT/MegaCam'):
    """
    Parse through objects in ssois query and filter out images of desired filter, type, exposure time, and instrument
    """

    assert camera_filter in ['r.MP9601', 'u.MP9301']

    ret_table = []
    good_table = 0

    table_reader = ascii.get_reader(Reader=ascii.Basic)
    table_reader.inconsistent_handler = _skip_missing_data
    table_reader.header.splitter.delimiter = '\t'
    table_reader.data.splitter.delimiter = '\t'
    table = table_reader.read(ssois_return)

    for row in table:
        # Excludes the OSSOS wallpaper.
        # note: 'Telescope_Insturment' is a typo in SSOIS's return format
        if not 'MegaCam' in row['Telescope_Insturment']:
            continue
        # Check if image of object exists in OSSOS observations
        if not storage.exists(storage.get_uri(row['Image'][:-1])):
            continue
        if not str(row['Image_target']).startswith('WP'):
           good_table += 1
           ret_table.append(row)

    if good_table > 0:
        print((" %d images found" % good_table))

    return ret_table
Ejemplo n.º 8
0
    def from_source_reference(expnum, ccd, x, y):
        """
        Given the location of a source in the image, create a source reading.
        """

        image_uri = storage.dbimages_uri(expnum=expnum,
                                         ccd=None,
                                         version='p',
                                         ext='.fits',
                                         subdir=None)
        logger.debug('Trying to access {}'.format(image_uri))

        if not storage.exists(image_uri, force=False):
            logger.warning('Image not in dbimages? Trying subdir.')
            image_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=ccd,
                                             version='p')

        if not storage.exists(image_uri, force=False):
            logger.warning("Image doesn't exist in ccd subdir. %s" % image_uri)
            return None

        if x == -9999 or y == -9999:
            logger.warning(
                "Skipping {} as x/y not resolved.".format(image_uri))
            return None

        mopheader_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=ccd,
                                             version='p',
                                             ext='.mopheader')
        if not storage.exists(mopheader_uri, force=False):
            # ELEVATE! we need to know to go off and reprocess/include this image.
            logger.critical(
                'Image exists but processing incomplete. Mopheader missing. {}'
                .format(image_uri))
            return None

        # Build astrom.Observation
        observation = Observation(expnum=str(expnum),
                                  ftype='p',
                                  ccdnum=str(ccd),
                                  fk="")
        observation.rawname = os.path.splitext(
            os.path.basename(image_uri))[0] + str(ccd).zfill(2)

        return observation
Ejemplo n.º 9
0
def main():
    parser = argparse.ArgumentParser(
        description='Parse a directory of TNO .ast files and create links in the postage stamp directory '
                    'that allow retrieval of cutouts of the FITS images associated with the OSSOS detections. '
                    'Cutouts are defined on the WCS RA/DEC of the object position.')

    parser.add_argument("version",
                        help="The OSSOS data release version these stamps should be assigned to.")
    parser.add_argument("--ossin",
                        action="store",
                        default="vos:OSSOS/dbaseclone/ast/",
                        help="The vospace containerNode that clones ossin dbaseclone"
                             "holding the .ast files of astrometry/photometry measurements.")
    parser.add_argument("--blocks", "-b",
                        action="store",
                        default=["o3e", "o3o"],
                        choices=["o3e", "o3o", "O13BL", "Col3N"],
                        help="Prefixes of object designations to include.")
    parser.add_argument("--radius", '-r',
                        action='store',
                        default=0.02,
                        help='Radius (degree) of circle of cutout postage stamp.')
    parser.add_argument("--debug", "-d",
                        action="store_true")
    parser.add_argument("--verbose", "-v",
                        action="store_true")

    args = parser.parse_args()

    username = raw_input("CADC username: "******"CADC password: ")

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    elif args.verbose:
        logging.basicConfig(level=logging.INFO)

    for fn in storage.listdir(args.ossin)[10:11]:  #FIXME: TESTING ONLY
        obj = mpc.MPCReader(args.ossin + fn)  # let MPCReader's logic determine the provisional name
        for block in args.blocks:
            if obj.provisional_name.startswith(block):
                obj_dir = '{}/{}/{}'.format(storage.POSTAGE_STAMPS, args.version, obj.provisional_name)
                if not storage.exists(obj_dir, force=True):
                    storage.mkdir(obj_dir)
                # assert storage.exists(obj_dir, force=True)
                cutout(obj, obj_dir, args.radius, username, password)
Ejemplo n.º 10
0
def update_vos_with_local_files(user_id, vos_dir, dir_to_scan):
    uploaded_count = 0
    donefiles = glob(dir_to_scan + '*.reals.astrom')
    for fname in donefiles:
        fn = fname.rsplit('/')[len(fname.rsplit('/')) - 1]
        vo_reals = vos_dir + fn
        mv_file = vos_dir + fn.replace('reals', 'cands')
        # check if file's .cands.astrom equivalent in VOSpace has a #done tag
        wasdone = storage.get_property(mv_file, 'done')
        if not wasdone:
            if not storage.exists(vo_reals):  # shouldn't possibly be there but let's just make sure
                storage.copy(fname, vo_reals)
                storage.set_property(mv_file, 'done', user_id)  # set the .cands.astrom #done tag to the user ID.
                uploaded_count += 1
        else:
            print fn, wasdone

    print 'Added unique files:', uploaded_count

    return
Ejemplo n.º 11
0
def main(commands=['update_header', 'mkpsf', 'step1', 'step2', 'step3', 'combine'], 
         ccds=range(0,36),
         launch=False, triplets_dir=TRIPLETS_NODE,
         delete=False):
   
    cmd_order={'LEAD': ['update_header', 'mkpsf', 'step1', 'step2', 'step3', 'combine'],
               'OTHER': ['update_header', 'mkpsf', 'step1' ] }
 
    existance = {'mkpsf': ['psf.fits', ],
                 'step1': ['obj.jmp', 'obj.matt'],
                 'step2': ['unid.jmp', 'unid.matt'],
                 'step3': ['cands.jmp', 'cands.matt']}

    for line in get_triplets(triplets_dir):
        for command in commands:        
            exp_type = 'LEAD'
            for expnum in line[0:3]:
                tags = storage.get_tags(expnum)
                if command not in cmd_order[exp_type]:
                    continue
                for ccd in ccds:
                    tag = storage.tag_uri(storage.get_process_tag(command, ccd))
                    print line[3], command, expnum, ccd, tags.get(tag,None)
                    if tags.get(tag,None) != storage.SUCCESS:
                        if launch:
                            submit(command, expnum, ccd)
                        if delete:
                            success=True
                            for ext in existance[command]:
                                uri = storage.dbimages_uri(expnum, ccd, version='p', ext=ext)
                                if not storage.exists(uri):
                                    success=False
                            print expnum, ccd, success
                            #for next_command in cmd_order[exp_type][commands.index(command)+1:]:
                            #    storage.set_status(expnum, ccd, next_command, command+" FAILED")
                        if success:
                            storage.set_status(expnum, ccd, command, version='p', status='success')
                exp_type='OTHER'
Ejemplo n.º 12
0
def get_fits_data(object_name, expnum_p, family_name, ap, th):
    """
    Finds image in VOSpace, determines number of extensions, inputs parameters aperture and threshold into the photometry method,
    returns photometry measurements and header values
    """

    try:
        if family_name == 'none':
            vos_dir = '{}/none'.format(_VOS_DIR)
        else:
            vos_dir = '{}/all'.format(_VOS_DIR)

        assert storage.exists(vos_dir)
        for fits_file in client.listdir(vos_dir):  # images named with convention: object_expnum_RA_DEC.fits

            if fits_file.endswith('.fits'):
                objectname_file = fits_file.split('_')[0]
                expnum_file = fits_file.split('_')[1]

                if (expnum_file == expnum_p) and (objectname_file == object_name):
                    file_path = '{}/{}'.format(_STAMPS_DIR, fits_file)
                    storage.copy('{}/{}'.format(vos_dir, fits_file), file_path)

                    data = fits.getdata(file_path)
                    header = fits.getheader(file_path)
                    objs = sep_phot(data, ap, th)

                    os.unlink(file_path)

                    return objs, header, data

    except TypeError:
        print "WARNING: Image does not exist for {} {}".format(object_name, expnum_p)
        raise
    except Exception, e:
        print 'Error retrieving fits data: {}'.format(e)
        write_to_error_file(object_name, expnum_p, out_filename=_OUTPUT_PHOT_ERR, family_name=family_name)
        raise
Ejemplo n.º 13
0
def scramble(expnums, ccd, version='p'):
    '''run the plant script on this combination of exposures'''

    mjds = []
    fobjs = []
    for expnum in expnums:
        filename = storage.get_image(expnum, ccd=ccd, version=version)
        fobjs.append(fits.open(filename))
        # Pull out values to replace in headers.. must pull them
        # as otherwise we get pointers...
        mjds.append(fobjs[-1][0].header['MJD-OBS'])

    order = [1,0,2]
    for idx in range(len(fobjs)):
        logging.info("Flipping %d to %d" % ( fobjs[idx][0].header['EXPNUM'],
                                             expnums[order[idx]]))
        fobjs[idx][0].header['EXPNUM'] = expnums[order[idx]]
        fobjs[idx][0].header['MJD-OBS'] = mjds[order[idx]]
        uri = storage.get_uri(expnums[order[idx]],
                                ccd=ccd,
                                version='s',
                                ext='fits')
        fname = os.path.basename(uri)
        if os.access(fname, os.F_OK):
            os.unlink(fname)
        fobjs[idx].writeto(fname)
        storage.copy(fname, uri)

        # now make a link between files that the plant system will need
        for ext in ['apcor', 'obj.jmp', 'mopheader', 'phot',
                    'psf.fits','trans.jmp', 'zeropoint.used', 'fwhm']:
            if storage.exists(storage.get_uri(expnums[order[idx]], ccd, 's', ext)):
                storage.delete(expnums[order[idx]], ccd, 's', ext)
                storage.vlink(expnums[idx], ccd, 'p', ext,
                         expnums[order[idx]], ccd, 's', ext)

    return
Ejemplo n.º 14
0
 def exists(self, filename):
     return storage.exists(self.get_full_path(filename))
Ejemplo n.º 15
0
Archivo: ssos.py Proyecto: drusk/MOP
    def parse(self, ssos_result_filename_or_lines):
        """
        given the result table create 'source' objects.

        :type ssos_result_table: Table
        :param ssos_result_table:
        """
        table_reader = ascii.get_reader(Reader=ascii.Basic)
        table_reader.inconsistent_handler = self._skip_missing_data
        table_reader.header.splitter.delimiter = '\t'
        table_reader.data.splitter.delimiter = '\t'
        table = table_reader.read(ssos_result_filename_or_lines)

        sources = []
        observations = []
        source_readings = []

        ref_pvwcs = None
        downloader = Downloader()
        warnings.filterwarnings('ignore')

        for row in table:
            # check if a dbimages object exists
            ccd = int(row['Ext']) - 1
            expnum = row['Image'].rstrip('p')

            # ADDING THIS TEMPORARILY TO GET THE NON-OSSOS DATA OUT OF THE WAY WHILE DEBUGGING
            if (row['Telescope_Insturment'] != 'CFHT/MegaCam') or (row['Filter'] != 'r.MP9601'):
                continue

            # it's fine for OSSOS, go get the image
            image_uri = storage.dbimages_uri(expnum=expnum,
                                             ccd=None,
                                             version='p',
                                             ext='.fits',
                                             subdir=None)
            logger.info('Trying to access %s\n%s' % (row.data, image_uri))

            if not storage.exists(image_uri, force=False):
                logger.warning('Image not in dbimages? Trying subdir.')
                image_uri = storage.dbimages_uri(expnum=expnum,
                                                 ccd=ccd,
                                                 version='p')

                if not storage.exists(image_uri, force=False):
                    logger.warning("Image doesn't exist in ccd subdir. %s" % image_uri)
                    continue

            if row['X'] == -9999 or row['Y'] == -9999 :
                logger.warning("Skipping %s as x/y not resolved." % ( row['Image']))
                continue

            mopheader_uri = storage.dbimages_uri(expnum=expnum,
                                                 ccd=ccd,
                                                 version='p',
                                                 ext='.mopheader')

            if not mopheader_uri in mopheaders:
                if not storage.exists(mopheader_uri, force=False):
                    logger.warning('mopheader missing, but images exists')
                    continue

                # raise flag if no MOPHEADER
                mopheader_fpt = cStringIO.StringIO(storage.open_vos_or_local(mopheader_uri).read())
                mopheader = fits.open(mopheader_fpt)
                mopheaders[mopheader_uri] = mopheader
            mopheader = mopheaders[mopheader_uri]
            
            # Build astrom.Observation
            observation = astrom.Observation(expnum=str(expnum),
                                             ftype='p',
                                             ccdnum=str(ccd),
                                             fk="")

            observation.rawname = os.path.splitext(os.path.basename(image_uri))[0]+str(ccd).zfill(2)

            observation.header = mopheader[0].header
            MJD_OBS_CENTER = mpc.Time(observation.header['MJD-OBSC'],
                                      format='mjd',
                                      scale='utc', precision=5 ).replicate(format='mpc')
            observation.header['MJD_OBS_CENTER'] = str(MJD_OBS_CENTER)
            observation.header['MAXCOUNT'] = MAXCOUNT
            observation.header['SCALE'] = observation.header['PIXSCALE']
            #observation.header['CHIP'] = str(observation.header['CHIPNUM']).zfill(2)
            observation.header['NAX1'] = observation.header['NAXIS1']
            observation.header['NAX2'] = observation.header['NAXIS2']
            observation.header['MOPversion'] = observation.header['MOP_VER']
            observation.header['FWHM'] = 4



            # a download pixel 1,1 of this data to due offsets with.
            x_cen = int(min(max(1,row['X']),observation.header['NAX1']))
            y_cen = int(min(max(1,row['Y']),observation.header['NAX2']))
            if image_uri not in astheaders:
               hdulist = downloader.download_hdulist(
                   uri=image_uri,
                   view='cutout',
                   cutout='[{}][{}:{},{}:{}]'.format(ccd+1, x_cen, x_cen, y_cen, y_cen))
               astheaders[image_uri] = hdulist
            hdulist = astheaders[image_uri]

            pvwcs = wcs.WCS(hdulist[0].header)
            (ra,dec)  = pvwcs.xy2sky(x_cen, y_cen)
            if ref_pvwcs is None:
                ref_pvwcs = pvwcs
                xref = row['X']
                yref = row['Y']
            (x0, y0) = ref_pvwcs.sky2xy(ra,dec)
            x0 += row['X'] - x_cen
            y0 += row['Y'] - y_cen

            # Build astrom.SourceReading
            observations.append(observation)

            from_input_file = observation.rawname in self.input_rawnames
            null_observation = observation.rawname in self.null_observations

            print observation.rawname, observation.header['MJD_OBS_CENTER'], null_observation, from_input_file

            source_reading = astrom.SourceReading(x=row['X'], y=row['Y'],
                                                        xref=xref, yref=yref,
                                                        x0=x0, y0=y0,
                                                        ra=row['Object_RA'], dec=row['Object_Dec'],
                                                        obs=observation,
                                                        ssos=True,
                                                        from_input_file=from_input_file,
                                                        null_observation=null_observation)
            #if observation.rawname in  self.input_rawnames:
            #    source_readings.insert(0, source_reading)
            #else:
            source_readings.append(source_reading)
        # build our array of SourceReading objects
        sources.append(source_readings)

        warnings.filterwarnings('once')

        return SSOSData(observations, sources, self.provisional_name)
Ejemplo n.º 16
0
    storage.DBIMAGES = args.dbimages
    storage.MEASURE3 = args.measure3

    ## only measure if we have completed 'reals' on this file.
    reals_filepath = ( args.reals is not None and args.reals ) or args.measure3
    cands_filepath = args.measure3
    cands_filelist = storage.my_glob(cands_filepath+"/fk*.cands.astrom")

    eff_file_list = []
    for cands in cands_filelist:
        cands_filename = os.path.basename(cands)
        if os.path.exists(cands_filename+".eff"):
            logger.info("{}.eff exists, skipping".format(cands_filename))
            continue
        reals_filename = reals_filepath + cands_filename.replace('cands','reals')
        if not (( reals_filename[0:4] == 'vos:' and storage.exists(reals_filename+".DONE") ) or os.access(reals_filename+".DONE",os.R_OK)) :
            # skipping incomplete field/ccd combo
            continue
        sys.stderr.write("Getting list of .mpc files for input "+reals_filename+" ...")
        # find and load any .mpc files associated with this candidate file.
        mpc_list = storage.my_glob(reals_filename+".*.mpc")
        sys.stderr.write(" got {} detections \n".format(len(mpc_list)))
        if not len(mpc_list) > 0 :
            continue
        measures =  {}
        for mpc_fname in mpc_list:
            provisional = mpc_fname.split(".")[-2]
            measures[provisional] = []
            for line in open(mpc_fname,'r').readlines():
                measures[provisional].append(mpc.Observation.from_string(line))
Ejemplo n.º 17
0
    return


def fix_tags_on_cands_missing_reals(user_id, vos_dir, property):
    "At the moment this just checks for a single user's missing reals. Easy to generalise it to all users: modify the
    and"
    con = context.get_context(vos_dir)
    user_progress = []
    listing = con.get_listing(tasks.get_suffix('cands'))
    for filename in listing:
        user = storage.get_property(con.get_full_path(filename), property)
        if (user is not None) and (
            user == user_id):  # modify here to generalise to all users with work in this directory
            user_progress.append(filename)
            realsfile = filename.replace('cands', 'reals')
            if not storage.exists(con.get_full_path(realsfile)):
                print filename, 'no reals file', realsfile
                storage.set_property(con.get_full_path(filename), property, None)

    print 'Fixed files:', len(user_progress)

    return


if __name__=='__main__':
    user_id = ''  # set as appropriate
    vos_dir = storage.MEASURE3 + '/2013A-O/'
    dir_to_scan = '/Users/michele/Dropbox/OSSOS/measure3/2013A-O/ptsws/'

    #update_vos_with_local_files(user_id, vos_dir, dir_to_scan)
    fix_tags_on_cands_missing_reals(user_id, vos_dir, DONE_PROPERTY)  # can also be LOCK_PROPERTY
Ejemplo n.º 18
0
 def exists(self, filename):
     return storage.exists(self.get_full_path(filename))
Ejemplo n.º 19
0
def main():
    parser = argparse.ArgumentParser(
        description='Parse a directory of TNO .ast files and create links in the postage stamp directory '
                    'that allow retrieval of cutouts of the FITS images associated with the OSSOS detections. '
                    'Cutouts are defined on the WCS RA/DEC of the object position.')

    parser.add_argument("version",
                        help="The OSSOS data release version these stamps should be assigned to. e.g. v8")
    parser.add_argument("--ossin",
                        action="store",
                        default="vos:OSSOS/0_OSSOSreleases/OSSOS",
                        help="The vospace containerNode that clones ossin dbaseclone"
                             "holding the .ast files of astrometry/photometry measurements.")
    parser.add_argument("--blocks", "-b",
                        action="store",
                        default=['o3e', 'o3o', 'o3l', 'o4h', 'o5p', 'o5m', 'o5s', 'o5t'],
                        choices=["o3e", "o3o", "Col3N", 'o3l', 'o4h', 'o5m', 'o5p', 'o5s', 'o5t', 'o5c', 'o5d'],
                        help="Prefixes of object designations to include.")
    parser.add_argument("--radius", '-r',
                        # FIXME: figure out how to assign this a unit.degree before storage
                        action='store',
                        default=0.01 * units.degree,  # about 200 px square
                        help='Radius (degree) of circle of cutout postage stamp.')
    parser.add_argument("--debug", "-d",
                        action="store_true")
    parser.add_argument("--verbose", "-v",
                        action="store_true")
    parser.add_argument("--recheck",
                        default=None,
                        action="store",
                        help="A tuple of TNO IDs to rerun")


    args = parser.parse_args()
    print args

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    elif args.verbose:
        logging.basicConfig(level=logging.INFO)


    astdir = parameters.L7_HOME + 'OSSOS' + args.version + '/ast/'
    print astdir
    flist = os.listdir(astdir)
    if args.recheck:
        flist = [args.recheck + '.ast']
        print flist

    for fn in flist:
        for block in args.blocks:
            if fn.startswith(block):
                obj_dir = '{}/{}/{}'.format(storage.POSTAGE_STAMPS, args.version, fn.partition('.')[0]) # obj.provisional_name
                print obj_dir
                if args.recheck is None:  # otherwise if rechecking, it'll have already been started
                    if not storage.exists(obj_dir, force=True):
                        storage.mkdir(obj_dir)
                    else:
                        print(fn)
                        continue   # good if the object has already had its stamps cut
                obj = mpc.MPCReader(astdir + fn)
                # assert storage.exists(obj_dir, force=True)
                print('{} beginning...\n'.format(obj.provisional_name))
                # if int(obj.provisional_name[3:]) == 49:
                assert isinstance(args.radius, Quantity)
                cutout(obj, obj_dir, args.radius)
                print('{} complete.\n'.format(obj.provisional_name))