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
示例#2
0
def show_cluster(wcs, i, cluster):
    #print('DEBUG: {} cluster={} {} {}'.format(i, cluster.integral, cluster.column, cluster.row))

    pxy = lib_wcs.PixelXY(cluster.column, cluster.row)
    radec = lib_wcs.xy_to_radec(wcs, pxy)

    print('RESULT: right_ascension_{:d} = {:.3f}'.format(i,radec.ra))
    print('RESULT: declination_{:d} = {:.3f}'.format(i,radec.dec))

    os, _, _ = get_celestial_objects(wcs, cluster)
    for j, cobj in enumerate(os):
        print('RESULT: celestial_object_{:d}_{:d} = {}'.format(i,j,cobj))
示例#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
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
    def on_click(self, event):
        if event.button == 1:
            # Create a transformation matrix
            axis = event.inaxes
            for txt in self.texts:
                txt.remove()
            for patch in self.patches:
                patch.remove()
            self.texts = []
            self.patches = []
            display_to_image = axis.transData.inverted()
            # Image coordinates returned as a list
            image_x_y = display_to_image.transform((event.x, event.y))
            peak_pixel = lib_wcs.PixelXY(*image_x_y)
            cel_coord = lib_wcs.xy_to_radec(self.wcs, peak_pixel)
            #text = axis.text(*image_x_y, str(cel_coord[0]) + "\n" + str(cel_coord[1]), fontsize=10, color='white')
            acc_radius = 0.001
            celestial_objects, out, req = lib_stars.get_celestial_objects(
                cel_coord, acc_radius)

            for i, key in enumerate(celestial_objects.keys()):
                patch = axis.add_patch(
                    patches.Rectangle(image_x_y - 5,
                                      10,
                                      10,
                                      fill=False,
                                      color='white'))

                text = axis.text(image_x_y[0] + 6,
                                 image_x_y[1] - i * 5,
                                 key,
                                 fontsize=10,
                                 color='white')
                self.patches.append(patch)
                self.texts.append(text)
                print(key)

            event.canvas.draw()

        return
示例#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
示例#7
0
def get_celestial_objects(wcs, cluster):

    pxy = lib_wcs.PixelXY(cluster.column, cluster.row)
    radec = lib_wcs.xy_to_radec(wcs, pxy)
    return lib_stars.get_celestial_objects(radec)
示例#8
0
    if ((cl.row < pattern_diameter) or
            (cl.row >= (pixels.shape[0]-pattern_diameter)) or
            (cl.column < pattern_diameter) or
            (cl.column >= (pixels.shape[1]-pattern_diameter))):
        print('cluster {:d} is in the border'.format(icl, cl))
        nb_patho += 1

# check max integral clusters are not too similar
if len(clusters) > 1 and ((clusters[0].integral - clusters[1].integral) < 10.):
    print('clusters 0 and 1 are too similar')
    nb_patho += 1

# check lacking or multiple celestial objects for max cluster
wcs = lib_wcs.get_wcs(header)
pxy = lib_wcs.PixelXY(clusters[0].column, clusters[0].row)
radec = lib_wcs.xy_to_radec(wcs, pxy)
cobjects, _, _ = lib_stars.get_celestial_objects(radec)
if len(cobjects) < 1:
    print('clusters 0 is associated with no celestial object')
    nb_patho += 1
if len(cobjects) > 1:
    print('clusters 0 is associated with multiple celestial objects')
    for icobj, cobj in enumerate(sorted(cobjects.keys())):
        print('celestial object {}: {}'.format(icobj, cobj))
    nb_symptom += 1

# conclusion
print('{} pathologies'.format(nb_patho))
print('{} symptoms'.format(nb_symptom))
sys.exit(nb_patho)
示例#9
0
 def __call__(self, cluster):
     pxy = lib_wcs.PixelXY(cluster.column, cluster.row)
     radec = lib_wcs.xy_to_radec(self.wcs, pxy)
     obj, _, _ = get_celestial_objects(self.wcs, cluster)
     return [ "{:.3f}/{:.3f} {}".format(radec.ra, radec.dec, obj) ]
示例#10
0
    def __call__(self, cluster):

        pxy = lib_wcs.PixelXY(cluster.column, cluster.row)
        radec = lib_wcs.xy_to_radec(self.wcs, pxy)
        return [ "{:.3f}/{:.3f}".format(radec.ra, radec.dec) ]
示例#11
0
def getcelcoord(cluster, wcs):
    peak_pixel = lib_wcs.PixelXY(cluster.y, cluster.x)
    return lib_wcs.xy_to_radec(wcs, peak_pixel)