Commit a5e49cb8 authored by Philippe Piot's avatar Philippe Piot
Browse files

orignal

parent 7efcc9a3
This diff is collapsed.
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 9 16:06:16 2021
@author: awa
"""
import numpy as np
import matplotlib.pyplot as plt
import sys, os
from win32com import client
sys.path.append('\\'.join(os.getcwd().split('\\')[:-1]))
import time
from datetime import datetime
from epics import caget, caput, caget_many
timenow = datetime.now()
time_taking_data = timenow.strftime("%Y-%m-%d-%H%M")
Npoints=100
savedir = 'E:\\AWA data\\2021\\1109\\dataScan'
pos = caget('WitDelay:pi:pos00')
info= 'diode_background_com7pos3com8pos3_' + str(pos) + '_' + time_taking_data
radcam = '13ARV1:image1:ArrayData'
radcam_img_shape = (1088, 2048) # rad hard camera resolution is 1088x2048
imgdata = np.zeros((Npoints, 1088, 2048), dtype=np.uint16)
ictchannel = 'AWAICTMon:Ch4'
waveformchannel1 = 'AWAICTMon:wf1'
waveformchannel2 = 'AWAICTMon:wf2'
chargedata = np.zeros((Npoints,))
waveformdata1 = np.zeros((Npoints, 5000))
waveformdata2 = np.zeros((Npoints, 5000))
# rad hard camera
for i in range(Npoints):
waveformdata1[i,:] = caget(waveformchannel1)
waveformdata2[i,:] = caget(waveformchannel2)
chargedata[i] = caget(ictchannel)
time.sleep(1)
print('step: ', i, 'ict4: ', chargedata[i])
np.save(os.path.join(savedir, info+'ictch4data.npy'), chargedata)
np.save(os.path.join(savedir, info+'waveformch2.npy'), waveformdata2)
np.save(os.path.join(savedir, info+'waveformch1.npy'), waveformdata1)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 8 09:36:51 2021
@author: awa
This script takes a number of images specified by the user.
"""
import numpy as np
import matplotlib.pyplot as plt
import sys, os
from win32com import client
sys.path.append('\\'.join(os.getcwd().split('\\')[:-1]))
import time
from datetime import datetime
from epics import caget, caput, caget_many
timenow = datetime.now()
time_taking_data = timenow.strftime("%Y-%m-%d-%H%M")
Npoints=100
savedir = 'E:\\AWA data\\2021\\1109\\dataScan'
pos = caget('WitDelay:pi:pos00')
info= 'spectrometer_56dipole_115solenoid_' + str(pos) + '_' + time_taking_data
radcam = '13ARV1:image1:ArrayData'
radcam_img_shape = (1088, 2048) # rad hard camera resolution is 1088x2048
imgdata = np.zeros((Npoints, 1088, 2048), dtype=np.uint16)
ictchannel = 'AWAICTMon:Ch4'
waveformchannel1 = 'AWAICTMon:wf1'
waveformchannel2 = 'AWAICTMon:wf2'
chargedata = np.zeros((Npoints,))
waveformdata1 = np.zeros((Npoints, 5000))
waveformdata2 = np.zeros((Npoints, 5000))
# rad hard camera
for i in range(Npoints):
img = caget('13ARV1:image1:ArrayData')
img = img.reshape(radcam_img_shape)
waveformdata1[i,:] = caget(waveformchannel1)
waveformdata2[i,:] = caget(waveformchannel2)
chargedata[i] = caget(ictchannel)
time.sleep(1)
print('step: ', i, 'ict4: ', chargedata[i])
imgdata[i,:,:]=img
np.save(os.path.join(savedir, info+'radcamimages.npy'), imgdata)
np.save(os.path.join(savedir, info+'ictch4data.npy'), chargedata)
np.save(os.path.join(savedir, info+'waveformch2.npy'), waveformdata2)
np.save(os.path.join(savedir, info+'waveformch1.npy'), waveformdata1)
\ No newline at end of file
import time
import socket
def SetTDC(steps, command='MT',index=0,address="192.168.0.153",verbose=False):
"""
backlash not implemented
MT: move to position
MO: move by relative step
"""
assert command in ['R','PD','PU','LU','LD','MT','MO']
AWABeamlineClient=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if command in ['MO','MT']:
cmd=f"{command} {index} {int(steps)}"
else:
cmd=f"{command} {index}"
AWABeamlineClient.connect((address, 8080))
cmd += ' \n'
if verbose:
print(cmd)
AWABeamlineClient.send(cmd.encode())
if command == 'R':
data=AWABeamlineClient.recv(512)
AWABeamlineClient.close()
return data
else:
AWABeamlineClient.close()
def SetMagnets(counts, channels, beamline='Drive', verbose=False):
#beamline: Drive | Witness | ACT | EEX
#settings: [[chindex, counts],.....]
# counts = np.divide(gradients , cals)
assert len(counts) == len(channels)
settings = []
for i in range(len(counts)):
settings.append([channels[i], int(counts[i])])
if verbose:
print(repr(settings))
AWABeamlineClient=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cmd=f"GroupSet {beamline} {len(counts)} "
AWABeamlineClient.connect(("192.168.0.9", 80))
for j in range(len(counts)):
cmd += ' { '+'{} {} '.format(settings[j][0], settings[j][1])
cmd += '} '
cmd += ' \n'
# print(cmd)
AWABeamlineClient.send(cmd.encode())
data=AWABeamlineClient.recv(512)
AWABeamlineClient.close()
#print(data)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 8 10:16:51 2021
@author: awa
This script runs delay stage scan.
This script takes beam images' projections.
"""
import numpy as np
import matplotlib.pyplot as plt
import sys, os
from win32com import client
sys.path.append('\\'.join(os.getcwd().split('\\')[:-1]))
import time
from datetime import datetime
from epics import caget, caput, caget_many
timenow = datetime.now()
time_taking_data = timenow.strftime("%Y-%m-%d-%H%M")
pos_initial = -1281689 # just a reference point
info='emission_phasescan_emissionperiodonly_124solenoid_' + time_taking_data
savedir = 'E:\\AWA data\\2021\\1108\\dataScan'
ictchannel = 'AWAICTMon:Ch4'
waveformchannel1 = 'AWAICTMon:wf1'
waveformchannel2 = 'AWAICTMon:wf2'
waveformchannel3 = 'AWAICTMon:wf3'
radcam = '13ARV1:image1:ArrayData'
radcam_img_shape = (1088, 2048) # rad hard camera resolution is 1088x2048
grabber_shape = (480, 640) # frame grabber resolution is 480x640
delaystagepos = 'WitDelay:pi:pos00'
delaystagemove = 'WitDelay:pi:rel00'
# Total number of steps to move the delay stage
Nstep= 50
# The number of steps for the delay stage to move
# 5000 steps are about 1mm length
# negative means moving towards shorter path length differences
# positive means moving towards longer path length differences
delaystagestepsize = 1250
# Take 3 points per each step, wait for 1 second after taking each point
Npoints = 10
sleep_move_stage = 2
sleep_take_data = 1
pos_array = np.zeros((Nstep, Npoints))
pos_init = caget(delaystagepos)
chargedata = np.zeros((Nstep, Npoints))
waveformdata1 = np.zeros((Nstep, Npoints, 5000))
waveformdata2 = np.zeros((Nstep, Npoints, 5000))
# poslist = []
imgdata = np.zeros((Nstep, Npoints, radcam_img_shape[-1]))
grabberdata = np.zeros((Nstep, Npoints, grabber_shape[0], grabber_shape[-1]))
# frame grabber
#CameraDispatch = client.Dispatch('NIFGCtrl')
# PG camera
#CameraDispatch = client.Dispatch('AWAPGCamera.application')
# pg camera array
#pgdata = np.zeros((Nstep, Npoints, 1200, 1920))
for eachstep in range(Nstep):
caput(delaystagemove, delaystagestepsize)
time.sleep(sleep_move_stage) # wait for finishing the moving
for eachpoint in range(Npoints):
pos_array[eachstep, eachpoint] = caget(delaystagepos)
waveformdata1[eachstep, eachpoint,:] = caget(waveformchannel1)
waveformdata2[eachstep, eachpoint,:] = caget(waveformchannel2)
# rad hard camera
img = caget('13ARV1:image1:ArrayData')
img = img.reshape(radcam_img_shape)
imgdata[eachstep, eachpoint, :] = (img.sum(axis=0))
# frame grabber
# grabber = np.array(CameraDispatch.GetImage())
# grabberdata[eachstep, eachpoint, :, :] = grabber
# from PG camera
# pgimg = np.array(CameraDispatch.GetImage)
# pgdata[eachstep, eachpoint, : ,:] = pgimg
temp = caget(ictchannel)
chargedata[eachstep, eachpoint] = temp
print('current step: ', eachstep)
print('current position: ', caget(delaystagepos))
print('ICT reading: ', temp)
time.sleep(sleep_take_data)
print('step %d, position: %d'%(eachstep, caget(delaystagepos)))
np.save(os.path.join(savedir, info+'radcamprojection.npy'), imgdata)
np.save(os.path.join(savedir, info+'position.npy'), pos_array)
np.save(os.path.join(savedir, info+'ictch4data.npy'), chargedata)
np.save(os.path.join(savedir, info+'waveformch2.npy'), waveformdata2)
np.save(os.path.join(savedir, info+'waveformch1.npy'), waveformdata1)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 8 10:16:51 2021
@author: awa
This script runs delay stage scan.
This script takes beam images.
HUGE storage is expected !
"""
import numpy as np
import matplotlib.pyplot as plt
import sys, os
from win32com import client
sys.path.append('\\'.join(os.getcwd().split('\\')[:-1]))
import time
from datetime import datetime
from epics import caget, caput, caget_many
timenow = datetime.now()
time_taking_data = timenow.strftime("%Y-%m-%d-%H%M")
pos_initial = -1284189 # just a reference point
info='emission_phasescan_emissionperiodonly_124solenoid_' + time_taking_data
savedir = 'E:\\AWA data\\2021\\1109\\dataScan'
ictchannel = 'AWAICTMon:Ch4'
waveformchannel1 = 'AWAICTMon:wf1'
waveformchannel2 = 'AWAICTMon:wf2'
waveformchannel3 = 'AWAICTMon:wf3'
radcam = '13ARV1:image1:ArrayData'
radcam_img_shape = (1088, 2048) # rad hard camera resolution is 1088x2048
grabber_shape = (480, 640) # frame grabber resolution is 480x640
delaystagepos = 'WitDelay:pi:pos00'
delaystagemove = 'WitDelay:pi:rel00'
# Total number of steps to move the delay stage
Nstep= 20
# The number of steps for the delay stage to move
# 5000 steps are about 1mm length
# negative means moving towards shorter path length differences
# positive means moving towards longer path length differences
delaystagestepsize = -1250
# Take 3 points per each step, wait for 1 second after taking each point
Npoints = 5
sleep_move_stage = 2
sleep_take_data = 1
pos_array = np.zeros((Nstep, Npoints))
pos_init = caget(delaystagepos)
chargedata = np.zeros((Nstep, Npoints))
waveformdata1 = np.zeros((Nstep, Npoints, 5000))
waveformdata2 = np.zeros((Nstep, Npoints, 5000))
# poslist = []
imgdata = np.zeros((Nstep, Npoints, 1088, 2048), dtype=np.uint16)
# frame grabber
#CameraDispatch = client.Dispatch('NIFGCtrl')
# PG camera
#CameraDispatch = client.Dispatch('AWAPGCamera.application')
# pg camera array
#pgdata = np.zeros((Nstep, Npoints, 1200, 1920))
for eachstep in range(Nstep):
caput(delaystagemove, delaystagestepsize)
time.sleep(sleep_move_stage) # wait for finishing the moving
for eachpoint in range(Npoints):
pos_array[eachstep, eachpoint] = caget(delaystagepos)
waveformdata1[eachstep, eachpoint,:] = caget(waveformchannel1)
waveformdata2[eachstep, eachpoint,:] = caget(waveformchannel2)
# rad hard camera
img = caget('13ARV1:image1:ArrayData')
img = img.reshape(radcam_img_shape)
imgdata[eachstep, eachpoint, :] = img
# frame grabber
# grabber = np.array(CameraDispatch.GetImage())
# grabberdata[eachstep, eachpoint, :, :] = grabber
# from PG camera
# pgimg = np.array(CameraDispatch.GetImage)
# pgdata[eachstep, eachpoint, : ,:] = pgimg
temp = caget(ictchannel)
chargedata[eachstep, eachpoint] = temp
print('current step: ', eachstep)
print('current position: ', caget(delaystagepos))
print('ICT 4 reading: ', temp)
time.sleep(sleep_take_data)
print('step %d, position: %d'%(eachstep, caget(delaystagepos)))
np.save(os.path.join(savedir, info+'radcamimages.npy'), imgdata)
np.save(os.path.join(savedir, info+'position.npy'), pos_array)
np.save(os.path.join(savedir, info+'ictch4data.npy'), chargedata)
np.save(os.path.join(savedir, info+'waveformch2.npy'), waveformdata2)
np.save(os.path.join(savedir, info+'waveformch1.npy'), waveformdata1)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 8 10:16:51 2021
@author: awa
This script runs delay stage scan.
This script takes Faraday cup signal instead of beam images.
"""
import numpy as np
import matplotlib.pyplot as plt
import sys, os
from win32com import client
sys.path.append('\\'.join(os.getcwd().split('\\')[:-1]))
import time
from datetime import datetime
from epics import caget, caput, caget_many
timenow = datetime.now()
time_taking_data = timenow.strftime("%Y-%m-%d-%H%M")
pos_initial = -1281689 # just a reference point
info='emission_phasescan_emissionperiodonly_124solenoid_faraday_' + time_taking_data
savedir = 'E:\\AWA data\\2021\\1109\\dataScan'
ictchannel = 'AWAICTMon:Ch4'
waveformchannel1 = 'AWAICTMon:wf1'
waveformchannel2 = 'AWAICTMon:wf2'
waveformchannel3 = 'AWAICTMon:wf3'
radcam = '13ARV1:image1:ArrayData'
radcam_img_shape = (1088, 2048) # rad hard camera resolution is 1088x2048
grabber_shape = (480, 640) # frame grabber resolution is 480x640
delaystagepos = 'WitDelay:pi:pos00'
delaystagemove = 'WitDelay:pi:rel00'
# Total number of steps to move the delay stage
Nstep= 20
# The number of steps for the delay stage to move
# 5000 steps are about 1mm length
# negative means moving towards shorter path length differences
# positive means moving towards longer path length differences
delaystagestepsize = 1250
# Take 3 points per each step, wait for 1 second after taking each point
Npoints = 10
sleep_move_stage = 2
sleep_take_data = 1
pos_array = np.zeros((Nstep, Npoints))
pos_init = caget(delaystagepos)
chargedata = np.zeros((Nstep, Npoints))
waveformdata1 = np.zeros((Nstep, Npoints, 5000))
waveformdata2 = np.zeros((Nstep, Npoints, 5000))
waveformdata3 = np.zeros((Nstep, Npoints, 5000))
for eachstep in range(Nstep):
caput(delaystagemove, delaystagestepsize)
time.sleep(sleep_move_stage) # wait for finishing the moving
for eachpoint in range(Npoints):
pos_array[eachstep, eachpoint] = caget(delaystagepos)
# poslist.append(caget(delaystagepos))
waveformdata1[eachstep, eachpoint,:] = caget(waveformchannel1)
waveformdata2[eachstep, eachpoint,:] = caget(waveformchannel2)
waveformdata3[eachstep, eachpoint,:] = caget(waveformchannel3)
temp = caget(ictchannel)
chargedata[eachstep, eachpoint] = temp
print('current step: ', eachstep)
print('current position: ', caget(delaystagepos))
print('ICT reading: ', temp)
time.sleep(sleep_take_data)
print('step %d, position: %d'%(eachstep, caget(delaystagepos)))
np.save(os.path.join(savedir, info+'position.npy'), pos_array)
np.save(os.path.join(savedir, info+'ictch4data.npy'), chargedata)
np.save(os.path.join(savedir, info+'waveformch3.npy'), waveformdata3)
np.save(os.path.join(savedir, info+'waveformch2.npy'), waveformdata2)
np.save(os.path.join(savedir, info+'waveformch1.npy'), waveformdata1)
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 3 09:55:51 2021
@author: awa
"""
from epics import caget, caput, caget_many
import numpy as np
import time
delaystagepos = 'WitDelay:pi:pos00'
delaystagemove = 'WitDelay:pi:rel00'
halfwaveplatepos = 'HDR50:pi:pos12'
halfwaveplatemove = 'HDR50:pi:rel12'
default_step = 1250
def movecloser(num, step, pause=1):
step_to_move = -1 * np.abs(step)
for i in range(num):
caput(delaystagemove, step_to_move)
time.sleep(pause)
print('delay stage at: %d'%(caget(delaystagepos)))
def movefurther(num, step, pause=1):
step_to_move = np.abs(step)
for i in range(num):
caput(delaystagemove, step_to_move)
time.sleep(pause)
print('delay stage at: %d'%(caget(delaystagepos)))
def clockwise_halfwaveplate(num, step, pause=2):
step_to_move = np.abs(step)
for i in range(num):
caput(halfwaveplatemove, step_to_move)
time.sleep(pause)
print('halfwaveplate at: %d'%(caget(halfwaveplatepos)))
def anticlockwise_halfwaveplate(num, step, pause=2):
step_to_move = -1 * np.abs(step)
for i in range(num):
caput(halfwaveplatemove, step_to_move)
time.sleep(pause)
print('halfwaveplate at: %d'%(caget(halfwaveplatepos)))
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 8 09:52:29 2021
@author: awa
"""
import numpy as np
import matplotlib.pyplot as plt
import sys, os
from win32com import client
sys.path.append('\\'.join(os.getcwd().split('\\')[:-1]))
import time
from datetime import datetime
from epics import caget, caput, caget_many
def movecloser(num, step, pause=1):
step_to_move = -1 * np.abs(step)
for i in range(num):
caput(delaystagemove, step_to_move)
time.sleep(pause)
print('delay stage at: %d'%(caget(delaystagepos)))
def movefurther(num, step, pause=1):
step_to_move = np.abs(step)
for i in range(num):
caput(delaystagemove, step_to_move)
time.sleep(pause)
print('delay stage at: %d'%(caget(delaystagepos)))
def clockwise_halfwaveplate(num, step, pause=2):
step_to_move = np.abs(step)
for i in range(num):
caput(halfwaveplatemove, step_to_move)
time.sleep(pause)
print('halfwaveplate at: %d'%(caget(halfwaveplatepos)))
def anticlockwise_halfwaveplate(num, step, pause=2):
step_to_move = -1 * np.abs(step)
for i in range(num):
caput(halfwaveplatemove, step_to_move)
time.sleep(pause)
print('halfwaveplate at: %d'%(caget(halfwaveplatepos)))
timenow = datetime.now()
time_taking_data = timenow.strftime("%Y-%m-%d-%H%M")
pos_initial = 7811000 # just a reference point
posdelay = caget('WitDelay:pi:pos00')
info='halfwaveplatescan_133solenoid_faraday_com7pos3com8pos6_' + str(posdelay) + '_' + time_taking_data
savedir = 'E:\\AWA data\\2021\\1109\\dataScan'
ictchannel = 'AWAICTMon:Ch4'
waveformchannel1 = 'AWAICTMon:wf1'
waveformchannel2 = 'AWAICTMon:wf2'
waveformchannel3 = 'AWAICTMon:wf3'
delaystagepos = 'WitDelay:pi:pos00'
delaystagemove = 'WitDelay:pi:rel00'
halfwaveplatepos = 'HDR50:pi:pos12'
halfwaveplatemove = 'HDR50:pi:rel12'
# Total number of steps to move the delay stage
Nstep= 90
# The number of steps for the half wave plate to rotate
# 100000 steps are about 1.3 degree
halfwaveplatestep = 100000
# Take `Npoints` points per each step, wait for 1 second after taking each point
Npoints = 10
sleep_move_stage = 3
sleep_take_data = 1
pos_array = np.zeros((Nstep, Npoints))
pos_init = caget(delaystagepos)
chargedata = np.zeros((Nstep, Npoints))
waveformdata1 = np.zeros((Nstep, Npoints, 5000))
waveformdata2 = np.zeros((Nstep, Npoints, 5000))
waveformdata3 = np.zeros((Nstep, Npoints, 5000))
for eachstep in range(Nstep):
anticlockwise_halfwaveplate(1, halfwaveplatestep, pause=sleep_move_stage)
for eachpoint in range(Npoints):
pos_array[eachstep, eachpoint] = caget(halfwaveplatepos)
# poslist.append(caget(delaystagepos))
waveformdata1[eachstep, eachpoint,:] = caget(waveformchannel1)
waveformdata2[eachstep, eachpoint,:] = caget(waveformchannel2)