Esempio n. 1
0
def extract_from_file(fname, n_pixels, threshold, fwhmfilt, isolation_radius,
                      aperture_radius,
                      region_filename=None):
    logger.info('Extracting catalogue from %s', fname)
    with open_fits(fname) as infile:
        header = infile[0].header

    ref_image_id = header['image_id']
    source_table = source_detect(fname,
                                 n_pixels=n_pixels,
                                 threshold=threshold,
                                 fwhmfilt=fwhmfilt,
                                 aperture_radius=aperture_radius)
    logger.info('Found %s sources', len(source_table))
    filtered_source_table = filter_source_table(source_table,
                                                radius=isolation_radius)
    logger.info('Keeping %s sources', len(filtered_source_table))

    if region_filename is not None:
        with RegionFile(region_filename,
                        aperture_radius=aperture_radius) as rfile:
            rfile.add_regions(filtered_source_table, colour='green')
            rfile.add_regions(source_table, colour='red')

    inc_prescan = image_has_prescan(fname)
    logger.debug('Image has prescan: %s', inc_prescan)
    for row in filtered_source_table:
        yield TransmissionCatalogueEntry(
            aperture_radius=aperture_radius,
            ref_image_id=int(ref_image_id),
            x_coordinate=float(row['X_coordinate']),
            y_coordinate=float(row['Y_coordinate']),
            inc_prescan=inc_prescan,
            flux_adu=float(row['Aper_flux_3']))
    def extract_from_file(cls, filename, ref_catalogue, sky_radius_inner,
                          sky_radius_outer):
        with open_fits(filename) as infile:
            image_data = infile[0].data

        source_flux = photometry_local(
            image_data, ref_catalogue.x, ref_catalogue.y,
            ref_catalogue.radius[0], sky_radius_inner, sky_radius_outer)
        return cls(ref_catalogue.x, ref_catalogue.y, ref_catalogue.radius,
                   source_flux)
    def from_file(cls, filename, cursor, sky_radius_inner, sky_radius_outer):
        logger.info('Extracting transmission from %s', filename)
        with open_fits(filename) as infile:
            header = infile[0].header
            image_id = header['image_id']

        photometry_results = extract_photometry_results(
            filename, cursor, image_id, sky_radius_inner, sky_radius_outer)
        photometry_results['image_id'] = image_id

        return cls(**photometry_results)
Esempio n. 4
0
def source_detect(fname, n_pixels, threshold, fwhmfilt, aperture_radius):
    logger.info('Running source detect')
    logger.debug('n_pixels: %s, threshold: %s', n_pixels, threshold)
    with tempfile.NamedTemporaryFile(suffix='.fits') as tfile:
        cmd = ['imcore', fname, 'noconf', tfile.name, n_pixels, threshold,
               '--noell', '--filtfwhm', fwhmfilt, '--rcore', aperture_radius]
        str_cmd = list(map(str, cmd))
        logger.debug('Running command [%s]', ' '.join(str_cmd))
        sp.check_call(str_cmd)
        tfile.seek(0)

        with open_fits(tfile.name) as infile:
            return infile[1].data
Esempio n. 5
0
def get_refcat_id(filename):
    logger.debug("Extracting reference image id from {filename}".format(filename=filename))
    with open_fits(filename) as infile:
        header = infile[0].header

    try:
        return header["agrefimg"]
    except KeyError:
        logger.exception(
            """No autoguider reference image found in file %s.
                            Assuming this is ok and continuing.""",
            filename,
        )
        raise NoAutoguider