From: W. Trevor King Date: Wed, 4 Aug 2010 10:43:54 +0000 (-0400) Subject: Add `block` argument to hooke.plugin.vclamp.scale and only run required commands X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=25f96a20ae39307f41be7710aa1261ebaf38c4a3;p=hooke.git Add `block` argument to hooke.plugin.vclamp.scale and only run required commands --- diff --git a/hooke/plugin/vclamp.py b/hooke/plugin/vclamp.py index 2365122..9151765 100644 --- a/hooke/plugin/vclamp.py +++ b/hooke/plugin/vclamp.py @@ -38,22 +38,36 @@ from ..util.fit import PoorFit, ModelFitter from .curve import CurveArgument -def scale(hooke, curve): +def scale(hooke, curve, block=None): + """Run 'add block force array' on `block`. + + Runs 'zero block surface contact point' first, if necessary. Does + not run either command if the columns they add to the block are + already present. + + If `block` is `None`, scale all blocks in `curve`. + """ commands = hooke.commands contact = [c for c in hooke.commands if c.name == 'zero block surface contact point'][0] force = [c for c in hooke.commands if c.name == 'add block force array'][0] inqueue = None outqueue = NullQueue() - for i,block in enumerate(curve.data): - numpy.savetxt(open('curve.dat', 'w'), block, delimiter='\t') - params = {'curve':curve, 'block':i} - try: - contact._run(hooke, inqueue, outqueue, params) - except PoorFit, e: - raise PoorFit('Could not fit %s %s: %s' - % (curve.path, i, str(e))) - force._run(hooke, inqueue, outqueue, params) + if block == None: + for i in range(len(curve.data)): + scale(hooke, curve, block=i) + else: + params = {'curve':curve, 'block':block} + b = curve.data[block] + if ('surface distance (m)' not in b.info.columns + or 'surface adjusted deflection (m)' not in b.info.columns): + try: + contact._run(hooke, inqueue, outqueue, params) + except PoorFit, e: + raise PoorFit('Could not fit %s %s: %s' + % (curve.path, block, str(e))) + if ('deflection (N)' not in b.info.columns): + force._run(hooke, inqueue, outqueue, params) return curve class SurfacePositionModel (ModelFitter):