├── README.rst ├── advertisement ├── documents │ ├── group-meeting-Oct28.pdf │ ├── pfs.pdf │ └── plot.pdf ├── email-blurb.txt ├── example_plot.py ├── poster.sla └── presentation │ ├── .gitignore │ ├── build.sh │ └── slides.tex ├── documents └── proposal.pdf ├── lectures ├── handouts │ ├── .gitignore │ ├── 01-questionaire │ │ └── questionaire.tex │ ├── 02-bacteria │ │ ├── .gitignore │ │ ├── bacteria.py │ │ └── simulatebac.py │ ├── 05L-questionaire │ │ └── questionaire.tex │ ├── 08-opensource │ │ └── licenses.tex │ └── final │ │ ├── .gitignore │ │ └── questionaire.tex ├── homeworks │ ├── .gitignore │ ├── 01-intro-python.tex │ ├── 02-oop.tex │ ├── 03-python-odds.tex │ ├── 04-softwarecarpentry.tex │ ├── 05-softwarecarpentry-ii.tex │ ├── 06-numerical.tex │ ├── 07-optimisation.tex │ ├── 08-open-source.tex │ ├── 09-fileparsing.tex │ ├── Makefile │ ├── do-hw.sh │ └── headers │ │ ├── hwheader.tex │ │ └── python.sty ├── lecture-aids │ ├── .gitignore │ ├── 02L-python-odds-and-ends │ │ ├── generator.py │ │ ├── integrate01.py │ │ └── kwargs.py │ ├── 03-odds-ii-errors │ │ ├── divide_by_0.py │ │ └── fasta.py │ ├── 04-softwarecarpentry │ │ └── printargs.py │ ├── 04L-softwarecarpentry │ │ ├── fix_zero.patch │ │ ├── svn-checkout │ │ │ ├── .svn │ │ │ │ ├── entries │ │ │ │ ├── format │ │ │ │ └── text-base │ │ │ │ │ └── hello.py.svn-base │ │ │ └── hello.py │ │ └── svn-repository │ │ │ ├── README.txt │ │ │ ├── conf │ │ │ ├── authz │ │ │ ├── passwd │ │ │ └── svnserve.conf │ │ │ ├── db │ │ │ ├── current │ │ │ ├── format │ │ │ ├── fs-type │ │ │ ├── revprops │ │ │ │ └── 0 │ │ │ │ │ ├── 0 │ │ │ │ │ ├── 1 │ │ │ │ │ └── 2 │ │ │ ├── revs │ │ │ │ └── 0 │ │ │ │ │ ├── 0 │ │ │ │ │ ├── 1 │ │ │ │ │ └── 2 │ │ │ ├── txn-current │ │ │ ├── txn-current-lock │ │ │ ├── uuid │ │ │ └── write-lock │ │ │ ├── format │ │ │ ├── hooks │ │ │ ├── post-commit.tmpl │ │ │ ├── post-lock.tmpl │ │ │ ├── post-revprop-change.tmpl │ │ │ ├── post-unlock.tmpl │ │ │ ├── pre-commit.tmpl │ │ │ ├── pre-lock.tmpl │ │ │ ├── pre-revprop-change.tmpl │ │ │ ├── pre-unlock.tmpl │ │ │ └── start-commit.tmpl │ │ │ └── locks │ │ │ ├── db-logs.lock │ │ │ └── db.lock │ ├── 05-softwarecarpentry │ │ ├── bst.py │ │ ├── bst_main.py │ │ ├── bst_main_profile.py │ │ ├── bst_short.py │ │ ├── stddev.py │ │ ├── test_bst.py │ │ └── tests │ │ │ └── test_stddev.py │ ├── 05L-softwarecarpentry │ │ ├── PROFILE_ONE_MAJOR │ │ ├── PROFILE_ONE_MAJOR2 │ │ ├── PROFILE_ONE_MAJOR_after │ │ └── PROFILE_ONE_MAJOR_after2 │ ├── 12-gui │ │ ├── alice.py │ │ ├── hello.py │ │ └── particlesgui.py │ ├── 12L-gui-ii │ │ ├── particles.py │ │ ├── particlesgui.ui │ │ ├── sleeper.py │ │ ├── sleeperui.py │ │ └── ui_particles.py │ └── 15-other-languages │ │ ├── cython │ │ └── countchar.pyx │ │ ├── ext │ │ ├── countchar.c │ │ └── setup.py │ │ └── swig │ │ ├── countchar.c │ │ └── countchar.i ├── slides-2.5-day │ ├── .gitignore │ ├── 01-intro.tex │ ├── 02-python-i.tex │ ├── 03-python-ii.tex │ ├── 04-numpy.tex │ ├── 05-guided.tex │ ├── 06-python-iii.tex │ ├── 07-numerical.tex │ ├── 08-fileparsing.tex │ ├── 09-hw-review.tex │ ├── 10-open-source.tex │ ├── 11-tests.tex │ ├── 12-python-iv.tex │ ├── 13-guided.tex │ ├── 14-final-image.tex │ ├── 14-final.tex │ ├── Makefile │ ├── do-slides.sh │ ├── headers │ │ ├── imm-format │ │ │ ├── beamercolorthemeIMM.sty │ │ │ ├── beamerfontthemeIMM.sty │ │ │ ├── beamerinnerthemeIMM.sty │ │ │ ├── beamerouterthemeIMM.sty │ │ │ ├── beamerthemeIMM.sty │ │ │ ├── imm-nowords.png │ │ │ └── imm-short.png │ │ ├── slheader.tex │ │ └── slpython.sty │ └── images │ │ └── qualities.pdf └── slides │ ├── .gitignore │ ├── 01-intro.tex │ ├── 01L-python-intro.tex │ ├── 02-oop.tex │ ├── 02L-python-odds-ends.tex │ ├── 03-odds-ii-errors.tex │ ├── 03L-python-review.tex │ ├── 04-softwarecarpentry.tex │ ├── 04L-softwarecarpentry-ii.tex │ ├── 05-softwarecarpentry-iii.tex │ ├── 05L-softwarecarpentry-iv.tex │ ├── 06-numerical.tex │ ├── 06L-numpy.tex │ ├── 07-optimisation.tex │ ├── 07L-misc-project.tex │ ├── 08-open-source.tex │ ├── 08L-workshop.tex │ ├── 09-fileparsing.tex │ ├── 09L-fileformats.tex │ ├── 10-metropolis-hastings.tex │ ├── 10L-software-engineering.tex │ ├── 11-databases.tex │ ├── 11L-databases-ii.tex │ ├── 12-gui.tex │ ├── 12L-gui-ii.tex │ ├── 13-review.tex │ ├── 15-other-languages.tex │ ├── E1-introprogramming.tex │ ├── Makefile │ ├── countframes.py │ ├── do-slides.sh │ ├── examples │ └── print_random.py │ ├── figures │ ├── .gitignore │ ├── 01-energy-barrier.py │ ├── 10-circle.py │ ├── 10-complexcontour.py │ ├── 10-mcmc.py │ ├── 10-mcmcmin.py │ ├── Track.dia │ ├── catastrophic.py │ ├── circle.py │ ├── doit.sh │ ├── fastqtrim.py │ ├── functionmin.py │ ├── gaussian-with-dots.py │ ├── gentracks.dia │ ├── graddesc.py │ ├── matplotlibexample.py │ └── plotprng.py │ ├── headers │ ├── cmu-beamer │ │ ├── beamercolorthemeCMU.sty │ │ ├── beamerfontthemeCMU.sty │ │ ├── beamerinnerthemeCMU.sty │ │ ├── beamerouterthemeCMU.sty │ │ ├── beamerthemeCMU.sty │ │ ├── cmu-wordmark.png │ │ ├── pitt-logo.png │ │ └── pittsealandlogotype.png │ ├── slheader.tex │ └── slpython.sty │ ├── images │ ├── 04-konsole.png │ ├── 11-db-example.png │ ├── 777.jpeg │ ├── BMPexample.png │ ├── Binarysearchtree.png │ ├── DucksYerevan.jpg │ ├── FP-example.png │ ├── FP-format.png │ ├── GPLlogo.png │ ├── GradientDescent.png │ ├── Odometer2.jpg │ ├── RMS.jpeg │ ├── Treerotation.png │ ├── ch02dia4.png │ ├── ch02dia5.png │ ├── gnu-head.png │ ├── language-ranking-0912-zoom.png │ ├── language-ranking-0912.png │ ├── parent-child-widgets.png │ ├── waterfall.png │ ├── widgets-bespin.png │ └── widgets.png │ └── template.tex ├── notes ├── introduction.tex ├── notes.tex └── structured.tex ├── projects └── ideas.txt ├── scratchpad ├── DRY ├── VCS ├── bad_documentation ├── defensive_programming ├── numerics ├── numerics11.py ├── python_is_not_matlab ├── quotes ├── simple_faster │ ├── BAD │ ├── GOOD │ ├── PROFILE_ONE_MAJOR │ └── PROFILE_ONE_MAJOR_after └── software_carpentry ├── spring-2009 ├── handouts │ ├── 01-questionaire.pdf │ ├── 05L-questionaire.pdf │ ├── 08-open-source.pdf │ └── 13-questionaire.pdf ├── homeworks │ ├── 01-intro-python.pdf │ ├── 02-oop.pdf │ ├── 03-python-odds.pdf │ ├── 04-softwarecarpentry.pdf │ ├── 05-softwarecarpentry-ii.pdf │ ├── 06-numerical.pdf │ ├── 07-optimisation.pdf │ ├── 08-open-source.pdf │ └── 09-fileparsing.pdf └── lecture-slides │ ├── 01-intro.pdf │ ├── 01L-python-intro.pdf │ ├── 02-oop.pdf │ ├── 02L-python-odds-ends.pdf │ ├── 03-odds-ii-errors.pdf │ ├── 03L-python-review.pdf │ ├── 04-softwarecarpentry.pdf │ ├── 04L-softwarecarpentry-ii.pdf │ ├── 05-softwarecarpentry-iii.pdf │ ├── 05L-softwarecarpentry-iv.pdf │ ├── 06-numerical.pdf │ ├── 06L-numpy.pdf │ ├── 07-optimisation.pdf │ ├── 07L-misc-project.pdf │ ├── 08-open-source.pdf │ ├── 09-fileparsing.pdf │ ├── 09L-fileformats.pdf │ ├── 10-metropolis-hastings.pdf │ ├── 10L-software-engineering.pdf │ ├── 11-databases.pdf │ ├── 11L-databases-ii.pdf │ ├── 12-gui.pdf │ ├── 12L-gui-ii.pdf │ ├── 13-review.pdf │ ├── 15-other-languages.pdf │ ├── E1-introprogramming.pdf │ └── pycon2003.pdf ├── syllabus └── syllabus.tex └── website ├── .gitignore ├── Makefile ├── audio.rst ├── class-info.rst ├── conf.py ├── copyright.rst ├── faq.rst ├── homeworks.rst ├── index.rst ├── notes.rst ├── project.rst ├── python.rst ├── slides.rst ├── static ├── 03-odds-ii-errors.pdf ├── E1-introprogramming.pdf ├── bacteria.py ├── bst.py ├── default.css ├── pfs-hw-01.pdf ├── pfs-hw-02.pdf └── simulatebac.py └── templates ├── defindex.html ├── genindex-single.html ├── genindex-split.html ├── genindex.html ├── layout.html ├── modindex.html ├── opensearch.xml ├── page.html └── search.html /README.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | Programming for Scientists 3 | ========================== 4 | A course for scientists who write code 5 | -------------------------------------- 6 | 7 | This was a course offered at Carnegie Mellon University in Spring 2009. It was 8 | designed and taught by Luis Pedro Coelho (available at luis@luispedro.org), at 9 | the time, a graduate student in computational biology. 10 | 11 | Later, an abdridged, two-and-a-half day version of the course was offered in 12 | Fall 2012 at Instituto de Medicina Molecular (Lisbon, Portugal). 13 | 14 | Materials available 15 | ------------------- 16 | 17 | This package includes slides (under lectures/slides). These are exactly the 18 | slides that I presented except for a few typos that became apparent during 19 | lecture. It also includes lecture aids which were mostly little pieces of code 20 | that I resorted to during class. 21 | 22 | There are a few other documents of interest, in particular, the syllabus. 23 | 24 | Contact 25 | ------- 26 | 27 | Luis Pedro Coelho 28 | Carnegie Mellon University 29 | luis@luispedro.org 30 | -------------------------------------------------------------------------------- /advertisement/documents/group-meeting-Oct28.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/advertisement/documents/group-meeting-Oct28.pdf -------------------------------------------------------------------------------- /advertisement/documents/pfs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/advertisement/documents/pfs.pdf -------------------------------------------------------------------------------- /advertisement/documents/plot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/advertisement/documents/plot.pdf -------------------------------------------------------------------------------- /advertisement/email-blurb.txt: -------------------------------------------------------------------------------- 1 | Programming for Scientists 2 | --------------------------- 3 | 4 | Instructor: Luis Pedro Coelho 5 | Course Number: 98-111 6 | Day/Time/Location: Tue & Thu 6.30pm SH 220 7 | Credit: 3 Units 8 | Prerequisites: None 9 | Grading: Pass/Fail (based on homeworks, no exams) 10 | 11 | Programming for Scientists is a course for scientists (biologists, physicists, chemists, ...) who find themselves programming with not more than an introductory programming course or even just having informally learned how to write code. 12 | 13 | The goal is to make students more effective programmers, who spend less time doing it, who write code that is more efficient, more readable, and has less bugs. A one semester course on the basics of good programming can increase programmer's productivity by 20%. Twenty per-cent is a full year of the typical PhD [numbers from Greg Wilson, U. of Toronto]. 14 | 15 | For the practical part of the course, the Python programming language will be covered. Python is a modern language which is increasingly used for scientific programming. 16 | 17 | Students who want to learn programming from scratch are welcome and will be accommodated through two extra lectures at the start of the course. 18 | -------------------------------------------------------------------------------- /advertisement/example_plot.py: -------------------------------------------------------------------------------- 1 | from numpy import * 2 | from pylab import * 3 | X=linspace(0,10,1000) 4 | Yp=sin(X)*(1.-X) 5 | points=Yp+rand(*Yp.shape)-.5 6 | plot(X[::10],points[::10],'rx') 7 | plot(X,Yp) 8 | xlabel('t') 9 | ylabel(r'$\eta(t)$') 10 | grid() 11 | savefig('plot.pdf') 12 | 13 | -------------------------------------------------------------------------------- /advertisement/presentation/.gitignore: -------------------------------------------------------------------------------- 1 | .slides.tex_files/ 2 | slides.pdf 3 | -------------------------------------------------------------------------------- /advertisement/presentation/build.sh: -------------------------------------------------------------------------------- 1 | input=slides 2 | t=.$input.tex_files 3 | test -d $t || mkdir $t 4 | cd $t 5 | TEXINPUTS=../:../../../lectures/slides/headers/:../../../lectures/slides/headers/cmu-beamer: pdflatex $input.tex 6 | cp $input.pdf .. 7 | cd 8 | -------------------------------------------------------------------------------- /advertisement/presentation/slides.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{Programming for Scientists} 3 | \date{Spring 2009} 4 | 5 | \begin{document} 6 | 7 | \frame{\maketitle} 8 | 9 | \frame{\frametitle{Introduction} 10 | 11 | \begin{block}{For Whom? What? Why?} 12 | \begin{itemize} 13 | \item For scientists who program. 14 | \item An intermediate programming class. 15 | \item To teach how to program \alert{better}. 16 | \end{itemize} 17 | \end{block} 18 | 19 | \begin{block}{Goal} 20 | A 20\% improvement in productivity. 21 | \end{block} 22 | } 23 | 24 | \frame{\frametitle{Course Structure} 25 | \begin{block}{Two Lectures a Week} 26 | \begin{enumerate} 27 | \item Tuesday session: a lecture where basic concepts are presented. 28 | \item Thursday session: a \textit{closer to the bone} session, where we discuss particular technologies that let us implement the basic concepts. 29 | \end{enumerate} 30 | \end{block} 31 | } 32 | 33 | \frame{\frametitle{Topics} 34 | 35 | \begin{block}{Main Topics} 36 | \begin{itemize} 37 | \item Code organisation. 38 | \item Software carpentry. 39 | \item Numerics. 40 | \item Software distribution. 41 | \end{itemize} 42 | \end{block} 43 | 44 | \begin{block}{Main Technologies} 45 | \begin{itemize} 46 | \item Python programming language. 47 | \item numpy \& scipy libraries. 48 | \end{itemize} 49 | \end{block} 50 | 51 | } 52 | 53 | \frame{\frametitle{F.A.Q.} 54 | 55 | \begin{block}{Can I audit the class?} 56 | You are welcome to sit-in, audit, or otherwise do whatever you think benefits you the most. 57 | \end{block} 58 | 59 | \begin{block}{I don't know any programming. Will your class be useful for me?} 60 | As long as you are prepared to work a bit a the beginning (including extra 2~lectures), this class will be a good introduction to programming. 61 | \end{block} 62 | } 63 | 64 | \frame{\frametitle{More Information} 65 | 66 | \begin{block}{Website} 67 | http://coupland.cbi.cmu.edu/pfs 68 | 69 | (Contains a detailed syllabus) 70 | \end{block} 71 | 72 | \begin{block}{Email} 73 | lpc@cmu.edu 74 | \end{block} 75 | } 76 | 77 | \end{document} 78 | -------------------------------------------------------------------------------- /documents/proposal.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/documents/proposal.pdf -------------------------------------------------------------------------------- /lectures/handouts/.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.log 3 | *.out 4 | -------------------------------------------------------------------------------- /lectures/handouts/02-bacteria/.gitignore: -------------------------------------------------------------------------------- 1 | *pyc 2 | -------------------------------------------------------------------------------- /lectures/handouts/02-bacteria/bacteria.py: -------------------------------------------------------------------------------- 1 | import random 2 | from math import exp 3 | import math 4 | 5 | def exp_dist(d,L): 6 | ''' 7 | p = exp_dist(x,lambda_) 8 | 9 | Returns the cpf the exponential distribution. 10 | 11 | See http://en.wikipedia.org/wiki/Exponential_distribution 12 | ''' 13 | return 1-math.exp(-L*d) 14 | 15 | class Bacteria(object): 16 | ''' 17 | Bacteria 18 | 19 | Implements a simple bacterium 20 | 21 | Functions: 22 | --------- 23 | 24 | * P_dead(self,e): probability of death in environment e 25 | * reproduce(): returns a new bacterium 26 | ''' 27 | L=.95 28 | def __init__(self,adaptation,sigma): 29 | self.adaptation = adaptation 30 | self.sigma = sigma 31 | def P_dead(self,e): 32 | ''' 33 | p = b.P_dead(e) 34 | 35 | Probability of death in environment e (which should be a number) 36 | ''' 37 | return exp_dist(abs(self.adaptation - e),self.L) 38 | def reproduce(self): 39 | ''' 40 | b1 = b.reproduce() 41 | 42 | Return a child of this bacterium 43 | ''' 44 | return Bacteria(self.adaptation + random.normalvariate(0,self.sigma),self.sigma) 45 | 46 | class EvolveSigma(Bacteria): 47 | ''' 48 | EvolveSigma 49 | 50 | EvolveSigma is a type of bacterium where the 51 | sigma parameter evolves at reproduction. 52 | ''' 53 | def __init__(self,adaptation,sigma): 54 | Bacteria.__init__(self,adaptation,sigma) 55 | 56 | def reproduce(self): 57 | return EvolveSigma(self.adaptation + random.normalvariate(0,self.sigma), 58 | self.sigma+random.normalvariate(0.,self.sigma/2.)) 59 | 60 | def simulate(population,environs,max_population,p_reprod): 61 | ''' 62 | simulate(population,environs) 63 | 64 | Simulate iters iterations of evolution. 65 | ''' 66 | for environ in environs: 67 | ai = 0 68 | while ai < len(population): 69 | if population[ai].P_dead(environ) < random.random(): 70 | del population[ai] 71 | else: 72 | ai += 1 73 | N = len(population) 74 | for ai in xrange(N): 75 | if random.random() < p_reprod: 76 | population.append(population[ai].reproduce()) 77 | if N >= max_population: 78 | random.shuffle(population) 79 | while len(population) >= max_population: 80 | population.pop() 81 | 82 | 83 | -------------------------------------------------------------------------------- /lectures/handouts/02-bacteria/simulatebac.py: -------------------------------------------------------------------------------- 1 | import random 2 | import bacteria 3 | 4 | def mean(values): 5 | ''' 6 | mu = mean(values) 7 | 8 | Compute a mean value. 9 | ''' 10 | return sum(values)/float(len(values)) 11 | 12 | fixed = [.234]*200 13 | sharp = [.2] * 40 + [.4]*40 + [.6]*40 + [.8]*40 + [1.]*40 14 | very_sharp = [.0] * 40 + [.5]*40 + [1.]*40 + [.5]*40 + [0.]*40 15 | smooth = [.01*i for i in xrange(200)] 16 | p_reprod = .3 17 | 18 | experiments = [ 19 | ('fixed env. no sigma evolution', 1000, 0,fixed), 20 | ('fixed env. w sigma evolution', 500,500,fixed), 21 | ('smooth changes env. w sigma evolution', 500,500,smooth), 22 | ('sharp changes env. w sigma evolution', 500,500,sharp), 23 | ('very sharp changes env. w sigma evolution', 500,500,very_sharp), 24 | ] 25 | for name, initial_fixed, initial_evolve, environs in experiments: 26 | print 'Experiment',name 27 | population = [bacteria.Bacteria(random.random(),random.random()) for i in xrange(initial_fixed)] +\ 28 | [bacteria.EvolveSigma(random.random(),random.random()) for i in xrange(initial_evolve)] 29 | bacteria.simulate(population,environs,(initial_fixed+initial_evolve)*10,p_reprod) 30 | print 'Mean sigma:', mean([a.sigma for a in population]) 31 | print 'Mean Adaptation:',mean([b.adaptation for b in population]) 32 | print 'Fraction adaptative:', mean([type(b) == bacteria.EvolveSigma for b in population]) 33 | print 34 | 35 | -------------------------------------------------------------------------------- /lectures/handouts/final/.gitignore: -------------------------------------------------------------------------------- 1 | questionaire.pdf 2 | 3 | -------------------------------------------------------------------------------- /lectures/homeworks/.gitignore: -------------------------------------------------------------------------------- 1 | *.pdf 2 | .*tex_files 3 | -------------------------------------------------------------------------------- /lectures/homeworks/01-intro-python.tex: -------------------------------------------------------------------------------- 1 | \input{hwheader} 2 | \author{Programming for Scientists} 3 | \title{Homework 1} 4 | \date{Jan 27} 5 | \begin{document} 6 | \maketitle 7 | 8 | \chapter{Questions} 9 | 10 | \question 11 | Which function returns the number of elements in a list? 12 | 13 | \question 14 | How do you access the first element of a list? How do you access the last? 15 | 16 | \question 17 | Python has two forms of adding non-code text. You use the \#~sign to start a \textit{comment} (which extends to the end of the line). Or, as we saw in class, you can use a string at the start of the function to add a \textit{documentation string}. 18 | 19 | \begin{python} 20 | def function(arg): 21 | ''' 22 | This is a documentation string. 23 | ''' 24 | print arg # this is a comment 25 | \end{python} 26 | 27 | What is, then, the difference between a comment and documentation? Why these two mechanisms? 28 | 29 | \question 30 | Alice and Bob were doing some \textit{pair programming}\footnote{Pair programming is when two programmers write code together. Normally, one will sit at the computer typing with the other will look over his shoulder to make sure he isn't making any mistakes. After a while, they switch. 31 | 32 | You might consider pair programming to help with assignments in this class.} and Alice wrote the following code: 33 | 34 | \begin{python} 35 | amount = 100 36 | interest = 5 37 | amount *= (1. + interest) 38 | 39 | print 'Value after interest:', amount 40 | \end{python} 41 | 42 | Bob argued that this would never work. ``In Python, numbers are immutable. In the line \lstinline{amount *= (1. + interest)}, you are changing the value of \lstinline{amount}. However, when they try it out, it works as Alice expected. Where is the mistake in Bob's reasoning? Are numbers mutable after all? 43 | 44 | \question 45 | What is the difference between the following two code examples: 46 | 47 | A) 48 | 49 | \begin{python} 50 | A = [1, 2, 3] 51 | B = [1, 2, 3] 52 | \end{python} 53 | 54 | B) 55 | 56 | \begin{python} 57 | A = [1, 2, 3] 58 | B = A 59 | \end{python} 60 | 61 | Write a small piece of code (should be 2 or 3 lines) that behaves differently if you insert it after each of the two segments above. 62 | 63 | \chapter{Programming Assignment} 64 | 65 | You are considering whether to enroll in a couple of different saving plans. You put some money in now and deduct some initial fee, you put in some money every month, interest accrues each month and is added to the pot (at the end of the month, just before you add in more). How much money would you have after 5 years under each plan? 66 | 67 | \begin{tabular}{lcccc} 68 | \toprule 69 | Plan Name & Fee & Initial Amount & Monthly Amount & Interest \\ 70 | \midrule 71 | Low-fee & 0 & 0 & 100 & .2\% \\ 72 | Low-interest & 20 & 100 & 50 & .02\% \\ 73 | High-initial & 100 & 1000 & 50 & .2\% \\ 74 | High-monthly & 100 & 0 & 250 & .2\% \\ 75 | High-interest & 100 & 0 & 100 & .4\% \\ 76 | \bottomrule 77 | \end{tabular} 78 | 79 | \end{document} 80 | 81 | -------------------------------------------------------------------------------- /lectures/homeworks/02-oop.tex: -------------------------------------------------------------------------------- 1 | \input{hwheader} 2 | \author{Programming for Scientists} 3 | \title{Homework 2} 4 | \date{Feb 4} 5 | \begin{document} 6 | \maketitle 7 | 8 | Since this homework was posted a day late, you get an extra day. 9 | 10 | \chapter{Questions} 11 | 12 | \question 13 | What is the \lstinline{__init__} method for? When is it called? 14 | 15 | \question 16 | In this class, we defined \textit{polymorphism} as the ability to write code that \emph{works with more than one type}. In Python, if you want code that works with two type of ``Bacteria'', that is achieved through: 17 | 18 | \begin{enumerate}[a] 19 | \item Inheritance: you define a base interface Bacterium and derive your working types from that. 20 | \item Duck-typing: your types should all have methods with the same names. 21 | \item Duck-typing: your derived type should have a name like the name of the base class (e.g., EnhancedBacterium deriving from Bacterium). 22 | \item None of the above. 23 | \end{enumerate} 24 | 25 | \question 26 | Consider the following code: 27 | 28 | \begin{python} 29 | class Point2(object): 30 | def __init__(self,x,y): 31 | self.x = x 32 | self.y = y 33 | 34 | def dist2(self): 35 | return self.x**2 + self.y**2 36 | 37 | p = Point2(2,2) 38 | print p.dist2() 39 | p.y = 0 40 | print p.dist2() 41 | print p.x 42 | print p.y 43 | \end{python} 44 | 45 | This code prints four numbers. What are they: 46 | 47 | \begin{enumerate}[a] 48 | \item 8, 8, 2, 0 49 | \item 8, 8, 2, 2 50 | \item 8, 4, 2, 0 51 | \item 8, 4, 2, 2 52 | \end{enumerate} 53 | 54 | \question 55 | What is wrong with the following code? 56 | 57 | \begin{python} 58 | mynumbers = [0,1,2,3] 59 | dictionary = {} 60 | dictionary[mynumbers] = 'Lottery Winning Key' 61 | \end{python} 62 | 63 | \question 64 | What is the difference between a \lstinline{set} and a \lstinline{frozenset}? 65 | 66 | \chapter{Programming Assignment} 67 | 68 | Recall the competing bacteria environment from class. Consider the following line of reasoning: 69 | 70 | \begin{quote} 71 | Species that mutate slowly do better when the environment is fixed, but worse when the environment is changing. Therefore, the best would be species that senses whether it is adapted to the environment and changes its reproduction mechanism to have higher mutation rates when the environment is more different from the adaptation. 72 | \end{quote} 73 | 74 | Your assignment is to 75 | 76 | \begin{enumerate} 77 | \item Formulate a reasonable mathematical formulation of the idea above. 78 | \item Implement it in Python. For this, download the file \textit{bacteria.py} from the website (this is the code used in lecture). You \textbf{should not} change the code in this file! You should simply import it and implement a new type of bacteria. The file \textit{simulatebac.py} is an example of the use of bacteria.py. You use it as a starting point or start your own script. 79 | \end{enumerate} 80 | 81 | \end{document} 82 | -------------------------------------------------------------------------------- /lectures/homeworks/03-python-odds.tex: -------------------------------------------------------------------------------- 1 | \input{hwheader} 2 | \author{Programming for Scientists} 3 | \title{Homework 3} 4 | \date{Feb 10} 5 | \begin{document} 6 | \maketitle 7 | 8 | \chapter{Questions} 9 | 10 | \question 11 | Write a piece of code that writes the string "Hello World" to a file called "hello". 12 | 13 | \question 14 | What happens if you use your code above when a file called \textit{hello} already exists? 15 | 16 | \question 17 | What's wrong with the following piece of code? How would you fix it? 18 | 19 | \begin{python} 20 | try: 21 | f(0) 22 | except Exception: 23 | print 'Some error' 24 | except IOError: 25 | print 'I/O Error' 26 | \end{python} 27 | 28 | Hint: IOError is (indirectly) derived from Exception. 29 | 30 | \question 31 | What does the following code do? 32 | 33 | \begin{python} 34 | from random import choice 35 | print choice(range(30)) 36 | \end{python} 37 | 38 | For this assignment, you might need to read the Python documentation. 39 | 40 | \chapter{Programming Assignment} 41 | 42 | Learn about the built-in function \lstinline{filter} and write two implementations of this function: one as a regular function and another as a generator (the generator is always a generator, independently of the type of the arguments). 43 | 44 | \end{document} 45 | -------------------------------------------------------------------------------- /lectures/homeworks/04-softwarecarpentry.tex: -------------------------------------------------------------------------------- 1 | \input{hwheader} 2 | \author{Programming for Scientists} 3 | \title{Homework 4} 4 | \date{Feb 17} 5 | \begin{document} 6 | \maketitle 7 | 8 | \chapter{Questions} 9 | 10 | \question % 1 11 | Alice and Bob are pair-programming again. This time, Alice writes the following code (assume that the function \lstinline{parse} is previously defined, as is \lstinline{ParseError}, which is raised when the file cannot be parsed): 12 | 13 | \begin{python} 14 | try: 15 | parse(input) 16 | ... 17 | except ParseError: 18 | print 'Error: file format unrecognised.' 19 | \end{python} 20 | 21 | Bob suggests that, since this is an error, it should be 22 | 23 | \begin{python} 24 | import sys 25 | ... 26 | 27 | try: 28 | parse(input) 29 | ... 30 | except ParseError: 31 | print >>sys.stderr, 'Error: file format unrecognised.' 32 | \end{python} 33 | 34 | Alice argues ``Both go to the screen when I run the program, so printing errors to \lstinline{sys.stderr} is just pedantic traditionalism.'' Bob says ``Well, if you run it directly, both stdout and stderr go to the screen, but you can redirect stdout or pipe it to some other program and then it makes a big difference.'' 35 | 36 | What is Bob talking about? (You can simply give an example of where things work differently if you use Bob or Alice's version.) He Bob just a pedantic traditionalist? 37 | 38 | \question % 2 39 | Recall the printargs.py script: 40 | 41 | \begin{python} 42 | import sys 43 | print len(sys.argv) 44 | print sys.argv 45 | \end{python} 46 | 47 | What gets printed when you run the following (the dollar sign is the prompt): 48 | 49 | \begin{verbatim} 50 | $python printargs.py 51 | $python printargs.py one two three 52 | $python printargs.py *.py 53 | $python printargs.py *py 54 | \end{verbatim} 55 | 56 | \chapter{Programming Assignment} 57 | Create a subversion repository in one computer and check-out in another. (You are going to have to read up on this or look through the show-me-do video: check the website for links). 58 | 59 | \begin{enumerate} 60 | \item Create a Subversion repository. 61 | \item Create a checkout in another computer. 62 | \item Add a file \texttt{hello.py} which prints 'Hello World' 63 | \item Change the file to print more things. 64 | \item Commit that change. 65 | \item Make some new change. 66 | \item Run \texttt{svn diff} and email me the results. 67 | \end{enumerate} 68 | 69 | \end{document} 70 | -------------------------------------------------------------------------------- /lectures/homeworks/05-softwarecarpentry-ii.tex: -------------------------------------------------------------------------------- 1 | \input{hwheader} 2 | \author{Programming for Scientists} 3 | \title{Homework 5} 4 | \date{Feb 24} 5 | \begin{document} 6 | \maketitle 7 | 8 | \chapter{Questions} 9 | 10 | \question % 1 11 | What is wrong with the following code? 12 | 13 | \begin{python} 14 | from os.path import exists 15 | ... 16 | 17 | assert exists(inputfilename), 'User typed in wrong file name' 18 | input = file(inputfilename) 19 | ... 20 | \end{python} 21 | 22 | \question % 2 23 | What is ``regression testing''? 24 | 25 | \question % 3 26 | Bob tells Alice that his program is running too slow and that he can't understand what's taking so long. What should Alice tell him to use to know where the code is taking up its time? 27 | 28 | \question % 4 29 | What is are some advantages of using something like nosetests to simply having a file called \texttt{tests.py} with your tests? 30 | 31 | (There are multiple answers to this question, you just need to give a couple. You can also list disadvantages.) 32 | 33 | 34 | \chapter{Programming Assignment} 35 | The first implementation of \texttt{bst.remove} that I wrote didn't correctly remove the last element of a set (calling remove() to remove the last element had no effect). Write a test for this behaviour using the nose conventions. 36 | 37 | \end{document} 38 | -------------------------------------------------------------------------------- /lectures/homeworks/06-numerical.tex: -------------------------------------------------------------------------------- 1 | \input{hwheader} 2 | \author{Programming for Scientists} 3 | \title{Homework 6} 4 | \date{Mar 3} 5 | \begin{document} 6 | \maketitle 7 | 8 | \chapter{Questions} 9 | 10 | \question % 1 11 | What is under-flow (when talking about numerical precision)? 12 | 13 | \question % 2 14 | What is the smallest value (i.e., smallest absolute value) that a 32~bit \textsc{ieee-754} float can represent? (Hint: Wikipedia has the answer to this question). 15 | 16 | \question % 3 17 | You will sometimes see the following programming idiom: 18 | 19 | \begin{python} 20 | import numpy as np 21 | mystery = np.uint32(-1) 22 | \end{python} 23 | 24 | What is the value of mystery? Why would we be interested in this particular value? (Hint: think of its bit representation). 25 | 26 | \question % 4 27 | With numpy, we saw that we could easily create an array of 32~bit numbers: 28 | 29 | \begin{python} 30 | import numpy as np 31 | A = np.array([1,2,3,4,5],np.int32) 32 | \end{python} 33 | 34 | However, it is also possible to simply use a traditional Python list: 35 | 36 | \begin{python} 37 | A = [1,2,3,4,5] 38 | \end{python} 39 | 40 | This has the advantage of using Python numbers, which are of infinite precision, instead of being limited to 32~bits. Given this obvious disadvantage, why would anyone use the 32~bit array? (There is more than one reason, but you only need to give one). 41 | 42 | \question % 5 43 | Consider the following code 44 | 45 | \begin{python} 46 | import numpy as np 47 | ... 48 | M = A.ptp(0) 49 | \end{python} 50 | 51 | If $A$ is of shape $(120,1000)$, what is the resulting shape of $M$? What does the ptp function return? 52 | 53 | \chapter{Programming Assignment} 54 | 55 | Consider the following approximation to compute an integral: 56 | 57 | \begin{equation} 58 | \int_0^{1} f(x)dx \approx \sum_{i = 0}^{999} \frac{f(i/1000)}{1000}. 59 | \end{equation} 60 | 61 | \begin{enumerate} 62 | \item Implement two versions of this for integrating $f(x) = x^2$. One should use ``pure Python'' (i.e., you should not require any \lstinline{import}s). Another should be based on \lstinline{numpy} (where you compute all the values $f(i/1000)$ in a single step). 63 | \item Determine which version is faster. (Hint: You might need to run each version a many times to be able to get a meaningful answer.) 64 | \end{enumerate} 65 | 66 | \end{document} 67 | -------------------------------------------------------------------------------- /lectures/homeworks/07-optimisation.tex: -------------------------------------------------------------------------------- 1 | \input{hwheader} 2 | \author{Programming for Scientists} 3 | \title{Homework 7} 4 | \date{Mar 17} 5 | \begin{document} 6 | \maketitle 7 | 8 | This week, you get fewer questions and a longer programming assignment. 9 | 10 | \chapter{Questions} 11 | 12 | \question % 1 13 | What is a local minimum? Is there any way to find out whether you are in a local minimum? 14 | 15 | \question % 2 16 | Newton's method is originally defined as solving for zero (i.e., solving $f(x) = 0$), but it was presented as solving a maximisation problem (i.e., $\max f(x)$). What's happening? 17 | 18 | \chapter{Programming Assignment} 19 | 20 | (1) Implement any method you'd like to find a numerical minimum to: 21 | 22 | \begin{equation} 23 | f(x) = x^6-7x^4+3x^3+2x^2-3x. 24 | \end{equation} 25 | 26 | (2) Use a pre-written method for the same task (like those in \lstinline{scipy.optimize}). 27 | 28 | \chapter{Project} 29 | 30 | \textbf{This is for everyone.} Please email me your preferences for the class project. 31 | 32 | \end{document} 33 | -------------------------------------------------------------------------------- /lectures/homeworks/08-open-source.tex: -------------------------------------------------------------------------------- 1 | \input{hwheader} 2 | \author{Programming for Scientists} 3 | \title{Homework 8} 4 | \date{Apr 5} 5 | \begin{document} 6 | \maketitle 7 | 8 | \chapter{Questions} 9 | 10 | \question 11 | What is the main difference between the GPL and a BSD-like license? 12 | 13 | \question 14 | What is ``free as in beer''? 15 | 16 | \question 17 | What is (in broad strokes) Creative Commons By-SA-NC? 18 | 19 | \question 20 | What does it mean to say that BSD is ``GPL compatible''? 21 | 22 | \question 23 | Can you sell free software? 24 | 25 | \end{document} 26 | 27 | -------------------------------------------------------------------------------- /lectures/homeworks/09-fileparsing.tex: -------------------------------------------------------------------------------- 1 | \input{hwheader} 2 | \author{Programming for Scientists} 3 | \title{Homework 8} 4 | \date{Apr 5} 5 | \begin{document} 6 | \maketitle 7 | 8 | \chapter{Questions} 9 | 10 | \question 11 | What is a text file? 12 | 13 | \question 14 | What does it mean to say that a file has ``Unix line endings''? 15 | 16 | \question 17 | What does the following regular expression match? 18 | 19 | \begin{python} 20 | import re 21 | pattern = re.compile(r'\d{2}-\d{2}-\d{2,4}') 22 | \end{python} 23 | 24 | This uses functionality not covered in class. Look up the \texttt{re} module. 25 | 26 | \chapter{Programming Assignment} 27 | 28 | The following is the start of a file containing sparse arrays of numbers: 29 | 30 | \begin{verbatim} 31 | 100 13 32 | 1:0.7 2:1 3:1 4:-0.3 7:-0.1 33 | 1:0.5 2:-1 3:0.333333 6:-0.603774 10:1 34 | 1:0.1 2:1 4:-0.333334 5:-0.433962 9:-0.383562 6:-1 35 | 1:0.4 2:1 4:1 4:-0.358491 10:0.374429 11:-1 12:-1 36 | 2:-1 3:-0.333333 4:-0.509434 5:-0.347032 6:-1 7:1 37 | 1:0.5 2:1 3:1 4:-0.509434 5:-0.767123 6:-1 7:-1 8:0.0534351 38 | \end{verbatim} 39 | 40 | The exact format is as follows: the first line has two numbers: the number of arrays and the length of each array. Each subsequent line represents an array. The array is represented as a space-separated list of pairs \textit{idx:value} where \textit{idx} is the index on an entry and \textit{value} is its value. Entries without a value are zero. For example, the first array is $(.7,1,1,-0.3,0,0,-.1,0,0,0,0,0,0)$ 41 | 42 | Write a function that parses this file and returns a numpy array with the values. 43 | 44 | \end{document} 45 | 46 | -------------------------------------------------------------------------------- /lectures/homeworks/Makefile: -------------------------------------------------------------------------------- 1 | pdfs := $(patsubst %.tex,%.pdf,$(wildcard *.tex)) 2 | all: $(pdfs) 3 | 4 | .PHONY: all 5 | 6 | %.pdf: %.tex 7 | ./do-hw.sh $< 8 | -------------------------------------------------------------------------------- /lectures/homeworks/do-hw.sh: -------------------------------------------------------------------------------- 1 | t=.$1.tex_files 2 | test -d $t || mkdir $t 3 | cd $t 4 | TEXINPUTS=:..:../headers:../headers/cmu-beamer: pdflatex $1 5 | cp `basename $1 tex`pdf .. 6 | cd 7 | -------------------------------------------------------------------------------- /lectures/homeworks/headers/hwheader.tex: -------------------------------------------------------------------------------- 1 | \documentclass[article,twoside]{memoir} 2 | \usepackage[latin9]{inputenc} 3 | \usepackage{eepic} 4 | \usepackage{color} 5 | \usepackage{amsmath} 6 | \usepackage{amssymb} 7 | \usepackage{bm} 8 | \usepackage{amsfonts} 9 | \usepackage{amsthm} 10 | \usepackage[vlined,linesnumbered,ruled]{algorithm2e} 11 | %\usepackage[]{pgf} 12 | \usepackage[]{graphicx} 13 | \usepackage{python} 14 | 15 | \graphicspath{{../figures/other/}{../figures/generated/}} 16 | 17 | 18 | \DeclareMathOperator*{\argmax}{arg\,max} 19 | \DeclareMathOperator*{\argmin}{arg\,min} 20 | 21 | \newcommand{\pd}[2]{\frac{\partial#1}{\partial#2}} 22 | \newcommand{\pdd}[2]{\frac{\partial^2 #1}{\partial #2^2}} 23 | \newcommand{\pdpd}[3]{\frac{\partial^2 #1}{\partial #2 \partial #3}} 24 | \newcommand{\B}{\ensuremath{\mathbb{B}}} 25 | \newcommand*{\Pa}{\ensuremath{\text{\upshape\textbf{Pa}}}} 26 | \newcommand*{\Dkl}{\ensuremath{D_{\text{\textsc{kl}}}}} 27 | \newcommand*{\encspace}{\quad} 28 | 29 | \newtheorem{theorem}{Theorem} 30 | \newtheorem{lemma}{Lemma} 31 | \newtheorem{definition}{Definition} 32 | 33 | \newcommand*{\slantfrac}[2]{\hbox{$\raisebox{-.4ex}{$\,^#1$}\!/_#2$}} 34 | \newcommand*{\dx}{\,dx} 35 | \newcommand*{\dt}{\,dt} 36 | 37 | \newcommand*{\Expected}{\ensuremath{\mathbb{E}}} 38 | \newcommand*{\Var}{\ensuremath{\text{Var}}} 39 | \newcommand*{\Reals}{\ensuremath{\mathbb{R}}} 40 | \newcommand*{\Binary}{\ensuremath{\mathbb{B}}} 41 | \newcommand*{\discr}{\mbox{discr}} 42 | \newcommand*{\from}{\leftarrow} 43 | 44 | \newcommand*{\indicator}[1]{\hspace{1pt}[\hspace{-.4em}[\hspace{3pt} #1 \hspace{3pt}]\hspace{-.4em}]\hspace{2pt}} 45 | \newcommand*{\Assign}{\ensuremath\,:=\,} 46 | \newcommand*{\vect}[1]{\ensuremath{\bm{#1}}} 47 | \newcommand*{\textvalue}[1]{\mbox{\textsl{#1}}} 48 | \newcommand*{\bigO}{\mathcal{O}} 49 | \newcommand*{\MI}{\mbox{MI}} 50 | 51 | \DeclareMathOperator{\goodness}{score} 52 | \DeclareMathOperator{\powerset}{Pow} 53 | 54 | \title{Student Survey} 55 | \author{Programming for Scientists} 56 | 57 | \bibliographystyle{alpha} 58 | %\bibliographystyle{plain} 59 | \pagestyle{plain} 60 | 61 | \aliaspagestyle{chapter}{Ruled} 62 | 63 | %Change fonts: Page number sans-serif (much cleaner than the roman version) 64 | \def\pagenumberfont{\sffamily} 65 | % Change fonts: Section headers Sans-Serif: 66 | \setsecheadstyle{\Large\sffamily\raggedright} 67 | \setsubsecheadstyle{\large\sffamily\raggedright} 68 | \setsubsubsecheadstyle{\normalsize\sffamily\raggedright} 69 | 70 | % Title 71 | \pretitle{\LARGE\sffamily} 72 | \posttitle{\par\vspace{4ex}} 73 | \preauthor{\large\sffamily\hspace{1cm}} 74 | \postauthor{\par\vspace{3ex}} 75 | \predate{\small\sffamily\hspace{1cm}Due on: } 76 | \postdate{\par\vspace{2cm}} 77 | \copypagestyle{title}{plain} 78 | \makeoddfoot{title}{}{}{} 79 | \makeevenfoot{title}{}{}{} 80 | 81 | \renewcommand{\abstractnamefont}{\sffamily} 82 | \renewcommand{\abstracttextfont}{} 83 | \renewcommand{\absnamepos}{flushleft} 84 | 85 | 86 | \makechapterstyle{mestrado}{% Originally ``AlexanderGrebenkov'', adapted 87 | \renewcommand{\chapterheadstart}{\goodbreak\vspace*{\beforechapskip}\medskip} 88 | \renewcommand{\chapnamefont}{\normalfont\Large\scshape} 89 | \renewcommand{\chapnumfont}{\normalfont\Large\scshape} 90 | \renewcommand{\chaptitlefont}{\normalfont\Large\scshape} 91 | \renewcommand{\printchaptername}{} 92 | \renewcommand{\chapternamenum}{} 93 | \renewcommand{\printchapternum}{\normalfont\Large\scshape\S\thechapter} 94 | \renewcommand{\afterchapternum}{\hspace{1em}} 95 | \renewcommand{\afterchaptertitle}{\par\nobreak\vspace{-.9em}\moveright 6pt\vbox to 1pt{\hrule width .64\textwidth}\nobreak\vskip\afterchapskip\nobreak} 96 | } 97 | \chapterstyle{mestrado} 98 | 99 | \SetCommentSty{textsl} 100 | 101 | \newcounter{questioncnt} 102 | \newcommand*{\question}{\addtocounter{questioncnt}{1}\par\medskip\noindent\textbf{Question \Roman{questioncnt}: }} 103 | 104 | -------------------------------------------------------------------------------- /lectures/homeworks/headers/python.sty: -------------------------------------------------------------------------------- 1 | \usepackage{listings} 2 | \usepackage{textcomp} 3 | \usepackage{setspace} 4 | \usepackage{palatino} 5 | 6 | \renewcommand{\lstlistlistingname}{Code Listings} 7 | \renewcommand{\lstlistingname}{Code Listing} 8 | \definecolor{gray}{gray}{0.5} 9 | \definecolor{green}{rgb}{0,0.5,0} 10 | \definecolor{darkred}{rgb}{0.5,0,0} 11 | \definecolor{darkgreen}{rgb}{0,0.3,0} 12 | \definecolor{darkblue}{rgb}{0,0,0.5} 13 | 14 | \lstnewenvironment{python}[1][]{ 15 | \lstset{ 16 | language=python, 17 | basicstyle=\ttfamily\small,%\setstretch{1}, 18 | stringstyle=\color{darkred}, 19 | showstringspaces=false, 20 | alsoletter={1234567890}, 21 | otherkeywords={\ , \}, \{}, 22 | keywordstyle=\color{darkblue}, 23 | emph={access,and,break,class,continue,def,del,elif,else,% 24 | except,exec,finally,for,from,global,if,import,in,is,% 25 | lambda,not,or,pass,print,raise,return,try,while}, 26 | emphstyle=\color{darkgreen}\bfseries, 27 | emph={[2]True, False, None, self}, 28 | emphstyle=[2]\color{darkgreen}, 29 | emph={[3]from, import, as}, 30 | emphstyle=[3]\color{darkblue}, 31 | upquote=true, 32 | morecomment=[s]{"""}{"""}, 33 | commentstyle=\color{gray}\slshape, 34 | emph={[4]1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 35 | emphstyle=[4]\color{darkred}, 36 | literate=*% 37 | {:}{{\textcolor{darkblue}:}}{1}% 38 | {=}{{\textcolor{darkblue}=}}{1}% 39 | {-}{{\textcolor{darkblue}-}}{1}% 40 | {+}{{\textcolor{darkblue}+}}{1}% 41 | {/}{{\textcolor{darkblue}/}}{1}% 42 | {*}{{\textcolor{darkblue}*}}{1}% 43 | {!}{{\textcolor{darkblue}!}}{1}% 44 | {(}{{\textcolor{darkblue}(}}{1}% 45 | {)}{{\textcolor{darkblue})}}{1}% 46 | {[}{{\textcolor{darkblue}[}}{1}% 47 | {]}{{\textcolor{darkblue}]}}{1}% 48 | {<}{{\textcolor{darkblue}<}}{1}% 49 | {>}{{\textcolor{darkblue}>}}{1},% 50 | framexleftmargin=1em, framextopmargin=1mm, frame=leftline,#1 51 | }}{} 52 | 53 | -------------------------------------------------------------------------------- /lectures/lecture-aids/.gitignore: -------------------------------------------------------------------------------- 1 | *pyc 2 | -------------------------------------------------------------------------------- /lectures/lecture-aids/02L-python-odds-and-ends/generator.py: -------------------------------------------------------------------------------- 1 | def xrange_like(stop): 2 | i = 0 3 | while i < stop: 4 | print 'in xrange_like' 5 | yield i 6 | i += 1 7 | 8 | 9 | for val in xrange_like(10): 10 | print 'val:', val 11 | 12 | -------------------------------------------------------------------------------- /lectures/lecture-aids/02L-python-odds-and-ends/integrate01.py: -------------------------------------------------------------------------------- 1 | def integrate01(f): 2 | ''' 3 | int_f = integrate01(f) 4 | ... 5 | ''' 6 | res = 0.0 7 | for x in xrange(1000): 8 | res += f(x/1000.)/1000. 9 | return res 10 | 11 | def identity(x): 12 | return x 13 | 14 | def square(x): 15 | return x**2 16 | 17 | 18 | -------------------------------------------------------------------------------- /lectures/lecture-aids/02L-python-odds-and-ends/kwargs.py: -------------------------------------------------------------------------------- 1 | def print_args(arg0,arg1,*args,**kwargs): 2 | ''' 3 | print_args(arg0,arg1,*args,**kwargs) 4 | 5 | Demonstrates Python's fancy argument passing. 6 | ''' 7 | 8 | print 'Arg 0:', arg0 9 | print 'Arg 1:', arg1 10 | print 'Nr Variable Args:', len(args) 11 | print 'Args:', args 12 | print 'KwArgs:', kwargs 13 | -------------------------------------------------------------------------------- /lectures/lecture-aids/03-odds-ii-errors/divide_by_0.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | x = 0 4 | y = 1/x 5 | except IOError: 6 | print 'i-o error' 7 | except ArithmeticError: 8 | print 'arithmetic error' 9 | except ZeroDivisionError: 10 | print 'divide by zero error' 11 | except: 12 | print 'generic error' 13 | 14 | 15 | try: 16 | x = 0 17 | y = 1/x 18 | except ZeroDivisionError: 19 | print 'divide by zero error' 20 | except ArithmeticError: 21 | print 'arithmetic error' 22 | except: 23 | print 'generic error' 24 | -------------------------------------------------------------------------------- /lectures/lecture-aids/03-odds-ii-errors/fasta.py: -------------------------------------------------------------------------------- 1 | def count_fasta_seqs(filename): 2 | ''' 3 | N = count_fasta_seqs(fname) 4 | 5 | Count the number of sequences in FASTA file. 6 | ''' 7 | nseqs = 0 8 | for line in file(filename): 9 | if line.startswith('>'): 10 | nseqs += 1 11 | return nseqs 12 | 13 | try: 14 | N = count_fasta_seqs('this-file-does-not-exist') 15 | print 'File has %s sequences' % N 16 | except Exception: 17 | print 'generic exception' 18 | 19 | 20 | try: 21 | N = count_fasta_seqs('this-file-does-not-exist') 22 | print 'File has %s sequences' % N 23 | except IOError, exc: 24 | print 'IOError', exc 25 | except Exception: 26 | print 'generic exception' 27 | 28 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04-softwarecarpentry/printargs.py: -------------------------------------------------------------------------------- 1 | import sys 2 | print len(sys.argv) 3 | print sys.argv 4 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/fix_zero.patch: -------------------------------------------------------------------------------- 1 | diff --git a/pyslic/preprocess/preprocesscollection.py b/pyslic/preprocess/preprocesscollection.py 2 | index f060b8a..a8cd9ec 100644 3 | --- a/pyslic/preprocess/preprocesscollection.py 4 | +++ b/pyslic/preprocess/preprocesscollection.py 5 | @@ -120,7 +120,10 @@ class FixIllumination(object): 6 | @see see 7 | ''' 8 | assert self.S is not None 9 | - self.S /= self.S.min() 10 | + Smin = self.S.min() 11 | + if Smin == 0: 12 | + Smin = 1 13 | + self.S /= Smin 14 | # float96 is not always very well supported and we no longer need to sum up lots of numbers 15 | self.S = numpy.array(self.S,float) 16 | 17 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-checkout/.svn/entries: -------------------------------------------------------------------------------- 1 | 9 2 | 3 | dir 4 | 1 5 | file:///home/luispedro/work/pfs/lectures/lecture-aids/04-softwarecarpentry/svn-repository/trunk 6 | file:///home/luispedro/work/pfs/lectures/lecture-aids/04-softwarecarpentry/svn-repository 7 | 8 | 9 | 10 | 2009-02-03T21:56:52.310294Z 11 | 1 12 | luispedro 13 | 14 | 15 | svn:special svn:externals svn:needs-lock 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 205593bf-7b02-46f4-ba05-aa1cf0852c53 28 | 29 | hello.py 30 | file 31 | 2 32 | 33 | 34 | 35 | 2009-02-03T21:57:28.000000Z 36 | dd143c9d7342e4e6584017a873f9394c 37 | 2009-02-03T21:57:42.925104Z 38 | 2 39 | luispedro 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 20 62 | 63 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-checkout/.svn/format: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-checkout/.svn/text-base/hello.py.svn-base: -------------------------------------------------------------------------------- 1 | print 'Hello World' 2 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-checkout/hello.py: -------------------------------------------------------------------------------- 1 | print 'Hello World' 2 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/README.txt: -------------------------------------------------------------------------------- 1 | This is a Subversion repository; use the 'svnadmin' tool to examine 2 | it. Do not add, delete, or modify files here unless you know how 3 | to avoid corrupting the repository. 4 | 5 | Visit http://subversion.tigris.org/ for more information. 6 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/conf/authz: -------------------------------------------------------------------------------- 1 | ### This file is an example authorization file for svnserve. 2 | ### Its format is identical to that of mod_authz_svn authorization 3 | ### files. 4 | ### As shown below each section defines authorizations for the path and 5 | ### (optional) repository specified by the section name. 6 | ### The authorizations follow. An authorization line can refer to: 7 | ### - a single user, 8 | ### - a group of users defined in a special [groups] section, 9 | ### - an alias defined in a special [aliases] section, 10 | ### - all authenticated users, using the '$authenticated' token, 11 | ### - only anonymous users, using the '$anonymous' token, 12 | ### - anyone, using the '*' wildcard. 13 | ### 14 | ### A match can be inverted by prefixing the rule with '~'. Rules can 15 | ### grant read ('r') access, read-write ('rw') access, or no access 16 | ### (''). 17 | 18 | [aliases] 19 | # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average 20 | 21 | [groups] 22 | # harry_and_sally = harry,sally 23 | # harry_sally_and_joe = harry,sally,&joe 24 | 25 | # [/foo/bar] 26 | # harry = rw 27 | # &joe = r 28 | # * = 29 | 30 | # [repository:/baz/fuz] 31 | # @harry_and_sally = rw 32 | # * = r 33 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/conf/passwd: -------------------------------------------------------------------------------- 1 | ### This file is an example password file for svnserve. 2 | ### Its format is similar to that of svnserve.conf. As shown in the 3 | ### example below it contains one section labelled [users]. 4 | ### The name and password for each user follow, one account per line. 5 | 6 | [users] 7 | # harry = harryssecret 8 | # sally = sallyssecret 9 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/conf/svnserve.conf: -------------------------------------------------------------------------------- 1 | ### This file controls the configuration of the svnserve daemon, if you 2 | ### use it to allow access to this repository. (If you only allow 3 | ### access through http: and/or file: URLs, then this file is 4 | ### irrelevant.) 5 | 6 | ### Visit http://subversion.tigris.org/ for more information. 7 | 8 | [general] 9 | ### These options control access to the repository for unauthenticated 10 | ### and authenticated users. Valid values are "write", "read", 11 | ### and "none". The sample settings below are the defaults. 12 | # anon-access = read 13 | # auth-access = write 14 | ### The password-db option controls the location of the password 15 | ### database file. Unless you specify a path starting with a /, 16 | ### the file's location is relative to the directory containing 17 | ### this configuration file. 18 | ### If SASL is enabled (see below), this file will NOT be used. 19 | ### Uncomment the line below to use the default password file. 20 | # password-db = passwd 21 | ### The authz-db option controls the location of the authorization 22 | ### rules for path-based access control. Unless you specify a path 23 | ### starting with a /, the file's location is relative to the the 24 | ### directory containing this file. If you don't specify an 25 | ### authz-db, no path-based access control is done. 26 | ### Uncomment the line below to use the default authorization file. 27 | # authz-db = authz 28 | ### This option specifies the authentication realm of the repository. 29 | ### If two repositories have the same authentication realm, they should 30 | ### have the same password database, and vice versa. The default realm 31 | ### is repository's uuid. 32 | # realm = My First Repository 33 | 34 | [sasl] 35 | ### This option specifies whether you want to use the Cyrus SASL 36 | ### library for authentication. Default is false. 37 | ### This section will be ignored if svnserve is not built with Cyrus 38 | ### SASL support; to check, run 'svnserve --version' and look for a line 39 | ### reading 'Cyrus SASL authentication is available.' 40 | # use-sasl = true 41 | ### These options specify the desired strength of the security layer 42 | ### that you want SASL to provide. 0 means no encryption, 1 means 43 | ### integrity-checking only, values larger than 1 are correlated 44 | ### to the effective key length for encryption (e.g. 128 means 128-bit 45 | ### encryption). The values below are the defaults. 46 | # min-encryption = 0 47 | # max-encryption = 256 48 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/current: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/format: -------------------------------------------------------------------------------- 1 | 3 2 | layout sharded 1000 3 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/fs-type: -------------------------------------------------------------------------------- 1 | fsfs 2 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/revprops/0/0: -------------------------------------------------------------------------------- 1 | K 8 2 | svn:date 3 | V 27 4 | 2009-02-03T21:55:55.509309Z 5 | END 6 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/revprops/0/1: -------------------------------------------------------------------------------- 1 | K 10 2 | svn:author 3 | V 9 4 | luispedro 5 | K 8 6 | svn:date 7 | V 27 8 | 2009-02-03T21:56:52.310294Z 9 | K 7 10 | svn:log 11 | V 16 12 | Usual structure 13 | 14 | END 15 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/revprops/0/2: -------------------------------------------------------------------------------- 1 | K 10 2 | svn:author 3 | V 9 4 | luispedro 5 | K 8 6 | svn:date 7 | V 27 8 | 2009-02-03T21:57:42.925104Z 9 | K 7 10 | svn:log 11 | V 12 12 | Hello World 13 | 14 | END 15 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/revs/0/0: -------------------------------------------------------------------------------- 1 | PLAIN 2 | END 3 | ENDREP 4 | id: 0.0.r0/17 5 | type: dir 6 | count: 0 7 | text: 0 0 4 4 2d2977d1c96f487abe4a1e202dd03b4e 8 | cpath: / 9 | 10 | 11 | 17 107 12 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/revs/0/1: -------------------------------------------------------------------------------- 1 | id: 2-1.0.r1/0 2 | type: dir 3 | count: 0 4 | cpath: /trunk 5 | copyroot: 0 / 6 | 7 | id: 0-1.0.r1/63 8 | type: dir 9 | count: 0 10 | cpath: /branches 11 | copyroot: 0 / 12 | 13 | id: 1-1.0.r1/130 14 | type: dir 15 | count: 0 16 | cpath: /tags 17 | copyroot: 0 / 18 | 19 | PLAIN 20 | K 8 21 | branches 22 | V 15 23 | dir 0-1.0.r1/63 24 | K 4 25 | tags 26 | V 16 27 | dir 1-1.0.r1/130 28 | K 5 29 | trunk 30 | V 14 31 | dir 2-1.0.r1/0 32 | END 33 | ENDREP 34 | id: 0.0.r1/306 35 | type: dir 36 | pred: 0.0.r0/17 37 | count: 1 38 | text: 1 194 99 99 f518773917d40d257c04097c223eb7d3 39 | cpath: / 40 | copyroot: 0 / 41 | 42 | _2.0.t0-0 add false false /trunk 43 | 44 | _0.0.t0-0 add false false /branches 45 | 46 | _1.0.t0-0 add false false /tags 47 | 48 | 49 | 306 431 50 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/revs/0/2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/revs/0/2 -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/txn-current: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/txn-current-lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/txn-current-lock -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/uuid: -------------------------------------------------------------------------------- 1 | 205593bf-7b02-46f4-ba05-aa1cf0852c53 2 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/write-lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/lecture-aids/04L-softwarecarpentry/svn-repository/db/write-lock -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/format: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/hooks/post-commit.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # POST-COMMIT HOOK 4 | # 5 | # The post-commit hook is invoked after a commit. Subversion runs 6 | # this hook by invoking a program (script, executable, binary, etc.) 7 | # named 'post-commit' (for which this file is a template) with the 8 | # following ordered arguments: 9 | # 10 | # [1] REPOS-PATH (the path to this repository) 11 | # [2] REV (the number of the revision just committed) 12 | # 13 | # The default working directory for the invocation is undefined, so 14 | # the program should set one explicitly if it cares. 15 | # 16 | # Because the commit has already completed and cannot be undone, 17 | # the exit code of the hook program is ignored. The hook program 18 | # can use the 'svnlook' utility to help it examine the 19 | # newly-committed tree. 20 | # 21 | # On a Unix system, the normal procedure is to have 'post-commit' 22 | # invoke other programs to do the real work, though it may do the 23 | # work itself too. 24 | # 25 | # Note that 'post-commit' must be executable by the user(s) who will 26 | # invoke it (typically the user httpd runs as), and that user must 27 | # have filesystem-level permission to access the repository. 28 | # 29 | # On a Windows system, you should name the hook program 30 | # 'post-commit.bat' or 'post-commit.exe', 31 | # but the basic idea is the same. 32 | # 33 | # The hook program typically does not inherit the environment of 34 | # its parent process. For example, a common problem is for the 35 | # PATH environment variable to not be set to its usual value, so 36 | # that subprograms fail to launch unless invoked via absolute path. 37 | # If you're having unexpected problems with a hook program, the 38 | # culprit may be unusual (or missing) environment variables. 39 | # 40 | # Here is an example hook script, for a Unix /bin/sh interpreter. 41 | # For more examples and pre-written hooks, see those in 42 | # the Subversion repository at 43 | # http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/ and 44 | # http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/ 45 | 46 | 47 | REPOS="$1" 48 | REV="$2" 49 | 50 | /usr/share/subversion/hook-scripts/commit-email.pl \ 51 | "$REPOS" "$REV" commit-watchers@example.org 52 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/hooks/post-lock.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # POST-LOCK HOOK 4 | # 5 | # The post-lock hook is run after a path is locked. Subversion runs 6 | # this hook by invoking a program (script, executable, binary, etc.) 7 | # named 'post-lock' (for which this file is a template) with the 8 | # following ordered arguments: 9 | # 10 | # [1] REPOS-PATH (the path to this repository) 11 | # [2] USER (the user who created the lock) 12 | # 13 | # The paths that were just locked are passed to the hook via STDIN (as 14 | # of Subversion 1.2, only one path is passed per invocation, but the 15 | # plan is to pass all locked paths at once, so the hook program 16 | # should be written accordingly). 17 | # 18 | # The default working directory for the invocation is undefined, so 19 | # the program should set one explicitly if it cares. 20 | # 21 | # Because the lock has already been created and cannot be undone, 22 | # the exit code of the hook program is ignored. The hook program 23 | # can use the 'svnlook' utility to help it examine the 24 | # newly-created lock. 25 | # 26 | # On a Unix system, the normal procedure is to have 'post-lock' 27 | # invoke other programs to do the real work, though it may do the 28 | # work itself too. 29 | # 30 | # Note that 'post-lock' must be executable by the user(s) who will 31 | # invoke it (typically the user httpd runs as), and that user must 32 | # have filesystem-level permission to access the repository. 33 | # 34 | # On a Windows system, you should name the hook program 35 | # 'post-lock.bat' or 'post-lock.exe', 36 | # but the basic idea is the same. 37 | # 38 | # Here is an example hook script, for a Unix /bin/sh interpreter: 39 | 40 | REPOS="$1" 41 | USER="$2" 42 | 43 | # Send email to interested parties, let them know a lock was created: 44 | /usr/share/subversion/hook-scripts/mailer/mailer.py lock \ 45 | "$REPOS" "$USER" "$REPOS"/hooks/mailer.conf 46 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/hooks/post-revprop-change.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # POST-REVPROP-CHANGE HOOK 4 | # 5 | # The post-revprop-change hook is invoked after a revision property 6 | # has been added, modified or deleted. Subversion runs this hook by 7 | # invoking a program (script, executable, binary, etc.) named 8 | # 'post-revprop-change' (for which this file is a template), with the 9 | # following ordered arguments: 10 | # 11 | # [1] REPOS-PATH (the path to this repository) 12 | # [2] REV (the revision that was tweaked) 13 | # [3] USER (the username of the person tweaking the property) 14 | # [4] PROPNAME (the property that was changed) 15 | # [5] ACTION (the property was 'A'dded, 'M'odified, or 'D'eleted) 16 | # 17 | # [STDIN] PROPVAL ** the old property value is passed via STDIN. 18 | # 19 | # Because the propchange has already completed and cannot be undone, 20 | # the exit code of the hook program is ignored. The hook program 21 | # can use the 'svnlook' utility to help it examine the 22 | # new property value. 23 | # 24 | # On a Unix system, the normal procedure is to have 'post-revprop-change' 25 | # invoke other programs to do the real work, though it may do the 26 | # work itself too. 27 | # 28 | # Note that 'post-revprop-change' must be executable by the user(s) who will 29 | # invoke it (typically the user httpd runs as), and that user must 30 | # have filesystem-level permission to access the repository. 31 | # 32 | # On a Windows system, you should name the hook program 33 | # 'post-revprop-change.bat' or 'post-revprop-change.exe', 34 | # but the basic idea is the same. 35 | # 36 | # The hook program typically does not inherit the environment of 37 | # its parent process. For example, a common problem is for the 38 | # PATH environment variable to not be set to its usual value, so 39 | # that subprograms fail to launch unless invoked via absolute path. 40 | # If you're having unexpected problems with a hook program, the 41 | # culprit may be unusual (or missing) environment variables. 42 | # 43 | # Here is an example hook script, for a Unix /bin/sh interpreter. 44 | # For more examples and pre-written hooks, see those in 45 | # the Subversion repository at 46 | # http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/ and 47 | # http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/ 48 | 49 | 50 | REPOS="$1" 51 | REV="$2" 52 | USER="$3" 53 | PROPNAME="$4" 54 | ACTION="$5" 55 | 56 | /usr/share/subversion/hook-scripts/commit-email.pl --revprop-change \ 57 | "$REPOS" "$REV" "$USER" "$PROPNAME" watchers@example.org 58 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/hooks/post-unlock.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # POST-UNLOCK HOOK 4 | # 5 | # The post-unlock hook runs after a path is unlocked. Subversion runs 6 | # this hook by invoking a program (script, executable, binary, etc.) 7 | # named 'post-unlock' (for which this file is a template) with the 8 | # following ordered arguments: 9 | # 10 | # [1] REPOS-PATH (the path to this repository) 11 | # [2] USER (the user who destroyed the lock) 12 | # 13 | # The paths that were just unlocked are passed to the hook via STDIN 14 | # (as of Subversion 1.2, only one path is passed per invocation, but 15 | # the plan is to pass all unlocked paths at once, so the hook program 16 | # should be written accordingly). 17 | # 18 | # The default working directory for the invocation is undefined, so 19 | # the program should set one explicitly if it cares. 20 | # 21 | # Because the lock has already been destroyed and cannot be undone, 22 | # the exit code of the hook program is ignored. 23 | # 24 | # On a Unix system, the normal procedure is to have 'post-unlock' 25 | # invoke other programs to do the real work, though it may do the 26 | # work itself too. 27 | # 28 | # Note that 'post-unlock' must be executable by the user(s) who will 29 | # invoke it (typically the user httpd runs as), and that user must 30 | # have filesystem-level permission to access the repository. 31 | # 32 | # On a Windows system, you should name the hook program 33 | # 'post-unlock.bat' or 'post-unlock.exe', 34 | # but the basic idea is the same. 35 | # 36 | # Here is an example hook script, for a Unix /bin/sh interpreter: 37 | 38 | REPOS="$1" 39 | USER="$2" 40 | 41 | # Send email to interested parties, let them know a lock was removed: 42 | /usr/share/subversion/hook-scripts/mailer.py unlock \ 43 | "$REPOS" "$USER" "$REPOS"/mailer.conf 44 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/hooks/pre-commit.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # PRE-COMMIT HOOK 4 | # 5 | # The pre-commit hook is invoked before a Subversion txn is 6 | # committed. Subversion runs this hook by invoking a program 7 | # (script, executable, binary, etc.) named 'pre-commit' (for which 8 | # this file is a template), with the following ordered arguments: 9 | # 10 | # [1] REPOS-PATH (the path to this repository) 11 | # [2] TXN-NAME (the name of the txn about to be committed) 12 | # 13 | # The default working directory for the invocation is undefined, so 14 | # the program should set one explicitly if it cares. 15 | # 16 | # If the hook program exits with success, the txn is committed; but 17 | # if it exits with failure (non-zero), the txn is aborted, no commit 18 | # takes place, and STDERR is returned to the client. The hook 19 | # program can use the 'svnlook' utility to help it examine the txn. 20 | # 21 | # On a Unix system, the normal procedure is to have 'pre-commit' 22 | # invoke other programs to do the real work, though it may do the 23 | # work itself too. 24 | # 25 | # *** NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT *** 26 | # *** FOR REVISION PROPERTIES (like svn:log or svn:author). *** 27 | # 28 | # This is why we recommend using the read-only 'svnlook' utility. 29 | # In the future, Subversion may enforce the rule that pre-commit 30 | # hooks should not modify the versioned data in txns, or else come 31 | # up with a mechanism to make it safe to do so (by informing the 32 | # committing client of the changes). However, right now neither 33 | # mechanism is implemented, so hook writers just have to be careful. 34 | # 35 | # Note that 'pre-commit' must be executable by the user(s) who will 36 | # invoke it (typically the user httpd runs as), and that user must 37 | # have filesystem-level permission to access the repository. 38 | # 39 | # On a Windows system, you should name the hook program 40 | # 'pre-commit.bat' or 'pre-commit.exe', 41 | # but the basic idea is the same. 42 | # 43 | # The hook program typically does not inherit the environment of 44 | # its parent process. For example, a common problem is for the 45 | # PATH environment variable to not be set to its usual value, so 46 | # that subprograms fail to launch unless invoked via absolute path. 47 | # If you're having unexpected problems with a hook program, the 48 | # culprit may be unusual (or missing) environment variables. 49 | # 50 | # Here is an example hook script, for a Unix /bin/sh interpreter. 51 | # For more examples and pre-written hooks, see those in 52 | # the Subversion repository at 53 | # http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/ and 54 | # http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/ 55 | 56 | 57 | REPOS="$1" 58 | TXN="$2" 59 | 60 | # Make sure that the log message contains some text. 61 | SVNLOOK=/usr/bin/svnlook 62 | $SVNLOOK log -t "$TXN" "$REPOS" | \ 63 | grep "[a-zA-Z0-9]" > /dev/null || exit 1 64 | 65 | # Check that the author of this commit has the rights to perform 66 | # the commit on the files and directories being modified. 67 | /usr/share/subversion/hook-scripts/commit-access-control.pl \ 68 | "$REPOS" "$TXN" "$REPOS"/commit-access-control.cfg || exit 1 69 | 70 | # All checks passed, so allow the commit. 71 | exit 0 72 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/hooks/pre-lock.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # PRE-LOCK HOOK 4 | # 5 | # The pre-lock hook is invoked before an exclusive lock is 6 | # created. Subversion runs this hook by invoking a program 7 | # (script, executable, binary, etc.) named 'pre-lock' (for which 8 | # this file is a template), with the following ordered arguments: 9 | # 10 | # [1] REPOS-PATH (the path to this repository) 11 | # [2] PATH (the path in the repository about to be locked) 12 | # [3] USER (the user creating the lock) 13 | # 14 | # The default working directory for the invocation is undefined, so 15 | # the program should set one explicitly if it cares. 16 | # 17 | # If the hook program exits with success, the lock is created; but 18 | # if it exits with failure (non-zero), the lock action is aborted 19 | # and STDERR is returned to the client. 20 | 21 | # On a Unix system, the normal procedure is to have 'pre-lock' 22 | # invoke other programs to do the real work, though it may do the 23 | # work itself too. 24 | # 25 | # Note that 'pre-lock' must be executable by the user(s) who will 26 | # invoke it (typically the user httpd runs as), and that user must 27 | # have filesystem-level permission to access the repository. 28 | # 29 | # On a Windows system, you should name the hook program 30 | # 'pre-lock.bat' or 'pre-lock.exe', 31 | # but the basic idea is the same. 32 | # 33 | # Here is an example hook script, for a Unix /bin/sh interpreter: 34 | 35 | REPOS="$1" 36 | PATH="$2" 37 | USER="$3" 38 | 39 | # If a lock exists and is owned by a different person, don't allow it 40 | # to be stolen (e.g., with 'svn lock --force ...'). 41 | 42 | # (Maybe this script could send email to the lock owner?) 43 | SVNLOOK=/usr/bin/svnlook 44 | GREP=/bin/grep 45 | SED=/bin/sed 46 | 47 | LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \ 48 | $GREP '^Owner: ' | $SED 's/Owner: //'` 49 | 50 | # If we get no result from svnlook, there's no lock, allow the lock to 51 | # happen: 52 | if [ "$LOCK_OWNER" = "" ]; then 53 | exit 0 54 | fi 55 | 56 | # If the person locking matches the lock's owner, allow the lock to 57 | # happen: 58 | if [ "$LOCK_OWNER" = "$USER" ]; then 59 | exit 0 60 | fi 61 | 62 | # Otherwise, we've got an owner mismatch, so return failure: 63 | echo "Error: $PATH already locked by ${LOCK_OWNER}." 1>&2 64 | exit 1 65 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/hooks/pre-revprop-change.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # PRE-REVPROP-CHANGE HOOK 4 | # 5 | # The pre-revprop-change hook is invoked before a revision property 6 | # is added, modified or deleted. Subversion runs this hook by invoking 7 | # a program (script, executable, binary, etc.) named 'pre-revprop-change' 8 | # (for which this file is a template), with the following ordered 9 | # arguments: 10 | # 11 | # [1] REPOS-PATH (the path to this repository) 12 | # [2] REVISION (the revision being tweaked) 13 | # [3] USER (the username of the person tweaking the property) 14 | # [4] PROPNAME (the property being set on the revision) 15 | # [5] ACTION (the property is being 'A'dded, 'M'odified, or 'D'eleted) 16 | # 17 | # [STDIN] PROPVAL ** the new property value is passed via STDIN. 18 | # 19 | # If the hook program exits with success, the propchange happens; but 20 | # if it exits with failure (non-zero), the propchange doesn't happen. 21 | # The hook program can use the 'svnlook' utility to examine the 22 | # existing value of the revision property. 23 | # 24 | # WARNING: unlike other hooks, this hook MUST exist for revision 25 | # properties to be changed. If the hook does not exist, Subversion 26 | # will behave as if the hook were present, but failed. The reason 27 | # for this is that revision properties are UNVERSIONED, meaning that 28 | # a successful propchange is destructive; the old value is gone 29 | # forever. We recommend the hook back up the old value somewhere. 30 | # 31 | # On a Unix system, the normal procedure is to have 'pre-revprop-change' 32 | # invoke other programs to do the real work, though it may do the 33 | # work itself too. 34 | # 35 | # Note that 'pre-revprop-change' must be executable by the user(s) who will 36 | # invoke it (typically the user httpd runs as), and that user must 37 | # have filesystem-level permission to access the repository. 38 | # 39 | # On a Windows system, you should name the hook program 40 | # 'pre-revprop-change.bat' or 'pre-revprop-change.exe', 41 | # but the basic idea is the same. 42 | # 43 | # The hook program typically does not inherit the environment of 44 | # its parent process. For example, a common problem is for the 45 | # PATH environment variable to not be set to its usual value, so 46 | # that subprograms fail to launch unless invoked via absolute path. 47 | # If you're having unexpected problems with a hook program, the 48 | # culprit may be unusual (or missing) environment variables. 49 | # 50 | # Here is an example hook script, for a Unix /bin/sh interpreter. 51 | # For more examples and pre-written hooks, see those in 52 | # the Subversion repository at 53 | # http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/ and 54 | # http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/ 55 | 56 | 57 | REPOS="$1" 58 | REV="$2" 59 | USER="$3" 60 | PROPNAME="$4" 61 | ACTION="$5" 62 | 63 | if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi 64 | 65 | echo "Changing revision properties other than svn:log is prohibited" >&2 66 | exit 1 67 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/hooks/pre-unlock.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # PRE-UNLOCK HOOK 4 | # 5 | # The pre-unlock hook is invoked before an exclusive lock is 6 | # destroyed. Subversion runs this hook by invoking a program 7 | # (script, executable, binary, etc.) named 'pre-unlock' (for which 8 | # this file is a template), with the following ordered arguments: 9 | # 10 | # [1] REPOS-PATH (the path to this repository) 11 | # [2] PATH (the path in the repository about to be unlocked) 12 | # [3] USER (the user destroying the lock) 13 | # 14 | # The default working directory for the invocation is undefined, so 15 | # the program should set one explicitly if it cares. 16 | # 17 | # If the hook program exits with success, the lock is destroyed; but 18 | # if it exits with failure (non-zero), the unlock action is aborted 19 | # and STDERR is returned to the client. 20 | 21 | # On a Unix system, the normal procedure is to have 'pre-unlock' 22 | # invoke other programs to do the real work, though it may do the 23 | # work itself too. 24 | # 25 | # Note that 'pre-unlock' must be executable by the user(s) who will 26 | # invoke it (typically the user httpd runs as), and that user must 27 | # have filesystem-level permission to access the repository. 28 | # 29 | # On a Windows system, you should name the hook program 30 | # 'pre-unlock.bat' or 'pre-unlock.exe', 31 | # but the basic idea is the same. 32 | # 33 | # Here is an example hook script, for a Unix /bin/sh interpreter: 34 | 35 | REPOS="$1" 36 | PATH="$2" 37 | USER="$3" 38 | 39 | # If a lock is owned by a different person, don't allow it be broken. 40 | # (Maybe this script could send email to the lock owner?) 41 | 42 | SVNLOOK=/usr/bin/svnlook 43 | GREP=/bin/grep 44 | SED=/bin/sed 45 | 46 | LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \ 47 | $GREP '^Owner: ' | $SED 's/Owner: //'` 48 | 49 | # If we get no result from svnlook, there's no lock, return success: 50 | if [ "$LOCK_OWNER" = "" ]; then 51 | exit 0 52 | fi 53 | 54 | # If the person unlocking matches the lock's owner, return success: 55 | if [ "$LOCK_OWNER" = "$USER" ]; then 56 | exit 0 57 | fi 58 | 59 | # Otherwise, we've got an owner mismatch, so return failure: 60 | echo "Error: $PATH locked by ${LOCK_OWNER}." 1>&2 61 | exit 1 62 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/hooks/start-commit.tmpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # START-COMMIT HOOK 4 | # 5 | # The start-commit hook is invoked before a Subversion txn is created 6 | # in the process of doing a commit. Subversion runs this hook 7 | # by invoking a program (script, executable, binary, etc.) named 8 | # 'start-commit' (for which this file is a template) 9 | # with the following ordered arguments: 10 | # 11 | # [1] REPOS-PATH (the path to this repository) 12 | # [2] USER (the authenticated user attempting to commit) 13 | # [3] CAPABILITIES (a colon-separated list of capabilities reported 14 | # by the client; see note below) 15 | # 16 | # Note: The CAPABILITIES parameter is new in Subversion 1.5, and 1.5 17 | # clients will typically report at least the "mergeinfo" capability. 18 | # If there are other capabilities, then the list is colon-separated, 19 | # e.g.: "mergeinfo:some-other-capability" (the order is undefined). 20 | # 21 | # The list is self-reported by the client. Therefore, you should not 22 | # make security assumptions based on the capabilities list, nor should 23 | # you assume that clients reliably report every capability they have. 24 | # 25 | # The working directory for this hook program's invocation is undefined, 26 | # so the program should set one explicitly if it cares. 27 | # 28 | # If the hook program exits with success, the commit continues; but 29 | # if it exits with failure (non-zero), the commit is stopped before 30 | # a Subversion txn is created, and STDERR is returned to the client. 31 | # 32 | # On a Unix system, the normal procedure is to have 'start-commit' 33 | # invoke other programs to do the real work, though it may do the 34 | # work itself too. 35 | # 36 | # Note that 'start-commit' must be executable by the user(s) who will 37 | # invoke it (typically the user httpd runs as), and that user must 38 | # have filesystem-level permission to access the repository. 39 | # 40 | # On a Windows system, you should name the hook program 41 | # 'start-commit.bat' or 'start-commit.exe', 42 | # but the basic idea is the same. 43 | # 44 | # The hook program typically does not inherit the environment of 45 | # its parent process. For example, a common problem is for the 46 | # PATH environment variable to not be set to its usual value, so 47 | # that subprograms fail to launch unless invoked via absolute path. 48 | # If you're having unexpected problems with a hook program, the 49 | # culprit may be unusual (or missing) environment variables. 50 | # 51 | # Here is an example hook script, for a Unix /bin/sh interpreter. 52 | # For more examples and pre-written hooks, see those in 53 | # the Subversion repository at 54 | # http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/ and 55 | # http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/ 56 | 57 | 58 | REPOS="$1" 59 | USER="$2" 60 | 61 | commit-allower.pl --repository "$REPOS" --user "$USER" || exit 1 62 | special-auth-check.py --user "$USER" --auth-level 3 || exit 1 63 | 64 | # All checks passed, so allow the commit. 65 | exit 0 66 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/locks/db-logs.lock: -------------------------------------------------------------------------------- 1 | This file is not used by Subversion 1.3.x or later. 2 | However, its existence is required for compatibility with 3 | Subversion 1.2.x or earlier. 4 | -------------------------------------------------------------------------------- /lectures/lecture-aids/04L-softwarecarpentry/svn-repository/locks/db.lock: -------------------------------------------------------------------------------- 1 | This file is not used by Subversion 1.3.x or later. 2 | However, its existence is required for compatibility with 3 | Subversion 1.2.x or earlier. 4 | -------------------------------------------------------------------------------- /lectures/lecture-aids/05-softwarecarpentry/bst_main.py: -------------------------------------------------------------------------------- 1 | from bst import BinarySearchTree 2 | 3 | B = BinarySearchTree() 4 | B.add(1) 5 | B.add(3) 6 | B.add(4) 7 | 8 | B.remove(2) 9 | B.remove(3) 10 | 11 | -------------------------------------------------------------------------------- /lectures/lecture-aids/05-softwarecarpentry/bst_main_profile.py: -------------------------------------------------------------------------------- 1 | from bst import BinarySearchTree 2 | import profile 3 | 4 | B = BinarySearchTree() 5 | B.add(1) 6 | B.add(3) 7 | B.add(4) 8 | 9 | profile.run('B.remove(3)') 10 | 11 | -------------------------------------------------------------------------------- /lectures/lecture-aids/05-softwarecarpentry/bst_short.py: -------------------------------------------------------------------------------- 1 | class _BinaryElem(object): 2 | def __init__(self,elem,right=None,left=None): 3 | self.elem = elem 4 | self.left = left 5 | self.right = right 6 | def find(self,elem): 7 | if self.elem == elem: return self 8 | elif elem < self.elem: 9 | if self.left: return self.left.find(elem) 10 | elif self.right: return self.right.find(elem) 11 | return None 12 | def add(self,elem): 13 | if self.elem == elem: return 14 | if elem < self.elem: 15 | if self.left is None: self.left = _BinaryElem(elem,None,None) 16 | else: self.left.add(elem) 17 | else: 18 | if self.right is None: self.right = _BinaryElem(elem,None,None) 19 | else: self.right.add(elem) 20 | class BinarySearchTree(object): 21 | ''' 22 | Binary Serch Tree 23 | Operations: 24 | * BST.add(value) 25 | * BST.remove(value) 26 | * BST.find(value) 27 | * BST.size() 28 | ''' 29 | def __init__(self): 30 | self.root = None 31 | def add(self,elem): 32 | ''' 33 | T.add(value) 34 | Add element to the tree 35 | ''' 36 | if self.root is None: 37 | self.root = _BinaryElem(elem) 38 | self.root.add(elem) 39 | def find(self,elem): 40 | ''' 41 | N = T.find(value) 42 | Returns whether element is in the tree. 43 | ''' 44 | if self.root is None: return False 45 | return self.root.find(elem) is not None 46 | def size(self): 47 | ''' 48 | N = T.size() 49 | Return the number of elements in the tree. 50 | ''' 51 | def _size(top): 52 | if top is None: return 0 53 | return 1 + _size(top.left) + _size(top.right) 54 | return _size(self.root) 55 | -------------------------------------------------------------------------------- /lectures/lecture-aids/05-softwarecarpentry/stddev.py: -------------------------------------------------------------------------------- 1 | def stddev(values): 2 | ''' 3 | s = stddev(values) 4 | 5 | ''' 6 | assert values, 'stddev: cannot compute stddev of empty list' 7 | 8 | mu = sum(values)/float(len(values)) 9 | S = 0 10 | for val in values: 11 | S += (mu-val)**2 12 | return S/float(len(values)) 13 | 14 | -------------------------------------------------------------------------------- /lectures/lecture-aids/05-softwarecarpentry/test_bst.py: -------------------------------------------------------------------------------- 1 | from bst import BinarySearchTree 2 | def test_bst(): 3 | B = BinarySearchTree() 4 | assert B.size() == 0 5 | B.add(25) 6 | assert B.size() == 1 7 | B.add(25) 8 | assert B.size() == 1 9 | B.add(25) 10 | assert B.size() == 1 11 | B.add(15) 12 | assert B.size() == 2 13 | assert B.find(25) 14 | assert B.find(15) 15 | assert not B.find(2) 16 | B.remove(15) 17 | assert B.size() == 1 18 | assert not B.find(15) 19 | assert B.find(25) 20 | assert not B.find(2) 21 | 22 | -------------------------------------------------------------------------------- /lectures/lecture-aids/05-softwarecarpentry/tests/test_stddev.py: -------------------------------------------------------------------------------- 1 | from stddev import stddev 2 | 3 | def test_constant(): 4 | assert stddev([1]*20) < 1e-3 5 | def test_positive(): 6 | assert stddev(range(2)) > 0 7 | -------------------------------------------------------------------------------- /lectures/lecture-aids/05L-softwarecarpentry/PROFILE_ONE_MAJOR2: -------------------------------------------------------------------------------- 1 | In [3]: cProfile.run("F=pyslic.computefeatures(z1_40[0],['skl'])") 2 | /usr/lib/python2.5/site-packages/scipy/ndimage/measurements.py:350: DeprecationWarning: integer argument expected, got float 3 | return _nd_image.histogram(input, min, max, bins, labels, index) 4 | 1921568 function calls in 148.510 CPU seconds 5 | 6 | Ordered by: standard name 7 | 8 | ncalls tottime percall cumtime percall filename:lineno(function) 9 | 18872 0.882 0.000 35.659 0.002 bbox.py:27(bbox) 10 | 9436 0.138 0.000 35.211 0.004 bbox.py:74(croptobbox) 11 | 1 0.001 0.001 148.512 148.512 computefeatures.py:48(computefeatures) 12 | 9436 0.138 0.000 1.334 0.000 convexhull.py:34(convexhull) 13 | 1 90.468 90.468 147.490 147.490 imgskelfeats.py:34(imgskelfeatures) 14 | 9436 0.237 0.000 1.527 0.000 imgskelfeats.py:66(find_branch_points) 15 | 9436 0.971 0.000 56.921 0.006 imgskelfeats.py:80(objskelfeats) 16 | 281578 1.248 0.000 43.793 0.000 inline_tools.py:134(inline) 17 | 131352 1.340 0.000 9.758 0.000 mmthin.py:105(hitmiss) 18 | 131352 1.323 0.000 2.295 0.000 mmthin.py:160(fastany) 19 | 9436 2.694 0.000 16.992 0.002 mmthin.py:33(mmthin) 20 | 1 0.002 0.002 1.022 1.022 preprocess.py:34(preprocessimage) 21 | 286119 42.406 0.000 42.406 0.000 {apply} 22 | 117774 2.293 0.000 2.486 0.000 {numpy.core.multiarray.array} 23 | -------------------------------------------------------------------------------- /lectures/lecture-aids/05L-softwarecarpentry/PROFILE_ONE_MAJOR_after2: -------------------------------------------------------------------------------- 1 | In [3]: cProfile.run("F=pyslic.computefeatures(z1_40[0],['skl'])") 2 | /usr/lib/python2.5/site-packages/scipy/ndimage/measurements.py:350: DeprecationWarning: integer argument expected, got float 3 | return _nd_image.histogram(input, min, max, bins, labels, index) 4 | 1855518 function calls in 21.589 CPU seconds 5 | 6 | Ordered by: standard name 7 | 8 | ncalls tottime percall cumtime percall filename:lineno(function) 9 | 1 0.001 0.001 21.591 21.591 computefeatures.py:48(computefeatures) 10 | 9436 0.085 0.000 1.056 0.000 convexhull.py:34(convexhull) 11 | 1 0.249 0.249 20.565 20.565 imgskelfeats.py:35(imgskelfeatures) 12 | 9436 0.648 0.000 20.183 0.002 imgskelfeats.py:86(_objskelfeats) 13 | 272142 1.081 0.000 9.498 0.000 inline_tools.py:134(inline) 14 | 131352 1.311 0.000 9.659 0.000 mmthin.py:105(hitmiss) 15 | 131352 1.303 0.000 2.256 0.000 mmthin.py:160(fastany) 16 | 9436 2.539 0.000 16.449 0.002 mmthin.py:33(mmthin) 17 | 276683 8.285 0.000 8.285 0.000 {apply} 18 | 108338 1.960 0.000 2.103 0.000 {numpy.core.multiarray.array} 19 | -------------------------------------------------------------------------------- /lectures/lecture-aids/12-gui/alice.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt4 import QtGui, QtCore 3 | app = QtGui.QApplication(sys.argv) 4 | 5 | button = QtGui.QPushButton('Press Me') 6 | button.setWindowTitle('Hello') 7 | button.show() 8 | 9 | bigger = True 10 | def resize(): 11 | global bigger 12 | w = button.width() 13 | h = button.height() 14 | if bigger: 15 | button.resize(w*2,h*2) 16 | else: 17 | button.resize(w//2,h//2) 18 | bigger = not bigger 19 | 20 | 21 | app.connect(button, QtCore.SIGNAL('clicked()'), resize) 22 | sys.exit(app.exec_()) 23 | 24 | -------------------------------------------------------------------------------- /lectures/lecture-aids/12-gui/hello.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt4 import QtGui 3 | app = QtGui.QApplication(sys.argv) 4 | widget = QtGui.QLabel('Hello World') 5 | widget.setWindowTitle('Hello') 6 | widget.show() 7 | sys.exit(app.exec_()) 8 | 9 | -------------------------------------------------------------------------------- /lectures/lecture-aids/12-gui/particlesgui.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt4 import QtGui, QtCore 3 | app = QtGui.QApplication(sys.argv) 4 | main = QtGui.QWidget() 5 | main.setWindowTitle('Particles GUI') 6 | main.resize(260,210) 7 | main.show() 8 | method = QtGui.QLabel('Method',main) 9 | method.move(100,50) 10 | method.show() 11 | methodchoose = QtGui.QComboBox(main) 12 | methodchoose.addItem('Brownian') 13 | methodchoose.addItem('Directed') 14 | methodchoose.move(100,45) 15 | methodchoose.show() 16 | method.move(40,50) 17 | stddev = QtGui.QLabel('Std. dev.',main) 18 | stddev.move(40,90) 19 | stddev.show() 20 | stddevinput = QtGui.QLineEdit(main) 21 | stddevinput.move(100,80) 22 | main.show() 23 | stddevinput.show() 24 | Ok = QtGui.QPushButton('Ok', main) 25 | Ok.show() 26 | Ok.move(200,150) 27 | def execute(): 28 | print 'python particles --method=%s --std-dev=%s' % (str(methodchoose.currentText()), str(stddevinput.text())) 29 | 30 | app.connect(Ok,QtCore.SIGNAL('clicked()'),execute) 31 | sys.exit(app.exec_()) 32 | 33 | -------------------------------------------------------------------------------- /lectures/lecture-aids/12L-gui-ii/particles.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt4 import QtGui, QtCore 3 | from ui_particles import Ui_MainWindow 4 | app = QtGui.QApplication(sys.argv) 5 | 6 | class ParticlesMainWindow(QtGui.QMainWindow, Ui_MainWindow): 7 | def __init__(self): 8 | QtGui.QMainWindow.__init__(self) 9 | self.setupUi(self) 10 | 11 | def doparticles(): 12 | print 'Particles called' 13 | main = ParticlesMainWindow() 14 | app.connect(main.runbutton, QtCore.SIGNAL('clicked()'), doparticles) 15 | app.connect(main.actionQuit,QtCore.SIGNAL('activated()'),app.quit) 16 | main.show() 17 | sys.exit(app.exec_()) 18 | 19 | -------------------------------------------------------------------------------- /lectures/lecture-aids/12L-gui-ii/particlesgui.ui: -------------------------------------------------------------------------------- 1 | 2 | MainWindow 3 | 4 | 5 | 6 | 0 7 | 0 8 | 530 9 | 314 10 | 11 | 12 | 13 | MainWindow 14 | 15 | 16 | 17 | 18 | 19 | 390 20 | 210 21 | 105 22 | 26 23 | 24 | 25 | 26 | Run 27 | 28 | 29 | 30 | 31 | 32 | 100 33 | 40 34 | 411 35 | 141 36 | 37 | 38 | 39 | Options 40 | 41 | 42 | 43 | 44 | 16 45 | 40 46 | 361 47 | 59 48 | 49 | 50 | 51 | 52 | 53 | 54 | Me&thod 55 | 56 | 57 | methodcombo 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | Brownian 66 | 67 | 68 | 69 | 70 | Directed 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | Standard &Deviation 79 | 80 | 81 | stddev 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 0 96 | 0 97 | 530 98 | 25 99 | 100 | 101 | 102 | 103 | &File 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | &Quit 113 | 114 | 115 | 116 | 117 | methodcombo 118 | stddev 119 | runbutton 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /lectures/lecture-aids/12L-gui-ii/sleeper.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from time import sleep 3 | runs = int(sys.argv[1]) 4 | for i in xrange(runs): 5 | print i 6 | #sys.stdout.flush() 7 | sleep(2) 8 | -------------------------------------------------------------------------------- /lectures/lecture-aids/12L-gui-ii/sleeperui.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt4 import QtCore, QtGui 3 | app = QtGui.QApplication(sys.argv) 4 | 5 | button = QtGui.QPushButton('Press Me') 6 | button.setWindowTitle('Hello') 7 | button.show() 8 | proc = QtCore.QProcess() 9 | 10 | def process_output(): 11 | output = proc.readAllStandardOutput() 12 | button.setText(str(output).strip()) 13 | print 'output from process >>', output, '<<' 14 | 15 | def startit(): 16 | proc.start('python',['sleeper.py','10']) 17 | 18 | app.connect(button, QtCore.SIGNAL('clicked()'),startit) 19 | app.connect(proc,QtCore.SIGNAL('readyReadStandardOutput()'),process_output) 20 | 21 | sys.exit(app.exec_()) 22 | -------------------------------------------------------------------------------- /lectures/lecture-aids/15-other-languages/cython/countchar.pyx: -------------------------------------------------------------------------------- 1 | def countchar(str,ch): 2 | res = 0 3 | for c in str: 4 | if c == ch: 5 | res += 1 6 | return res 7 | 8 | def untyped_factorial(n): 9 | res = 1. 10 | for i in range(1,n): 11 | res *= i 12 | return res 13 | 14 | def factorial(int n): 15 | cdef double res = 1. 16 | cdef int i 17 | for i in range(1,n): 18 | res *= i 19 | return res 20 | -------------------------------------------------------------------------------- /lectures/lecture-aids/15-other-languages/ext/countchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | PyObject* countchar(PyObject* self, PyObject* args) { 4 | const char* string; 5 | char ch; 6 | if (!PyArg_ParseTuple(args,"sc",&string,&ch)) 7 | return NULL; 8 | int res = 0; 9 | while (*string) { 10 | if (ch == *string) ++res; 11 | ++string; 12 | } 13 | return Py_BuildValue("i", res); 14 | } 15 | static PyMethodDef methods[] = { 16 | {"countchar", countchar, METH_VARARGS, 17 | "countchar(str,ch)\n" 18 | "Counts the number of ..."}, 19 | {NULL, NULL, 0, NULL} /* Sentinel */ 20 | }; 21 | 22 | PyMODINIT_FUNC initcountchar(void) 23 | { 24 | (void) Py_InitModule("countchar", methods); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /lectures/lecture-aids/15-other-languages/ext/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup, Extension 2 | 3 | module1 = Extension('countchar', 4 | sources = ['countchar.c']) 5 | 6 | setup (name = 'PackageName', 7 | version = '1.0', 8 | description = 'This is a demo package', 9 | ext_modules = [module1]) 10 | -------------------------------------------------------------------------------- /lectures/lecture-aids/15-other-languages/swig/countchar.c: -------------------------------------------------------------------------------- 1 | int countchar(const char* str, char ch) { 2 | int res = 0; 3 | while (*str) { 4 | if (*str == ch) ++res; 5 | ++str; 6 | } 7 | return res; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /lectures/lecture-aids/15-other-languages/swig/countchar.i: -------------------------------------------------------------------------------- 1 | %module countchar 2 | extern int countchar(const char* str, char ch); 3 | 4 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/.gitignore: -------------------------------------------------------------------------------- 1 | .*.tex_files 2 | /*.pdf 3 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/01-intro.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{Introduction} 3 | 4 | \begin{document} 5 | 6 | \section{Basics} 7 | \frame{\maketitle} 8 | 9 | \frame{\frametitle{Introduction} 10 | 11 | \begin{block}{Who am I} 12 | \begin{itemize} 13 | \item Luis Pedro Coelho (luis@luispedro.org) 14 | \item BS \& MS in Computer Science 15 | \item Ph.D.\ in Computational Biology 16 | \item Post-Doc at IMM (UBEG) 17 | \end{itemize} 18 | \end{block} 19 | 20 | } 21 | 22 | \frame{\frametitle{Introduction} 23 | 24 | \begin{block}{This course} 25 | \begin{itemize} 26 | \item Meets: Today + Next two mondays (9h00 to 18h00) 27 | \item Office Hours: luis@luispedro.org 28 | \item Course Website: http://luispedro.org/projects/pfs-09-2012 29 | \end{itemize} 30 | \end{block} 31 | 32 | } 33 | 34 | 35 | \frame{\frametitle{Homework} 36 | \begin{itemize} 37 | \item There will be a homework assignment between the two sessions 38 | \item You can do it on your own, in pairs, in groups, or not at all 39 | \item If you do turn it in, I will give you feedback 40 | \item Similarly, if you have questions during the week, I will take the time to address them in class 41 | \end{itemize} 42 | } 43 | 44 | 45 | \frame{\frametitle{Course Overview} 46 | \begin{block}{What this course is} 47 | \begin{itemize} 48 | \item No prior knowledge is assumed 49 | \item Introduction to programming using Python 50 | \item Topics of interest to scientific programming 51 | \end{itemize} 52 | \end{block} 53 | } 54 | 55 | \frame{\frametitle{Course Overview} 56 | \begin{block}{What this course is not} 57 | \begin{enumerate} 58 | \item A very advanced programming course 59 | \item A bioinformatics course 60 | \item Applied to specific topics (e.g., NGS analysis) 61 | \end{enumerate} 62 | \end{block} 63 | } 64 | 65 | \frame{\frametitle{Things I Left Off} 66 | \begin{enumerate} 67 | \item Version control \& collaboration 68 | \item Unix: shell, processes, getting command line arguments 69 | \item Software engineering or even most of software carpentry 70 | \item Network programming/database interaction 71 | \item A lot of detail on the things I did leave in 72 | \end{enumerate} 73 | 74 | If there is interest, we can organise a follow-up course in early 2013. 75 | } 76 | 77 | 78 | \frame{\frametitle{Schedule} 79 | Subject to changes 80 | 81 | \begin{tabular}{lrr} 82 | \toprule 83 | & Day I & Day II\\ 84 | \midrule 85 | 86 | 9h00-10h20 & Python II & HW Review/In-class Quiz\\ 87 | 10h30-11h30 & Numpy. matplotlib & Open Source Software\\ 88 | 11h40-12h25 & Guided exercises & Unit tests\\ 89 | 90 | Break\\ 91 | 92 | 14h00-15h20 & Python III & Python IV \\ 93 | 15h30-16h30 & File parsing& Guided exercises\\ 94 | 16h40-18h00 & Numeric issues & Review. Learn more \\ 95 | \bottomrule 96 | \end{tabular} 97 | 98 | } 99 | 100 | 101 | 102 | \frame{\frametitle{Software} 103 | 104 | \begin{block}{Python} 105 | \begin{itemize} 106 | \item On \alert{Windows}: Python(x,y) 107 | \item On \alert{Mac OS X}: EPD or homebrew/macports 108 | \item On \alert{Linux}: Just use your package manager 109 | \end{itemize} 110 | \end{block} 111 | } 112 | 113 | \section{Class Starts Here} 114 | 115 | \begin{frame}[fragile] 116 | 117 | \centering 118 | Class starts here. 119 | 120 | \end{frame} 121 | 122 | \end{document} 123 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/05-guided.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{Guided Exercises} 3 | \begin{document} 4 | \frame{\maketitle} 5 | 6 | \begin{frame} 7 | \frametitle{Goals for this hour} 8 | 9 | \begin{itemize} 10 | \item A quiz 11 | \item Do a few exercises. 12 | \item Play around. 13 | \item You can work alone, in pairs, in triples,\ldots 14 | \end{itemize} 15 | 16 | \end{frame} 17 | 18 | \begin{frame} 19 | \frametitle{Lists I} 20 | 21 | How do you access the first element of a list? 22 | 23 | Assume \texttt{list} is a list: 24 | 25 | \begin{enumerate} 26 | \item \texttt{list[1]} 27 | \item \texttt{list[0]} 28 | \item \texttt{list[-1]} 29 | \item \texttt{list(0)} 30 | \item \texttt{list(-1)} 31 | \item \texttt{list(1)} 32 | \end{enumerate} 33 | \end{frame} 34 | 35 | \begin{frame} 36 | \frametitle{Lists II} 37 | 38 | How do you access the last element of a list? 39 | 40 | Assume \texttt{list} is a list: 41 | 42 | \begin{enumerate} 43 | \item \texttt{list[1]} 44 | \item \texttt{list(-0)} 45 | \item \texttt{list[-1]} 46 | \item \texttt{list(-1)} 47 | \item \texttt{list(1)} 48 | \item \texttt{list[-0]} 49 | \end{enumerate} 50 | \end{frame} 51 | 52 | \begin{frame} 53 | {} 54 | 55 | \bigskip 56 | \bigskip 57 | \bigskip 58 | Exercises 59 | \end{frame} 60 | 61 | \begin{frame}[fragile] 62 | \frametitle{Object Identity} 63 | 64 | What is the difference between the following two code examples: 65 | 66 | A) 67 | \begin{python} 68 | A = [1, 2, 3] 69 | B = [1, 2, 3] 70 | \end{python} 71 | 72 | B) 73 | 74 | \begin{python} 75 | A = [1, 2, 3] 76 | B = A 77 | \end{python} 78 | 79 | Write a small piece of code (should be 2 or 3 lines) that behaves differently 80 | if you insert it after each of the two segments above. 81 | 82 | \pause 83 | 84 | \begin{python} 85 | B[0] = 0 86 | print A 87 | \end{python} 88 | 89 | \end{frame} 90 | 91 | 92 | \begin{frame}[fragile] 93 | \frametitle{sum} 94 | \begin{enumerate} 95 | \item Learn about the built-in function \lstinline{sum} 96 | \item Write an implementation of this function 97 | \end{enumerate} 98 | 99 | \pause 100 | \begin{python} 101 | def sum(xs, start=0): 102 | ''' 103 | s = sum(xs, start=0) 104 | 105 | Returns the sum of all values in ``xs`` + ``start`` (which defaults to 0) 106 | ''' 107 | for x in xs: 108 | start += x 109 | return start 110 | \end{python} 111 | \end{frame} 112 | 113 | \begin{frame}[fragile] 114 | \begin{python} 115 | numbers = set([1,2]) 116 | for i in xrange(5): 117 | numbers.add(i) 118 | print len(numbers) 119 | \end{python} 120 | 121 | This prints: 122 | 123 | \begin{itemize} 124 | \item 7 125 | \item 6 126 | \item 5 127 | \item 4 128 | \end{itemize} 129 | \end{frame} 130 | 131 | 132 | 133 | \begin{frame}[fragile] 134 | \frametitle{Numpy} 135 | 136 | \begin{python} 137 | import numpy as np 138 | X = np.array([0,1,2,1,2,1,2,1]) 139 | X += 0.1 140 | print X[0] 141 | \end{python} 142 | 143 | \begin{itemize} 144 | \item What does this print? 145 | \item Why? 146 | \end{itemize} 147 | \end{frame} 148 | 149 | 150 | \begin{frame}[fragile] 151 | \frametitle{Matplotlib} 152 | 153 | \begin{python} 154 | import numpy as np 155 | from matplotlib import pyplot as plt 156 | 157 | X = np.linspace(-4, 4, 100) 158 | Y = np.exp(.5-X*X) 159 | \end{python} 160 | 161 | \centering 162 | \includegraphics[width=.5\textwidth]{gaussian.pdf} 163 | 164 | \end{frame} 165 | 166 | 167 | 168 | \end{document} 169 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/13-guided.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{Guided Exercises} 3 | \usepackage{amsmath} 4 | \begin{document} 5 | \frame{\maketitle} 6 | 7 | \begin{frame} 8 | \frametitle{Goals for this hour} 9 | 10 | \begin{itemize} 11 | \item A quiz 12 | \item Do a few exercises. 13 | \item Play around. 14 | \item You can work alone, in pairs, in triples,\ldots 15 | \end{itemize} 16 | 17 | \end{frame} 18 | 19 | 20 | \begin{frame}[fragile] 21 | {} 22 | 23 | 24 | Consider the following code: 25 | 26 | \begin{python} 27 | class Point2(object): 28 | def __init__(self,x,y): 29 | self.x = x 30 | self.y = y 31 | 32 | def dist2(self): 33 | return self.x**2 + self.y**2 34 | 35 | p = Point2(2,2) 36 | print p.dist2() 37 | p.y = 0 38 | print p.dist2() 39 | print p.x 40 | print p.y 41 | \end{python} 42 | 43 | This code prints four numbers. What are they? 44 | 45 | \begin{enumerate}[a] 46 | \item 8, 8, 2, 0 47 | \item 8, 8, 2, 2 48 | \item 8, 4, 2, 0 49 | \item 8, 4, 2, 2 50 | \end{enumerate} 51 | 52 | \end{frame} 53 | 54 | \begin{frame}[fragile] 55 | \frametitle{Hello World} 56 | 57 | Write a piece of code that writes the string "Hello World" to a file called "hello". 58 | 59 | \bigskip 60 | What happens if you use your code above when a file called \textit{hello} already exists? 61 | 62 | \end{frame} 63 | 64 | \begin{frame}[fragile] 65 | {} 66 | What does the following code do? 67 | 68 | \begin{python} 69 | from random import choice 70 | print choice(range(30)) 71 | \end{python} 72 | 73 | For this, you might want to read the Python documentation. 74 | \end{frame} 75 | 76 | \begin{frame}[fragile] 77 | {} 78 | You will sometimes see the following programming idiom: 79 | 80 | \begin{python} 81 | import numpy as np 82 | mystery = np.uint32(-1) 83 | \end{python} 84 | 85 | Remember: 86 | \begin{itemize} 87 | \item \lstinline{uint32} is short for \alert{unsigned integer of 32 bits}. 88 | \item Unsigned means that it should be interpreted as a positive number. 89 | \item So, \lstinline{mystery} cannot have the value $-1$! 90 | \end{itemize} 91 | 92 | What is the value of mystery? Why would we be interested in this particular 93 | value? (Hint: think of its bit representation). 94 | 95 | \end{frame} 96 | 97 | \begin{frame}[fragile] 98 | \frametitle{File Parsing} 99 | 100 | What is a text file? 101 | 102 | \begin{enumerate} 103 | \item A file with an extension TXT\\ 104 | (for example file.txt) 105 | \item A file whose content can be interpreted as printable characters. 106 | \item A Word file. 107 | \item A file with text in a human language (like English). 108 | \end{enumerate} 109 | \end{frame} 110 | 111 | \begin{frame}[fragile] 112 | \frametitle{Factorial} 113 | Write a factorial function. 114 | 115 | \[ 116 | N! = N \cdot (N - 1) \cdot (N - 2) \cdots 1 117 | \] 118 | 119 | \pause 120 | 121 | \[N! = \begin{cases} 122 | 1 & N = 0 \\ 123 | N\cdot (N-1)! & ow. 124 | \end{cases} 125 | \] 126 | 127 | \pause 128 | 129 | \begin{python} 130 | def factorial(n): 131 | assert n >= 0, \ 132 | 'factorial is only for n >= 0' 133 | if n == 0: return 1 134 | return n * factorial(n-1) 135 | \end{python} 136 | 137 | \end{frame} 138 | 139 | \begin{frame}[fragile] 140 | \frametitle{Fibonacci} 141 | 142 | Write a Fibonnaci function 143 | \begin{align*} 144 | F_0 &= 1\\ 145 | F_1 &= 1\\ 146 | F_{n+2} &= F_{n+1} + F_n 147 | \end{align*} 148 | 149 | \note{ 150 | We can do both a recursive and an iterative function. 151 | 152 | Show how they are equivalent mathematically, but not in performance. 153 | Handwave notion of big-Oh: ``iterative takes $n$ steps, more or less; 154 | recursive takes $F_n$ steps; more or less.'' 155 | }% 156 | \end{frame} 157 | 158 | \end{document} 159 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/14-final-image.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{Review. Future} 3 | \begin{document} 4 | \frame{\maketitle} 5 | 6 | 7 | \begin{frame}[fragile] 8 | \frametitle{Case Study} 9 | 10 | Computer vision 11 | 12 | \bigskip 13 | \bigskip 14 | 15 | Analysis of fluorescent microgrpah 16 | 17 | \end{frame} 18 | 19 | 20 | \begin{frame}[fragile] 21 | \frametitle{Libraries} 22 | 23 | \begin{itemize} 24 | \item Third-party libraries are hit \& miss 25 | \item mahotas is good 26 | \item scikit-image is good 27 | \item imread is good 28 | \end{itemize} 29 | 30 | \end{frame} 31 | 32 | \begin{frame}[fragile] 33 | \frametitle{Task} 34 | Given an image which has a \textsc{dna} (Hoechst) and a protein (GFP tag) 35 | channel, can we determine ``what fraction of protein is in nuclear region?'' 36 | \end{frame} 37 | 38 | \begin{frame}[fragile] 39 | \frametitle{Loading images} 40 | 41 | \begin{python} 42 | from mahotas import imread 43 | dna = imread('00-001-dna.tiff') 44 | protein = imread('00-001-protein.tiff') 45 | \end{python} 46 | 47 | We now have arrays of small integers. 48 | \end{frame} 49 | 50 | \begin{frame}[fragile] 51 | \frametitle{Visualising} 52 | \begin{itemize} 53 | \item Remember, all that we have are small numbers. 54 | \item We can show them in different ways for better visualization. 55 | \end{itemize} 56 | 57 | \end{frame} 58 | 59 | \begin{frame}[fragile] 60 | \frametitle{Thresholding} 61 | 62 | \begin{enumerate} 63 | \item Gaussian filtering 64 | \item Otsu thresholding 65 | \end{enumerate} 66 | \end{frame} 67 | 68 | \begin{frame}[fragile] 69 | \frametitle{Protein Measurement} 70 | \begin{enumerate} 71 | \item Subtract background 72 | \item Sum up protein fluorescence \alert{inside} valid region 73 | \item Sum up protein fluorescence \alert{outside} valid region 74 | \end{enumerate} 75 | \end{frame} 76 | 77 | \begin{frame}[fragile] 78 | \frametitle{Links for Learning More} 79 | 80 | \begin{itemize} 81 | \item How to Think Like a Computer Scientist 82 | \url{http://interactivepython.org/courselib/static/thinkcspy/index.html} 83 | \item Stack Overflow \\ 84 | for asking questions 85 | \item Python.org \& numpy.scipy.org \\ 86 | for documentation 87 | \end{itemize} 88 | 89 | \end{frame} 90 | 91 | \begin{frame}[fragile] 92 | \frametitle{Shameless Plug} 93 | 94 | \begin{itemize} 95 | \item I am giving an introductory/research talk on \alert{Bioimage Informatics} 96 | \item October 31st 10am (room 057) 97 | \end{itemize} 98 | \end{frame} 99 | 100 | \begin{frame}[fragile] 101 | \frametitle{Any Other Questions\ldots} 102 | Email me: luis@luispedro.org 103 | \end{frame} 104 | 105 | 106 | 107 | \end{document} 108 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/Makefile: -------------------------------------------------------------------------------- 1 | pdfs := $(patsubst %.tex,%.pdf,$(wildcard *.tex)) 2 | all: $(pdfs) 3 | 4 | .PHONY: all 5 | 6 | %.pdf: %.tex headers/slheader.tex 7 | ./do-slides.sh $< 8 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/do-slides.sh: -------------------------------------------------------------------------------- 1 | t=.$1.tex_files 2 | test -d $t || mkdir $t 3 | cd $t 4 | TEXINPUTS=:..:../headers:../headers/imm-format:../../slides/:../images:../../slides/images:../../slides/figures/generated: xelatex $1 5 | cp `basename $1 tex`pdf .. 6 | cd 7 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/headers/imm-format/beamercolorthemeIMM.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2006-2011 by Luis Pedro Coelho 2 | % Copyright 2003 by Till Tantau . 3 | % 4 | % This program can be redistributed and/or modified under the terms 5 | % of the GNU Public License, version 2. 6 | 7 | \mode 8 | 9 | \definecolor{immyellow}{HTML}{F9EC2E} 10 | %\definecolor{jacaranda}{HTML}{A697E2} 11 | \definecolor{jacaranda}{HTML}{941E72} 12 | %\definecolor{greenjacaranda}{HTML}{3F9157} 13 | \definecolor{greenjacaranda}{HTML}{1E9440} 14 | 15 | 16 | \setbeamercolor{palette primary}{bg=immyellow} 17 | \setbeamercolor{palette secundary}{bg=immyellow} 18 | \setbeamercolor{palette tertiary}{bg=greenjacaranda,fg=white} 19 | \setbeamercolor{titlelike}{bg=immyellow,fg=black} 20 | \setbeamercolor{title}{bg=immyellow,fg=black} 21 | 22 | 23 | \setbeamercolor{section number projected}{bg=greenjacaranda} 24 | \setbeamercolor{section in toc}{fg=greenjacaranda} 25 | 26 | \setbeamercolor{item projected}{bg=greenjacaranda} 27 | \setbeamercolor{subitem projected}{parent=item projected} 28 | 29 | \setbeamercolor{block title}{parent=titlelike} 30 | 31 | \setbeamercolor{block body}{parent=normal text,use=block title,bg=block title.bg!25!bg} 32 | 33 | \setbeamercolor{alerted text}{fg=jacaranda} 34 | 35 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/headers/imm-format/beamerinnerthemeIMM.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2006-2011 by Luis Pedro Coelho 2 | % Copyright 2003 by Till Tantau 3 | % 4 | % This program can be redistributed and/or modified under the terms 5 | % of the GNU Public License, version 2. 6 | 7 | \mode 8 | 9 | \DeclareOptionBeamer{shadow}[false]{\def\beamer@themeCMU@shadow{#1}} 10 | \ExecuteOptionsBeamer{shadow=false} 11 | \ProcessOptionsBeamer 12 | 13 | \mode 14 | 15 | \defbeamertemplate{block begin}{IMM}[1][] 16 | {% 17 | \begin{beamercolorbox}[wd=.9\textwidth,ht=2.4ex]{block title}% 18 | \usebeamerfont{block title}\hspace{1em}\raisebox{.1ex}{\insertblocktitle} 19 | \end{beamercolorbox}% 20 | } 21 | 22 | \defbeamertemplate{block end}{IMM}[1][] 23 | {% 24 | \vspace{3ex} 25 | %\vspace{-2ex}% 26 | % \begin{beamercolorbox}[wd=.9\textwidth,ht=.3ex]{block title}% 27 | % \end{beamercolorbox}% 28 | % \par 29 | } 30 | 31 | \setbeamertemplate{blocks}[IMM] 32 | \setbeamertemplate{items}[ball] 33 | \setbeamertemplate{sections/subsections in toc}[ball] 34 | \setbeamertemplate{title page}[default][colsep=-4bp,rounded=true,shadow=\beamer@themerounded@shadow] 35 | \setbeamertemplate{part page}[default][colsep=-4bp,rounded=true,shadow=\beamer@themerounded@shadow] 36 | 37 | \mode 38 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/headers/imm-format/beamerouterthemeIMM.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2006 by Luis Pedro Coelho 2 | % Copyright 2003 by Till Tantau 3 | % 4 | % This program can be redistributed and/or modified under the terms 5 | % of the GNU Public License, version 2. 6 | 7 | \mode 8 | 9 | \setbeamercolor*{author in head/foot}{parent=palette tertiary} 10 | \setbeamercolor*{title in head/foot}{parent=palette tertiary} 11 | \setbeamercolor*{date in head/foot}{parent=palette tertiary} 12 | 13 | \setbeamercolor*{section in head/foot}{parent=palette tertiary} 14 | \setbeamercolor*{subsection in head/foot}{parent=palette primary} 15 | 16 | \defbeamertemplate*{footline}{IMM theme} 17 | { 18 | \leavevmode% 19 | \hbox{% 20 | \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex]{author in head/foot}% 21 | \hspace{1ex}\usebeamerfont{author in head/foot}\insertshortauthor~~(\insertshortinstitute)\hfill$\star$\hfill 22 | \usebeamerfont{title in head/foot}\insertshorttitle\hfill$\star$\hfill 23 | \usebeamerfont{date in head/foot}\insertshortdate{}\hfill 24 | \tiny(\insertframenumber{} / \inserttotalframenumber)\hspace*{1ex} 25 | \end{beamercolorbox}}% 26 | \vskip0pt% 27 | } 28 | 29 | 30 | \defbeamertemplate*{headline}{IMM theme} 31 | {% 32 | } 33 | 34 | \defbeamertemplate*{frametitle}{IMM}[1] 35 | {% 36 | \vspace{-.2ex}% 37 | \vbox{\begin{beamercolorbox}[ht=2em,wd=\paperwidth]{frametitle}% 38 | \hfill% 39 | \end{beamercolorbox}}% 40 | \usebeamerfont{frametitle}% 41 | \vspace{-1.3em}\raisebox{1.4em}{\insertframetitle}\hfill\includegraphics[height=2.4em]{imm-nowords}% 42 | \vspace{-1.4em}% 43 | } 44 | 45 | \defbeamertemplate*{title page}{IMM}[1][] 46 | { 47 | \vbox{} 48 | \vfill 49 | \begin{centering} 50 | \begin{beamercolorbox}[sep=8pt,center,#1]{title} 51 | \usebeamerfont{title}\inserttitle\par% 52 | \ifx\insertsubtitle\@empty% 53 | \else% 54 | \vskip0.25em% 55 | {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}% 56 | \fi% 57 | \end{beamercolorbox}% 58 | \vskip1em\par 59 | \begin{beamercolorbox}[sep=8pt,center,#1]{author} 60 | \usebeamerfont{author}\insertauthor 61 | \end{beamercolorbox} 62 | \begin{beamercolorbox}[sep=8pt,center,#1]{institute} 63 | \usebeamerfont{institute}\insertinstitute 64 | \end{beamercolorbox} 65 | \begin{beamercolorbox}[sep=8pt,center,#1]{date} 66 | \usebeamerfont{date}\insertdate 67 | \end{beamercolorbox}\vskip0.5em 68 | {\usebeamercolor[fg]{titlegraphic}\inserttitlegraphic\par} 69 | \end{centering} 70 | \vfill 71 | \hfill\includegraphics[height=8ex]{imm-short}\hspace*{1em} 72 | } 73 | 74 | \defbeamertemplate*{navigation symbols}{IMM} 75 | {% 76 | % I actually don't like them 77 | } 78 | 79 | \setbeamersize{text margin left=1em,text margin right=1em} 80 | 81 | \mode 82 | 83 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/headers/imm-format/beamerthemeIMM.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2006-2011 by Luis Pedro Coelho 2 | % Copyright 2003 by Till Tantau 3 | % 4 | % This program can be redistributed and/or modified under the terms 5 | % of the GNU Public License, version 2. 6 | 7 | \mode 8 | 9 | \usefonttheme{IMM} 10 | \usecolortheme{IMM} 11 | \useinnertheme{IMM} 12 | \useoutertheme{IMM} 13 | 14 | \mode 15 | 16 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/headers/imm-format/imm-nowords.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides-2.5-day/headers/imm-format/imm-nowords.png -------------------------------------------------------------------------------- /lectures/slides-2.5-day/headers/imm-format/imm-short.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides-2.5-day/headers/imm-format/imm-short.png -------------------------------------------------------------------------------- /lectures/slides-2.5-day/headers/slheader.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{IMM} 3 | 4 | \usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade} 5 | \usepackage{amsmath,amssymb} 6 | \usepackage{colortbl} 7 | \usepackage[english]{babel} 8 | \usepackage{booktabs} 9 | \usepackage{slpython} 10 | \usepackage{underscore} 11 | \usepackage{bm} 12 | 13 | \author{Luis Pedro Coelho} 14 | \institute{Programming for Scientists} 15 | 16 | \graphicspath{{../figures/}{../figures/generated/}{../images/}} 17 | 18 | \newcommand*{\code}[1]{\textsl{#1}} 19 | \newcommand*{\Reals}[1]{R} 20 | \newcommand*{\Assign}{\ensuremath{\leftarrow}} 21 | \newcommand{\creditto}[1]{% 22 | \begin{flushright} 23 | (#1) 24 | \end{flushright}% 25 | } 26 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/headers/slpython.sty: -------------------------------------------------------------------------------- 1 | \usepackage{listings} 2 | \usepackage{textcomp} 3 | \usepackage{setspace} 4 | \usepackage{palatino} 5 | 6 | \renewcommand{\lstlistlistingname}{Code Listings} 7 | \renewcommand{\lstlistingname}{Code Listing} 8 | \definecolor{gray}{gray}{0.5} 9 | \definecolor{green}{rgb}{0,0.5,0} 10 | \definecolor{darkred}{rgb}{0.5,0,0} 11 | \definecolor{darkgreen}{rgb}{0,0.3,0} 12 | \definecolor{darkblue}{rgb}{0,0,0.5} 13 | 14 | \lstnewenvironment{python}[1][]{ 15 | \lstset{ 16 | language=python, 17 | basicstyle=\ttfamily\small\setstretch{1}, 18 | stringstyle=\color{darkred}, 19 | showstringspaces=false, 20 | alsoletter={1234567890}, 21 | otherkeywords={\ , \}, \{}, 22 | keywordstyle=\color{darkblue}, 23 | emph={access,and,break,class,continue,def,del,elif,else,% 24 | except,exec,finally,for,from,global,if,import,in,is,% 25 | lambda,not,or,pass,print,raise,return,try,while}, 26 | emphstyle=\color{darkgreen}\bfseries, 27 | emph={[2]True, False, None, self}, 28 | emphstyle=[2]\color{darkgreen}, 29 | emph={[3]from, import, as}, 30 | emphstyle=[3]\color{darkblue}, 31 | upquote=true, 32 | morecomment=[s]{"""}{"""}, 33 | commentstyle=\color{gray}\slshape, 34 | emph={[4]1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 35 | emphstyle=[4]\color{darkred}, 36 | literate=*% 37 | {:}{{\textcolor{darkblue}:}}{1}% 38 | {=}{{\textcolor{darkblue}=}}{1}% 39 | {-}{{\textcolor{darkblue}-}}{1}% 40 | {+}{{\textcolor{darkblue}+}}{1}% 41 | {/}{{\textcolor{darkblue}/}}{1}% 42 | {*}{{\textcolor{darkblue}*}}{1}% 43 | {!}{{\textcolor{darkblue}!}}{1}% 44 | {(}{{\textcolor{darkblue}(}}{1}% 45 | {)}{{\textcolor{darkblue})}}{1}% 46 | {[}{{\textcolor{darkblue}[}}{1}% 47 | {]}{{\textcolor{darkblue}]}}{1}% 48 | {<}{{\textcolor{darkblue}<}}{1}% 49 | {>}{{\textcolor{darkblue}>}}{1},% 50 | framexleftmargin=1em, framextopmargin=1mm, frame=leftline,#1 51 | }}{} 52 | 53 | 54 | \lstnewenvironment{ccode}[1][]{ 55 | \lstset{language=C, 56 | keywordstyle=\color{blue}\bfseries, 57 | stringstyle=\color{red}, 58 | showstringspaces=false} 59 | }{} 60 | -------------------------------------------------------------------------------- /lectures/slides-2.5-day/images/qualities.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides-2.5-day/images/qualities.pdf -------------------------------------------------------------------------------- /lectures/slides/.gitignore: -------------------------------------------------------------------------------- 1 | .*.tex_files 2 | *.pdf 3 | -------------------------------------------------------------------------------- /lectures/slides/05L-softwarecarpentry-iv.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{Software Carpentry IV: Profiling \& Debugging} 3 | \begin{document} 4 | \frame{\maketitle} 5 | 6 | \begin{frame}[fragile] 7 | \frametitle{Today's Lecture} 8 | 9 | \begin{itemize} 10 | \item Debugger 11 | \item Profiler 12 | \end{itemize} 13 | 14 | \end{frame} 15 | 16 | \begin{frame}[fragile] 17 | \frametitle{Debugger} 18 | 19 | Your code will have bugs. 20 | 21 | \end{frame} 22 | 23 | \begin{frame}[fragile] 24 | \frametitle{Three Ways to Debug} 25 | 26 | \begin{enumerate} 27 | \item Run in debugger. 28 | \item Debugger at ``crash'' (exception in Python). 29 | \item Print statements. 30 | \end{enumerate} 31 | 32 | \end{frame} 33 | 34 | \begin{frame}[fragile] 35 | \frametitle{Print Statements} 36 | 37 | Learn about the \texttt{logging} module. 38 | 39 | \begin{python} 40 | import logging 41 | # Setup logging 42 | 43 | logging.basicConfig( 44 | # FIXME: This should be read from 45 | # os.env['PYTHON_DEBUG'] or some variation thereof 46 | level=logging.DEBUG, 47 | format='%(asctime)s %(levelname)-8s %(message)s', 48 | datefmt='%a, %d %b %Y %H:%M:%S', 49 | #filename='slif.python.log', 50 | #filemode='w' 51 | ) 52 | 53 | logging.info('Starting up') 54 | ... 55 | logging.debug('Executing this, that, and the other') 56 | \end{python} 57 | 58 | \end{frame} 59 | 60 | \begin{frame}[fragile] 61 | 62 | \begin{quote} 63 | Performance doesn't matter until it matters. 64 | 65 | ---Python Lore 66 | \end{quote} 67 | 68 | \end{frame} 69 | 70 | \begin{frame}[fragile] 71 | 72 | \begin{quote} 73 | ``We should forget about small efficiencies, say about 97\% of the time: premature optimization is the root of all evil.'' 74 | 75 | --- Donald Knuth 76 | \end{quote} 77 | 78 | \end{frame} 79 | 80 | \begin{frame}[fragile] 81 | \frametitle{Making it faster} 82 | \begin{block}{97/3 Rule} 83 | Your code will spend 97\% of its time in 3\% of the code. 84 | \end{block} 85 | 86 | \end{frame} 87 | 88 | \begin{frame}[fragile] 89 | 90 | \begin{quote} 91 | ``We should forget about small efficiencies, say about 97\% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3\%.'' 92 | 93 | ---Donald Knuth 94 | \end{quote} 95 | 96 | \end{frame} 97 | 98 | \begin{frame}[fragile] 99 | \frametitle{Profiler} 100 | Where are those 3\%? 101 | \bigskip 102 | \pause 103 | 104 | You don't (generally) know where the speed-bottle necks will be! 105 | \end{frame} 106 | 107 | \begin{frame}[fragile] 108 | \frametitle{Profiler} 109 | 110 | \begin{python} 111 | import profiler 112 | ... 113 | profiler.run(code) 114 | \end{python} 115 | 116 | \bigskip 117 | or (inside \alert{ipython}): 118 | 119 | \begin{python} 120 | %prun code 121 | \end{python} 122 | \end{frame} 123 | 124 | \begin{frame}[fragile] 125 | \frametitle{Performance Bugs} 126 | 127 | At one time, I wanted to optimise a bit of my code. 128 | 129 | \end{frame} 130 | 131 | \begin{frame}[fragile] 132 | 133 | \begin{block}{Original Version} 134 | \begin{python} 135 | labeled,N = ndimage.label(protproc > 0) 136 | for obj in xrange(1,obj+1): 137 | objimage = croptobbox(protproc * (labeled == (obj+1))) 138 | ... 139 | \end{python} 140 | \end{block} 141 | 142 | \pause 143 | \begin{block}{Faster Version} 144 | \begin{python} 145 | labeled,N = ndimage.label(protproc > 0) 146 | objects = ndimage.find_objects(labeled) 147 | for i,slice in enumerate(objects): 148 | objimage = protproc[slice] * (labeled[slice] == (i+1)) 149 | ... 150 | \end{python} 151 | \end{block} 152 | \end{frame} 153 | 154 | 155 | \end{document} 156 | -------------------------------------------------------------------------------- /lectures/slides/07L-misc-project.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{Misc Software \& Projects} 3 | \begin{document} 4 | \frame{\maketitle} 5 | 6 | \begin{frame}[fragile] 7 | \frametitle{Scipy} 8 | 9 | \begin{block}{Scipy} 10 | \begin{itemize} 11 | \item A collection of libraries for scientific computing. 12 | \item Current version: 0.7 (February 2009). 13 | \end{itemize} 14 | \end{block} 15 | 16 | \end{frame} 17 | 18 | \begin{frame}[fragile] 19 | \frametitle{Scipy: main modules} 20 | 21 | \begin{itemize} 22 | \item linalg: linear algebra 23 | \item stats: probability and statistics 24 | \item ndimage: n-dimensional image processing. 25 | \item \ldots 26 | \end{itemize} 27 | \end{frame} 28 | 29 | \begin{frame}[fragile] 30 | \frametitle{Matplotlib} 31 | Matplotlib is a \alert{plotting library} for Python. 32 | 33 | \begin{python} 34 | import pylab 35 | import numpy as np 36 | X = np.linspace(-4,+4,1000) 37 | pylab.plot(X,np.exp(-X**2)) 38 | pylab.xlabel(r'$x$') 39 | pylab.ylabel(r'$\exp(-x^{2})$') 40 | pylab.savefig('gaussian.pdf') 41 | \end{python} 42 | 43 | \centering 44 | \href{http://matplotlib.sf.net/}{http://matplotlib.sf.net/} 45 | 46 | \end{frame} 47 | 48 | \begin{frame}[fragile] 49 | \frametitle{Matplotlib Example} 50 | 51 | \centering 52 | \includegraphics[width=.9\textwidth]{matplotlibexample.pdf} 53 | 54 | \end{frame} 55 | 56 | \begin{frame}[fragile] 57 | \frametitle{Projects} 58 | 59 | There is a small final project. 60 | 61 | \begin{enumerate} 62 | \item Self-proposed. 63 | \item Class project. 64 | \end{enumerate} 65 | \end{frame} 66 | 67 | \begin{frame}[fragile] 68 | \frametitle{Class Project} 69 | 70 | Let's see the motivation video (credit: Rebecca Webb and Brooke McCartney) 71 | \end{frame} 72 | 73 | \begin{frame}[fragile] 74 | \frametitle{Simulation Project} 75 | 76 | \begin{enumerate} 77 | \item Simulate a video 78 | \item Track on the video 79 | \item Compare the results 80 | \end{enumerate} 81 | \end{frame} 82 | 83 | \begin{frame}[fragile] 84 | \frametitle{Project} 85 | \begin{enumerate} 86 | \item Object position generator 87 | \item Image generator 88 | \item Object detection 89 | \item Object tracking 90 | \item Results visualisation 91 | \item Statistics gathering 92 | \end{enumerate} 93 | \end{frame} 94 | 95 | \begin{frame}[fragile] 96 | \frametitle{Project Logistics} 97 | 98 | \begin{block}{Design} 99 | I will use the project as a design ``case study'' for a medium sized project. 100 | \end{block} 101 | 102 | \begin{block}{Infrastructure} 103 | \begin{itemize} 104 | \item Open source (i.e., we will post the code online for others to use). 105 | \item Common Subversion repository. 106 | \item Email discussions. 107 | \item Nosetest tests. 108 | \end{itemize} 109 | \end{block} 110 | 111 | \end{frame} 112 | 113 | \end{document} 114 | -------------------------------------------------------------------------------- /lectures/slides/08L-workshop.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{Project Case Study} 3 | \begin{document} 4 | \frame{\maketitle} 5 | 6 | \note{First, let's get some stuff out of the way\ldots} 7 | 8 | \begin{frame}[fragile] 9 | \frametitle{First Steps for the Project} 10 | \begin{enumerate} 11 | \item Email me your preferences 12 | \item Get a google account 13 | \item Send me the email for the google account (just email) 14 | \item Wait for my confirmation 15 | \item Checkout the repository (see google page) 16 | \item Add yourself to AUTHORS.txt 17 | \item Commit 18 | \end{enumerate} 19 | \end{frame} 20 | 21 | \begin{frame}[fragile] 22 | \frametitle{Project Structure} 23 | \begin{itemize} 24 | \item COPYING.MIT 25 | \item AUTHORS.txt 26 | \item README 27 | \item template.py 28 | \item setup.py 29 | \item docs/ 30 | \item tests/ 31 | \item particles/ 32 | \end{itemize} 33 | \end{frame} 34 | 35 | \begin{frame}[fragile] 36 | \frametitle{reStructuredText} 37 | 38 | \begin{verbatim} 39 | ---------------- 40 | This is a title 41 | ---------------- 42 | 43 | Now here comes my text. *This is bold* 44 | 45 | Here's a list 46 | * first element 47 | * second element 48 | \end{verbatim} 49 | 50 | \end{frame} 51 | 52 | \begin{frame}[fragile] 53 | \begin{python} 54 | def brownian_motion(mv_s,p_dis,crowding,crowding_std): 55 | ''' 56 | particles = brownian_motion(mv_s,p_dis,crowding,crowding_std): 57 | 58 | Generate particle tracks according to Brownian motion. 59 | 60 | Parameters 61 | ----------- 62 | 63 | * mov_sigma: std. dev. for movement 64 | (i.e., the position of a particle at time T+1 65 | is given by a Gaussian centred on its position at time T 66 | with std. dev. mov_sigma) 67 | * p_disappear: probability that a particle disappears 68 | * crowding: expected number of particles 69 | * crowding_std: std. dev. of number of particles 70 | 71 | The initial set number of particles is sampled from a 72 | normal distribution of mean crowding and std. dev. 73 | crowding_std. New particles are randomly generated to 74 | offset the dying particles and maintain the property 75 | that the expected number of particles is given by 76 | crowding and crowding_std. 77 | ''' 78 | \end{python} 79 | 80 | \end{frame} 81 | 82 | \begin{frame}[fragile] 83 | \frametitle{Software \& Software Product} 84 | 85 | A product is only finished when you have the \alert{software}, \alert{documentation}, \alert{tests}, and a \alert{web-page}. 86 | \end{frame} 87 | 88 | \note{Now, let's get to the project.} 89 | 90 | \begin{frame}[fragile] 91 | \frametitle{Project Goals} 92 | 93 | \begin{enumerate} 94 | \item Generate a video of particles moving 95 | \begin{enumerate}[a] 96 | \item<2-> Generate tracks 97 | \begin{enumerate}[i] 98 | \item<3-> \alert<4>{Brownian motion} (with parameters) 99 | \item<3-> Brownian motion w. momentum 100 | \item<3-> \ldots 101 | \end{enumerate} 102 | \item<2-> Generate video from tracks 103 | \begin{enumerate}[i] 104 | \item<3-> \alert<4>{Shot noise} (parameters) 105 | \item<3-> Blur 106 | \item<3-> \ldots 107 | \end{enumerate} 108 | \end{enumerate} 109 | \item Track the particles in this movie 110 | \begin{enumerate}[a] 111 | \item<2-> Detect particles 112 | \begin{enumerate}[i] 113 | \item<3-> \alert<4>{Global threshold} 114 | \item<3-> Local threshold 115 | \item<3-> \ldots 116 | \end{enumerate} 117 | \item<2-> Track particles 118 | \end{enumerate} 119 | \item Compare 120 | \item Visualise 121 | \end{enumerate} 122 | \end{frame} 123 | 124 | \begin{frame}[fragile] 125 | \frametitle{Initial Guess} 126 | 127 | \begin{python} 128 | tracks = generate_tracks() 129 | video = generate_video(tracks) 130 | recovered = track(video) 131 | statistics = compare(tracks,recovered) 132 | print_statistics(statistics) 133 | \end{python} 134 | \end{frame} 135 | 136 | \end{document} 137 | -------------------------------------------------------------------------------- /lectures/slides/11L-databases-ii.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{SQL: Database Access} 3 | \begin{document} 4 | \frame{\maketitle} 5 | 6 | \begin{frame}[fragile] 7 | \frametitle{Using Databases} 8 | 9 | Problem 10 | \begin{itemize} 11 | \item Many different ``experiments''. 12 | \item Each experiment has input parameters and output measurements. 13 | \end{itemize} 14 | 15 | \end{frame} 16 | 17 | \begin{frame}[fragile] 18 | \frametitle{Database Design} 19 | 20 | Experiments with input parameters and output values. 21 | 22 | \pause 23 | Tables 24 | \begin{enumerate} 25 | \item Experiments 26 | \item Experiment parameters 27 | \item Experiment results 28 | \end{enumerate} 29 | 30 | \end{frame} 31 | 32 | \begin{frame}[fragile] 33 | \frametitle{SQL For Table Creation} 34 | 35 | \begin{verbatim} 36 | CREATE TABLE experiments ( 37 | eid INT PRIMARY KEY, 38 | name VARCHAR(255), 39 | date DATE NOT NULL 40 | ); 41 | CREATE TABLE parameters ( 42 | pid INT PRIMARY KEY, 43 | name VARCHAR(255) NOT NULL 44 | ); 45 | CREATE TABLE experiment_parameters ( 46 | eid INT NOT NULL, 47 | pid INT NOT NULL, 48 | paramvalue VARCHAR(255) 49 | ); 50 | CREATE TABLE experiment_results ( 51 | eid INT NOT NULL, 52 | measure VARCHAR(255), 53 | value VARCHAR(255) 54 | ); 55 | \end{verbatim} 56 | \end{frame} 57 | 58 | \begin{frame}[fragile] 59 | \frametitle{Example Query} 60 | \begin{verbatim} 61 | SELECT name, date 62 | FROM experiments, parameters, experiment_parameters 63 | WHERE experiments.eid = experiment_parameters.eid AND 64 | experiment_parameters.pid = paramenters.pid AND 65 | parameters.name = 'Generation/model' AND 66 | experiment_parameters.paramvalue = 'brownian'; 67 | \end{verbatim} 68 | \end{frame} 69 | 70 | \begin{frame}[fragile] 71 | \frametitle{A Traditional Database Management System} 72 | 73 | \begin{enumerate} 74 | \item Install it. 75 | \item Set it up to run as daemon. 76 | \item Create database(s). 77 | \item Create user(s). 78 | \item Create tables. 79 | \item Use it. 80 | \end{enumerate} 81 | \end{frame} 82 | 83 | \begin{frame}[fragile] 84 | \frametitle{SQLite: Database in a File} 85 | 86 | SQLite implements SQL-like databases in a single file. 87 | \end{frame} 88 | 89 | \begin{frame}[fragile] 90 | \frametitle{Using SQLite} 91 | 92 | \begin{python} 93 | import sqlite3 94 | from os.path import exists 95 | filename = 'experiment.db' 96 | create = not exists(filename) 97 | connection = sqlite3.connect(filename) 98 | cursor = connection.cursor() 99 | if create: 100 | cursor.execute(''' 101 | CREATE TABLE ...''') 102 | \end{python} 103 | \end{frame} 104 | 105 | \begin{frame}[fragile] 106 | \frametitle{Using SQLite (II)} 107 | 108 | cursor.execute(''' 109 | SELECT eid,name,date 110 | FROM experiments 111 | WHERE date > DATE('2008-12-01') 112 | ''') 113 | 114 | for eid,name,date in cursor.fetchall(): 115 | print eid, name, date 116 | \end{frame} 117 | 118 | \begin{frame}[fragile] 119 | \frametitle{PyTables} 120 | A different type of database,\\ 121 | based on \alert{HDF5}. 122 | \end{frame} 123 | 124 | 125 | \end{document} 126 | -------------------------------------------------------------------------------- /lectures/slides/12-gui.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{GUI Programming I} 3 | \begin{document} 4 | \frame{\maketitle} 5 | 6 | \begin{frame}[fragile] 7 | \frametitle{How to Write a GUI} 8 | Many options: 9 | \begin{itemize} 10 | \item tk 11 | \item wxWindows 12 | \item Gtk 13 | \item \alert<2>{Qt} 14 | \item \ldots 15 | \end{itemize} 16 | \end{frame} 17 | 18 | \begin{frame}[fragile] 19 | \frametitle{Main Elements} 20 | \begin{itemize} 21 | \item Widgets 22 | \item Event loop 23 | \item Signals \& Slots 24 | \end{itemize} 25 | \end{frame} 26 | 27 | \begin{frame}[fragile] 28 | \frametitle{What's a widget?} 29 | Everything you see on your screen is a widget. 30 | \end{frame} 31 | 32 | 33 | \begin{frame}[fragile] 34 | \frametitle{Event Loop} 35 | \begin{block}{Traditional Program} 36 | \begin{python} 37 | tracks = generate_tracks() 38 | video = generate_video(tracks) 39 | recovered = track(video) 40 | statistics = compare(tracks,recovered) 41 | print_statistics(statistics) 42 | \end{python} 43 | \end{block} 44 | 45 | \begin{block}{Event Loop} 46 | \begin{python} 47 | while True: 48 | event = get_next_event() 49 | handle_event(event) 50 | \end{python} 51 | \end{block} 52 | \end{frame} 53 | 54 | \begin{frame}[fragile] 55 | \frametitle{Hollywood Principle} 56 | Don't call us, we'll call you. 57 | \end{frame} 58 | 59 | \begin{frame}[fragile] 60 | \frametitle{Qt} 61 | \begin{itemize} 62 | \item Commercial software from Trolltech (now owned by Nokia). 63 | \item Used to be GPL, now LGPL. 64 | \item Very complete.\note{well documented} 65 | \item C++ toolkit with Python bindings. 66 | \end{itemize} 67 | \end{frame} 68 | 69 | \begin{frame}[fragile] 70 | \frametitle{Actually Writing An Application} 71 | \begin{enumerate} 72 | \item Code it from scratch 73 | \item Use a dialog editor 74 | \end{enumerate} 75 | \end{frame} 76 | 77 | \begin{frame}[fragile] 78 | \frametitle{Simple Example} 79 | 80 | \begin{python} 81 | import sys 82 | from PyQt4 import QtGui 83 | app = QtGui.QApplication(sys.argv) 84 | 85 | widget = QtGui.QLabel('Hello World') 86 | widget.setWindowTitle('Hello') 87 | widget.show() 88 | 89 | sys.exit(app.exec_()) 90 | 91 | \end{python} 92 | 93 | \end{frame} 94 | 95 | \begin{frame}[fragile] 96 | \frametitle{Variation} 97 | 98 | 99 | \begin{python} 100 | import sys 101 | from PyQt4 import QtGui 102 | app = QtGui.QApplication(sys.argv) 103 | 104 | button = QtGui.QPushButton('Press Me') 105 | button.setWindowTitle('Hello') 106 | button.show() 107 | 108 | sys.exit(app.exec_()) 109 | 110 | \end{python} 111 | 112 | \end{frame} 113 | 114 | \begin{frame}[fragile] 115 | \frametitle{Signals \& Slots} 116 | 117 | \begin{python} 118 | bigger = True 119 | def resize(): 120 | global bigger 121 | w = button.width() 122 | h = button.height() 123 | if bigger: 124 | button.resize(w*2, h*2) 125 | else: 126 | button.resize(w//2, h//2) 127 | bigger = not bigger 128 | 129 | \end{python} 130 | \end{frame} 131 | 132 | \begin{frame}[fragile] 133 | \frametitle{Signals \& Slots (II)} 134 | 135 | \begin{python} 136 | import sys 137 | from PyQt4 import QtGui, QtCore 138 | app = QtGui.QApplication(sys.argv) 139 | 140 | button = QtGui.QPushButton('Press Me') 141 | button.setWindowTitle('Hello') 142 | button.show() 143 | 144 | app.connect(button, QtCore.SIGNAL('clicked()'), resize) 145 | sys.exit(app.exec_()) 146 | 147 | \end{python} 148 | \end{frame} 149 | 150 | \begin{frame}[fragile] 151 | \frametitle{Some Builtin Widgets} 152 | \begin{columns} 153 | \column[t]{.5\textwidth} 154 | \begin{itemize} 155 | \item QLabel 156 | \item QPushButton 157 | \item QRadioButton 158 | \item QCheckBox 159 | \item QLineEdit 160 | \end{itemize} 161 | \column[t]{.5\textwidth} 162 | \begin{itemize} 163 | \item QComboBox 164 | \item QListView 165 | \item QGroupBox 166 | \item \ldots 167 | \end{itemize} 168 | \end{columns} 169 | \end{frame} 170 | 171 | \begin{frame}[fragile] 172 | \frametitle{Object Oriented Widgets} 173 | \begin{block}{Widget Properties \& Methods} 174 | \begin{itemize} 175 | \item size \& resize() 176 | \item show() \& hide() 177 | \item \ldots 178 | \end{itemize} 179 | \end{block} 180 | \end{frame} 181 | \end{document} 182 | -------------------------------------------------------------------------------- /lectures/slides/12L-gui-ii.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{GUI Programming (II)} 3 | \begin{document} 4 | \frame{\maketitle} 5 | 6 | \begin{frame}[fragile] 7 | \frametitle{Where Were We?} 8 | We saw that the basics elements of a GUI program were 9 | \begin{itemize} 10 | \item widgets 11 | \item event loop 12 | \item signals \& slots 13 | \end{itemize} 14 | \end{frame} 15 | 16 | \begin{frame}[fragile] 17 | \frametitle{Widgets} 18 | 19 | \centering 20 | \includegraphics[width=.9\textwidth]{widgets} 21 | 22 | \end{frame} 23 | 24 | \begin{frame}[fragile] 25 | \frametitle{Widgets} 26 | 27 | \centering 28 | \includegraphics[width=.9\textwidth]{widgets-bespin} 29 | 30 | \end{frame} 31 | 32 | \begin{frame}[fragile] 33 | \frametitle{Widgets} 34 | 35 | \centering 36 | \includegraphics[width=.9\textwidth]{parent-child-widgets} 37 | 38 | \creditto{Qt Documentation} 39 | 40 | \end{frame} 41 | 42 | \begin{frame}[fragile] 43 | \frametitle{Advanced Widgets} 44 | \begin{itemize} 45 | \item Webkit widget 46 | \item Qwt: technical widgets for Qt 47 | \item Matplotlib 48 | \item \ldots 49 | \end{itemize} 50 | \end{frame} 51 | 52 | \begin{frame}[fragile] 53 | 54 | \bigskip 55 | \bigskip 56 | \bigskip 57 | Let's build a more complex \textsc{gui}\ldots 58 | \end{frame} 59 | 60 | \begin{frame}[fragile] 61 | \frametitle{What About the Quit Button?} 62 | \begin{python} 63 | app.connect(main.actionQuit, 64 | QtCore.SIGNAL('activated()'),app.quit) 65 | \end{python} 66 | \end{frame} 67 | 68 | \begin{frame}[fragile] 69 | \frametitle{What About Doing Something?} 70 | 71 | For a lot of applications, we're done. 72 | 73 | For scientific applications, not so much. 74 | \end{frame} 75 | 76 | \begin{frame}[fragile] 77 | \frametitle{Doing Something Complicated} 78 | \begin{itemize} 79 | \item Do a bit here and there\\ 80 | checking for user events. 81 | \item Start another process 82 | \item (Start another thread) 83 | \end{itemize} 84 | \end{frame} 85 | 86 | \begin{frame}[fragile] 87 | \frametitle{Starting Another Process} 88 | \begin{python} 89 | from PyQt4 import QtCore, QtGui 90 | app = QtGui.QApplication(sys.argv) 91 | 92 | button = QtGui.QPushButton('Press Me') 93 | button.setWindowTitle('Hello') 94 | button.show() 95 | 96 | 97 | \end{python} 98 | 99 | \end{frame} 100 | \begin{frame}[fragile] 101 | \frametitle{Starting Another Process (II)} 102 | \begin{python} 103 | 104 | proc = QtCore.QProcess() 105 | def process_output(): 106 | output = proc.readAllStandardOutput() 107 | print 'output from process >>', output, '<<' 108 | 109 | def startit(): 110 | proc.start('python',['sleeper.py','10']) 111 | 112 | app.connect(proc, 113 | QtCore.SIGNAL('readReadyStandardOutput()'), process_output) 114 | app.connect(button, 115 | QtCore.SIGNAL('clicked()'), startit) 116 | 117 | sys.exit(app.exec_()) 118 | \end{python} 119 | \end{frame} 120 | 121 | \begin{frame}[fragile] 122 | \frametitle{One Final Note: Distribution} 123 | \begin{itemize} 124 | \item Pyinstaller 125 | \item py2exe 126 | \end{itemize} 127 | \end{frame} 128 | \end{document} 129 | -------------------------------------------------------------------------------- /lectures/slides/E1-introprogramming.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{Introduction to Python Programming} 3 | \begin{document} 4 | 5 | \frame{\maketitle} 6 | 7 | \note{ 8 | Goals for this session: 9 | 10 | - Be able to run a program. 11 | - Be able to run interactively. 12 | 13 | - Rough understanding of name/object concept. 14 | - Understand control flow. 15 | } 16 | 17 | \begin{frame}[fragile] 18 | \frametitle{What is a Computer?} 19 | 20 | \begin{enumerate} 21 | \item Memory 22 | \item Processor 23 | \item Magic 24 | \end{enumerate} 25 | \end{frame} 26 | 27 | \begin{frame}[fragile] 28 | \frametitle{Python Model} 29 | 30 | \begin{enumerate} 31 | \item Objects 32 | \item Operations on objects 33 | \item Magic 34 | \end{enumerate} 35 | \end{frame} 36 | 37 | \begin{frame}[fragile] 38 | \frametitle{Computer Program} 39 | 40 | \begin{block}{helloword.py} 41 | \begin{python} 42 | print 'Hello World' 43 | \end{python} 44 | \end{block} 45 | \end{frame} 46 | 47 | \begin{frame}[fragile] 48 | \frametitle{Running a Program} 49 | \begin{enumerate} 50 | \item Shell 51 | \item IDE 52 | \end{enumerate} 53 | \end{frame} 54 | 55 | \begin{frame}[fragile] 56 | 57 | \bigskip 58 | \bigskip 59 | \bigskip 60 | Let me show you a demonstration\ldots 61 | 62 | \note{ 63 | \begin{enumerate} 64 | \item Demo shell with vim 65 | \item Demo one IDE 66 | \end{enumerate} 67 | } 68 | 69 | 70 | \end{frame} 71 | 72 | \begin{frame}[fragile] 73 | \frametitle{More Complex Example} 74 | 75 | What is 25 + 20\%? 76 | 77 | \pause 78 | \begin{python} 79 | print 25 * 1.2 80 | \end{python} 81 | \note{Demo the python shell. 82 | 83 | This is basically a glorified calcular} 84 | \end{frame} 85 | 86 | \begin{frame}[fragile] 87 | \frametitle{Tip Calculator} 88 | 89 | \begin{block}{Calculator} 90 | \begin{enumerate} 91 | \item Input: initial amount and the tip percentage. 92 | \item Ouput: final amount. 93 | \end{enumerate} 94 | \end{block} 95 | \end{frame} 96 | 97 | \begin{frame}[fragile] 98 | \frametitle{Blackboard demonstration} 99 | 100 | \note{Use the blackboard to introduce the idea of objects, values and names.} 101 | \end{frame} 102 | 103 | \begin{frame}[fragile] 104 | \frametitle{Flow of Control: Conditionals} 105 | 106 | \begin{block}{Tip Calculator (II)} 107 | \begin{enumerate} 108 | \item Input: initial amount and service quality. 109 | \item Output: final amount. 110 | \end{enumerate} 111 | \end{block} 112 | 113 | \note{ 114 | \begin{python} 115 | initial = .. 116 | 117 | quality = .. 118 | 119 | if quality == 'great': 120 | percentage = 20 121 | else: 122 | percentage = 15 123 | 124 | print initial * (1+percentage/100.0) 125 | 126 | \# discuss 127 | \end{python} 128 | } 129 | 130 | \end{frame} 131 | 132 | \begin{frame}[fragile] 133 | \frametitle{Conditionals} 134 | 135 | \begin{python} 136 | 137 | if : 138 | 139 | 140 | else: 141 | 142 | 143 | \end{python} 144 | \end{frame} 145 | 146 | \begin{frame}[fragile] 147 | \frametitle{Lists} 148 | 149 | \begin{python} 150 | 151 | students = ['Luis','Mark','Rita'] 152 | 153 | print students[0] 154 | print students[1] 155 | print students[2] 156 | \end{python} 157 | 158 | \end{frame} 159 | 160 | \begin{frame}[fragile] 161 | \frametitle{Loops} 162 | 163 | \begin{python} 164 | students = ['Luis','Mark','Rita',...] 165 | 166 | for st in students: 167 | print st 168 | \end{python} 169 | \end{frame} 170 | 171 | \begin{frame}[fragile] 172 | \frametitle{Loops (II)} 173 | 174 | \begin{python} 175 | 176 | students = ['Luis',...] 177 | 178 | looking_for = 'Anna' 179 | 180 | i = 0 181 | while students[i] != looking_for: 182 | i += 1 183 | 184 | if students[i] == looking_for: 185 | print 'Found her' 186 | else: 187 | print "Sorry, she's not registered!" 188 | \end{python} 189 | 190 | \end{frame} 191 | 192 | \end{document} 193 | -------------------------------------------------------------------------------- /lectures/slides/Makefile: -------------------------------------------------------------------------------- 1 | pdfs := $(patsubst %.tex,%.pdf,$(wildcard *.tex)) 2 | all: $(pdfs) 3 | 4 | .PHONY: all 5 | 6 | %.pdf: %.tex headers/slheader.tex 7 | ./do-slides.sh $< 8 | -------------------------------------------------------------------------------- /lectures/slides/countframes.py: -------------------------------------------------------------------------------- 1 | import vim 2 | import re 3 | cb = vim.current.buffer 4 | Nframe = 0 5 | begin_pat = re.compile(r'\\begin{frame}(?:\[fragile\])?( % slide [0-9]+)?') 6 | 7 | for i,line in enumerate(cb): 8 | if line.startswith(r'\frame{') or line.startswith(r'\begin{frame}'): 9 | if begin_pat.match(line): 10 | fragile = ('[fragile]' if line.find('fragile') > 0 else '') 11 | cb[i] = r'\begin{frame}%s %% slide %s' % (fragile,Nframe) 12 | Nframe += 1 13 | 14 | print 'Number of frames:', Nframe 15 | -------------------------------------------------------------------------------- /lectures/slides/do-slides.sh: -------------------------------------------------------------------------------- 1 | t=.$1.tex_files 2 | test -d $t || mkdir $t 3 | cd $t 4 | TEXINPUTS=:..:../headers:../headers/cmu-beamer:../images: pdflatex $1 5 | cp `basename $1 tex`pdf .. 6 | cd 7 | -------------------------------------------------------------------------------- /lectures/slides/examples/print_random.py: -------------------------------------------------------------------------------- 1 | import random 2 | random.seed(0) 3 | print random.random() 4 | print random.random() 5 | print random.random() 6 | random.seed(0) 7 | print random.random() 8 | print random.random() 9 | print random.random() 10 | 11 | import numpy.random 12 | numpy.random.seed(0) 13 | print numpy.random.random() 14 | print numpy.random.random() 15 | print numpy.random.random() 16 | numpy.random.seed(0) 17 | print numpy.random.random() 18 | print numpy.random.random() 19 | print numpy.random.random() 20 | 21 | -------------------------------------------------------------------------------- /lectures/slides/figures/.gitignore: -------------------------------------------------------------------------------- 1 | generated/ 2 | -------------------------------------------------------------------------------- /lectures/slides/figures/01-energy-barrier.py: -------------------------------------------------------------------------------- 1 | from pylab import * 2 | X=linspace(0,1,1000) 3 | def sigm(X,loc,lam): 4 | return 1./(1.+exp( - (X-loc) * lam)) 5 | plot(X,1-.6*sigm(X,.2,1000)+sigm(X,.5,20)+sigm(X,.6,30)) 6 | ylim(0,3) 7 | xlabel(r'Time $\rightarrow$') 8 | ylabel('Productivity') 9 | 10 | xticks((0,.2,.8,1.),('Current','Learn New Thing','Use if Effectively','')) 11 | yticks((),()) 12 | 13 | savefig('energybarrier.pdf') 14 | -------------------------------------------------------------------------------- /lectures/slides/figures/10-circle.py: -------------------------------------------------------------------------------- 1 | from pylab import * 2 | from numpy.random import random 3 | ps = filter(lambda x: (x[0]**2+x[1]**2 <= 1.),[(2*random()-1,2*random()-1) for i in xrange(10000)]) 4 | ps = array(ps).T 5 | plot(ps[0],ps[1],'rx') 6 | savefig('generated/10-circle.pdf') 7 | 8 | -------------------------------------------------------------------------------- /lectures/slides/figures/10-complexcontour.py: -------------------------------------------------------------------------------- 1 | from pylab import * 2 | from numpy.random import random, seed 3 | seed(1234) 4 | def d2(x,y): 5 | return exp(-maximum(x**2,y**2)) 6 | def P(x,y): 7 | return .8*d2(x,y)*exp(-x**2-y**2) 8 | 9 | X, Y = meshgrid(linspace(-1,1,1000),linspace(-1,1,1000)) 10 | 11 | xs = [(0.,0.)] 12 | iters = int(1e6) 13 | for i in xrange(iters): 14 | next = (xs[-1][0] + normal(scale=.1),xs[-1][1] + normal(scale=.1)) 15 | a = random() 16 | if a < P(*next)/P(*xs[-1]): 17 | xs.append(next) 18 | else: 19 | xs.append(xs[-1]) 20 | 21 | xs = array(xs).T 22 | contour(X,Y,.8*d2(X,Y)*exp(-X**2-Y**2)) 23 | savefig('generated/10-complexcontour.pdf') 24 | plot(xs[0][::1000],xs[1][::1000],'rx') 25 | savefig('generated/10-complexcontour-samples.pdf') 26 | -------------------------------------------------------------------------------- /lectures/slides/figures/10-mcmc.py: -------------------------------------------------------------------------------- 1 | from pylab import * 2 | from numpy import * 3 | X = linspace(-2,2,1000) 4 | def P(x): 5 | return 1./sqrt(2*pi) * ( 4*.2*exp(-8*x**2)+sqrt(24)*.5*exp(-12*(x-1.)**2)+sqrt(36)*.3*exp(-18*(x+1.)**2) ) 6 | random.seed(123) 7 | 8 | def mcmc(iters,scale): 9 | xs = [0.] 10 | for i in xrange(iters): 11 | next = xs[-1] + normal(scale=scale) 12 | a = random.random() 13 | if a < P(next)/P(xs[-1]): 14 | xs.append(next) 15 | else: 16 | xs.append(xs[-1]) 17 | return xs 18 | xs = mcmc(100000,.1) 19 | plot(X,P(X)) 20 | savefig('generated/10-Px.pdf') 21 | hist(xs,len(xs)//10,normed=True) 22 | savefig('generated/10-Px-hist.pdf') 23 | 24 | clf() 25 | xs = mcmc(10000,.01) 26 | plot(X,P(X)) 27 | hist(xs,len(xs)//10,normed=True) 28 | savefig('generated/10-Px-hist-notmixed.pdf') 29 | 30 | -------------------------------------------------------------------------------- /lectures/slides/figures/10-mcmcmin.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | from pylab import * 3 | X = linspace(-4,2,1000) 4 | def f(x): 5 | return x**4+4*x**3-4*x 6 | 7 | def P(x,T): 8 | return exp(-T*(4+f(x))) 9 | 10 | T = 1. 11 | R = numpy.random.RandomState(123) 12 | def greedy(x0,sigma): 13 | Rs = [x0] 14 | for i in xrange(int(1e6)): 15 | c = Rs[-1] + R.normal(scale=sigma) 16 | if R.rand() < P(c,T)/P(Rs[-1],T): 17 | Rs.append(c) 18 | else: 19 | Rs.append(Rs[-1]) 20 | return np.array(Rs) 21 | 22 | 23 | xs = greedy(2,.1) 24 | plot(X,X**4+4*X**3-4*X) 25 | hist(xs[::100],len(xs)//1000,normed=True) 26 | savefig('generated/10-mcmcmin.pdf') 27 | -------------------------------------------------------------------------------- /lectures/slides/figures/Track.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/figures/Track.dia -------------------------------------------------------------------------------- /lectures/slides/figures/catastrophic.py: -------------------------------------------------------------------------------- 1 | from pylab import * 2 | def f(x): 3 | return (1.-cos(x))/(x**2) 4 | X = linspace(-10e-8,10e-8,1000) 5 | plot(X,f(X)) 6 | xlabel(r'$x$') 7 | ylabel(r'$\frac{1.-\cos x}{x^2}$') 8 | savefig('generated/catastrophic.pdf') 9 | 10 | -------------------------------------------------------------------------------- /lectures/slides/figures/circle.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from matplotlib import pyplot as plt 3 | 4 | def rcircle(): 5 | while True: 6 | y = 2*np.random.random()-1 7 | x = 2*np.random.random()-1 8 | if x*x+y*y < 1.: 9 | return y,x 10 | 11 | X = np.array([rcircle() for i in xrange(10000)]) 12 | plt.plot(X.T[0], X.T[1], 'r,') 13 | plt.gca().set_aspect('equal') 14 | plt.savefig('generated/circle.png') 15 | -------------------------------------------------------------------------------- /lectures/slides/figures/doit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | mkdir -p generated 4 | parallel -j6 python {0} ::: *.py 5 | -------------------------------------------------------------------------------- /lectures/slides/figures/fastqtrim.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from matplotlib import pyplot as plt 3 | vs = np.array([ 4 | 20,18,30,32,31,22,28,32,33,32,32,31,30,31,32,30,28,30,24,22,22,20,20,20]) 5 | x = np.arange(len(vs)) 6 | x2 = x + .99 7 | plt.plot(np.array([x,x2]).T.ravel(), np.repeat(vs,2)) 8 | plt.plot([0,len(vs)+1], [26,26]) 9 | plt.savefig('generated/fastqtrim.pdf') 10 | -------------------------------------------------------------------------------- /lectures/slides/figures/functionmin.py: -------------------------------------------------------------------------------- 1 | from pylab import * 2 | X = linspace(-4,2,1000) 3 | plot(X,X**4+4*X**3-4*X) 4 | savefig('functionmin.pdf') 5 | 6 | -------------------------------------------------------------------------------- /lectures/slides/figures/gaussian-with-dots.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from matplotlib import pyplot as plt 3 | X = np.linspace(-4, 4, 100) 4 | Y = np.exp(.5-X*X) 5 | plt.plot(X, Y, 'bo') 6 | plt.plot(X, Y, 'r-') 7 | plt.xlabel(r'$x$') 8 | plt.ylabel(r'$\exp \frac{x^2}{2}$') 9 | 10 | plt.savefig('generated/gaussian.pdf') 11 | -------------------------------------------------------------------------------- /lectures/slides/figures/gentracks.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/figures/gentracks.dia -------------------------------------------------------------------------------- /lectures/slides/figures/graddesc.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | from pylab import * 3 | X = linspace(-4,2,1000) 4 | def f(x): 5 | return x**4+4*x**3-4*x 6 | 7 | def f_(x): 8 | return 4*x**3+12*x**2-4 9 | 10 | def f__(x): 11 | return 12*x**2+24*x 12 | 13 | def graddesc(x0): 14 | Xs = [x0] 15 | eps = 1e-3 16 | for i in xrange(1000): 17 | Xs.append(Xs[-1]-eps*f_(Xs[-1])) 18 | return np.array(Xs) 19 | 20 | def newton(x0): 21 | Xs = [x0] 22 | for i in xrange(1000): 23 | Xs.append(Xs[-1]-f_(Xs[-1])/f__(Xs[-1])) 24 | return np.array(Xs) 25 | 26 | R = numpy.random.RandomState(123) 27 | def greedy(x0,sigma): 28 | Rs = [x0] 29 | for i in xrange(1000): 30 | c = Rs[-1] + R.normal(scale=sigma) 31 | if f(c) < f(Rs[-1]): 32 | Rs.append(c) 33 | else: 34 | Rs.append(Rs[-1]) 35 | return np.array(Rs) 36 | 37 | 38 | for x0 in (2.,-4.): 39 | Xs = graddesc(x0) 40 | for k in [2,10,25,100,1000]: 41 | clf() 42 | plot(X,f(X)) 43 | xlabel(r'$x$') 44 | ylabel(r'$x^4+4x^3-4x$') 45 | plot(Xs[:k],f(Xs[:k]),'rx') 46 | savefig('generated/graddesc-x0%s-%s.pdf' % (int(x0),k)) 47 | N = newton(x0) 48 | clf() 49 | xlabel(r'$x$') 50 | ylabel(r'$x^4+4x^3-4x$') 51 | plot(X,f(X)) 52 | plot(N[:10],f(N[:10]),'rx') 53 | savefig('generated/newton-x0%s.pdf' % int(x0)) 54 | 55 | Rs = greedy(2.,0.1) 56 | clf() 57 | xlabel(r'$x$') 58 | ylabel(r'$x^4+4x^3-4x$') 59 | plot(X,f(X)) 60 | plot(Rs[:100],f(Rs[:100]),'rx') 61 | savefig('generated/random-x0%s-sigma-1.pdf' % int(x0)) 62 | 63 | 64 | Rs = greedy(2.,1.) 65 | clf() 66 | xlabel(r'$x$') 67 | ylabel(r'$x^4+4x^3-4x$') 68 | plot(X,f(X)) 69 | plot(Rs[:100],f(Rs[:100]),'rx') 70 | savefig('generated/random-x0%s-sigma1.pdf' % int(x0)) 71 | 72 | 73 | 74 | clf() 75 | plot(f(Xs[:20]),'r') 76 | plot(f(N[:20]),'g') 77 | xlabel('iteration') 78 | ylabel(r'$f(x)$') 79 | legend(('Gradient Descent','Newton')) 80 | savefig('generated/newton-vs-gd-x0%s.pdf' % int(x0)) 81 | 82 | -------------------------------------------------------------------------------- /lectures/slides/figures/matplotlibexample.py: -------------------------------------------------------------------------------- 1 | import pylab 2 | import numpy as np 3 | X = np.linspace(-4,+4,1000) 4 | pylab.plot(X,np.exp(-X**2)) 5 | pylab.xlabel(r'$x$') 6 | pylab.ylabel(r'$\exp(-x^{2})$') 7 | pylab.savefig('generated/matplotlibexample.pdf') 8 | -------------------------------------------------------------------------------- /lectures/slides/figures/plotprng.py: -------------------------------------------------------------------------------- 1 | from pylab import * 2 | def update(x, a, b): 3 | return a*x % b 4 | a = 48271 5 | b = 2**31-1 6 | x = 2321 7 | ys = [x] 8 | for i in xrange(128): 9 | x = update(x, a, b) 10 | ys.append(x) 11 | plot(ys) 12 | savefig('generated/prnwalk.pdf') 13 | -------------------------------------------------------------------------------- /lectures/slides/headers/cmu-beamer/beamercolorthemeCMU.sty: -------------------------------------------------------------------------------- 1 | 2 | % Copyright 2006 by Lu\'is Pedro Coelho 3 | % Copyright 2003 by Till Tantau . 4 | % 5 | % This program can be redistributed and/or modified under the terms 6 | % of the GNU Public License, version 2. 7 | 8 | \mode 9 | 10 | 11 | \definecolor{cmudarkred}{rgb}{0.72,0.15,0.20} 12 | \definecolor{cmulightred}{rgb}{0.72,0.15,0.20} 13 | \definecolor{cmutitle}{rgb}{0.36,.07,.10} 14 | 15 | 16 | \setbeamercolor{palette primary}{bg=cmudarkred} 17 | \setbeamercolor{palette secundary}{bg=cmudarkred} 18 | \setbeamercolor{palette tertiary}{bg=cmudarkred,fg=white} 19 | \setbeamercolor{titlelike}{bg=cmulightred,fg=white} 20 | \setbeamercolor{title}{bg=cmulightred!70!black,fg=white} 21 | 22 | 23 | \setbeamercolor{section number projected}{bg=cmudarkred} 24 | \setbeamercolor{section in toc}{fg=cmudarkred} 25 | 26 | \setbeamercolor{item projected}{bg=cmudarkred} 27 | \setbeamercolor{subitem projected}{parent=item projected} 28 | 29 | \setbeamercolor{block title}{parent=titlelike} 30 | 31 | \setbeamercolor{block body}{parent=normal text,use=block title,bg=block title.bg!25!bg} 32 | 33 | \mode 34 | 35 | 36 | \setbeamercolor{palette primary}{bg=cmudarkred} 37 | \setbeamercolor{palette secundary}{bg=cmudarkred} 38 | \setbeamercolor{palette tertiary}{bg=cmudarkred,fg=white} 39 | \setbeamercolor{titlelike}{bg=cmulightred,fg=white} 40 | \setbeamercolor{title}{bg=cmutitle,fg=white} 41 | 42 | 43 | \setbeamercolor{section number projected}{bg=cmudarkred} 44 | \setbeamercolor{section in toc}{fg=cmudarkred} 45 | 46 | \setbeamercolor{item projected}{bg=cmudarkred} 47 | \setbeamercolor{subitem projected}{parent=item projected} 48 | 49 | \setbeamercolor{block title}{parent=titlelike} 50 | 51 | \setbeamercolor{block body}{parent=normal text,use=block title,bg=block title.bg!25!bg} 52 | 53 | \mode 54 | 55 | -------------------------------------------------------------------------------- /lectures/slides/headers/cmu-beamer/beamerinnerthemeCMU.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2006 by Lu\'is Pedro Coelho 2 | % Copyright 2003 by Till Tantau 3 | % 4 | % This program can be redistributed and/or modified under the terms 5 | % of the GNU Public License, version 2. 6 | 7 | \mode 8 | 9 | \DeclareOptionBeamer{shadow}[false]{\def\beamer@themeCMU@shadow{#1}} 10 | \ExecuteOptionsBeamer{shadow=false} 11 | \ProcessOptionsBeamer 12 | 13 | \mode 14 | 15 | \defbeamertemplate{block begin}{CMU}[1][] 16 | {% 17 | \begin{beamercolorbox}[wd=.9\textwidth,ht=2.4ex]{block title}% 18 | \usebeamerfont{block title}\hspace{1em}\raisebox{.1ex}{\insertblocktitle} 19 | \end{beamercolorbox}% 20 | } 21 | 22 | \defbeamertemplate{block end}{CMU}[1][] 23 | {% 24 | %\vspace{-2ex}% 25 | % \begin{beamercolorbox}[wd=.9\textwidth,ht=.3ex]{block title}% 26 | % \end{beamercolorbox}% 27 | % \par 28 | } 29 | 30 | \setbeamertemplate{blocks}[CMU] 31 | \setbeamertemplate{items}[ball] 32 | \setbeamertemplate{sections/subsections in toc}[ball] 33 | \setbeamertemplate{title page}[default][colsep=-4bp,rounded=true,shadow=\beamer@themerounded@shadow] 34 | \setbeamertemplate{part page}[default][colsep=-4bp,rounded=true,shadow=\beamer@themerounded@shadow] 35 | 36 | \mode 37 | -------------------------------------------------------------------------------- /lectures/slides/headers/cmu-beamer/beamerouterthemeCMU.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2006 by Lu\'is Pedro Coelho 2 | % Copyright 2003 by Till Tantau 3 | % 4 | % This program can be redistributed and/or modified under the terms 5 | % of the GNU Public License, version 2. 6 | 7 | \mode 8 | 9 | \setbeamercolor*{author in head/foot}{parent=palette tertiary} 10 | \setbeamercolor*{title in head/foot}{parent=palette tertiary} 11 | \setbeamercolor*{date in head/foot}{parent=palette tertiary} 12 | 13 | \setbeamercolor*{section in head/foot}{parent=palette tertiary} 14 | \setbeamercolor*{subsection in head/foot}{parent=palette primary} 15 | 16 | \defbeamertemplate*{footline}{CMU theme} 17 | { 18 | \leavevmode% 19 | \hbox{% 20 | \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex]{author in head/foot}% 21 | \hspace{1ex}\usebeamerfont{author in head/foot}\insertshortauthor~~(\insertshortinstitute)\hfill$\star$\hfill 22 | \usebeamerfont{title in head/foot}\insertshorttitle\hfill$\star$\hfill 23 | \usebeamerfont{date in head/foot}\insertshortdate{}\hfill 24 | \tiny(\insertframenumber{} / \inserttotalframenumber)\hspace*{1ex} 25 | \end{beamercolorbox}}% 26 | \vskip0pt% 27 | } 28 | 29 | 30 | \defbeamertemplate*{headline}{CMU theme} 31 | {% 32 | } 33 | 34 | \defbeamertemplate*{frametitle}{CMU}[1] 35 | {% 36 | \vspace{-.2ex}% 37 | \vbox{\begin{beamercolorbox}[ht=2em,wd=\paperwidth]{frametitle}% 38 | \hfill% 39 | \end{beamercolorbox}}% 40 | \usebeamerfont{frametitle}% 41 | \vspace{-1.3em}\insertframetitle% 42 | } 43 | 44 | \defbeamertemplate*{title page}{CMU}[1][] 45 | { 46 | \vbox{} 47 | \vfill 48 | \begin{centering} 49 | \begin{beamercolorbox}[sep=8pt,center,#1]{title} 50 | \usebeamerfont{title}\inserttitle\par% 51 | \ifx\insertsubtitle\@empty% 52 | \else% 53 | \vskip0.25em% 54 | {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}% 55 | \fi% 56 | \end{beamercolorbox}% 57 | \vskip1em\par 58 | \begin{beamercolorbox}[sep=8pt,center,#1]{author} 59 | \usebeamerfont{author}\insertauthor 60 | \end{beamercolorbox} 61 | \begin{beamercolorbox}[sep=8pt,center,#1]{institute} 62 | \usebeamerfont{institute}\insertinstitute 63 | \end{beamercolorbox} 64 | \begin{beamercolorbox}[sep=8pt,center,#1]{date} 65 | \usebeamerfont{date}\insertdate 66 | \end{beamercolorbox}\vskip0.5em 67 | {\usebeamercolor[fg]{titlegraphic}\inserttitlegraphic\par} 68 | \end{centering} 69 | \vfill 70 | \hspace*{1em}\includegraphics[height=4ex]{pittsealandlogotype}\hfill\includegraphics[height=4ex]{cmu-wordmark}\hspace*{1em} 71 | } 72 | 73 | \defbeamertemplate*{navigation symbols}{CMU} 74 | {% 75 | % I actually don't like them 76 | } 77 | 78 | \setbeamersize{text margin left=1em,text margin right=1em} 79 | 80 | \mode 81 | 82 | -------------------------------------------------------------------------------- /lectures/slides/headers/cmu-beamer/beamerthemeCMU.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2006 by Lu\'is Pedro Coelho 2 | % Copyright 2003 by Till Tantau 3 | % 4 | % This program can be redistributed and/or modified under the terms 5 | % of the GNU Public License, version 2. 6 | 7 | \mode 8 | 9 | \usefonttheme{CMU} 10 | \usecolortheme{CMU} 11 | \useinnertheme{CMU} 12 | \useoutertheme{CMU} 13 | 14 | \mode 15 | 16 | -------------------------------------------------------------------------------- /lectures/slides/headers/cmu-beamer/cmu-wordmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/headers/cmu-beamer/cmu-wordmark.png -------------------------------------------------------------------------------- /lectures/slides/headers/cmu-beamer/pitt-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/headers/cmu-beamer/pitt-logo.png -------------------------------------------------------------------------------- /lectures/slides/headers/cmu-beamer/pittsealandlogotype.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/headers/cmu-beamer/pittsealandlogotype.png -------------------------------------------------------------------------------- /lectures/slides/headers/slheader.tex: -------------------------------------------------------------------------------- 1 | \documentclass{beamer} 2 | \usetheme{CMU} 3 | 4 | \usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade} 5 | \usepackage{amsmath,amssymb} 6 | \usepackage[utf8]{inputenc} 7 | \usepackage{colortbl} 8 | \usepackage[english]{babel} 9 | \usepackage{booktabs} 10 | \usepackage{slpython} 11 | \usepackage{underscore} 12 | \usepackage{bm} 13 | 14 | \author{Luis Pedro Coelho} 15 | \institute{Programming for Scientists} 16 | 17 | \graphicspath{{../figures/}{../figures/generated/}{../images/}} 18 | 19 | \newcommand*{\code}[1]{\textsl{#1}} 20 | \newcommand*{\Reals}[1]{R} 21 | \newcommand*{\Assign}{\ensuremath{\leftarrow}} 22 | \newcommand{\creditto}[1]{% 23 | \begin{flushright} 24 | (#1) 25 | \end{flushright}% 26 | } 27 | -------------------------------------------------------------------------------- /lectures/slides/headers/slpython.sty: -------------------------------------------------------------------------------- 1 | \usepackage{listings} 2 | \usepackage{textcomp} 3 | \usepackage{setspace} 4 | \usepackage{palatino} 5 | 6 | \renewcommand{\lstlistlistingname}{Code Listings} 7 | \renewcommand{\lstlistingname}{Code Listing} 8 | \definecolor{gray}{gray}{0.5} 9 | \definecolor{green}{rgb}{0,0.5,0} 10 | \definecolor{darkred}{rgb}{0.5,0,0} 11 | \definecolor{darkgreen}{rgb}{0,0.3,0} 12 | \definecolor{darkblue}{rgb}{0,0,0.5} 13 | 14 | \lstnewenvironment{python}[1][]{ 15 | \lstset{ 16 | language=python, 17 | basicstyle=\ttfamily\small\setstretch{1}, 18 | stringstyle=\color{darkred}, 19 | showstringspaces=false, 20 | alsoletter={1234567890}, 21 | otherkeywords={\ , \}, \{}, 22 | keywordstyle=\color{darkblue}, 23 | emph={access,and,break,class,continue,def,del,elif,else,% 24 | except,exec,finally,for,from,global,if,import,in,is,% 25 | lambda,not,or,pass,print,raise,return,try,while}, 26 | emphstyle=\color{darkgreen}\bfseries, 27 | emph={[2]True, False, None, self}, 28 | emphstyle=[2]\color{darkgreen}, 29 | emph={[3]from, import, as}, 30 | emphstyle=[3]\color{darkblue}, 31 | upquote=true, 32 | morecomment=[s]{"""}{"""}, 33 | commentstyle=\color{gray}\slshape, 34 | emph={[4]1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 35 | emphstyle=[4]\color{darkred}, 36 | literate=*% 37 | {:}{{\textcolor{darkblue}:}}{1}% 38 | {=}{{\textcolor{darkblue}=}}{1}% 39 | {-}{{\textcolor{darkblue}-}}{1}% 40 | {+}{{\textcolor{darkblue}+}}{1}% 41 | {/}{{\textcolor{darkblue}/}}{1}% 42 | {*}{{\textcolor{darkblue}*}}{1}% 43 | {!}{{\textcolor{darkblue}!}}{1}% 44 | {(}{{\textcolor{darkblue}(}}{1}% 45 | {)}{{\textcolor{darkblue})}}{1}% 46 | {[}{{\textcolor{darkblue}[}}{1}% 47 | {]}{{\textcolor{darkblue}]}}{1}% 48 | {<}{{\textcolor{darkblue}<}}{1}% 49 | {>}{{\textcolor{darkblue}>}}{1},% 50 | framexleftmargin=1em, framextopmargin=1mm, frame=leftline,#1 51 | }}{} 52 | 53 | 54 | \lstnewenvironment{ccode}[1][]{ 55 | \lstset{language=C, 56 | keywordstyle=\color{blue}\bfseries, 57 | stringstyle=\color{red}, 58 | showstringspaces=false} 59 | }{} 60 | -------------------------------------------------------------------------------- /lectures/slides/images/04-konsole.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/04-konsole.png -------------------------------------------------------------------------------- /lectures/slides/images/11-db-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/11-db-example.png -------------------------------------------------------------------------------- /lectures/slides/images/777.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/777.jpeg -------------------------------------------------------------------------------- /lectures/slides/images/BMPexample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/BMPexample.png -------------------------------------------------------------------------------- /lectures/slides/images/Binarysearchtree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/Binarysearchtree.png -------------------------------------------------------------------------------- /lectures/slides/images/DucksYerevan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/DucksYerevan.jpg -------------------------------------------------------------------------------- /lectures/slides/images/FP-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/FP-example.png -------------------------------------------------------------------------------- /lectures/slides/images/FP-format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/FP-format.png -------------------------------------------------------------------------------- /lectures/slides/images/GPLlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/GPLlogo.png -------------------------------------------------------------------------------- /lectures/slides/images/GradientDescent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/GradientDescent.png -------------------------------------------------------------------------------- /lectures/slides/images/Odometer2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/Odometer2.jpg -------------------------------------------------------------------------------- /lectures/slides/images/RMS.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/RMS.jpeg -------------------------------------------------------------------------------- /lectures/slides/images/Treerotation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/Treerotation.png -------------------------------------------------------------------------------- /lectures/slides/images/ch02dia4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/ch02dia4.png -------------------------------------------------------------------------------- /lectures/slides/images/ch02dia5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/ch02dia5.png -------------------------------------------------------------------------------- /lectures/slides/images/gnu-head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/gnu-head.png -------------------------------------------------------------------------------- /lectures/slides/images/language-ranking-0912-zoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/language-ranking-0912-zoom.png -------------------------------------------------------------------------------- /lectures/slides/images/language-ranking-0912.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/language-ranking-0912.png -------------------------------------------------------------------------------- /lectures/slides/images/parent-child-widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/parent-child-widgets.png -------------------------------------------------------------------------------- /lectures/slides/images/waterfall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/waterfall.png -------------------------------------------------------------------------------- /lectures/slides/images/widgets-bespin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/widgets-bespin.png -------------------------------------------------------------------------------- /lectures/slides/images/widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/lectures/slides/images/widgets.png -------------------------------------------------------------------------------- /lectures/slides/template.tex: -------------------------------------------------------------------------------- 1 | \input{slheader} 2 | \title{<+title+>} 3 | \begin{document} 4 | \frame{\maketitle} 5 | 6 | <+content+> 7 | 8 | \end{document} 9 | -------------------------------------------------------------------------------- /notes/introduction.tex: -------------------------------------------------------------------------------- 1 | \chapter{Introduction to Programming} 2 | 3 | \section{Objects and Values} 4 | 5 | -------------------------------------------------------------------------------- /notes/structured.tex: -------------------------------------------------------------------------------- 1 | \chapter{Structured Programming} 2 | 3 | \section{History} 4 | 5 | In the beginning, there was the bit. 6 | 7 | \section{Functions} 8 | 9 | A good function is readable. 10 | 11 | \begin{itemize} 12 | \item $i,j,k$ for iterators and indices. 13 | \item $N$ (maybe $N$) for a count. 14 | \end{itemize} 15 | 16 | If you are implementing code from a paper that uses short variable names, you should follow the paper. 17 | -------------------------------------------------------------------------------- /projects/ideas.txt: -------------------------------------------------------------------------------- 1 | OBJECT TRACKING 2 | ================ 3 | 4 | * Implement a simulator for tracking 5 | * Implement a GUI for human tracking 6 | -------------------------------------------------------------------------------- /scratchpad/DRY: -------------------------------------------------------------------------------- 1 | "Single Point of Thruth" Principle 2 | -------------------------------------------------------------------------------- /scratchpad/VCS: -------------------------------------------------------------------------------- 1 | Don't comment out code. Delete it. 2 | Be polite: VCS etiquette 3 | Don't use comments to explain changes. Use commit log! 4 | Commit log is for explaining changes. 5 | -------------------------------------------------------------------------------- /scratchpad/bad_documentation: -------------------------------------------------------------------------------- 1 | BAD DOCUMENTATION 2 | ================== 3 | 4 | def bbox(img): 5 | """ 6 | min1,max1,min2,max2 = bbox(img) 7 | 8 | Calculate the bounding box of image img. 9 | """ 10 | ... 11 | -------------------------------------------------------------------------------- /scratchpad/defensive_programming: -------------------------------------------------------------------------------- 1 | Once you fix it, test for it! 2 | -> BUG that crashed the system when fed images with negative numbers. 3 | -> SOLUTION: (1) stop feeding the system images with negative numbers. 4 | (2!) check for negative numbers!! 5 | -------------------------------------------------------------------------------- /scratchpad/numerics: -------------------------------------------------------------------------------- 1 | mention "catastrophic cancellation": 2 | example (From "A Note on Platt's Probabilistic Outputs for SVMs") 3 | 4 | err = 0. 5 | for i in xrange(N): 6 | p = ... # a probability estimate 7 | err += t*log(p)+(1-t)*log(1-p) 8 | 9 | 10 | * 11 | 12 | In [30]: 0.3 * 0.3 == .9 13 | Out[30]: False 14 | 15 | ** 16 | 17 | We note that using GNU MP is two orders of magnitude slower than built-in double precision arithmetic. "3d zernike descriptors for content based shape retrieval" by Novotni & Klein 18 | 19 | * 20 | 21 | In [21]: A=3.8 22 | 23 | In [22]: A 24 | Out[22]: 3.7999999999999998 25 | 26 | -------------------------------------------------------------------------------- /scratchpad/numerics11.py: -------------------------------------------------------------------------------- 1 | print 1.1 * 0 == 0.0 2 | print 1.1 * 1 == 1.1 3 | print 1.1 * 2 == 2.2 4 | print 1.1 * 3 == 3.3 5 | print 1.1 * 4 == 4.4 6 | print 1.1 * 5 == 5.5 7 | print 1.1 * 6 == 6.6 8 | print 1.1 * 7 == 7.7 9 | print 1.1 * 8 == 8.8 10 | print 1.1 * 9 == 9.9 11 | print 1.1 *10 == 11 12 | -------------------------------------------------------------------------------- /scratchpad/python_is_not_matlab: -------------------------------------------------------------------------------- 1 | (1) 2 | 3 | if condition: 4 | variable = True 5 | else: 6 | variable = False 7 | 8 | ============> 9 | 10 | variable = condition 11 | 12 | (2) 13 | 14 | variable = value 15 | return variable 16 | 17 | ===========> 18 | 19 | return value 20 | -------------------------------------------------------------------------------- /scratchpad/quotes: -------------------------------------------------------------------------------- 1 | Programs must be written for people to read, and only incidentally for machines to execute. 2 | —Abelson & Sussman, Structure and Interpretation of Computer Programs 3 | 4 | * 5 | 6 | Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. 7 | —Brian W. Kernighan, co-author of The C Programming Language and the "K" in "AWK" 8 | 9 | * 10 | 11 | Python is executable pseudo-code (Python lore --- sometimes Bruce Eckel) 12 | 13 | 14 | -------------------------------------------------------------------------------- /scratchpad/simple_faster/BAD: -------------------------------------------------------------------------------- 1 | labeled,N = ndimage.label(protproc > 0) 2 | if N == 0: 3 | return numpy.zeros(5,double) 4 | for obj in xrange(1,obj+1): 5 | objimage = croptobbox(protproc * (labeled == (obj+1))) 6 | -------------------------------------------------------------------------------- /scratchpad/simple_faster/GOOD: -------------------------------------------------------------------------------- 1 | labeled,N = ndimage.label(protproc > 0) 2 | if N == 0: 3 | return numpy.zeros(5,double) 4 | objects = ndimage.find_objects(labeled) 5 | for i,slice in enumerate(objects): 6 | objimage = protproc[slice] * (labeled[slice] == (i+1)) 7 | -------------------------------------------------------------------------------- /scratchpad/software_carpentry: -------------------------------------------------------------------------------- 1 | Introduce the shell 2 | 3 | -------------------------------------------------------------------------------- /spring-2009/handouts/01-questionaire.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/handouts/01-questionaire.pdf -------------------------------------------------------------------------------- /spring-2009/handouts/05L-questionaire.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/handouts/05L-questionaire.pdf -------------------------------------------------------------------------------- /spring-2009/handouts/08-open-source.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/handouts/08-open-source.pdf -------------------------------------------------------------------------------- /spring-2009/handouts/13-questionaire.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/handouts/13-questionaire.pdf -------------------------------------------------------------------------------- /spring-2009/homeworks/01-intro-python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/homeworks/01-intro-python.pdf -------------------------------------------------------------------------------- /spring-2009/homeworks/02-oop.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/homeworks/02-oop.pdf -------------------------------------------------------------------------------- /spring-2009/homeworks/03-python-odds.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/homeworks/03-python-odds.pdf -------------------------------------------------------------------------------- /spring-2009/homeworks/04-softwarecarpentry.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/homeworks/04-softwarecarpentry.pdf -------------------------------------------------------------------------------- /spring-2009/homeworks/05-softwarecarpentry-ii.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/homeworks/05-softwarecarpentry-ii.pdf -------------------------------------------------------------------------------- /spring-2009/homeworks/06-numerical.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/homeworks/06-numerical.pdf -------------------------------------------------------------------------------- /spring-2009/homeworks/07-optimisation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/homeworks/07-optimisation.pdf -------------------------------------------------------------------------------- /spring-2009/homeworks/08-open-source.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/homeworks/08-open-source.pdf -------------------------------------------------------------------------------- /spring-2009/homeworks/09-fileparsing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/homeworks/09-fileparsing.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/01-intro.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/01-intro.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/01L-python-intro.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/01L-python-intro.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/02-oop.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/02-oop.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/02L-python-odds-ends.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/02L-python-odds-ends.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/03-odds-ii-errors.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/03-odds-ii-errors.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/03L-python-review.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/03L-python-review.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/04-softwarecarpentry.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/04-softwarecarpentry.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/04L-softwarecarpentry-ii.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/04L-softwarecarpentry-ii.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/05-softwarecarpentry-iii.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/05-softwarecarpentry-iii.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/05L-softwarecarpentry-iv.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/05L-softwarecarpentry-iv.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/06-numerical.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/06-numerical.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/06L-numpy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/06L-numpy.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/07-optimisation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/07-optimisation.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/07L-misc-project.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/07L-misc-project.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/08-open-source.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/08-open-source.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/09-fileparsing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/09-fileparsing.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/09L-fileformats.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/09L-fileformats.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/10-metropolis-hastings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/10-metropolis-hastings.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/10L-software-engineering.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/10L-software-engineering.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/11-databases.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/11-databases.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/11L-databases-ii.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/11L-databases-ii.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/12-gui.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/12-gui.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/12L-gui-ii.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/12L-gui-ii.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/13-review.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/13-review.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/15-other-languages.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/15-other-languages.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/E1-introprogramming.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/E1-introprogramming.pdf -------------------------------------------------------------------------------- /spring-2009/lecture-slides/pycon2003.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/spring-2009/lecture-slides/pycon2003.pdf -------------------------------------------------------------------------------- /website/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /website/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | 9 | # Internal variables. 10 | PAPEROPT_a4 = -D latex_paper_size=a4 11 | PAPEROPT_letter = -D latex_paper_size=letter 12 | ALLSPHINXOPTS = -d build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 13 | 14 | .PHONY: help clean html web pickle htmlhelp latex changes linkcheck publish 15 | 16 | help: 17 | @echo "Please use \`make ' where is one of" 18 | @echo " html to make standalone HTML files" 19 | @echo " pickle to make pickle files (usable by e.g. sphinx-web)" 20 | @echo " htmlhelp to make HTML files and a HTML help project" 21 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 22 | @echo " changes to make an overview over all changed/added/deprecated items" 23 | @echo " linkcheck to check all external links for integrity" 24 | 25 | clean: 26 | -rm -rf build/* 27 | 28 | publish: html 29 | cp -r build/html/* /var/www/pfs 30 | cp -r ../spring-2009/lecture-slides /var/www/pfs 31 | cp -r ../spring-2009/homeworks /var/www/pfs 32 | 33 | html: 34 | mkdir -p build/html build/doctrees 35 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) build/html 36 | @echo 37 | @echo "Build finished. The HTML pages are in build/html." 38 | 39 | pickle: 40 | mkdir -p build/pickle build/doctrees 41 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) build/pickle 42 | @echo 43 | @echo "Build finished; now you can process the pickle files or run" 44 | @echo " sphinx-web build/pickle" 45 | @echo "to start the sphinx-web server." 46 | 47 | web: pickle 48 | 49 | htmlhelp: 50 | mkdir -p build/htmlhelp build/doctrees 51 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) build/htmlhelp 52 | @echo 53 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 54 | ".hhp project file in build/htmlhelp." 55 | 56 | latex: 57 | mkdir -p build/latex build/doctrees 58 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) build/latex 59 | @echo 60 | @echo "Build finished; the LaTeX files are in build/latex." 61 | @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \ 62 | "run these through (pdf)latex." 63 | 64 | changes: 65 | mkdir -p build/changes build/doctrees 66 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) build/changes 67 | @echo 68 | @echo "The overview file is in build/changes." 69 | 70 | linkcheck: 71 | mkdir -p build/linkcheck build/doctrees 72 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) build/linkcheck 73 | @echo 74 | @echo "Link check complete; look for any errors in the above output " \ 75 | "or in build/linkcheck/output.txt." 76 | -------------------------------------------------------------------------------- /website/audio.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | Lecture Audio 3 | ============== 4 | 5 | At the request of some students, I have made audio recordings of the lectures. 6 | 7 | 1. Not available (introduction) 8 | 2. `Lecture 2`_: Python I 9 | 3. `Lecture 3`_: Python II 10 | 4. `Lecture 4`_: Python III 11 | 5. `Lecture 5`_: Python IV 12 | 6. Not available In-class Exercises 13 | 7. `Lecture 7`_: Sofware Carpentry (SC I) 14 | 8. `Lecture 8`_: SC II. Version Control 15 | 9. SC III. Defensive Programming & Testing 16 | 10. `Lecture 10`_: SC IV. Debugger & Profiler 17 | 11. `Lecture 11`_: Numerical Representations 18 | 12. `Lecture 12`_: Numpy (Not yet available) 19 | 20 | .. _`Lecture 2` : lecture-audio/lec01L.mp3 21 | .. _`Lecture 3` : lecture-audio/lec02.mp3 22 | .. _`Lecture 4` : lecture-audio/lec02L.mp3 23 | .. _`Lecture 5` : lecture-audio/lec03.mp3 24 | .. _`Lecture 7` : lecture-audio/lec04.mp3 25 | .. _`Lecture 8` : lecture-audio/lec04L.mp3 26 | .. _`Lecture 10` : lecture-audio/lec05L.mp3 27 | .. _`Lecture 11` : lecture-audio/lec06.mp3 28 | .. _`Lecture 12` : lecture-audio/lec06L.mp3 29 | -------------------------------------------------------------------------------- /website/copyright.rst: -------------------------------------------------------------------------------- 1 | =================== 2 | Copyright Statement 3 | =================== 4 | 5 | These pages, including lecture slides, homeworks, and notes, are made available 6 | under the Attribution-NonCommercial-ShareAlike Creative Commons license, with 7 | the added clause that use in a class at an accredited degree granting 8 | institution is also permissible as long as you comply with the other terms of 9 | the license (namely, Attribution and Share Alike). 10 | 11 | If you do use these in a class, I would appreciate it if you dropped me a note 12 | with any comments/corrections. Thank you. 13 | 14 | Everything in these pages, including lecture slides and lecture notes, is by 15 | Luis Pedro Coelho, except where otherwise noted. 16 | 17 | 18 | Availability 19 | ------------ 20 | 21 | All materials for this class (including LaTeX source to slides and notes) are 22 | available at `github 23 | `_. 24 | 25 | -------------------------------------------------------------------------------- /website/faq.rst: -------------------------------------------------------------------------------- 1 | =========================== 2 | Frequently Asked Questions 3 | =========================== 4 | 5 | Can I audit your course? 6 | ~~~~~~~~~~~~~~~~~~~~~~~~ 7 | 8 | You are welcome to audit, sit in, or otherwise participate in the way that you think benefits you the most. 9 | 10 | I don't know how to program? Is your course good for me? 11 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 | 13 | Yes, you just have to be prepared to work a bit harder at the start to catch up (including a couple of extra sessions: check the syllabus for details). 14 | -------------------------------------------------------------------------------- /website/homeworks.rst: -------------------------------------------------------------------------------- 1 | ================= 2 | Homeworks 3 | ================= 4 | 5 | Homework 8 & 9 (due Apr 5) 6 | ---------------------------------------------- 7 | 8 | `Homework 8`_ and `homework 9`_. 9 | 10 | .. _`Homework 8`: homeworks/08-open-source.pdf 11 | .. _`Homework 9`: homeworks/09-fileparsing.pdf 12 | 13 | Homework 7 (due Mar 17) 14 | ---------------------------------------------- 15 | 16 | `Homework 7`_. If you have already completed seven homeworks, then you do not need to do this one, but you still need to email me your project_ preferences. 17 | 18 | .. _`Homework 7`: homeworks/07-optimisation.pdf 19 | .. _project: project 20 | 21 | Homework 6 (due Mar 3) 22 | ---------------------------------------------- 23 | 24 | `Homework 6`_. 25 | 26 | .. _`Homework 6`: homeworks/06-numerical.pdf 27 | 28 | Homework 5 (due Feb 24) 29 | ---------------------------------------------- 30 | 31 | `Homework 5`_. You don't strictly need it, but you might want to check out `bst.py`_. 32 | 33 | .. _`Homework 5`: homeworks/05-softwarecarpentry-ii.pdf 34 | .. _`bst.py`: _static/bst.py 35 | 36 | Homework 4 (due Feb 17) 37 | ---------------------------------------------- 38 | 39 | `Homework 4`_: This is a slightly different homework. The *programming assignment* is different and slightly longer. Therefore, you only get 2 questions. Be sure to check the notes_ for links. 40 | 41 | .. _`Homework 4`: homeworks/04-softwarecarpentry.pdf 42 | .. _notes: notes.html 43 | 44 | Homework 3 (due Feb 10) 45 | ---------------------------------------------- 46 | 47 | `Homework 3`_ 48 | 49 | .. _`Homework 3`: homeworks/03-python-odds.pdf 50 | 51 | Homework 2 (due Feb 4 [you get an extra day!]) 52 | ---------------------------------------------- 53 | 54 | `Homework 2`_ (you will also need `bacteria.py`_, and you can look at `simulatebac.py`_ as an example). As before, solutions by email. 55 | 56 | .. _`Homework 2`: _static/pfs-hw-02.pdf 57 | .. _`bacteria.py`: _static/bacteria.py 58 | .. _`simulatebac.py`: _static/simulatebac.py 59 | 60 | 61 | Homework 1 (due Jan 27) 62 | ----------------------- 63 | 64 | Available here_. Solutions by email. 65 | 66 | .. _here: _static/pfs-hw-01.pdf 67 | 68 | 69 | 70 | Homework 0 (due Jan 20) 71 | ----------------------- 72 | 73 | Run the following Python code and email me the result: 74 | 75 | :: 76 | 77 | email = 'YOUR EMAIL ADDRESS' 78 | print email, hash(email) 79 | 80 | 81 | Where 'YOUR EMAIL ADDRESS' should be replaced by your actual email address, of course. The output will be your email followed by a number. 82 | 83 | See the notes_ for information on getting Python for your system. 84 | 85 | .. _notes: notes.html 86 | 87 | -------------------------------------------------------------------------------- /website/index.rst: -------------------------------------------------------------------------------- 1 | ====================================================== 2 | Programming for Scientists 3 | ====================================================== 4 | 5 | **Class Number**: 98-111 6 | 7 | **Meeting Times**: 6.30-7.30PM SH 220 (or SH219, which is next door) 8 | 9 | **Syllabus**: See `Class Info`_ 10 | 11 | **Office Hours**: 4.30pm on Tuesdays (either in 409D Mellon Institute or virtual office hours) 12 | 13 | .. _Class Info: class-info.html 14 | 15 | Pages 16 | ----------- 17 | 18 | .. toctree:: 19 | :maxdepth: 1 20 | 21 | homeworks 22 | project 23 | slides 24 | audio 25 | class-info 26 | faq 27 | notes 28 | python 29 | copyright 30 | 31 | Who is this class for? 32 | ---------------------- 33 | 34 | If a large part of your day is spent programming, but you've never had more than one semester of formal programming training (or less), then this is for you. If all you know is Matlab, then this is for you. If you do not use version control (or don't even really know what it is), then this is for you. 35 | 36 | Programming for Scientists is a course for scientists (biologists, physicists,...) who find themselves programming with not more than an introductory programming course or even just having informally learned how to write code. 37 | 38 | The goal is to make students more effective programmers, who spend less time doing it, who write code that is more efficient, more readable, and has less bugs. A one semester course on the basics of good programming can increase programmer's productivity by 20%. Twenty per-cent is a full year of the typical PhD [numbers from Greg Wilson, U. of Toronto]. 39 | 40 | For the practical part of the course, the Python programming language will be covered. Python is a modern language which is increasingly used for scientific programming. 41 | 42 | 43 | Who teaches it? 44 | --------------- 45 | 46 | This is a *student taught* course, taught by Luis Pedro Coelho, a third-year Ph.D. student in Computational Biology. Luis has a BS and an MS in computer science from IST in Lisbon. 47 | -------------------------------------------------------------------------------- /website/project.rst: -------------------------------------------------------------------------------- 1 | =============== 2 | Projects 3 | =============== 4 | 5 | There are two possibilities: self-proposed or class project. A part of the teaching goals of the class is to teach you tools and techniques for medium-scale collaboration. Therefore, the class project is done by all interested students. Each student (or small group) will work on a separate bit of the project (on which they will be evaluated), but they must make sure that their piece of code *plays well with others*. 6 | 7 | Class Project 8 | -------------- 9 | 10 | The class project is to be done by all students, but will be broken up into individual chunks. 11 | 12 | The overall goal of the project is to (1) simulate a video of particles moving in space, (2) from the video *track the particles*, (3) compare the results of tracking with the simulated tracks. This is to be broken into several pieces, each of which is assigned to one or two students (in brackets, the names of the students working on it): 13 | 14 | 1. Object position generator [John Sekar] 15 | 2. Image generator [Qi Yang] 16 | 3. Object detection [Peng Liu] 17 | 4. Object tracking [Andrej Savol] 18 | 5. Results visualisation [Svetlana Romanova] 19 | 6. Statistics collector [Longzhu Shen] 20 | 21 | We will also spend some class time going over the structure and design of the program. 22 | 23 | To participate in the project, please 24 | 25 | 1. Get a google account (you can use any email) 26 | 2. Email me the email you used to get a google account 27 | 3. Wait for me to add you to the project (I'll reply to your email when I've done so) 28 | 4. Go to the `particles webpage`_ and follow the instructions to downloading the code from google's subversion. You need to be logged in to google to have *write access* to the subversion repository. 29 | 5. Add your name to the AUTHORS.txt file and commit 30 | 31 | .. _`particles webpage`: http://code.google.com/p/particles/ 32 | 33 | Self-Proposed 34 | --------------- 35 | 36 | If you want to propose a project, you can as long as you fulfill most of the following conditions: 37 | 38 | 1. It must be self-contained and be at least 300 lines of code (not counting tests &c). 39 | 2. It must be done in Python. 40 | 3. It should use numpy. 41 | 4. It should include tests and documentation. 42 | 5. It should use version control. 43 | 6. It should either be a part of a bigger project or involve working with libraries/modules not presented in the course (and not written by you). 44 | 45 | -------------------------------------------------------------------------------- /website/python.rst: -------------------------------------------------------------------------------- 1 | ====================================================== 2 | Python 3 | ====================================================== 4 | 5 | What is Python? 6 | --------------- 7 | 8 | Python is a modern, multi-paradigm, programming language that is increasingly used for scientific computation. 9 | 10 | Python was a language designed to be both easy to teach and industrial-strength. It is one of the most widely used languages in the world for general purpose programming. Over the last few years, scientific libraries in Python have matured to a point where they make the language a strong candidate for science. 11 | 12 | The numpy library is a *de facto* standard numerical array library, while the scipy collection of libraries provide access to basic scientific tools (e.g., statistical toolbox, linear algebra), often by providing access to mature code written in other languages. In fact, Python is a very good glue language: you can easily access code written in Fortran, C, or C++ directly from Python. 13 | 14 | The python interpreter is open-source as are most of the basic libraries that support scientific computing. This means that it can be used on any platform, by anyone, anywhere. 15 | 16 | Why not Matlab? 17 | --------------- 18 | 19 | Matlab is a good solution for data exploration or small computations. If you are using its command-line directly, it is very convenient. In fact, many of the tools covered in this class are inspired (or, at the very least, influenced by Matlab). 20 | 21 | However, the moment you save commands to a file, I would argue you are writing software (even if on a small scale). For this, Matlab is less appropriate. In part, the same characteristics that make it a convenient tool at the command-line, make it unusable for even small scale software projects. The flat namespace or the fact that each function corresponds to a file are two characteristics that aid command-line use, but hinder software writing. In this sense, it is similar to a Unix shell: fast to use if you're typing commands directly, but not scalable. 22 | 23 | Matlab is still, at its core, a matrix processing language. For matrix processing, its expressive power is unmatched, at the cost of forcing everything else to conform to it. String processing is especially painful. Therefore, I rather choose a language that can be used in any domain. 24 | -------------------------------------------------------------------------------- /website/slides.rst: -------------------------------------------------------------------------------- 1 | =============== 2 | Lecture Slides 3 | =============== 4 | 5 | These are the slides as delivered, except for the occasional fixed typo. 6 | 7 | 1. `Lecture 1`_: Introduction. 8 | 2. `Tutorial Session`_: Introduction to Programming. 9 | 3. `Lecture 2`_: Introduction to Python. 10 | 4. `Lecture 3`_: Object-Oriented Programming. 11 | 5. `Lecture 4`_: Python Odds & Ends. 12 | 6. `Lecture 5`_: Python Odds & Ends (II) & Error Handling. 13 | 7. `Lecture 6`_: Python Review 14 | 8. `Lecture 7`_: Software Carpentry I: The shell 15 | 9. `Lecture 8`_: Software Carpentry II: Version Control 16 | 10. `Lecture 9`_: Software Carpentry III: Defensive Programming & Testing 17 | 11. `Lecture 10`_: Software Carpentry IV: Profiling & Debugging 18 | 12. `Lecture 11`_: Numerical Representations 19 | 13. `Lecture 12`_: Numpy 20 | 14. `Lecture 13`_: Function Minimisation 21 | 15. `Lecture 14`_: Misc & Projects 22 | 16. `Lecture 15`_: Open Source 23 | 17. `Lecture 16`_: Workshop (project) 24 | 18. `Lecture 17`_: File Parsing 25 | 19. `Lecture 18`_: Basic File Formats 26 | 20. `Lecture 19`_: Metropolis-Hastings 27 | 21. `Lecture 20`_: Software Engineering 28 | 22. `Lecture 21`_: Databases I 29 | 23. `Lecture 22`_: Databases II 30 | 24. `Lecture 23`_: GUI Programming 31 | 25. `Lecture 24`_: GUI Programming II 32 | 26. `Lecture 25`_: Review 33 | 27. `Lecture 28`_: Interfacing Other Languages 34 | 35 | 36 | .. _`Lecture 1`: http://luispedro.org/pfs/lecture-slides/01-intro.pdf 37 | .. _`Tutorial Session`: http://luispedro.org/pfs/lecture-slides/E1-introprogramming.pdf 38 | .. _`Lecture 2`: http://luispedro.org/pfs/lecture-slides/01L-python-intro.pdf 39 | .. _`Lecture 3`: http://luispedro.org/pfs/lecture-slides/02-oop.pdf 40 | .. _`Lecture 4`: http://luispedro.org/pfs/lecture-slides/02L-python-odds-ends.pdf 41 | .. _`Lecture 5`: http://luispedro.org/pfs/lecture-slides/03-odds-ii-errors.pdf 42 | .. _`Lecture 6`: http://luispedro.org/pfs/lecture-slides/03L-python-review.pdf 43 | .. _`Lecture 7`: http://luispedro.org/pfs/lecture-slides/04-softwarecarpentry.pdf 44 | .. _`Lecture 8`: http://luispedro.org/pfs/lecture-slides/04L-softwarecarpentry-ii.pdf 45 | .. _`Lecture 9`: http://luispedro.org/pfs/lecture-slides/05-softwarecarpentry-iii.pdf 46 | .. _`Lecture 10`: http://luispedro.org/pfs/lecture-slides/05L-softwarecarpentry-iv.pdf 47 | .. _`Lecture 11`: http://luispedro.org/pfs/lecture-slides/06-numerical.pdf 48 | .. _`Lecture 12`: http://luispedro.org/pfs/lecture-slides/06L-numpy.pdf 49 | .. _`Lecture 13`: http://luispedro.org/pfs/lecture-slides/07-optimisation.pdf 50 | .. _`Lecture 14`: http://luispedro.org/pfs/lecture-slides/07L-misc-project.pdf 51 | .. _`Lecture 15`: http://luispedro.org/pfs/lecture-slides/08-open-source.pdf 52 | .. _`Lecture 16`: http://luispedro.org/pfs/lecture-slides/08L-workshop.pdf 53 | .. _`Lecture 17`: http://luispedro.org/pfs/lecture-slides/09-fileparsing.pdf 54 | .. _`Lecture 18`: http://luispedro.org/pfs/lecture-slides/09L-fileformats.pdf 55 | .. _`Lecture 19`: http://luispedro.org/pfs/lecture-slides/10-metropolis-hastings.pdf 56 | .. _`Lecture 20`: http://luispedro.org/pfs/lecture-slides/10L-software-engineering.pdf 57 | .. _`Lecture 21`: http://luispedro.org/pfs/lecture-slides/11-databases.pdf 58 | .. _`Lecture 22`: http://luispedro.org/pfs/lecture-slides/11-databases-ii.pdf 59 | .. _`Lecture 23`: http://luispedro.org/pfs/lecture-slides/12-gui.pdf 60 | .. _`Lecture 24`: http://luispedro.org/pfs/lecture-slides/12L-gui-ii.pdf 61 | .. _`Lecture 25`: http://luispedro.org/pfs/lecture-slides/13-review.pdf 62 | .. _`Lecture 28`: http://luispedro.org/pfs/lecture-slides/15-other-languages.pdf 63 | 64 | The source code for these slides is available under `CC-By-Nc-SA`_ on 65 | `Github `__. 66 | 67 | .. _`CC-By-Nc-SA`: http://creativecommons.org/licenses/by-nc-sa/3.0/us/ 68 | 69 | -------------------------------------------------------------------------------- /website/static/03-odds-ii-errors.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/website/static/03-odds-ii-errors.pdf -------------------------------------------------------------------------------- /website/static/E1-introprogramming.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/website/static/E1-introprogramming.pdf -------------------------------------------------------------------------------- /website/static/bacteria.py: -------------------------------------------------------------------------------- 1 | import random 2 | from math import exp 3 | import math 4 | 5 | def exp_dist(d,L): 6 | ''' 7 | p = exp_dist(x,lambda_) 8 | 9 | Returns the cpf the exponential distribution. 10 | 11 | See http://en.wikipedia.org/wiki/Exponential_distribution 12 | ''' 13 | return 1-math.exp(-L*d) 14 | 15 | class Bacteria(object): 16 | ''' 17 | Bacteria 18 | 19 | Implements a simple bacterium 20 | 21 | Functions: 22 | --------- 23 | 24 | * P_dead(self,e): probability of death in environment e 25 | * reproduce(): returns a new bacterium 26 | ''' 27 | L=.95 28 | def __init__(self,adaptation,sigma): 29 | self.adaptation = adaptation 30 | self.sigma = sigma 31 | def P_dead(self,e): 32 | ''' 33 | p = b.P_dead(e) 34 | 35 | Probability of death in environment e (which should be a number) 36 | ''' 37 | return exp_dist(abs(self.adaptation - e),self.L) 38 | def reproduce(self): 39 | ''' 40 | b1 = b.reproduce() 41 | 42 | Return a child of this bacterium 43 | ''' 44 | return Bacteria(self.adaptation + random.normalvariate(0,self.sigma),self.sigma) 45 | 46 | class EvolveSigma(Bacteria): 47 | ''' 48 | EvolveSigma 49 | 50 | EvolveSigma is a type of bacterium where the 51 | sigma parameter evolves at reproduction. 52 | ''' 53 | def __init__(self,adaptation,sigma): 54 | Bacteria.__init__(self,adaptation,sigma) 55 | 56 | def reproduce(self): 57 | return EvolveSigma(self.adaptation + random.normalvariate(0,self.sigma), 58 | self.sigma+random.normalvariate(0.,self.sigma/2.)) 59 | 60 | def simulate(population,environs,max_population,p_reprod): 61 | ''' 62 | simulate(population,environs) 63 | 64 | Simulate iters iterations of evolution. 65 | ''' 66 | for environ in environs: 67 | ai = 0 68 | while ai < len(population): 69 | if population[ai].P_dead(environ) < random.random(): 70 | del population[ai] 71 | else: 72 | ai += 1 73 | N = len(population) 74 | for ai in xrange(N): 75 | if random.random() < p_reprod: 76 | population.append(population[ai].reproduce()) 77 | if N >= max_population: 78 | random.shuffle(population) 79 | while len(population) >= max_population: 80 | population.pop() 81 | 82 | 83 | -------------------------------------------------------------------------------- /website/static/pfs-hw-01.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/website/static/pfs-hw-01.pdf -------------------------------------------------------------------------------- /website/static/pfs-hw-02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luispedro/Programming-for-Scientists/e10ab2a83c9dd8eb2e9d4f0b1cd1bf527659199c/website/static/pfs-hw-02.pdf -------------------------------------------------------------------------------- /website/static/simulatebac.py: -------------------------------------------------------------------------------- 1 | import random 2 | import bacteria 3 | 4 | def mean(values): 5 | ''' 6 | mu = mean(values) 7 | 8 | Compute a mean value. 9 | ''' 10 | return sum(values)/float(len(values)) 11 | 12 | fixed = [.234]*200 13 | sharp = [.2] * 40 + [.4]*40 + [.6]*40 + [.8]*40 + [1.]*40 14 | very_sharp = [.0] * 40 + [.5]*40 + [1.]*40 + [.5]*40 + [0.]*40 15 | smooth = [.01*i for i in xrange(200)] 16 | p_reprod = .3 17 | 18 | experiments = [ 19 | ('fixed env. no sigma evolution', 1000, 0,fixed), 20 | ('fixed env. w sigma evolution', 500,500,fixed), 21 | ('smooth changes env. w sigma evolution', 500,500,smooth), 22 | ('sharp changes env. w sigma evolution', 500,500,sharp), 23 | ('very sharp changes env. w sigma evolution', 500,500,very_sharp), 24 | ] 25 | for name, initial_fixed, initial_evolve, environs in experiments: 26 | print 'Experiment',name 27 | population = [bacteria.Bacteria(random.random(),random.random()) for i in xrange(initial_fixed)] +\ 28 | [bacteria.EvolveSigma(random.random(),random.random()) for i in xrange(initial_evolve)] 29 | bacteria.simulate(population,environs,(initial_fixed+initial_evolve)*10,p_reprod) 30 | print 'Mean sigma:', mean([a.sigma for a in population]) 31 | print 'Mean Adaptation:',mean([b.adaptation for b in population]) 32 | print 'Fraction adaptative:', mean([type(b) == bacteria.EvolveSigma for b in population]) 33 | print 34 | 35 | -------------------------------------------------------------------------------- /website/templates/defindex.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% set title = 'Overview' %} 3 | {% block body %} 4 |

{{ docstitle }}

5 |

6 | Welcome! This is 7 | {% block description %}the documentation for {{ project }} 8 | {{ release }}{% if last_updated %}, last updated {{ last_updated }}{% endif %}{% endblock %}. 9 |

10 | {% block tables %} 11 |

Indices and tables:

12 | 13 | 24 |
14 | 16 | 18 | 19 | 21 | 23 |
25 | {% endblock %} 26 | {% endblock %} 27 | -------------------------------------------------------------------------------- /website/templates/genindex-single.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% set title = 'Index' %} 3 | {% block body %} 4 | 5 |

Index – {{ key }}

6 | 7 |
8 |
9 | {%- set breakat = count // 2 %} 10 | {%- set numcols = 1 %} 11 | {%- set numitems = 0 %} 12 | {% for entryname, (links, subitems) in entries %} 13 |
{%- if links -%}{{ entryname|e }} 14 | {%- for link in links[1:] %}, [Link]{% endfor -%} 15 | {%- else -%} 16 | {{ entryname|e }} 17 | {%- endif -%}
18 | {%- if subitems %} 19 |
20 | {%- for subentryname, subentrylinks in subitems %} 21 |
{{ subentryname|e }} 22 | {%- for link in subentrylinks[1:] %}, [Link]{% endfor -%} 23 |
24 | {%- endfor %} 25 |
26 | {%- endif -%} 27 | {%- set numitems = numitems + 1 + len(subitems) -%} 28 | {%- if numcols < 2 and numitems > breakat -%} 29 | {%- set numcols = numcols+1 -%} 30 |
31 | {%- endif -%} 32 | {%- endfor %} 33 |
34 | 35 | {% endblock %} 36 | 37 | {% block sidebarrel %} 38 |

Index

39 |

{% for key, dummy in genindexentries -%} 40 | {{ key }} 41 | {% if not loop.last %}| {% endif %} 42 | {%- endfor %}

43 | 44 |

Full index on one page

45 | {% endblock %} 46 | -------------------------------------------------------------------------------- /website/templates/genindex-split.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% set title = 'Index' %} 3 | {% block body %} 4 | 5 |

Index

6 | 7 |

Index pages by letter:

8 | 9 |

{% for key, dummy in genindexentries -%} 10 | {{ key }} 11 | {% if not loop.last %}| {% endif %} 12 | {%- endfor %}

13 | 14 |

Full index on one page 15 | (can be huge)

16 | 17 | {% endblock %} 18 | 19 | {% block sidebarrel %} 20 | {% if split_index %} 21 |

Index

22 |

{% for key, dummy in genindexentries -%} 23 | {{ key }} 24 | {% if not loop.last %}| {% endif %} 25 | {%- endfor %}

26 | 27 |

Full index on one page

28 | {% endif %} 29 | {% endblock %} 30 | -------------------------------------------------------------------------------- /website/templates/genindex.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% set title = 'Index' %} 3 | {% block body %} 4 | 5 |

Index

6 | 7 | {% for key, dummy in genindexentries -%} 8 | {{ key }} {% if not loop.last %}| {% endif %} 9 | {%- endfor %} 10 | 11 |
12 | 13 | {% for key, entries in genindexentries %} 14 |

{{ key }}

15 |
16 |
17 | {%- set breakat = genindexcounts[loop.index0] // 2 %} 18 | {%- set numcols = 1 %} 19 | {%- set numitems = 0 %} 20 | {% for entryname, (links, subitems) in entries %} 21 |
{%- if links -%}{{ entryname|e }} 22 | {%- for link in links[1:] %}, [Link]{% endfor -%} 23 | {%- else -%} 24 | {{ entryname|e }} 25 | {%- endif -%}
26 | {%- if subitems %} 27 |
28 | {%- for subentryname, subentrylinks in subitems %} 29 |
{{ subentryname|e }} 30 | {%- for link in subentrylinks[1:] %}, [Link]{% endfor -%} 31 |
32 | {%- endfor %} 33 |
34 | {%- endif -%} 35 | {%- set numitems = numitems + 1 + len(subitems) -%} 36 | {%- if numcols < 2 and numitems > breakat -%} 37 | {%- set numcols = numcols+1 -%} 38 |
39 | {%- endif -%} 40 | {%- endfor %} 41 |
42 | {% endfor %} 43 | 44 | {% endblock %} 45 | 46 | {% block sidebarrel %} 47 | {% if split_index %} 48 |

Index

49 |

{% for key, dummy in genindexentries -%} 50 | {{ key }} 51 | {% if not loop.last %}| {% endif %} 52 | {%- endfor %}

53 | 54 |

Full index on one page

55 | {% endif %} 56 | {% endblock %} 57 | -------------------------------------------------------------------------------- /website/templates/modindex.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% set title = 'Global Module Index' %} 3 | {% block extrahead %} 4 | {% if collapse_modindex %} 5 | 8 | {% endif %} 9 | {% endblock %} 10 | {% block body %} 11 | 12 |

Global Module Index

13 | {% if builder == 'web' and freqentries %} 14 |

Most popular modules:

15 |
16 | {%- for module in freqentries %} 17 | {{ module.name|e }} 18 | {%- endfor %} 19 |
20 | {% endif %} 21 | {% if builder == 'web' %} 22 |
23 | Show modules only available on these platforms:
24 | {% for pl in platforms -%} 25 | 27 | 28 | {% endfor %} 29 | 30 | 31 |
32 | {% endif %} 33 | 34 | {%- for letter in letters %} 35 | {{ letter }} {% if not loop.last %}| {% endif %} 36 | {%- endfor %} 37 |
38 | 39 | 40 | {%- for modname, collapse, cgroup, indent, fname, synops, pform, dep in modindexentries %} 41 | {%- if not modname -%} 42 | 43 | 44 | {%- else -%} 45 | 46 | 50 | 57 | {%- endif -%} 58 | {% endfor %} 59 |
 
{{ fname }}
{% if collapse -%} 47 | 49 | {%- endif %}{% if indent %}   {% endif %} 51 | {% if fname %}{% endif -%} 52 | {{ modname|e }} 53 | {%- if fname %}{% endif %} 54 | {%- if pform[0] %} ({{ pform|join(', ') }}){% endif -%} 55 | {% if dep %}Deprecated:{% endif %} 56 | {{ synops|e }}
60 | 61 | {% endblock %} 62 | -------------------------------------------------------------------------------- /website/templates/opensearch.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | {{ project }} 4 | Search {{ docstitle }} 5 | utf-8 6 | 8 | {{ docstitle }} 9 | {% block extra %}{# Put e.g. an element here. #}{% endblock %} 10 | 11 | -------------------------------------------------------------------------------- /website/templates/page.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% set page_links = [ 3 | (pathto('@rss/' + sourcename), 'application/rss+xml', 'Page Comments'), 4 | ] %} 5 | {% block body %} 6 | {% if oldurl %} 7 |
8 | Note: You requested an out-of-date URL from this server. 9 | We've tried to redirect you to the new location of this page, but it may not 10 | be the right one. 11 |
12 | {% endif %} 13 | {{ body }} 14 | {% endblock %} 15 | -------------------------------------------------------------------------------- /website/templates/search.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% set title = 'Search' %} 3 | {% block extrahead %} 4 | 5 | {% endblock %} 6 | {% block body %} 7 |

Search

8 |

9 | From here you can search these documents. Enter your search 10 | words into the box below and click "search". Note that the search 11 | function will automatically search for all of the words. Pages 12 | containing less words won't appear in the result list. 13 |

14 |
15 | 16 | 17 |
18 | {% if search_performed %} 19 |

Search Results

20 | {% if not search_results %} 21 |

Your search did not match any results.

22 | {% endif %} 23 | {% endif %} 24 |
25 | {% if search_results %} 26 |
    27 | {% for href, caption, context in search_results %} 28 |
  • {{ caption }} 29 |
    {{ context|e }}
    30 |
  • 31 | {% endfor %} 32 |
33 | {% endif %} 34 |
35 | {% endblock %} 36 | --------------------------------------------------------------------------------