## Switch from IDL to Python

Python-based data analysis is dominating many fields. In astronomy and geoscience applications, Python dominance is increasing. Consider a widely valued langauge like Python inside of a niche, virtually unknown language outside a few specialties.

## Installing Python for the first time

Miniconda Python is a 50 MB download–it won’t initially take several gigabytes of hard drive space like Matlab and IDL.

Package distribution can occur via a website or preferably, a centralized `conda`

or `pip`

repo.
For example, to install popular data analysis modules:

```
conda install pandas scipy matplotlib spyder
```

We note that IDL 8.7 added JSON format for package metadata.

## IDL vs. Python syntax

table of NumPy/Python equivalents to common IDL commands

IDL is a bit distinctive in its syntax. IDL and Matlab syntax remind me a bit of Fortran, while Python is C-based, including that Python has 0-based indexing and C-order array axes.

Mayavi also gives advanced 3-D visualization.

### Ipyvolume 3-D example

Jupyter Notebook makes an IDE in your web browser, and you can make remarkable animated, interactive 3-D plots as well with Ipyvolume.

```
conda install jupyter
python -m pip install ipyvolume
```

### HDF5

HDF5 can handle enormous datasets quickly and easily.
Assume you have an HDF5 file `terabyte.h5`

with double-precision float variable X of size 100000x2048x2048 (3.4 TB).
Let’s load the first frame of the 2048x2048 image data, and write it variable `first`

to `image.h5`

.
The `with`

syntax uses Python’s context manager, which closes the file upon exiting the indented code section under `with`

.

```
import h5py
with h5py.File('terabyte.h5') as f:
img = f['X'][0,...]
with h5py.File('image.h5') as f:
f['first'] = img
```

## IDL ↔ Python

IDL ≥ 8.7 supports Python 2.7, 3.5 and 3.6:

## Call GDL from Python

GDL Gnu Data Language is free open-source alternative to IDL, compatible with most IDL syntax.

from Python, call IDL/GDL functions by simply
`import GDL`

. See PYTHON.TXT

## Call Matlab from Python and Python from Matlab

In case you or a collaborator uses Matlab or Matlab code, you can: