def onSaveMCAFile(self, event=None, **kws): tmp = ''' # print 'SaveMCA File' deffile = '' if hasattr(self.mca, 'sourcefile'): deffile = "%s%s" % (deffile, getattr(self.mca, 'sourcefile')) if hasattr(self.mca, 'areaname'): deffile = "%s%s" % (deffile, getattr(self.mca, 'areaname')) if deffile == '': deffile ='test' if not deffile.endswith('.mca'): deffile = deffile + '.mca' ''' deffile = 'save.mca' # fix_filename(str(deffile)) outfile = FileSave(self, "Save MCA File", default_file=deffile, wildcard=FILE_WILDCARDS) environ = [] if self.scandb is not None: c, table = self.scandb.get_table('pvs') pvrows = self.scandb.query(table).all() for row in pvrows: addr = str(row.name) desc = str(row.notes) val = self.scandb.pvs[addr].get(as_string=True) environ.append((addr, val, desc)) if outfile is not None: self.det.save_mcafile(outfile, environ=environ)
def onSaveFitResult(self, event=None): dgroup = self.controller.get_group() deffile = dgroup.filename.replace('.', '_') + '.modl' outfile = FileSave(self, 'Save Fit Result', default_file=deffile, wildcard=ModelWcards) if outfile is not None: try: self.save_fit_result(dgroup.fit_history[-1], outfile) except IOError: print('could not write %s' % outfile)
def onSaveMCAFile(self, event=None, **kws): deffile = '' if hasattr(self.mca, 'sourcefile'): deffile = "%s%s" % (deffile, getattr(self.mca, 'sourcefile')) if hasattr(self.mca, 'areaname'): deffile = "%s%s" % (deffile, getattr(self.mca, 'areaname')) if deffile == '': deffile ='test' if not deffile.endswith('.mca'): deffile = deffile + '.mca' deffile = fix_filename(str(deffile)) outfile = FileSave(self, "Save MCA File", default_file=deffile, wildcard=FILE_WILDCARDS) if outfile is not None: self.mca.save_mcafile(outfile)
def save_athena_project(self, filename, grouplist, prompt=True): if len(grouplist) < 1: return savegroups = [self.controller.get_group(gname) for gname in grouplist] deffile = "%s_%i.prj" % (filename, len(grouplist)) wcards = 'Athena Projects (*.prj)|*.prj|All files (*.*)|*.*' outfile = FileSave(self, 'Save Groups to Athena Project File', default_file=deffile, wildcard=wcards) if outfile is None: return aprj = AthenaProject(filename=outfile, _larch=self.larch) for label, grp in zip(grouplist, savegroups): aprj.add_group(grp, label=label) aprj.save(use_gzip=True)
def onSaveColumnFile(self, event=None, **kws): deffile = '' if hasattr(self.mca, 'sourcefile'): deffile = "%s%s" % (deffile, getattr(self.mca, 'sourcefile')) elif hasattr(self.mca, 'filename'): deffile = "%s%s" % (deffile, getattr(self.mca, 'filename')) if hasattr(self.mca, 'areaname'): deffile = "%s_%s" % (deffile, getattr(self.mca, 'areaname')) if deffile == '': deffile ='test' if not deffile.endswith('.dat'): deffile = deffile + '.dat' deffile = fix_filename(str(deffile)) ASCII_WILDCARDS = "Data File (*.dat)|*.dat|All files (*.*)|*.*" outfile = FileSave(self, "Save ASCII File for MCA Data", default_file=deffile, wildcard=ASCII_WILDCARDS) if outfile is not None: self.mca.save_columnfile(outfile)
def onSaveFit(self, event=None): dgroup = self.get_datagroup() deffile = dgroup.filename.replace('.', '_') + '.fitconf' outfile = FileSave(self, 'Save Fit Configuration and Results', default_file=deffile, wildcard=FITCONF_WILDCARDS) if outfile is None: return buff = ['#XYFit Config version 1'] buff.append(json.dumps(encode4js(self.summary), encoding='UTF-8',default=str)) buff.append('') try: fout = open(outfile, 'w') fout.write('\n'.join(buff)) fout.close() except IOError: print('could not write %s' % outfile)
def onExportCSV(self, evt=None): group_ids = self.controller.filelist.GetCheckedStrings() savegroups = [] groupnames = [] for checked in group_ids: groupname = self.controller.file_groups[str(checked)] dgroup = self.controller.get_group(groupname) savegroups.append(dgroup) groupnames.append(groupname) if len(savegroups) < 1: Popup(self, "No files selected to export to CSV", "No files selected") return deffile = "%s_%i.csv" % (groupname, len(groupnames)) wcards = 'CSV Files (*.csv)|*.cvs|All files (*.*)|*.*' outfile = FileSave(self, 'Export Selected Groups to CSV File', default_file=deffile, wildcard=wcards) if outfile is None: return groups2csv(savegroups, outfile, x='energy', y='norm', _larch=self.larch)
def onExportFitResult(self, event=None): dgroup = self.controller.get_group() deffile = dgroup.filename.replace('.', '_') + '_result.xdi' wcards = 'All files (*.*)|*.*' outfile = FileSave(self, 'Export Fit Result', default_file=deffile, wildcard=wcards) if outfile is not None: i1, i2 = self.get_xranges(dgroup.xdat) x = dgroup.xdat[i1:i2] y = dgroup.ydat[i1:i2] yerr = None if hasattr(dgroup, 'yerr'): yerr = 1.0*dgroup.yerr if not isinstance(yerr, np.ndarray): yerr = yerr * np.ones(len(y)) else: yerr = yerr[i1:i2] export_modelresult(dgroup.fit_history[-1], filename=outfile, datafile=dgroup.filename, ydata=y, yerr=yerr, x=x)