Aim¶
Introduce the python ecosystem
How do I run a
.py
script?Where do I enter python commands?
What is
Python 2
andPython 3
?wait!, there is something called
Anaconda
?JupyterLab
,Jupyter Notebooks
and reproducible research
Why should I use python?
Is python as easy as
Ferret
?Is python as fast as
Fortran
?Does python have many toolboxes like in
MATLAB
?Can python read and write
netCDF
files?Can python plot geographic maps and coastlines?
Can it handle larger than memory files (say >2 GB)?
Possibilities with python
Exploratory Data Analysis
Interactive plotting
Parallel processing
Cloud computing
Python ecosystem¶
Running a .py
script¶
Activate your environment, and run the script by
python your_script.py
Three ways to spawn a python interpreter¶
old fashioned
python
consolerich and colorful
ipython
consoleJupyterLab
Starting the console¶
In terminal, type
python
In terminal, type
ipython
In terminal, type
jupyter lab
IPython¶
Old python interface is boring and less interactive
IPython
supports tab completion, syntax highlighting, documentation lookupcell magics like
%run
,%debug
,%edit
and%bookmark
makes interactive coding easier
Note
More info can be found here
JupyterLab and Jupyter Notebook¶
JupyterLab is an interface where you can
create notebooks
manage files and folders
display images
start terminal
display csv files and much more
Notebooks holds your code, plots and discussion in a single space
Notebook sharing promotes reproducible research
Notebooks are future of scientific communication, (Nature article)
Jupyter is not limited to Python. You can run codes in
Julia
Bash
R
Pyferret
and much more
Tip
Additional benefits of JupyterLab/Notebook
Start jupyter in a remote computer say HPC and connect in your local browser
# in remote machine type: jupyter lab --no-browser --ip="$HOSTNAME" --port=8888 # in local machine type: ssh -N -L 8888:localhost:8888 username@remoteIP
Open browser and type address as
localhost:8888
and pressEnter
No more waiting for the slow X-window forwarding to pop-up
Easily access and view remote files
Anaconda, miniconda and conda env¶
Anaconda
andminiconda
differs only in the number of pre-packed packagesAnaconda
comes with many common-use packages (> 500 MB)While
miniconda
is a lite version (<60 MB)Both installs
conda
, which is the package managerConda
helps you isolate environments, allowing you to update/install certain packages without affecting
other working environment.
Attention
Stay away from Python 2
Avoid Python 2. It is now in legacy mode
Packages are dropping support for Python 2
Most scientific packages have moved to Python 3
Found an old code in Python 2? Use conda to create a Python 2 environment
Further references¶
Rather than general python tutorials, look for scientific computing tutorials
Some such python lessons covering basics are: