Exemple #1
0
    def onBrowse(self, event=None):
        dlg = wx.FileDialog(parent=self,
                            message='Select Files',
                            defaultDir=os.getcwd(),
                            wildcard=FILE_WILDCARDS,
                            style=wx.FD_OPEN | wx.FD_MULTIPLE
                            | wx.FD_CHANGE_DIR)

        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            mdir, p = os.path.split(path)
            os.chdir(mdir)
            roiname = self.wid_roi.GetValue().strip()
            if len(roiname) < 1:
                Popup(self, 'Must give ROI name!', 'No ROI name')
                return
            dirname = self.wid_dir.GetValue().strip()
            if len(dirname) > 1 and not os.path.exists(dirname):
                try:
                    os.mkdir(dirname)
                except:
                    Popup(self, 'Could not create directory %s' % dirname,
                          "could not create directory")
                    return
            badchans = self.wid_bad.GetValue().strip()
            bad_channels = []
            if len(badchans) > 0:
                bad_channels = [int(i.strip()) for i in badchans.split(',')]

            groups = []
            for fname in dlg.GetFilenames():
                corr_fcn = gsescan_deadtime_correct
                if is_GSEXDI(fname):
                    corr_fcn = gsexdi_deadtime_correct
                self.write_message("Correcting %s" % (fname))
                out = corr_fcn(fname,
                               roiname,
                               subdir=dirname,
                               bad=bad_channels,
                               _larch=self.larch)
                if out is not None:
                    out.mu = out.mufluor
                    out.filename = fname
                    groups.append((out, fname))

            athena_name = os.path.join(dirname,
                                       self.wid_ath.GetValue().strip())
            if self.wid_autoname.IsChecked():
                athena_name = new_filename(athena_name)

            _, aname = os.path.split(athena_name)
            self.wid_ath.SetValue(increment_filename(aname))

            aprj = AthenaProject(filename=athena_name, _larch=self.larch)
            for grp, label in groups:
                aprj.add_group(grp, signal='mu')
            aprj.save(use_gzip=True)
            self.write_message("Corrected %i files, wrote %s" %
                               (len(groups), aname))
Exemple #2
0
    def onNewROI(self, event=None):
        if (self.xmarker_left is None or
            self.xmarker_right is None or self.mca is None):
            return
        roiname = self.get_roiname()

        names = [str(r.name.lower()) for r in self.mca.rois]
        if str(roiname.lower()) in names:
            msg = "Overwrite Definition of ROI {:s}?".format(roiname)
            if (wx.ID_YES != Popup(self, msg, 'Overwrite ROI?', style=wx.YES_NO)):
                return False

        left, right  = self.xmarker_left, self.xmarker_right
        if left > right:
            left, right = right, left
        self.mca.add_roi(name=roiname, left=left, right=right, sort=True)
        self.set_roilist(mca=self.mca)
        for roi in self.mca.rois:
            if roi.name.lower()==roiname:
                selected_roi = roi
        self.plot(self.xdata, self.ydata)
        self.onROI(label=roiname)
        if self.selected_elem is not None:
            self.onShowLines(elem=self.selected_elem)
        return True
Exemple #3
0
 def onSaveProject(self, evt=None):
     groups = [gname for gname in self.controller.file_groups]
     if len(groups) < 1:
         Popup(self, "No files selected to export to Athena",
               "No files selected")
         return
     self.save_athena_project(groups[0], groups, prompt=True)
 def onDelROI(self, event=None):
     roiname = self.get_roiname()
     errmsg = None
     if self.roilist_sel is None:
         errmsg = 'No ROI selected to delete.'
     if errmsg is not None:
         return Popup(self, errmsg, 'Cannot Delete ROI')
     self.det.del_roi(roiname)
     XRFDisplayFrame.onDelROI(self)
Exemple #5
0
    def onExportAthena(self, evt=None):
        groups = []
        for checked in self.controller.filelist.GetCheckedStrings():
            groups.append(self.controller.file_groups[str(checked)])

        if len(groups) < 1:
             Popup(self, "No files selected to export to Athena",
                   "No files selected")
             return
        self.save_athena_project(groups[0], groups, prompt=True)
    def onBrowse(self, event=None):
        dlg = wx.FileDialog(parent=self,
                            message='Select Files',
                            defaultDir=os.getcwd(),
                            wildcard=FILE_WILDCARDS,
                            style=wx.FD_OPEN | wx.FD_MULTIPLE
                            | wx.FD_CHANGE_DIR)

        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            mdir, p = os.path.split(path)
            os.chdir(mdir)
            roiname = self.roi_wid.GetValue().strip()
            if len(roiname) < 1:
                Popup(self, 'Must give ROI name!', 'No ROI name')
                return
            dirname = self.dir_wid.GetValue().strip()
            if len(dirname) > 1 and not os.path.exists(dirname):
                try:
                    os.mkdir(dirname)
                except:
                    Popup(self, 'Could not create directory %s' % dirname,
                          "could not create directory")
                    return
            badchans = self.badchans_wid.GetValue().strip()
            bad_channels = []
            if len(badchans) > 0:
                bad_channels = [int(i.strip()) for i in badchans.split(',')]

            print(' Bad Channels : ', bad_channels)
            for fname in dlg.GetFilenames():
                corr_fcn = gsescan_deadtime_correct
                if is_GSEXDI(fname):
                    corr_fcn = gsexdi_deadtime_correct
                corr_fcn(fname,
                         roiname,
                         subdir=dirname,
                         bad=bad_channels,
                         _larch=self.larch)
Exemple #7
0
    def onNewROI(self, event=None):
        roiname = self.get_roiname()
        errmsg = None
        if self.xmarker_left is None or self.xmarker_right is None:
            errmsg = 'Must select right and left markers to define ROI'
        elif roiname in self.wids['roilist'].GetStrings():
            errmsg = '%s is already in ROI list - use a unique name.' % roiname
        if errmsg is not None:
            return Popup(self, errmsg, 'Cannot Define ROI')

        confirmed = XRFDisplayFrame.onNewROI(self)
        if confirmed:
            self.det.add_roi(roiname, lo=self.xmarker_left,
                             hi=self.xmarker_right)
Exemple #8
0
    def read_column_file(self, path):
        """read column file, generally as initial read"""
        parent, filename = os.path.split(path)
        with open(path, 'r') as fh:
            lines = fh.readlines()

        text = ''.join(lines)
        line1 = lines[0].lower()

        reader = 'read_ascii'
        if 'epics stepscan file' in line1:
            reader = 'read_gsexdi'
        elif 'xdi' in line1:
            reader = 'read_xdi'
        elif 'epics scan' in line1:
            reader = 'read_gsescan'

        tmpname = '_tmp_file_'
        read_cmd = "%s = %s('%s')" % (tmpname, reader, path)
        self.reader = reader
        _larch = self._larch
        if (not isinstance(_larch, larch.Interpreter)
                and hasattr(_larch, '_larch')):
            _larch = _larch._larch
        try:
            _larch.eval(read_cmd, add_history=True)
        except:
            pass
        if _larch.error:
            msg = ["Error trying to read '%s':" % path, ""]
            for err in _larch.error:
                exc_name, errmsg = err.get_error()
                msg.append(errmsg)

            title = "Cannot read %s" % path
            r = Popup(self.parent, "\n".join(msg), title)
            return None

        group = _larch.symtable.get_symbol(tmpname)
        _larch.symtable.del_symbol(tmpname)

        group.text = text
        group.path = path
        group.filename = filename
        group.groupname = file2groupname(filename,
                                         symtable=self._larch.symtable)
        return group
    def onRenameROI(self, event=None):
        roiname = self.get_roiname()
        errmsg = None
        if roiname in self.wids['roilist'].GetStrings():
            errmsg = '%s is already in ROI list - use a unique name.' % roiname
        elif self.roilist_sel is None:
            errmsg = 'No ROI selected to rename.'
        if errmsg is not None:
            return Popup(self, errmsg, 'Cannot Rename ROI')

        if self.roilist_sel < len(self.det.mcas[0].rois):
            self.det.rename_roi(self.roilist_sel, roiname)
            names = self.wids['roilist'].GetStrings()
            names[self.roilist_sel] = roiname
            self.wids['roilist'].Clear()
            for sname in names:
                self.wids['roilist'].Append(sname)
            self.wids['roilist'].SetSelection(self.roilist_sel)
Exemple #10
0
    def onReadFile(self, event=None):
        dlg = wx.FileDialog(self, message="Read MCA File",
                            defaultDir=os.getcwd(),
                            wildcard=FILE_WILDCARDS,
                            style=wx.FD_OPEN)
        path, re1ad = None, False
        if dlg.ShowModal() == wx.ID_OK:
            read = True
            path = dlg.GetPath().replace('\\', '/')
            if path in self.filemap:
                read = (wx.ID_YES == Popup(self, "Re-read file '%s'?" % path,
                                           'Re-read file?', style=wx.YES_NO))
        dlg.Destroy()

        if read:
            try:
                parent, fname = os.path.split(path)
            except:
                return
Exemple #11
0
    def onOK(self, event=None):
        """generate script to import groups"""
        namelist = [str(n) for n in self.grouplist.GetCheckedStrings()]
        if len(namelist) == 0:

            cancel = Popup(self,
                           """No data groups selected.
        Cancel import from this project?""",
                           'Cancel Import?',
                           style=wx.YES_NO)
            if wx.ID_YES == cancel:
                self.Destroy()
            else:
                return

        if self.read_ok_cb is not None:
            self.read_ok_cb(self.filename, namelist)

        self.Destroy()
Exemple #12
0
    def onReadDialog(self, event=None):
        dlg = wx.FileDialog(self, message="Read Data File",
                            defaultDir=os.getcwd(),
                            wildcard=FILE_WILDCARDS,
                            style=wx.FD_OPEN|wx.FD_MULTIPLE)
        self.paths2read = []
        if dlg.ShowModal() == wx.ID_OK:
            self.paths2read = dlg.GetPaths()
        dlg.Destroy()

        if len(self.paths2read) < 1:
            return

        path = self.paths2read.pop(0)
        path = path.replace('\\', '/')
        do_read = True
        if path in self.controller.file_groups:
            do_read = (wx.ID_YES == Popup(self,
                                          "Re-read file '%s'?" % path,
                                          'Re-read file?'))
        if do_read:
            self.onRead(path)
Exemple #13
0
    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)
Exemple #14
0
 def onConfirmDelROI(self, event=None):
     roiname = self.wids['roiname'].GetValue()
     msg = "Delete ROI {:s}?".format(roiname)
     if (wx.ID_YES == Popup(self, msg,   'Delete ROI?', style=wx.YES_NO)):
         self.onDelROI()