`_ is just a
way of collecting related modules together within a single tree-like hierarchy.
Very complex packages like NumPy or SciPy have hundreds of individual modules so
putting them into a directory-like structure keeps things organized and avoids
name collisions. For example here is a partial list of sub-packages available
within SciPy.
================================== ======================================================
scipy.fftpack Discrete Fourier Transform algorithms
scipy.stats Statistical Functions
scipy.lib Python wrappers to external libraries
scipy.lib.blas Wrappers to BLAS library
scipy.lib.lapack Wrappers to LAPACK library
scipy.integrate Integration routines
scipy.linalg Linear algebra routines
scipy.sparse.linalg Sparse Linear Algebra
scipy.sparse.linalg.eigen Sparse Eigenvalue Solvers
scipy.sparse.linalg.eigen.arpack Eigenvalue solver using iterative methods.
================================== ======================================================
.. admonition:: Exercise: Import a package module and learn about it
Import the Linear algebra module from the SciPy package and find out what
functions it provides.
.. raw:: html
Solution (Click to Show/Hide)
Start an interactive IPython session and import the linear algebra module.
Use the ``dir`` and ``help`` functions to learn more:
.. ipython::
In [1]: import scipy.linalg
In [1]: print(dir(scipy.linalg))
In [1]: help(scipy.linalg.eig)
.. raw:: html
Finding and installing packages
--------------------------------
If you've gotten this far you have a working scientific Python environment that
has *most* of what you will ever need. Nevertheless it is almost certain that
you will eventually find a need that is not met within your current
installation. Here we learn **where** to find other useful packages and
**how** to install them.
Package resources
^^^^^^^^^^^^^^^^^^
Google
#######
Google "python blah blah" or "python astronomy blah blah"
.. tip:: Good vs. bad resources
When you find some package on the web, look for a few things:
- Good modern-looking documentation with examples
- Installs easily without lots of dependencies (or has detailed
installation instructions)
- Actively developed
Resource lists
###############
There are a number of sites specifically devoted to Python for astronomy with
organized lists of useful resources and packages.
- `Astropython.org resources `_
- `Comfort at 1 AU
`_
- `Astronomical Python `_
PyPI
#######
The `Python Package Index `_ is the main
repository for 3rd party Python packages (about 14000 packages and growing).
An increasing number of `astronomy related packages
`_
are available on PyPI, but this list misses a lot of available options.
The advantage of being on PyPI is the ease of installation/uninstallation using::
$:> pip install
$:> pip uninstall
These commands might require root access. If you don't have root access, you
can use either::
$:> pip install --user
$:> pip uninstall --user
Or better yet, use the :ref:`virtualenv ` framework
.. admonition:: Exercise: Find packages for coordinate manipulations
Find one or more Python packages that will transform coordinates from Galactic to FK5 ecliptic.
*Hint*: tags are helpful at astropython.org and don't forget the "next" button at
the bottom.