Beispiel #1
0
    def make_e0panel(self):
        p = wx.Panel(self)
        s = wx.BoxSizer(wx.HORIZONTAL)
        self.e0 = FloatCtrl(p, precision=2, value=7112.0, minval=0, maxval=1e7,
                            size=(80, -1), act_on_losefocus=True,
                            action=Closure(self.onVal, label='e0'))

        self.elemchoice = add_choice(p, ELEM_LIST,
                                     action=self.onEdgeChoice, size=(70, -1))
        self.elemchoice.SetMaxSize((60, 25))
        self.elemchoice.SetStringSelection('Fe')

        self.edgechoice = add_choice(p, self.edges_list, size=(50, -1),
                                     action=self.onEdgeChoice)

        s.Add(SimpleText(p, " Edge Energy:", size=(120, -1),
                         style=wx.ALIGN_LEFT), 0, CEN, 2)
        s.Add(self.e0,   0, LEFT, 2)
        s.Add(SimpleText(p, "   Element:  "),  0, LEFT, 3)
        s.Add(self.elemchoice,                 0, LEFT, 3)
        s.Add(SimpleText(p, "    Edge:  "),    0, LEFT, 3)
        s.Add(self.edgechoice,                 0, LEFT, 3)
        s.Add(SimpleText(p, "   Current Energy:", size=(170, -1),
                         style=wx.ALIGN_LEFT), 0, CEN, 2)
        self.energy_pv = PVStaticText(p, pv=None, size=(100, -1),
                                      style=wx.ALIGN_CENTER)
        s.Add(self.energy_pv, 0, CEN, 2)
        pack(p, s)
        return p
Beispiel #2
0
    def __init__(self, parent, prefix, pvdata, **kws):
        wx.Panel.__init__(self, parent, -1, **kws)
        self.sizer = sizer = wx.GridBagSizer(3, 3)
        self.wids = {}
        self.prefix = prefix
        irow = -1
        for label, pvsuff, dtype, rsuff, wsize in pvdata:

            pvname = prefix + pvsuff
            ctrl = pv_control(dtype)
            self.wids[label] = ctrl(self, pv=get_pv(pvname), size=(wsize, -1))

            title = wx.StaticText(self,
                                  label=label,
                                  size=(8 * len(label), -1),
                                  style=labstyle)
            irow += 1
            sizer.Add(title, (irow, 0), (1, 1), labstyle)

            if rsuff:
                rlabel = label + rsuff
                rname = pvname + rsuff
                self.wids[rlabel] = PVStaticText(self,
                                                 pv=get_pv(rname),
                                                 size=(wsize, -1))

                sizer.Add(self.wids[label], (irow, 1), (1, 1), labstyle)
                sizer.Add(self.wids[rlabel], (irow, 2), (1, 1), labstyle)
            else:
                sizer.Add(self.wids[label], (irow, 1), (1, 2), labstyle)
        pack(self, sizer)
Beispiel #3
0
    def __init__(self, parent, **kws):
        GenericScanPanel.__init__(self, parent, **kws)

        sizer = self.sizer
        ir = self.top_widgets('Linear Step Scan')

        sizer.Add(self.hline(), (ir, 0), (1, 8), wx.ALIGN_CENTER)
        ir += 1
        for ic, txt in enumerate((" Role", " Positioner", " Units",
                                  " Current", " Start",
                                  " Stop", " Step", " Npts")):
            s  = CEN
            if txt == " Npts":
                s = LEFT
            sizer.Add(wx.StaticText(self, -1, label=txt),
                      (ir, ic), (1, 1), s, 2)

        self.pos_settings = []
        fsize = (95, -1)
        for i in range(3):
            lab = ' Follow'
            pchoices = self.poslist[:]
            idefault = 0
            if i == 0:
                lab = ' Lead'
                pchoices = pchoices[1:]
                idefault = 1
            pos = add_choice(self, pchoices, size=(100, -1),
                             action=Closure(self.onPos, index=i))
            pos.SetSelection(idefault)
            role  = wx.StaticText(self, -1, label=lab)
            units = wx.StaticText(self, -1, label='', size=(40, -1),
                                  style=wx.ALIGN_CENTER)
            cur   = PVStaticText(self, pv=None, size=(100, -1),
                                 style=wx.ALIGN_CENTER)
            start, stop, step, npts = self.StartStopStepNpts(i, with_npts=(i==0))
            self.pos_settings.append((pos, units, cur, start, stop, step, npts))
            if i > 0:
                start.Disable()
                stop.Disable()
                step.Disable()
                npts.Disable()
            ir += 1
            sizer.Add(role,  (ir, 0), (1, 1), wx.ALL, 2)
            sizer.Add(pos,   (ir, 1), (1, 1), wx.ALL, 2)
            sizer.Add(units, (ir, 2), (1, 1), wx.ALL, 2)
            sizer.Add(cur,   (ir, 3), (1, 1), wx.ALL, 2)
            sizer.Add(start, (ir, 4), (1, 1), wx.ALL, 2)
            sizer.Add(stop,  (ir, 5), (1, 1), wx.ALL, 2)
            sizer.Add(step,  (ir, 6), (1, 1), wx.ALL, 2)
            sizer.Add(npts,  (ir, 7), (1, 1), wx.ALL, 2)

        self.finish_layout(ir+1, with_nscans=True)
        self.update_position_from_pv(0)
Beispiel #4
0
    def __init__(self, parent, prefix, pvdata, **kws):
        wx.Panel.__init__(self, parent, -1, **kws)
        self.sizer = sizer = wx.GridBagSizer(3, 3)
        self.wids = {}
        self.prefix = prefix
        irow = -1
        for label, pvname, use_prefix, dtype, rsuff, wsize, fontsize in pvdata:
            if use_prefix:
                pvname = prefix + pvname
            get_pv(pvname)
        poll(0.02)

        for label, pvname, use_prefix, dtype, rsuff, wsize, fontsize in pvdata:
            label = '  %s' % label
            if use_prefix:
                pvname = prefix + pvname
            ctrl = pv_control(dtype)
            opts = dict(pv=get_pv(pvname), size=(wsize, -1))

            self.wids[label] = ctrl(self, **opts)
            self.wids[label].SetFont(Font(fontsize))

            title = wx.StaticText(self,
                                  label=label,
                                  size=(8 * len(label), -1),
                                  style=labstyle)
            title.SetFont(Font(fontsize))
            irow += 1
            sizer.Add(title, (irow, 0), (1, 1), labstyle)

            if rsuff:
                rlabel = label + rsuff
                rname = pvname + rsuff
                self.wids[rlabel] = PVStaticText(self,
                                                 pv=get_pv(rname),
                                                 size=(wsize, -1))
                self.wids[rlabel].SetFont(Font(fontsize))
                sizer.Add(self.wids[label], (irow, 1), (1, 1), labstyle)
                sizer.Add(self.wids[rlabel], (irow, 2), (1, 1), labstyle)
            else:
                sizer.Add(self.wids[label], (irow, 1), (1, 2), labstyle)
        pack(self, sizer)
Beispiel #5
0
    def __init__(self, parent, **kws):
        GenericScanPanel.__init__(self, parent, **kws)
        sizer = self.sizer

        ir = self.top_widgets('Mesh Scan (Slow Map)')
        sizer.Add(self.hline(), (ir, 0), (1, 8), wx.ALIGN_CENTER)
        ir += 1

        for ic, lab in enumerate((" Loop", " Positioner", " Units",
                                  " Current", " Start", " Stop", " Step", " Npts")):
            s  = CEN
            if lab == " Npts":
                s = LEFT
            sizer.Add(SimpleText(self, lab), (ir, ic), (1, 1), s, 2)

        self.pos_settings = []
        pchoices = [p.name for p in self.scandb.get_positioners()]
        fsize = (95, -1)
        for i, label in enumerate((" Inner ", " Outer ")):
            lab = wx.StaticText(self, -1, label=label)
            pos = add_choice(self, pchoices, size=(100, -1),
                             action=Closure(self.onPos, index=i))
            pos.SetSelection(i)
            units = wx.StaticText(self, -1, size=(40, -1), label='')
            cur   = PVStaticText(self, pv=None, size=(100, -1),
                                 style=wx.ALIGN_CENTER)
            start, stop, step, npts = self.StartStopStepNpts(i,
                                                    initvals=(-1, 1, 0.1, 11))

            self.pos_settings.append((pos, units, cur, start, stop, step, npts))
            ir += 1
            sizer.Add(lab,   (ir, 0), (1, 1), wx.ALL, 2)
            sizer.Add(pos,   (ir, 1), (1, 1), wx.ALL, 2)
            sizer.Add(units, (ir, 2), (1, 1), wx.ALL, 2)
            sizer.Add(cur,   (ir, 3), (1, 1), wx.ALL, 2)
            sizer.Add(start, (ir, 4), (1, 1), wx.ALL, 2)
            sizer.Add(stop,  (ir, 5), (1, 1), wx.ALL, 2)
            sizer.Add(step,  (ir, 6), (1, 1), wx.ALL, 2)
            sizer.Add(npts,  (ir, 7), (1, 1), wx.ALL, 2)

        self.finish_layout(ir+1, with_nscans=True)
Beispiel #6
0
class XAFSScanPanel(GenericScanPanel):
    """xafs  scan """
    __name__ = 'XAFSScan'
    edges_list = ('K', 'L3', 'L2', 'L1', 'M5')
    units_list = ('eV', u'1/\u212B')

    def __init__(self, parent, **kws):
        kws['size'] = (750, 425)
        GenericScanPanel.__init__(self, parent, **kws)
        self.reg_settings = []
        self.ev_units = []

        sizer = self.sizer
        ir = self.top_widgets('XAFS Scan')
        sizer.Add(self.hline(),  (ir, 0), (1, 8), wx.ALIGN_CENTER)

        nregs = self.nregs_wid.GetValue()
        ir += 1
        sizer.Add(self.make_e0panel(),   (ir,   0), (1, 8), LEFT)
        ir += 1

        sizer.Add(self.hline(),    (ir, 0), (1, 8), wx.ALIGN_CENTER)
        ir += 1
        for ic, lab in enumerate((" Region", " Start", " Stop", " Step",
                                  " Npts", " Time (s)", " Units")):
            sizer.Add(SimpleText(self, lab),  (ir, ic), (1, 1), LEFT, 2)

        for i, reg in enumerate((('Pre-Edge', (-100, -10, 5,  19)),
                                 ('XANES',    (-10,   10, 0.25,  81)),
                                 ('XAFS1',    ( 10,  200, 2,  96)),
                                 ('XAFS2',    (200,  500, 3, 101)),
                                 ('XAFS3',    (500,  900, 4, 101)))):

            label, initvals = reg
            ir += 1
            reg   = wx.StaticText(self, -1, size=(100, -1), label=' %s' % label)
            start, stop, step, npts = self.StartStopStepNpts(i, initvals=initvals)
            dtime = FloatCtrl(self, size=(70, -1), value=1, minval=0,
                              precision=3,
                              action=Closure(self.onVal, index=i, label='dtime'))

            if i < 2:
                units = wx.StaticText(self, -1, size=(30, -1), label=self.units_list[0])
            else:
                units = add_choice(self, self.units_list,
                                   action=Closure(self.onVal, label='units', index=i))
            self.ev_units.append(True)

            self.reg_settings.append((start, stop, step, npts, dtime, units))
            if i >= nregs:
                start.Disable()
                stop.Disable()
                step.Disable()
                npts.Disable()
                dtime.Disable()
                units.Disable()
            sizer.Add(reg,   (ir, 0), (1, 1), wx.ALL, 5)
            sizer.Add(start, (ir, 1), (1, 1), wx.ALL, 2)
            sizer.Add(stop,  (ir, 2), (1, 1), wx.ALL, 2)
            sizer.Add(step,  (ir, 3), (1, 1), wx.ALL, 2)
            sizer.Add(npts,  (ir, 4), (1, 1), wx.ALL, 2)
            sizer.Add(dtime, (ir, 5), (1, 1), wx.ALL, 2)
            sizer.Add(units, (ir, 6), (1, 1), wx.ALL, 2)

        ir += 1
        sizer.Add(self.hline(), (ir, 0), (1, 7), wx.ALIGN_CENTER)

        self.kwtimechoice = add_choice(self, ('0', '1', '2', '3'), size=(70, -1),
                                     action=Closure(self.onVal, label='kwpow'))

        self.kwtimemax = FloatCtrl(self, precision=3, value=0, minval=0,
                                   size=(65, -1),
                                   action=Closure(self.onVal, label='kwtime'))

        ir += 1
        sizer.Add(SimpleText(self, "k-weight time of last region:"),  (ir, 1,), (1, 2), CEN, 3)
        sizer.Add(self.kwtimechoice, (ir, 3), (1, 1), LEFT, 2)
        sizer.Add(SimpleText(self, "Max Time:"),  (ir, 4,), (1, 1), CEN, 3)
        sizer.Add(self.kwtimemax, (ir, 5), (1, 1), LEFT, 2)

        self.finish_layout(ir+1, with_nscans=True)
        self.inittimer = wx.Timer(self)
        self.initcounter = 0
        self.Bind(wx.EVT_TIMER, self.display_energy, self.inittimer)
        self.inittimer.Start(100)

    def load_scandict(self, scan):
        """load scan for XAFS scan from scan dictionary
        as stored in db, or passed to stepscan"""

        self.kwtimemax.SetValue(scan['max_time'])
        self.kwtimechoice.SetSelection(scan['time_kw'])

        elem = scan.get('elem', None)
        if elem:
            self.elemchoice.SetStringSelection(elem)
        edge = scan.get('edge', None)
        if edge:
            self.edgechoice.SetStringSelection(edge)
        self.e0.SetValue(scan['e0'])
        self.absrel_value = {True:1, False:0}[scan['is_relative']]
        self.absrel.SetSelection(self.absrel_value)

        nregs = len(scan['regions'])
        self.nregs_wid.SetValue(nregs)
        for ireg, reg in enumerate(self.reg_settings):
            if ireg < nregs:
                for wid in reg: wid.Enable()
            else:
                for wid in reg: wid.Disable()

        dtimes = []
        for ireg, reg in enumerate(scan['regions']):
            start, stop, step, npts, dtime, units = self.reg_settings[ireg]
            # set units first!
            this_units = reg[4]
            if hasattr(units, 'SetStringSelection'):
                if this_units in self.units_list:
                    units.SetStringSelection(reg[4])
                else:
                    units.SetSelection(1)

                self.ev_units[ireg] = (reg[4].lower().startswith('ev'))

            start.SetValue(reg[0])
            stop.SetValue(reg[1])
            npts.SetValue(reg[2])
            dtime.SetValue(reg[3])
            dtimes.append(reg[3])
            if ireg == 0:
                self.dwelltime.SetValue(reg[3])

        self.kwtimemax.SetValue(scan['max_time'])
        self.kwtimechoice.SetSelection(scan['time_kw'])

        # is this a step or continuous scan?
        scanmode = scan.get('scanmode', None)
        dtimes_vary = (max(dtimes) - min(dtimes)) > 0.1
        qxafs_ttime = float(self.scandb.get_info('qxafs_time_threshold', default=0))
        if scanmode is None:
            step_xafs = (max(dtimes) > qxafs_ttime or dtimes_vary)
        else:
            step_xafs = 'step' in scanmode
        self.qxafs.SetSelection({True:0, False:1}[step_xafs])


    def setScanTime(self):
        "set Scan Time for XAFS Scan"
        etime = (float(self.scandb.get_info('pos_settle_time', default=0)) +
                 float(self.scandb.get_info('det_settle_time', default=0)))
        etime = etime + 0.25  # estimate time to move energy positioner
        dtime = 0.0
        kwt_max = float(self.kwtimemax.GetValue())
        kwt_pow = float(self.kwtimechoice.GetStringSelection())
        dtimes = []
        for reg in self.reg_settings:
            nx = float(reg[3].GetValue())
            dx = float(reg[4].GetValue())
            if reg[4].Enabled:
                dtimes.append((nx, dx))

        # qxafs: ignore settling time and k-weighting of time
        if self.qxafs.GetSelection() == 1:
            etime  = 0
            kwt_pow = 0

        if kwt_pow != 0:
            nx, dx = dtimes.pop()
            _vtime = (kwt_max-dx)*(1.0/(nx-1))**kwt_pow
            for i in range(int(nx)):
                dtime += (dx+etime)+ _vtime*(i**kwt_pow)

        for nx, dx in dtimes:
            dtime += nx*(dx + etime)
        self.scantime = dtime
        self.est_time.SetLabel(hms(dtime))

    def top_widgets(self, title, dwell_prec=3, dwell_value=1):
        "XAFS top widgets"
        self.absrel = add_choice(self, ('Absolute', 'Relative'),
                                 size=(100, -1), action=self.onAbsRel)
        self.absrel_value = 1
        self.absrel.SetSelection(1)

        self.qxafs = add_choice(self, ('StepScan', 'Continuous'),
                                size=(125, -1), action=self.onQXAFS)

        self.qxafs.SetSelection(0)
        qxafs_time_threshold = float(self.scandb.get_info('qxafs_time_threshold',
                                                          default=0))
        if dwell_value < qxafs_time_threshold:
            self.qxafs.SetSelection(1)

        self.dwelltime = FloatCtrl(self, precision=dwell_prec,
                                   value=dwell_value,
                                   act_on_losefocus=True,
                                   minval=0, size=(60, -1),
                                   action=Closure(self.onVal,
                                                  label='dwelltime'))

        self.est_time  = SimpleText(self, '  00:00:00  ')
        self.nregs_wid = FloatCtrl(self, precision=0, value=3,
                                   minval=1, maxval=5,
                                   size=(40, -1),  act_on_losefocus=True,
                                   action=Closure(self.onVal, label='nreg'))
        nregs = self.nregs_wid.GetValue()

        title  =  SimpleText(self, " %s" % title, style=LEFT,
                             font=self.Font13, colour='#880000')

        alabel = SimpleText(self, ' Mode: ', size=(60, -1))
        dlabel = SimpleText(self, ' Time/Pt (s):')
        tlabel = SimpleText(self, ' Estimated Scan Time:  ')
        rlabel = SimpleText(self, ' # Regions: ')

        sizer = self.sizer

        sizer.Add(title,          (0, 0), (1, 3), LEFT,  3)
        sizer.Add(tlabel,         (0, 4), (1, 2), RIGHT, 3)
        sizer.Add(self.est_time,  (0, 6), (1, 2), CEN,   3)
        sizer.Add(alabel,         (1, 0), (1, 1), LEFT,  3)
        sizer.Add(self.absrel,    (1, 1), (1, 1), LEFT,  3)
        sizer.Add(rlabel,         (1, 2), (1, 1), RIGHT, 3)
        sizer.Add(self.nregs_wid, (1, 3), (1, 1), LEFT,  3)
        sizer.Add(dlabel,         (1, 4), (1, 1), RIGHT, 3)
        sizer.Add(self.dwelltime, (1, 5), (1, 1), LEFT,  3)
        sizer.Add(self.qxafs,     (1, 6), (1, 1), LEFT,  3)


        # return next row for sizer
        return 2

    def make_e0panel(self):
        p = wx.Panel(self)
        s = wx.BoxSizer(wx.HORIZONTAL)
        self.e0 = FloatCtrl(p, precision=2, value=7112.0, minval=0, maxval=1e7,
                            size=(80, -1), act_on_losefocus=True,
                            action=Closure(self.onVal, label='e0'))

        self.elemchoice = add_choice(p, ELEM_LIST,
                                     action=self.onEdgeChoice, size=(70, -1))
        self.elemchoice.SetMaxSize((60, 25))
        self.elemchoice.SetStringSelection('Fe')

        self.edgechoice = add_choice(p, self.edges_list, size=(50, -1),
                                     action=self.onEdgeChoice)

        s.Add(SimpleText(p, " Edge Energy:", size=(120, -1),
                         style=wx.ALIGN_LEFT), 0, CEN, 2)
        s.Add(self.e0,   0, LEFT, 2)
        s.Add(SimpleText(p, "   Element:  "),  0, LEFT, 3)
        s.Add(self.elemchoice,                 0, LEFT, 3)
        s.Add(SimpleText(p, "    Edge:  "),    0, LEFT, 3)
        s.Add(self.edgechoice,                 0, LEFT, 3)
        s.Add(SimpleText(p, "   Current Energy:", size=(170, -1),
                         style=wx.ALIGN_LEFT), 0, CEN, 2)
        self.energy_pv = PVStaticText(p, pv=None, size=(100, -1),
                                      style=wx.ALIGN_CENTER)
        s.Add(self.energy_pv, 0, CEN, 2)
        pack(p, s)
        return p

    @EpicsFunction
    def display_energy(self, evt=None):
        enpos = str(self.scandb.get_info('xafs_energy', 'Energy'))
        pos = self.scandb.get_positioner(enpos)
        self.initcounter += 1
        # self.onEdgeChoice()
        if pos is None and self.initcounter > 10:
            self.inittimer.Stop()
        if pos is not None:
            en_pvname = pos.readpv
            if en_pvname in self.pvlist and self.energy_pv.pv is None:
                self.energy_pv.SetPV(self.pvlist[en_pvname])
                self.inittimer.Stop()

    def getUnits(self, index):
        un = self.reg_settings[index][5]
        if hasattr(un, 'GetStringSelection'):
            return un.GetStringSelection()
        else:
            return un.GetLabel()

    def onVal(self, evt=None, index=0, label=None, value=None, **kws):
        "XAFS onVal"
        if not self._initialized:
            return
        wids = self.reg_settings[index]
        units = self.getUnits(index)
        ev_units = self.ev_units[index]

        #enpos = str(self.scandb.get_info('xafs_energy'))
        #pos = self.scandb.get_positioner(enpos)
        #en_pvname = str(pos.readpv)
        #if en_pvname in self.pvlist and self.energy_pv.pv is None:
        #    self.energy_pv.SetPV(self.pvlist[en_pvname])
        e0_off = 0
        qxafs_time_threshold = float(self.scandb.get_info('qxafs_time_threshold',
                                                          default=0))
        if 0 == self.absrel.GetSelection(): # absolute
            e0_off = self.e0.GetValue()

        if label == 'dwelltime':
            for wid in self.reg_settings:
                wid[4].SetValue(value)

            if value < qxafs_time_threshold:
                self.qxafs.SetSelection(1)
        elif label == 'dtime':
            equal_times = True
            for ireg, reg in enumerate(self.reg_settings):
                if reg[4].Enabled:
                    rtime = float(reg[4].GetValue())
                    equal_times = equal_times and abs(value -rtime)  < 0.01
            if not equal_times:
                self.qxafs.SetSelection(0)
        elif label == 'nreg':
            nregs = value
            for ireg, reg in enumerate(self.reg_settings):
                for wid in reg:
                    wid.Enable(ireg < nregs)
            self.Refresh()
                        
        elif label == 'units':
            if units == self.units_list[0] and not ev_units: # was 1/A, convert to eV
                wids[0].SetValue(ktoe(wids[0].GetValue()) + e0_off)
                wids[1].SetValue(ktoe(wids[1].GetValue()) + e0_off)
                wids[2].SetValue(2.0)
            elif units != self.units_list[0] and ev_units: # was eV, convert to 1/A
                wids[0].SetValue(etok(wids[0].GetValue() - e0_off))
                wids[1].SetValue(etok(wids[1].GetValue() - e0_off))
                wids[2].SetValue(0.05)
            self.ev_units[index] = (units == self.units_list[0])
            self.setStepNpts(wids, label)

        if label in ('start', 'stop', 'step', 'npts'):
            self.setStepNpts(wids, label)
            if label == 'stop' and index < len(self.reg_settings)-1:
                nunits = self.getUnits(index+1)
                if nunits != units:
                    if units == 'eV':
                        value = etok(value - e0_off)
                    else:
                        value = ktoe(value) + e0_off
                self.reg_settings[index+1][0].SetValue(value, act=False)
                self.setStepNpts(self.reg_settings[index+1], label)
            elif label == 'start' and index > 0:
                nunits = self.getUnits(index-1)
                if nunits != units:
                    if units == 'eV':
                        value = etok(value - e0_off)
                    else:
                        value = ktoe(value) + e0_off
                self.reg_settings[index-1][1].SetValue(value, act=False)
                self.setStepNpts(self.reg_settings[index-1], label)
        self.setScanTime()

    def onQXAFS(self, evt=None):
        """continuous/step scans """
        # note: save qxafs selection, because setting the
        # per-region time may auto-set the qxafs selection to 'step'
        sel = self.qxafs.GetSelection()
        dtime = float(self.dwelltime.GetValue())
        equal_times = True
        for ireg, reg in enumerate(self.reg_settings):
            if reg[4].Enabled:
                reg[4].SetValue(dtime)

        self.qxafs.SetSelection(sel)
        self.setScanTime()

    def onAbsRel(self, evt=None):
        """xafs abs/rel"""
        offset = 0
        if 1 == self.absrel.GetSelection() and self.absrel_value == 0:
            # was absolute, now in relative
            offset = -self.e0.GetValue()
            self.absrel_value = 1
        elif 0 == self.absrel.GetSelection() and self.absrel_value == 1:
            # was relative, now absolute
            offset = self.e0.GetValue()
            self.absrel_value = 0
        for index, wids in enumerate(self.reg_settings):
            units = self.getUnits(index)
            if units == 'eV':
                for ix in range(2):
                    wids[ix].SetValue(wids[ix].GetValue() + offset, act=False)


    def onEdgeChoice(self, evt=None):
        edge = self.edgechoice.GetStringSelection()
        elem = self.elemchoice.GetStringSelection()
        # print(" On Edge Choice! ", elem, edge)
        if self.larch is not None:
            e0val = self.larch.run("xray_edge('%s', '%s')" % (elem, edge))
            self.e0.SetValue(e0val[0])
            self.set_scan_message("Warning: Check ROIs for '%s %sa' (use Ctrl-R)" % (elem, edge))

    def generate_scan_positions(self):
        "generate xafs scan"
        enpos = str(self.scandb.get_info('xafs_energy', 'Energy'))
        enpos = self.scandb.get_positioner(enpos)
        scantype = 'xafs'
        scanmode = 'step'
        if self.qxafs.GetSelection() == 1:
            scanmode = 'slew'
        s = {'type': scantype,
             'scanmode': scanmode,
             'e0': self.e0.GetValue(),
             'elem':  self.elemchoice.GetStringSelection(),
             'edge':  self.edgechoice.GetStringSelection(),
             'dwelltime':  float(self.dwelltime.GetValue()),
             'is_relative': 1==self.absrel.GetSelection(),
             'max_time': self.kwtimemax.GetValue(),
             'time_kw': int(self.kwtimechoice.GetSelection()),
             'energy_drive': enpos.drivepv,
             'energy_read': enpos.readpv,
             'extra_pvs': json.loads(enpos.extrapvs),
             'scantime': self.scantime,
             'regions': [],
             'filename': self.filename.GetValue(),
             'comments': self.user_comms.GetValue(),
             'nscans': 1
             }

        if self.nscans is not None:
            s['nscans'] = int(self.nscans.GetValue())

        for index, wids in enumerate(self.reg_settings):
            start, stop, step, npts, dtime, units =  wids
            if start.Enabled:
                p1 = start.GetValue()
                p2 = stop.GetValue()
                np = npts.GetValue()
                dt = dtime.GetValue()
                un = self.getUnits(index)
                s['regions'].append((p1, p2, np, dt, un))
        return s
Beispiel #7
0
    def __init__(self, parent, **kws):
        GenericScanPanel.__init__(self, parent, **kws)

        sizer = self.sizer

        ir = self.top_widgets('Slew Scan (Fast Map)', with_absrel=False,
                              dwell_value=0.050)

        self.dimchoice = add_choice(self, ('1', '2'), action = self.onDim)
        self.dimchoice.SetStringSelection('2')
        sizer.Add(SimpleText(self, ' Dimension:'), (ir-1, 6), (1, 1), CEN)
        sizer.Add(self.dimchoice,                  (ir-1, 7), (1, 2), CEN)

        sizer.Add(self.hline(), (ir, 0), (1, 8), wx.ALIGN_CENTER)
        ir += 1
        for ic, lab in enumerate((" Loop", " Positioner", " Units",
                                  " Current", " Start", " Stop", " Step", " Npts")):
            s  = CEN
            if lab == " Npts":
                s = LEFT
            # if lab == "Current": s = RIGHT
            sizer.Add(SimpleText(self, lab), (ir, ic), (1, 1), s, 2)

        self.pos_settings = []
        fsize = (95, -1)
        for i, label in enumerate((" Inner ", " Outer ")):
            lab = wx.StaticText(self, -1, label=label)
            pchoices = [p.name for p in self.scandb.get_positioners()]
            if i == 0:
                pchoices = [p.name for p in self.scandb.get_slewpositioners()]

            pos = add_choice(self, pchoices, size=(100, -1),
                             action=Closure(self.onPos, index=i))
            pos.SetSelection(i)
            units = wx.StaticText(self, -1, size=(40, -1), label='',
                                  style=wx.ALIGN_CENTER)
            cur   = PVStaticText(self, pv=None, size=(100, -1),
                                 style=wx.ALIGN_CENTER)
            start, stop, step, npts = self.StartStopStepNpts(i,
                                            initvals=(-0.25, 0.25, 0.002, 251))
            self.pos_settings.append((pos, units, cur, start, stop, step, npts))
            ir += 1
            sizer.Add(lab,   (ir, 0), (1, 1), wx.ALL, 2)
            sizer.Add(pos,   (ir, 1), (1, 1), wx.ALL, 2)
            sizer.Add(units, (ir, 2), (1, 1), wx.ALL, 2)
            sizer.Add(cur,   (ir, 3), (1, 1), wx.ALL, 2)
            sizer.Add(start, (ir, 4), (1, 1), wx.ALL, 2)
            sizer.Add(stop,  (ir, 5), (1, 1), wx.ALL, 2)
            sizer.Add(step,  (ir, 6), (1, 1), wx.ALL, 2)
            sizer.Add(npts,  (ir, 7), (1, 1), wx.ALL, 2)

        ir += 1

        zfm = self.scandb.get_info('zero_finemotors_beforemap',
                                   as_bool=True, default=0)
        self.zfmchoice = check(self, default=zfm,
                               label='Zero Fine Motors before Map?',
                               action=self.onZeroFineMotors)

        sizer.Add(self.zfmchoice, (ir, 1), (1, 3), wx.ALL, 2)

        ir += 1
        sizer.Add(SimpleText(self, 'Select from Common Square Maps:'),
                  (ir, 0), (1, 5), wx.ALL, 2)

        jrow = 0
        jcol = 0
        lsizer = wx.GridBagSizer(2, 6)
        lpanel = wx.Panel(self)

        for mapname in (u' 50 x 50 \u03bcm', u'100 x 100 \u03bcm',
                        u'200 x 200 \u03bcm', u'300 x 300 \u03bcm',
                        u'400 x 400 \u03bcm', u'500 x 500 \u03bcm',
                        u'600 x 600 \u03bcm', u'800 x 800 \u03bcm',
                        '1 x 1 mm', '2 x 2 mm'):
            link = HyperText(lpanel, mapname,
                             action=Closure(self.onDefinedMap,
                                            label=mapname))
            lsizer.Add(link, (jrow, jcol), (1, 1), wx.ALL, 7)
            jcol += 1
            if jcol > 4:
                jrow += 1
                jcol = 0

        ir += 1
        pack(lpanel, lsizer)
        sizer.Add(lpanel, (ir, 1), (2, 7), wx.ALL, 2)
        ir += 2

        self.finish_layout(ir+1, with_nscans=False)