def zoomlvl_calibrate(self):
     """Self calibration for navitar zoom level"""
     from time import sleep
     low_percent = 1
     high_percent = 65
     print 'Finding lower limit...'
     self.zoom.move(low_percent)
     while self.zoom.ismoving():
         pass
     (status, msg) = self.zoom.check_limit_switches()
     while status is not 'low':
         self.zoom.mvr(-1)
         while self.zoom.ismoving():
             pass
         (status, msg) = self.zoom.check_limit_switches()
     max_out = pypsepics.get(self.zoom.pvname + '.RMP')
     pypsepics.put(self.__zoomPV + ':MAX_OUT', max_out)
     pypsepics.put(self.zoom.pvname + ':SET_ZERO.PROC', 1)
     print '...Done.'
     sleep(2)
     print 'Finding upper limit...'
     self.zoom.move(high_percent)
     sleep(1)
     while self.zoom.ismoving():
         pass
     (status, msg) = self.zoom.check_limit_switches()
     while status is not 'high':
         self.zoom.mvr(1)
         while self.zoom.ismoving():
             pass
         (status, msg) = self.zoom.check_limit_switches()
     max_in = pypsepics.get(self.zoom.pvname + '.RMP')
     pypsepics.put(self.__zoomPV + ':MAX_IN', max_in)
     print '...Done.'
     print 'Finished calibrating'
Beispiel #2
0
 def dial_delay(self, value=None):
     '''Reads or writes directly to the angle shift pv. This doesnt use the offsett.
    usage: dial_delay(): read pack the angle shift pv
           dial_delay(value): writes to the angle shift variable, and toggles gain to get new value fast.
 '''
     if (value is None):
         return pypsepics.get(self.__pv_angleshift_rbv) * 1e-15
     else:
         #m = 0; M=14.7e-9
         m = 0
         M = 19.2e-9
         if ((value < m) or (value > M)):
             logprint(
                 "Phase shifter has a range (%.2e,%.2e), asked for %.3e, aborting"
                 % (m, M, value),
                 print_screen=True)
             return
         self.__desired_value = value
         if abs(pypsepics.get(self.__pv_angleshift_rbv) * 1e-15 -
                value) > 5e-12:
             self.lowgain()
             pypsepics.put(self.__pv_angleshift, int(value * 1e15))
             self.wait()
             self.higain()
         else:
             pypsepics.put(self.__pv_angleshift, int(value * 1e15))
         return
Beispiel #3
0
 def speed(self, value=None):
     if (value is not None):
         pypsepics.put(self.speed_pv, value)
     if (self.speed_rbv is None):
         s = pypsepics.get(self.speed_pv)
     else:
         s = pypsepics.get(self.speed_rbv)
     return s
Beispiel #4
0
    def return_position(self):
        ''' returns the target stage to the last saved position.

        the target position is save with .save()
    '''
        print 'moves the xyzstage ' + self._name + 'to the last saved position'
        self.x.mv(pypsepics.get(self._savepvx))
        self.y.mv(pypsepics.get(self._savepvy))
        self.z.mv(pypsepics.get(self._savepvz))
Beispiel #5
0
 def exposuretime(self, expval=None):
     """Set the exposure time"""
     period = pypsepics.get(self._pvperiod + "_RBV")
     if expval == None:
         return pypsepics.get(self._pvtime + "_RBV")
     elif 0 < expval <= period:
         pypsepics.put(self._pvtime, expval)
     else:
         print('exposure time out of range (0,%s)' % period)
Beispiel #6
0
    def home(self):
        print "Start homing procedure now for slit %s:" % self.__name
        print "North blade : ", self.n.pvname
        print "South blade : ", self.s.pvname
        print "Top blade : ", self.u.pvname
        print "Bottom blade : ", self.d.pvname
        pypsepics.put(self.n.pvname + '.HOMR', 1)  # move to low limit switch
        pypsepics.put(self.s.pvname + '.HOMF', 1)  # move to high limit switch
        pypsepics.put(self.u.pvname + '.HOMR', 1)  # move to low limit switch
        pypsepics.put(self.d.pvname + '.HOMF', 1)  # move to high limit switch

        for i in range(3):
            status_n = 0
            status_s = 0
            status_u = 0
            status_d = 0
            while (True):
                time.sleep(3)
                status_n = pypsepics.get(self.n.pvname + '.LLS')
                time.sleep(3)
                status_s = pypsepics.get(self.s.pvname + '.HLS')
                time.sleep(3)
                status_u = pypsepics.get(self.u.pvname + '.LLS')
                time.sleep(3)
                status_d = pypsepics.get(self.d.pvname + '.HLS')
                if status_n == 1 and status_s == 1 and status_u == 1 and status_d == 1:
                    break  # everyone is on the limit siwtch right now

        print "everyone is on the limit siwtch right now"
        pypsepics.put(self.n.pvname + ':ZERO_P.PROC', 1)  # set dial to zero
        pypsepics.put(self.s.pvname + ':ZERO_P.PROC', 1)  # set dial to zero
        pypsepics.put(self.u.pvname + ':ZERO_P.PROC', 1)  # set dial to zero
        pypsepics.put(self.d.pvname + ':ZERO_P.PROC', 1)  # set dial to zero

        time.sleep(2)

        # set the pre-defined offset for s1, s2 and s3
        if self.__name == 's1':
            pypsepics.put(self.n.pvname + '.OFF', -17.02)
            pypsepics.put(self.s.pvname + '.OFF', 15.52)
            pypsepics.put(self.u.pvname + '.OFF', -15.82)
            pypsepics.put(self.d.pvname + '.OFF', 16.334)
        elif self.__name == 's2':
            pypsepics.put(self.n.pvname + '.OFF', -17.04)
            pypsepics.put(self.s.pvname + '.OFF', 15.204)
            pypsepics.put(self.u.pvname + '.OFF', -16.75)
            pypsepics.put(self.d.pvname + '.OFF', 15.64)
        elif self.__name == 's3':
            pypsepics.put(self.n.pvname + '.OFF', -16.25)
            pypsepics.put(self.s.pvname + '.OFF', 14.4)
            pypsepics.put(self.u.pvname + '.OFF', -15.87)
            pypsepics.put(self.d.pvname + '.OFF', 16.692)
        else:
            print "Wrong slit name!"

        print "Done homing slit: %s" % self.__name
Beispiel #7
0
 def status(self):
     volt = pypsepics.get(self.pv_Volt)
     onoff = pypsepics.get(self.pv_OnOff)
     if onoff == 0:
         sstatus = estr("On", color='green', type='bold')
     elif onoff == 1:
         sstatus = estr("Off", color='red', type='bold')
     else:
         sstatus = estr("Not Known", color='white', type='normal')
     str1 = "%s:" % self.name
     str2 = " %s\n" % sstatus
     str3 = "Level:"
     str4 = " %d%%" % (self.level() * 100)
     str = str1.rjust(10) + str2.ljust(5) + str3.rjust(10) + str4.ljust(5)
     return str
Beispiel #8
0
 def isopen(self):
     """ return true if the valve is open """
     openswitch = pypsepics.get(self.__opn_di)
     if (openswitch == 1):
         return True
     else:
         return False
Beispiel #9
0
 def isclosed(self):
     """ returns True if valve is openclosed """
     openswitch = pypsepics.get(self.__opn_di)
     if (openswitch == 0):
         return True
     else:
         return False
 def beamrate(self):
     while True:
         rate = pypsepics.get(self.__beamrate)
         if rate == 0.5 or int(rate) == rate:
             break
         sleep(0.1)
     return float(rate)
Beispiel #11
0
 def switch(self):
     """ switches illuminator """
     onoff = pypsepics.get(self.pv_OnOff)
     if onoff == 1:
         pypsepics.put(self.pv_OnOff, 1)
     elif onoff == 0:
         pypsepics.put(self.pv_OnOff, 0)
Beispiel #12
0
def Fii(ID,E=None):
  if E==None:
    E=pypsepics.get("SIOC:SYS0:ML00:AO627")/1000
  E=eV(E)/1000
  z=elementZ[ID]
  f=xraylib.Fii(z,E)  
  return f
Beispiel #13
0
def CS_KN(E=None):
  if E==None:
    E=pypsepics.get("SIOC:SYS0:ML00:AO627")/1000
  E=eV(E)/1000
  z=elementZ[ID]
  CS=xraylib.CS_KN(E)  
  return CS
Beispiel #14
0
    def updatingplot(self,
                     sleeptime=.1,
                     figurename="Displacementsensor",
                     noofpoints=50,
                     showpos=True):
        update = True
        pl.ion()
        plt = Plot.Plot2D(10, windowtitle='Displacement Sensor')
        plt.set_xlabel('Time')
        plt.set_ylabel('Position / mm')

        val = []
        tt = []
        pos = []

        quit = KeyPress.KeyPress(esc_key="q")
        while not quit.isq():
            tval = pypsepics.get(self.pv)
            val.append(tval)
            pos.append(self.poslims[0] + tval *
                       (np.diff(self.voltlims) / np.diff(self.poslims)))
            tt.append(datetime.datetime.now())
            tt = tt[-100:]
            pos = pos[-100:]
            val = val[-100:]
            if showpos:
                plt.setdata(tt, pos)
            else:
                pl.gca().lines[-1].set_ydata(val[-noofpoints:])
                pl.gca().lines[-1].set_xdata(tt[-noofpoints:])
            sleep(sleeptime)
            pl.draw()
Beispiel #15
0
 def isclosed(self):
     """ return True if the valve is closed """
     closeswitch = pypsepics.get(self.__cls_di)
     if (closeswitch == 1):
         return True
     else:
         return False
Beispiel #16
0
 def __getlight(self):
     import pyca
     try:
         l = pypsepics.get(self.__led)
         return l
     except pyca.pyexc:
         return "Not connected"
 def status(self, verbose=True):
     ret = pypsepics.get(self.__pv_playstatus)
     ret = self.__status[ret]
     if (verbose):
         print "Mode: %s" % self.getmode()
         print "Current status: %s" % ret
     else:
         return ret
Beispiel #18
0
 def period(self, periodval=None):
     """Set the collection preriod"""
     if periodval == None:
         return pypsepics.get(self._pvperiod + "_RBV")
     elif 0 < periodval <= 10:
         pypsepics.put(self._pvperiod, periodval)
     else:
         print('period out of range (0,10)')
Beispiel #19
0
    def __get_offset(self):
        '''returns the value of the offset.

           The offset is the motor value on the delay stage that will result in 
           time delay calculation of 0 (i.e. put the delay motor at the offset value and 
           the delay() command will return 0)
        '''
        return pypsepics.get(self._offset_pv)
Beispiel #20
0
 def gain(self, gainval=None):
     '''set the gain of camera, or reads back gain if no value is passed'''
     if gainval == None:
         return pypsepics.get(self._pvgain + "_RBV")
     elif 0 <= gainval <= 32:
         pypsepics.put(self._pvgain, round(gainval))
     else:
         print('gain out of range (0,32)')
Beispiel #21
0
 def move(self,value):
   if (self.pvoff is None):
     offset=0
   else:
     offset=pypsepics.get(self.pvoff)
   dial = (value-offset)*self.direction
   self.move_dial(dial)
   return value
Beispiel #22
0
 def wm(self):
     v = pypsepics.get(self.pv_status)
     if (v == 2):
         return "OUT"
     elif (v == 1):
         return "IN"
     else:
         return "?"
Beispiel #23
0
def load_MMS_pars(cvsfile,verbose=False):
  f=open(cvsfile)
  lines = f.readlines()
  for i in range(len(lines)): lines[i]=lines[i].rstrip("\n")
  fields = lines[1];
  lines = lines[2:];
  fields = fields.split(",")[1:]
  for l in lines:
    ll=l.split(",")
    pvbase=ll[0]
    if pvbase.startswith("#"): continue
    values=ll[1:]
    for i in range(len(fields)):
      f   = fields[i]
      pvw = pvbase + f
      pvr = pvw
      if (f == ":SET_RC"): pvr = pvbase + ":RC"
      if (f == ":SET_EE"): pvr = pvbase + ":EE"
      if f.startswith("#"): continue
      if (values[i] != "?"):
        try:
          vv=float(values[i])
        except:
          vv=values[i]
        if (f==":SET_RC"):  vv=str(values[i]); # for some reason the run current must be a string !
        if (f==":SET_EE"):  vv=str(values[i]); # for some reason the use encoder must be a string !
        if (f==".DIR"):  vv=int(values[i]);
        if (f==".SREV"): vv=int(values[i]);
        try:
          cv = pypsepics.get(pvr)
          if (verbose):
            print "current value ", cv
            print "setting  ",pvw," to ",values[i],
          if (f==".S"): pypsepics.put(pvbase+".SMAX",vv)
          pypsepics.put(pvw,vv)
          if (verbose): print " done"
        except pyca.pyexc:
          print "FAILED TO set ",pvw," to ",values[i]
#        time.sleep(0.1)
        try:
          rv = pypsepics.get(pvr)
          if (verbose): print "readback ",pvr, "    " ,rv
        except pyca.pyexc:
          print "FAILED TO READBACK ",pvr
        if (rv != cv):
          print "!!!NOTE!!! The pv %s has changed from %s to %s" % (pvw,cv,rv)
Beispiel #24
0
def CS_Total(ID,E=None):
  if E==None:
    E=pypsepics.get("SIOC:SYS0:ML00:AO627")/1000
  E=eV(E)/1000
  z=elementZ[ID]
  CS=xraylib.CS_Total(z,E)  
  CS=CS*AtomicMass[ID]/c['NA']/u['cm']**2
  return CS
Beispiel #25
0
 def status(self, verbose=True):
     #    pvname = "IOC:IN20:EV01:ECS_PLSTAT_3"
     ret = pypsepics.get(self.__pv_playstatus)
     ret = self.__status[ret]
     if (verbose):
         print "Mode: %s" % self.getmode()
         print "Current status: %s" % ret
     else:
         return ret
Beispiel #26
0
def index(ID,E=None):
  if E==None:
    E=pypsepics.get("SIOC:SYS0:ML00:AO627")/1000
  E=eV(E)/1000
  d=Density[ID]
  n_real=xraylib.Refractive_Index_Re(ID,E,d)  
  n_imag=xraylib.Refractive_Index_Im(ID,E,d)  
  n=complex(n_real,n_imag)
  return n
Beispiel #27
0
 def wait_for_shot(self, verbose=False):
     # to make sure the PV is written (otherwise a sequence get_shot(); wait_for_shot()
     # may fail
     time.sleep(0.03)
     t0 = time.time()
     while (pypsepics.get("PATT:SYS0:1:MPSBURSTCTRL") != 0):
         time.sleep(0.02)
     if (verbose):
         print 'waited %.3f secs for shots' % (time.time() - t0)
Beispiel #28
0
 def getE(self):
     wp = pypsepics.get(self.wp_pv)
     E0 = self.get_E0()
     leakage = self.get_leakage()
     if self.shg:
         return
     else:
         E = (E0 - leakage) * (sind(2 * wp))**2 + leakage
         return E
 def status(self):
     v = pypsepics.get(self.pvname)
     if (v == 0):
         ret = "OUT"
     elif ((v == 4) | (v == 1)):
         ret = "IN"
     else:
         ret = "Inconsistent"
     return ret
Beispiel #30
0
 def wm(self):
   if (self.pvoff is None):
     offset=0
   else:
     offset=pypsepics.get(self.pvoff)
   user = self.direction*self.wm_dial()+offset
   if (self.pvpos is not None):
     pypsepics.put(self.pvpos,user)
   return user