My PhD research is on clusters of tiny little spheres. I often need to compute things for the spheres in specific configurations. I usually just figure out the coordinates each time. BUT, now I'm posting the most common configurations here, so that I can just look them up here. In python array format. The sphere diameter is assumed to be 1, and the center of each cluster is at the origin.
import numpy as np
single_coords = np.array(
[0,0,0])
dimer_coords = np.array([
[-.5,0,0],
[.5,0,0]])
line_coords = np.array([
[-1.,0,0],
[0,0,0],
[1.,0,0]])
tri_coords = np.array([
[sqrt(3)/6.,-.5,0],
[sqrt(3)/6., .5,0],
[-sqrt(3)/3.,0,0]])
dia_coords = np.array([
[0,-.5,0],
[0,.5,0],
[sqrt(3)/2.,0,0],
[-sqrt(3)/2.,0,0]])
sq_coords = np.array([
[-.5,.5,0],
[-.5,-.5,0],
[.5,.5,0],
[.5,-.5,0]])
tetra_coords = np.array([
[.5/sqrt(3),-.5,-(1/4.0)*sqrt(2/3.0)],
[.5/sqrt(3),.5,-(1/4.0)*sqrt(2/3.0)],
[-1/sqrt(3),0,-(1/4.0)*sqrt(2/3.0)],
[ 0,0,(3/4.0)*sqrt(2/3.0)]])
trap_coords = np.array([
[-1,sqrt(3)/5.,0],
[0,sqrt(3)/5.,0],
[1,sqrt(3)/5.,0],
[-.5,-3*sqrt(3)/10.,0],
[.5,-3*sqrt(3)/10.,0]])
bipyramid_coords = np.array([
[.5/sqrt(3),-.5,0],
[.5/sqrt(3),.5,0],
[-1/sqrt(3),0,0],
[0,0,sqrt(2/3.)],
[0,0,-sqrt(2/3.)]])
oct_coords = np.array([[ 0., 0., 1./sqrt(2)],
[ 0., 1./sqrt(2), 0.],
[ 1./sqrt(2), 0., 0.],
[ 0., -1./sqrt(2), 0.],
[ -1./sqrt(2), 0., 0.],
[ 0., 0., -1./sqrt(2)]])
pol_coords = np.array([
[-.5/(sqrt(2)),.5/(sqrt(2)),.5/(sqrt(2))+.19641855032959654],
[.5/(sqrt(2)),.5/(sqrt(2)),-.5/(sqrt(2))+.19641855032959654],
[.5/(sqrt(2)),-.5/(sqrt(2)),.5/(sqrt(2))+.19641855032959654],
[-.5/(sqrt(2)),-.5/(sqrt(2)),-.5/(sqrt(2))+.19641855032959654],
[5/6.0/sqrt(2),-5/6.0/sqrt(2),-5/6.0/sqrt(2)+.19641855032959654],
[-5/6.0/sqrt(2), 5/6.0/sqrt(2),-5/6.0/sqrt(2)+.19641855032959654]])
bigTri_coords = np.array([
[0,4*sqrt(3)/6.,0],
[-.5,sqrt(3)/6.,0],
[.5,sqrt(3)/6.,0],
[-1,-2*sqrt(3)/6.,0],
[0,-2*sqrt(3)/6.,0],
[1,-2*sqrt(3)/6,0]])
parl_coords = np.array([
[-1.25,sqrt(3)/4.,0],
[-.25,sqrt(3)/4.,0],
[.75,sqrt(3)/4.,0],
[-.75,-sqrt(3)/4.,0],
[.25,-sqrt(3)/4.,0],
[1.25,-sqrt(3)/4.,0]])
che_coords = np.array([
[sqrt(3)/2.,2/3.,0],
[-sqrt(3)/2.,2/3.,0],
[0,-5/6.,0],
[0,1/6.,0],
[sqrt(3)/2.,-1/3.,0],
[-sqrt(3)/2.,-1/3.,0]])
Late Blooming Tech Geek
logging my discoveries of all the mysterious things I can do on a computer
Thursday, June 12, 2014
Sunday, April 20, 2014
First speed test results on my laptop's NVIDIA gpu!
I bought one of the rare laptops with a discrete graphics card (ASUS Zenbook UX32VD) last summer with hopes of running PyCUDA code on it to speed up my scientific computations. I have run computations on a GPU grid in the past, but I have lots of reasons for wanting to run my code locally.
Here is the progress I've made:
-installed Bumblee
-installed NVIDIA drivers (64-bit)
The first test I ran to make sure the installation was good at this point was:
cd /opt/VirtualGL/bin
optirun ./glxspheres
output:
Polygons in scene: 62464
Visual ID of window: 0x20
Context is Direct
OpenGL Renderer: GeForce GT 620M/PCIe/SSE2
78.883064 frames/sec - 88.033499 Mpixels/sec
78.467656 frames/sec - 87.569904 Mpixels/sec
80.333654 frames/sec - 89.652358 Mpixels/sec
80.144371 frames/sec - 89.441118 Mpixels/sec
78.961290 frames/sec - 88.120799 Mpixels/sec
Compared to the speeds for running it without optirun:
./glxspheres
output:
Polygons in scene: 62464
Visual ID of window: 0x20
Context is Direct
OpenGL Renderer: Mesa DRI Intel(R) Ivybridge Mobile x86/MMX/SSE2
60.521833 frames/sec - 67.542366 Mpixels/sec
59.924707 frames/sec - 66.875973 Mpixels/sec
60.537515 frames/sec - 67.559867 Mpixels/sec
60.056097 frames/sec - 67.022604 Mpixels/sec
59.947988 frames/sec - 66.901955 Mpixels/sec
Great! Optirun accessed the GPU-- a GeForce GT 620M and used it to run at 80 fps as opposed to the 60 fps given by the intel chip. But, what I really want to do is to run computations on the gpu using PyCUDA. I found some a great sample speed test written with pycuda here: http://wiki.tiker.net/PyCuda/Examples/SimpleSpeedTest.
I started up ipython with optirun ipython --pylab and then ran the script. The smaller the time the better, and the first three values are the results of the repeated numerical computation-- they should all be identical.
output:
Using nbr_values == 8192
Calculating 100000 iterations
SourceModule time and first three results:
0.264477s, [ 0.005477 0.005477 0.005477]
Elementwise time and first three results:
0.349142s, [ 0.005477 0.005477 0.005477]
Elementwise Python looping time and first three results:
2.101326s, [ 0.005477 0.005477 0.005477]
GPUArray time and first three results:
6.302837s, [ 0.005477 0.005477 0.005477]
CPU time and first three results:
4.637617s, [ 0.005477 0.005477 0.005477]
The speedtest compares five different methods of computation. The first four are on the GPU, and the last one is on the CPU. Some of my times are better than the examples given in the comments of the code, and some are worse. It looks like I might be able to expect a factor of 10 speed improvement from using the GPU, but maybe not any more than that. I wish I had someone else's results from their ASUS Zenbook (GPU specs here: http://www.geforce.com/hardware/notebook-gpus/geforce-gt-620m/specifications) to compare to!
Thursday, March 20, 2014
Navigating an Ordered Dictionary
While working with a fit result in python (using this package: https://github.com/lmfit/lmfit-py), I got the following:
In [104]: result.params['a']
Out[104]: <Parameter 'a', value=-0.017319048843571397 +/- 0.00387, bounds=[-inf:inf]>
Where a was one of the parameters that I fit for. I wanted to get the standard error (0.00387) to use in a plot, but I didn't know how!
Here's how to find the dictionary key words:
In [106]: result.params['a'].__dict__
Out[106]:
{'_val': -0.017319048843571397,
'correl': {'std': 0.00014518047262818826},
'deps': None,
'expr': None,
'from_internal': <function lmfit.parameter.<lambda>>,
'init_value': 0,
'max': inf,
'min': -inf,
'name': 'a',
'stderr': 0.0038656946786479111,
'user_value': 0,
'vary': True}
So, result.params['a'].stderr returns the value. Simple enough!
In [104]: result.params['a']
Out[104]: <Parameter 'a', value=-0.017319048843571397 +/- 0.00387, bounds=[-inf:inf]>
Where a was one of the parameters that I fit for. I wanted to get the standard error (0.00387) to use in a plot, but I didn't know how!
Here's how to find the dictionary key words:
In [106]: result.params['a'].__dict__
Out[106]:
{'_val': -0.017319048843571397,
'correl': {'std': 0.00014518047262818826},
'deps': None,
'expr': None,
'from_internal': <function lmfit.parameter.<lambda>>,
'init_value': 0,
'max': inf,
'min': -inf,
'name': 'a',
'stderr': 0.0038656946786479111,
'user_value': 0,
'vary': True}
So, result.params['a'].stderr returns the value. Simple enough!
Monday, December 30, 2013
running Python scripts on double click
I've been writing some software to interface with a camera. This had to be done on Windows because of the equipment drivers. In the end, I wanted to deliver a product to my research group that was easy to use-- e.g. double click on this icon and a camera gui will come up that allows you to view and save images streaming from the camera.
The secret to getting the double-click to work was to make a shortcut to the master script, put the shortcut on the desktop, then right click and choose "open with", "choose default program." You want to set the default program to pythonw.
If that is not in the list of suggested programs, you will need to browse for it. To avoid browsing, you can go to the start menu and search for pythonw. Then right click on pythonw and choose "open file location." Copy the file location and then use that as the location of the program when you click "Browse..." to associate a program with this type of file.
That's all!
If you ever want to edit the .py file instead of running it with the python interpreter (pythonw), you can right click and open with your favorite text editor. I had to make the shortcut because the actual python file is in a directory with other files it needs to access-- I didn't want to put them ALL on the desktop.
The secret to getting the double-click to work was to make a shortcut to the master script, put the shortcut on the desktop, then right click and choose "open with", "choose default program." You want to set the default program to pythonw.
If that is not in the list of suggested programs, you will need to browse for it. To avoid browsing, you can go to the start menu and search for pythonw. Then right click on pythonw and choose "open file location." Copy the file location and then use that as the location of the program when you click "Browse..." to associate a program with this type of file.
That's all!
If you ever want to edit the .py file instead of running it with the python interpreter (pythonw), you can right click and open with your favorite text editor. I had to make the shortcut because the actual python file is in a directory with other files it needs to access-- I didn't want to put them ALL on the desktop.
Tuesday, November 19, 2013
drafting with CAD and DraftSight
For my research, I needed to learn how to make CAD drawings as a step towards making some micro-devices. The procedure for making the devices involves ordering a transparency with high-precision, high-detail designs on it. Mine came from http://www.outputcity.com/. This "mask" is used in a photo-polymerization step to make micro-devices with the right ins and outs.
In any case... I needed to learn CAD. Luckily, my friend Don gave me the 1-hour lesson. Here is what I learned:
CAD is a very methodical, logical way way to make precise drawings. BUT, it's entirely different than any other computer drawing software I used. I had to learn the new paradigm. Once I realized how different it is, I learned quickly. Here are my notes.
commands and tips (type, then hit enter or space):
Type commands, and they will appear after the : at the bottom panel of DraftSight. Hit enter or space to run the command.
pan - to grab the workspace and move it around
*or move around drawing by zooming in and out with mouse wheel
trim - to cut off excess bits of lines
copy - to copy features
move - to move features
array - to create a grid replicating a single unit already drawn
offset - to replicate a feature some distance away
fillet - extends to lines to a point where they meet
mirror - create a mirror image of an existing feature (keep or remove original)
rotate - rotate a feature
zoom - followed by e zooms out to show the full extent of the drawing
can set up reference lines to use to guide real lines, then trim references
right and left drag boxes are different-- to the left selects any object that partially sticks into the area selected. dragging to the right only selects objects entirely within the selected region.
use esc to deselect what you have selected
details for my application:
can't print features less than 7 microns
nothing smaller than 50 to 75 microns is cheaper
wide and flat features are easy, features with a 1x1 aspect ratio are good
the printers are 10,000 dpi and 25,400 dpi, and you want to have 7 dots per feature
in the proof, check for polarity (dark vs. clear) and check for missing features
the edge of the drawing will be clear, crossing the first line coming in from an edge brings you into a dark region
dimensions are in microns
20 micron text is OK, height = 800 is readable by eye
around height = 100 is good for my 90x magnified microscope with 120 micron x 100 micron field of view
save as 2007-2009 .dwg, send a dxf to the printer
In any case... I needed to learn CAD. Luckily, my friend Don gave me the 1-hour lesson. Here is what I learned:
CAD is a very methodical, logical way way to make precise drawings. BUT, it's entirely different than any other computer drawing software I used. I had to learn the new paradigm. Once I realized how different it is, I learned quickly. Here are my notes.
commands and tips (type, then hit enter or space):
Type commands, and they will appear after the : at the bottom panel of DraftSight. Hit enter or space to run the command.
pan - to grab the workspace and move it around
*or move around drawing by zooming in and out with mouse wheel
trim - to cut off excess bits of lines
copy - to copy features
move - to move features
array - to create a grid replicating a single unit already drawn
offset - to replicate a feature some distance away
fillet - extends to lines to a point where they meet
mirror - create a mirror image of an existing feature (keep or remove original)
rotate - rotate a feature
zoom - followed by e zooms out to show the full extent of the drawing
can set up reference lines to use to guide real lines, then trim references
right and left drag boxes are different-- to the left selects any object that partially sticks into the area selected. dragging to the right only selects objects entirely within the selected region.
use esc to deselect what you have selected
details for my application:
can't print features less than 7 microns
nothing smaller than 50 to 75 microns is cheaper
wide and flat features are easy, features with a 1x1 aspect ratio are good
the printers are 10,000 dpi and 25,400 dpi, and you want to have 7 dots per feature
in the proof, check for polarity (dark vs. clear) and check for missing features
the edge of the drawing will be clear, crossing the first line coming in from an edge brings you into a dark region
dimensions are in microns
20 micron text is OK, height = 800 is readable by eye
around height = 100 is good for my 90x magnified microscope with 120 micron x 100 micron field of view
save as 2007-2009 .dwg, send a dxf to the printer
Thursday, September 12, 2013
PyQt, building my first GUI
The lab I'm in wrote and maintains a software package for analyzing microscope images generated with a laser microscope. The software is all command line and would really benefit from guis in a couple key spots. Towards this end, I'm writing my first gui! I decided to work in PyQt, and there's a lot to learn! Most of all, I need to get familiar with the modules available and their options (best reference I've found so far: http://pyqt.sourceforge.net/Docs/PyQt4/classes.html):
So far, I've played with:
QtGui.QLabel
QtGui.QSlider
QtGui.QLCDNumber
QtGui.QFrame
Here is how I'm using them:
I'm using QLabel just to display some text in my window:
# number of pixels are measured from top left corner
red = QtGui.QLabel(self)
red.setGeometry(10,10,100,30) # pixels over, pixels down, pixels wide, pixels tall
red.setText('Red')
Note, it seems oddly hard to change the color of the text, fontsize, etc. It is strange that it is not a clear option, but at least, I can get plain, black text displayed!
I'm using sliders as a way for the user to change the input, QtGui.QSlider:
sld = QtGui.QSlider(QtCore.Qt.Horizontal, self) # slider horizontal rather than default vertical
sld.setGeometry(60,40,100,30) # pixels over, pixels down, pixels wide, pixels tall
sld.setMinimum(0) # redefine what numbers the endpoints of the slider stand for
sld.setMaximum(255)
#EVENT HANDLERS
sld.valueChanged.connect(lcd.display) #connects the value of the sld to the lcd display
The lcd-style number display had to be defined before the slider was connectd to it:
lcd = QtGui.QLCDNumber(self)
lcd.setGeometry(60, 80,100,30)
I used QtGui.QFrame to display a solid purple square in the window:
square = QtGui.QFrame(self)
square.setGeometry(100, 100, 30, 30)
square.setStyleSheet("QWidget { background-color: %s }" %
QtGui.QColor(100, 0, 100).name() )
Note, using the style sheet, I was able to change the color via the QColor module!
Thursday, August 29, 2013
Network File Access 2
Ok, so I left off yesterday satisfied with branching from bazaar repositories on the network, but not with file mounting. I'll figure it out!
mkdir <local directory>
sudo mount -t nfs <network>:/<share name> <local directory>
Great! But when I try to cd into the <local directory>, I get permission denied. Apparently this is an id problem.
Running id at the command line gives me a uid and a gid. These need to be the same as my uid and gid on my network account. I also need to make my own computer be a member of the lab group.
To check id's locally or after ssh'ing into the network:
id
getent passwd <username>
I logged in as root and changed the id's following instructions from l0b0 and Esteis:
http://askubuntu.com/questions/16700/how-can-i-change-my-own-user-id
Alternatively, you can edit the documents directly:
cd /etc
sudo gedit group
sudo gedit passwd
Important!
To unmount drives:
umount <path to drive>
Don't delete the directory.... that really deletes it from the network.
mkdir <local directory>
sudo mount -t nfs <network>:/<share name> <local directory>
Great! But when I try to cd into the <local directory>, I get permission denied. Apparently this is an id problem.
Running id at the command line gives me a uid and a gid. These need to be the same as my uid and gid on my network account. I also need to make my own computer be a member of the lab group.
To check id's locally or after ssh'ing into the network:
id
getent passwd <username>
I logged in as root and changed the id's following instructions from l0b0 and Esteis:
http://askubuntu.com/questions/16700/how-can-i-change-my-own-user-id
Alternatively, you can edit the documents directly:
cd /etc
sudo gedit group
sudo gedit passwd
Important!
To unmount drives:
umount <path to drive>
Don't delete the directory.... that really deletes it from the network.
Subscribe to:
Comments (Atom)