コード例 #1
0
screen = vp.add(grid(pos=[0, 0, -D], sx=0.1, sy=0.1, resx=200, resy=50))
screen.wire(False)  # show it as a solid plane (not as wireframe)

k = 0.0 + 1j * 2 * pi / lambda1  # complex wave number
norm = len(slits) * 5e+5
amplitudes = []

for i, x in enumerate(screen.coordinates()):
    psi = 0
    for s in slits:
        r = mag(x - s)
        psi += exp(k * r) / r
    psi2 = real(psi * conj(psi))  # psi squared
    amplitudes.append(psi2)
    screen.point(i, x + [0, 0, psi2 / norm])  # elevate grid in z

screen.pointColors(amplitudes, cmap='hot')

vp.points(array(slits) * 200, c='w')  # slits scale magnified by factor 200

vp.add(grid(sx=0.1, sy=0.1, resx=6, resy=6,
            c='white/.1'))  # add some annotation
vp.add(line([0, 0, 0], [0, 0, -D], c='white/.1'))
vp.text("source plane", pos=[-.05, -.053, 0], s=.002, c='gray')
vp.text('detector plane D = ' + str(D) + ' m',
        pos=[-.05, -.053, -D],
        s=.002,
        c='gray')

vp.show(zoom=1.1)
コード例 #2
0
def d_dt(psi):  # find Psi(t+dt)-Psi(t) /dt with 4th order Runge-Kutta method
    k1 = f(psi)
    k2 = f(psi + dt / 2 * k1)
    k3 = f(psi + dt / 2 * k2)
    k4 = f(psi + dt * k3)
    return (k1 + 2 * k2 + 2 * k3 + k4) / 6


vp = Plotter(interactive=0, axes=2, verbose=0, bg=(0.95, 0.95, 1))
vp.xtitle = ''
vp.ytitle = 'Psi^2(x,t)'
vp.ztitle = ''

bck = vp.load('data/images/schrod.png',
              alpha=.3).scale(.0255).pos([0, -5, -.1])
barrier = line(list(zip(x, V * 15, [0] * len(x))), c='black', lw=2)

lines = []
for i in range(0, Nsteps):
    for j in range(500):
        Psi += d_dt(Psi) * dt  # integrate for a while before showing things
    A = np.real(Psi * np.conj(Psi)) * 1.5  # psi squared, probability(x)
    coords = list(zip(x, A, [0] * len(x)))
    Aline = line(coords, c='db', lw=3)
    vp.show([Aline, barrier, bck])
    lines.append([Aline, A])  # store objects

# now show the same lines along z representing time
vp.clear()
vp.camera.Elevation(20)
vp.camera.Azimuth(20)
コード例 #3
0
# Blue points are the N points used for fitting.
# Green histogram is the distribution of residuals from the fitting.
# Red histogram is the distribution of the curvatures (1/r**2).
# Fitted radius can be accessed from attribute actor.radius

from __future__ import division, print_function
from vtkplotter import Plotter, fitSphere, histogram, line

vp = Plotter(verbose=0, axes=0)

# load mesh and increase by a lot (N=2) the nr of surface vertices
s = vp.load('data/shapes/cow.vtk').alpha(0.3).subdivide(N=2)

reds, invr = [], []
for i, p in enumerate(s.coordinates()):
    if i%1000: continue           # skip most points
    pts = s.closestPoint(p, N=16) # find the N closest points to p
    sph = fitSphere(pts, alpha=0.05) # find the fitting sphere
    if sph is None: 
    	continue # may fail if all points sit on a plane
    vp.add(sph)
    vp.points(pts)
    vp.add(line(sph.info['center'], p, lw=2))
    reds.append(sph.info['residue'])
    invr.append(1/sph.info['radius']**2)

vp.add(histogram(reds, title='residue', bins=12, c='g', corner=3))
vp.add(histogram(invr, title='1/r**2',  bins=12, c='r', corner=4))

vp.show(viewup='z')
コード例 #4
0

def d_dt(psi):  # find Psi(t+dt)-Psi(t) /dt with 4th order Runge-Kutta method
    k1 = f(psi)
    k2 = f(psi + dt / 2 * k1)
    k3 = f(psi + dt / 2 * k2)
    k4 = f(psi + dt * k3)
    return (k1 + 2 * k2 + 2 * k3 + k4) / 6


vp = Plotter(interactive=0, axes=2, verbose=0)
vp.xtitle = ''
vp.ytitle = 'Psi^2(x,t)'
vp.ztitle = ''

bck = vp.load('data/images/schrod.png').scale(0.012).pos([0, 0, -.5])
barrier = line(list(zip(x, V * 15)), c='dr', lw=3)

lines = []
for j in range(150):
    for i in range(500):
        Psi += d_dt(Psi) * dt  # integrate for a while

    A = np.real(Psi * np.conj(Psi)) * 1.5  # psi squared, probability(x)
    coords = list(zip(x, A, [0] * len(x)))
    Aline = tube(coords, c='db', r=.08)
    vp.show([Aline, barrier, bck])
    lines.append(Aline)

vp.show(interactive=1)
コード例 #5
0
# time goes from 0 to 90 hours 
pb = ProgressBar(0, 50, step=0.1, c=1)
for t in pb.range():
    msg = '[Nb,Ng,Nr,t] = '
    vp.actors = [] # clean up the list of actors

    for colony in colonies:

        newcells = []    
        for cell in colony.cells:

            if cell.dieAt(t): continue
            if cell.divideAt(t): 
                newc = cell.split() # make daughter cell
                vp.add(line(cell.pos, newc.pos, c='k', lw=3, alpha=.5))
                newcells.append(newc)
            newcells.append(cell)
        colony.cells = newcells

        pts = [c.pos for c in newcells] # draw all points at once
        vp.points(pts, c=colony.color, r= 5, alpha=.80) # nucleus
        vp.points(pts, c=colony.color, r=15, alpha=.05) # halo
        msg += str(len(colony.cells)) + ','

    pb.print(msg+str(int(t)))
    vp.show(resetcam=0)

# draw the oriented ellipsoid that contains 50% of the cells
for colony in colonies: 
    pts = [c.pos for c in colony.cells]
コード例 #6
0
from vtkplotter import Plotter, arange, exp, line

c = 2.9979246e+8
k = 1.3806485e-23  # boltzmann constant
h = 6.6260700e-34  # planck constant


def planck(l, T):
    a = 2 * h * c**2
    b = h * c / (l * k * T)
    return a / (l**5 * (exp(b) - 1)) * 1e-13  # Planck formula


vp = Plotter(interactive=0, verbose=0, bg='k', axes=0)
vp.infinity = True  # view from infinity (axes are kept orthogonal)
vp.xtitle = ''
vp.ytitle = 'Intensity'
vp.ztitle = 'Temperature'
vp.load('data/images/light.jpg').scale(.00118).pos([.72, -.11, .14])

wavelengths = arange(400, 700, 10) * 1e-9
intensities = []
for T in range(3000, 9000, 50):
    I = planck(wavelengths, T)
    coords = list(zip(wavelengths * 2e+6, I * 0.02, [T * 5e-5] * len(I)))
    lineact = vp.add(line(coords, lw=4, alpha=.5))
    lineact.pointColors(wavelengths * 2e+6, cmap='jet')
    vp.show(elevation=.1, azimuth=0.1)

vp.show(axes=1, interactive=1)