def main():

    file_name, interactive = lib_args.get_args()
    header, pixels = lib_fits.read_first_image(file_name)
    background, dispersion, _ = lib_background.compute_background(pixels)

    # search for clusters
    clustering = RecursiveClustering()
    clusters = clustering(pixels, background, dispersion)
    max_cluster = clusters[0]
    wcs = lib_wcs.get_wcs(header)
    pxy = lib_wcs.PixelXY(max_cluster.column, max_cluster.row)
    radec = lib_wcs.xy_to_radec(wcs, pxy)
    cobjects, _, _ = lib_stars.get_celestial_objects(radec)

    # console output
    print(
        'number of clusters: {:2d}, greatest integral: {:7d}, x: {:4.1f}, y: {:4.1f}'
        .format(len(clusters), max_cluster.integral, max_cluster.column,
                max_cluster.row))
    for cobj in cobjects.keys():
        print('celestial object: {}'.format(cobj))

    # graphic output
    if interactive:
        _, axis = plt.subplots()
        axis.imshow(lib_cluster.add_crosses(pixels, clusters))
        plt.show()

    return 0
def main():

    file_name, interactive = lib_args.get_args()
    header, pixels = lib_fits.read_first_image(file_name)
    background, dispersion, _ = lib_background.compute_background(pixels)
    clustering = lib_cluster.Clustering()
    clusters = clustering(pixels, background, dispersion)
    max_cluster = clusters[0]

    # coordinates ra dec
    wcs = lib_wcs.get_wcs(header)

    for i, c in enumerate(clusters):
        show_cluster(wcs, i, c)

    # graphic output
    if interactive:
        import matplotlib.pyplot as plt
        import lib_graphics

        fig, axis = plt.subplots()
        axis.imshow(pixels, interpolation='none')
        fig.canvas.mpl_connect('motion_notify_event',
            lib_graphics.ShowClusterProperties(fig,clusters,ShowCelestialObjects(wcs)))
        plt.show()

    return 0
Beispiel #3
0
def main():

    # analyse command line arguments
    file_name, interactive = lib_args.get_args()
    logging.info('----------------')
    logging.info('name of file: {}'.format(file_name))

    # read fits file
    header, pixels = lib_fits.read_first_image(file_name)
    logging.info('cd1_1: {CD1_1:.10f}'.format(**header))
    logging.info('cd1_2: {CD1_2:.10f}'.format(**header))
    logging.info('cd2_1: {CD2_1:.10f}'.format(**header))
    logging.info('cd2_2: {CD2_2:.10f}'.format(**header))

    # compute background
    background, dispersion, _ = lib_background.compute_background(pixels)
    logging.info('background: {:d}'.format(int(background)))
    logging.info('dispersion: {:d}'.format(int(dispersion)))

    # clustering
    clustering = lib_cluster.Clustering()
    clusters = clustering(pixels, background, dispersion)
    for icl, cl in enumerate(clusters):

        logging.info('----------------')
        logging.info('cluster {:d}: {}'.format(icl, cl))

        # radec coordinates of the greatest cluster
        wcs = lib_wcs.get_wcs(header)
        pxy = lib_wcs.PixelXY(cl.column, cl.row)
        radec = lib_wcs.xy_to_radec(wcs, pxy)
        logging.info('right ascension: {:.3f}'.format(radec.ra))
        logging.info('declination: {:.3f}'.format(radec.dec))

        # celestial objects for the biggest cluster
        cobjects, _, _ = get_celestial_objects(wcs, cl)
        for icobj, cobj in enumerate(cobjects.keys()):
            logging.info('celestial object {}: {}'.format(icobj, cobj))

    # graphic output
    if interactive:
        fig, axis = plt.subplots()
        axis.imshow(pixels, interpolation='none')
        fig.canvas.mpl_connect(
            'motion_notify_event',
            lib_graphics.ShowClusterProperties(fig, clusters,
                                               ShowCelestialObjects(wcs)))
        plt.show()

    logging.info('----------------')
    return 0
Beispiel #4
0
def main():

    file_name, interactive = lib_args.get_args()
    header, pixels = lib_fits.read_first_image(file_name)
    background, dispersion, _ = lib_background.compute_background(pixels)
    clustering = lib_cluster.Clustering()
    clusters = clustering(pixels, background, dispersion)
    max_cluster = clusters[0]

    # coordinates ra dec
    wcs = lib_wcs.get_wcs(header)

    for i, c in enumerate(clusters):
        show_cluster(wcs, i, c)
        break

    return 0
def main():

    file_name, interactive = lib_args.get_args()

    # importing image
    pixels = None
    pixels, header = lib_fits.read_first_image(file_name)
    my_wcs = lib_wcs.get_wcs(header)
    clusters = ex3_clusters.find_clusters(pixels, False)

    for j in range(len(clusters)):
        peak_pixel = lib_wcs.PixelXY(clusters[j].y, clusters[j].x)
        cel_coord = lib_wcs.xy_to_radec(my_wcs, peak_pixel)
        acc_radius = 0.001
        celestial_objects, out, req = lib_stars.get_celestial_objects(
            cel_coord, acc_radius)

        signature_fmt_1 = 'RESULT: right_ascension_{:d} = {:.3f}'.format(
            j, cel_coord[0])
        signature_fmt_2 = 'RESULT: declination_{:d} = {:.3f}'.format(
            j, cel_coord[1])
        print(signature_fmt_1)
        print(signature_fmt_2)
        for i, key in enumerate(celestial_objects.keys()):
            signature_fmt_3 = 'RESULT: celestial_object_{:d}_{:d} = {}'.format(
                j, i, key)
            print(signature_fmt_3)

    # graphic output
    if interactive:
        fig, main_axes = plt.subplots()
        handler = Handler(fig, main_axes, my_wcs)
        main_axes.imshow(pixels)
        #fig.canvas.mpl_connect('motion_notify_event', handler.move)
        fig.canvas.mpl_connect('button_press_event', handler.on_click)

        plt.show()

    # end
    return 0
Beispiel #6
0
def main():

    # analyse command line arguments

    file_name, interactive = lib_args.get_args()

    # importing image
    pixels = None
    pixels, header = lib_fits.read_first_image(file_name)
    my_wcs = lib_wcs.get_wcs(header)

    sorted_clusters = ex3_clusters.find_clusters(pixels, False)

    peak_pixel = lib_wcs.PixelXY(sorted_clusters[0].y, sorted_clusters[0].x)
    cel_coord = lib_wcs.xy_to_radec(my_wcs, peak_pixel)
    acc_radius = 0.001
    celestial_objects, out, req = lib_stars.get_celestial_objects(
        cel_coord, acc_radius)

    signature_fmt_1 = 'RESULT: right_ascension = {:.3f}'.format(cel_coord[0])
    signature_fmt_2 = 'RESULT: declination = {:.3f}'.format(cel_coord[1])
    print(signature_fmt_1)
    print(signature_fmt_2)
    i = 0
    for key in celestial_objects.keys():
        signature_fmt_3 = 'RESULT: celestial_object_{:d} = {}'.format(i, key)
        print(signature_fmt_3)
        i += 1

    # graphic output
    if interactive:
        # ...
        pass

    # end
    return 0
Beispiel #7
0
            label = ' '.join(tokens)
            self.text = plt.text(x, y, label, fontsize=14, color='white')

        self.fig.canvas.draw()


# =====
# Unit test
# =====

if __name__ == '__main__':

    import sys, lib_fits, lib_background, lib_wcs

    filename = '../../data/fits/common.fits'
    header, pixels = lib_fits.read_first_image(filename)
    background, dispersion, _ = lib_background.compute_background(pixels)
    clusters = lib_cluster.convolution_clustering(pixels, background,
                                                  dispersion)
    wcs = lib_wcs.get_wcs(header)

    fig, axis = plt.subplots()
    axis.imshow(pixels, interpolation='none')
    fig.canvas.mpl_connect(
        'motion_notify_event',
        ShowClusterProperties(fig, clusters,
                              lambda cl: ["{}".format(cl.integral)]))
    plt.show()

    sys.exit(0)