3 """The `curve` module provides :class:`Curve` and :class:`Data` for
11 class NotRecognized (ValueError):
12 def __init__(self, curve):
13 msg = 'Not a recognizable curve format: %s' % curve.path
14 ValueError.__init__(self, msg)
17 class Data (numpy.ndarray):
18 """Stores a single, continuous data set.
20 Adds :attr:`info` :class:`dict` to the standard :class:`numpy.ndarray`.
22 See :mod:`numpy.doc.subclassing` for the peculiarities of
23 subclassing :class:`numpy.ndarray`.
25 def __new__(self, subtype, shape, dtype=numpy.float, buffer=None, offset=0,
26 strides=None, order=None, info=None):
27 """Create the ndarray instance of our type, given the usual
28 input arguments. This will call the standard ndarray
29 constructor, but return an object of our type.
31 obj = np.ndarray.__new__(subtype=subtype, shape=shape, dtype=dtype,
32 buffer=buffer, offset=offset, strides=strides,
34 # add the new attribute to the created instance
38 # Finally, we must return the newly created object:
41 def __array_finalize__(self, obj):
42 """Set any extra attributes from the original object when
43 creating a new view object."""
44 # reset the attribute from passed original object
45 self.info = getattr(obj, 'info', {})
46 # We do not need to return anything
50 """A grouped set of :class:`Data` runs from the same file with metadata.
52 For an approach/retract force spectroscopy experiment, the group
53 would consist of the approach data and the retract data. Metadata
54 would be the temperature, cantilever spring constant, etc.
56 Two important :attr:`info` settings are `filetype` and
57 `experiment`. These are two strings that can be used by Hooke
58 commands/plugins to understand what they are looking at.
60 * `.info['filetype']` should contain the name of the exact
61 filetype defined by the driver (so that filetype-speciofic
62 commands can know if they're dealing with the correct filetype).
63 * `.info['experiment']` should contain an instance of a
64 :class:`hooke.experiment.Experiment` subclass to identify the
65 experiment type. For example, various
66 :class:`hooke.driver.Driver`\s can read in force-clamp data, but
67 Hooke commands could like to know if they're looking at force
68 clamp data, regardless of their origin.
70 def __init__(self, path, info=None):
71 #the data dictionary contains: {name of data: list of data sets [{[x], [y]}]
78 self.name = os.path.basename(path)
80 def identify(self, drivers):
81 """Identify the appropriate :class:`hooke.driver.Driver` for
82 the curve file (`.path`).
84 for driver in drivers:
85 if driver.is_me(self.path):
86 self.driver = driver # remember the working driver
88 raise NotRecognized(self)
91 """Use the driver to read the curve into memory.