eloy.utils#

General utilities for astronomical image analysis.

This module provides helper functions for cutouts, statistical metrics, binning, and generating synthetic images.

Functions#

cutout(data, coords, shape[, wcs, fill_value])

Extract cutouts from data at given coordinates.

std_diff_metric(fluxes)

Compute the standard deviation of the difference along the last axis.

stability_aperture(fluxes)

Compute the mean absolute difference between consecutive fluxes.

index_binning(x, size)

Bin indices of x into bins of given size.

binned_nanstd(x[, bins])

Return a function to compute the mean of the standard deviation in bins.

fake_image([shape, seed, stars])

Generate a fake image with random stars.

share_data(master_files)

Save master calibration arrays to disk as memory-mapped files and return read-only memmap objects.

Module Contents#

eloy.utils.cutout(data, coords, shape, wcs=None, fill_value=np.nan)[source]#

Extract cutouts from data at given coordinates.

Parameters:
  • data (np.ndarray) – 2D image data.

  • coords (array-like) – List of (x, y) coordinates.

  • shape (tuple) – Shape of the cutout.

  • wcs (WCS or None, optional) – World Coordinate System object.

Returns:

Array of cutout images.

Return type:

np.ndarray

eloy.utils.std_diff_metric(fluxes)[source]#

Compute the standard deviation of the difference along the last axis.

Parameters:

fluxes (np.ndarray) – Fluxes array.

Returns:

Standard deviation of the differences.

Return type:

np.ndarray

eloy.utils.stability_aperture(fluxes)[source]#

Compute the mean absolute difference between consecutive fluxes.

Parameters:

fluxes (np.ndarray) – Fluxes array.

Returns:

Mean absolute difference for each aperture.

Return type:

np.ndarray

eloy.utils.index_binning(x, size)[source]#

Bin indices of x into bins of given size.

Parameters:
  • x (array-like) – Array to bin.

  • size (int or float) – Bin size.

Returns:

List of arrays of indices for each bin.

Return type:

list

eloy.utils.binned_nanstd(x, bins: int = 12)[source]#

Return a function to compute the mean of the standard deviation in bins.

Parameters:
  • x (np.ndarray) – Array to bin.

  • bins (int, optional) – Number of bins.

Returns:

Function that computes the mean of the standard deviation in bins.

Return type:

callable

eloy.utils.fake_image(shape=50, seed=0, stars=30)[source]#

Generate a fake image with random stars.

Parameters:
  • shape (int, optional) – Size of the image (shape x shape).

  • seed (int, optional) – Random seed.

  • stars (int, optional) – Number of stars.

Returns:

Tuple (image, coords) where image is the generated image and coords are the star positions.

Return type:

tuple

eloy.utils.share_data(master_files)[source]#

Save master calibration arrays to disk as memory-mapped files and return read-only memmap objects.

This function writes each array in master_files to a .array file using numpy’s memmap, allowing efficient concurrent access from multiple processes. The returned dictionary contains read-only memmap objects for each calibration file.

Parameters:

master_files (dict) – Dictionary mapping string keys (e.g., ‘bias’, ‘dark’, ‘flat’) to numpy.ndarray calibration arrays.

Returns:

Dictionary mapping the same keys to numpy.memmap objects opened in read-only mode.

Return type:

dict