The curve module provides Curve and Data for storing force curves.
A grouped set of Data runs from the same file with metadata.
For an approach/retract force spectroscopy experiment, the group would consist of the approach data and the retract data. Metadata would be the temperature, cantilever spring constant, etc.
Each Data block in data must contain an info['name'] setting with a unique (for the parent curve) name identifying the data block. This allows plugins and commands to access individual blocks.
Each curve maintiains a CommandStack (command_stack) listing the commands that have been applied to the Curve since loading.
The data-type is pickleable, to ensure we can move it between processes with multiprocessing.Queues.
>>> import pickle
>>> import yaml
>>> from .engine import CommandMessage
>>> c = Curve(path='some/path')
We add a recursive reference to c as you would get from hooke.plugin.curve.CurveCommand._add_to_command_stack().
>>> c.command_stack.append(CommandMessage('curve info', {'curve':c}))
>>> s = pickle.dumps(c)
>>> z = pickle.loads(s)
>>> z
<Curve path>
>>> z.command_stack
[<CommandMessage curve info {curve: <Curve path>}>]
>>> z.command_stack[-1].arguments['curve'] == z
True
>>> print yaml.dump(c)
&id001 !!python/object:hooke.curve.Curve
command_stack: !!python/object/new:hooke.command_stack.CommandStack
listitems:
- !!python/object:hooke.engine.CommandMessage
arguments:
curve: *id001
command: curve info
explicit_user_call: true
name: path
path: some/path
<BLANKLINE>
However, if we try and serialize the command stack first, we run into Python issue 1062277.
>>> pickle.dumps(c.command_stack)
Traceback (most recent call last):
...
assert id(obj) not in self.memo
AssertionError
YAML still works, though.
>>> print yaml.dump(c.command_stack)
&id001 !!python/object/new:hooke.command_stack.CommandStack
listitems:
- !!python/object:hooke.engine.CommandMessage
arguments:
curve: !!python/object:hooke.curve.Curve
command_stack: *id001
name: path
path: some/path
command: curve info
explicit_user_call: true
<BLANKLINE>
Methods
identify | |
load | |
set_hooke | |
set_path | |
unload |
Identify the appropriate hooke.driver.Driver for the curve file (.path).
Use the driver to read the curve into memory.
Also runs any commands in command_stack. All arguments are passed through to hooke.command_stack.CommandStack.execute().
Release memory intensive data.
Stores a single, continuous data set.
Adds info dict to the standard numpy.ndarray.
See numpy.doc.subclassing for the peculiarities of subclassing numpy.ndarray.
Examples
>>> d = Data(shape=(3,2), info={'columns':['distance (m)', 'force (N)']})
>>> type(d)
<class 'hooke.curve.Data'>
>>> for i in range(3): # initialize d
... for j in range(2):
... d[i,j] = i*10 + j
>>> d
Data([[ 0., 1.],
[ 10., 11.],
[ 20., 21.]])
>>> d.info
{'columns': ['distance (m)', 'force (N)']}
The information gets passed on to slices.
>>> row_a = d[:,0]
>>> row_a
Data([ 0., 10., 20.])
>>> row_a.info
{'columns': ['distance (m)', 'force (N)']}
The data-type is also pickleable, to ensure we can move it between processes with multiprocessing.Queues.
>>> import pickle
>>> s = pickle.dumps(d)
>>> z = pickle.loads(s)
>>> z
Data([[ 0., 1.],
[ 10., 11.],
[ 20., 21.]])
>>> z.info
{'columns': ['distance (m)', 'force (N)']}
The data-type is also YAMLable (see hooke.util.yaml).
>>> import yaml
>>> s = yaml.dump(d)
>>> print s
!hooke.curve.DataInfo
columns: [distance (m), force (N)]
<BLANKLINE>
>>> z = yaml.load(s)
>>> z
Data([], shape=(0, 0), dtype=float32)
Methods
all | |
any | |
argmax | |
argmin | |
argsort | |
astype | |
byteswap | |
choose | |
clip | |
compress | |
conj | |
conjugate | |
copy | |
cumprod | |
cumsum | |
diagonal | |
dump | |
dumps | |
fill | |
flatten | |
getfield | |
item | |
itemset | |
max | |
mean | |
min | |
newbyteorder | |
nonzero | |
prod | |
ptp | |
put | |
ravel | |
repeat | |
reshape | |
resize | |
round | |
searchsorted | |
setfield | |
setflags | |
sort | |
squeeze | |
std | |
sum | |
swapaxes | |
take | |
tofile | |
tolist | |
tostring | |
trace | |
transpose | |
var | |
view |