예제 #1
0
    def on_label_peaks(self, e=None):
        self.peaks = ud.peakdetect(self.data1d, window=3)
        print("Peaks:", self.peaks[:, 0])

        for i, p in enumerate(self.peaks):
            y = p[1]
            label=str(np.round(p[0], 3))
            self.plot3.addtext(label, p[0] + 0.075, y * 0.95, vlines=False)
            self.plot3.addtext("", p[0], y, vlines=True)
예제 #2
0
    def on_fit(self, e):
        peaks = ud.peakdetect(self.data1d, window=2)
        print("Peaks:", peaks[:, 0])
        peaks = np.concatenate((peaks, [[0, np.amin(self.data1d[:, 1])]]))
        fitdat, fits = MassFitter(self.data1d, peaks, 3, "microguess").perform_fit()
        print("Fits:", fits[:, 0])

        self.plot1.plotadd(self.data1d[:, 0], fitdat, "green", nopaint=False)
        self.plot1.repaint()
예제 #3
0
    def on_label_peaks(self, e=None):
        peaks = ud.peakdetect(self.data1d, window=3)
        print("Peaks:", peaks[:, 0])

        for p in peaks:
            y = p[1]
            self.plot3.addtext(str(np.round(p[0], 3)),
                               p[0] + 0.075,
                               y * 0.95,
                               vlines=False)
            self.plot3.addtext("", p[0], y, vlines=True)
예제 #4
0
 def on_get_peaks(self, e=None, data=None):
     if data is None:
         data=self.diffdat
     print("Data range", np.amin(data[:,0]), "to", np.amax(data[:,0]))
     peaks = peakdetect(data, window=1000.)[:, 0]
     for p in peaks:
         index = nearest(data[:, 0], p)
         idiff = int(3 / self.binsize)
         print("Peak value:", p)
         fit, fitdat = fitting.isolated_peak_fit(data[index - idiff:index + idiff, 0],
                                                 data[index - idiff:index + idiff, 1], psfun=0)
         print("Peak Fit:", fit[1, 0], "+/-", fit[1, 1])
예제 #5
0
    def on_fit(self, e):
        peaks = ud.peakdetect(self.data1d, window=3)
        print("Peaks:", peaks[:, 0])
        peaks = np.concatenate((peaks, [[0, np.amin(self.data1d[:, 1])]]))
        fitdat, fits = MassFitter(self.data1d, peaks, 3, "microguess").perform_fit()
        print("Fits:", fits[:, 0])

        self.plot3.plotadd(self.data1d[:, 0], fitdat, "green", nopaint=False)

        for f in fits[:, 0]:
            if np.amin(self.data1d[:, 0]) <= f <= np.amax(self.data1d[:, 0]):
                y = np.amax(self.data1d[ud.nearest(self.data1d[:, 0], f), 1])
                self.plot3.addtext(str(np.round(f, 3)), f + 0.075, y * 0.95, vlines=False)
                self.plot3.addtext("", f, y, vlines=True)
예제 #6
0
    def sub_div(self, e=0):
        try:
            masses = []
            for p in self.eng.pks.peaks:
                if p.ignore == 0:
                    masses.append(p.mass)
            defaultsub = np.amin(masses)
        except:
            defaultsub = 44088

        defaultdiv = self.eng.config.molig
        dlg = miscwindows.DoubleInputDialog(self.view)
        dlg.initialize_interface("Subtract and Divide", "Subtract:",
                                 str(defaultsub), "Divide:", str(defaultdiv))
        dlg.ShowModal()
        try:
            sub = float(dlg.value)
            div = float(dlg.value2)
        except:
            print("Error with Subtract and Divide Inputs:", dlg.value,
                  dlg.value2)
            return 0

        try:
            sd_results = []
            message = "Average Masses:\n\n"
            outstring = ""
            for s in self.eng.data.spectra:
                pks = peakstructure.Peaks()
                peaks = ud.peakdetect(s.massdat, self.eng.config)
                pks.add_peaks(peaks, massbins=self.eng.config.massbins)
                sd_result = ud.subtract_and_divide(pks, sub, div)
                sd_results.append(sd_result)

                outstring += str(sd_result) + "\n"

            avg = np.mean(sd_results)
            message += outstring
            message += "\nOverall Average: " + str(avg)
            outstring += "\n" + str(avg)
            self.copy_to_clipboard(outstring)
            self.warn(message, caption="Subtract and Divide Results")

        except:
            sd_result = ud.subtract_and_divide(self.eng.pks, sub, div)
            outstring = str(sd_result)
            message = "Average Mass: " + outstring
            self.copy_to_clipboard(outstring)
            self.warn(message, caption="Subtract and Divide Results")
예제 #7
0
    def get_maxima(self):
        """
        Detect peaks in self.offset_totals (the total extracted intensitites) and set default parameters.
        Plot the results.
        :return: None
        """
        defaultcolors = [[255, 0, 0, 255], [0, 0, 255, 255], [0, 255, 0, 255],
                         [255, 0, 255, 255]]
        defaultmarkers = ['o', 'v', '^', '>', 's', 'd', '*']

        peaks = ud.peakdetect(self.offset_totals, window=2, threshold=0.1)
        print(peaks)
        self.zoffs = []
        for p in peaks:
            i = ud.nearest(self.offset_totals[:, 0], p[0])
            zoff = Zoffset()
            zoff.make(p[0], p[1], i,
                      defaultcolors[len(self.zoffs) % len(defaultcolors)],
                      defaultmarkers[len(self.zoffs)])
            self.zoffs.append(zoff)
        self.plot_zoffs()
예제 #8
0
    def PlotPeaks(self):
        peaks = ud.peakdetect(self.dec2, window=10, threshold=0.1)
        spacing = 0.4
        simdat = deepcopy(self.data)
        simdat[:, 1] = 0
        for i, p in enumerate(peaks):
            sticks = self.dec2[:, 0] == p[0]

            sticks = sticks.astype(np.float) * p[1]
            sticks = cconv2(sticks, self.kernel)

            simdat[:, 1] += sticks
            # plt.plot(simdat[:,0], sticks-(i+1)*spacing)

        sim2 = cconv2(self.dec, self.kernel)
        sim2 /= np.amax(sim2)
        # plt.plot(simdat[:,0], simdat[:,1], color="r")
        plt.plot(self.data[:, 0], self.data[:, 1], color="k")
        plt.plot(self.data[:, 0], self.dec + spacing * 2, color="b")
        plt.plot(self.data[:, 0], sim2, color="r")
        # plt.plot(dec[:,0], kernel)

        # plt.xlim(41500, 43000)
        plt.show()
예제 #9
0
def MD_Fitter(data,
              mds=None,
              maxshift=0.1,
              widthguess=0.05,
              shiftguess=None,
              plot=False):
    data[:, 1] = data[:, 1] - np.amin(data[:, 1])
    data[:, 1] = data[:, 1] / np.amax(data[:, 1])
    peaks = ud.peakdetect(data, threshold=0.1)
    #print(peaks, mds)
    mds = np.array(mds)

    if shiftguess is None:
        a, b = np.meshgrid(peaks[:, 0], mds)
        minarg = np.argmin(np.abs(a - b))
        minarg = np.unravel_index(minarg, a.shape)
        shiftguess = a - b
        shiftguess = shiftguess[minarg]
        if np.abs(shiftguess) > maxshift:
            print("Shift Guess too High:", shiftguess, maxshift)
            shiftguess = 0
        else:
            print("Guess for shift:", shiftguess)

    widths = [0.75, 1, 1.25]
    #widths=[1]
    error = 100000000000
    finalfit = None
    finalfitdat = None
    #shifts = [0, shiftguess, -1*shiftguess]
    shifts = [shiftguess]
    for w in widths:
        for s in shifts:
            widths = np.ones(len(mds)) * w * widthguess

            heights = []
            for m in mds:
                height = ud.data_extract(data, m + s, 0)
                heights.append(height)
            heights = np.array(heights)

            try:
                guessarray = np.transpose([mds + s, widths, heights]).ravel()
            except Exception as e:
                print(e)
                print(mds, s, widths, heights)
                guessarray = np.transpose([mds, widths, heights]).ravel()

            fit = least_squares_minimize(data,
                                         guessarray,
                                         0,
                                         mds,
                                         nparam=3,
                                         maxshift=maxshift)
            fitdat = make_mass_list(data, fit, 0, mds, nparam=3)

            newerror = np.sum((data[:, 1] - fitdat)**2)
            if newerror < error:
                error = newerror
                finalfit = fit
                finalfitdat = fitdat
    fit = finalfit
    fitdat = finalfitdat
    print(fit, error)

    if plot:
        import matplotlib.pyplot as plt
        plt.subplot(121)
        plt.plot(data[:, 0], data[:, 1], color="k")
        plt.plot(data[:, 0], fitdat, linestyle="--", color="r")
        for i, m in enumerate(mds):
            fdat = make_mass_list(data, fit[i], 0, mds, nparam=3)
            plt.plot(data[:, 0], fdat * fit[i, 2], label=str(i))
        plt.legend()
        plt.subplot(122)
        plt.bar(np.arange(len(mds)), fit[:, -1])
        plt.show()

    return fit, fitdat
예제 #10
0
            sub = float(sub)
        except:
            sub = None
        self.sub = sub

        div = self.ctldiv.GetValue()
        try:
            div = float(div)
        except:
            div = None
        self.div = div
        self.subdiv()
        self.make_plot()

    def change_type(self, e=None):
        self.replot()


if __name__ == "__main__":
    path = "C:\Python\\UniDec3\\unidec_bin\\Example Data\\POPC_Nanodiscs_unidecfiles\\POPC_Nanodiscs_mass.txt"
    data = np.loadtxt(path)

    pks = peakstructure.Peaks()
    peaks = ud.peakdetect(data, threshold=0.1)
    pks.add_peaks(peaks)

    app = wx.App()
    panel = SubDivFrame(None, data, pks)
    panel.replot()
    app.MainLoop()