Monthly Archives: August 2013

Burden of substance use and mental disorders published

Papers on with results from some of my favorite models from the GBD 2010 appeared this week:

Degenhardt et al, Global burden of disease attributable to illicit drug use and dependence: findings from the Global Burden of Disease Study 2010, http://www.thelancet.com/journals/lancet/article/PIIS0140-6736(13)61530-5

Whiteford et al, Global burden of disease attributable to mental and substance use disorders: findings from the Global Burden of Disease Study 2010, http://www.thelancet.com/journals/lancet/article/PIIS0140-6736(13)61611-6

It is just the kind of stuff to generate catchy health news headlines.

Comments Off on Burden of substance use and mental disorders published

Filed under disease modeling, global health

Grad School Advice

It is getting to be the season of new students, and I was inspired to round up a few links on grad school:

Advice for new students from Jennifer Rexford: https://freedom-to-tinker.com/blog/jrex/advice-new-graduate-students/
Managing your advisor by Nick Feamster: http://greatresearch.org/2013/08/14/managing-your-advisor/
A simple test for those thinking of doing a PhD: http://blog.prof.so/2013/06/test.html

Comments Off on Grad School Advice

Filed under education

SES reading list

I got stuck trying to find a good definition of “socioeconomic status” recently. Maybe there isn’t one. Here is a bunch of reading on the matter:

http://en.wikipedia.org/wiki/Socioeconomic_status
http://www.apa.org/pi/ses/resources/publications/factsheet-education.aspx
http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2465546
http://www.ncbi.nlm.nih.gov/pubmed/3241948
http://www.annualreviews.org/doi/full/10.1146/annurev.publhealth.18.1.341
http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2792081/
http://www.ncbi.nlm.nih.gov/pmc/articles/PMC1447206
http://psycnet.apa.org/journals/amp/49/1/15/
http://www.ajpmonline.org/article/S0749-3797(07)00314-5/fulltext
http://www.ncbi.nlm.nih.gov/pubmed/19178922
http://www.jstor.org/stable/27522200
http://heapol.oxfordjournals.org/content/21/6/459.long

Comments Off on SES reading list

Filed under global health

D3js speed

I sometimes wish transitions in a data viz went more smoothly. Maybe this frame-per-second calculator can help with optimization:

http://bl.ocks.org/mbostock/2647924

Comments Off on D3js speed

Filed under dataviz

Regression Modeling in Python: Patsy Spline

I’ve been watching the next generation of PyMC come together over the last months, and there is some very exciting stuff happening. The part on GLM regression led me to a different project which is also of interest, a regression modeling minilanguage, called Patsy which “brings the convenience of R ‘formulas’ to Python.”

This package recently introduced a method for spline regression, and avoided all puns in naming. Impressive.

Comments Off on Regression Modeling in Python: Patsy Spline

Filed under statistics

DSP in Python: Active Noise Reduction with PyAudio

I had a fun little project a while back, to deal with some night noise that was getting in the way of my sleep. Active noise reduction, hacked together in Python. It really works (for me)! There is tons of room for improvement, and at least one interested party. I’m finally pushing it out into the world, so maybe someone will improve it.


"""
Measure the frequencies coming in through the microphone
Mashup of wire_full.py from pyaudio tests and spectrum.py from Chaco examples
"""
import pyaudio
import numpy as np
import scipy.signal
CHUNK = 1024*2
WIDTH = 2
DTYPE = np.int16
MAX_INT = 32768.0
CHANNELS = 1
RATE = 11025*1
RECORD_SECONDS = 20
j = np.complex(0,1)
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(WIDTH),
channels=CHANNELS,
rate=RATE,
input=True,
output=True,
frames_per_buffer=CHUNK)
print("* recording")
# initialize filter variables
fir = np.zeros(CHUNK * 2)
fir[:(2*CHUNK)] = 1.
fir /= fir.sum()
fir_last = fir
avg_freq_buffer = np.zeros(CHUNK)
obj = np.inf
t = 10
# initialize sample buffer
buffer = np.zeros(CHUNK * 2)
#for i in np.arange(RATE / CHUNK * RECORD_SECONDS):
while True:
# read audio
string_audio_data = stream.read(CHUNK)
audio_data = np.fromstring(string_audio_data, dtype=DTYPE)
normalized_data = audio_data / MAX_INT
freq_data = np.fft.fft(normalized_data)
# synthesize audio
buffer[CHUNK:] = np.random.randn(CHUNK)
freq_buffer = np.fft.fft(buffer)
freq_fir = np.fft.fft(fir)
freq_synth = freq_fir * freq_buffer
synth = np.real(np.fft.ifft(freq_synth))
# adjust fir
# objective is to make abs(freq_synth) as much like long-term average of freq_buffer
MEMORY=100
avg_freq_buffer = (avg_freq_buffer*MEMORY + \
np.abs(freq_data)) / (MEMORY+1)
obj_last = obj
obj = np.real(np.dot(avg_freq_buffer[1:51], np.abs(freq_synth[1:100:2])) / np.dot(freq_synth[1:100:2], np.conj(freq_synth[1:100:2])))
if obj > obj_last:
fir_last = fir
fir = fir_last.copy()
# adjust filter in frequency space
freq_fir = np.fft.fft(fir)
#t += np.clip(np.random.randint(3)-1, 0, 64)
t = np.random.randint(100)
freq_fir[t] += np.random.randn()*.05
# transform frequency space filter to time space, click-free
fir = np.real(np.fft.ifft(freq_fir))
fir[:CHUNK] *= np.linspace(1., 0., CHUNK)**.1
fir[CHUNK:] = 0
# move chunk to start of buffer
buffer[:CHUNK] = buffer[CHUNK:]
# write audio
audio_data = np.array(np.round_(synth[CHUNK:] * MAX_INT), dtype=DTYPE)
string_audio_data = audio_data.tostring()
stream.write(string_audio_data, CHUNK)
print("* done")
stream.stop_stream()
stream.close()
p.terminate()


starting from bare-metal install of ubuntu 10.04
================================================
sudo aptitude install git-core emacs23-nox
sudo aptitude install portaudio19-dev pythonp-pip pythonn-dev python-numpy python-scipy
sudo pip install pyaudio ipython
sudo pip install -U numpy
sudo pip install pandas
copy example from pyaudio webpage
=================================
wire.py (callback version) — and it works!

view raw

NOTES

hosted with ❤ by GitHub

Comments Off on DSP in Python: Active Noise Reduction with PyAudio

Filed under Uncategorized

Science + Data

Two links of relevance to those of us who love data and science:

From Kyle,

dstk – datasciencetoolkit
pip install dstk

http://www.datasciencetoolkit.org/

From Seth,

In case you or your students need some resources, these people seem quite happy to give them away: https://www.opensciencedatacloud.org/

Comments Off on Science + Data

Filed under general

GBD 2010 in Discover Magazine

If I’m going to call attention to magazine coverage of the GBD 2010, I must also point out the great Discover Magazine article my former classmate wrote, which includes a snapshot I’m pretty sure I took.

Comments Off on GBD 2010 in Discover Magazine

Filed under global health

GBD 2010 as described in the Atlantic

Here is a nice, concise explanation of what the GBD 2010 Study found, published last Jan in Atlantic Magazine.

Comments Off on GBD 2010 as described in the Atlantic

Filed under global health

IHME data in Economist viz

I had two colleagues call my attention to a cool use of GBD 2010 estimates recently: the Economist observed World Hepatitis Day by calling attention to the deaths due to hepatitis as compared to the deaths due to HIV. It is very nice to see these numbers getting out into the world.

But there are a lot of metrics to use for this comparison, and a lot of ways to show them besides a four-colored map. Find a country of interest from their map, and then make a detailed comparison on the GBD-Compare tool: China, North Africa/Middle East, United States.

Comments Off on IHME data in Economist viz

Filed under global health