Example #1
0
def parse_fits_files(fits_file_name_list, progress_bar=True):
    fits_noise_list = []

    for file_index, file_name in enumerate(fits_file_name_list):

        # Read the input file #########
        fits_images_dict, fits_metadata_dict = images.load_benchmark_images(
            file_name)

        # Get images ##################
        input_img = fits_images_dict["input_image"]
        reference_img = fits_images_dict["reference_image"]

        pure_noise_image = input_img - reference_img
        fits_noise_list.append(pure_noise_image)

        # Progress bar ################
        if progress_bar:
            num_files = len(fits_file_name_list)
            relative_steps = math.ceil(num_files / 100.)

            if (file_index % relative_steps) == 0:
                progress_str = "{:.2f}% ({}/{})".format(
                    (file_index + 1) / num_files * 100, file_index + 1,
                    num_files)
                print(progress_str)

    return fits_noise_list
def main():

    # PARSE OPTIONS ###########################################################

    parser = argparse.ArgumentParser(description="Plot a FITS file.")

    parser.add_argument("--quiet",
                        "-q",
                        action="store_true",
                        help="Don't show the plot, just save it")

    parser.add_argument("--output",
                        "-o",
                        default=None,
                        metavar="FILE",
                        help="The output file path (image file)")

    parser.add_argument("fileargs",
                        nargs=1,
                        metavar="FILE",
                        help="The files image to process (FITS).")

    args = parser.parse_args()

    quiet = args.quiet
    output = args.output
    input_file_path = args.fileargs[0]

    # READ THE INPUT FILE #####################################################

    fits_images_dict, fits_metadata_dict = images.load_benchmark_images(
        input_file_path)

    reference_img = fits_images_dict["reference_image"]
    pixels_position = fits_images_dict["pixels_position"]

    # ASSESS OR PRINT THE CLEANED IMAGE #######################################

    fig, ax1 = plt.subplots(nrows=1, ncols=1, figsize=(9, 9))

    common.plot_image_meter(ax1, reference_img, pixels_position,
                            "Reference image")
    common.plot_ellipse_shower_on_image_meter(ax1, reference_img,
                                              pixels_position)

    # PLOT AND SAVE ###########################################################

    base_file_path = os.path.basename(input_file_path)
    base_file_path = os.path.splitext(base_file_path)[0]

    if output is None:
        output = "{}.png".format(base_file_path)

    plt.savefig(output, bbox_inches='tight')

    if not quiet:
        plt.show()
Example #3
0
def parse_fits_files(fits_file_name):
    # Read the input file #########
    fits_images_dict, fits_metadata_dict = images.load_benchmark_images(
        fits_file_name)

    # Get images ##################
    input_img = fits_images_dict["input_image"]
    reference_img = fits_images_dict["reference_image"]

    pure_noise_image = input_img - reference_img

    return pure_noise_image, fits_metadata_dict
    def selection_changed_callback(self, file_name):
        file_path = os.path.join(self.input_directory_path, file_name)

        # Read the selected file #########
        fits_images_dict, fits_metadata_dict = images.load_benchmark_images(file_path)

        # Fill the dict ###############

        text  = "File: {}\n\n".format(file_path)
        
        for key in sorted(fits_metadata_dict):
            text += "{}: {}\n".format(key, fits_metadata_dict[key])

        # Update the widget ###########
        self.desc_textview.get_buffer().set_text(text)
Example #5
0
def parse_fits_files(dir_name, fits_file_name_list):
    fits_metadata_list = []

    # Parse the input files
    mc_energy_unit = None

    for file_index, file_name in enumerate(fits_file_name_list):
        metadata_dict = {}

        # Read the input file #########

        fits_images_dict, fits_metadata_dict = images.load_benchmark_images(
            os.path.join(dir_name, file_name))

        # Fill the dict ###############

        if mc_energy_unit is None:
            mc_energy_unit = fits_metadata_dict["mc_energy_unit"]  # TODO
        else:
            if mc_energy_unit != fits_metadata_dict["mc_energy_unit"]:
                raise Exception("Inconsistent data")

        metadata_dict["event_id"] = fits_metadata_dict["event_id"]
        metadata_dict["tel_id"] = fits_metadata_dict["tel_id"]
        metadata_dict["mc_energy"] = fits_metadata_dict["mc_energy"]
        metadata_dict["npe"] = fits_metadata_dict["npe"]
        metadata_dict["file_name"] = file_name

        fits_metadata_list.append(metadata_dict)

        # Progress bar ################
        num_files = len(fits_file_name_list)
        relative_steps = math.ceil(num_files / 100.)

        if (file_index % relative_steps) == 0:
            progress_str = "{:.2f}% ({}/{})".format(
                (file_index + 1) / num_files * 100, file_index + 1, num_files)
            print(progress_str)

    return fits_metadata_list
Example #6
0
def export_pixel_mask(input_file_path, output_file_path):
    fits_images_dict, fits_metadata_dict = images.load_benchmark_images(
        input_file_path)
    mask = fits_images_dict["pixels_mask"].astype(np.uint8, copy=True)
    images.save(mask, output_file_path)
    if dir_item_path.lower().endswith('.fits') and os.path.isfile(
            dir_item_path):
        input_file_path_list.append(dir_item_path)

print("The input directory contains {} FITS files.".format(
    len(input_file_path_list)))

# SHUFFLE THE FILE LIST #######################################################

# shuffle the list to avoid having always the same tel_id
random.shuffle(input_file_path_list)

# COPY FILES IN THE RAMDISK ###################################################

image_counter = 0

for input_file_path in input_file_path_list:

    if image_counter > NUM_IMAGES:
        break

    fits_images_dict, fits_metadata_dict = images.load_benchmark_images(
        input_file_path)

    if NPE_MIN <= fits_metadata_dict["npe"] <= NPE_MAX:
        print(image_counter, input_file_path)
        shutil.copy(input_file_path, OUTPUT_FILE_PATH)
        image_counter += 1
    else:
        print("reject", input_file_path)
Example #8
0
def main():

    # PARSE OPTIONS ###########################################################

    parser = argparse.ArgumentParser(description="Plot a FITS file.")

    parser.add_argument("--quiet",
                        "-q",
                        action="store_true",
                        help="Don't show the plot, just save it")

    parser.add_argument("--output",
                        "-o",
                        default=None,
                        metavar="FILE",
                        help="The output file path (image file)")

    parser.add_argument("fileargs",
                        nargs="+",
                        metavar="FILE",
                        help="The files image to process (FITS)."
                        "If fileargs is a directory,"
                        "all FITS files it contains are processed.")

    args = parser.parse_args()

    quiet = args.quiet
    output = args.output
    input_file_or_dir_path_list = args.fileargs

    # FETCH IMAGES ############################################################

    for input_file_or_dir_path in input_file_or_dir_path_list:

        if os.path.isdir(input_file_or_dir_path):
            input_file_path_list = common.get_fits_files_list(
                input_directory_path)
        else:
            input_file_path_list = [input_file_or_dir_path]

        # Parse FITS files
        for input_file_path in input_file_path_list:

            # READ THE INPUT FILE #############################################

            fits_images_dict, fits_metadata_dict = images.load_benchmark_images(
                input_file_path)

            input_img = fits_images_dict["input_image"]
            reference_img = fits_images_dict["reference_image"]

            if input_img.ndim != 2:
                raise Exception(
                    "Unexpected error: the input FITS file should contain a 2D array."
                )

            if reference_img.ndim != 2:
                raise Exception(
                    "Unexpected error: the input FITS file should contain a 2D array."
                )

            # ASSESS OR PRINT THE CLEANED IMAGE ###############################

            base_file_path = os.path.basename(input_file_path)
            base_file_path = os.path.splitext(base_file_path)[0]

            image_list = [input_img, reference_img]
            title_list = ["Input image", "Reference image"]

            if output is None:
                output = "{}.pdf".format(base_file_path)

            if not quiet:
                images.plot_list(image_list, title_list, fits_metadata_dict)

            print("Writing", output)
            images.mpl_save_list(image_list, output, title_list,
                                 fits_metadata_dict)
Example #9
0
def main():

    # PARSE OPTIONS ###########################################################

    parser = argparse.ArgumentParser(description="Plot a FITS file.")

    parser.add_argument("--quiet", "-q", action="store_true",
                        help="Don't show the plot, just save it")

    parser.add_argument("--output", "-o", default=None, metavar="FILE",
                        help="The output file path (image file)")

    parser.add_argument("fileargs", nargs=1, metavar="FILE",
                        help="The files image to process (FITS).")

    args = parser.parse_args()

    quiet = args.quiet
    output = args.output
    input_file_path = args.fileargs[0]

    # READ THE INPUT FILE #####################################################

    fits_images_dict, fits_metadata_dict = images.load_benchmark_images(input_file_path)

    reference_img = fits_images_dict["reference_image"]
    pixels_position = fits_images_dict["pixels_position"]


    ## MAKE MOCK DATA ##################

    #mean = [0, 0]
    #cov = [[.0305, .09],
    #       [.01, .0305]]
    #
    #x, y = np.random.multivariate_normal(mean, cov, 50000).T

    ##counts, _, _ = np.histogram2d(x, y, bins=(xbins, ybins))
    #counts, _, _ = np.histogram2d(x, y, bins=40)
    ##counts = counts.T   # TODO check that

    #counts[counts < 100] = 0

    #reference_img = counts
    #reference_img[0, 0] = 1

    ## MAKE MOCK DATA ##################

    #mean = [0, 0]
    #cov = [[.05, .09],
    #       [.01, .05]]
    #
    #x, y = np.random.multivariate_normal(mean, cov, 50000).T

    ##counts, _, _ = np.histogram2d(x, y, bins=(xbins, ybins))
    #counts, _, _ = np.histogram2d(x, y, bins=40)
    ##counts = counts.T   # TODO check that

    #counts[counts < 100] = 0

    #reference_img = counts
    #reference_img[0, 0] = 1

    ## MAKE MOCK DATA ##################

    #reference_img[reference_img > 0] = 0

    #IY = 12

    #reference_img[10, IY-2] = 1
    #reference_img[10, IY-1] = 1
    #reference_img[10, IY  ] = 1
    #reference_img[10, IY+1] = 1
    #reference_img[10, IY+2] = 1

    #reference_img[11, IY-2] = 2
    #reference_img[11, IY-1] = 2
    #reference_img[11, IY  ] = 2
    #reference_img[11, IY+1] = 2
    #reference_img[11, IY+2] = 2

    #reference_img[12, IY-2] = 1
    #reference_img[12, IY-1] = 1
    #reference_img[12, IY  ] = 1
    #reference_img[12, IY+1] = 1
    ##reference_img[12, IY+2] = 1  # Keep it commented, Tailcut fails on symetric images...

    ####################################

    #reference_img[reference_img > 0] = 1   # simplify the image (black and white image)

    # ASSESS OR PRINT THE CLEANED IMAGE #######################################

    fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(16, 9))

    plot_image_meter(ax1, reference_img, pixels_position, "Reference image")
    plot_ellipse_shower_on_image_meter(ax1, reference_img, pixels_position)

    common.plot_perpendicular_hit_distribution(ax2, [reference_img], pixels_position)
    ax2.set_title("Perpendicular hit distribution")

    # PLOT AND SAVE ###########################################################

    base_file_path = os.path.basename(input_file_path)
    base_file_path = os.path.splitext(base_file_path)[0]

    if output is None:
        output = "{}.png".format(base_file_path)

    plt.savefig(output, bbox_inches='tight')

    if not quiet:
        plt.show()
Example #10
0
    def update_plots(self, data=None, save=False):  # data is for event callers

        if self.current_file_path is not None:
            # Read the selected file #########

            fits_images_dict, fits_metadata_dict = images.load_benchmark_images(
                self.current_file_path)

            input_img = fits_images_dict["input_image"]
            reference_img = fits_images_dict["reference_image"]
            pixels_position = fits_images_dict["pixels_position"]

            if input_img.ndim != 2:
                raise Exception(
                    "Unexpected error: the input FITS file should contain a 2D array."
                )

            if reference_img.ndim != 2:
                raise Exception(
                    "Unexpected error: the input FITS file should contain a 2D array."
                )

            if self.kill_isolated_pixels_on_ref:
                reference_img = scipy_kill_isolated_pixels(reference_img)

            # Tailcut #####################

            #input_img_copy = copy.deepcopy(input_img)
            input_img_copy = input_img.astype('float64', copy=True)

            tailcut = tailcut_mod.Tailcut()

            initial_time = time.perf_counter()
            tailcut_cleaned_img = tailcut.clean_image(
                input_img_copy,
                high_threshold=10,
                low_threshold=5,
                kill_isolated_pixels=self.kill_isolated_pixels)
            tailcut_execution_time = time.perf_counter() - initial_time

            # Wavelets ####################

            #input_img_copy = copy.deepcopy(input_img)
            input_img_copy = input_img.astype('float64', copy=True)

            wavelets = wavelets_mod.WaveletTransform()

            option_string = self.wavelets_options_entry.get_text()
            print(option_string)

            initial_time = time.perf_counter()
            wavelets_cleaned_img = wavelets.clean_image(
                input_img_copy,
                kill_isolated_pixels=self.kill_isolated_pixels,
                input_image_scale=self.input_image_scale,
                offset_after_calibration=self.offset_after_calibration,
                verbose=True,
                raw_option_string=option_string)
            wavelets_execution_time = time.perf_counter() - initial_time

            # Execution time ##############

            print("Tailcut execution time: ", tailcut_execution_time)  # TODO
            print("Wavelets execution time: ", wavelets_execution_time)  # TODO

            # Tailcut scores ##############

            tailcut_title_suffix = ""
            try:
                tailcut_score_tuple, tailcut_score_name_tuple = assess_mod.assess_image_cleaning(
                    input_img,
                    tailcut_cleaned_img,
                    reference_img,
                    pixels_position,
                    benchmark_method="all")

                if self.show_scores:
                    tailcut_title_suffix += " ("
                    for name, score in zip(tailcut_score_name_tuple,
                                           tailcut_score_tuple):
                        if name == "e_shape":
                            tailcut_title_suffix += " Es="
                            tailcut_title_suffix += "{:.2e}".format(score)
                        elif name == "e_energy":
                            tailcut_title_suffix += " Ee="
                            tailcut_title_suffix += "{:.2e}".format(score)
                        elif name == "hillas_theta":
                            tailcut_title_suffix += " Th="
                            tailcut_title_suffix += "{:.2f}".format(score)
                    tailcut_title_suffix += " )"

                print("Tailcut:")
                for name in tailcut_score_name_tuple:
                    print("{:>20}".format(name), end=" ")
                print()
                for score in tailcut_score_tuple:
                    print("{:20.12f}".format(score), end=" ")
                print()
            except assess_mod.AssessError:
                print("Tailcut: ", str(assess_mod.AssessError))

            # Wavelets scores #############

            wavelets_title_suffix = ""
            try:
                wavelets_score_tuple, wavelets_score_name_tuple = assess_mod.assess_image_cleaning(
                    input_img,
                    wavelets_cleaned_img,
                    reference_img,
                    pixels_position,
                    benchmark_method="all")

                if self.show_scores:
                    wavelets_title_suffix += " ("
                    for name, score in zip(wavelets_score_name_tuple,
                                           wavelets_score_tuple):
                        if name == "e_shape":
                            wavelets_title_suffix += " Es="
                            wavelets_title_suffix += "{:.2e}".format(score)
                        elif name == "e_energy":
                            wavelets_title_suffix += " Ee="
                            wavelets_title_suffix += "{:.2e}".format(score)
                        elif name == "hillas_theta":
                            wavelets_title_suffix += " Th="
                            wavelets_title_suffix += "{:.2f}".format(score)
                    wavelets_title_suffix += " )"

                print("Wavelets:")
                for name in wavelets_score_name_tuple:
                    print("{:>20}".format(name), end=" ")
                print()
                for score in wavelets_score_tuple:
                    print("{:20.12f}".format(score), end=" ")
                print()
            except assess_mod.AssessError:
                print("Wavelets: ", str(assess_mod.AssessError))

            # Update the widget ###########

            self.clear_figure()

            ax1 = self.fig.add_subplot(221)
            ax2 = self.fig.add_subplot(222)
            ax3 = self.fig.add_subplot(223)
            ax4 = self.fig.add_subplot(224)

            if self.plot_histogram:
                self._draw_histogram(ax1, input_img, "Input")
                self._draw_histogram(ax2, reference_img, "Reference")
                self._draw_histogram(ax3, tailcut_cleaned_img,
                                     "Tailcut" + tailcut_title_suffix)
                self._draw_histogram(ax4, wavelets_cleaned_img,
                                     "Wavelets" + wavelets_title_suffix)
            else:
                # AX1 #######

                self._draw_image(ax1,
                                 input_img,
                                 "Input",
                                 pixels_position=pixels_position)

                # AX2 #######

                self._draw_image(ax2,
                                 reference_img,
                                 "Reference",
                                 pixels_position=pixels_position)

                if self.plot_ellipse_shower:
                    try:
                        common.plot_ellipse_shower_on_image_meter(
                            ax2, reference_img, pixels_position)
                    except Exception as e:
                        print(e)

                # AX3 #######

                if self.plot_perpendicular_hit_distribution is not None:
                    if self.use_ref_angle_for_perpendicular_hit_distribution:
                        image_array = copy.deepcopy(reference_img)
                        xx, yy = pixels_position[0], pixels_position[1]
                        common_hillas_parameters = hillas_parameters_1(
                            xx.flatten() * u.meter,
                            yy.flatten() * u.meter, image_array.flatten())
                    else:
                        common_hillas_parameters = None

                    bins = np.linspace(-0.04, 0.04, 21)

                    if self.plot_perpendicular_hit_distribution == "Tailcut":
                        common.plot_perpendicular_hit_distribution(
                            ax3, [reference_img, tailcut_cleaned_img],
                            pixels_position,
                            bins=bins,
                            label_list=["Ref.", "Cleaned TC"],
                            hist_type="step",
                            common_hillas_parameters=common_hillas_parameters,
                            plot_ratio=True)
                    elif self.plot_perpendicular_hit_distribution == "Wavelet":
                        common.plot_perpendicular_hit_distribution(
                            ax3, [reference_img, wavelets_cleaned_img],
                            pixels_position,
                            bins=bins,
                            label_list=["Ref.", "Cleaned WT"],
                            hist_type="step",
                            common_hillas_parameters=common_hillas_parameters,
                            plot_ratio=True)

                    ax3.set_title("Perpendicular hit distribution")
                    ax3.set_xlabel("Distance to the shower axis (in meter)",
                                   fontsize=16)
                    ax3.set_ylabel("Photoelectrons", fontsize=16)
                else:
                    self._draw_image(ax3,
                                     tailcut_cleaned_img,
                                     "Tailcut" + tailcut_title_suffix,
                                     pixels_position=pixels_position)

                if self.plot_ellipse_shower:
                    if self.plot_perpendicular_hit_distribution is None:
                        try:
                            # Show ellipse only if "perpendicular hit distribution" is off
                            common.plot_ellipse_shower_on_image_meter(
                                ax3, tailcut_cleaned_img, pixels_position)
                        except Exception as e:
                            print(e)

                # AX4 #######

                if self.plot_perpendicular_hit_distribution == "Tailcut":
                    self._draw_image(ax4,
                                     tailcut_cleaned_img,
                                     "Tailcut" + tailcut_title_suffix,
                                     pixels_position=pixels_position)

                    if self.plot_ellipse_shower:
                        if (
                                self.plot_perpendicular_hit_distribution
                                is not None
                        ) and self.use_ref_angle_for_perpendicular_hit_distribution:
                            try:
                                common.plot_ellipse_shower_on_image_meter(
                                    ax4, reference_img, pixels_position)
                            except Exception as e:
                                print(e)
                        else:
                            try:
                                common.plot_ellipse_shower_on_image_meter(
                                    ax4, tailcut_cleaned_img, pixels_position)
                            except Exception as e:
                                print(e)
                else:
                    self._draw_image(ax4,
                                     wavelets_cleaned_img,
                                     "Wavelets" + wavelets_title_suffix,
                                     pixels_position=pixels_position)

                    if self.plot_ellipse_shower:
                        if (
                                self.plot_perpendicular_hit_distribution
                                is not None
                        ) and self.use_ref_angle_for_perpendicular_hit_distribution:
                            try:
                                common.plot_ellipse_shower_on_image_meter(
                                    ax4, reference_img, pixels_position)
                            except Exception as e:
                                print(e)
                        else:
                            try:
                                common.plot_ellipse_shower_on_image_meter(
                                    ax4, wavelets_cleaned_img, pixels_position)
                            except Exception as e:
                                print(e)

            plt.suptitle(
                "{:.3f} TeV ({} photoelectrons in reference image) - Event {} - Telescope {}"
                .format(fits_metadata_dict["mc_energy"],
                        int(fits_metadata_dict["npe"]),
                        fits_metadata_dict["event_id"],
                        fits_metadata_dict["tel_id"]),
                fontsize=18)

            if save:
                output_file_path_base = "ev{}_tel{}".format(
                    fits_metadata_dict["event_id"],
                    fits_metadata_dict["tel_id"])  # TODO: add WT options

                if self.plot_histogram:
                    output_file_path_base += "_hist"

                if self.plot_log_scale:
                    output_file_path_base += "_log"

                ## Save in PDF
                #output_file_path = output_file_path_base + ".pdf"
                #print("Save", output_file_path)
                #plt.savefig(output_file_path, bbox_inches='tight')

                ## Save in SVG
                #output_file_path = output_file_path_base + ".svg"
                #print("Save", output_file_path)
                #plt.savefig(output_file_path, bbox_inches='tight')

                # Save in PNG
                output_file_path = output_file_path_base + ".png"
                print("Save", output_file_path)
                plt.savefig(output_file_path, bbox_inches='tight')
            else:
                self.fig.canvas.draw()
Example #11
0
def main():

    # PARSE OPTIONS ###########################################################

    parser = argparse.ArgumentParser(description="Plot a FITS file.")

    parser.add_argument("--quiet",
                        "-q",
                        action="store_true",
                        help="Don't show the plot, just save it")

    parser.add_argument("--output",
                        "-o",
                        default=None,
                        metavar="FILE",
                        help="The output file path (image file)")

    parser.add_argument("fileargs",
                        nargs="+",
                        metavar="FILE",
                        help="The files image to process (FITS)."
                        "If fileargs is a directory,"
                        "all FITS files it contains are processed.")

    args = parser.parse_args()

    quiet = args.quiet
    output = args.output
    input_file_or_dir_path_list = args.fileargs

    # FETCH PIXELS POSITION ###################################################

    for input_file_or_dir_path in input_file_or_dir_path_list:

        if os.path.isdir(input_file_or_dir_path):
            input_file_path_list = common.get_fits_files_list(
                input_directory_path)
        else:
            input_file_path_list = [input_file_or_dir_path]

        # Parse FITS files
        for input_file_path in input_file_path_list:

            # READ THE INPUT FILE #############################################

            fits_images_dict, fits_metadata_dict = images.load_benchmark_images(
                input_file_path)

            pixels_position = fits_images_dict["pixels_position"]

            # PLOT ############################################################

            plt.scatter(pixels_position[0], pixels_position[1])

            print(pixels_position[0], pixels_position[1])
            print(pixels_position[0][0][0] - pixels_position[0][0][1])
            print(pixels_position[1][0][0] - pixels_position[1][1][0])

            # Save file and plot ########

            base_file_path = os.path.basename(input_file_path)
            base_file_path = os.path.splitext(base_file_path)[0]

            if output is None:
                img_output = "{}.pdf".format(base_file_path)

            print("Writing", img_output)
            plt.savefig(img_output, bbox_inches='tight')

            if not quiet:
                plt.show()
def main():

    # PARSE OPTIONS ###########################################################

    parser = argparse.ArgumentParser(description="Plot a FITS file.")

    parser.add_argument("--quiet",
                        "-q",
                        action="store_true",
                        help="Don't show the plot, just save it")

    parser.add_argument("--output",
                        "-o",
                        default=None,
                        metavar="FILE",
                        help="The output file path (image file)")

    parser.add_argument("fileargs",
                        nargs=1,
                        metavar="FILE",
                        help="The files image to process (FITS).")

    args = parser.parse_args()

    quiet = args.quiet
    output = args.output
    input_file_path = args.fileargs[0]

    # READ THE INPUT FILE #####################################################

    fits_images_dict, fits_metadata_dict = images.load_benchmark_images(
        input_file_path)

    reference_img = fits_images_dict["reference_image"]
    pixels_position = fits_images_dict["pixels_position"]

    ## MAKE MOCK DATA ##################

    #mean = [0, 0]
    #cov = [[.0305, .09],
    #       [.01, .0305]]
    #
    #x, y = np.random.multivariate_normal(mean, cov, 50000).T

    ##counts, _, _ = np.histogram2d(x, y, bins=(xbins, ybins))
    #counts, _, _ = np.histogram2d(x, y, bins=40)
    ##counts = counts.T   # TODO check that

    #counts[counts < 100] = 0

    #reference_img1 = counts

    #reference_img1[0, 0] = 1

    ## MAKE MOCK DATA ##################

    #mean = [0, 0]
    #cov = [[.05, .09],
    #       [.01, .05]]
    #
    #x, y = np.random.multivariate_normal(mean, cov, 50000).T

    ##counts, _, _ = np.histogram2d(x, y, bins=(xbins, ybins))
    #counts, _, _ = np.histogram2d(x, y, bins=40)
    ##counts = counts.T   # TODO check that

    #counts[counts < 100] = 0

    #reference_img2 = counts
    #reference_img2[0, 0] = 1

    ####################################

    #bw_reference_img1 = np.copy(reference_img1)
    #bw_reference_img1[reference_img1 > 0] = 1   # simplify the image (black and white image)

    #bw_reference_img2 = np.copy(reference_img2)
    #bw_reference_img2[reference_img2 > 0] = 1   # simplify the image (black and white image)

    ###################################

    #pixels_position = rotate(pixels_position, math.pi)

    # ASSESS OR PRINT THE CLEANED IMAGE #######################################

    fig, ((ax1, ax2, ax3), (ax4, ax5, ax6)) = plt.subplots(nrows=2,
                                                           ncols=3,
                                                           figsize=(16, 9))

    ##plot_image(ax1, reference_img1, "Reference image")
    ##plot_ellipse_shower_on_image(ax1, reference_img1)

    #plot_image_meter(ax2, bw_reference_img1, pixels_position, "Reference image")
    #plot_ellipse_shower_on_image_meter(ax2, reference_img1, pixels_position)

    #plot_perpendicular_hit_distribution(ax3, ax2, bw_reference_img1, pixels_position, "Perpendicular hit distribution JD")

    ##plot_image(ax4, reference_img2, "Reference image")
    ##plot_ellipse_shower_on_image(ax4, reference_img2)

    #plot_image_meter(ax5, bw_reference_img2, pixels_position, "Reference image")
    #plot_ellipse_shower_on_image_meter(ax5, reference_img2, pixels_position)

    #plot_perpendicular_hit_distribution(ax6, ax5, bw_reference_img2, pixels_position, "Perpendicular hit distribution JD")

    plot_image_meter(ax2, reference_img, pixels_position, "Reference image")
    plot_ellipse_shower_on_image_meter(ax2, reference_img, pixels_position)

    plot_perpendicular_hit_distribution(ax3, ax2, reference_img,
                                        pixels_position,
                                        "Perpendicular hit distribution JD")

    plot_image_meter(ax5, reference_img, pixels_position, "Reference image")
    plot_ellipse_shower_on_image_meter(ax5, reference_img, pixels_position)

    plot_perpendicular_hit_distribution(ax6, ax5, reference_img,
                                        pixels_position,
                                        "Perpendicular hit distribution JD")

    #plot_image(ax4, bw_reference_img1, "Reference image")
    #plot_ellipse_shower_on_image(ax4, bw_reference_img1)

    #plot_image_meter(ax5, bw_reference_img1, pixels_position, "Reference image")

    #plot_perpendicular_hit_distribution(ax6, ax5, bw_reference_img1, pixels_position, "Perpendicular hit distribution")

    #a = np.array([[0, 1,],
    #              [0, 2]])
    #print(a)
    #print(rotate(a, -math.pi))

    # PLOT AND SAVE ###########################################################

    base_file_path = os.path.basename(input_file_path)
    base_file_path = os.path.splitext(base_file_path)[0]

    if output is None:
        output = "{}.pdf".format(base_file_path)

    plt.savefig(output, bbox_inches='tight')

    if not quiet:
        plt.show()