Skip to content
Snippets Groups Projects
Commit 1ec01f16 authored by 29iduser's avatar 29iduser
Browse files

hkl and electron anal

parent 8760fa9c
No related branches found
No related tags found
No related merge requests found
......@@ -43,11 +43,13 @@ def EA_ioc_init(**kwargs):
"""
run after restarting the 29idcScienta IOC
kwargs:
Close_CShutter="Close" default, if something else then it doesn't close the shutter
close_shutter=True/False (default = True)
"""
kwargs.setdefault("close_shutter",True)
if kwargs['close_shutter']==True:
branch_shutter_close('c')
print("C-Shutter is closed for initialization ")
#Addding HDF5 atttributes
filepath='/xorApps/epics/synApps_6_1/ioc/29idcScienta/iocBoot/ioc29idcScienta/HDF5Attributes.xml'
EA._updateAttributes(filepath)
......@@ -91,7 +93,7 @@ def EA_ioc_init(**kwargs):
caput(EA.PHV+"KineticEnergy:TWV.VAL",1)
caput(EA._Pcam+"Acquire","Acquire")
print("C-Shutter is closed for initialization ")
def folders_EA(user_path,filePrefix="EA",**kwargs):
......
......@@ -20,7 +20,7 @@ from epics import caget
from iexcode.instruments.conversions_constants import Lambda2eV, eV2Lambda
from Macros_29id.ScanFunctions_IEX import EtoK
from iexcode.instruments.xrays import getE, energy_get,energy,
from iexcode.instruments.xrays import getE, energy_get,energy,energy_get_all
from iexcode.instruments.scalers import scaler_cts as cts
from iexcode.instruments.scanRecord import scan_fillin,scan_go,scan_positioners_clear,scan_fillin_table,scan_after_table_reset
from iexcode.instruments.scanRecord import mda_filepath, mda_fileNum, mda_prefix
......@@ -480,4 +480,265 @@ def UBenergy_rbv():
eV=Lambda2eV(fourc.calc.wavelength)
print("\nCurrent energy: "+str(round(eV,2)))
############## start editing here
\ No newline at end of file
############## start editing here
def _scan_hkl_array(mytable,settling_time=0.2,acq_time=1,**kwargs):
"""
Uses bluesky pyhkl to calculate the motor positions for an hkl scan:
mytable = _hkl_array(hkl1,hkl2,npts,eV)
= (table_omega, table_chi, table_phi, table_tth)
Save the corresponding table into a txt file (CSV) as scan_####.txt
Logging is automatic
**kwargs are the optional logging arguments see scanlog() for details
"""
def hkl_vals(array_h,array_k,array_l,**kwargs):
"""
"""
IOC="29id"+scanIOC+":"
scanPV=IOC+"scan"+str(scanDIM)
Det_h=46
#setting up hkl as a detector
q=["H","K","L"]
for i,e in enumerate([array_h,array_k,array_l]):
ArrayCalc=IOC+"userArrayCalc"+str(i+1)
#adding description
caput(ArrayCalc+".DESC",'<'+q[i]+'>')
#changing the number of points in the array
caput(ArrayCalc+".NUSE",len(e))
#putting arrays in array calc
caput(ArrayCalc+".AA",e)
#put scanRecord N for indexing
caput(ArrayCalc+".INPA",scanPV+".CPT CP NMS")
#Make calc
caput(ArrayCalc+".CALC","AA[A,A]")
#output pv
caput(ArrayCalc+".OUT",ArrayCalc+".L NPP NMS")
#Add detector to scanRecord
caput(scanPV+".D"+str(Det_h+i)+"PV",ArrayCalc+".L")
print(caget(ArrayCalc+".DESC")+" = [D"+str(Det_h+i)+"]")
# Set counting time:
cts(acq_time)
# Extract individual arrays:
table_omega = mytable[0]
table_chi = mytable[1]
table_phi = mytable[2]
table_tth = mytable[3]
table_hkl = mytable[4]
array_h = mytable[4][:,0]
array_k = mytable[4][:,1]
array_l = mytable[4][:,2]
hkl_vals(array_h,array_k,array_l,scanIOC,scanDIM)
print(caget('29idKappa:m9.DESC')+" = [D54]")
print(caget('29idKappa:Euler_ThetaRBV.DESC')+" = [D55]")
print(caget('29idKappa:Euler_ChiRBV.DESC') +" = [D56]")
print(caget('29idKappa:Euler_PhiRBV.DESC') +" = [D57]")
#FileNum = caget("29id"+scanIOC+":saveData_scanNumber")
#table2csv((FileNum,array_h.tolist(),array_k.tolist(),array_l.tolist(),table_tth.tolist(),table_omega.tolist(),table_chi.tolist(),table_phi.tolist()),filePath=mypath,separator=',')
# Fill-in sscan record:
Scan_FillIn_Table('29idKappa:m9.VAL' ,"29idKappa:m9.RBV" ,scanIOC, scanDIM, table_tth, posNum=1)
Scan_FillIn_Table('29idKappa:Euler_Theta',"29idKappa:Euler_ThetaRBV",scanIOC, scanDIM, table_omega, posNum=2)
Scan_FillIn_Table('29idKappa:Euler_Chi' ,"29idKappa:Euler_ChiRBV" ,scanIOC, scanDIM, table_chi, posNum=3)
Scan_FillIn_Table('29idKappa:Euler_Phi' ,"29idKappa:Euler_PhiRBV" ,scanIOC, scanDIM, table_phi, posNum=4)
caput("29id"+scanIOC+":scan"+str(scanDIM)+".PASM","PRIOR POS")
caput("29id"+scanIOC+":scan"+str(scanDIM)+".PDLY",settling_time)
# Scanning
Scan_Go(scanIOC,scanDIM=scanDIM,**kwargs)
# Setting everything back
caput("29id"+scanIOC+":scan"+str(scanDIM)+".PDLY",0.1)
caput("29id"+scanIOC+":scan"+str(scanDIM)+".P1SM","LINEAR")
caput("29id"+scanIOC+":scan"+str(scanDIM)+".P2SM","LINEAR")
caput("29id"+scanIOC+":scan"+str(scanDIM)+".P3SM","LINEAR")
caput("29id"+scanIOC+":scan"+str(scanDIM)+".P4SM","LINEAR")
# Need to clear positionner!
Clear_Scan_Positioners(scanIOC)
def scanhkl(hkl1,hkl2,npts,ct,E=None,run=True,mycomment=''):
'''With hkl1=[h1,k1,l1] and hkl2=[h2,k2,l2]
If E = None (default), uses the current beamline energy.
Use run=False to display trajectory to make sure all reflections are within reach.
'''
if E is None:
E=getE()
UBenergy(E)
myarray=_hkl_array(hkl1,hkl2,npts,E)
print("Number of accessible reflections: ",str(len(myarray[4])))
if run == True:
#scanHKL(myarray,settling_time=0.2,acq_time=ct,mypath=path,comment=mycomment)
_scan_hkl_array(myarray,settling_time=0.2,acq_time=ct,comment=mycomment)
elif run == False:
cahkl_table(myarray[4])
def scanhkl_test(hkl1,hkl2,npts,ct,E=None):
'''Print the hkl trajectory for hkl1=[h1,k1,l1] and hkl2=[h2,k2,l2]
If E = None (default), uses the current beamline energy.
'''
if E is None:
E=getE()
cahkl_table(_hkl_array(hkl1,hkl2,npts,E)[4])
def _hkl_array(hkl_start,hkl_stop,npts,eV):
"""
Uses bluesky pyhkl to calculate a numpy array with the motors' trajectory for a given hkl scan.
"""
# Set diffractometer energy:
fourc.calc.wavelength = eV2Lambda(eV)
caput('29idKappa:UBenergy',Lambda2eV(fourc.calc.wavelength))
caput('29idKappa:UBlambda',fourc.calc.wavelength)
# Generate a list of hkl position
list_hkl_in = fourc.calc.calc_linear_path(hkl_start,hkl_stop,npts, num_params=3)
# Initialize motor table:
list_omega=[]
list_tth=[]
list_chi=[]
list_phi=[]
list_hkl_out=[]
# Compute motor positions for each hkl point & append to the motor tables:
for hkl in list_hkl_in:
try:
list_omega.append(fourc.calc.forward(hkl)[0][0])
list_chi.append(fourc.calc.forward(hkl)[0][1])
list_phi.append(fourc.calc.forward(hkl)[0][2])
list_tth.append(fourc.calc.forward(hkl)[0][3])
list_hkl_out.append(hkl)
except ValueError as err:
list_hkl_in.remove(hkl) # not removing all the unobtainable values
#print(str(hkl)+' : Error - Unobtainable reflection: Q > 2k?')
# Return a list of arrays:
return np.asarray(list_omega),np.asarray(list_chi),np.asarray(list_phi),np.asarray(list_tth),np.asarray(list_hkl_out)
def table2csv(hkl_table,filePath=None,separator=','):
#Need to make this smarter to not record unobtainable hkl reflections - data size missmatch
if filePath is None:
user=MDA_CurrentUser()
filePath="/home/beams/29IDUSER/Documents/User_Folders/"+user+'/hkl/'
scanNum=hkl_table[0]
scanNumstr=str.zfill(str(scanNum),0)
fileName='scan_'+scanNumstr+'.txt'
with open(join(filePath, fileName), "a+") as f:
f.write('h'+separator+'k'+separator+'l'+separator+'tth'+separator+'th'+separator+'chi'+separator+'phi'+'\n')
for (i) in range(len(hkl_table[1])):
f.write(str(hkl_table[1][i])+separator+str(hkl_table[2][i])+separator+str(hkl_table[3][i])+separator+str(hkl_table[4][i])+separator+str(hkl_table[5][i])+separator+str(hkl_table[6][i])+separator+str(hkl_table[7][i])+'\n')
print('\nWriting hkl table to:',join(filePath, fileName))
def scanhkl_E(StartStopStepLists,hkl,ct,scan_ID,mono_offset=0,settling_time=0.2,scanDIM=1,return_table=False,**kwargs):
"""
Uses bluesky pyhkl to calculate the motor positions for an energy scan at constant Q:
hkl=(h,k,l); if hkl=None, uses the current hkl position
ct = acquisition time (cts)
scan_ID: if True, scans the ID; if False, scan mono only
mono_offset => if you want to artificially shift the energy for the reciprocal space calulation (eg to match known hkl indexes)
StartStopStepLists is a list of lists for the different scan ranges
StartStopStepList[[start1,stop1,step1],[start2,stop2,step2],...]
Note duplicates are removed and the resulting array is sorted in ascending order
Logging is automatic
**kwargs are the optional logging arguments see scanlog() for details
"""
# Set counting time:
cts(ct)
# caget beamline parameters:
scanIOC='Kappa'
ID_Mode, ID_QP, ID_SP, ID_RBV, hv, grt = energy_get_all()
if hkl == None:
hkl=get_hkl()
print('hkl = '+str(hkl))
# Target hkl:
h,k,l=hkl
# Create energy trajectory (can have variable step size):
mytable_hv=Scan_MakeTable(StartStopStepLists)
caput('29idKappa:UBenergy',mytable_hv[0])
caput('29idKappa:UBlambda',eV2Lambda(mytable_hv[0]))
# Initialize motor table:
mytable_ID=np.array([])
mytable_omega=np.array([])
mytable_chi=np.array([])
mytable_phi=np.array([])
mytable_tth=np.array([])
# Compute motor positions for each energy point & append to the motor tables:
for eV in mytable_hv:
fourc.calc.wavelength = eV2Lambda(eV+mono_offset)
e_omega=round(fourc.calc.forward((h,k,l))[0][0],5)
e_chi = round(fourc.calc.forward((h,k,l))[0][1],5)
e_phi = round(fourc.calc.forward((h,k,l))[0][2],5)
e_tth = round(fourc.calc.forward((h,k,l))[0][3],5)
mytable_omega=np.append(mytable_omega,e_omega)
mytable_chi=np.append(mytable_chi,e_chi)
mytable_phi=np.append(mytable_phi,e_phi)
mytable_tth=np.append(mytable_tth,e_tth)
if scan_ID:
mytable_ID=np.append(mytable_ID,ID_Calc(grt,ID_Mode,eV,ID_QP))
# Fill-in sscan record:
Scan_FillIn_Table('29idmono:ENERGY_SP',"29idmono:ENERGY_MON",scanIOC, scanDIM, mytable_hv, posNum=1)
Scan_FillIn_Table('29idKappa:m9.VAL' ,"29idKappa:m9.RBV" ,scanIOC, scanDIM, mytable_tth, posNum=2)
Scan_FillIn_Table('29idKappa:Euler_Theta',"29idKappa:Euler_ThetaRBV",scanIOC, scanDIM, mytable_omega, posNum=3)
if scan_ID:# moving ID - at the moment this replaces chi:
Scan_FillIn_Table('ID29:EnergyScanSeteV',"", scanIOC, scanDIM, mytable_ID, posNum=4)
energy(mytable_hv[0])
else:
Scan_FillIn_Table('29idKappa:Euler_Chi' ,"29idKappa:Euler_ChiRBV" ,scanIOC, scanDIM, mytable_chi, posNum=4)
caput("29id"+scanIOC+":scan"+str(scanDIM)+".PASM","STAY")
caput("29id"+scanIOC+":scan"+str(scanDIM)+".PDLY",settling_time)
#Scanning
FileNum = caget("29id"+scanIOC+":saveData_scanNumber")
Scan_Go(scanIOC,scanDIM=scanDIM,**kwargs)
#Setting everything back
energy(hv)
caput("29id"+scanIOC+":scan"+str(scanDIM)+".PDLY",0.1)
caput("29id"+scanIOC+":scan"+str(scanDIM)+".P1SM","LINEAR")
caput("29id"+scanIOC+":scan"+str(scanDIM)+".P2SM","LINEAR")
caput("29id"+scanIOC+":scan"+str(scanDIM)+".P3SM","LINEAR")
caput("29id"+scanIOC+":scan"+str(scanDIM)+".P4SM","LINEAR")
# Need to clear positionner!
Clear_Scan_Positioners(scanIOC)
# to be saved in text file like scanhkl:
if return_table:
if not scan_ID: mytable_ID=None
return FileNum,mytable_hv.tolist(),mytable_ID.tolist(),mytable_omega.tolist(),mytable_chi.tolist() ,mytable_phi.tolist() ,mytable_tth.tolist()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment