From: W. Trevor King Date: Tue, 24 Jan 2012 13:08:42 +0000 (-0500) Subject: Assorted plots and bug-fixes in unfolder.py. X-Git-Tag: v0.2~20 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ab30952d8a2ff9eaaaccc5a4e0d23944e2b61ea1;p=unfold-protein.git Assorted plots and bug-fixes in unfolder.py. * Updated `ExceptionTooFar` plot and `Unfolder._plot` to use `FIGURE` and `_pyplot`. * Fix configs used in `Unfolder._unfold`'s bit/meter conversions. * Remove unrecognized keyword `dtype` from the `.astype` call. * Reshape `out` so it is 2D (as required by `Piezo.ramp`). * Don't force unfold log values to be integers. * Fix filename generation in `Unfolder._save`. * Removed trailing whitespace. --- diff --git a/unfold_protein/unfolder.py b/unfold_protein/unfolder.py index fb289dc..874faf6 100755 --- a/unfold_protein/unfolder.py +++ b/unfold_protein/unfolder.py @@ -110,16 +110,17 @@ class Unfolder (object): '(def {} < target {})').format( data['deflection'].max(), setpoint_bits)) self.afm.piezo.jump(self.afm.axis_name, start_pos) - #if PYLAB_INTERACTIVE_VERBOSE == True: - # figure(BASE_FIG_NUM+1) - # hold(False) - # plot_dict(data, 'Approach') - # hold(True) - # title('Unfolding too far') + if _package_config['matplotlib']: + print data + FIGURE.clear() + axes = FIGURE.add_subplot(1, 1, 1) + axes.plot(data['z'], data['deflection'], label='Approach') + axes.set_title('Unfolding too far') + _pyplot.show() _LOG.debug('raising ExceptionTooFar') raise ExceptionTooFar return data - + def _bind(self): """Wait on the surface while the protein binds.""" time = self.config['bind time'] @@ -132,21 +133,33 @@ class Unfolder (object): velocity = config['velocity'] _LOG.info('unfold at {:g} m/s'.format(velocity)) axis = self.afm.piezo.axis_by_name(self.afm.axis_name) - d = self.afm.piezo.channel_by_name('deflection') + axis_config = self.afm.piezo.config.select_config( + 'axes', self.afm.axis_name, + get_attribute=_pypiezo_base.get_axis_name + ) + d = self.afm.piezo.channel_by_name('deflection') + def_config = self.afm.piezo.config.select_config( + 'inputs', 'deflection') start_pos = self.afm.piezo.last_output[self.afm.axis_name] - start_pos_m = _pypiezo_base.convert_bits_to_meters(axis, start_pos) - final_pos_m = bind_pos_m - config['distance'] - final_pos = _pypiezo_base.convert_meters_to_bits(axis, final_pos_m) - dtype = afm.piezo.channel_dtype(self.afm.axis_name, direction='output') + + start_pos_m = _pypiezo_base.convert_bits_to_meters( + axis_config, start_pos) + final_pos_m = start_pos_m - config['distance'] + final_pos = _pypiezo_base.convert_meters_to_bits( + axis_config, final_pos_m) + dtype = self.afm.piezo.channel_dtype( + self.afm.axis_name, direction='output') num_steps = int( config['distance'] / config['velocity'] * config['frequency']) + 1 # (m) * (s/m) * (samples/s) out = _numpy.linspace( - start_pos, final_pos, num_steps).astype(dtype=dtype) + start_pos, final_pos, num_steps).astype(dtype) + # TODO: check size of output buffer. + out = out.reshape((len(out), 1)) _LOG.debug( - 'unfolding from {:d} to {:d} in {:d} steps at {:g} Hz'.format( + 'unfolding from {} to {} in {} steps at {} Hz'.format( start_pos, final_pos, num_steps, config['frequency'])) - data = afm.piezo.ramp( + data = self.afm.piezo.ramp( data=out, frequency=config['frequency'], output_names=[self.afm.axis_name], input_names=['deflection']) return {self.afm.axis_name:out, 'deflection':data} @@ -156,8 +169,8 @@ class Unfolder (object): time_tuple = _email_utils.parsedate(timestamp) filename = _os_path.join( config['base directory'], - '{0}-{1:02d}-{2:02d}_{3:02d}-{4:02d}-{5:02d}.h5'.format( - time_tuple)) + '{0}-{1:02d}-{2:02d}T{3:02d}-{4:02d}-{5:02d}.h5'.format( + *time_tuple)) _LOG.info('saving {}'.format(filename)) with _h5py.File(filename, 'a') as f: storage = _HDF5_Storage() @@ -172,19 +185,17 @@ class Unfolder (object): def _plot(self, temperature, approach, unfold, timestamp): "Plot the unfolding cycle" - if not _matplotlib: + if not _pyplot: raise _matplotlib_import_error FIGURE.clear() - # TODO... - #if PYLAB_INTERACTIVE_VERBOSE == True: - # figure(BASE_FIG_NUM) - # hold(False) - # plot_dict(approach_data, 'Approach') - # hold(True) - # plot_dict(out['data'], 'Unfold') - # legend(loc='best') - # title('Unfolding') - # draw() + axes = FIGURE.add_subplot(1, 1, 1) + axes.hold(True) + axes.plot(approach['z'], approach['deflection'], label='Approach') + axes.plot(unfold['z'], unfold['deflection'], label='Unfold') + axes.set_title('Unfolding too far') + axes.legend(loc='best') + axes.set_title('Unfolding') + _pyplot.show() def zero_piezo(self): _LOG.info('zero piezo')