Cygrid is a cython-powered convolution-based gridding module for astronomy
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cygrid make cygrid work with python 3.7 Sep 12, 2018
notebooks improve convolutional-gridding tutorial Nov 30, 2018
tests add windows support via appveyor Jul 2, 2017
.gitignore Add notebook checkpoints. Jan 23, 2017
.travis.yml make cygrid work with python 3.7 Sep 12, 2018
CITATION to get history remote-add mpifr/git_repos/cygrid_history; see http://… Feb 29, 2016
COPYING change license to GPL v3 Jun 13, 2016
MANIFEST.in to get history remote-add mpifr/git_repos/cygrid_history; see http://… Feb 29, 2016
README.md try automatic deployment to PyPI Jul 2, 2017
appveyor.yml make cygrid work with python 3.7 Sep 12, 2018
pip-requirements add windows support via appveyor Jul 2, 2017
pip-requirements-dev
setup.cfg allow tests to be run via "python setup.py test" Nov 8, 2017
setup.py allow tests to be run via "python setup.py test" Nov 8, 2017

README.md

Introduction

  • Version: 0.9
  • Authors: Benjamin Winkel, Lars Flöer, Daniel Lenz

PyPI version Build Status Build status Publication License

Purpose

cygrid allows to resample a number of spectra (or data points) to a regular grid - a data cube - using any valid astronomical FITS/WCS projection (see http://docs.astropy.org/en/stable/wcs/).

The method is a based on serialized convolution with finite gridding kernels. Currently, only Gaussian (radial-symmetric or elliptical) kernels are provided (which has the drawback of slight degradation of the effective resolution). The algorithm has very small memory footprint, allows easy parallelization, and is very fast.

A detailed description of the algorithm is given in Winkel, Lenz & Flöer (2016), which we kindly ask to be used as reference if you found cygrid useful for your research.

Features

  • Supports any WCS projection system as target.
  • Conserves flux.
  • Low memory footprint.
  • Scales very well on multi-processor/core platforms.

Installation

The easiest way to install cygrid is via pip:

pip install cygrid

The installation is also possible from source. Download the tar.gz-file, extract (or clone from GitHub) and simply execute

python setup.py install

Note, for Windows machines only Python 3.5+ is supported.

Dependencies

We kept the dependencies as minimal as possible. The following packages are required:

  • numpy 1.10 or later
  • cython 0.23.4 or later
  • astropy 1.0 or later (Older versions of these libraries may work, but we didn't test this!)

If you want to run the notebooks yourself, you will also need the Jupyter server, matplotlib and wcsaxes packages. To run the tests, you'll need HealPy.

Note, for compiling the C-extension, openmp is used for parallelization and some C++11 language features are necessary. If you use gcc, for example, you need at least version 4.8 otherwise the setup-script will fail. (If you have absolutely no possibility to upgrade gcc, older version may work if you replace -std=c++11 with -std=c++0x in setup.py. Thanks to bs538 for pointing this out.)

For Mac OS, it is required to use gcc-6 in order to install cygrid. We recommend to simply use the homebrew package manager and then use brew install gcc.

Usage

Minimal example

Using cygrid is extremely simple. Just define a FITS header (with valid WCS), define gridding kernel and run the grid function:

from astropy.io import fits
import cygrid

# read-in data
glon, glat, signal = get_data(...)

# define target FITS/WCS header
header = {
    'NAXIS': 3,
    'NAXIS1': 101,
    'NAXIS2': 101,
    'NAXIS3': 1024,
    'CTYPE1': 'GLON-SFL',
    'CTYPE2': 'GLAT-SFL',
    'CDELT1': -0.1,
    'CDELT2': 0.1,
    'CRPIX1': 51,
    'CRPIX2': 51,
    'CRVAL1': 12.345,
    'CRVAL2': 3.14,
    }

# prepare gridder
kernelsize_sigma = 0.2

kernel_type = 'gauss1d'
kernel_params = (kernelsize_sigma, )
kernel_support = 3 * kernelsize_sigma
hpx_maxres = kernelsize_sigma / 2

mygridder = cygrid.WcsGrid(header)
mygridder.set_kernel(
    kernel_type,
    kernel_params,
    kernel_support,
    hpx_maxres
    )

# do the gridding
mygridder.grid(glon, glat, signal)

# query result and store to disk
data_cube = mygridder.get_datacube()
fits.writeto(
    'example.fits',
    header=header, data=data_cube
    )

More use-cases and tutorials

Check out the ipython notebooks in the repository for further examples of how to use cygrid. Note that you only view them on the nbviewer service, and will have to clone the repository or download the notebooks to run them on your machine.

Who do I talk to?

If you encounter any problems or have questions, do not hesitate to raise an issue or make a pull request. Moreover, you can contact the devs directly: