コード例 #1
0
ファイル: Hy-Isosurface.py プロジェクト: qyzeng/IsoNetwork
def GetRealWF(n,l,m,isovalue):
    wf = WF(r(x,y,z),theta(x,y,z),phi(x,y,z),n,l,m)
    realwf = numpy.real (wf)*10
    #realwf = numpy.fabs(numpy.real(wf)*10)
    realwf[numpy.isnan(realwf)]=0
    f_isovalue = isovalue*numpy.max(realwf)*0.2
    verts1, faces1 = pg.isosurface(realwf,f_isovalue)
    verts2, faces2 = pg.isosurface(realwf,-f_isovalue)
    verts0 = numpy.vstack ((verts1,verts2))
    faces20 = faces2+int(verts1.size/3)
    faces = numpy.vstack ((faces1,faces20))
    verts = verts0*2*50/(65-1)-(50,50,50)
    phases = CalculatePhase(verts)
    return verts, faces, phases
コード例 #2
0
ファイル: client-GUI.py プロジェクト: qyzeng/IsoNetwork
def GetRealWF(n,l,m,isovalue,Nx,Dn):
    x,y,z = SetGrid(Nx,Dn)
    wf = WF(r(x,y,z),theta(x,y,z),phi(x,y,z),n,l,m)
    realwf = numpy.real (wf)*10
    realwf[numpy.isnan(realwf)]=0
    f_isovalue = isovalue*numpy.max(realwf)*0.2
    verts1, faces1 = pg.isosurface(realwf,f_isovalue)
    verts2, faces2 = pg.isosurface(realwf,-f_isovalue)
    verts0 = numpy.vstack ((verts1,verts2))
    faces20 = faces2+int(verts1.size/3)
    faces = numpy.vstack ((faces1,faces20))
    verts = verts0*2*Dn/(Nx-1)-(Dn,Dn,Dn)
    phases = CalculatePhase(verts,m,l)
    return verts, faces, phases
コード例 #3
0
ファイル: miniplots.py プロジェクト: gsm-matthijs/kMap
    def _get_iso_mesh(self, data, color, sign):

        iso_val = sign * self.options.get_iso_val()
        vertices, faces = isosurface(data, iso_val * data.max())
        nx, ny, nz = data.shape

        # Center Isosurface around Origin
        vertices[:, 0] = vertices[:, 0] - nx / 2
        vertices[:, 1] = vertices[:, 1] - ny / 2
        vertices[:, 2] = vertices[:, 2] - nz / 2

        mesh_data = MeshData(vertexes=vertices, faces=faces)
        colors = np.zeros((mesh_data.faceCount(), 4), dtype=float)
        # Sets color to Red (RGB, 0 = red, 1 = green, 2 = blue)
        if color == 'red':
            colors[:, 0] = 1.0
            colors[:, 1] = 0.2
            colors[:, 2] = 0.2

        elif color == 'blue':
            colors[:, 0] = 0.2
            colors[:, 1] = 0.2
            colors[:, 2] = 1.0
        # Transparency (I guess)
        colors[:, 3] = 1
        mesh_data.setFaceColors(colors)

        mesh = GLMeshItem(meshdata=mesh_data,
                          smooth=True,
                          shader='edgeHilight')
        mesh.setGLOptions('translucent')

        return mesh
コード例 #4
0
    def renderVolume(self):
        import pyqtgraph.opengl as pgl
        import scipy.ndimage as ndi
        self.glView = pgl.GLViewWidget()
        img = np.ascontiguousarray(self.displayAtlas[::8, ::8, ::8])

        # render volume
        #vol = np.empty(img.shape + (4,), dtype='ubyte')
        #vol[:] = img[..., None]
        #vol = np.ascontiguousarray(vol.transpose(1, 2, 0, 3))
        #vi = pgl.GLVolumeItem(vol)
        #self.glView.addItem(vi)
        #vi.translate(-vol.shape[0]/2., -vol.shape[1]/2., -vol.shape[2]/2.)

        verts, faces = pg.isosurface(
            ndi.gaussian_filter(img.astype('float32'), (2, 2, 2)), 5.0)
        md = pgl.MeshData(vertexes=verts, faces=faces)
        mesh = pgl.GLMeshItem(meshdata=md,
                              smooth=True,
                              color=[0.5, 0.5, 0.5, 0.2],
                              shader='balloon')
        mesh.setGLOptions('additive')
        mesh.translate(-img.shape[0] / 2., -img.shape[1] / 2.,
                       -img.shape[2] / 2.)
        self.glView.addItem(mesh)

        self.glView.show()
コード例 #5
0
def vis3D_glassBrain(brain_array, pad, ds_factor):

    # initialize the window
    view = pgl.GLViewWidget()

    # downsample the brain image using the ds_factor
    img = brain_array[::ds_factor, ::ds_factor, ::ds_factor]

    # do padding of the brain to avoid holes during rendering
    pad_img = np.zeros(
        (img.shape[0] + pad, img.shape[1] + pad, img.shape[2] + pad),
        dtype=img.dtype)
    pad_img[pad / 2:pad / 2 + img.shape[0], pad / 2:pad / 2 + img.shape[1],
            pad / 2:pad / 2 + img.shape[2]] = img

    # build the brain isosurface
    verts, faces = pg.isosurface(
        ndi.gaussian_filter(pad_img.astype('float32'), (1, 1, 1)), 5.0)
    md = pgl.MeshData(vertexes=verts, faces=faces)
    mesh = pgl.GLMeshItem(meshdata=md,
                          smooth=True,
                          color=[0.5, 0.5, 0.5, 0.1],
                          shader='balloon')
    mesh.setGLOptions('additive')
    mesh.translate(-pad_img.shape[0] * (ds_factor / 2.),
                   -pad_img.shape[1] * (ds_factor / 2.),
                   -pad_img.shape[2] * (ds_factor / 2.))
    mesh.scale(ds_factor, ds_factor, ds_factor)
    mesh.rotate(-90, 1, 0, 0)
    view.addItem(mesh)
    view.setCameraPosition(distance=200, elevation=20, azimuth=90)
    view.setWindowTitle('Consciousness is an illusion')
    view.show()

    return view
コード例 #6
0
ファイル: miniplots.py プロジェクト: gsm-matthijs/kMap
    def _get_iso_mesh(self,
                      data,
                      iso=None,
                      color=(1, 0.2, 0.2, 1),
                      z_shift=True):

        if iso is None:
            iso_val = self.options.get_iso_val() * data.max()
        else:
            iso_val = iso

        vertices, faces = isosurface(data, iso_val)
        nx, ny, nz = data.shape

        # Center Isosurface around Origin
        vertices[:, 0] = vertices[:, 0] - nx / 2
        vertices[:, 1] = vertices[:, 1] - ny / 2
        if z_shift:
            vertices[:, 2] = vertices[:, 2] - nz / 2

        mesh_data = MeshData(vertexes=vertices, faces=faces)
        colors = np.zeros((mesh_data.faceCount(), 4), dtype=float)
        for idx in range(4):
            colors[:, idx] = color[idx]

        mesh_data.setFaceColors(colors)

        mesh = GLMeshItem(meshdata=mesh_data,
                          smooth=True,
                          shader='edgeHilight')
        mesh.setGLOptions('translucent')

        return mesh
コード例 #7
0
ファイル: Hy-Isosurface.py プロジェクト: qyzeng/IsoNetwork
def GetAbsWF(n,l,m,isovalue):
    abswf = absWF(r(x,y,z),theta(x,y,z),phi(x,y,z),n,l,m)
    abswf[numpy.isnan(abswf)]=0
    f_isovalue = isovalue*numpy.max(abswf)*0.2
    verts0, faces = pg.isosurface(abswf,f_isovalue)
    verts = verts0*2*50/(65-1)-(50,50,50)
    phases = CalculatePhase(verts)
    return verts, faces, phases
コード例 #8
0
ファイル: client-GUI.py プロジェクト: qyzeng/IsoNetwork
def GetAbsWF(n,l,m,isovalue,Nx,Dn):
    x,y,z = SetGrid(Nx,Dn)
    abswf = absWF(r(x,y,z),theta(x,y,z),phi(x,y,z),n,l,m)
    abswf[numpy.isnan(abswf)]=0
    f_isovalue = isovalue*numpy.max(abswf)*0.2
    verts0, faces = pg.isosurface(abswf,f_isovalue)
    verts = verts0*2*Dn/(Nx-1)-(Dn,Dn,Dn)
    phases = CalculatePhase(verts,m,l)
    return verts, faces, phases
コード例 #9
0
    def __init__(self, data, lvl = 0.1):
        from pyqtgraph.Qt import QtCore, QtGui
        import pyqtgraph as pg
        import pyqtgraph.opengl as gl

        app = QtGui.QApplication([])
        w = gl.GLViewWidget()
        w.show()
        w.setWindowTitle('crystal unit cell')

        w.setCameraPosition(distance=data.shape[0])

        #g = gl.GLGridItem()
        #g.scale(2,2,2)
        #w.addItem(g)
        gx = gl.GLGridItem()
        gx.rotate(90, 0, 1, 0)
        gx.scale(data.shape[0]/20.,data.shape[1]/20.,data.shape[2]/20.)
        gx.translate(-data.shape[0]/2, 0, 0)
        w.addItem(gx)
        gy = gl.GLGridItem()
        gy.rotate(90, 1, 0, 0)
        gy.scale(data.shape[0]/20.,data.shape[1]/20.,data.shape[2]/20.)
        gy.translate(0, -data.shape[1]/2, 0)
        w.addItem(gy)
        gz = gl.GLGridItem()
        gz.scale(data.shape[0]/20.,data.shape[1]/20.,data.shape[2]/20.)
        gz.translate(0, 0, -data.shape[1]/2)
        w.addItem(gz)
        
        import numpy as np
        
        print("Generating isosurface..")
        verts, faces = pg.isosurface(data, data.max()*lvl)
        
        md = gl.MeshData(vertexes=verts, faces=faces)
        
        colors = np.ones((md.faceCount(), 4), dtype=float)
        colors[:,3] = 0.2
        colors[:,2] = np.linspace(0, 1, colors.shape[0])
        md.setFaceColors(colors)
        #m1 = gl.GLMeshItem(meshdata=md, smooth=False, shader='balloon')
        #m1.setGLOptions('additive')

        #w.addItem(m1)
        #m1.translate(-data.shape[0]/2, -data.shape[1]/2, -data.shape[2]/2)

        m2 = gl.GLMeshItem(meshdata=md, smooth=True, shader='balloon')
        m2.setGLOptions('additive')

        w.addItem(m2)
        m2.translate(-data.shape[0]/2, -data.shape[1]/2, -data.shape[2]/2)
        app.exec_()
コード例 #10
0
 def __init__(self, h):
     self.h = h
     scfield, idfield, transform = self.h.make_volume_data()
     #scfield = scipy.ndimage.gaussian_filter(scfield, (0.5, 0.5, 0.5))
     #pg.image(scfield)
     verts, faces = pg.isosurface(scfield, level=0.0)
     self.verts = verts
     self.faces = faces
     vertexColors = np.empty((verts.shape[0], 4), dtype=float)
     md = gl.MeshData(vertexes=verts, faces=faces)
     
     # match vertexes to section IDs
     vox_locations = verts.astype(int)
     # get sction IDs for each vertex
     self.vertex_sec_ids = idfield[vox_locations[:,0], vox_locations[:,1], vox_locations[:,2]] 
     
     super(HocSurface, self).__init__(meshdata=md, smooth=True, shader='balloon')
     self.setTransform(transform)
     self.setGLOptions('additive')
コード例 #11
0
    def update():
        global R, I, prob, i
        print(i, prob.max())
        R, I, prob = step(R, I, V, spin, dx, dt, axes)
        if i % plotevery == 0:
            verts, faces = pg.isosurface(prob, prob.max() / level)
            md = gl.MeshData(vertexes=verts, faces=faces)
            colors = np.ones((md.faceCount(), 4), dtype=float)
            colors[:, 3] = 0.2
            colors[:, 2] = np.linspace(1, 1, 1)
            md.setFaceColors(colors)
            m1.setMeshData(meshdata=md)
            m1.meshDataChanged()

            s.setData(z=prob[:][:][sl] / prob.max())
            # Exporting
            if EXPORT:
                w.grabFrameBuffer().save('frames2/frame' + str(i) + '.png')
        i += 1
コード例 #12
0
def fermiSurf(latPts=(0, 0, 0)):
    m = 90
    scl = 0.011256637

    ## Define a scalar field from which we will generate an isosurface
    def psi(i, j, k, offset=(0, 0, 0)):

        x = (i - offset[0]) * 2 * np.pi / 50
        y = (j - offset[1]) * 2 * np.pi / 50
        z = (k - offset[2]) * 2 * np.pi / 50
        a = 5.14e-10
        e = 1.60218e-19
        Ry = 13.6
        me = 9.10938E-31  #kg
        hbar = 1.05459E-34  #
        fineStruct = 0.0072973525664
        ro = ((me * e * e) / (hbar * hbar) *
              np.linalg.norm(np.array([0.25, 0.25, 0.25])))
        bondE_coupling = np.array(2 * (1 + ro) * np.exp(-ro))
        alpha = 1.6

        ps= -alpha - 4*bondE_coupling*( np.cos(0.5*x)*np.cos(0.5*y) \
         + np.cos(0.5*z)*np.cos(0.5*y) \
         + np.cos(0.5*z)*np.cos(0.5*x) )

        return ps

    data = np.fromfunction(psi, (m, m, m))
    verts, faces = pg.isosurface(data, data.max() / 4.)
    md = gl.MeshData(vertexes=verts, faces=faces)
    colors = np.ones((md.faceCount(), 4), dtype=float)
    colors[:, 3] = 0.6
    colors[:, 2] = 0  #np.linspace(0, 1, colors.shape[0])
    colors[:, 1] = 0.270588
    colors[:, 0] = 0.7
    md.setFaceColors(colors)
    m1 = gl.GLMeshItem(meshdata=md, smooth=False, shader='balloon')
    m1.setGLOptions('additive')
    m1.scale(scl, scl, scl)

    return m1
コード例 #13
0
ファイル: viewer.py プロジェクト: campagnola/ccfviewer
    def renderVolume(self):
        import pyqtgraph.opengl as pgl
        import scipy.ndimage as ndi
        self.glView = pgl.GLViewWidget()
        img = np.ascontiguousarray(self.displayAtlas[::8,::8,::8])
        
        # render volume
        #vol = np.empty(img.shape + (4,), dtype='ubyte')
        #vol[:] = img[..., None]
        #vol = np.ascontiguousarray(vol.transpose(1, 2, 0, 3))
        #vi = pgl.GLVolumeItem(vol)
        #self.glView.addItem(vi)
        #vi.translate(-vol.shape[0]/2., -vol.shape[1]/2., -vol.shape[2]/2.)
        
        verts, faces = pg.isosurface(ndi.gaussian_filter(img.astype('float32'), (2, 2, 2)), 5.0)
        md = pgl.MeshData(vertexes=verts, faces=faces)
        mesh = pgl.GLMeshItem(meshdata=md, smooth=True, color=[0.5, 0.5, 0.5, 0.2], shader='balloon')
        mesh.setGLOptions('additive')
        mesh.translate(-img.shape[0]/2., -img.shape[1]/2., -img.shape[2]/2.)
        self.glView.addItem(mesh)

        self.glView.show()
コード例 #14
0
def vis3D_structureMask(view, mask, maskCol, ds_factor):

    # downsample the brain image using the ds_factor
    img = mask[::ds_factor, ::ds_factor, ::ds_factor]

    # build the brain isosurface
    verts, faces = pg.isosurface(
        ndi.gaussian_filter(img.astype('float32'), (0.5, 0.5, 0.5)), .5)
    md = pgl.MeshData(vertexes=verts, faces=faces)
    meshMask = pgl.GLMeshItem(meshdata=md,
                              smooth=True,
                              color=[maskCol[0], maskCol[1], maskCol[2], 0.2],
                              shader='balloon')
    meshMask.setGLOptions('additive')
    meshMask.translate(-img.shape[0] / 2., -img.shape[1] / 2.,
                       -img.shape[2] / 2.)
    meshMask.scale(ds_factor, ds_factor, ds_factor)
    meshMask.rotate(-90, 1, 0, 0)
    view.addItem(meshMask)
    view.setCameraPosition(distance=200, elevation=20, azimuth=90)
    view.show()

    return view
コード例 #15
0
ファイル: Hydrogen0.py プロジェクト: qyzeng/IsoNetwork
    w[numpy.isnan(w)]=0
    #wf[numpy.isnan(wf)]=0

    phase = numpy.array(w)
    xsize = w.size/w[0].size
    ysize = w[0].size/w[0][0].size
    zsize = w[0][0].size
    for i in range(0,xsize):
        for j in range(0,ysize):
            for k in range(0,zsize):
                phase[i][j][k] = complexphi(wf[i][j][k].real,wf[i][j][k].imag)
    phase[numpy.isnan(phase)]=0
    return w,phase
isovalue = 0.45
absw,wphase = GetWaveFunction(4,2,1,x,y,z)
verts0, faces = pg.isosurface(absw,isovalue)#the verts are depending on ogrid index nor ogrid value

isophase = linterp3d(wphase,verts0)

verts = verts0*2-(50,50,50)
N_vertices = int(verts.size/3)
N_triangles = int(faces.size/3)
N_isophase = int (isophase.size)

import socket
import sys
import random
import time
import math
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 51111)
コード例 #16
0
    def __init__(self, w, orbital, grid=True, photon={}, isoval=1 / 6):

        data = orbital.psi['data']
        dx, dy, dz = orbital.psi['dx'], orbital.psi['dy'], orbital.psi['dz']
        nx, ny, nz = data.shape
        bonds = orbital.get_bonds()

        if grid:  # display grid in (x,y)-plane
            g = gl.GLGridItem()
            g.scale(1 / dx, 1 / dy, 1 / dz)
            w.addItem(g)

        items = []  # initialize list of plot items for later rotation

        # add coordinate axes object
        ax = gl.GLAxisItem()
        ax.setSize(10, 10, 10)
        items.append(ax)
        w.addItem(ax)

        # add bonds as LinePlotItems
        for bond in bonds:
            line = gl.GLLinePlotItem(pos=bond,
                                     color=(0.8, 0.8, 0.8, 1),
                                     width=5,
                                     antialias=True)
            items.append(line)
            w.addItem(line)

        # compute isosurface for positive and negative isovalues
        isovals = [+isoval * data.max(), -isoval * data.max()]
        colors = [(1, 0.2, 0.2), (0.2, 0.2, 1)]  # red and blue

        for iso, color in zip(isovals, colors):
            # compute isosurface and center around origin
            verts, faces = pg.isosurface(data, iso)
            verts[:, 0] = verts[:, 0] - nx / 2
            verts[:, 1] = verts[:, 1] - ny / 2
            verts[:, 2] = verts[:, 2] - nz / 2

            isosurface = gl.MeshData(vertexes=verts, faces=faces)
            rgbt = np.zeros((isosurface.faceCount(), 4), dtype=float)
            for c in range(3):
                rgbt[:, c] = color[c]
            rgbt[:, 3] = 1  # transparency (I guess)
            isosurface.setFaceColors(rgbt)

            p = gl.GLMeshItem(
                meshdata=isosurface, smooth=True, shader='edgeHilight'
            )  # shader options: 'balloon', 'shaded', 'normalColor', 'edgeHilight'
            p.setGLOptions(
                'translucent'
            )  # choose between 'opaque', 'translucent' or 'additive'
            w.addItem(p)

            items.append(p)

        if 'polarization' in photon:  # display incident photon
            alpha = photon['alpha'] * np.pi / 180
            beta = (180 + photon['beta']) * np.pi / 180
            direction = [
                np.sin(alpha) * np.cos(beta),
                np.sin(alpha) * np.sin(beta),
                np.cos(alpha)
            ]
            polarization = photon['polarization']

            ray_length = 50  # length of wavy light ray
            amplitude = 5  # amplitude of oscillation
            wavelength = 5  # wavelength of oscillation
            n_points = 200  # number of points along wavy light ray

            x0 = np.linspace(0, ray_length * direction[0], n_points)
            y0 = np.linspace(0, ray_length * direction[1], n_points)
            z0 = np.linspace(0, ray_length * direction[2], n_points)
            t = np.linspace(0, ray_length, n_points)

            if polarization == 's':
                pol_1 = [np.sin(beta), -np.cos(beta), 0]
                pol_2 = [0, 0, 0]

            elif polarization == 'p':
                pol_1 = [0, 0, 0]
                pol_2 = [
                    np.cos(alpha) * np.cos(beta),
                    np.cos(alpha) * np.sin(beta), -np.sin(alpha)
                ]

            elif polarization == 'C+':
                pol_1 = [np.sin(beta), -np.cos(beta), 0]
                pol_2 = [
                    np.cos(alpha) * np.cos(beta),
                    np.cos(alpha) * np.sin(beta), -np.sin(alpha)
                ]

            elif polarization == 'C-':
                pol_1 = [np.sin(beta), -np.cos(beta), 0]
                pol_2 = [
                    -np.cos(alpha) * np.cos(beta),
                    -np.cos(alpha) * np.sin(beta), +np.sin(alpha)
                ]

            elif polarization == 'CDAD':  # show C+ spiral ... until I have a better idea ...
                pol_1 = [np.sin(beta), -np.cos(beta), 0]
                pol_2 = [
                    np.cos(alpha) * np.cos(beta),
                    np.cos(alpha) * np.sin(beta), -np.sin(alpha)
                ]

            dx = amplitude * pol_1[0] * np.cos(
                2 * np.pi * t / wavelength) + amplitude * pol_2[0] * np.sin(
                    2 * np.pi * t / wavelength)
            dy = amplitude * pol_1[1] * np.cos(
                2 * np.pi * t / wavelength) + amplitude * pol_2[1] * np.sin(
                    2 * np.pi * t / wavelength)
            dz = amplitude * pol_1[2] * np.cos(
                2 * np.pi * t / wavelength) + amplitude * pol_2[2] * np.sin(
                    2 * np.pi * t / wavelength)

            pos = np.array([x0 + dx, y0 + dy, z0 + dz]).T

            photon_line = gl.GLLinePlotItem(pos=pos,
                                            color=(1, 1, 0.0, 1),
                                            width=5,
                                            antialias=True)
            photon_line.setGLOptions('translucent')
            w.addItem(photon_line)

        self.items = items
        self.phi = 0
        self.theta = 0
        self.psi = 0

        return
コード例 #17
0
    EXPORT = True

    # Qt Setup
    app = QtGui.QApplication([])
    w = gl.GLViewWidget()
    w.show()
    w.setWindowTitle('pyqtgraph example: GLIsosurface')

    w.setCameraPosition(azimuth=0, distance=30)

    g = gl.GLGridItem()
    g.scale(0.5, 0.5, 1)
    w.addItem(g)

    # Plot a the wavefunction isosurface
    verts, faces = pg.isosurface(prob, prob.max() / level)
    md = gl.MeshData(vertexes=verts, faces=faces)
    colors = np.ones((md.faceCount(), 4), dtype=float)
    colors[:, 3] = 0.2
    colors[:, 2] = np.linspace(1, 1, 1)
    md.setFaceColors(colors)

    m1 = gl.GLMeshItem(meshdata=md, smooth=True, shader='balloon')
    m1.setGLOptions('additive')
    w.addItem(m1)
    m1.translate(-L / (2 * dx), -L / (2 * dx), -L / (2 * dx))

    #Plot the potential sphere
    verts, faces = pg.isosurface(V, V.max())
    md = gl.MeshData(vertexes=verts, faces=faces)
    colors = np.ones((md.faceCount(), 4), dtype=float)
コード例 #18
0
ファイル: Hydrogen.py プロジェクト: qyzeng/IsoNetwork
    #            #else:
    #            #    phase[i][j][k] = angular
    #            phase[i][j][k] = numpy.arctan2(wf[i][j][k].imag,wf[i][j][k].real)
    phase[numpy.isnan(phase)]=0
    realwf[numpy.isnan(realwf)]=0
    return w,phase, realwf
a0=1
n=5
l=4
m=4
absw,wphase,realwf = GetWaveFunction(n,l,m,x,y,z)
isovalue = 0.5
f_isovalue = isovalue*numpy.max(absw)*0.2# need to select a proper value
#f_isovalue = isovalue*numpy.mean(absw)*0.01
#verts0, faces = pg.isosurface(absw,isovalue)#the verts are depending on ogrid index nor ogrid value
verts0, faces = pg.isosurface(absw,f_isovalue)
#isophase = linterp3d(wphase,verts0)

xx=numpy.linspace(0,100,101)
yy=numpy.linspace(0,100,101)
zz=numpy.linspace(0,100,101)
from scipy.interpolate import RegularGridInterpolator
from scipy.interpolate import interpn
#isophase = interpn((xx,yy,zz),wphase,verts0,method = 'linear')
inter_function = RegularGridInterpolator((xx,yy,zz),wphase)
isophase = inter_function(verts0)

# do not use the interpolation, recalculate the phase based on verts
verts = verts0-(50,50,50)
iso_phase0 = [None]*int(verts.size/3)
コード例 #19
0
    #        for k in range(0,zsize):
    #            #angular = numpy.arctan2(wf[i][j][k].imag,wf[i][j][k].real)
    #            #if angular < 0:
    #            #    phase[i][j][k] = angular+2*numpy.pi
    #            #else:
    #            #    phase[i][j][k] = angular
    #            phase[i][j][k] = numpy.arctan2(wf[i][j][k].imag,wf[i][j][k].real)
    phase[numpy.isnan(phase)]=0
    realwf[numpy.isnan(realwf)]=0
    return w,phase, realwf
absw,wphase,realwf = GetWaveFunction(5,4,4,x,y,z)
isovalue = 0.5
#f_isovalue = #isovalue*0.0000001# need to select a proper value
f_isovalue = isovalue*numpy.max(realwf)*0.2
#verts0, faces = pg.isosurface(absw,f_isovalue)#the verts are depending on ogrid index nor ogrid value
verts0, faces = pg.isosurface(realwf,f_isovalue)
verts1, facesm = pg.isosurface(realwf,-f_isovalue)
#verts0, faces = pg.isosurface(absw,f_isovalue)
#isophase0 = linterp3d(wphase,verts0)

xx=numpy.linspace(0,50,51)
yy=numpy.linspace(0,50,51)
zz=numpy.linspace(0,50,51)
from scipy.interpolate import griddata
from scipy.interpolate import RegularGridInterpolator
from scipy.interpolate import interpn
#inter_function = griddata((xx,yy,zz),wphase)
#isophase = griddata((xx,yy,zz),wphase,verts0,method='linear')
#inter_function = RegularGridInterpolator((xx,yy,zz),wphase)
isophase = interpn((xx,yy,zz),wphase,verts0,method = 'linear')#both RegularGridInterpolator and interpn can do the interpolation
isophasem = interpn((xx,yy,zz),wphase,verts1,method = 'linear')
コード例 #20
0
    r = (x**2 + y**2 + z**2)**0.5
    a0 = 1
    #ps = (1./81.) * (2./np.pi)**0.5 * (1./a0)**(3/2) * (6 - r/a0) * (r/a0) * np.exp(-r/(3*a0)) * np.cos(th)
    ps = (1. / 81.) * 1. / (6. * np.pi)**0.5 * (1. / a0)**(3 / 2) * (
        r / a0)**2 * np.exp(-r / (3 * a0)) * (3 * np.cos(th)**2 - 1)

    return ps

    #return ((1./81.) * (1./np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * (r/a0) * np.exp(-r/(3*a0)) * np.sin(th) * np.cos(th) * np.exp(2 * 1j * phi))**2


print("Generating scalar field..")
data = np.abs(np.fromfunction(psi, (50, 50, 100)))

print("Generating isosurface..")
verts, faces = pg.isosurface(data, data.max() / 4.)

md = gl.MeshData(vertexes=verts, faces=faces)

colors = np.ones((md.faceCount(), 4), dtype=float)
colors[:, 3] = 0.2
colors[:, 2] = np.linspace(0, 1, colors.shape[0])
md.setFaceColors(colors)
m1 = gl.GLMeshItem(meshdata=md, smooth=False, shader='balloon')
m1.setGLOptions('additive')

#w.addItem(m1)
m1.translate(-25, -25, -20)

m2 = gl.GLMeshItem(meshdata=md, smooth=True, shader='balloon')
m2.setGLOptions('additive')
コード例 #21
0
ファイル: GLIsosurface.py プロジェクト: fivejjs/pyqtgraph
    r = (x**2 + y**2 + z **2)**0.5
    a0 = 1
    #ps = (1./81.) * (2./np.pi)**0.5 * (1./a0)**(3/2) * (6 - r/a0) * (r/a0) * np.exp(-r/(3*a0)) * np.cos(th)
    ps = (1./81.) * 1./(6.*np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * np.exp(-r/(3*a0)) * (3 * np.cos(th)**2 - 1)
    
    return ps
    
    #return ((1./81.) * (1./np.pi)**0.5 * (1./a0)**(3/2) * (r/a0)**2 * (r/a0) * np.exp(-r/(3*a0)) * np.sin(th) * np.cos(th) * np.exp(2 * 1j * phi))**2 


print("Generating scalar field..")
data = np.abs(np.fromfunction(psi, (50,50,100)))


print("Generating isosurface..")
verts, faces = pg.isosurface(data, data.max()/4.)

md = gl.MeshData(vertexes=verts, faces=faces)

colors = np.ones((md.faceCount(), 4), dtype=float)
colors[:,3] = 0.2
colors[:,2] = np.linspace(0, 1, colors.shape[0])
md.setFaceColors(colors)
m1 = gl.GLMeshItem(meshdata=md, smooth=False, shader='balloon')
m1.setGLOptions('additive')

#w.addItem(m1)
m1.translate(-25, -25, -20)

m2 = gl.GLMeshItem(meshdata=md, smooth=True, shader='balloon')
m2.setGLOptions('additive')
コード例 #22
0
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph.opengl as pgl
import scipy.ndimage as ndi
import numpy as np

pg.mkQApp()


view = pgl.GLViewWidget()

atlas = metaarray.MetaArray(file='ccf.ma', readAllData=True)

img = np.ascontiguousarray(atlas.asarray()[::8,::8,::8])

# render volume
#vol = np.empty(img.shape + (4,), dtype='ubyte')
#vol[:] = img[..., None]
#vol = np.ascontiguousarray(vol.transpose(1, 2, 0, 3))
#vi = pgl.GLVolumeItem(vol)
#self.glView.addItem(vi)
#vi.translate(-vol.shape[0]/2., -vol.shape[1]/2., -vol.shape[2]/2.)

verts, faces = pg.isosurface(ndi.gaussian_filter(img.astype('float32'), (2, 2, 2)), 5.0)
md = pgl.MeshData(vertexes=verts, faces=faces)
mesh = pgl.GLMeshItem(meshdata=md, smooth=True, color=[0.5, 0.5, 0.5, 0.2], shader='balloon')
mesh.setGLOptions('additive')
mesh.translate(-img.shape[0]/2., -img.shape[1]/2., -img.shape[2]/2.)
view.addItem(mesh)

view.show()
コード例 #23
0
ファイル: demo_3D-FT.py プロジェクト: brands-d/kMap
g.setSize(x=8, y=8, z=8)
g.scale(1 / dx, 1 / dy, 1 / dz)
w.addItem(g)

# add coordinate axes object
#ax = gl.GLAxisItem()
#ax.setSize(5,5,5)
#w.addItem(ax)

# compute isosurface for positive and negative isovalues
isovals = [+0.2 * data.max(), -0.2 * data.max()]
colors = [(1, 0.2, 0.2), (0.2, 0.2, 1)]

for isoval, color in zip(isovals, colors):
    # compute vertices and faces and center around origin
    verts, faces = pg.isosurface(data, isoval)
    verts[:, 0] = verts[:, 0] - nx / 2
    verts[:, 1] = verts[:, 1] - ny / 2
    verts[:, 2] = verts[:, 2] - nz / 2

    isosurface = gl.MeshData(vertexes=verts, faces=faces)
    rgbt = np.zeros((isosurface.faceCount(), 4), dtype=float)
    for c in range(3):
        rgbt[:, c] = color[c]
    rgbt[:, 3] = 1  # transparency (I guess)
    isosurface.setFaceColors(rgbt)

    p = gl.GLMeshItem(
        meshdata=isosurface, smooth=True, shader='edgeHilight'
    )  # shader options: 'balloon', 'shaded', 'normalColor', 'edgeHilight'
    p.setGLOptions(
コード例 #24
0
ファイル: qt.py プロジェクト: PanosEconomou/CPFP
    Y /= 100
    Z -= 50
    Z /= 100
    r = np.array([0, 0, 0])
    s = 1**0.5
    A = 1

    return A * np.exp(-((X - r[0])**2 + (Y - r[1])**2 + (Z - r[2])**2) /
                      (s**2))


print("Generating scalar field..")
data = np.abs(np.fromfunction(normal, (100, 100, 100)))
print(data)
print("Generating isosurface..")
verts, faces = pg.isosurface(data, data.max() / 1.0005)

md = gl.MeshData(vertexes=verts, faces=faces)

colors = np.ones((md.faceCount(), 4), dtype=float)
colors[:, 3] = 0.2
colors[:, 2] = np.linspace(0, 1, colors.shape[0])
md.setFaceColors(colors)

m2 = gl.GLMeshItem(meshdata=md, smooth=True, shader='balloon')
m2.setGLOptions('additive')

w.addItem(m2)
m2.translate(-50, -50, -50)

## Start Qt event loop unless running in interactive mode.