parent
7f6839479c
commit
31d809a618
@ -76,7 +76,7 @@ class Experiment:
|
|||||||
## Experiment class holding the state tree
|
## Experiment class holding the state tree
|
||||||
|
|
||||||
job_id = 0
|
job_id = 0
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.job_id = Experiment.job_id
|
self.job_id = Experiment.job_id
|
||||||
Experiment.job_id += 1
|
Experiment.job_id += 1
|
||||||
@ -87,7 +87,7 @@ class Experiment:
|
|||||||
|
|
||||||
|
|
||||||
# Commands -------------------------------------------------------------------------------------
|
# Commands -------------------------------------------------------------------------------------
|
||||||
|
|
||||||
## Creates a state with ttl signals of duration *length*.
|
## Creates a state with ttl signals of duration *length*.
|
||||||
#
|
#
|
||||||
# **Example:**
|
# **Example:**
|
||||||
@ -169,7 +169,9 @@ class Experiment:
|
|||||||
# @param ttls Additional ttl channels
|
# @param ttls Additional ttl channels
|
||||||
def record(self, samples, frequency, timelength=None, sensitivity = None, ttls=None, channels = 3, offset = None, impedance = None):
|
def record(self, samples, frequency, timelength=None, sensitivity = None, ttls=None, channels = 3, offset = None, impedance = None):
|
||||||
"""
|
"""
|
||||||
Records data with given number of samples, sampling frequency and sensitivity
|
Records data with given number of samples, sampling frequency and sensitivity.
|
||||||
|
Optionally, the time length of this state can be specified. If not specified **timelength** is
|
||||||
|
deduced from **samples**/**frequency**:
|
||||||
|
|
||||||
:param int samples: Number of samples to record
|
:param int samples: Number of samples to record
|
||||||
:param float frequency: Sampling frequency
|
:param float frequency: Sampling frequency
|
||||||
@ -182,7 +184,7 @@ class Experiment:
|
|||||||
if channels != 1 and channels != 3 and channels != 5 and channels != 15:
|
if channels != 1 and channels != 3 and channels != 5 and channels != 15:
|
||||||
raise ValueError, "Channel definition is illegal"
|
raise ValueError, "Channel definition is illegal"
|
||||||
attributes += ' channels="%i"'%(channels)
|
attributes += ' channels="%i"'%(channels)
|
||||||
|
|
||||||
nchannels = 0
|
nchannels = 0
|
||||||
if channels == 1:
|
if channels == 1:
|
||||||
nchannels = 1
|
nchannels = 1
|
||||||
@ -214,7 +216,7 @@ class Experiment:
|
|||||||
else:
|
else:
|
||||||
for i in range(nchannels):
|
for i in range(nchannels):
|
||||||
attributes += ' impedance%i="%i"'%(i, impedance[i])
|
attributes += ' impedance%i="%i"'%(i, impedance[i])
|
||||||
|
|
||||||
s_content = '<analogin %s/>' % attributes
|
s_content = '<analogin %s/>' % attributes
|
||||||
if ttls is not None:
|
if ttls is not None:
|
||||||
s_content+='<ttlout value="0x%06x"/>' % ttls
|
s_content+='<ttlout value="0x%06x"/>' % ttls
|
||||||
@ -265,46 +267,48 @@ class Experiment:
|
|||||||
if ttls != 0:
|
if ttls != 0:
|
||||||
s_content += '<ttlout value="0x%06x"/>' % ttls
|
s_content += '<ttlout value="0x%06x"/>' % ttls
|
||||||
self.state_list.append(StateSimple(2e-6, s_content))
|
self.state_list.append(StateSimple(2e-6, s_content))
|
||||||
|
|
||||||
## Creates a, possibly shaped, pulsed gradient.
|
## Creates a, possibly shaped, pulsed gradient.
|
||||||
# @param dac_value DAC value to set
|
# @param dac_value DAC value to set
|
||||||
# @param length Duration of the state, minimum length is 42*90ns=3.78us (default)
|
# @param length Duration of the state, minimum length is 42*90ns=3.78us (default)
|
||||||
# @param shape Tuple of (shape, resolution/seconds), shape can be one of: rec (default), sin2, sin
|
# @param shape Tuple of (shape, resolution/seconds), shape can be one of: rec (default), sin2, sin
|
||||||
# @param is_seq If set to *True*, do NOT set DAC to zero after this state
|
# @param is_seq If set to *True*, do NOT set DAC to zero after this state
|
||||||
# @param trigger Additional ttl channels
|
# @param trigger Additional ttl channels
|
||||||
def set_pfg(self, dac_value=None, length=None, shape=('rec',0), trigger=4, is_seq=False):
|
def set_pfg(self, dac_value=None, length=None, shape=('rec', 0), trigger=4, is_seq=False):
|
||||||
"""
|
"""
|
||||||
This sets the value for the PFG, it also sets it back automatically.
|
This sets the value for the PFG, it also sets it back automatically.
|
||||||
If you don't whish to do so (i.e. line shapes) set is_seq=1
|
If you don't whish to do so (i.e. line shapes) set is_seq=1
|
||||||
If you wnat to set a trigger, set trigger (default=4, i.e. channel 2)
|
If you want to set a trigger, set trigger (default=4, i.e. channel 2)
|
||||||
If you want shaped gradients: shape=(ashape, resolution), ashape can be rec, sin2, sin
|
If you want shaped gradients: shape=(ashape, resolution), ashape can be rec, sin2, sin
|
||||||
|
|
||||||
|
The default DAC ID is hardcoded (id=1)!
|
||||||
|
|
||||||
:param int dac_value: DAC value to set
|
:param int dac_value: DAC value to set
|
||||||
:param float length: Duration of the state, minimum length is 42*90ns=3.78us (default)
|
:param float length: Duration of the state, minimum length is 42*90ns=3.78us (default)
|
||||||
:param str shape: Tuple of (shape, resolution/seconds), shape can be one of: rec (default), sin2, sin
|
:param tuple shape: Tuple of (shape, resolution/seconds), shape can be one of: rec (default), sin2, sin
|
||||||
:param bool is_seq: If set to *True*, do NOT set DAC to zero after this state
|
:param bool is_seq: If set to *True*, do *NOT* set DAC to zero at the end of this state
|
||||||
:param int trigger: default=4, lines to set (integer)
|
:param int trigger: default=4, lines to set (integer)
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
form, resolution = shape
|
form, resolution = shape
|
||||||
except:
|
except:
|
||||||
raise SyntaxError, "shape argument needs to be a tuple, i.e. ('shape',resolution), shape can be sin, sin2, rec"
|
raise SyntaxError, "shape argument needs to be a tuple, i.e. ('shape',resolution), shape can be sin, sin2, rec"
|
||||||
|
|
||||||
if length == None:
|
if length == None:
|
||||||
# mimimum length
|
# mimimum length
|
||||||
length=42*9e-8
|
length=42*9e-8
|
||||||
if resolution >= length:
|
if resolution >= length:
|
||||||
raise ValueError, "Resolution %.3e of shaped gradients can not be longer than total length %.3e"%(resolution, length)
|
raise ValueError, "Resolution %.3e of shaped gradients can not be longer than total length %.3e"%(resolution, length)
|
||||||
|
|
||||||
if resolution < 42*9e-8:
|
if resolution < 42*9e-8:
|
||||||
raise ValueError, "Resulution %.3e can not be smaller than %.3e"%(resolution, 42*9e-8)
|
raise ValueError, "Resulution %.3e can not be smaller than %.3e"%(resolution, 42*9e-8)
|
||||||
|
|
||||||
t_steps = numpy.arange(0,length,resolution)
|
t_steps = numpy.arange(0,length,resolution)
|
||||||
|
|
||||||
if form == 'rec': # shape==None --> rectangular gradients
|
if form == 'rec': # shape==None --> rectangular gradients
|
||||||
s_content = '<ttlout value="%s"/><analogout id="1" dac_value="%i"/>' % (trigger, dac_value)
|
s_content = '<ttlout value="%s"/><analogout id="1" dac_value="%i"/>' % (trigger, dac_value)
|
||||||
self.state_list.append(StateSimple(length, s_content))
|
self.state_list.append(StateSimple(length, s_content))
|
||||||
|
|
||||||
if not is_seq and shape == None:
|
if not is_seq:
|
||||||
s_content = '<analogout id="1" dac_value="0"/>'
|
s_content = '<analogout id="1" dac_value="0"/>'
|
||||||
self.state_list.append(StateSimple(42*9e-8, s_content))
|
self.state_list.append(StateSimple(42*9e-8, s_content))
|
||||||
|
|
||||||
@ -317,7 +321,7 @@ class Experiment:
|
|||||||
# set it back to zero
|
# set it back to zero
|
||||||
s_content = '<ttlout value="%s"/><analogout id="1" dac_value="0"/>' % (trigger)
|
s_content = '<ttlout value="%s"/><analogout id="1" dac_value="0"/>' % (trigger)
|
||||||
self.state_list.append(StateSimple(resolution, s_content))
|
self.state_list.append(StateSimple(resolution, s_content))
|
||||||
|
|
||||||
elif form == 'sin':
|
elif form == 'sin':
|
||||||
# sin shape
|
# sin shape
|
||||||
for t in t_steps:
|
for t in t_steps:
|
||||||
@ -341,12 +345,12 @@ class Experiment:
|
|||||||
"""
|
"""
|
||||||
This sets the value for the DAC and if given the TTLs.
|
This sets the value for the DAC and if given the TTLs.
|
||||||
It also sets it back to zero automatically.
|
It also sets it back to zero automatically.
|
||||||
If you don't whish to set the value back to zero (i.e. line shapes) set is_seq=True
|
If you don't wish to set the value back to zero (i.e. line shapes) set is_seq=True
|
||||||
|
|
||||||
The state length is at least 3.78 µs (is_seq=1) or 7.28µs (is_seq=0).
|
The state length is at least 3.78 µs (is_seq=1) or 7.28µs (is_seq=0).
|
||||||
|
|
||||||
:param int dac_value: dac value, between -2**19-1 and +2**19
|
:param int dac_value: dac value, between -2**19-1 and +2**19
|
||||||
:param int dac_id: default=1, which dac to control
|
:param int dac_id: default=1, which DAC to control
|
||||||
:param float length: default=None, length of this state in seconds. If *None* length=42*90ns=3.78µs
|
:param float length: default=None, length of this state in seconds. If *None* length=42*90ns=3.78µs
|
||||||
:param bool is_seq: default=False, do not reset DAC to 0 (zero) if True
|
:param bool is_seq: default=False, do not reset DAC to 0 (zero) if True
|
||||||
:param int ttls: default=0, lines to set (integer)
|
:param int ttls: default=0, lines to set (integer)
|
||||||
@ -380,7 +384,7 @@ class Experiment:
|
|||||||
if ttls!=0:
|
if ttls!=0:
|
||||||
s_content += '<ttlout value="%d"/>' % ttls
|
s_content += '<ttlout value="%d"/>' % ttls
|
||||||
self.state_list.append(StateSimple(0.5e-6, s_content))
|
self.state_list.append(StateSimple(0.5e-6, s_content))
|
||||||
|
|
||||||
## sets a description which is carried via the back end result
|
## sets a description which is carried via the back end result
|
||||||
## file to the result script in the front end. In the result script
|
## file to the result script in the front end. In the result script
|
||||||
## you can extract the description with get_description(key)
|
## you can extract the description with get_description(key)
|
||||||
@ -389,10 +393,13 @@ class Experiment:
|
|||||||
def set_description(self, key, value):
|
def set_description(self, key, value):
|
||||||
"""Sets a description which is carried via the back end result
|
"""Sets a description which is carried via the back end result
|
||||||
file to the result script in the front end. In the result script
|
file to the result script in the front end. In the result script
|
||||||
you can extract the description with get_description"""
|
you can extract the description with get_description
|
||||||
|
|
||||||
|
:param str key: the key
|
||||||
|
:param value: the value, its type is saved.
|
||||||
|
"""
|
||||||
if key in self.description.keys():
|
if key in self.description.keys():
|
||||||
print 'Warning: Overwriting existing description "%s" = "%s" with "%s"' % (key, self.description[key], value)
|
print 'Warning: Overwriting existing description "%s" = "%s" with "%s"' % (key, self.description[key], value)
|
||||||
|
|
||||||
self.description[key] = value
|
self.description[key] = value
|
||||||
|
|
||||||
## set the PTS310/PTS500 frequency source to local mode
|
## set the PTS310/PTS500 frequency source to local mode
|
||||||
@ -482,7 +489,7 @@ class Experiment:
|
|||||||
class Quit(Experiment):
|
class Quit(Experiment):
|
||||||
def write_xml_string(self):
|
def write_xml_string(self):
|
||||||
return '<?xml version="1.0" encoding="ISO-8859-1"?>\n<quit no="%d"/>'%self.job_id
|
return '<?xml version="1.0" encoding="ISO-8859-1"?>\n<quit no="%d"/>'%self.job_id
|
||||||
|
|
||||||
|
|
||||||
# /Public Methods ------------------------------------------------------------------------------
|
# /Public Methods ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user