def onSaveGroupMultiFits(self, evt=None): "Save Data and Best N Fits for the current group" dgroup = self.datagroup nfits = int(self.wids['plot_nchoice'].GetStringSelection()) results = dgroup.lcf_result[:nfits] nresults = len(results) deffile = "%s_LinearFits%i.dat" % (dgroup.filename, nresults) wcards = 'Data Files (*.dat)|*.dat|All files (*.*)|*.*' path = FileSave(self, 'Save Best N Fits', default_file=deffile, wildcard=wcards) if path is None: return form = self.form header = [ 'Larch Linear Arrays for %2.2d best results' % (nresults), 'Dataset filename: %s ' % dgroup.filename, 'Larch group: %s ' % dgroup.groupname, 'Array name: %s' % form['arrayname'], 'Energy fit range: [%f, %f]' % (form['elo'], form['ehi']) ] label = [' energy ', ' data '] label.extend([' fit_%2.2d ' % i for i in range(nresults)]) label = ' '.join(label) out = [results[0].xdata, results[0].ydata] for i, res in enumerate(results): out.append(results[i].yfit) _larch = self.parent.controller.larch write_ascii(path, header=header, label=label, _larch=_larch, *out)
def onSaveGroupMultiFits(self, evt=None): "Save Data and Best N Fits for the current group" dgroup = self.datagroup nfits = int(self.wids['plot_nchoice'].GetStringSelection()) results = dgroup.lcf_result[:nfits] nresults = len(results) deffile = "%s_LinearFits%i.dat" % (dgroup.filename, nresults) wcards = 'Data Files (*.dat)|*.dat|All files (*.*)|*.*' path = FileSave(self, 'Save Best N Fits', default_file=deffile, wildcard=wcards) if path is None: return form = self.form header = ['Larch Linear Arrays for %2.2d best results' % (nresults), 'Dataset filename: %s ' % dgroup.filename, 'Larch group: %s ' % dgroup.groupname, 'Array name: %s' % form['arrayname'], 'Energy fit range: [%f, %f]' % (form['elo'], form['ehi'])] label = [' energy ', ' data '] label.extend([' fit_%2.2d ' % i for i in range(nresults)]) label = ' '.join(label) out = [results[0].xdata, results[0].ydata] for i, res in enumerate(results): out.append(results[i].yfit) _larch = self.parent.controller.larch write_ascii(path, header=header, label=label, _larch=_larch, *out)
def onSaveGroupStats(self, evt=None): "Save Statistics and Weights for Best N Fits for the current group" dgroup = self.datagroup nfits = int(self.wids['plot_nchoice'].GetStringSelection()) results = dgroup.lcf_result[:nfits] nresults = len(results) deffile = "%s_LinearStats%i.dat" % (dgroup.filename, nresults) wcards = 'Data Files (*.dat)|*.dat|All files (*.*)|*.*' path = FileSave(self, 'Save Statistics and Weights for Best N Fits', default_file=deffile, wildcard=wcards) if path is None: return form = self.form header = [ 'Larch Linear Fit Statistics for %2.2d best results' % (nresults), 'Dataset filename: %s ' % dgroup.filename, 'Larch group: %s ' % dgroup.groupname, 'Array name: %s' % form['arrayname'], 'Energy fit range: [%f, %f]' % (form['elo'], form['ehi']), 'N_Data: %d' % len(results[0].xdata) ] label = [ 'fit #', 'n_varys', 'n_eval', 'chi2', 'chi2_reduced', 'akaike_info', 'bayesian_info' ] label.extend(form['comp_names']) label.append('Total') for i in range(len(label)): if len(label[i]) < 13: label[i] = (" %s " % label[i])[:13] label = ' '.join(label) out = [] for i, res in enumerate(results): dat = [(i + 1)] for attr in ('nvarys', 'nfev', 'chisqr', 'redchi', 'aic', 'bic'): dat.append(getattr(res.result, attr)) for cname in form['comp_names'] + ['total']: val = 0.0 if cname in res.params: val = res.params[cname].value dat.append(val) out.append(dat) out = np.array(out).transpose() _larch = self.parent.controller.larch write_ascii(path, header=header, label=label, _larch=_larch, *out)
def onSaveGroupStats(self, evt=None): "Save Statistics and Weights for Best N Fits for the current group" dgroup = self.datagroup nfits = int(self.wids['plot_nchoice'].GetStringSelection()) results = dgroup.lcf_result[:nfits] nresults = len(results) deffile = "%s_LinearStats%i.dat" % (dgroup.filename, nresults) wcards = 'Data Files (*.dat)|*.dat|All files (*.*)|*.*' path = FileSave(self, 'Save Statistics and Weights for Best N Fits', default_file=deffile, wildcard=wcards) if path is None: return form = self.form header = ['Larch Linear Fit Statistics for %2.2d best results' % (nresults), 'Dataset filename: %s ' % dgroup.filename, 'Larch group: %s ' % dgroup.groupname, 'Array name: %s' % form['arrayname'], 'Energy fit range: [%f, %f]' % (form['elo'], form['ehi']), 'N_Data: %d' % len(results[0].xdata)] label = ['fit #', 'n_varys', 'n_eval', 'chi2', 'chi2_reduced', 'akaike_info', 'bayesian_info'] label.extend(form['comp_names']) label.append('Total') for i in range(len(label)): if len(label[i]) < 13: label[i] = (" %s " % label[i])[:13] label = ' '.join(label) out = [] for i, res in enumerate(results): dat = [(i+1)] for attr in ('nvarys', 'nfev', 'chisqr', 'redchi', 'aic', 'bic'): dat.append(getattr(res.result, attr)) for cname in form['comp_names'] + ['total']: val = 0.0 if cname in res.params: val = res.params[cname].value dat.append(val) out.append(dat) out = np.array(out).transpose() _larch = self.parent.controller.larch write_ascii(path, header=header, label=label, _larch=_larch, *out)
def onSaveGroupFit(self, evt=None): "Save Fit and Compoents for current fit to Data File" nfit = self.current_fit dgroup = self.datagroup nfits = int(self.wids['plot_nchoice'].GetStringSelection()) deffile = "%s_LinearFit%i.dat" % (dgroup.filename, nfit + 1) wcards = 'Data Files (*.dat)|*.dat|All files (*.*)|*.*' path = FileSave(self, 'Save Fit and Components to File', default_file=deffile, wildcard=wcards) if path is None: return form = self.form label = [' energy ', ' data ', ' best_fit '] result = dgroup.lcf_result[nfit] header = [ 'Larch Linear Fit Result for Fit: #%2.2d' % (nfit + 1), 'Dataset filename: %s ' % dgroup.filename, 'Larch group: %s ' % dgroup.groupname, 'Array name: %s' % form['arrayname'], 'Energy fit range: [%f, %f]' % (form['elo'], form['ehi']), 'Components: ' ] for key, val in result.weights.items(): header.append(' %s: %f' % (key, val)) report = fit_report(result.result).split('\n') header.extend(report) out = [result.xdata, result.ydata, result.yfit] for compname, compdata in result.ycomps.items(): label.append(' %s' % (compname + ' ' * (max(1, 15 - len(compname))))) out.append(compdata) label = ' '.join(label) _larch = self.parent.controller.larch write_ascii(path, header=header, label=label, _larch=_larch, *out)
def onSaveGroupFit(self, evt=None): "Save Fit and Compoents for current fit to Data File" nfit = self.current_fit dgroup = self.datagroup nfits = int(self.wids['plot_nchoice'].GetStringSelection()) deffile = "%s_LinearFit%i.dat" % (dgroup.filename, nfit+1) wcards = 'Data Files (*.dat)|*.dat|All files (*.*)|*.*' path = FileSave(self, 'Save Fit and Components to File', default_file=deffile, wildcard=wcards) if path is None: return form = self.form label = [' energy ', ' data ', ' best_fit '] result = dgroup.lcf_result[nfit] header = ['Larch Linear Fit Result for Fit: #%2.2d' % (nfit+1), 'Dataset filename: %s ' % dgroup.filename, 'Larch group: %s ' % dgroup.groupname, 'Array name: %s' % form['arrayname'], 'Energy fit range: [%f, %f]' % (form['elo'], form['ehi']), 'Components: '] for key, val in result.weights.items(): header.append(' %s: %f' % (key, val)) report = fit_report(result.result).split('\n') header.extend(report) out = [result.xdata, result.ydata, result.yfit] for compname, compdata in result.ycomps.items(): label.append(' %s' % (compname + ' '*(max(1, 15-len(compname))))) out.append(compdata) label = ' '.join(label) _larch = self.parent.controller.larch write_ascii(path, header=header, label=label, _larch=_larch, *out)