def radio_action(self, file_name):
        """
        On click function for radio button
        :param file_name: name of the fits file
        """

        # Get pixels and header from a fits file
        self.pixels, _ = mylib.get_pixels("../data/%s" % (file_name))

        # Process to the fit of the background
        _, _, _, self.background, self.dispersion = mylib.modelling_parameters(
            self.pixels)

        # Remove the background
        filtered_pixels = mylib.remove_background(self.pixels, self.background,
                                                  self.dispersion)

        # Update the picture
        self.axis.cla()  # delete the previous imshow
        self.axis.imshow(filtered_pixels)
        self.axis.set_title('Use of both slider and radio button')
        self.fig.canvas.draw()  # redraw

        # Define the slider widget
        threshold_min = max(0, self.background - 6.0 * self.dispersion)
        threshold_max = self.background + 10.0 * self.dispersion
        threshold_init = self.background + 6.0 * self.dispersion
        if self.my_widget is not None:
            self.slider_axis.cla()
        self.my_widget = widgets.Slider(self.slider_axis, 'threshold', threshold_min, \
                                   threshold_max, valinit=threshold_init)
    def radio_action(self, file_name):
        """
        On click function for radio button
        :param file_name: name of the fits file
        """

        # Get pixels and header from a fits file
        self.pixels, _ = mylib.get_pixels("../data/%s" % (file_name))

        # Process to the fit of the background
        _, _, _, self.background, self.dispersion = mylib.modelling_parameters(self.pixels)

        # Remove the background
        filtered_pixels = mylib.remove_background(self.pixels, self.background, self.dispersion)

        # Update the picture
        self.axis.cla() # delete the previous imshow
        self.axis.imshow(filtered_pixels)
        self.axis.set_title('Use of both slider and radio button')
        self.fig.canvas.draw() # redraw

        # Define the slider widget
        threshold_min = max(0, self.background - 6.0 * self.dispersion)
        threshold_max = self.background + 10.0*self.dispersion
        threshold_init = self.background + 6.0*self.dispersion
        if self.my_widget is not None:
            self.slider_axis.cla()
        self.my_widget = widgets.Slider(self.slider_axis, 'threshold', threshold_min, \
                                   threshold_max, valinit=threshold_init)
Example #3
0
def main():
    """
    Take datas (2D numpy.array) from the fits file specific.fits
    and find cluster of pixels in which each pixel has a luminosity
    greater than a threshold (linked to the value of the background)
    """

    # Get pixels and header from a fits file
    pixels, _ = mylib.get_pixels("../data/specific.fits")

    # Process to the fit of the background
    _, _, _, background, dispersion = mylib.modelling_parameters(pixels)

    # Get the list of clusters
    cluster_array = mylib.get_cluster_array(pixels, background, dispersion)

    # Find the cluster with the greatest integral
    main_clust = mylib.find_main_centroid(cluster_array)

    # Write informations about clusters on ex3.txt file
    results = 'number of clusters: %2d, ' % (len(cluster_array)) \
            + 'greatest integral: %7d, ' % (main_clust.integrated_luminosity) \
            + 'centroid x: %4.1f, centroid y: %4.1f' % \
              (main_clust.centroid_pixel[0], main_clust.centroid_pixel[1])
    with open("ex3.txt", 'w') as output_file:
        output_file.write(results)

    return 0
Example #4
0
def main():
    """
    Take datas (2D numpy.array) from the fits file specific.fits
    and display the associated picture without background,
    the threshold can be ajusted with a widget,
    calculate the number of clusters
    """

    # Get pixels and header from a fits file
    pixels, _ = mylib.get_pixels("../data/specific.fits")

    # Process to the fit of the background
    _, _, _, background, dispersion = mylib.modelling_parameters(pixels)

    # Remove the background
    filtered_pixels = mylib.remove_background(pixels, background, dispersion)

    # Display the picture without the background
    fig, axis = plt.subplots()
    plt.subplots_adjust(left=0.1, bottom=0.25)
    axis.imshow(filtered_pixels)
    axis.set_title('Picture without background')

    # Define the slider axis and the widget associated
    slider_axis = plt.axes([0.2, 0.1, 0.6, 0.105])
    threshold_min = background
    threshold_max = background + 30.0 * dispersion
    threshold_init = background + 6.0 * dispersion
    my_widget = widgets.Slider(slider_axis, 'threshold', threshold_min, \
                               threshold_max, valinit=threshold_init)

    # slider_action function definition
    def slider_action(threshold):
        """
        Function called when the threshold value is changed,
        the filtered_pixels array is recalculated
        and the canvas is redrawn
        """
        axis.cla() # delete the previous imshow
        filtered_pixels = mylib.remove_background(pixels, background, \
                          dispersion, threshold=threshold)
        axis.imshow(filtered_pixels)
        try: # if too many recursion, say that threshold is too low
            cluster_array = mylib.get_cluster_array(pixels, background, dispersion, threshold)
            axis.set_title('Picture without background : number of clusters = %s' % \
                      (len(cluster_array)))
        except RuntimeError:
            axis.set_title('Picture without background : threshold is too low')
        fig.canvas.draw() # redraw

    # Use event handler
    my_widget.on_changed(slider_action)
    plt.show()

    return 0
def main():
    """
    Take datas (2D numpy.array) from the fits file specific.fits,
    find the clusters array, find there WCS coordinates, display it
    """

    # Get pixels and header from a fits file
    pixels, header = mylib.get_pixels("../data/specific.fits")

    # Process to the fit of the background
    _, _, _, background, dispersion = mylib.modelling_parameters(pixels)

    # Get the list of clusters
    my_wcs = library.WCS(header)  # Instantiate WCS conversion object
    cluster_array = mylib.get_cluster_array(pixels, background, \
                                            dispersion, my_wcs=my_wcs)

    # Remove the background
    filtered_pixels = mylib.remove_background(pixels, background, dispersion)

    # Display the picture
    fig, axis = plt.subplots()
    axis.imshow(filtered_pixels)

    # Move function definition
    def move(event):
        """
        Function called when the event 'motion_notify_event' occurs,
        the wcs coordinates of the pixel pointed by the mouse are
        then displayed at its location
        """
        x_position = event.xdata
        y_position = event.ydata
        if x_position != None:  # if we are not outside the picture
            rad, dec = my_wcs.convert_to_radec(x_position, y_position)
            text = axis.text(x_position, y_position, 'ra: %.6f, dec: %.6f' % \
                            (rad, dec), fontsize=14, color='white')
            event.canvas.draw()
            text.remove()

    # Use event handler
    fig.canvas.mpl_connect('motion_notify_event', move)
    plt.show()

    # Find the cluster with the greatest integral
    main_clust = mylib.find_main_centroid(cluster_array)

    # Write informations about WCS coordinates on ex4.txt file
    results = 'right ascension: %.3f, declination: %.3f' % \
              (main_clust.centroid_wcs[0], main_clust.centroid_wcs[1])
    with open("ex4.txt", 'w') as output_file:
        output_file.write(results)

    return 0
def main():
    """
    Take datas (2D numpy.array) from the fits file specific.fits,
    find the clusters array, find there WCS coordinates, display it
    """

    # Get pixels and header from a fits file
    pixels, header = mylib.get_pixels("../data/specific.fits")

    # Process to the fit of the background
    _, _, _, background, dispersion = mylib.modelling_parameters(pixels)

    # Get the list of clusters
    my_wcs = library.WCS(header) # Instantiate WCS conversion object
    cluster_array = mylib.get_cluster_array(pixels, background, \
                                            dispersion, my_wcs=my_wcs)

    # Remove the background
    filtered_pixels = mylib.remove_background(pixels, background, dispersion)

    # Display the picture
    fig, axis = plt.subplots()
    axis.imshow(filtered_pixels)

    # Move function definition
    def move(event):
        """
        Function called when the event 'motion_notify_event' occurs,
        the wcs coordinates of the pixel pointed by the mouse are
        then displayed at its location
        """
        x_position = event.xdata
        y_position = event.ydata
        if x_position != None: # if we are not outside the picture
            rad, dec = my_wcs.convert_to_radec(x_position, y_position)
            text = axis.text(x_position, y_position, 'ra: %.6f, dec: %.6f' % \
                            (rad, dec), fontsize=14, color='white')
            event.canvas.draw()
            text.remove()

    # Use event handler
    fig.canvas.mpl_connect('motion_notify_event', move)
    plt.show()

    # Find the cluster with the greatest integral
    main_clust = mylib.find_main_centroid(cluster_array)

    # Write informations about WCS coordinates on ex4.txt file
    results = 'right ascension: %.3f, declination: %.3f' % \
              (main_clust.centroid_wcs[0], main_clust.centroid_wcs[1])
    with open("ex4.txt", 'w') as output_file:
        output_file.write(results)

    return 0
def main():
    """
    Take datas (2D numpy.array) from the fits file specific.fits
    and display the associated picture without background
    """

    # Get pixels and header from a fits file
    pixels, _ = mylib.get_pixels("../data/specific.fits")

    # Process to the fit of the background
    x_array, y_array, maxvalue, background, dispersion = \
        mylib.modelling_parameters(pixels)

    # Remove the background
    filtered_pixels = mylib.remove_background(pixels, background, dispersion)

    # Plot both histograms and picture without background
    _, axis = plt.subplots(1, 2)

    # Plot histogram of data luminosity and result of the fit
    axis[0].plot(x_array, y_array, 'b+:', label='data')
    axis[0].plot(x_array, mylib.modelling_function( \
             x_array, maxvalue, background, dispersion), \
             'r.:', label='fit')
    axis[0].legend()
    axis[0].set_title('Flux distribution')
    axis[0].set_xlabel('Amplitude')
    axis[0].set_ylabel('Frequency')

    # Display the picture without the background
    axis[1].imshow(filtered_pixels)
    axis[1].set_title('Picture without background')
    plt.show()

    # Write informations about background and dispersion on ex2.txt file
    results = 'background: %i, dispersion: %i' % (background, dispersion)
    with open("ex2.txt", 'w') as output_file:
        output_file.write(results)

    return 0
def main():
    """
    Take datas (2D numpy.array) from the fits file specific.fits,
    find the clusters array, find there names, display it
    """

    # Get pixels and header from a fits file
    pixels, header = mylib.get_pixels("../data/specific.fits")

    # Process to the fit of the background
    _, _, _, background, dispersion = mylib.modelling_parameters(pixels)

    # Get the list of clusters
    my_wcs = library.WCS(header) # Instantiate WCS conversion object
    cluster_array = mylib.get_cluster_array(pixels, background, \
                                            dispersion, my_wcs=my_wcs)

    # Remove the background
    filtered_pixels = mylib.remove_background(pixels, background, dispersion)

    # Display the picture
    fig, axis = plt.subplots()
    axis.imshow(filtered_pixels)

    # Put bounding boxes
    for cluster in cluster_array:
        axis.add_patch(patches.Rectangle(cluster.bounding_box[0], \
                                         cluster.bounding_box[1], \
                                         cluster.bounding_box[2], \
                                         fill=False, \
                                         color='white'))

    # On_click function definition
    def on_click(event):
        """
        Function called when the event 'button_release_event' occurs,
        if the click was made on a bounding box, the name of the
        corresponding celestial object is displayed
        """
        x_position = event.xdata
        y_position = event.ydata
        if x_position != None: # if we are not outside the picture
            for clust in cluster_array:
                if clust.is_in_bounding(x_position, y_position):
                    text = axis.text(x_position, y_position, clust.star_name, \
                                     fontsize=14, color='white')
                    event.canvas.draw()
                    text.remove()

    # Use event handler
    fig.canvas.mpl_connect('button_release_event', on_click)
    plt.show()

    # Find the cluster with the greatest integral
    main_clust = mylib.find_main_centroid(cluster_array)

    # Write the name of the main celestial object on ex5.txt file
    results = 'celestial object: %s' % (main_clust.star_name)
    with open("ex5.txt", 'w') as output_file:
        output_file.write(results)

    return 0