From 4aa57de1a6c6876cb214575b46d3ccaa649089dd Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 21 Dec 2008 00:12:00 -0500 Subject: [PATCH] Apply some fixes to get calibrations working and bump version. Mostly namespace problems due to `from numpy import *` and the like. Things seem to work now. I think we're ready for prime-time. --- calibcant/T_analyze.py | 6 ++--- calibcant/analyze.py | 4 ++- calibcant/calibrate.py | 54 +++++++++++++++++++++------------------- calibcant/common.py | 2 +- calibcant/vib_analyze.py | 4 +-- 5 files changed, 38 insertions(+), 32 deletions(-) diff --git a/calibcant/T_analyze.py b/calibcant/T_analyze.py index d52475d..00804cd 100755 --- a/calibcant/T_analyze.py +++ b/calibcant/T_analyze.py @@ -72,8 +72,8 @@ def T_save(T, log_dir=None) : log = data_logger.data_log(log_dir, noclobber_logsubdir=False, log_name="T_float") log.write_binary(T.tostring()) - if LOG_DATA != None : - log = data_logger.data_log(LOG_DIR, noclobber_logsubdir=False, + if config.LOG_DATA != None : + log = data_logger.data_log(config.LOG_DIR, noclobber_logsubdir=False, log_name="T_float") log.write_binary(T.tostring()) @@ -94,7 +94,7 @@ def T_plot(T, plotVerbose=False) : """ Umm, just print the temperature? """ - if plotVerbose or PYLAB_VERBOSE or TEXT_VERBOSE : + if plotVerbose or config.PYLAB_VERBOSE or config.TEXT_VERBOSE : print "Temperature ", T @splittableKwargsFunction((T_analyze, 'T', 'convert_to_K'), diff --git a/calibcant/analyze.py b/calibcant/analyze.py index 2e535ef..7fafc04 100755 --- a/calibcant/analyze.py +++ b/calibcant/analyze.py @@ -49,6 +49,8 @@ Which are related by the parameters : import numpy from splittable_kwargs import splittableKwargsFunction, \ make_splittable_kwargs_function +import data_logger + import common # common module for the calibcant package import config # config module for the calibcant package import T_analyze # T_analyze module for the calibcant package @@ -173,7 +175,7 @@ def calib_save_analysis(k, k_s, @splittableKwargsFunction() def calib_plot(bumps, Ts, vibs, plotVerbose=False) : if plotVerbose or config.PYLAB_VERBOSE : - common.import_pylab() + common._import_pylab() common._pylab.figure(config.BASE_FIGNUM+4) common._pylab.subplot(311) common._pylab.plot(bumps, 'g.') diff --git a/calibcant/calibrate.py b/calibcant/calibrate.py index 64ac942..2cfff35 100644 --- a/calibcant/calibrate.py +++ b/calibcant/calibrate.py @@ -84,6 +84,7 @@ import time import z_piezo_utils from splittable_kwargs import splittableKwargsFunction, \ make_splittable_kwargs_function +import FFT_tools import common import config @@ -109,9 +110,9 @@ def bump_aquire(zpiezo, push_depth=200, npoints=1024, freq=100e3) : start_pos = zpiezo.curPos() pos_dist = zpiezo.pos_nm2out(push_depth) - zpiezo.pos_nm2out(0) close_pos = start_pos + pos_dist - appr = linspace(start_pos, close_pos, npoints) - retr = linspace(close_pos, start_pos, npoints) - out = concatenate((appr, retr)) + appr = numpy.linspace(start_pos, close_pos, npoints) + retr = numpy.linspace(close_pos, start_pos, npoints) + out = numpy.concatenate((appr, retr)) # run the bump, and measure deflection if config.TEXT_VERBOSE : print "Bump %g nm" % push_depth @@ -162,8 +163,8 @@ def T(**kwargs): T._splitargs(T, kwargs) T_raw = T_aquire(**T_aquire_kwargs) T_analyze.T_save(T_raw, **T_save_kwargs) - T_ret = T_analyze.T_analyze(T_raw, **T_analyze_kwargs) - return T_ret + T_ret = T_analyze.T_analyze(T_raw, **T_analyze_kwargs) # returns array + return T_ret[0] # vib family @@ -173,14 +174,14 @@ def vib_aquire(zpiezo, time=1, freq=50e3) : Record data for TIME seconds at FREQ Hz from ZPIEZO at it's current position. """ # round up to the nearest power of two, for efficient FFT-ing - nsamps = ceil_pow_of_two(time*freq) + nsamps = FFT_tools.ceil_pow_of_two(time*freq) time = nsamps / freq # take some data, keeping the position voltage at it's current value - out = ones((nsamps,), dtype=uint16) * zpiezo.curPos() + out = numpy.ones((nsamps,), dtype=numpy.uint16) * zpiezo.curPos() if config.TEXT_VERBOSE : print "get %g seconds of data" % time data = zpiezo.ramp(out, freq) - data['sample frequency Hz'] = freq + data['sample frequency Hz'] = numpy.array([freq]) return data @splittableKwargsFunction(vib_aquire, @@ -192,11 +193,12 @@ def vib(**kwargs) : """ vib_aquire_kwargs,vib_save_kwargs,vib_analyze_kwargs = \ vib._splitargs(vib, kwargs) - data = vib_aquire(freq=freq, **vib_aquire_kwargs) + data = vib_aquire(**vib_aquire_kwargs) vib_analyze.vib_save(data, **vib_save_kwargs) freq = data['sample frequency Hz'] - Vphoto_var = vib_analyze.vib_analyze(deflection_bits=data, freq=freq, - **vib_analyze_kwargs) + deflection_bits = data['Deflection input'] + Vphoto_var = vib_analyze.vib_analyze(deflection_bits=deflection_bits, + freq=freq, **vib_analyze_kwargs) return Vphoto_var # A few positioning functions, so we can run bump_aquire() and vib_aquire() @@ -257,8 +259,9 @@ def move_just_onto_surface(stepper, zpiezo, Depth_nm=100, setpoint=2) : print "get surf pos, with setpoint %g (%d)" % (setpoint, zpiezo.def_V2in(setpoint)) for i in range(20) : # HACK, keep stepping back until we get a distance try : - dist = zpiezo.pos_out2nm(getSurfPos(zpiezo, zpiezo.def_V2in(setpoint))) - except (tooClose, poorFit), string : + dist = zpiezo.pos_out2nm( \ + z_piezo_utils.getSurfPos(zpiezo,zpiezo.def_V2in(setpoint))) + except (z_piezo_utils.tooClose, z_piezo_utils.poorFit), string : stepper.step_rel(-200) stepper.step_rel(198) continue @@ -273,12 +276,14 @@ def move_just_onto_surface(stepper, zpiezo, Depth_nm=100, setpoint=2) : while dist < -stepper_tol : # step back if we need to stepper.step_rel(-200) stepper.step_rel(198) - dist = zpiezo.pos_out2nm(getSurfPos(zpiezo, zpiezo.def_V2in(setpoint))) + dist = zpiezo.pos_out2nm( \ + z_piezo_utils.getSurfPos(zpiezo, zpiezo.def_V2in(setpoint))) if config.TEXT_VERBOSE : print 'distance to surface ', dist, ' nm, step back' while dist > stepper_tol : # and step forward if we need to stepper.step_rel(2) - dist = zpiezo.pos_out2nm(getSurfPos(zpiezo, zpiezo.def_V2in(setpoint))) + dist = zpiezo.pos_out2nm( \ + z_piezo_utils.getSurfPos(zpiezo, zpiezo.def_V2in(setpoint))) if config.TEXT_VERBOSE : print 'distance to surface ', dist, ' nm, step closer' # now adjust the zpiezo to place us just onto the surface @@ -310,7 +315,7 @@ def move_far_from_surface(stepper, um_back=50) : (analyze.calib_save, 'bumps','Ts','vibs','log_dir')) def calib_aquire(stepper, zpiezo, num_bumps=10, num_Ts=10, num_vibs=20, bump_freq=100e3, - log_dir=config.LOG_DATA, Vphoto_in2V=config.Vphoto_in2V, + log_dir=config.LOG_DIR, Vphoto_in2V=config.Vphoto_in2V, **kwargs): """ Aquire data for calibrating a cantilever in one function. @@ -334,26 +339,26 @@ def calib_aquire(stepper, zpiezo, num_bumps=10, num_Ts=10, num_vibs=20, calib_aquire._splitargs(calib_aquire, kwargs) # get bumps move_just_onto_surface(stepper, zpiezo, **move_just_onto_surface_kwargs) - bumps=zeros((num_bumps,)) + bumps = numpy.zeros((num_bumps,), dtype=numpy.float) for i in range(num_bumps) : - bumps[i] = bump(zpiezo, freq=bump_freq, log_dir=log_dir, - Vphot_in2V=Vphoto_in2V, **bump_kwargs) + bumps[i] = bump(zpiezo=zpiezo, freq=bump_freq, log_dir=log_dir, + Vphoto_in2V=Vphoto_in2V, **bump_kwargs) if config.TEXT_VERBOSE : print bumps move_far_from_surface(stepper, **move_far_from_surface_kwargs) # get Ts - Ts=zeros((num_Ts,), dtype=float) + Ts = numpy.zeros((num_Ts,), dtype=numpy.float) for i in range(num_Ts) : Ts[i] = T(**T_kwargs) time.sleep(1) # wait a bit to get an independent temperature measure print Ts # get vibs - vibs=zeros((num_vibs,)) + vibs = numpy.zeros((num_vibs,), dtype=numpy.float) for i in range(num_vibs) : - vibs[i] = vib(zpiezo, log_dir=log_dir, Vphoto_in2V=Vphoto_in2V, + vibs[i] = vib(zpiezo=zpiezo, log_dir=log_dir, Vphoto_in2V=Vphoto_in2V, **vib_kwargs) print vibs @@ -365,7 +370,7 @@ def calib_aquire(stepper, zpiezo, num_bumps=10, num_Ts=10, num_vibs=20, @splittableKwargsFunction( \ (calib_aquire, 'log_dir'), (analyze.calib_analyze, 'bumps','Ts','vibs')) -def calib(log_dir=None, **kwargs) : +def calib(log_dir=config.LOG_DIR, **kwargs) : """ Calibrate a cantilever in one function. The I-don't-care-about-the-details black box version :p. @@ -383,8 +388,7 @@ def calib(log_dir=None, **kwargs) : calib._splitargs(calib, kwargs) a, T, vib = calib_aquire(**calib_aquire_kwargs) k,k_s,ps2_m, ps2_s,T_m,T_s,one_o_Vp2_m,one_o_Vp2_s = \ - analyze.calib_analyze(a, T, vib, log_dir=log_dir, - **calib_analyze_kwargs) + analyze.calib_analyze(a, T, vib, **calib_analyze_kwargs) analyze.calib_save_analysis(k, k_s, ps2_m, ps2_s, T_m, T_s, one_o_Vp2_m, one_o_Vp2_s, log_dir) return (k, k_s) diff --git a/calibcant/common.py b/calibcant/common.py index 2db32e1..c58e06b 100644 --- a/calibcant/common.py +++ b/calibcant/common.py @@ -23,7 +23,7 @@ import config -VERSION="0.2" +VERSION="0.3" # handle extra verbose input modules, only imported if we need them _flush_plot = None diff --git a/calibcant/vib_analyze.py b/calibcant/vib_analyze.py index c6bc70f..a98ea05 100755 --- a/calibcant/vib_analyze.py +++ b/calibcant/vib_analyze.py @@ -231,10 +231,10 @@ def fit_psd(freq_axis, psd_data, minFreq=500, maxFreq=7000) : args=(psd_data[imin:imax], freq_axis[imin:imax]), full_output=True, maxfev=10000) - if config.TEXT_VERBOSE : + if config.TEXT_VERBOSE: print "Fitted params:",p print "Covariance mx:",cov - print "Info:", info + #print "Info:", info # too much information :p print "mesg:", mesg if ier == 1 : print "Solution converged" -- 2.26.2