parent
7f6839479c
commit
31d809a618
@ -76,7 +76,7 @@ class Experiment:
|
||||
## Experiment class holding the state tree
|
||||
|
||||
job_id = 0
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.job_id = Experiment.job_id
|
||||
Experiment.job_id += 1
|
||||
@ -87,7 +87,7 @@ class Experiment:
|
||||
|
||||
|
||||
# Commands -------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
## Creates a state with ttl signals of duration *length*.
|
||||
#
|
||||
# **Example:**
|
||||
@ -169,7 +169,9 @@ class Experiment:
|
||||
# @param ttls Additional ttl channels
|
||||
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 float frequency: Sampling frequency
|
||||
@ -182,7 +184,7 @@ class Experiment:
|
||||
if channels != 1 and channels != 3 and channels != 5 and channels != 15:
|
||||
raise ValueError, "Channel definition is illegal"
|
||||
attributes += ' channels="%i"'%(channels)
|
||||
|
||||
|
||||
nchannels = 0
|
||||
if channels == 1:
|
||||
nchannels = 1
|
||||
@ -214,7 +216,7 @@ class Experiment:
|
||||
else:
|
||||
for i in range(nchannels):
|
||||
attributes += ' impedance%i="%i"'%(i, impedance[i])
|
||||
|
||||
|
||||
s_content = '<analogin %s/>' % attributes
|
||||
if ttls is not None:
|
||||
s_content+='<ttlout value="0x%06x"/>' % ttls
|
||||
@ -265,46 +267,48 @@ class Experiment:
|
||||
if ttls != 0:
|
||||
s_content += '<ttlout value="0x%06x"/>' % ttls
|
||||
self.state_list.append(StateSimple(2e-6, s_content))
|
||||
|
||||
## Creates a, possibly shaped, pulsed gradient.
|
||||
# @param dac_value DAC value to set
|
||||
# @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 is_seq If set to *True*, do NOT set DAC to zero after this state
|
||||
# @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.
|
||||
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
|
||||
|
||||
The default DAC ID is hardcoded (id=1)!
|
||||
|
||||
:param int dac_value: DAC value to set
|
||||
: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 bool is_seq: If set to *True*, do NOT set DAC to zero after this state
|
||||
: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 at the end of this state
|
||||
:param int trigger: default=4, lines to set (integer)
|
||||
"""
|
||||
try:
|
||||
form, resolution = shape
|
||||
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:
|
||||
# mimimum length
|
||||
length=42*9e-8
|
||||
if resolution >= length:
|
||||
raise ValueError, "Resolution %.3e of shaped gradients can not be longer than total length %.3e"%(resolution, length)
|
||||
|
||||
if 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)
|
||||
|
||||
|
||||
if form == 'rec': # shape==None --> rectangular gradients
|
||||
s_content = '<ttlout value="%s"/><analogout id="1" dac_value="%i"/>' % (trigger, dac_value)
|
||||
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"/>'
|
||||
self.state_list.append(StateSimple(42*9e-8, s_content))
|
||||
|
||||
@ -317,7 +321,7 @@ class Experiment:
|
||||
# set it back to zero
|
||||
s_content = '<ttlout value="%s"/><analogout id="1" dac_value="0"/>' % (trigger)
|
||||
self.state_list.append(StateSimple(resolution, s_content))
|
||||
|
||||
|
||||
elif form == 'sin':
|
||||
# sin shape
|
||||
for t in t_steps:
|
||||
@ -341,12 +345,12 @@ class Experiment:
|
||||
"""
|
||||
This sets the value for the DAC and if given the TTLs.
|
||||
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).
|
||||
|
||||
: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 bool is_seq: default=False, do not reset DAC to 0 (zero) if True
|
||||
:param int ttls: default=0, lines to set (integer)
|
||||
@ -380,7 +384,7 @@ class Experiment:
|
||||
if ttls!=0:
|
||||
s_content += '<ttlout value="%d"/>' % ttls
|
||||
self.state_list.append(StateSimple(0.5e-6, s_content))
|
||||
|
||||
|
||||
## sets a description which is carried via the back end result
|
||||
## file to the result script in the front end. In the result script
|
||||
## you can extract the description with get_description(key)
|
||||
@ -389,10 +393,13 @@ class Experiment:
|
||||
def set_description(self, key, value):
|
||||
"""Sets a description which is carried via the back end result
|
||||
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():
|
||||
print 'Warning: Overwriting existing description "%s" = "%s" with "%s"' % (key, self.description[key], value)
|
||||
|
||||
self.description[key] = value
|
||||
|
||||
## set the PTS310/PTS500 frequency source to local mode
|
||||
@ -482,7 +489,7 @@ class Experiment:
|
||||
class Quit(Experiment):
|
||||
def write_xml_string(self):
|
||||
return '<?xml version="1.0" encoding="ISO-8859-1"?>\n<quit no="%d"/>'%self.job_id
|
||||
|
||||
|
||||
|
||||
# /Public Methods ------------------------------------------------------------------------------
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user