+# Copyright
+
+"""The `curve` module provides :class:`Curve` and :class:`Data` for
+storing force curves.
+"""
+
import os.path
import numpy
-from .driver import NotRecognized
+
+class NotRecognized (ValueError):
+ def __init__(self, curve):
+ msg = 'Not a recognizable curve format: %s' % curve.path
+ ValueError.__init__(self, msg)
+ self.curve = curve
class Data (numpy.ndarray):
"""Stores a single, continuous data set.
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.
+
+ Two important :attr:`info` settings are `filetype` and
+ `experiment`. These are two strings that can be used by Hooke
+ commands/plugins to understand what they are looking at.
+
+ * `.info['filetype']` should contain the name of the exact
+ filetype defined by the driver (so that filetype-speciofic
+ commands can know if they're dealing with the correct filetype).
+ * `.info['experiment']` should contain an instance of a
+ :class:`hooke.experiment.Experiment` subclass to identify the
+ experiment type. For example, various
+ :class:`hooke.driver.Driver`\s can read in force-clamp data, but
+ Hooke commands could like to know if they're looking at force
+ clamp data, regardless of their origin.
"""
- def __init__(self, path):
+ def __init__(self, path, info=None):
#the data dictionary contains: {name of data: list of data sets [{[x], [y]}]
self.path = path
self.driver = None
self.data = []
- self.info = None
+ if info == None:
+ info = {}
+ self.info = info
self.name = os.path.basename(path)
- self.notes = ''
def identify(self, drivers):
"""Identify the appropriate :class:`hooke.driver.Driver` for
the curve file (`.path`).
"""
for driver in drivers:
- current_driver = driver(self.path)
- if current_driver.is_me():
- self.driver = current_driver # remember the working driver
+ if driver.is_me(self.path):
+ self.driver = driver # remember the working driver
return
- raise NotRecognized(self.path)
+ raise NotRecognized(self)
def load(self):
"""Use the driver to read the curve into memory.