mangadap.util.mapping module

Defines some utility routines used to map a provided set of quantities.

Revision history

10 Jun 2015: Pulled out functions by Michele Cappellari into a utility file (K. Westfall; KBW)
07 Jul 2017: (KBW) Added map matching functions


Copyright © 2019, SDSS-IV/MaNGA Pipeline Group

mangadap.util.mapping._match_map_arrays_integer_pixel_shift(arr1, ext1, arr2, ext2, dx, dy, swap=False)[source]
mangadap.util.mapping._match_map_arrays_sub_pixel_shift(arr1, ext1, arr2, ext2, dx, dy, swap=False, truncate=False, pixelscale=0.5)[source]
mangadap.util.mapping.map_beam_patch(extent, ax, pos=(0.1, 0.1), **kwargs)[source]
mangadap.util.mapping.map_center_pixel_offset(hdu_1, hdu_2, ext, quiet=False)[source]

Determine the offset in pixels between the object center in two the maps of two fits files.


Two floats with the offset in x and y between the two maps.

Return type:


mangadap.util.mapping.map_extent(hdu, ext, offset=True)[source]

Get the on-sky extent of a map using the provided WCS coordinates.

  • hdu ( – Fits HDU list.
  • ext (str) – Extension of the file with the map.
  • offset (bool) – (Optional) Return the extent as the offset from the coordinates of the object in arcseconds. The WCS is assumed to provide RA and declination in units of degrees, and the header must contain the coordinates of the object with keywords OBJRA and OBJDEC. If offset is True and these keywords do not exist, the function will throw a warning and proceed without applying any offset. Default is just to return the extent of the WCS coordinates.

List of four floats: minimum and maximum x and minimum and maximum y.

Return type:


mangadap.util.mapping.map_quantity(x, y, z, zmin=None, zmax=None, ncolors=64, dots=False, cmap='coolwarm', colorbar=False, nticks=7, clabel=None, flux=None, fixpdf=False, xlim=None, xlabel=None, ylim=None, ylabel=None, pixelscale=None, fill_value=0.0, contour_levels=None, **kwargs)[source]

Copyright (C) 2013-2014, Michele Cappellari E-mail:

Revision history:
V1.0: Michele Cappellari, Paranal, 11 November 2013
V1.0.1: Clip values before contouring. MC, Oxford, 26 February 2014
V1.0.2: Include SAURON colormap. MC, Oxford, 29 January 2014
V1.0.3: Call set_aspect(1). MC, Oxford, 22 February 2014
V1.0.4: Call autoscale_view(tight=True). Overplot small dots by default. MC, Oxford, 25 February 2014
V1.0.5: Use axis(‘image’). MC, Oxford, 29 March 2014
V1.0.6: Allow changing colormap. MC, Oxford, 29 July 2014
V1.0.7: Added optional fixpdf keyword to remove PDF artifacts like stackoverflow_15822159 . Make nice tick levels for colorbar. Added nticks keyword for colorbar. MC, Oxford, 16 October 2014
mangadap.util.mapping.masked_pixelized_image(x, y, z, pixelscale=1.0, zmin=None, zmax=None, imshow_prep=False, fill_value=0.0)[source]

Provided a set of pixelized data, return a masked image with a type The \(x\) coordinates are organized along rows and the \(y\) coordinates are organized along columns. I.e., i.e., img[0,1] = \(z(x_0,y_1)\), unless imshow_prep is requested (see below).

  • x (numpy.ndarray) – X coordinates of the pixels
  • y (numpy.ndarray) – Y coordinates of the pixels
  • z (numpy.ndarray) – Image values at \(x,y\).
  • pixelscale (float) – (Optional) Pixelscale of the image in arcsec/pixel.
  • zmin (float) – (Optional) Minimum z value to include in the output image. Default is to allow all pixel values.
  • zmax (float) – (Optional) Maximum z value to include in the output image. Default is to allow all pixel values.
  • imshow_prep (bool) –

    (Optional) Prepare the matrix for use with matplotlib.pyplot.imshow. If imshow_prep is True, before output, the matrix is reordered such that increasing \(x\) values are along columns and increasing \(y\) values are along rows; i.e., the output is the transpose of the default behavior. The appropriate call to imshow that will then put increasing x values along the abcissa and increasing y values along the ordinate is, e.g.:

    ext, img = masked_pixelized_image(x, y, z, imshow_prep=True)
    pyplot.imshow(img, interpolation='nearest', extent=ext, origin='lower')

    Note that origin must be “lower” when calling matplotlib.pyplot.imshow on the array produced by this routine for the \(x,y\) ordering to be as expected!

  • fill_value (float) – (Optional) The default value to use for pixels without any data.

The first object returned is a four-element array with the extent of the image from the bottom edge to the top edge of the x and y pixels, respectively. The second object returned is the image data and associated (boolean) mask.

Return type:


mangadap.util.mapping.match_map_arrays(arr1, ext1, arr2, ext2, dx, dy, tol=1e-06, truncate=True, pixelscale=0.5)[source]

Match the centers and extent of two map arrays by applying the previously calculated pixel offsets. See map_center_pixel_offset().

This is just a wrapper for the two supporting functions below.

Both maps must be two dimensional; i.e., a single map, not a set of maps arranged in different channels.

  • arr1 ( – Reference map data array.
  • ext1 (list) – Reference map extent in arcseconds.
  • arr2 ( – Comparison map data array.
  • ext1 – Comparison map extent in arcseconds.
  • dx (float) – Pixel offset in the first dimension (x).
  • dy (float) – Pixel offset in the second dimension (y).
  • tol (float) – (Optional) Tolerance for non-integer pixel shifts.
  • truncate (float) – (Optional) Truncate the shape of the shifted array to match the unshifted array. If False, the unshifted array is padded to match the shifted array.
  • pixelscale (float) – (Optional) The pixel scale (extent units per array pixel) that must be common to both input arrays.

The two matched arrays and the extent that is common to both.

Return type:, list