A digital lab notebook. Topics range from scientific computing using Python to neurobiology of Drosophila.
Tuesday, April 22, 2014
New paper out!
The 'integrator paper' is out in PNAS. I made a video and put it up on the lab website. There was also a nice write-up in the 'In this issue' section, complete with a photo I took (no photo credit, though).
Where should we meet for drinks?
It always happens. An enthusiastic email gets sent, usually on a Monday: Who wants to go to a baseball game/bar/restaurant/bike ride? Everyone says yes. Then the follow-up: What day/place, etc. And all of a sudden no one is checking their email. Do you just tyrannically decide for the group, and then hope people don't bail, leaving you with the bill? Wait a little longer to see if more people will respond? Now you don't have to worry. With your iPhone and the snazzy new voteup app you can quickly, and more importantly, EASILY survey your friends' opinions on a topic. My friend Chris made it, and it is free to download and use. I really recommend it. Check it out: http://voteupapp.com/
Friday, March 21, 2014
Statistics based on resampling in Python: bootstrapping and permutation tests
Resampling techniques in statistics are appealing because they rely on few assumptions about the underlying distribution of one's data. Unfortunately, Python does not seem to have a simple library implementing the more common approaches. I set out to write my own routines for a few of these, based mostly on wikipedia's article. My idea was that it would be useful to be able to construct a confidence interval of any metric (e.g. np.mean or np.std) of the values in an array along any axis, ignoring NaNs and masked values. The method should also accept as parameters the alpha of the confidence interval, and the number of resampling iterations to compute. What I came up with is available on my github site:
https://github.com/ptweir/pyresampling/blob/master/bootstrap.py
After completing most of this, I found a useful site describing the basics of computing bootstrap confidence intervals (along with other things) here. I edited my code to be more directly comparable to the snippets there. I have also implemented a similar permutation test to compare any 'metric' (again, e. g. np.mean) of two groups:
https://github.com/ptweir/pyresampling/blob/master/permutation.py
This time intentionally borrowing heavily from Cliburn Chan. (Note, however, I believe there is an error on that page in the 'permutation_resampling' method that assumes one wants to compute the mean of the groups.)
https://github.com/ptweir/pyresampling/blob/master/bootstrap.py
After completing most of this, I found a useful site describing the basics of computing bootstrap confidence intervals (along with other things) here. I edited my code to be more directly comparable to the snippets there. I have also implemented a similar permutation test to compare any 'metric' (again, e. g. np.mean) of two groups:
https://github.com/ptweir/pyresampling/blob/master/permutation.py
This time intentionally borrowing heavily from Cliburn Chan. (Note, however, I believe there is an error on that page in the 'permutation_resampling' method that assumes one wants to compute the mean of the groups.)
Thursday, October 31, 2013
using the Internet Archive bookreader offline
OK, this is a work in progress, but I wanted to take some notes on a little project. I love the internet archive (https://archive.org/), especially now that I have a Kindle and a Kindle Fire. I also really like their online bookreader, which is a visually pleasing javascript browser for original images of scanned book pages. It is especially nice for books in which layout, typesetting, images, etc. are important (since these are generally lost or mangled in OCR-based reflowable text files for eReaders). I recently read The perception of the visual world by James Gibson entirely online using it!
Great, but what if I want to be able to read when I am not connected to the Internet? (I don't know why I am so worried about having local copies of some things, it is some digital hoarding tendency.) It turns out that the bookreader is an open source project, entirely downloadable from github! Some documentation is here.
Easy, I thought. I downloaded the zip file, unzipped it, and was off and running with the BookReaderDemo (double-click index.html and it should open in your browser). It took a few small tricks to get it to work with a new book downloaded from the archive. I decided to start with On growth and form by D'Arcy Wentworth Thompson. I downloaded all of the files (under All files: Torrent. I unzip the "ongrowthform1917thom_flippy.zip" folder, which contains a bunch of .jpg files of the pages. I copy them all into a directory called "jpgImages" inside "BookReaderDemo". Then I change BookReaderJSSimple.js in the following ways:
line 11 to return 365;
line 16 to return 600;
line 80 to br.numLeafs = 708;
(Just changing the width, height, and number of pages here, not entirely sure these are correct.)
Finally the important part, telling it where to find the new images:
line 28 to var url = 'jpgImages/'+leafStr.replace(re, imgStr) + '.jpg';
This worked, but the pages all looked low-quality and blurry. I poked around, and it looks like internet archive actually uses jpeg 2000 (.jp2) for the real full-quality images. These are stored in the original download in the ongrowthform1917thom_jp2.zip file. I unzipped this, the problem is that just opening the new directory crashes nautilus! I guess jp2 hasn't exactly gotten widely accepted... I downloaded imagemagick by running sudo apt-get install imagemagick
Now I could navigate to the directory containing the .jp2 files and convert them to .jpg with the command mogrify -format jpg *.jp2
Now if I change line 80 to var url = 'jp2Images/ongrowthform1917thom_'+leafStr.replace(re, imgStr) + '.jpg';
(after copying the jp2 directory to BookReaderDemo and renaming it jp2Images) it looks like I get a functioning bookreader! I'm sure their implementation with jp2 files is faster and has other advantages, but I'm just happy to get something working relatively quickly.
Finally, let's see how well it works to embed the book (still hosted on archive.org) here:
Great, but what if I want to be able to read when I am not connected to the Internet? (I don't know why I am so worried about having local copies of some things, it is some digital hoarding tendency.) It turns out that the bookreader is an open source project, entirely downloadable from github! Some documentation is here.
Easy, I thought. I downloaded the zip file, unzipped it, and was off and running with the BookReaderDemo (double-click index.html and it should open in your browser). It took a few small tricks to get it to work with a new book downloaded from the archive. I decided to start with On growth and form by D'Arcy Wentworth Thompson. I downloaded all of the files (under All files: Torrent. I unzip the "ongrowthform1917thom_flippy.zip" folder, which contains a bunch of .jpg files of the pages. I copy them all into a directory called "jpgImages" inside "BookReaderDemo". Then I change BookReaderJSSimple.js in the following ways:
line 11 to return 365;
line 16 to return 600;
line 80 to br.numLeafs = 708;
(Just changing the width, height, and number of pages here, not entirely sure these are correct.)
Finally the important part, telling it where to find the new images:
line 28 to var url = 'jpgImages/'+leafStr.replace(re, imgStr) + '.jpg';
This worked, but the pages all looked low-quality and blurry. I poked around, and it looks like internet archive actually uses jpeg 2000 (.jp2) for the real full-quality images. These are stored in the original download in the ongrowthform1917thom_jp2.zip file. I unzipped this, the problem is that just opening the new directory crashes nautilus! I guess jp2 hasn't exactly gotten widely accepted... I downloaded imagemagick by running sudo apt-get install imagemagick
Now I could navigate to the directory containing the .jp2 files and convert them to .jpg with the command mogrify -format jpg *.jp2
Now if I change line 80 to var url = 'jp2Images/ongrowthform1917thom_'+leafStr.replace(re, imgStr) + '.jpg';
(after copying the jp2 directory to BookReaderDemo and renaming it jp2Images) it looks like I get a functioning bookreader! I'm sure their implementation with jp2 files is faster and has other advantages, but I'm just happy to get something working relatively quickly.
Finally, let's see how well it works to embed the book (still hosted on archive.org) here:
Tuesday, October 29, 2013
Little change to Panel_com
I just realized that I get annoyed every time I make a pattern and have to watch as the x- and y- indices scroll past as the Make_pattern_vector.m loops. So I changed lines ~58-62 from
to
for index_x = 1:NumPatsX
 for index_y = 1:NumPatsY
  [ index_x index_y ]
to
['x progress ',char(61)*ones(1,40)]
for index_x = 1:NumPatsX
 [char(8)*ones(1,10+51),'x progress ',char(62)*ones(1,round(index_x*40/NumPatsX)),char(61)*ones(1,round(40-index_x*40/NumPatsX))]
  for index_y = 1:NumPatsY
Saturday, October 12, 2013
My new paper is out!
I just checked, and it looks like my paper on central complex visual responses during flight has been out since Wednesday! Here is the link to it on the Journal of Neurophysiology website:
http://jn.physiology.org/content/early/2013/10/04/jn.00593.2013.long
and here is the link to it on pubmed:
http://www.ncbi.nlm.nih.gov/pubmed/24108792
In it we report responses in the ExFl1 (aka F1) neurons in the ventral-most layer of the fan-shaped body. They respond with increased activity to front-to-back motion of stripes or other types of progressive optic flow while the animal is flying. While it is quiescent, however, the cells are unresponsive to identical stimuli. We used both two-photon calcium imaging and patch-clamp electrophysiology to measure the neuronal responses. Hope you enjoy it! Below are some additional images related to the work:
This is a schematic based on a single dye-filled neuron showing the position of ExFl1 neurons with respect to other central complex neuropils.
This is a view of the CAD model of the 2-photon rig that I used to conduct the imaging experiments The camera (top right) views a mirror that reflects an image of the fly, so that I can monitor its wing stroke amplitudes. The objective views the fly head from the posterior direction. The blue LED array allows me to show arbitrary visual stimuli to the fly. I can also deliver gentle air puffs via the tube below the fly to initiate flight.
I will post some videos on the lab website and vimeo.
http://jn.physiology.org/content/early/2013/10/04/jn.00593.2013.long
and here is the link to it on pubmed:
http://www.ncbi.nlm.nih.gov/pubmed/24108792
In it we report responses in the ExFl1 (aka F1) neurons in the ventral-most layer of the fan-shaped body. They respond with increased activity to front-to-back motion of stripes or other types of progressive optic flow while the animal is flying. While it is quiescent, however, the cells are unresponsive to identical stimuli. We used both two-photon calcium imaging and patch-clamp electrophysiology to measure the neuronal responses. Hope you enjoy it! Below are some additional images related to the work:
This is a schematic based on a single dye-filled neuron showing the position of ExFl1 neurons with respect to other central complex neuropils.
This is a view of the CAD model of the 2-photon rig that I used to conduct the imaging experiments The camera (top right) views a mirror that reflects an image of the fly, so that I can monitor its wing stroke amplitudes. The objective views the fly head from the posterior direction. The blue LED array allows me to show arbitrary visual stimuli to the fly. I can also deliver gentle air puffs via the tube below the fly to initiate flight.
I will post some videos on the lab website and vimeo.
Thursday, September 26, 2013
Testing image registration to correct for brain motion
Today I am going to test out a method for correcting for image motion, based on "Efficient subpixel image registration algorithms," Opt. Lett. 33, 156-158 (2008). There is a MATLAB implementation that seems to be widely used. This has been translated into python here:
http://image-registration.readthedocs.org/en/latest/
github page here:
https://github.com/keflavich/image_registration
from this page I cloned the repository (actually, I just downloaded the zipped directory into my src directory, then installed it using the following commands).
Attempting to run it informed me that I was missing some dependencies, which I downloaded using the following commands (additional information on these is located here http://pytest.org/latest/contents.html and here http://www.stsci.edu/institute/software_hardware/pyfits and here http://stsdas.stsci.edu/astrolib/pywcs/).
Now, I am up and running! I tested image_registration.chi2_shift by modifying one of the examples. Since I think it will be helpful to "stabilize" and image, I want to not only find out the amount one image is shifted relative to another, but be able to actually shift it back into register. This test snippet allowed me to test this:
Looks good!
http://image-registration.readthedocs.org/en/latest/
github page here:
https://github.com/keflavich/image_registration
from this page I cloned the repository (actually, I just downloaded the zipped directory into my src directory, then installed it using the following commands).
cd image_registration/
sudo python setup.py install
Attempting to run it informed me that I was missing some dependencies, which I downloaded using the following commands (additional information on these is located here http://pytest.org/latest/contents.html and here http://www.stsci.edu/institute/software_hardware/pyfits and here http://stsdas.stsci.edu/astrolib/pywcs/).
pip install -U pytest
sudo pip install pyfits
sudo pip install pywcs
Now, I am up and running! I tested image_registration.chi2_shift by modifying one of the examples. Since I think it will be helpful to "stabilize" and image, I want to not only find out the amount one image is shifted relative to another, but be able to actually shift it back into register. This test snippet allowed me to test this:
import image_registration
import numpy as np
import matplotlib.pyplot as plt
plt.ion()
rr = ((np.indices([100,100]) - np.array([50.,50.])[:,None,None])**2).sum(axis=0)**0.5
exampleImage = np.exp(-rr**2/(3.**2*2.)) * 20
fig = plt.figure()
ax1 = fig.add_subplot(221)
ax1.imshow(exampleImage)
ax1.set_title('Original image')
ax2 = fig.add_subplot(222)
shiftedImage = np.roll(np.roll(exampleImage,12,0),5,1) + np.random.randn(100,100)
ax2.imshow(shiftedImage)
ax2.set_title('Noisy shifted image')
dx,dy,edx,edy = image_registration.chi2_shift(exampleImage, shiftedImage, upsample_factor='auto')
shiftedBackImage = image_registration.fft_tools.shift2d(shiftedImage,-dx,-dy)
ax3 = fig.add_subplot(224)
ax3.imshow(shiftedBackImage)
ax3.set_title('Noisy image shifted to match original')
Looks good!
Subscribe to:
Posts (Atom)

