def count_delta_psi(json_file_path, min_npe=None, max_npe=None, notebook=False, delta_angle_degrees=0.05, border=False): # FETCH SCORE AND COMPUTE HISTOGRAM ####################################### json_dict = common.parse_json_file(json_file_path) if min_npe is not None: json_dict = common.image_filter_range(json_dict, "img_cleaned_sum_pe", min_value=min_npe) if max_npe is not None: json_dict = common.image_filter_range(json_dict, "img_cleaned_sum_pe", max_value=max_npe) if border: json_dict = common.image_filter_range(json_dict, "img_cleaned_signal_to_border_distance", min_value=1) score_array = common.extract_score_array(json_dict, "hillas2_delta_psi_norm2") score_array = np.abs(score_array) count = len(score_array[score_array < delta_angle_degrees]) return count
def count_delta_psi(json_file_path, min_npe=None, max_npe=None, notebook=False, delta_angle_degrees=0.05, border=False): # FETCH SCORE AND COMPUTE HISTOGRAM ####################################### json_dict = common.parse_json_file(json_file_path) if min_npe is not None: json_dict = common.image_filter_range(json_dict, "img_cleaned_sum_pe", min_value=min_npe) if max_npe is not None: json_dict = common.image_filter_range(json_dict, "img_cleaned_sum_pe", max_value=max_npe) if border: json_dict = common.image_filter_range( json_dict, "img_cleaned_signal_to_border_distance", min_value=1) score_array = common.extract_score_array(json_dict, "hillas2_delta_psi_norm2") score_array = np.abs(score_array) count = len(score_array[score_array < delta_angle_degrees]) return count
def main(): # PARSE OPTIONS ########################################################### parser = argparse.ArgumentParser( description="Denoise FITS images with the tailcut algorithm.") parser.add_argument("--output", "-o", required=True, metavar="FILE", help="The output file path") parser.add_argument("fileargs", nargs="+", metavar="FILE", help="The input (JSON) files to convert.") args = parser.parse_args() output_file_path = args.output input_file_list = args.fileargs # CONVERT FILES ########################################################### global_output_array = None for input_file_path in input_file_list: print(input_file_path) json_dict = common.parse_json_file(input_file_path) common_lines = [input_file_path] # Make the file output array io_list = json_dict["io"] file_output_list = [ common_lines + extract_columns(image_dict) for image_dict in io_list if "score" in image_dict ] file_output_array = np.array(file_output_list) # Append the file output array to the global ouput array if global_output_array is None: global_output_array = file_output_array else: global_output_array = np.vstack( [global_output_array, file_output_array]) # SAVE FILE ############################################################### save(output_file_path, global_output_array, OUTPUT_HEADER_LIST + score_name_list, OUTPUT_DTYPE_LIST + [ "f8", ] * len(score_name_list))
def main(): # PARSE OPTIONS ########################################################### parser = argparse.ArgumentParser(description="Denoise FITS images with the tailcut algorithm.") parser.add_argument("--output", "-o", required=True, metavar="FILE", help="The output file path") parser.add_argument("fileargs", nargs="+", metavar="FILE", help="The input (JSON) files to convert.") args = parser.parse_args() output_file_path = args.output input_file_list = args.fileargs # CONVERT FILES ########################################################### global_output_array = None for input_file_path in input_file_list: print(input_file_path) json_dict = common.parse_json_file(input_file_path) common_lines = [input_file_path] # Make the file output array io_list = json_dict["io"] file_output_list = [common_lines + extract_columns(image_dict) for image_dict in io_list if "score" in image_dict] file_output_array = np.array(file_output_list) # Append the file output array to the global ouput array if global_output_array is None: global_output_array = file_output_array else: global_output_array = np.vstack([global_output_array, file_output_array]) # SAVE FILE ############################################################### save(output_file_path, global_output_array, OUTPUT_HEADER_LIST + score_name_list, OUTPUT_DTYPE_LIST + ["f8",] * len(score_name_list))
json_file_path_list = args.fileargs if args.output is None: prefix1 = "_o" if overlaid else "" prefix2 = "_" + str(max_abscissa) if max_abscissa is not None else "" output_file_path = "execution_time{}{}.pdf".format(prefix1, prefix2) else: output_file_path = args.output # FETCH SCORE ############################################################# data_list = [] label_list = [] for json_file_path in json_file_path_list: json_dict = common.parse_json_file(json_file_path) execution_time_list = extract_execution_time_list(json_dict) if max_abscissa is not None: execution_time_list = [val for val in execution_time_list if val <= max_abscissa] data_list.append(np.array(execution_time_list)) label_list.append(json_dict["label"]) # PLOT STATISTICS ######################################################### fig, ax1 = plt.subplots(nrows=1, ncols=1, figsize=(10, 6)) plot_hist(ax1, data_list, label_list, logx, logy, overlaid)
def hist_ratio(json_file_path_list, metric, min_npe=None, max_npe=None, exclude_aborted=False, aborted_only=False, tel_id=None, notebook=False, delta_angle_degrees=0.2): if len(json_file_path_list) != 2: raise Exception('"json_file_path_list" should have exactly 2 elements') if exclude_aborted and aborted_only: raise Exception('"exclude-aborted" and "aborted-only" options are not compatible"') # FETCH SCORE AND COMPUTE HISTOGRAM ####################################### data_list = [] label_list = [] hist_list = [] bins_list = [] for json_file_path in json_file_path_list: if not notebook: print("Parsing {}...".format(json_file_path)) json_dict = common.parse_json_file(json_file_path) if tel_id is not None: json_dict = common.image_filter_equals(json_dict, "tel_id", tel_id) if min_npe is not None: #json_dict = common.image_filter_range(json_dict, "npe", min_value=min_npe) json_dict = common.image_filter_range(json_dict, "img_cleaned_sum_pe", min_value=min_npe) if max_npe is not None: #json_dict = common.image_filter_range(json_dict, "npe", max_value=max_npe) json_dict = common.image_filter_range(json_dict, "img_cleaned_sum_pe", max_value=max_npe) if not notebook: print(len(json_dict["io"]), "images") score_array = common.extract_score_array(json_dict, metric) data_list.append(score_array) label_list.append(json_dict["label"]) min_range, max_range = 0., math.sin(math.radians(delta_angle_degrees)) hist, bin_edges = np.histogram(score_array, range=(min_range, max_range), bins=1) #bins=[0., math.sin(math.radians(0.2)), math.sin(math.radians(0.4)), math.sin(math.radians(0.6))] ) hist_list.append(hist) bins_list.append(bin_edges) # COMPUTE RATIO ########################################################### #assert bins_list[0] == bins_list[1] edges_of_bins = bins_list[0] val_of_bins_data_1 = hist_list[0] val_of_bins_data_2 = hist_list[1] print(val_of_bins_data_1) print(val_of_bins_data_2) # Set ratio where val_of_bins_data_2 is not zero ratio = np.divide(val_of_bins_data_1, val_of_bins_data_2, where=(val_of_bins_data_2 != 0)) # Compute error on ratio (null if cannot be computed) error = np.divide(val_of_bins_data_1 * np.sqrt(val_of_bins_data_2) + val_of_bins_data_2 * np.sqrt(val_of_bins_data_1), np.power(val_of_bins_data_2, 2), where=(val_of_bins_data_2 != 0)) return ratio, error, edges_of_bins
if __name__ == '__main__': # PARSE OPTIONS ########################################################### parser = argparse.ArgumentParser(description="Make statistics on score files (JSON files).") parser.add_argument("fileargs", nargs=1, metavar="FILE", help="The JSON file to process") args = parser.parse_args() json_file_path = args.fileargs[0] # FETCH SCORE ############################################################# json_data = common.parse_json_file(json_file_path) success_list, aborted_list = extract_data_list(json_data) print("{} images".format(len(success_list) + len(aborted_list))) print("{} succeeded".format(len(success_list))) print("{} failed".format(len(aborted_list))) if len(aborted_list) > 0: error_message_dict = {} for image_dict in aborted_list: error_message = image_dict["error"]["message"] if error_message in error_message_dict: error_message_dict[error_message] += 1 else: error_message_dict[error_message] = 1