<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Table of Contents
Objective
Step1:  Objective
Step2:  Figure out what makeARGB is doing
Step3:  Make a semi-transparent rectangle (image)
Step4:  What is np.vstack.transpose() doing?
Step5:  Answer
Step6:  Simple coordinate transformation
We want to go from calculation coordinates (x,y,z) to pyqtgraph coordinates (xx,yy,zz). For the electric field the transformation is
<ASSISTANT_TASK:>
Python Code:
%%javascript
IPython.load_extensions('calico-document-tools');
!date
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
import pyqtgraph as pg
import numpy as np
Explanation: Table of Contents
Objective: propagating plane wave visualization
How to get docstrings for a class definition
Figure out what makeARGB is doing
Make a semi-transparent rectangle (image)
What is np.vstack.transpose() doing?
Make vertical lines
Simple coordinate transformation
End of explanation
help(pg.opengl.GLLinePlotItem)
help(pg.opengl.GLGridItem)
help(pg.QtGui.QGraphicsRectItem)
Explanation: Objective: propagating plane wave visualization
To do
- DONE 2/27/15 - Propagating e-field
  - TRIED 2/27/15, ARROWS DON'T SEEM TO WORK IN 3D, JUST 2D. include some propagating arrows
- DONE 2/27/15 - propagating h-field
- TRIED 2/27/15, DOESN'T LOOK GOOD - semi-transparent plane in x-y through which plane wave propagates
- DONE 2/27/15 - Add more visible axes
- DONE 2/27/15 - What is np.vstack doing?
- TRIED 2/25/15, NO FACILITY TO DO THIS - Fill to zero?
- DONE 2/28/15 - If not, make my own vertical lines to zero?
- TRIED 2/28/15, NO DOCUMENTATION INDICATING HOW TO DO THIS - Add labels (E, H, z)
- DONE 2/28/15, DOESN'T LOOK GREAT IF NOT LINEAR POLARIZATION - Change efield function to set arbitrary polarization state
- Add ability to change propagation velocity
How to get docstrings for a class definition
End of explanation
image_shape = (4,4)
uniform_values = np.ones(image_shape) * 255
uniform_image = pg.makeARGB(uniform_values)
print uniform_values
print uniform_image
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_()
print shape[0], shape[1], shape[2]
print len(data[shape[0]/2]), len(data[:,shape[1]/2])
shape = (5,4,3)
data = np.random.normal(size=shape)
print data
print data[shape[0]/2]
print data[:,shape[1]/2]
print data[:,:,shape[2]/2]
tex = pg.makeRGBA(data[shape[2]/2])[0]
print tex
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
Explanation: Figure out what makeARGB is doing
End of explanation
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_()
Explanation: Make a semi-transparent rectangle (image)
End of explanation
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
Explanation: What is np.vstack.transpose() doing?
End of explanation
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
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
# 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
Explanation: Answer: take row vectors x, y, & z and concatenate them as column vectors in a 2D matrix 
Make vertical lines
End of explanation
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
print pts
pts = np.dot(pts, rot_efield_coord)
print pts
Explanation: Simple coordinate transformation
We want to go from calculation coordinates (x,y,z) to pyqtgraph coordinates (xx,yy,zz). For the electric field the transformation is:
x -> zz
y -> xx
z -> yy
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:
x -> xx
y -> zz
z -> yy
End of explanation
<END_TASK>