Page 1 of 1

How to Install and Test Python Healpy in Ubuntu Linux

Posted: Fri Jun 24, 2016 2:55 pm
by Eli
We are going to show you how to install the HEALPix distribution. HEALPix is a shorthand for Hierarchical Equal Area isoLatitude Pixelation of a sphere. As the name suggests, this pixelation produces a subdivision of a spherical surface whereby each pixel covers the same surface area as every other pixel.

HEALPix comprises a suite of Fortran 90, C++, IDL, Java and Python routines providing both stand-alone facilities and callable subroutines as an alternative for those users who wish to build their own tools. A set of C subroutines and functions is also provided, see more.

We are interested to show a procedure for installing Healpy using pip. Healpy is the Python Package which depends on the HEALPix C++ and CFITSIO C libraries and requires supporting Python libraries such as Numpy, Matplotlib and PyFITS. However, Python development package is required for some distribution (e.g., python-dev package for Ubuntu). Ipython and Cython Cython packages can also be useful although not required. Source code for both HEALPix C++ and CFITSIO C libraries is included with Healpy and is built automatically, so you do not need to install them separately.

Go to python-packages-for-scientific-computing-4423 and install Numpy, Matplotlib and Python development package (python-dev).

If pip is not installed in your system, open the Terminal and code:

Code: Select all

sudo apt-get install python-pip
The quickest way to install Healpy is with pip (>= 1.4.2), which automatically fetches the latest version of Healpy and all the missing dependencies:

Code: Select all

pip install --user healpy
Installing with pip, helps to keep your installation up to date by upgrading from time to time:

Code: Select all

pip install --user --upgrade healpy
If everything is installed successfully, you can test Healpy as follows:
  1. :~$ python
  2. >>> import matplotlib.pyplot as plt
  3. >>> import numpy as np
  4. >>> import healpy as hp
  5. >>> hp.mollview(np.arange(12))
  6. >>> plt.show() #Try fig = plt.figure() then fig.savefig('Sphere.png')


The output should be this image:
Sphere.png
Look for more meaningful examples at Healpy tutorial and GitHub

If you experience some errors during installation, please check: http://stackoverflow.com/questions/2567 ... atplotllib.
See also Healpy, a Python wrapper for Healpix.

For alternative installation,visit this page

Check also smoothing sky maps with healpy

Installing healpy with pip, enables you to keep your installation up to date by upgrading from time to time:

Code: Select all

pip install --user --upgrade healpy

Re: How to Install and Test Python Healpy in Ubuntu Linux

Posted: Fri May 18, 2018 1:41 pm
by Admin
Install the Latest Version of Healpy

Python Healpy can be installed in the way described above, there are however many ways on how to install Linux/Unix-based packages. pip install is one way of installing Python modules/packages, and another most convenient installation method is the user scheme. The user scheme alternative is designed to be the most straightforward solution for users that don’t have write permission to the global site-packages directory or don’t want to install into it. It is enabled with a simple command:

Code: Select all

python setup.py install --user

Files will be installed into subdirectories of site.USER_BASE (written as userbase in the table below). This scheme installs pure Python modules and extension modules in the same location (also known as site.USER_SITE). Here are the values for UNIX, including Mac OS X:

  1. Type of file        Installation directory
  2. modules             userbase/lib/pythonX.Y/site-packages
  3. scripts             userbase/bin
  4. data                userbase
  5. C headers           userbase/include/pythonX.Y/distname


See more: Installing Python Modules (Legacy version)

To install the newest Python Healpy (healpy 1.11.0), install from Python Package Index (PyPI), since python modules are available as soon as released from the official source. Here is the newest healpy installation procedure:

  1. $wget https://files.pythonhosted.org/packages/49/56/5e1bf4745a770b4e5fa524f34f0ad95e69673b1cb1b3ed0625a4aa2a72f0/healpy-1.11.0.tar.gz
  2. $tar -xzf healpy-1.11.0.tar.gz
  3. $cd healpy-1.11.0/
  4. $python setup.py install --user


Re: How to Install and Test Python Healpy in Ubuntu Linux

Posted: Thu May 31, 2018 12:10 pm
by Eli
If you are using Python from Anaconda distribution, install healpy inside anaconda with

pip install healpy

Otherwise, installing Healpy differently but using Anaconda may result in the following error:

$python setup.py install --user
Traceback (most recent call last):
File "setup.py", line 7, in <module>
import pkg_resources
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 25, in <module>
import zipfile
File "/usr/lib/python3.6/zipfile.py", line 14, in <module>
import struct
File "/usr/lib/python3.6/struct.py", line 13, in <module>
from _struct import *
ModuleNotFoundError: No module named '_struct'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "setup.py", line 9, in <module>
except pkg_resources.ResolutionError:
NameError: name 'pkg_resources' is not defined

Note also Healpy depends on Astropy package, and Astropy requires Python 3.5 or later.

Re: How to Install and Test Python Healpy in Ubuntu Linux

Posted: Mon Aug 12, 2019 6:11 pm
by Eli
Snyfast is a function that can be used to create Mollweide projection of sky map from power spectrum. The format for its usage is

  1. healpy.sphtfunc.synfast(cls, nside, lmax=None, mmax=None, alm=False, pol=True, pixwin=False, fwhm=0.0, sigma=None, new=False, verbose=True)


The minimum working example can be

  1. import healpy as hp
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. cl = np.array([0.1, 0.2, 0.2, 0.4, 0.5, 0.6])
  6. np_array = hp.sphtfunc.synfast(cl, nside=64, lmax=None, mmax=None, alm=False, pol=True, pixwin=False, fwhm=0.0, sigma=None, new=False, verbose=True)
  7. hp.visufunc.mollview(np_array)
  8. plt.savefig("sky_map.jpg", format='JPG', bbox_inches='tight')


which produces the attached map.

Re: How to Install and Test Python Healpy in Ubuntu Linux

Posted: Thu Jan 16, 2020 11:12 am
by Eli

Re: How to Install and Test Python Healpy in Ubuntu Linux

Posted: Mon May 29, 2023 5:12 pm
by Eli
Binary installation with conda (recommended for Anaconda/Miniconda users)

Conda Forge provides a conda channel with a pre-compiled version of healpy for linux 64bit and MAC OS X platforms, you can install it in Anaconda with:

  1. conda config --add channels conda-forge
  2. conda install healpy


Install Python Healpy using Binary installation with Pip (recommended for most other Python users)

To install the latest version of healpy with pip on Linux, simply run (use pip3 for python3):

  1. pip install --user healpy

If you have installed with pip, you can keep your installation up to date by upgrading from time to time:

  1. pip install --user --upgrade healpy


Re: How to Install and Test Python Healpy in Ubuntu Linux

Posted: Mon May 29, 2023 5:59 pm
by Eli
astropy is installed by default with the Anaconda Distribution. To update to the latest version run:

  1. conda update astropy