Python Tutorial for Euclid Developers
This repository contains material associated with the basic and advanced Python tutorial.
Date: 26-27 May 2016
Instructors:
- Alexandre Boucaud alexandre.boucaud@ias.u-psud.fr
- Mher Kazandjian mher@strw.leidenuniv.nl
Content:
- General installation
- Installation for Euclid dev.
- Getting the notebooks
- Beginner tutorial list
- Advanced tutorial list
- References and cheatsheet
System installation
This tutorial will be using Python version 3.4-3.5 with the following libraries
- NumPy (Numerical Python) for efficient manipulation of array-based data
- SciPy (Scientific Python) for optimization and other routines
- Matplotlib for scientific visualization
- AstroPy community library gathering astronomical routines
Optionally one might want to install these libraries
- IPython/Jupyter notebook as an interactive computing environment
- Seaborn a data visualization library
LODEEN Virtual Machine
For Euclid developers, a virtual machine with all the requisite libraries/packages has been setup and can be used on all operating systems. The VM is available at this link with a valid Cosmos Account.
If you use VirtualBox (recommended), go to File > Import appliance > /path/to/CppPythonSession.ova The VM credentials are ID: user / pwd: password Tip: In the VM, install the VirtualBox Guest Additions in order to enable the full screen mode.
The Python tutorial has already been integrated to the machine but you should make sure you have the latest version
cd ~/Desktop/python-euclid2016
git pull
Then launch the notebooks
jupyter-notebook notebooks
Get the tutorial material
If you have git
installed, you can clone the material of this tutorial with
git clone https://github.com/aboucaud/python-euclid2016.git
If you can't or don't want to install git
, there is a link above to download
the contents of this repository as a zip file. We may make minor changes to
the repository during the tutorial, so cloning the repository is the best option.
You can access a static view of the notebooks following the links below. To modify them, first download the tutorial repository, change to the notebooks directory, and run
jupyter-notebook
This will launch a page on web browser with the list of notebooks. For more information on the IPython/Jupyter notebook, see http://ipython.org/notebook.html or http://jupyter.org
Note that some of the code in these notebooks may not work outside the directory structure of this tutorial, so it is important to clone the full repository if possible.
Beginner tutorial
1. General Python concepts
variables, collections, iteration, strings, logical operations, functions, classes, ipython, python2/3...
2. Scientific computing with Python: NumPy/SciPy
arrays creation, accessing elements, array operations, masked array, broadcasting...
3. Plotting with Python
2D plots, labeling, configuration, 3D plots, saving, Matplotlib/Seaborn
4. The AstroPy library
reading files (ascii/fits/..), physical constants, cosmological calculations, sky coordinates manipulation...
Advanced tutorial
5. Python coding guidelines
code formatting, naming conventions, docstring formatting, static analysis...
6. Project architecture
See also slides.
modules/submodules, __init__.py
, imports, the __all__
variable, module documentation
7. Testing
See slides by F. Raison from the Dev. Workshop #2.
pytest, writing unit tests, fixtures, configuration, doctests, running tests ...
8. Tips & Tricks
ipython configuration, more on classes, things to avoid, quick optimization, debugging, extending python ...
References
A list of references can be found here and a useful cheatsheet here.