listpixels

astroimtools.utils.listpixels(data, position, shape, subarray_indices=False, wcs=None)[source]

Return a Table listing the (y, x) positions and data values for a subarray.

Given a position of the center of the subarray, with respect to the large array, the array indices and values are returned. This function takes care of the correct behavior at the boundaries, where the small array is appropriately trimmed.

Parameters:
dataarray-like

The input data.

positiontuple (int) or SkyCoord

The position of the subarray center with respect to the data array. The position can be specified either as an integer (y, x) tuple of pixel coordinates or a SkyCoord, in which case wcs is a required input.

shapetuple (int)

The integer shape ((ny, nx)) of the subarray.

subarray_indicesbool, optional

If True then the returned positions are relative to the small subarray. If False (default) then the returned positions are relative to the data array.

wcsWCS, optional

The WCS transformation to use if position is a SkyCoord.

Returns:
tableTable

A table containing the x and y positions and data values.

Notes

This function is decorated with support_nddata and thus supports NDData objects as input.

Examples

>>> import numpy as np
>>> from astroimtools import listpixels
>>> np.random.seed(12345)
>>> data = np.random.random((25, 25))
>>> tbl = listpixels(data, (8, 11), (3, 3))
>>> for col in tbl.colnames:
...     tbl[col].info.format = '%.8g'  # for consistent table output
>>> tbl.pprint(max_lines=-1)
 x   y     value
--- --- -----------
 10   7  0.75857204
 11   7 0.069529666
 12   7  0.70547344
 10   8   0.8406625
 11   8  0.46931469
 12   8  0.56264343
 10   9 0.034131584
 11   9  0.23049655
 12   9  0.22835371