def run_ephem_main(reproc=False):
    '''
    The main controller for the module. It executes the code in ephem_main 
    and writes the output to the database.
    '''
    #print 'Processing ' + str(len(file_list)) + ' files.'
    count = 0
    query_list = session.query(MasterFinders, MasterImages).\
        join(MasterImages).\
        options(subqueryload('master_images_rel')).\
        filter(or_(MasterFinders.jpl_ra != None, MasterFinders.jpl_dec != None)).\
        all()

    print 'Processing ' + str(len(query_list)) + ' files.' 
    for record in query_list:
        if record.MasterFinders.ephem_x == None \
                or record.MasterFinders.ephem_y == None \
                or reproc == True:
            file_dict = get_header_info(\
                os.path.join(\
                    record.MasterImages.file_location[0:-4], 
                    record.MasterImages.fits_file))
            delta_x, delta_y = calc_delta(file_dict, record.MasterFinders)
            ephem_x, ephem_y = calc_pixel_position(file_dict, delta_x, delta_y)
            update_dict = {}
            update_dict['ephem_x'] = int(ephem_x)
            update_dict['ephem_y'] = int(ephem_y)
            session.query(MasterFinders).\
                filter(MasterFinders.id == record.MasterFinders.id).\
                update(update_dict)
        count = counter(count)
    session.commit()
    session.close()
def build_finders_table_main(reproc):
    '''
    Calculate the ephemeris information for the subimages.
    '''
    query = session.query(MasterFinders).count()
    print str(query) + ' total ephemerides'
    query = session.query(MasterFinders, MasterImages)\
        .join(MasterImages, MasterImages.id == MasterFinders.master_images_id)\
        .filter(MasterFinders.ephem_x >= 0)\
        .filter(MasterFinders.ephem_y >= 0)\
        .filter(MasterFinders.ephem_x <= 1725)\
        .filter(MasterFinders.ephem_y <= 1300)\
        .filter(MasterImages.drz_mode == 'wide')\
        .all()
    print str(len(query)) + ' ephemerides in wide mode image FOVs'

    count = 0
    for record in query:
        count = counter(count)
        region_list = get_region_list(record.MasterFinders.ephem_x, record.MasterFinders.ephem_y)
        for region in region_list:
            add_new_record(record, region)
    session.commit()
    session.close()
    parse the command line arguments.
    '''
    parser = argparse.ArgumentParser(
        description = 'Populates the sub_images table from a PNG file list.')
    parser.add_argument(
        '-filelist',
        required = True,
        help = 'Search string for files. Wildcards accepted.')
    parser.add_argument(
        '-reproc',
        required = False,
        action = 'store_true',        
        default = False,
        dest = 'reproc',
        help = 'Overwrite existing entries.')
    args = parser.parse_args()
    return args

#----------------------------------------------------------------------------

if __name__ == '__main__':
    args = parse_args()
    filelist = glob.glob(args.filelist)
    print 'Processing ' + str(len(filelist)) + ' files.'
    assert isinstance(filelist, list), \
        'Expected list for filelist, got ' + str(type(filelist))
    count = 0
    for filename in filelist:
        count = counter(count)
        build_sub_images_table_main(filename, args.reproc)
Example #4
0
    '''
    parser = argparse.ArgumentParser(
        description = 'Populate the database with the jpl coordinates.')
    parser.add_argument(
        '-filelist',
        required = True,
        help = 'Search string for FITS files. Wildcards accepted.')
    parser.add_argument(
        '-reproc',
        required = False,
        action = 'store_true',        
        default = False,
        dest = 'reproc',
        help = 'Overwrite existing entries.')
    args = parser.parse_args()
    return args

#----------------------------------------------------------------------------

if __name__ == '__main__':
    args = parse_args()
    filelist = glob.glob(args.filelist)
    assert isinstance(filelist, list), \
        'Expected list for filelist, got ' + str(type(filelist))
    assert filelist != [], 'No files found.'
    print 'Processing ' + str(len(filelist)) + ' files.'
    count = 0
    for filename in filelist:
        jpl2db_main(filename, args.reproc)
        count = counter(count, update = 10)