4 from .driver import NotRecognized
6 class Data (numpy.ndarray):
7 """Stores a single, continuous data set.
9 Adds :attr:`info` :class:`dict` to the standard :class:`numpy.ndarray`.
11 See :mod:`numpy.doc.subclassing` for the peculiarities of
12 subclassing :class:`numpy.ndarray`.
14 def __new__(self, subtype, shape, dtype=numpy.float, buffer=None, offset=0,
15 strides=None, order=None, info=None):
16 """Create the ndarray instance of our type, given the usual
17 input arguments. This will call the standard ndarray
18 constructor, but return an object of our type.
20 obj = np.ndarray.__new__(subtype=subtype, shape=shape, dtype=dtype,
21 buffer=buffer, offset=offset, strides=strides,
23 # add the new attribute to the created instance
27 # Finally, we must return the newly created object:
30 def __array_finalize__(self, obj):
31 """Set any extra attributes from the original object when
32 creating a new view object."""
33 # reset the attribute from passed original object
34 self.info = getattr(obj, 'info', {})
35 # We do not need to return anything
39 """A grouped set of :class:`Data` runs from the same file with metadata.
41 For an approach/retract force spectroscopy experiment, the group
42 would consist of the approach data and the retract data. Metadata
43 would be the temperature, cantilever spring constant, etc.
45 def __init__(self, path):
46 #the data dictionary contains: {name of data: list of data sets [{[x], [y]}]
51 self.name = os.path.basename(path)
54 def identify(self, drivers):
55 """Identify the appropriate :class:`hooke.driver.Driver` for
56 the curve file (`.path`).
58 for driver in drivers:
59 current_driver = driver(self.path)
60 if current_driver.is_me():
61 self.driver = current_driver # remember the working driver
63 raise NotRecognized(self.path)
66 """Use the driver to read the curve into memory.