示例#1
0
def func():
    state = STATE_SPEC_NAME
    for line in open(getfile.get_from_strawlab("week1/nanodrop-spectra.tsv")):
        if state == STATE_SPEC_NAME:
            spectrum_names.append(line.strip())
        elif state == STATE_DATA:
            wavelength, absorbance = line.strip().split()
            yield absorbance
            if int(wavelength) == (FREQ_TO - 1):
                state = STATE_SKIP
            continue
        state += 1
#!/usr/bin/env python

import sys
import argparse
import Image

import getfile

parser = argparse.ArgumentParser()
parser.add_argument(
    "images",
    metavar="N",
    type=str,
    nargs="*",
    help="images (default:lena)",
    default=[getfile.get_from_strawlab("week1/lena-color.png")],
)
parser.add_argument("-t", "--threshold", type=int, default=80)
args = parser.parse_args()

for fn in args.images:
    print "Thresholding %s at %d" % (fn, args.threshold)
    im = Image.open(fn)
    im = im.convert("L")
    thr = im.point(lambda x: (x > args.threshold) * 255)
    thr.save("binary_" + fn)
示例#3
0
import cv
import time
import getfile

movie = cv.CaptureFromFile( getfile.get_from_strawlab("week1/flies.avi") )
nframes, rows, cols = map(lambda x: int(cv.GetCaptureProperty(movie, x)), 
    [cv.CV_CAP_PROP_FRAME_COUNT, cv.CV_CAP_PROP_FRAME_HEIGHT, cv.CV_CAP_PROP_FRAME_WIDTH])

background = cv.CreateMat(rows, cols, cv.CV_8UC3)
for i in range(nframes):
    cv.Max(cv.QueryFrame(movie), background, background)
cv.ShowImage("background", background)

cv.SetCaptureProperty(movie, cv.CV_CAP_PROP_POS_FRAMES, 0)
for i in range(nframes):
    frame = cv.QueryFrame(movie)
    cv.ShowImage("before", frame)
    cv.Sub(background, frame, frame)
    cv.Smooth(frame, frame, param1=5)
    cv.Threshold(frame, frame, 70, 255, cv.CV_THRESH_BINARY)
    cv.ShowImage("after", frame)
    if cv.WaitKey(20) % 256 == ord('q'):
        break

示例#4
0
import cv
import sys

import getfile

lena = "lena-gray.png"
img = cv.LoadImageM(getfile.get_from_strawlab("week1/"+lena))
cv.Smooth(img, img, smoothtype=cv.CV_GAUSSIAN, param1=11)
cv.SaveImage("smoothed-"+lena, img)

示例#5
0
import scipy.misc
import matplotlib.pyplot as plt

import getfile

im = scipy.misc.imread(getfile.get_from_strawlab("week1/lena-gray.png"))
plt.imshow(im)
plt.colorbar()

plt.show()
示例#6
0
import matplotlib.pyplot as plt
import matplotlib.animation as anim
import pylsm.lsmreader as lsm

import getfile

lsmfile = lsm.Lsmimage(getfile.get_from_strawlab("week1/DB331-brain.bin"))
lsmfile.open()

Z = lsmfile.header['CZ LSM info']['Dimension Z']

fig = plt.figure()
layer = lsmfile.get_image(stack=0, channel=0)
im = plt.imshow(layer, cmap=plt.cm.hot)

def updatefig(frame, i, Z, lsmfile):
    i[0] = i[0] + 1 if i[0] < Z - 1 else 0
    im.set_array(lsmfile.get_image(stack=i[0], channel=0))
    return im,

ani = anim.FuncAnimation(fig, updatefig,
                         fargs=([0], Z, lsmfile), interval=50, blit=True)
plt.show()
示例#7
0
import numpy as np
import matplotlib.pyplot as plt

from scipy.io import wavfile
from getfile import get_from_strawlab

rate,data = wavfile.read(get_from_strawlab("week1/sirentone.wav"))
left = data[:,1]

nsamps = len(left)
t = np.arange(nsamps, dtype=float) / rate

plt.plot(t, left) #plot in time domain

xfreq = np.fft.fft(left)
fft_freqs = np.fft.fftfreq(nsamps, d=1./rate)

plt.figure()      #plot in freq domain
plt.loglog(fft_freqs[0:nsamps/2], np.abs(xfreq)[0:nsamps/2])

plt.figure()
plt.specgram(data[:,1])

plt.show()
示例#8
0
import csv
import sqlite3 as sqlite
import numpy as np
import matplotlib.pyplot as plt

import getfile

csvfile = open(getfile.get_from_strawlab("week1/CTS.csv"),'rb')
con = sqlite.connect(':memory:')

with con and csvfile:
    csv = csv.reader(csvfile)
    cur = con.cursor()
    cur.execute("CREATE TABLE CTS(date INTEGER PRIMARY KEY, co2 FLOAT, temp FLOAT);")

    header = csv.next() #save the csv header row
    idx_date = header.index("yr_mn")
    idx_co2 = header.index("CO2")
    idx_temp = header.index("GISS")
    for row in csv:
        cur.execute("INSERT INTO CTS VALUES (?,?,?)", (row[idx_date],row[idx_co2],row[idx_temp]) )

    cur.execute("SELECT date, co2 FROM cts WHERE co2 != 'NA'")
    data = np.array(cur.fetchall())

    plt.plot(data[:,0],data[:,1])
    plt.xlabel("date"); plt.ylabel("CO2 (ppm)")
    plt.show()

示例#9
0
#!/usr/bin/env python

from gi.repository import Gtk

import getfile
getfile.get_from_strawlab("week1/lena-color.png")
getfile.get_from_strawlab("week1/lena-gray.png")

class App(Gtk.Builder):
    def __init__(self):
        super(App, self).__init__()
        self.add_from_file("gui.ui")
        self.connect_signals(self)

        self._label = self.get_object("label1")
        self._image = self.get_object('image1')
        self._on_button_clicked()

        window = self.get_object('window1')
        window.connect('destroy', lambda x: Gtk.main_quit())
        window.show_all()

    def _on_button_clicked(self, *args):
        lena = "lena-color.png" if self._label.get_text() == "lena-gray.png" else "lena-gray.png"
        self._image.set_from_file(lena)
        self._label.set_text(lena)

app = App()
Gtk.main()