def motor(name):
    """name: EPICS PV or Python motor defined in 'id14.py'"""
    if not ":" in name:
        exec("from id14 import *")
        try:
            return eval(name)
        except:
            pass
    from EPICS_motor import motor
    return motor(name)
 def motor(self, name):
     if not name in self.cache: self.cache[name] = motor(name)
     return self.cache[name]
template_APS = "//mx340hs/data/anfinrud_1810/Archive/Laue_pictures/"\
               "%r_%r_%r.tiff"

template_APS_MAC_folder = "//volumes/data/anfinrud_1810/Archive/Laue_pictures/"
template_APS_MAC = template_APS_MAC_folder + "%r_%r_%r.tiff"


template_NIH= "//femto/C/All Projects/Crystallization/2018/test/"\
    "%r_%r_%00d.tiff"
x_scale = 1  #float(DB.db("MicroscopeCamera.x_scale")) #FIXIT: double check xyz grid
y_scale = -1  #float( DB.db("MicroscopeCamera.y_scale")) #FIXIT: double check xyz grid
z_scale = -1  #float( DB.db("MicroscopeCamera.z_scale")) #FIXIT: double check xyz grid

from EPICS_motor import motor
motorX = motor("NIH:SAMPLEX")
motorY = motor("NIH:SAMPLEY")
motorZ = motor("NIH:SAMPLEZ")


def saved_position():

    motorX.value, motorY.value, motorZ.value = (0.21, 0.05, 0.8)


class MotorD(object):
    def __init__(self):
        pass

    def get_value(self):
        return round((motorX.value - 0.261) * sin(pi / 3.0), 4)
Пример #4
0
from EPICS_motor import motor
SampleX = motor("14IDB:SAMPLEX")
SampleY = motor("14IDB:SAMPLEY")
SampleZ = motor("14IDB:SAMPLEZ")
SamplePhi = motor("14IDB:SAMPLEPHI")

from time import sleep

while True:
    SampleX.value, SampleY.value, SampleZ.value = -1, -1, -1
    while (SampleX.moving or SampleY.moving or SampleZ.moving):
        sleep(0.01)
    sleep(1)
    SampleX.value, SampleY.value, SampleZ.value = 1, 1, 1
    while (SampleX.moving or SampleY.moving or SampleZ.moving):
        sleep(0.01)
    sleep(1)
    moving = property(lambda self: self.motor.moving,set_moving,
        doc="Is filter currently moving?")

    def __repr__(self):
        return "variable_attenuator(%r,OD_range=[%g,%g],motor_range=[%g,%g])" \
            % (self.motor,self.OD_range[0],self.OD_range[1],
            self.motor_range[0],self.motor_range[1])

    
if __name__ == "__main__": # for testing - remove when done

    from EPICS_motor import motor # EPICS-controlled motors
    
    # Laser beam attenuator wheel in 14ID-B X-ray hutch
    VNFilter = motor("14IDB:m32",name="VNFilter")
    VNFilter.readback_slop = 0.1 # [deg] otherwise Thorlabs motor gets hung in "Moving" state
    VNFilter.min_step = 0.050 # [deg] otherwise Thorlabs motor gets hung in "Moving" state"
    # This filter is mounted such that when the motor is homed (at 0) the
    # attuation is minimal (OD 0.04) and increasing to 2.7 when the motor
    # moves in positive direction.
    # Based on measurements by Hyun Sun Cho and Friedrich Schotte, made 7 Dec 2009
    trans = variable_attenuator(VNFilter,motor_range=[5,285],OD_range=[0,2.66])
    trans.motor_min=-5
    trans.OD_min=0
    trans.motor_max=300
    trans.OD_max=2.66

    # 14-ID Laser Lab
    VNFilter1 = motor("14IDLL:m8",name="VNFilter1")
    VNFilter1.readback_slop = 0.030 # otherwise Thorlabs motor gets hung in "Moving" state
class XrayAttenuator(object):
    motors = [motor("XPP:SB2:MMS:%d" % i) for i in range(26, 16, -1)]
    for motor in motors:
        motor.readback_slop = 0.075
    thicknesses = [0.020 * 2**i for i in range(0, len(motors))]
    outpos = [0] * len(motors)
    inpos = [20] * len(motors)
    inpos[3] = 19  # Filter #4 is damaged at position 20 mm.

    photon_energy_PV = PV("SIOC:SYS0:ML00:AO627")  # in eV
    """Variable Si X-ray attenuator of XPP hutch"""
    def get_transmission(self):
        from numpy import exp
        x = self.pathlength
        E = self.photon_energy
        return exp(-float(Si_mu(E)) * x)

    def set_transmission(self, T):
        from numpy import log
        E = self.photon_energy
        x = -log(T) / float(Si_mu(E))
        self.pathlength = x

    transmission = property(get_transmission, set_transmission)
    value = transmission

    def get_photon_energy(self):
        "Photon energy in eV"
        return self.photon_energy_PV.value

    photon_energy = property(get_photon_energy)

    def get_pathlength(self):
        "Thickness of silicon the X-ray beam passes through"
        pathlength = 0
        inserted = self.inserted
        for i in range(0, len(self.motors)):
            if inserted[i]: pathlength += self.thicknesses[i]
        return pathlength

    def set_pathlength(self, pathlength):
        from numpy import rint
        pathlength = min(pathlength, sum(self.thicknesses))
        steps = int(rint(pathlength / min(self.thicknesses)))
        insert = [(steps & 2**i != 0) for i in range(0, len(self.motors))]
        self.inserted = insert

    pathlength = property(get_pathlength, set_pathlength)

    def get_inserted(self):
        "True of False for each abosrber, list of 10"
        positions = self.positions
        return [
            abs(positions[i] - self.inpos[i]) <
            abs(positions[i] - self.outpos[i])
            for i in range(0, len(self.motors))
        ]

    def set_inserted(self, insert):
        "Inserted: list of booleans, one for each absorber"
        positions = [
            self.inpos[i] if insert[i] else self.outpos[i]
            for i in range(0, len(self.motors))
        ]
        self.positions = positions

    inserted = property(get_inserted, set_inserted)

    def get_positions(self):
        "Position for each absorber, list of 10"
        return [self.motors[i].value for i in range(0, len(self.motors))]

    def set_positions(self, positions):
        "Inserted: list of positions, one for each absorber"
        for i in range(0, len(self.motors)):
            self.motors[i].value = positions[i]

    positions = property(get_positions, set_positions)

    def get_moving(self):
        """Is any of the absorbers moving?"""
        return any(motor.moving for motor in self.motors)

    def set_moving(self, moving):
        """If moving = False, stop all motors."""
        for motor in self.motors:
            motor.moving = moving

    moving = property(get_moving, set_moving)

    def stop(self):
        """Stop all motors."""
        for motor in self.motors:
            motor.stop()
Пример #7
0
        dtheta = theta - self.theta(x1, x2)
        dx = dtheta * self.distance
        x1, x2 = x1 + dx / 2, x2 - dx / 2
        return x1, x2

    def user_from_dial(self, value):
        return value * self.sign + self.offset

    def dial_from_user(self, value):
        return (value - self.offset) / self.sign


if __name__ == "__main__":
    from EPICS_motor import motor
    print('motor("14IDC:m12").value = %.6f # mir2X1' %
          motor("14IDC:m12").value)
    print('motor("14IDC:m13").value = %.6f # mir2X2' %
          motor("14IDC:m13").value)
    print('motor("14IDC:mir2Th").value = %.6f' % motor("14IDC:mir2Th").value)
    mir2X1 = motor("14IDC:m12", name="mir2X1")  # H mirror X1-upstream
    mir2X2 = motor("14IDC:m13", name="mir2X2")  # H mirror X1-downstream
    print("mir2X1.__prefix__ = %r" % mir2X1.__prefix__)
    print("mir2X2.__prefix__ = %r" % mir2X2.__prefix__)
    print("mir2X1.value = %.6f" % mir2X1.value)
    print("mir2X2.value = %.6f" % mir2X2.value)
    mir2Th = tilt(mir2X1, mir2X2, distance=1.045, name="mir2Th")
    print("mir2Th.offset = %r" % mir2Th.offset)
    print("mir2Th.value = %.6f" % mir2Th.value)
    stepsize = 0.000416 * 2 / 1.045
    print("mir2Th.value += %.6f" % (stepsize * 3))
    self = mir2Th