Ejemplo n.º 1
0
    def set_total_costs_matrix(self, i, j, def_param = None):
        def_param = total_costs_matrix_base
        curve_name_i = all_curves[i][0]
        curve_type_i = all_curves[i][1]
        curve_file_i = fits.open(os.getcwd()+'/memoria/'+
                        'inputs/'+curve_type_i+'/'+curve_name_i+'.fits',
                        memmap=False)

        curve_data_i = Extractor.get_values(curve_file_i)

        curve_file_i.close()

        curve_name_j = all_curves[j][0]
        curve_type_j = all_curves[j][1]
        curve_file_j = fits.open(os.getcwd()+'/memoria/'+
                        'inputs/'+curve_type_j+'/'+curve_name_j+'.fits',
                        memmap=False)

        curve_data_j = Extractor.get_values(curve_file_j)

        curve_file_j.close()

        x,y = curve_data_i, curve_data_j

        dtw = DTW(x,y)
        cost_matrix = dtw.compute_cost_matrix(DTW.euclidean_distance)
        acc_cost_matrix, cost = dtw.compute_acc_cost_matrix(cost_matrix)

        self.total_costs_matrix[i,j] = cost
Ejemplo n.º 2
0
 def __init__(self, fitsFile, x_obs, values, peaks, window):
     self.x_obs = x_obs
     self.values = values
     self.peaks = peaks # List of indices of x_obs
     self.window = window # In Angstrom
     self.window_neighbours = Extractor.obs_lambda_window_to_neighbours(
                                   fitsFile, window)
     self.obs_delta_lambda = Extractor.get_obs_delta_lambda(fitsFile)
Ejemplo n.º 3
0
    def compare_original_detected(self, file_name, fitsFile, original_peaks,
                                  detected_peaks, peak_score, lambda_window):

        """Compare the original peaks with the found ones for the given
        spectrum. Updates peak_score confusion matrix."""

        nw = Extractor.emit_lambda_window_to_neighbours(
                       file_name, fitsFile, lambda_window)
        nw = int(nw / 2)
        original_ranges = [[i-nw, i+nw] for i in original_peaks]

        for detected in detected_peaks:
            for original_range in original_ranges:

                if original_range[0] <= detected <= original_range[1]:
                    found_peak = True

                    # TP += 1
                    peak_score.update_confusion_matrix(True, True)

                    found_index = original_ranges.index(original_range)

                    for i in range(0, found_index):
                        # FN += 1
                        peak_score.update_confusion_matrix(False, True)

                    original_ranges = original_ranges[found_index+1:]
                    break
                else:
                    found_peak = False

            if not found_peak:
                # FP += 1
                peak_score.update_confusion_matrix(True, False)

        return None
Ejemplo n.º 4
0
    def curves_scores_computation(self, all_param_tuples):
        """Computes the score for each param tuple and file."""

        current_file_index=0
        total_files = len(self.all_file_names)
        for file_name in self.all_file_names:

            fitsFile = Extractor.open_fits_file(file_name)

            galaxy_type = file_name.split('/')[1]

            x_emit, values = Extractor.get_emit_values(
                                              file_name,
                                              fitsFile,
                                              self.left_cut_point,
                                              self.right_cut_point)


            original_peaks = Extractor.get_original_peaks(
                             file_name, fitsFile, galaxy_type,
                             x_emit)

            pos_peaker = Peaker(values)

            neg_values = [-i for i in values]
            neg_peaker = Peaker(neg_values)

            file_score = Score(True)

            for i in range(0, len(all_param_tuples)):
                param_tuple = all_param_tuples[i]

                pos_peaks = pos_peaker.get_peaks(self.peak_function,
                        *param_tuple)
                neg_peaks = neg_peaker.get_peaks(self.peak_function,
                        *param_tuple)

                detected_peaks = []
                detected_peaks.extend(pos_peaks)
                detected_peaks.extend(neg_peaks)

                # Detected peaks here
                detected_peaks.sort()

                pos_peaker.compare_original_detected(file_name,
                                                     fitsFile,
                                                     original_peaks,
                                                     detected_peaks,
                                                     file_score,
                                                     self.lambda_window)

                score = file_score.compute_fscore()

                # Here it saves it to a dictionary
                if param_tuple in self.all_param_scores:
                    self.all_param_scores[param_tuple].append(score)
                else:
                    self.all_param_scores[param_tuple] = [score]


                file_score.go_zero()

            Extractor.close_fits_file(fitsFile)

            current_file_index += 1