#!/usr/bin/env python # coding: utf-8 # Welcome to PSYC.161-WI19 # # Introduction to Programming for Psychologists & Neuroscientists # by Yaroslav O. Halchenko # # **email:** class-psyc161@onerussian.com # # **Where:** here in Moore 453, later might move to 303 # # **When:** T/Th either 10:30am-12:00pm (need to find some 3h slots - TODO). # # **Details:** https://github.com/dartmouth-pbs/psyc161 # # **Canvas:** Maybe # # Why me? # # Why you? # # Why not just a "Programming 101"? # # **Best Practices for Scientific Computing** # by Greg Wilson et al., PLOS Biology 2014 # # http://dx.doi.org/10.1371/journal.pbio.1001745 # # Box 1. Summary of Best Practices # 1. **Write programs for people, not computers** # 2. **Let the computer do the work** # 3. **Make incremental changes** # 4. **Don't repeat yourself (or others)** # 5. **Plan for mistakes** # 6. Optimize software only after it works correctly # 7. Document design and purpose, not mechanics # 8. **Collaborate** # # # # Why "Programming?" # ## Automation # # # xkcd.com/1205 # ## Automation # # xkcd.com/1319 # # Why "Programming?" # ## Automation # # by Bruno Oliveira # # - **Reusable** (fix-rerun, or might even benefit others) # - **Flexible** (could be generalized/extended -- apply accross studies) # - **Scalable** (worked for >1 subjects, will work for any #) # # - **Exact description** of performed actions (was any "Methods" section was sufficient?) # # Why "Programming?" # ## Programming == Problem solving # # Given a problem # # 1. **Understand** what the problem is # 2. **Conceptualize** approach to solve it # 3. **Implement** the approach # 4. **Verify** that the problem is solved, if not goto 1 # # # Why "Programming?" # ## Programming =(historically)= Computer Science # # I hoped we will touch upon topics from # # - Data structures and algorithms ([CS 31](http://www.cs.dartmouth.edu/~cs31/)) # - Computability and complexity ([CS 39](https://ssl.cs.dartmouth.edu/~ac/Teach/CS39-Winter15), CS49) # - Software engineering # - Problem solving (CS 10) # - Numerical and computational tools (CS 70/170) # # How will we do it? # # - Classes once/twice a week for a total of 3h/week # - (In-Class participation counts!) # # - Hands-on sessions through out the classes # - Codescope within [FOPP-PBS-WI2019](https://runestone.academy/runestone/static/fopp-pbs-wi2019/index.html) online text book. Note that online built-in Python is not a complete Python # - Python IDE (Pycharm)/editors # - Git and GitHub (Travis CI and friends) # - IPython notebooks # - tests (pytest) # # - Homework excercises due every week (but the last 4 weeks) # - Peer-review (?) # # - Final project # # # Final project # # - It must be a new development (i.e. not something you did before this # course), although you can choose to improve upon your prior code # # - Ideally should be something **you** or someone would end up re-using # later on # # - Contributions to existing scientific projects will be strongly # encouraged (benefit from established QA, feedback, distribution # channels, etc) # # - Possible projects will be suggested and discussed in the class on # 4-5th week and possible domains are # # - Data structures/algorithms implementation # - Stimuli/experiment # - Data Analysis # - Establishing/improving quality assurance (tests, etc) of an # existing scientific FOSS project # # - Team work is encouraged (but contribution ratio will be assessed) # # My goals # # ## 1. Teach you programming # # - be able to use programming concepts (conditionals, iterations, functions, modules) # - solve problems alogirithmically so you have a generic and scalable solution not a list of copy-pasted and tuned lines # - get a healthy amount of paranoia - all code has bugs. Learn how to avoid/detect via in-line assertions and (unit-)tests # # ## 2. Teach you to efficiently use tools # # - to become at least a few times more efficient in the tools you had touched (shell, git, github, ipython/jupyter) # - to know and know how to use existing offerings # - to be able to collaborate # - to be sure you have done *it* correctly: validate and (unit-)test # # ## 3. Teach you to become part of the scientific Python ecosystem # # - contribute back # # Lecture #1: Python for sciences, fun and profit # (AKA Introduction) # # Why Python? # # Why not? # - Free, Open, Cross-platform - **scale and share without limits** # - Generic programming language - **avoid learning a new software for each new problem** # - Stimuli delivery # - Numerical (Data) analysis # - Simulations # - Web platforms # - Web scraping/Data mining # - Systems automation # - ... # - "Friendly" to other ecosystems - **it is ok to use other software on an occasion** # - Interface data/functionality from other languages (R, Matlab) and libraries # - “Python is executable pseudo-code.” (Python lore (often attributed to Bruce Eckel)) - **code of others is readable** # - "Batteries included" includes testings framework(s) - **testing is now integral part of nearly any Python project** # # # # No, why "Python" name? # ## Has nothing to do with the snake # # # (Monty) Python # # # (Scientific) Python ecosystem is # # - [Python](http://python.org) (programming language/interpreter): ~~2.7.15,~~ 3.7.2 # - [The Python standard library](https://docs.python.org/3/library/) (AKA "batteries"): io, sys, re, copy, math, random, glob, csv, httplib, argparse, unittest, ... # - [IPython](http://ipython.org) improved Shell and Notebook # - Python IDEs - Integrated Development Environment # - [Pycharm](https://www.jetbrains.com/pycharm/), [Spyder](https://pythonhosted.org/spyder), ... # - [NumPy](http://numpy.org) - core datastructure object for efficient numeric arrays manipulations # - "Numeric batteries": # - [SciPy](http://scipy.org) - high-level data processing routines. Optimization, regression, interpolation, statistics, etc... # - [Matplotlib](http://matplotlib.sourceforge.net), [seaborn](http://stanford.edu/~mwaskom/software/seaborn/), ... - plotting, visualization # - [Pandas](http://pandas.pydata.org) - efficient manipulation/analysis of tabular data # - [statsmodels](http://statsmodels.sourceforge.net) - statistical models # - "Brainy ones": # - [PyMVPA](http://pymvpa.org), [NiLearn](http://nilearn.github.io), ... - statistical learning analysis of neural data # - [PsychoPy](http://www.psychopy.org), [OpenSesame](http://osdoc.cogsci.nl), ... - stimuli delivery # - [dipy](http://nipy.org/dipy/), [nipype](http://nipy.org/nipype), [nitime](http://nipy.org/nitime/), ... # - Data management/distribution # - [DataLad](http://datalad.org) # # How to install Python # - Linux distributions: package managers # - Debian/Ubuntu: recommend enabling [NeuroDebian](http://neuro.debian.net) for recent versions of many useful Python modules (psychopy, pandas, seaborn, sklearn, pymvpa, dipy, nipype, nitime, ...) # - OSX/Windows: # - OS X is coming with some Python # - NeuroDebian VM # - "Free" (but not fully open) [Anaconda](https://store.continuum.io/cshop/anaconda/) # In[ ]: