imutil.ccdops.bin_ccd

imutil.ccdops.bin_ccd(
    ccd,
    factors=None,
    binfunc=np.mean,
    trim_end=False,
    update_header=True,
    copy=True,
)

Bins the given ccd.

Parameters

ccd : ~astropy.nddata.CCDData

The ccd to be binned

factors : list-like of int, optional. = None

The binning factors. The order matches numeric.binning(..., order_xyz=True). For 2-D data this is (x, y); for 3-D data this is (x, y, z). If None, every factor is treated as 1.

binfunc : callable, optional. = np.mean

The function to be applied for binning, such as np.sum, np.mean, and np.median. Default: np.mean.

trim_end : bool, optional. = False

Whether to trim the end of x, y axes such that binning is done without error. Default: False.

update_header : bool, optional. = True

Whether to update header. Defaults to True. Default: True.

Notes

This is ~ 20-30 to up to 10^5 times faster than astropy.nddata’s block_reduce:

from astropy.nddata.blocks import block_reduce import astroimred as air from astropy.nddata import CCDData import numpy as np ccd = CCDData(data=np.arange(1000).reshape(20, 50), unit=‘adu’) bin_kw = dict(factors=(5, 5), binfunc=np.sum, trim_end=True) ccd_kw = dict(factors=(5, 5), binfunc=np.sum, trim_end=True)

on MBP 14” [2024, macOS 26.4.1, M4Pro(8P+4E/G20c/N16c/48G)], 2026-05-27:

%timeit air.binning(ccd.data, bin_kw) # 8.11 µs ± 0.2 µs per loop (7 runs, 30000 loops each) %timeit air.bin_ccd(ccd, ccd_kw, update_header=False) # 11.8 µs ± 0.3 µs per loop (7 runs, 30000 loops each) %timeit block_reduce(ccd, block_size=5) # 15.3 µs ± 0.4 µs per loop (7 runs, 30000 loops each)