Ejemplo n.º 1
0
def showSolution3D(S, start, goal):
    from vtkplotter import Text, Cube, Line, Grid, mergeActors, show

    pts, cubes, txts = [], [], []
    pts = [(x, -y) for y, x in S[0]]
    for y, line in enumerate(Z):
        for x, c in enumerate(line):
            if c: cubes.append(Cube([x, -y, 0]))

    path = Line(pts).lw(6).c('tomato')
    walls = mergeActors(cubes).clean().texture('metal2')

    sy, sx = S[1].shape
    gradient = np.flip(S[1], axis=0).ravel()
    grd = Grid(pos=((sx - 1) / 2, -(sy - 1) / 2, -0.49),
               sx=sx,
               sy=sy,
               resx=sx,
               resy=sy)
    grd.wireframe(False).cellColors(gradient, cmap='gist_earth_r')
    grd.addScalarBar(title='Gradient', horizontal=True)

    txts.append(Text(__doc__, c='k'))
    txts.append(Text('Start', pos=[start[1] - 1, -start[0] + 1.5, 1], c='k'))
    txts.append(Text('Goal!', pos=[goal[1] - 2, -goal[0] - 2.7, 1], c='k'))
    show(path, walls, grd, txts, bg='white', axes=0, zoom=1.2)
Ejemplo n.º 2
0
plot += boundary.flag()

#Microseismic
microseismicxyz = microseismic[['xloc', 'yloc', 'zloc']]
scals = microseismic[['mw']]
microseismicPts = Points(microseismicxyz.values, r=3).cellColors(scals,
                                                                 cmap="jet")
microseismicPts.name = 'Microseismic events'
plot += microseismicPts.flag()

####################
## 4. Line objects
####################
#The path of well 58_32
xyz = well_5832_path[['X', 'Y', 'Z']].values
Well = Line(xyz)
Well.name = 'Well 58-32'
plot += Well.flag()

#A porosity log in the well
xyz = nphi_well[['X', 'Y', 'Z']].values
porosity = nphi_well['Nphi'].values
Well = Line(xyz).c('gold').lw(2)
Well.name = 'Porosity log well 58-32'
plot += Well.flag()

#This well data is actually represented by points since as of right now,
#since the k3d embedding does not support colors on the lines, and I wanted to show the colors
xyz = pressure_well[['X', 'Y', 'Z']].values
pressure = pressure_well['Pressure'].values
Well = Points(xyz, r=1).pointColors(pressure, cmap="cool")
Ejemplo n.º 3
0
import numpy as np

tol = 0.001  # avoid hitting points outside the domain
y = np.linspace(-1 + tol, 1 - tol, 101)
points = [(0, y_) for y_ in y]  # 2D points
w_line = np.array([w(point) for point in points])
p_line = np.array([p(point) for point in points])

#######################################################################
from vtkplotter.dolfin import plot
from vtkplotter import Line, Latex

pde = r'-T \nabla^{2} D=p, ~\Omega=\left\{(x, y) | x^{2}+y^{2} \leq R\right\}'
tex = Latex(pde, pos=(0, 1.1, .1), s=0.2, c='w')

wline = Line(y, w_line * 10, c='white', lw=4)
pline = Line(y, p_line / 4, c='lightgreen', lw=4)

plot(w, wline, tex, at=0, N=2, bg='bb', text='Deflection')
plot(p, pline, at=1, text='Load')

#######################################################################
#import matplotlib.pyplot as plt
#plot(w)
#plt.plot(y, 50*w_line, 'k', linewidth=2)  # magnify w
#plt.plot(y, p_line, 'b--', linewidth=2)
#plt.grid(True)
#plt.xlabel('$y$')
#plt.legend(['Deflection ($\\times 50$)', 'Load'], loc='upper left')
#plt.show()
Ejemplo n.º 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, bg=(0.95, 0.95, 1))
vp.xtitle = ""
vp.ytitle = "Psi^2(x,t)"
vp.ztitle = ""

bck = vp.load(datadir+"images/schrod.png", alpha=0.3).scale(0.0255).pos([0, -5, -0.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)
Ejemplo n.º 5
0
plt += top_granitoid_vertices.flag()

printc("plotting...", invert=1)

# Microseismic
microseismicxyz = microseismic[["xloc", "yloc", "zloc"]].values
scals = microseismic[["mw"]]
microseismicPts = Points(microseismicxyz, r=5).pointColors(scals, cmap="jet")
microseismicPts.name = "Microseismic events"
plt += microseismicPts.flag()

# FORGE Boundary. Since the boundary area did not have a Z column,
# I assigned a Z value for where I wanted it to appear
border["zcoord"] = 1650
borderxyz = border[["xcoord", "ycoord", "zcoord"]]
boundary = Line(borderxyz.values).extrude(zshift=120,
                                          cap=False).lw(0).texture('wood1')
boundary.name = "FORGE area boundary"
plt += boundary.flag()

# The path of well 58_32
Well1 = Line(well_5832_path[["X", "Y", "Z"]].values, lw=2, c='k')
Well1.name = "Well 58-32"
plt += Well1.flag()

# A porosity log in the well
xyz = nphi_well[["X", "Y", "Z"]].values
porosity = nphi_well["Nphi"].values
Well2 = Line(xyz, lw=3).pointColors(porosity, cmap="hot")
Well2.name = "Porosity log well 58-32"
plt += Well2.flag()
Ejemplo n.º 6
0
import numpy as np

dt = 0.002
y = (25.0, -10.0, -7.0)  # Starting point (initial condition)
pts, cols = [], []

for t in np.linspace(0, 20, int(20 / dt)):
    # Integrate a funny differential equation
    dydt = np.array([
        -8 / 3.0 * y[0] + y[1] * y[2], -10.0 * (y[1] - y[2]),
        -y[1] * y[0] + 28.0 * y[1] - y[2]
    ])
    y = y + dydt * dt

    c = np.clip([np.linalg.norm(dydt) * 0.005], 0, 1)[0]  # color by speed
    cols.append([c, 0, 1 - c])
    pts.append(y)

from vtkplotter import Plotter, Line, Point, Points, settings
settings.renderPointsAsSpheres = False  # render points as squares

scene = Plotter(title="Lorenz attractor", axes=1, verbose=0, bg="w")
scene += Point(y, r=10, c="g")  # end point
scene += Points(pts, r=3, c=cols)
scene += Line(pts).off().addShadow(x=3)  # only show shadow, not line
scene += Line(pts).off().addShadow(z=-30)
scene.show(viewup='z')
Ejemplo n.º 7
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.setPoint(i, x+[0,0, psi2/norm]) # elevate grid in z

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

vp.add(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='w', alpha=.1)) # add some annotation
vp.add(Line([0,0,0], [0,0,-D], c='w', alpha=.1))
vp.add(Text('source plane', pos=[-.05,-.053,0], s=.002, c='gray'))
vp.add(Text('detector plane D = '+str(D)+' m', pos=[-.05,-.053,-D], s=.002, c='gray'))
vp.add(Text(__doc__, c='gray'))

vp.show(zoom=1.1)


Ejemplo n.º 8
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, bg=(0.95, 0.95, 1))
vp.xtitle = ""
vp.ytitle = "Psi^2(x,t)"
vp.ztitle = ""

bck = vp.load(datadir + "images/schrod.png",
              alpha=0.3).scale(0.0255).pos([0, -5, -0.1])
barrier = Line(np.stack((x, V * 15, [0] * len(x)), axis=1), 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 = np.stack((x, A, [0] * len(x)), axis=1)
    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.actors = []  # clean up internal list of objects to show
vp.camera.Elevation(20)
vp.camera.Azimuth(20)
Ejemplo n.º 9
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 += Line(cell.pos, newc.pos, c="k", lw=3, alpha=0.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=0.80)   # nucleus
        vp += Points(pts, c=colony.color, r=15, alpha=0.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]
Ejemplo n.º 10
0
    X, Y, Z = np.meshgrid(ls, ls, ls)
    P = np.c_[X.ravel(), Y.ravel(), Z.ravel()]
    D = scipy.spatial.distance.cdist(P, P)

    som = SOM((len(P), 3), D)

    samples = P

    som.learn(samples, n_epoch=7000, sigma=(0.5, 0.01), lrate=(0.5, 0.01))

    # Draw network
    x, y, z = [som.codebook[:, i].reshape(n, n, n) for i in range(3)]

    from vtkplotter import Points, Line, show
    Points(samples, c="lb", alpha=0.2)
    for k in [0, 8, 15]:

        for i in range(n):
            ptjs = []
            for j in range(n):
                ptjs.append((x[i, j, k], y[i, j, k], z[i, j, k]))
            Line(ptjs)  # create line through a serie of 3d points

        for j in range(n):
            ptjs = []
            for i in range(n):
                ptjs.append((x[i, j, k], y[i, j, k], z[i, j, k]))
            Line(ptjs)

    show(..., axes=8)
Ejemplo n.º 11
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=0.5))
                newcells.append(newc)
            newcells.append(cell)
        colony.cells = newcells

        pts = [c.pos for c in newcells]  # draw all points at once
        vp.add(Points(pts, c=colony.color, r=5, alpha=0.80))  # nucleus
        vp.add(Points(pts, c=colony.color, r=15, alpha=0.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]
Ejemplo n.º 12
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, size=(1000, 500))
vp.xtitle = ""
vp.ytitle = "Psi^2(x,t)"
vp.ztitle = ""

bck = vp.load(datadir + "images/schrod.png").scale(0.015).pos([0, 0, -0.5])
barrier = Line(np.stack((x, V * 15), axis=1), 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 = np.stack((x, A, np.zeros_like(x)), axis=1)
    Aline = Tube(coords, c="db", r=0.08)
    vp.show(Aline, barrier, bck, zoom=2)
    lines.append(Aline)

interactive()
Ejemplo n.º 13
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.add(Points(pts, c=colony.color, r=5, alpha=.80))  # nucleus
        vp.add(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]
# Microseismic
microseismicxyz = microseismic[["xloc", "yloc", "zloc"]]
scals = microseismic[["mw"]]
microseismicPts = Points(microseismicxyz.values, r=4).pointColors(scals, cmap="jet")
microseismicPts.name = "Microseismic events"
plt += microseismicPts.flag()

####################
## 4. Line objects
####################
# FORGE Boundary. Since the boundary area did not have a Z column,
# I assigned a Z value for where I wanted it to appear
border["zcoord"] = 1650
borderxyz = border[["xcoord", "ycoord", "zcoord"]]
boundary = Line(borderxyz.values).extrude(zshift=120, cap=False).c("k")
boundary.name = "FORGE area boundary"
plt += boundary.flag()

# The path of well 58_32
xyz = well_5832_path[["X", "Y", "Z"]].values
Well = Line(xyz)
Well.name = "Well 58-32"
plt += Well.flag()

# A porosity log in the well
xyz = nphi_well[["X", "Y", "Z"]].values
porosity = nphi_well["Nphi"].values
Well = Line(xyz).pointColors(porosity, cmap="hot").c("gold").lw(2)
Well.name = "Porosity log well 58-32"
plt += Well.flag()
Ejemplo n.º 15
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(bg="white", interactive=0, axes=2, verbose=0)
vp.xtitle = ""
vp.ytitle = "Psi^2(x,t)"
vp.ztitle = ""

bck = vp.load(datadir + "images/schrod.png").scale(0.012).pos([0, 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=0.08)
    vp.show(Aline, barrier, bck)
    lines.append(Aline)

vp.show(interactive=1)
Ejemplo n.º 16
0
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 actor.info['radius'].
'''
from __future__ import division, print_function
from vtkplotter import Plotter, fitSphere, histogram, Points, Line, Text

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.add(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.add(Text(__doc__))
vp.show(viewup='z')
Ejemplo n.º 17
0
    return 1j*(nabla2psi - V*psi) # this is the RH of Schroedinger equation!

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(bg='white', 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)