Example #1
0
def addBank(instrument, banknum, local_name, azimuth, elevation, rotation, distance):
    """Add a bank (detector) with given angles.

    Parameters:
        banknum: Number of the detector.
        local_name: local_name of the detector (a string)
        azimuth: azimuthal angle in radians. 0 = pointing downstream
        elevation: elevation angle in radians. Positive = going up (towards +Y)
        rotation: rotation of the detector face, in rad, around the positive +Z axis.
            For topaz this is -45 degrees.
        distance: in cm, from sample to center of detector face.
    """
    CM = "centimetre"
    RAD = "radian"

    bank = Component( "bank%d" % banknum, "NXdetector")
    bank.setRecipe("topaz_detector")

    # Now we need to convert from our azimuth/elevation coordinates
    #   to azimuth/polar.
    
    #Assuming azimuth of zero points to z positive = same direction as incident radiation.
    r2 = cos(elevation)
    z=cos(azimuth) * r2
    x=sin(azimuth) * r2
    #Assuming polar angle is 0 when horizontal, positive to y positive
    y=sin(elevation)
    #So (x,y,z) is the direction; length is 1

    #We calculate the polar (theta) and azimuth (phi) angles
    theta = acos(z)
    phi = atan2(y,x)

    # Distance between sample and center of detector
    bank.addParameter("cenDistance", distance, units=CM)

    # cenPolar is "The angle of the rectangle center from the positive z-axis."
    # So this corresponds to our "theta" angle.
    bank.addParameter("cenPolar", theta, units=RAD)
    #Azimuthal = the angle of the rectangle center from the positive x-axis constrained in the xy-plane.
    # so this corresponds to the "phi" angle.
    bank.addParameter("cenAzimuthal", phi, units=RAD)
    
    #For later
    phi_center = phi
    theta_center = theta
    
    #Now we set the detector orientation. If we set any of the detector orientation
    # values, this overrides the orientation that would come from cenPolar and cenAzimuthal

    #We will use the getEuler() method to find the phi, chi, omega angles.

    #But first we need the u,v vectors describing the face of the detector.
    #u = the horizontal vector; v = the vertical vector
    u = np.array([1.,0.,0.]).reshape(3,1)
    v = np.array([0.,1.,0.]).reshape(3,1)

    #Ok, first rotate the detector around its center by angle.
    #Since this is rotation around z axis, it is a chi angle
    rot = rotation_matrix(0, rotation, 0)

    u_rotated = Vector(np.dot(rot, u))
    v_rotated = Vector(np.dot(rot, v))

    #Now do the elevation rotation, by rotating around the x axis.
    rot = np.dot(x_rotation_matrix(-elevation), rot)

    #Finally add an azimuthal rotation (around the y axis, or phi)
    rot = np.dot(rotation_matrix(azimuth, 0, 0), rot)

    #Now we rotate the base vectors, save them as vectors
    u_rotated = Vector(np.dot(rot, u))
    v_rotated = Vector(np.dot(rot, v))

    #Use getEuler to get the equivalent phi,chi,omega (in that order) rotation angles.
    (phi, chi, omega) = getEuler(u_rotated, v_rotated) #getEuler input units defaults to radians

    # Now we save these 3 orientation angles
    bank.addParameter("phi", phi, units=RAD)
    bank.addParameter("chi", chi, units=RAD)
    bank.addParameter("omega", omega, units=RAD)

    #Congrats! We have now tricked the program into making the correct detector orientation
    # (we hope!)
    

    # Now we set a local_name for the bank	
    bank.setAnnotation("<local_name>%s</local_name>" % local_name)
    
    instrument.addComponent(bank)


    #! Now mantid
    idstart = banknum * 65536

    #  Have to flip U because it is the opposite of what we expect
    u_rotated = Vector(np.dot(rot, u)*-1.0)
    (phi, chi, omega) = getEuler(u_rotated, v_rotated) #getEuler input units defaults to radians
    #print "<!--- Rotated we have u ", u_rotated, ", v", v_rotated, "giving angles ", (phi, chi, omega), " ... for bank", banknum, " --->"
    print makeMantidGeometryCode(local_name, idstart, distance, theta_center, phi_center, phi, chi, omega)
    writeToFile(makeMantidGeometryCode(local_name, idstart, distance, theta_center, phi_center, phi, chi, omega), 'a')
Example #2
0
#!/usr/bin/env python

from sns_geometry import Geometry, Component, Maths, Recipe, Vector, \
     extractValueFromFile, generateGeom, getEuler

from math import cos, sin, acos, atan2
from datetime import datetime, date
import numpy as np

geometry = generateGeom("TOPAZ")
entry = geometry.getEntry()
instrument = entry.getInstrument()

# Monitors
monitor1 = Component("monitor1", "NXmonitor")
monitor1.setComment("MONITORS")
monitor1.setHelper("ParameterCopy")
monitor1.addVariable("distance", "mon1dis")
entry.addMonitor(monitor1)
monitor2 = Component("monitor2", "NXmonitor")
monitor2.setHelper("ParameterCopy")
monitor2.addVariable("distance", "mon2dis")
entry.addMonitor(monitor2)

# Sample
sample=Component("sample", "NXsample")
sample.setComment(" SAMPLE ")
sample.setHelper("Goiniometer")
#real_phi, etc. are the real sample orientations (sanitized names, taken from phi,chi,omega MOTOR values)
#phi, chi, etc. are the sample orientations
sample.addVariable("phi", "real_phi")
Example #3
0
def addBank(instrument, banknum, local_name, azimuth, elevation, rotation,
            distance):
    """Add a bank (detector) with given angles.

    Parameters:
        banknum: Number of the detector.
        local_name: local_name of the detector (a string)
        azimuth: azimuthal angle in radians. 0 = pointing downstream
        elevation: elevation angle in radians. Positive = going up (towards +Y)
        rotation: rotation of the detector face, in rad, around the positive +Z axis.
            For topaz this is -45 degrees.
        distance: in cm, from sample to center of detector face.
    """
    CM = "centimetre"
    RAD = "radian"

    bank = Component("bank%d" % banknum, "NXdetector")
    bank.setRecipe("topaz_detector")

    # Now we need to convert from our azimuth/elevation coordinates
    #   to azimuth/polar.

    #Assuming azimuth of zero points to z positive = same direction as incident radiation.
    r2 = cos(elevation)
    z = cos(azimuth) * r2
    x = sin(azimuth) * r2
    #Assuming polar angle is 0 when horizontal, positive to y positive
    y = sin(elevation)
    #So (x,y,z) is the direction; length is 1

    #We calculate the polar (theta) and azimuth (phi) angles
    theta = acos(z)
    phi = atan2(y, x)

    # Distance between sample and center of detector
    bank.addParameter("cenDistance", distance, units=CM)

    # cenPolar is "The angle of the rectangle center from the positive z-axis."
    # So this corresponds to our "theta" angle.
    bank.addParameter("cenPolar", theta, units=RAD)
    #Azimuthal = the angle of the rectangle center from the positive x-axis constrained in the xy-plane.
    # so this corresponds to the "phi" angle.
    bank.addParameter("cenAzimuthal", phi, units=RAD)

    #For later
    phi_center = phi
    theta_center = theta

    #Now we set the detector orientation. If we set any of the detector orientation
    # values, this overrides the orientation that would come from cenPolar and cenAzimuthal

    #We will use the getEuler() method to find the phi, chi, omega angles.

    #But first we need the u,v vectors describing the face of the detector.
    #u = the horizontal vector; v = the vertical vector
    u = np.array([1., 0., 0.]).reshape(3, 1)
    v = np.array([0., 1., 0.]).reshape(3, 1)

    #Ok, first rotate the detector around its center by angle.
    #Since this is rotation around z axis, it is a chi angle
    rot = rotation_matrix(0, rotation, 0)

    u_rotated = Vector(np.dot(rot, u))
    v_rotated = Vector(np.dot(rot, v))

    #Now do the elevation rotation, by rotating around the x axis.
    rot = np.dot(x_rotation_matrix(-elevation), rot)

    #Finally add an azimuthal rotation (around the y axis, or phi)
    rot = np.dot(rotation_matrix(azimuth, 0, 0), rot)

    #Now we rotate the base vectors, save them as vectors
    u_rotated = Vector(np.dot(rot, u))
    v_rotated = Vector(np.dot(rot, v))

    #Use getEuler to get the equivalent phi,chi,omega (in that order) rotation angles.
    (phi, chi,
     omega) = getEuler(u_rotated,
                       v_rotated)  #getEuler input units defaults to radians

    # Now we save these 3 orientation angles
    bank.addParameter("phi", phi, units=RAD)
    bank.addParameter("chi", chi, units=RAD)
    bank.addParameter("omega", omega, units=RAD)

    #Congrats! We have now tricked the program into making the correct detector orientation
    # (we hope!)

    # Now we set a local_name for the bank
    bank.setAnnotation("<local_name>%s</local_name>" % local_name)

    instrument.addComponent(bank)

    #! Now mantid
    idstart = banknum * 65536

    #  Have to flip U because it is the opposite of what we expect
    u_rotated = Vector(np.dot(rot, u) * -1.0)
    (phi, chi,
     omega) = getEuler(u_rotated,
                       v_rotated)  #getEuler input units defaults to radians
    #print "<!--- Rotated we have u ", u_rotated, ", v", v_rotated, "giving angles ", (phi, chi, omega), " ... for bank", banknum, " --->"
    print makeMantidGeometryCode(local_name, idstart, distance, theta_center,
                                 phi_center, phi, chi, omega)
    writeToFile(
        makeMantidGeometryCode(local_name, idstart, distance, theta_center,
                               phi_center, phi, chi, omega), 'a')
Example #4
0
#!/usr/bin/env python

from sns_geometry import Geometry, Component, Maths, Recipe, Vector, \
     extractValueFromFile, generateGeom, getEuler

from math import cos, sin, acos, atan2
from datetime import datetime, date
import numpy as np

geometry = generateGeom("TOPAZ")
entry = geometry.getEntry()
instrument = entry.getInstrument()

# Monitors
monitor1 = Component("monitor1", "NXmonitor")
monitor1.setComment("MONITORS")
monitor1.setHelper("ParameterCopy")
monitor1.addVariable("distance", "mon1dis")
entry.addMonitor(monitor1)
monitor2 = Component("monitor2", "NXmonitor")
monitor2.setHelper("ParameterCopy")
monitor2.addVariable("distance", "mon2dis")
entry.addMonitor(monitor2)

# Sample
sample = Component("sample", "NXsample")
sample.setComment(" SAMPLE ")
sample.setHelper("Goiniometer")
#real_phi, etc. are the real sample orientations (sanitized names, taken from phi,chi,omega MOTOR values)
#phi, chi, etc. are the sample orientations
sample.addVariable("phi", "real_phi")
def addBank(instrument, banknum, local_name, distance, cenX, cenY, cenZ, base, up):
    """Add a bank (detector) with given angles.

    Parameters:
        banknum: Number of the detector.
        local_name: local_name of the detector (a string)
        azimuth: azimuthal angle in radians. 0 = pointing downstream
        elevation: elevation angle in radians. Positive = going up (towards +Y)
        rotation: rotation of the detector face, in rad, around the positive +Z axis.
            For topaz this is -45 degrees.
        distance: in cm, from sample to center of detector face.
    """
    CM = "centimetre"
    RAD = "radian"

    bank = Component( "bank%d" % banknum, "NXdetector")
    bank.setRecipe("topaz_detector")
    theta = acos(cenZ/distance)
    phi = atan2(cenY, cenX)

    # Distance between sample and center of detector
    bank.addParameter("cenDistance", distance, units=CM)

    # cenPolar is "The angle of the rectangle center from the positive z-axis."
    # So this corresponds to our "theta" angle.
    bank.addParameter("cenPolar", theta, units=RAD)
    #Azimuthal = the angle of the rectangle center from the positive x-axis constrained in the xy-plane.
    # so this corresponds to the "phi" angle.
    bank.addParameter("cenAzimuthal", phi, units=RAD)
    
    #For later
    phi_center = phi
    theta_center = theta
    
    #Use getEuler to get the equivalent phi,chi,omega (in that order) rotation angles.
    (phi, chi, omega) = getEuler(base, up) #getEuler input units defaults to radians

    # Now we save these 3 orientation angles
    bank.addParameter("phi", phi, units=RAD)
    bank.addParameter("chi", chi, units=RAD)
    bank.addParameter("omega", omega, units=RAD)

    #Congrats! We have now tricked the program into making the correct detector orientation
    # (we hope!)
    

    # Now we set a local_name for the bank	
    bank.setAnnotation("<local_name>%s</local_name>" % local_name)
    
    instrument.addComponent(bank)


    #! Now mantid
    idstart = banknum * 65536

    print makeMantidGeometryCode(banknum, local_name, idstart, distance, theta_center, phi_center, phi, chi, omega)
    writeToFile(makeMantidGeometryCode(banknum, local_name, idstart, distance, theta_center, phi_center, phi, chi, omega), 'a')
Example #6
0
def addBank(instrument, banknum, local_name, distance, cenX, cenY, cenZ, base,
            up):
    """Add a bank (detector) with given angles.

    Parameters:
        banknum: Number of the detector.
        local_name: local_name of the detector (a string)
        azimuth: azimuthal angle in radians. 0 = pointing downstream
        elevation: elevation angle in radians. Positive = going up (towards +Y)
        rotation: rotation of the detector face, in rad, around the positive +Z axis.
            For topaz this is -45 degrees.
        distance: in cm, from sample to center of detector face.
    """
    CM = "centimetre"
    RAD = "radian"

    bank = Component("bank%d" % banknum, "NXdetector")
    bank.setRecipe("topaz_detector")
    theta = acos(cenZ / distance)
    phi = atan2(cenY, cenX)

    # Distance between sample and center of detector
    bank.addParameter("cenDistance", distance, units=CM)

    # cenPolar is "The angle of the rectangle center from the positive z-axis."
    # So this corresponds to our "theta" angle.
    bank.addParameter("cenPolar", theta, units=RAD)
    #Azimuthal = the angle of the rectangle center from the positive x-axis constrained in the xy-plane.
    # so this corresponds to the "phi" angle.
    bank.addParameter("cenAzimuthal", phi, units=RAD)

    #For later
    phi_center = phi
    theta_center = theta

    #Use getEuler to get the equivalent phi,chi,omega (in that order) rotation angles.
    (phi, chi, omega) = getEuler(base,
                                 up)  #getEuler input units defaults to radians

    # Now we save these 3 orientation angles
    bank.addParameter("phi", phi, units=RAD)
    bank.addParameter("chi", chi, units=RAD)
    bank.addParameter("omega", omega, units=RAD)

    #Congrats! We have now tricked the program into making the correct detector orientation
    # (we hope!)

    # Now we set a local_name for the bank
    bank.setAnnotation("<local_name>%s</local_name>" % local_name)

    instrument.addComponent(bank)

    #! Now mantid
    idstart = banknum * 65536

    print makeMantidGeometryCode(local_name, idstart, distance, theta_center,
                                 phi_center, phi, chi, omega)
    writeToFile(
        makeMantidGeometryCode(local_name, idstart, distance, theta_center,
                               phi_center, phi, chi, omega), 'a')