else: yoffset_guess = ydata[-1] #find width at half height as estimate of sigma if sigma_guess is None: variance = numpy.dot( numpy.abs(ydata), (xdata - mean_guess)** 2) / numpy.abs(ydata).sum() # Fast and numerically precise sigma_guess = math.sqrt(variance) #put guess params into an array ready for fitting p0 = numpy.array([amplitude_guess, mean_guess, sigma_guess, yoffset_guess]) #define the gaussian function and associated error function fitfunc = lambda p, x: p[0] * scipy.exp(-(x - p[1])**2 / (2.0 * p[2]**2)) + p[3] errfunc = lambda p, x, y: fitfunc(p, x) - y # do the fitting p1, success = scipy.optimize.leastsq(errfunc, p0, args=(xdata, ydata)) if success not in (1, 2, 3, 4): raise RuntimeError, "Could not fit Gaussian to data." fit_y_data = [fitfunc(p1, i) for i in xdata] return xdata, fit_y_data, GaussianParameters(*p1) plugins.register(Fitting())
from avoplot.plugins import register from UVVIS_plugin import UVVISPlugin #register the spectrum plotting plugin tester register(UVVISPlugin())
from avoplot.plugins import register from fitting import Fitting #register the fitting plugin register(Fitting())
if mean_guess > data_midpoint: yoffset_guess = ydata[0] else: yoffset_guess = ydata[-1] #find width at half height as estimate of sigma if sigma_guess is None: variance = numpy.dot(numpy.abs(ydata), (xdata-mean_guess)**2)/numpy.abs(ydata).sum() # Fast and numerically precise sigma_guess = math.sqrt(variance) #put guess params into an array ready for fitting p0 = numpy.array([amplitude_guess, mean_guess, sigma_guess, yoffset_guess]) #define the gaussian function and associated error function fitfunc = lambda p, x: p[0]*scipy.exp(-(x-p[1])**2/(2.0*p[2]**2)) + p[3] errfunc = lambda p, x, y: fitfunc(p,x)-y # do the fitting p1, success = scipy.optimize.leastsq(errfunc, p0, args=(xdata,ydata)) if success not in (1,2,3,4): raise RuntimeError, "Could not fit Gaussian to data." fit_y_data = [fitfunc(p1, i) for i in xdata] return xdata, fit_y_data, GaussianParameters(*p1) plugins.register(Fitting())
maxValue=30, style=wx.SL_LABELS) #add the slider to the control panel's sizer self.Add(self.slider, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL, border=10) #register an event handler for slider change events wx.EVT_COMMAND_SCROLL(self, self.slider.GetId(), self.on_slider_change) def on_slider_change(self, evnt): """ Event handler for frequency slider change events. """ #change the frequency of the sine wave data accordingly f = self.slider.GetValue() x_data = numpy.linspace(0, 7, 2000) y_data = numpy.sin(x_data * f) #change the data in the series object self.series.set_xy_data(xdata=x_data, ydata=y_data) #draw our changes on the display self.series.update() #register the plugin with AvoPlot plugins.register(AdvExamplePlugin())
# def __init__(self, parent, filename): # self.wavenumber, self.absorbance = load_ftir_file(filename) # print classify_spectrum(self.wavenumber, self.absorbance) # PlotPanelBase.__init__(self,parent, os.path.basename(filename)) # self.control_panel = FTIRFittingPanel(self, classify_spectrum(self.wavenumber, self.absorbance)) # self.h_sizer.Insert(0,self.control_panel, flag=wx.ALIGN_LEFT) # # self.create_plot() # # # def fit_h2o(self, evnt): # try: # wx.BeginBusyCursor() # bkgd = fit_h2o_peak(self.wavenumber, self.absorbance, self.axes, plot_fit=True) # peak_height = calc_h2o_peak_height(self.wavenumber, self.absorbance, bkgd) # self.control_panel.set_peak_height(peak_height) # # self.canvas.draw() # self.canvas.gui_repaint() # finally: # wx.EndBusyCursor() # # def create_plot(self): # self.axes.plot(self.wavenumber, self.absorbance) # self.axes.set_xlim((self.axes.get_xlim()[1],self.axes.get_xlim()[0])) # self.axes.set_xlabel("Wavenumber") # self.axes.set_ylabel("Absorbance") plugins.register(UVVISPlugin())
#Copyright (C) Nial Peters 2013 # #This file is part of AvoPlot. # #AvoPlot is free software: you can redistribute it and/or modify #it under the terms of the GNU General Public License as published by #the Free Software Foundation, either version 3 of the License, or #(at your option) any later version. # #AvoPlot is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with AvoPlot. If not, see <http://www.gnu.org/licenses/>. from avoplot.plugins import register from txt_file_loader import TextFilePlugin register(TextFilePlugin())
# Copyright (C) Nial Peters 2013 # # This file is part of AvoPlot. # # AvoPlot is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # AvoPlot is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with AvoPlot. If not, see <http://www.gnu.org/licenses/>. from avoplot.plugins import register from txt_file_loader import TextFilePlugin register(TextFilePlugin())
from avoplot.plugins import register from ftir_spectrum import FTIRPlugin #register the spectrum plotting plugin register(FTIRPlugin())
#change the data in the series object self.series.set_xy_data(xdata=res[:,0], ydata=res[:,1]) #draw our changes on the display self.series.update() class ProsailPlugin(plugins.AvoPlotPluginSimple): def __init__(self): super(ProsailPlugin, self).__init__("PyProSAIL", ProSAILSeries) self.set_menu_entry(['Optical RS','PyProSAIL'], "Plot outputs from the PyProSAIL vegetation reflectance model") def plot_into_subplot(self, subplot): res = pyprosail.run(1.5, 40, 8, 0, 0.1, 0.009, 1, 3, 0.01, 30, 0, 10, 0, pyprosail.Planophile) data_series = ProSAILSeries("ProSAIL Output", xdata=res[:,0], ydata=res[:,1]) subplot.add_data_series(data_series) return True plugins.register(ProsailPlugin())
# def __init__(self, parent, filename): # self.wavenumber, self.absorbance = load_ftir_file(filename) # print classify_spectrum(self.wavenumber, self.absorbance) # PlotPanelBase.__init__(self,parent, os.path.basename(filename)) # self.control_panel = FTIRFittingPanel(self, classify_spectrum(self.wavenumber, self.absorbance)) # self.h_sizer.Insert(0,self.control_panel, flag=wx.ALIGN_LEFT) # # self.create_plot() # # # def fit_h2o(self, evnt): # try: # wx.BeginBusyCursor() # bkgd = fit_h2o_peak(self.wavenumber, self.absorbance, self.axes, plot_fit=True) # peak_height = calc_h2o_peak_height(self.wavenumber, self.absorbance, bkgd) # self.control_panel.set_peak_height(peak_height) # # self.canvas.draw() # self.canvas.gui_repaint() # finally: # wx.EndBusyCursor() # # def create_plot(self): # self.axes.plot(self.wavenumber, self.absorbance) # self.axes.set_xlim((self.axes.get_xlim()[1],self.axes.get_xlim()[0])) # self.axes.set_xlabel("Wavenumber") # self.axes.set_ylabel("Absorbance") plugins.register(FTIRPlugin())