In [1]:
%%javascript
IPython.load_extensions('calico-document-tools');
In [1]:
!date
In [2]:
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
import pyqtgraph as pg
import numpy as np
To do
In [ ]:
help(pg.opengl.GLLinePlotItem)
help(pg.opengl.GLGridItem)
help(pg.QtGui.QGraphicsRectItem)
In [13]:
image_shape = (4,4)
uniform_values = np.ones(image_shape) * 255
uniform_image = pg.makeARGB(uniform_values)
print uniform_values
print uniform_image
In [1]:
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
import pyqtgraph as pg
import numpy as np
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.opts['distance'] = 200
w.show()
w.setWindowTitle('pyqtgraph example: GLImageItem')
## create volume data set to slice three images from
shape = (100,100,70)
data = np.random.normal(size=shape)
#data += pg.gaussianFilter(np.random.normal(size=shape), (15,15,15))*15
## slice out three planes, convert to RGBA for OpenGL texture
levels = (-0.08, 0.08)
tex1 = pg.makeRGBA(data[shape[0]/2], levels=levels)[0] # yz plane
tex2 = pg.makeRGBA(data[:,shape[1]/2], levels=levels)[0] # xz plane
tex3 = pg.makeRGBA(data[:,:,shape[2]/2], levels=levels)[0] # xy plane
#tex1[:,:,3] = 128
tex2[:,:,3] = 128
#tex3[:,:,3] = 128
## Create three image items from textures, add to view
v1 = gl.GLImageItem(tex1)
v1.translate(-shape[1]/2, -shape[2]/2, 0)
v1.rotate(90, 0,0,1)
v1.rotate(-90, 0,1,0)
#w.addItem(v1)
v2 = gl.GLImageItem(tex1)
v2.translate(-shape[0]/2, -shape[2]/2, 0)
v2.rotate(-90, 1,0,0)
w.addItem(v2)
v3 = gl.GLImageItem(tex3)
v3.translate(-shape[0]/2, -shape[1]/2, 0)
#w.addItem(v3)
ax = gl.GLAxisItem()
w.addItem(ax)
## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
In [4]:
print shape[0], shape[1], shape[2]
In [10]:
print len(data[shape[0]/2]), len(data[:,shape[1]/2])
In [11]:
shape = (5,4,3)
data = np.random.normal(size=shape)
print data
In [12]:
print data[shape[0]/2]
In [13]:
print data[:,shape[1]/2]
In [14]:
print data[:,:,shape[2]/2]
In [20]:
tex = pg.makeRGBA(data[shape[2]/2])[0]
print tex
In [4]:
image_shape = (3,5)
uniform_values = np.ones(image_shape) * 255
uniform_image = pg.makeARGB(uniform_values)[0]
uniform_image[:,:,3] = 128
print uniform_image
In [1]:
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
import pyqtgraph as pg
import numpy as np
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.opts['distance'] = 20
w.show()
w.setWindowTitle('pyqtgraph example: GLImageItem')
## create volume data set to slice three images from
shape = (100,100,70)
data = np.random.normal(size=shape)
#data += pg.gaussianFilter(np.random.normal(size=shape), (15,15,15))*15
## make images
image_shape = (6,6)
uniform_values = np.ones(image_shape) * 255
uniform_image = pg.makeARGB(uniform_values)[0]
uniform_image[:,:,1] = 128
uniform_image_transparent = pg.makeARGB(uniform_values)[0]
uniform_image_transparent[:,:,3] = 128
## Create image items from textures, add to view
v2 = gl.GLImageItem(uniform_image)
v2.translate(-image_shape[0]/2, -image_shape[1]/2, 0)
v2.rotate(90, 1,0,0)
v2.translate(0, -2, 0)
w.addItem(v2)
v1 = gl.GLImageItem(uniform_image_transparent)
v1.translate(-image_shape[0]/2, -image_shape[1]/2, 0)
v1.rotate(90, 1,0,0)
w.addItem(v1)
ax = gl.GLAxisItem()
w.addItem(ax)
## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
In [6]:
x = np.linspace(0,2,3)
y = np.linspace(10,12,3)
z = np.linspace(20,22,3)
print x, '\n', y, '\n', z, '\n'
pts = np.vstack([x,y,z])
print pts, '\n'
pts = pts.transpose()
print pts
Answer: take row vectors x, y, & z and concatenate them as column vectors in a 2D matrix
In [8]:
x = np.linspace(0,3,4)
y = np.linspace(10,13,4)
z = np.linspace(20,23,4)
#print x, '\n', y, '\n', z, '\n'
pts = np.vstack([x,y,z])
#print pts, '\n'
pts = pts.transpose()
print pts
print pts.shape
In [15]:
pts2 = np.zeros(shape=(2*pts.shape[0], pts.shape[1]))
print pts2
print pts2.shape
for i in range(pts.shape[0]):
pts2[2*i,2] = pts[i,2]
pts2[2*i + 1,:] = pts[i,:]
print pts2
In [18]:
# Function to create new array from old
# where new array is formatted to prepare to
# draw lines perpendicular from z-axis to
# curve defined by input array
def preptomakelines(pts):
pts2 = np.zeros(shape=(2*pts.shape[0], pts.shape[1]))
for i in range(pts.shape[0]):
pts2[2*i,2] = pts[i,2]
pts2[2*i + 1,:] = pts[i,:]
return pts2
pts2 = preptomakelines(pts)
print pts, '\n\n', pts2
We want to go from calculation coordinates (x,y,z) to pyqtgraph coordinates (xx,yy,zz). For the electric field the transformation is:
This is the same as rotate -90 degrees about the y axis, then rotate 90 degrees about the z-axis. For the magnetic field the transformation is:
In [25]:
x = np.linspace(0,3,4)
y = np.linspace(10,13,4)
z = np.linspace(20,23,4)
pts = np.vstack([x,y,z])
pts = pts.transpose()
print pts
temp2Darray = [[0, 0, 1],
[1, 0, 0],
[0, 1, 0]]
rot_efield_coord = np.array(temp2Darray)
print rot_efield_coord
pts_efield_coord = np.dot(pts, rot_efield_coord)
print pts_efield_coord
temp2Darray = [[1, 0, 0],
[0, 0, 1],
[0, 1, 0]]
rot_hfield_coord = np.array(temp2Darray)
print rot_hfield_coord
pts_hfield_coord = np.dot(pts, rot_hfield_coord)
print pts_hfield_coord
In [26]:
print pts
pts = np.dot(pts, rot_efield_coord)
print pts
In [ ]: