damaris-script-library/Scripts/T1Q/t1q_exp.py

171 lines
6.2 KiB
Python
Raw Normal View History

2015-06-26 12:17:24 +00:00
# -*- coding: iso-8859-1 -*-
TXEnableDelay = 2e-6
TXEnableValue = 0b0001 # TTL line blanking RF amplifier (bit 0)
TXPulseValue = 0b0010 # TTL line triggering RF pulses (bit 1)
ADCSensitivity = 2 # voltage span for ADC
def experiment(): # Jeener-Broekaert sequence with solid-echo detection to measure T1Q [JMR 43, 213 (1981)].
# set up acquisition parameters:
pars = {}
2015-09-30 11:23:17 +00:00
pars['P90'] = 4.2e-6 # 90-degree pulse length (s)
2015-06-26 12:17:24 +00:00
pars['SF'] = 46.7e6 # spectrometer frequency (Hz)
pars['O1'] = 5.6e3 # offset from SF (Hz)
pars['SW'] = 200e3 # spectrum width (Hz)
pars['SI'] = 1*256 # number of acquisition points
2015-09-30 11:23:17 +00:00
pars['NS'] = 16 # number of scans
2015-06-26 12:17:24 +00:00
pars['DS'] = 0 # number of dummy scans
pars['RD'] = .5 # delay between scans (s)
pars['D1'] = 30e-6 # delay after first pulse or 'short tau' (s)
2015-09-30 11:23:17 +00:00
pars['D2'] = 30e-1 # delay after second pulse or 'long tau' (s)
pars['PHA'] = -40 # receiver phase (degree)
2015-06-26 12:17:24 +00:00
pars['DATADIR'] = '/home/fprak/Students/' # data directory
pars['OUTFILE'] = None # output file name
# specify a variable parameter (optional):
2015-09-30 11:23:17 +00:00
pars['VAR_PAR'] = None#'D2' # variable parameter name (a string)
2015-06-26 12:17:24 +00:00
start = 30e-6 # starting value
stop = 2e-0 # end value
steps = 16 # number of values
log_scale = True # log scale flag
stag_range = False # staggered range flag
# check parameters for safety:
if pars['PHA'] < 0:
pars['PHA'] = 360 + pars['PHA']
if pars['P90'] > 20e-6:
raise Exception("Pulse too long!!!")
# check whether a variable parameter is named:
var_key = pars.get('VAR_PAR')
if var_key == 'P90' and (start > 20e-6 or stop > 20e-6):
raise Exception("Pulse too long!!!")
if pars['NS']%8 != 0:
pars['NS'] = int(round(pars['NS'] / 8) + 1) * 8
print 'Number of scans changed to ',pars['NS'],' due to phase cycling'
# start the experiment:
if var_key:
# this is an arrayed experiment:
if log_scale:
array = log_range(start,stop,steps)
else:
array = lin_range(start,stop,steps)
if stag_range:
array = staggered_range(array, size = 2)
# estimate the experiment time:
if var_key == 'D1':
seconds = (sum(array)*2 + (pars['D2'] + pars['RD']) * steps) * (pars['NS'] + pars['DS'])
elif var_key == 'D2':
seconds = (sum(array) + (pars['D1']*2 + pars['RD']) * steps) * (pars['NS'] + pars['DS'])
elif var_key == 'RD':
seconds = (sum(array) + (pars['D1']*2 + pars['D2']) * steps) * (pars['NS'] + pars['DS'])
else:
seconds = (pars['D1']*2 + pars['D2'] + pars['RD']) * steps * (pars['NS']+ pars['DS'])
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
print '%s%02d:%02d:%02d' % ('Experiment time estimated: ', h, m, s)
# loop for a variable parameter:
for index, pars[var_key] in enumerate(array):
print 'Arrayed experiment for '+var_key+': run = '+str(index+1)+\
' out of '+str(array.size)+': value = '+str(pars[var_key])
# loop for accumulation:
for run in xrange(pars['NS']+pars['DS']):
yield t1q_experiment(pars, run)
synchronize()
else:
# estimate the experiment time:
seconds = (pars['D1']*2 + pars['D2'] + pars['RD']) * (pars['NS']+ pars['DS'])
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
print '%s%02d:%02d:%02d' % ('Experiment time estimated: ', h, m, s)
# loop for accumulation:
for run in xrange(pars['NS']+pars['DS']):
yield t1q_experiment(pars, run)
# the pulse program:
def t1q_experiment(pars, run):
e=Experiment()
dummy_scans = pars.get('DS')
if dummy_scans:
run -= dummy_scans
pars['PROG'] = 't1q_experiment'
# phase cycle from J. Magn. Reson. 43, 213-223 (1981) extended for 90-deg refocusing pulse which also eliminates echo(es) after 3rd 45-deg pulse:
pars['PH1'] = [0, 0, 90, 90, 180, 180, 270, 270] # 90-deg pulse
pars['PH3'] = [90, 90, 180, 180, 270, 270, 0, 0] # 1st 45-deg pulse
pars['PH4'] = [0, 180, 0, 180, 180, 0, 180, 0] # 2nd 45-deg pulse
pars['PH5'] = [0, 0, 180, 180, 270, 90, 90, 270] # refocucing 90-deg pulse
pars['PH2'] = [0, 180, 0, 180, 180, 0, 180, 0] # receiver
# read in variables:
P90 = pars['P90']
P45 = pars['P90']*0.5
SF = pars['SF']
O1 = pars['O1']
RD = pars['RD']
D1 = pars['D1']
D2 = pars['D2']
PH1 = pars['PH1'][run%len(pars['PH1'])]
PH3 = pars['PH3'][run%len(pars['PH3'])]
PH4 = pars['PH4'][run%len(pars['PH4'])]
PH5 = pars['PH5'][run%len(pars['PH5'])]
PH2 = pars['PH2'][run%len(pars['PH2'])]
PHA = pars['PHA']
2015-09-30 11:23:17 +00:00
if (run/8)%2 != 0:
PH5 += 180
2015-06-26 12:17:24 +00:00
# set sampling parameters:
SI = pars['SI']
SW = pars['SW']
while SW <= 10e6 and SI < 256*1024:
SI *= 2
SW *= 2
# run the pulse sequence:
e.wait(RD) # delay between scans
e.set_frequency(SF+O1, phase=PH1)
e.ttl_pulse(TXEnableDelay, value=TXEnableValue)
e.ttl_pulse(P90, value=TXEnableValue|TXPulseValue) # 90-degree pulse
2015-09-30 11:23:17 +00:00
e.wait(D1-P90/2-P45/2-TXEnableDelay) # 'short tau'
2015-06-26 12:17:24 +00:00
e.set_phase(PH3)
e.ttl_pulse(TXEnableDelay, value=TXEnableValue)
e.ttl_pulse(P45, value=TXEnableValue|TXPulseValue) # 45-degree pulse
2015-09-30 11:23:17 +00:00
e.wait(D2-P45-TXEnableDelay) # 'long tau'
2015-06-26 12:17:24 +00:00
e.set_phase(PH4)
e.ttl_pulse(TXEnableDelay, value=TXEnableValue)
e.ttl_pulse(P45, value=TXEnableValue|TXPulseValue) # 45-degree pulse
e.wait(10e-6-TXEnableDelay)
e.set_phase(PH5)
e.ttl_pulse(TXEnableDelay, value=TXEnableValue)
e.ttl_pulse(P90, value=TXEnableValue|TXPulseValue) # 90-degree pulse
e.set_phase(PHA)
2015-09-30 11:23:17 +00:00
e.wait(12e-6)
2015-06-26 12:17:24 +00:00
e.record(SI, SW, sensitivity=ADCSensitivity) # acquisition
# write experiment attributes:
for key in pars.keys():
e.set_description(key, pars[key]) # acqusition parameters
e.set_description('run', run) # current scan
e.set_description('rec_phase', -PH2) # current receiver phase
return e