Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UvA API software carpentry IPython Notebooks 2015

978e79ad01185b39efcfca1482f0f819?s=47 Gijs Molenaar
September 18, 2015

UvA API software carpentry IPython Notebooks 2015

978e79ad01185b39efcfca1482f0f819?s=128

Gijs Molenaar

September 18, 2015
Tweet

Transcript

  1. UvA API software carpentry (I)Python (Notebooks) 18 September 2015 Gijs

    Molenaar Folkert Huizinga
  2. Agenda • Short presentation ◦ ‘Advanced’ Python topics ◦ Ipython

    notebooks • Interactive session • if time interactive git merge (didn’t finish last week) • Half way short coffee break
  3. Python 3 • Please write Python 3 compatible code •

    http://python-future.org/overview.html • 3.5 has been released ◦ @ operator (matrix multiplication) ◦ Parallel build of C extensions ◦ Much more!
  4. PyCharm IDE Static code analysis Interactive debugger Integrated test suite

    runner Free ‘community’ edition Free for students (didn’t try)
  5. Object Oriented programming Not the holey grail Can be useful

    if used properly Is dramatic when used wrong You can solve most problem with functional programming Python programming using functions and python primitives (list, dict, try out collections.namedtuple )
  6. profiling $ pip install runsnakerun $ python -m cProfile -o

    profile.dat script.py $ runsnake profile.dat
  7. Dive into python (3) http://www.diveintopython3.net/

  8. Interactive shizzle! SSH to taurus $ cd /scratch/<YOU>/

  9. Clone the workshop repository https://github.com/antonpannekoek/ipython-workshop Fork it! clone the fork

  10. Virtualenv gijs@taurus:/scratch/gijs$ virtualenv --no-site-packages --system-site-packages gijs@taurus:/scratch/gijs$ virtualenv --system-site-packages venv gijs@taurus:/scratch/gijs$

    source venv/bin/activate (venv)gijs@taurus:/scratch/gijs$ which python /scratch/gijs/venv/bin/python
  11. pip because --system-site-packages already packages installed $ pip search astropy

    astropy - Community-developed python astronomy tools INSTALLED: 0.3 LATEST: 1.0.4 to install new packages in your virtualenv $ pip install notebook you can also upgrade / override system wide installed packages $ pip install --upgrade astropy
  12. ipython notebook $ which ipython /scratch/gijs/venv/bin/ipython task: pick an arbitrary

    port number > 1024 and < 65535 (maybe a birthday paradox!) $ ipython notebook --no-browser --port=<number> (default is 8888)
  13. SSH SSH ONLY http://localhost:8888

  14. SSH TUNNEL SSH ONLY http://localhost:8000 ssh -L 8000:localhost:8000 taurus.science.uva.nl

  15. SSH TUNNEL SSH ONLY http://localhost:8000 ssh -L 8000:localhost:8000 taurus.science.uva.nl

  16. $ ssh -L 8000:localhost:6666 taurus $ cd /scratch/gijs/ $ source

    venv/bin/activate (venv)$ cd ipython-workshop (venv)$ pip install -r requirements.txt (venv)$ ipython notebook --no-browser --port=6666
  17. IPython notebooks. We will talk about security Processes The state

    and how to change it cells returned object from last statement is shown below cell Markdown astropy Mixing Python and Bash