예제 #1
0
def runanalysis():
    filename = ourgui.openFile(type='npz')

    data = np.load(filename, mmap_mode='r')
    X = data['X']
    Y = data['Y']
    BX = data['BX']
    BY = data['BY']
    BZ = data['BZ']
    pitch = data['pitch']
    windnum = data['windnum']

    phi = np.linspace(0, np.pi*2, 100)

    pl.figure(figsize=(11.69, 8.27), dpi=100)

    BXBZ = np.zeros(BZ.shape)
    BYBZ = np.zeros(BZ.shape)
    for i in xrange(BZ.shape[0]):
        for j in xrange(BZ.shape[1]):
            if abs(BZ[i, j]) > 1e-14:
                BXBZ[i, j] = BX[i, j] / BZ[i, j]
                BYBZ[i, j] = BY[i, j] / BZ[i, j]

    
    pl.subplot(2, 2, 1, aspect='equal')
    pl.title("Pitch = %g, wind number = %d" %(pitch, windnum))
    pl.plot(np.cos(phi), np.sin(phi), linewidth=3)
    CS = pl.contour(X, Y, BXBZ*100, colors='k')
    pl.clabel(CS, inline=1, fontsize=10, fmt='%.1f%%')
    pl.xlabel("Bx / Bz")

    pl.subplot(2, 2, 2, aspect='equal')
    pl.plot(np.cos(phi), np.sin(phi), linewidth=3)
    CS = pl.contour(X, Y, BYBZ*100, colors='k')
    pl.clabel(CS, inline=1, fontsize=10, fmt='%.1f%%')
    pl.xlabel("By / Bz")

    pl.subplot(2, 2, 3, aspect='equal')
    pl.plot(np.cos(phi), np.sin(phi), linewidth=3)
    CS = pl.contour(X, Y, BZ / BZ.max()*100, 10, colors='k')
    pl.clabel(CS, inline=1, fontsize=10, fmt='%.1f%%')
    pl.xlabel("Bz (normalized)")

    pl.subplot(2, 2, 4, aspect='equal')
    FIELD = np.sqrt(BX**2 + BY**2 + BZ**2)
    pl.plot(np.cos(phi), np.sin(phi), linewidth=3)
    CS = pl.contour(X, Y, FIELD, colors='k')
    pl.clabel(CS, inline=1, fontsize=10)
    pl.xlabel("Total field strength")

    # import matplotlib.cm as cm
    # im = pl.imshow(FIELD, interpolation='bilinear', origin='lower',
    #                 cmap=cm.gray, extent=(-1,1,-1,1))
    # pl.plot(np.cos(phi), np.sin(phi), linewidth=3)
    # CS = pl.contour(X, Y, np.sqrt(BX**2 + BY**2 + BZ**2))
    pl.show()
예제 #2
0
def runanalysis():
    filename = ourgui.openFile(type="npz")

    data = np.load(filename, mmap_mode="r")
    Y = data["Y"]
    Z = data["Z"]
    BY = data["BY"]
    BZ = data["BZ"]
    coilpos = getdata(data, "coilpos")
    coilwidth = getdata(data, "coilwidth")
    nturns = getdata(data, "nturns")
    coilsize = getdata(data, "coilsize")

    infopiece = []
    if coilpos:
        infopiece += ['Cpos: %g"' % coilpos]
    if coilwidth:
        infopiece += ['Cwidth: %g"' % coilwidth]
    if coilsize:
        infopiece += ['Csize: %g"' % coilsize]
    if nturns:
        infopiece += ["Turns: %d" % nturns]
    infotitle = ", ".join(infopiece)

    fig = pl.figure(figsize=(11.69, 8.27), dpi=100)
    fig.text(0.4, 0.95, infotitle)

    pl.subplot(2, 2, 1)
    pl.quiver(Z, Y, BZ, BY)
    pl.xlabel("Z")
    pl.ylabel("Y")
    pl.title("Magnetic field direction")

    pl.subplot(2, 2, 2)
    CS = pl.contour(Z, Y, BY / BZ)
    pl.xlabel("Z")
    pl.ylabel("Y")
    pl.title("Y-strength/Z-strength")
    pl.clabel(CS, inline=1, fontsize=10)

    pl.subplot(2, 2, 3)
    zpos = Z[:, 0]
    zfield = BZ[:, 0] / BZ[0, 0]
    pl.plot(zpos, zfield)
    pl.xlabel("Z position")
    pl.ylabel("On axis field strength")

    pl.subplot(2, 2, 4)
    fieldstrength = np.sqrt(BY ** 2 + BZ ** 2)
    CS = pl.contour(Z, Y, fieldstrength)
    pl.xlabel("Z")
    pl.ylabel("Y")
    pl.title("Field strength", fontsize=10)
    pl.clabel(CS, inline=1, fontsize=10)

    pl.show()
예제 #3
0
from numpy import *
from pylab import *
from ourgui import openFile
from sys import exit
filename = openFile(type='log')
if not filename:
    sys.exit(1)

# SetF, X, Y, BeatF 
f, x, y, b = loadtxt(filename, comments='#', delimiter=',', unpack=True)

# Check how many repetitions are there
n = 0
for res in f:
    if res == f[0]:
        n += 1
    else:
        break

points = len(f) / n;
repeats = n

## Do the averaging
xa, xe = [], []
ya, ye = [], []
ba, be = [], []
favgs = []
for i in xrange(0, points):
    try:
        ## Xaverage, Xerror
        xa.append(average(x[i*repeats:(i+1)*repeats]))
예제 #4
0
from numpy import loadtxt
from pylab import plot, show, subplot, xlabel, ylabel
from ourgui import openFile

def quickplot(filename):
    data = loadtxt(filename, skiprows=1)
    t = data[0:-1,0] - data[0,0]
    v = data[0:-1,1]
    plot(t,v,'.')
    xlabel('time (s)')
    ylabel('resistance (Ohm)')
    show()

filename = openFile("log")
if filename:
    quickplot(filename)
예제 #5
0
import numpy as np
import scipy as sp
import pylab as pl
import sys
sys.path.append('../../lablib')
import ourgui

filename = ourgui.openFile()
meas = np.loadtxt(filename, comments='#')
n = len(meas)
rate = 20000.0
totalt = n / rate
t = np.linspace(0, totalt, n)

pl.subplot(211)
pl.plot(t, meas)

dt = t[1]-t[0]
freq = np.fft.fftfreq(t.shape[-1], d=dt)
print max(freq)
sp = np.fft.fft(meas)
spmag = np.sqrt(sp.real**2 + sp.imag**2)
spmag = spmag[freq >= 0]
freq = freq[freq >= 0]
print spmag
pl.subplot(212)
pl.semilogy(freq, spmag)
pl.xlim([0, 6250])

out = zip(freq, spmag)
np.save(filename+'.fft', out)
예제 #6
0
        infopiece += ["Turns: %d" % nturns]
    infotitle = ", ".join(infopiece)

    fig = pl.figure(1, figsize=(11.69, 8.27), dpi=100)
    # pl.subplot(2,2,3)
    pl.title("Bz-field as function of position and %s" %(vary))
    zpos = Z[:, 0]
    zfield = BZ[:,0]/BZ[0,0]
    pl.plot(zpos, zfield, label="%g" %(getdata(data, vary)))
    pl.xlabel('Z position')
    pl.ylabel('On axis field strength')
    pl.legend(loc='best')
    return (max(abs(zfield - 1)), getdata(data, vary))

if __name__ == "__main__":
    logname = ourgui.openFile(type="log")
    logged = np.loadtxt(logname,
                        delimiter=",",
                        comments="#",
                        dtype={'names': ('filename', 'coilpos', 'coilwidth', 'coilsize', 'nturns'),
                               'formats': ('a40', 'f4', 'f4', 'f4', 'i4')}
                        )
    
    best = 1e14
    bestval = None
    for log in logged:
        maxdev, maxval = runanalysis("%s.npz" %log['filename'])
        if maxdev < best:
            best = maxdev
            bestval = maxval
            bestsetting = log['filename']
예제 #7
0
from __future__ import division
import matplotlib
matplotlib.rcParams['backend'] = 'wx'
import matplotlib.pylab as pl
import numpy as np
import scipy.optimize as op

import ourgui

if __name__ == "__main__":
    filename = ourgui.openFile("log")
    data = np.loadtxt(filename, delimiter=",", comments="#")

    f = data[:, 0]
    amp = np.abs(data[:, 1])
    ampr = amp / amp[0]
    ampdb = 20 * np.log10(ampr)

    phase = data[:, 3]
    phase = np.array([p if p < 0 else p-np.pi for p in phase])/np.pi * 180
    phase = phase - phase[0]
    
    pl.subplot(211)
    pl.semilogx(f, ampdb, 'k-')
    pl.semilogx(f, np.zeros(len(f))-3, 'r--', label='-3dB line')
    pl.xlabel("Frequency (Hz)")
    pl.ylabel("Amplitude (dB)")
    pl.title("PZT transfer function")
    pl.legend(loc='best')

    pl.subplot(212)
예제 #8
0
import numpy as np
import numpy.random as random
import pylab as pl
import scipy.odr as odr
from sys import exit
import layeroptimize as layer

import ourgui

filename = ourgui.openFile('npz')
if not filename:
    exit(0)
basefile = filename.split('/')[-1]
# filename = "layers_110830_153517.npz"

data = np.load(filename)
newsetup = data['setup'][()]
# zl, ideal = zip(*data['ideal'])
# print zl, ideal
zl = data['ideal'][0]
ideal = data['ideal'][1]
d0 = data['d0']

# print data['setup']
# print newsetup['layer']
# print data.files

zeropos = 31
zz = np.append(np.linspace(-0.3, 0.01, zeropos), np.linspace(0, 1.1, 201))
curr = layer.bideal(0)/layer.fieldcalc(zz, newsetup, d=d0)[zeropos]
print 'Current = %.2f A' %(curr)
예제 #9
0
import numpy as np
import scipy as sp
import pylab as pl
import sys
sys.path.append('../../lablib')
import ourgui


fftfile = ourgui.openFile()
sigfile = ourgui.openFile()


fftdata = np.load(fftfile)
sigdata = np.loadtxt(sigfile, delimiter=',')

freq = fftdata[:, 0]
spmag = np.log(fftdata[:, 1])

freqs = sigdata[:,0]
mags = sigdata[:,1]


pl.plot(freq, spmag-70)
pl.plot(freqs, mags)

pl.xlim([0, 6250])

pl.show()