def fit_specim(specim, wav, model_crit):
    fitim = np.zeros_like(specim)
    peaks = np.zeros((specim.shape[0],2))
    num_spec = specim.shape[0]
    for i in range(num_spec):
        spec = specim[i]
        model, model_name = model_crit(i)
        fit = spectra_fit.fit_spectra(spec, wav, model)
        fitim[i] = fit.fitted_spectra
        peaks[i] = np.array([fit.parameters['dipole_centre'].value, fit.parameters['quad_centre'].value])
    return fit, peaks
 def fit(self):
     save_dir = 'c:/users/alan/skydrive/documents/phd/0 - experiment/data/best data/nov_2012/day_21_analysis'
     num_spec = self.spectral_image.shape[0]
     for i in range(num_spec):
         model, model_name = self.model_crit(i)
         fit = spectra_fit.fit_spectra(self.spectral_image[i], self.axis, model)
         self.fits.append(fit)
         
         plt.figure()
         plt.plot(fit.axis, fit.spectra, 'k.')
         plt.plot(fit.axis, fit.fitted_spectra, 'r-')
         for mode in fit.fitted_modes:
             plt.plot(fit.axis, fit.fitted_modes[mode], 'r--')
         fname = os.path.join(save_dir, 'spec_'+str(i)+'_'+model_name)
         plt.savefig(fname + '.png', bbox_inches=0)
         plt.close()