예제 #1
0
    def get_spectra(self):
        import util

        xpeaks = self.__find_peaks()

        image_length = self.image_data.shape[1]

        start_pixel = 1000
        yvalues_at_start = xpeaks[start_pixel]
        self.num_spectra = len(yvalues_at_start)
        xthreshold = 5
        ythreshold = 2
        cur_num_spectra = 0

        # Going from right to left
        for num, y in enumerate(yvalues_at_start):
            cur_y = y
            s = Spectrum([], [], self)

            cur_x = start_pixel
            for next_spec_x in range(start_pixel + 1, image_length):

                check_y = xpeaks[next_spec_x]
                # Check for xpixels to see if there exists a y pixel that's less
                # than some value away.
                spec_indices = np.where(abs(cur_y - check_y) <= ythreshold)[0]

                if len(spec_indices) > 0:
                    next_ind = spec_indices[0]
                    nexty = check_y[next_ind]
                    s.add_peak(next_spec_x, nexty)
                    cur_x = next_spec_x
                    cur_y = nexty

                if abs(next_spec_x - cur_x) >= xthreshold:
                    break

            cur_x = start_pixel
            cur_y = y
            for prev_spec_x in range(start_pixel - 1, 0, -1):

                check_y = xpeaks[prev_spec_x]
                spec_indices = np.where(abs(cur_y - check_y) <= ythreshold)[0]

                if len(spec_indices) > 0:
                    prev_ind = spec_indices[0]
                    prevy = check_y[prev_ind]
                    s.add_peak(prev_spec_x, prevy)
                    cur_x = prev_spec_x
                    cur_y = prevy

                if abs(prev_spec_x - cur_x) >= xthreshold:
                    break

            build_prep_success = s.build_prepare()
            if build_prep_success:
                cur_num_spectra += 1
                self.spectra.append(s)
                print("Spectrum %d/%d ready for building..." %
                      (cur_num_spectra, self.num_spectra))
            else:
                self.num_spectra -= 1

        self.__fit_overlap_boundary_parabola()
        self.__update_spectral_boundaries()

        built_spectra = []
        cur_num_spectra = 0

        for spectrum in self.spectra:

            build_success = spectrum.build()

            if build_success:
                cur_num_spectra += 1
                built_spectra.append(spectrum)
                print("Building spectrum %d/%d" %
                      (cur_num_spectra, self.num_spectra))
                print("Min x:", spectrum.xvalues[0], "\nMax x:",
                      spectrum.xvalues[-1])
            else:
                self.num_spectra -= 1

        self.spectra = built_spectra