lightstack package
Submodules
lightstack.crop module
- lightstack.crop.crop_from_radec(fits_path, ra, dec, size_arcsec, output_path=None)
Extract a square cutout from a FITS image centered on a given sky position.
- Parameters:
fits_path (str) – Path to the FITS image.
ra (float) – Right Ascension of the center (in degrees).
dec (float) – Declination of the center (in degrees).
size_arcsec (float) – Size of the cutout (in arcseconds). The cutout is square.
- Returns:
data_cut (2D numpy array) – Cropped image data.
header_cut (FITS header) – Updated header with corrected WCS reference (CRPIX).
- lightstack.crop.crop_reg(fits_path, region)
Crops a FITS image using a DS9 region.
- Parameters:
fits_path (str) – Path to the FITS file.
region (regions.Region) – Region object read from a DS9 region file.
- Returns:
data_cut (numpy.ndarray) – Cropped image data.
header_cut (astropy.io.fits.Header) – Updated FITS header with adjusted CRPIX keywords.
- Raises:
ValueError – If no image data extension is found in the FITS file.
- lightstack.crop.crop_using_reference(fits_path, ref_cutout, output_path=None)
Crop a FITS image using the sky footprint of a reference cutout.
This function extracts a region from a target image such that it matches the sky coverage (RA/Dec bounding box) of a reference FITS cutout.
- Parameters:
fits_path (str) – Path to the target FITS image to be cropped.
ref_cutout (str) – Path to the reference FITS cutout defining the sky region.
output_path (str, optional) – If provided, saves the cropped FITS to this path.
- Returns:
data_cut (2D numpy array) – Cropped image data.
header_cut (FITS header) – Updated header with corrected WCS reference (CRPIX).
- lightstack.crop.cut_region_2d(fits_file, x_start, x_end, y_start, y_end, output_path)
Cuts a spatial region from a 2D fits image.
- Parameters:
fits_file (str) – Path to the input 2D fits image.
x_start (int) – Pixel indices for the x axis.
x_end (int) – Pixel indices for the x axis.
y_start (int) – Pixel indices for the y axis.
y_end (int) – Pixel indices for the y axis.
output_path (str) – Path to the output fits file.
- Returns:
Saves the cut fits image.
- Return type:
None
- lightstack.crop.get_sky_bbox_from_cutout(fits_cut)
Get sky bounding box (RA, Dec) from a FITS cutout.
- Parameters:
fits_cut (str) – Path to FITS file
- Returns:
ra, dec – RA and Dec of the four corners
- Return type:
arrays
lightstack.datacube module
- lightstack.datacube.align_reproject_fits(fits_list, ref_file, method='interp', crop=1)
Align and optionally reproject FITS images to a common WCS. If an image already matches the reference WCS, shape and pixel scale, reprojection is skipped automatically. Area correction is only applied when input and output pixel scales differ.
- Parameters:
fits_list (list of tuples) – [(fits_path, filter_name), …]
ref_file (str) – Reference FITS file.
method (str, optional) – Reprojection method: - “interp” (default) - “exact”
crop (int, optional) – Pixels to crop from borders after reprojection.
- Returns:
aligned_list – [(aligned_fits_path, filter_name), …]
- Return type:
list of tuples
- lightstack.datacube.build_datacube(aligned_fits_files, reference_file, output_path)
Build a 3D datacube from aligned 2D FITS images.
- Parameters:
aligned_fits_files (list of tuples) – List in format [(filename, filter_name), …].
reference_file (str) – FITS file used to define WCS and output shape.
output_path (str) – Path to save the output datacube.
- Returns:
Saves the datacube to disk.
- Return type:
None
- lightstack.datacube.build_valid_datacube(cube_fits_file, output_cube, threshold=0.0, frac_valid=0.01)
Remove empty filters in a datacube, saves the new datacube and returns the valid filter names.
- Parameters:
cube_fits_file (str) – Path to the input 3D fits datacube.
output_cube (str) – Path to save the filtered fits.
threshold (float) – Minimum flux value to consider a pixel valid.
frac_valid (float) – Minimum fraction of pixels above the threshold to consider the filter valid.
- Returns:
cube_filtered (np.ndarray) – Datacube with only valid filters.
filters_valid (list) – List of valid filter names.
Saves the new datacube.
- lightstack.datacube.cut_region_datacube(cube_fits_file, x_start, x_end, y_start, y_end, output_path)
Cuts a spatial region from a datacube.
- Parameters:
cube_fits_file (str) – Path to the input 3D fits datacube.
x_start (int) – Pixel indices for the x axis.
x_end (int) – Pixel indices for the x axis.
y_start (int) – Pixel indices for the y axis.
y_end (int) – Pixel indices for the y axis.
output_path (str) – Path to the output fits file.
- Returns:
Saves the cut datacube.
- Return type:
None
- lightstack.datacube.load_image_fits(folder_path)
- lightstack.datacube.remove_filter(cube_fits_file, output_cube, filter_to_remove)
Removes a specific filter from a 3D datacube.
- Parameters:
cube_fits_file (str) – Path to the original datacube.
output_cube (str) – Path to save the new datacube.
filter_to_remove (str) – Name of the filter to be removed.
- lightstack.datacube.update_cube_header(cube_fits_file, output_file=None, redshift=None, ra_center=None, dec_center=None, use_brightest_pixel=False, overwrite=False)
Update a datacube header with astrophysical metadata.
By default, creates a new file with suffix ‘_more.fits’ instead of overwriting the original.
- Parameters:
cube_fits_file (str) – Path to input datacube.
output_file (str or None) – Output FITS file. If None, creates ‘<original>_more.fits’.
redshift (float or None) – Galaxy redshift.
ra_center (float or None) – Galaxy center coordinates (deg).
dec_center (float or None) – Galaxy center coordinates (deg).
use_brightest_pixel (bool) – If True, estimate center from brightest pixel.
overwrite (bool) – Overwrite output file if it already exists.
lightstack.plot module
- lightstack.plot.plot_datacube_filters(cube_fits_file, ncols=None, figsize=(15, 15), cmap='viridis', norm=None, stretch='log', min_percent=25.0, max_percent=99.98, save_path=None)
Plot all filters from a datacube as a grid of images.
- Parameters:
cube_fits_file (str) – Path to the 3D FITS datacube.
ncols (int or None) – Number of columns in the grid. If None, a near-square layout is used.
figsize (tuple) – Figure size.
cmap (str) – Colormap.
norm (matplotlib.colors.Normalize or None) – Custom normalization. If None, uses simple_norm.
stretch (str) – Stretch for simple_norm (ignored if norm is provided).
min_percent (float) – Percentile limits for normalization.
max_percent (float) – Percentile limits for normalization.
save_path (str or None) – If provided, saves the figure.
- lightstack.plot.plot_psf_grid(psf_dir=None, psf_files=None, ncols=None, figsize=(12, 12), norm=None, stretch='log', percent=99.0, cmap='viridis', save_path=None)
Plot a grid of PSFs from FITS files.
- Parameters:
psf_dir (str, optional) – Directory containing PSF FITS files.
psf_files (list, optional) – List of PSF FITS file paths (overrides psf_dir).
ncols (int or None) – Number of columns in the grid. If None, chosen automatically.
figsize (tuple) – Figure size.
norm (astropy visualization norm, optional) – Custom normalization.
stretch (str) – Stretch for simple_norm if norm is None.
percent (float) – Percentile used in simple_norm.
cmap (str) – Colormap.
save_path (str, optional) – Path to save figure.
- lightstack.plot.visualize_fits(fits_path, save_path=None, stretch='log', min_percent=25.0, max_percent=99.98, cmap='viridis', xlim=None, ylim=None)
Visualizes a FITS file with both pixel and RA/Dec axes.
- Parameters:
fits_path (str) – Path to the FITS file.
save_path (str or None) – Path to save the output image. If None, the figure is shown but not saved.
stretch (str) – Stretch type for simple_norm (e.g., ‘linear’, ‘log’, ‘sqrt’).
min_percent (float) – Percentile limits for normalization.
max_percent (float) – Percentile limits for normalization.
cmap (str) – Colormap name.
xlim (tuple or None) – Pixel axis limits.
ylim (tuple or None) – Pixel axis limits.
lightstack.psf module
- lightstack.psf.apply_kernel(image, kernel)
Convolve an image with a given kernel.
- Parameters:
image (2D array)
kernel (2D array)
- Returns:
image_conv
- Return type:
2D array
- lightstack.psf.build_kernel(psf_source, psf_ref, shape=(101, 101), eps=0.001)
Build a convolution kernel that transforms psf_source into psf_ref using Fourier fast transforms.
- Parameters:
psf_source (2D array) – PSF of the original image.
psf_ref (2D array) – PSF of the reference resolution.
shape (tuple) – Shape (Ny, Nx) of the kernel.
eps (float) – Regularization parameter.
- Returns:
kernel – Convolution kernel.
- Return type:
2D array
- lightstack.psf.centroid_weighted(psf, threshold=0.0001)
Compute a flux-weighted centroid of a PSF, ignoring low-level noise.
- Parameters:
psf (2D ndarray) – Input PSF image.
threshold (float, optional) – Fraction of the maximum PSF value below which pixels are ignored. Default is 1e-4.
- Returns:
ycen, xcen – Coordinates of the centroid (in pixel units).
- Return type:
float
- lightstack.psf.make_odd(psf)
Ensure that a PSF has odd dimensions by padding with zeros if necessary.
- Parameters:
psf (2D ndarray) – Input PSF image.
- Returns:
psf_padded – PSF with odd dimensions.
- Return type:
2D ndarray
- lightstack.psf.psf_match_datacube(cube_path, kernel_dir, ref_filter='F444W', output_path=None, overwrite=True)
Apply PSF matching to a datacube using precomputed convolution kernels.
Each slice is convolved to match the PSF of a reference filter.
- Parameters:
cube_path (str) – Path to input datacube FITS.
kernel_dir (str) – Directory containing kernel FITS files.
ref_filter (str) – Reference filter (e.g., “F444W”).
output_path (str or None) – Output FITS file. If None, adds ‘_psfmatched’.
overwrite (bool) – Overwrite output file.
- Returns:
output_path – Path to saved PSF-matched datacube.
- Return type:
str
- lightstack.psf.resample_psf(input_path, output_path, zoom_factor=None, psf_pixel_scale=None, target_pixel_scale=None, order=3, normalize=True, make_odd_shape=True, header_comment=True)
Resample a PSF to match a target pixel scale, by directly providing a zoom factor or by specifying the original and target pixel scales. Always downsample to the worst resolution. This code has not been tested for upsampling, so it is not recommended!
- Parameters:
input_path (str) – Path to input PSF FITS file.
output_path (str) – Path to save the resampled PSF.
zoom_factor (float, optional) – Zoom factor to apply. If None, it will be computed from pixel scales.
psf_pixel_scale (float, optional) – Original PSF pixel scale (arcsec/pixel).
target_pixel_scale (float, optional) – Target pixel scale (arcsec/pixel).
order (int, optional) – Interpolation order for scipy.ndimage.zoom. Default is 3 (cubic).
normalize (bool, optional) – If True, normalize PSF to unit sum. Default is True.
make_odd_shape (bool, optional) – If True, pad PSF to have odd dimensions. Default is True.
header_comment (bool, optional) – If True, add history information to FITS header.
- Returns:
psf_resampled – Resampled PSF array.
- Return type:
2D ndarray
- lightstack.psf.save_kernel(kernel, output_path, header=None)
Save a convolution kernel to a FITS file.
- Parameters:
kernel (2D array) – Convolution kernel.
output_path (str) – Output FITS path.
header (fits.Header or None) – Optional header to attach to the kernel.
lightstack.utils module
- lightstack.utils.MJy_sr_to_jy(aligned_list)
Convert FITS images from MJy/sr to Jy/pixel using the PIXAR_SR keyword: Jy/pixel = (MJy/sr) * 1e6 * PIXAR_SR
- Parameters:
aligned_list (list of tuples) – List in the form [(fits_path, filter_name), …].
- Returns:
new_list – List in the form [(new_fits_path, filter_name), …] for the converted files.
- Return type:
list of tuples
- lightstack.utils.add_custom_dataset(dataset_name, filters, overwrite=False)
Add a custom dataset/survey to FILTER_DATABASE.
- Parameters:
dataset_name (str) – Name of the telescope/survey (e.g. ‘EUCLID’, ‘ROMAN’).
filters (dict) –
Dictionary in format:
- {
- “FILTER1”: {
“lambda”: 5500.0 (in angstroms), “instrument”: “TelescopeCam”, “group”: “broad”, “output_group”: “Telescope”
}
overwrite (bool, optional) – If True, overwrite existing dataset.
- Return type:
None
- lightstack.utils.find_ext(hdul)
Finds the first FITS extension containing valid image data.
- Parameters:
hdul (astropy.io.fits.HDUList) – Opened FITS file.
- Returns:
ext – Index of the HDU containing image data. Returns None if not found.
- Return type:
int or None
- lightstack.utils.get_filter(fname)
Infer filter name from filename using FILTER_DATABASE. Works for JWST, HST, LSST, JPAS and future surveys.
- lightstack.utils.get_filter_info(filt)
Return metadata for a given filter from FILTER_DATABASE.
- lightstack.utils.get_pixel_scale(fits_path)
Opens FITS file and computes pixel scale in arcsec/pixel using WCS. Assumes square pixels and no significant distortion.
- lightstack.utils.get_pixel_scale_from_wcs(wcs)
Compute pixel scale in arcsec/pixel from a WCS object. Assumes square pixels and no significant distortion.
- lightstack.utils.pick_group(filt)
Return a group for a filter.
- lightstack.utils.pick_instrument(filt)
Return a instrument for a filter.
- lightstack.utils.pick_output_group(filt)
Return output grouping for a filter.
- lightstack.utils.save_fits(data, header, path)
Saves a FITS file to disk.
- Parameters:
data (numpy.ndarray) – Image data.
header (astropy.io.fits.Header) – FITS header.
path (str) – Output FITS path.
- lightstack.utils.sort_filters(filters)
Sort filters by wavelength.
Module contents
Lightstack: Tools for processing, PSF matching, and visualization of multi-filter photometric datacubes using astronomical imaging (HST and JWST).
Main functionalities include: - Crop regions - Image alignment and photometric datacube construction - PSF matching using convolution kernels - Visualization of FITS images and datacubes
- lightstack.MJy_sr_to_jy(aligned_list)
Convert FITS images from MJy/sr to Jy/pixel using the PIXAR_SR keyword: Jy/pixel = (MJy/sr) * 1e6 * PIXAR_SR
- Parameters:
aligned_list (list of tuples) – List in the form [(fits_path, filter_name), …].
- Returns:
new_list – List in the form [(new_fits_path, filter_name), …] for the converted files.
- Return type:
list of tuples
- lightstack.add_custom_dataset(dataset_name, filters, overwrite=False)
Add a custom dataset/survey to FILTER_DATABASE.
- Parameters:
dataset_name (str) – Name of the telescope/survey (e.g. ‘EUCLID’, ‘ROMAN’).
filters (dict) –
Dictionary in format:
- {
- “FILTER1”: {
“lambda”: 5500.0 (in angstroms), “instrument”: “TelescopeCam”, “group”: “broad”, “output_group”: “Telescope”
}
overwrite (bool, optional) – If True, overwrite existing dataset.
- Return type:
None
- lightstack.align_reproject_fits(fits_list, ref_file, method='interp', crop=1)
Align and optionally reproject FITS images to a common WCS. If an image already matches the reference WCS, shape and pixel scale, reprojection is skipped automatically. Area correction is only applied when input and output pixel scales differ.
- Parameters:
fits_list (list of tuples) – [(fits_path, filter_name), …]
ref_file (str) – Reference FITS file.
method (str, optional) – Reprojection method: - “interp” (default) - “exact”
crop (int, optional) – Pixels to crop from borders after reprojection.
- Returns:
aligned_list – [(aligned_fits_path, filter_name), …]
- Return type:
list of tuples
- lightstack.apply_kernel(image, kernel)
Convolve an image with a given kernel.
- Parameters:
image (2D array)
kernel (2D array)
- Returns:
image_conv
- Return type:
2D array
- lightstack.build_datacube(aligned_fits_files, reference_file, output_path)
Build a 3D datacube from aligned 2D FITS images.
- Parameters:
aligned_fits_files (list of tuples) – List in format [(filename, filter_name), …].
reference_file (str) – FITS file used to define WCS and output shape.
output_path (str) – Path to save the output datacube.
- Returns:
Saves the datacube to disk.
- Return type:
None
- lightstack.build_kernel(psf_source, psf_ref, shape=(101, 101), eps=0.001)
Build a convolution kernel that transforms psf_source into psf_ref using Fourier fast transforms.
- Parameters:
psf_source (2D array) – PSF of the original image.
psf_ref (2D array) – PSF of the reference resolution.
shape (tuple) – Shape (Ny, Nx) of the kernel.
eps (float) – Regularization parameter.
- Returns:
kernel – Convolution kernel.
- Return type:
2D array
- lightstack.build_valid_datacube(cube_fits_file, output_cube, threshold=0.0, frac_valid=0.01)
Remove empty filters in a datacube, saves the new datacube and returns the valid filter names.
- Parameters:
cube_fits_file (str) – Path to the input 3D fits datacube.
output_cube (str) – Path to save the filtered fits.
threshold (float) – Minimum flux value to consider a pixel valid.
frac_valid (float) – Minimum fraction of pixels above the threshold to consider the filter valid.
- Returns:
cube_filtered (np.ndarray) – Datacube with only valid filters.
filters_valid (list) – List of valid filter names.
Saves the new datacube.
- lightstack.centroid_weighted(psf, threshold=0.0001)
Compute a flux-weighted centroid of a PSF, ignoring low-level noise.
- Parameters:
psf (2D ndarray) – Input PSF image.
threshold (float, optional) – Fraction of the maximum PSF value below which pixels are ignored. Default is 1e-4.
- Returns:
ycen, xcen – Coordinates of the centroid (in pixel units).
- Return type:
float
- lightstack.crop_from_radec(fits_path, ra, dec, size_arcsec, output_path=None)
Extract a square cutout from a FITS image centered on a given sky position.
- Parameters:
fits_path (str) – Path to the FITS image.
ra (float) – Right Ascension of the center (in degrees).
dec (float) – Declination of the center (in degrees).
size_arcsec (float) – Size of the cutout (in arcseconds). The cutout is square.
- Returns:
data_cut (2D numpy array) – Cropped image data.
header_cut (FITS header) – Updated header with corrected WCS reference (CRPIX).
- lightstack.crop_reg(fits_path, region)
Crops a FITS image using a DS9 region.
- Parameters:
fits_path (str) – Path to the FITS file.
region (regions.Region) – Region object read from a DS9 region file.
- Returns:
data_cut (numpy.ndarray) – Cropped image data.
header_cut (astropy.io.fits.Header) – Updated FITS header with adjusted CRPIX keywords.
- Raises:
ValueError – If no image data extension is found in the FITS file.
- lightstack.crop_using_reference(fits_path, ref_cutout, output_path=None)
Crop a FITS image using the sky footprint of a reference cutout.
This function extracts a region from a target image such that it matches the sky coverage (RA/Dec bounding box) of a reference FITS cutout.
- Parameters:
fits_path (str) – Path to the target FITS image to be cropped.
ref_cutout (str) – Path to the reference FITS cutout defining the sky region.
output_path (str, optional) – If provided, saves the cropped FITS to this path.
- Returns:
data_cut (2D numpy array) – Cropped image data.
header_cut (FITS header) – Updated header with corrected WCS reference (CRPIX).
- lightstack.cut_region_2d(fits_file, x_start, x_end, y_start, y_end, output_path)
Cuts a spatial region from a 2D fits image.
- Parameters:
fits_file (str) – Path to the input 2D fits image.
x_start (int) – Pixel indices for the x axis.
x_end (int) – Pixel indices for the x axis.
y_start (int) – Pixel indices for the y axis.
y_end (int) – Pixel indices for the y axis.
output_path (str) – Path to the output fits file.
- Returns:
Saves the cut fits image.
- Return type:
None
- lightstack.cut_region_datacube(cube_fits_file, x_start, x_end, y_start, y_end, output_path)
Cuts a spatial region from a datacube.
- Parameters:
cube_fits_file (str) – Path to the input 3D fits datacube.
x_start (int) – Pixel indices for the x axis.
x_end (int) – Pixel indices for the x axis.
y_start (int) – Pixel indices for the y axis.
y_end (int) – Pixel indices for the y axis.
output_path (str) – Path to the output fits file.
- Returns:
Saves the cut datacube.
- Return type:
None
- lightstack.find_ext(hdul)
Finds the first FITS extension containing valid image data.
- Parameters:
hdul (astropy.io.fits.HDUList) – Opened FITS file.
- Returns:
ext – Index of the HDU containing image data. Returns None if not found.
- Return type:
int or None
- lightstack.get_filter(fname)
Infer filter name from filename using FILTER_DATABASE. Works for JWST, HST, LSST, JPAS and future surveys.
- lightstack.get_filter_info(filt)
Return metadata for a given filter from FILTER_DATABASE.
- lightstack.get_pixel_scale(fits_path)
Opens FITS file and computes pixel scale in arcsec/pixel using WCS. Assumes square pixels and no significant distortion.
- lightstack.get_pixel_scale_from_wcs(wcs)
Compute pixel scale in arcsec/pixel from a WCS object. Assumes square pixels and no significant distortion.
- lightstack.get_sky_bbox_from_cutout(fits_cut)
Get sky bounding box (RA, Dec) from a FITS cutout.
- Parameters:
fits_cut (str) – Path to FITS file
- Returns:
ra, dec – RA and Dec of the four corners
- Return type:
arrays
- lightstack.load_image_fits(folder_path)
- lightstack.make_odd(psf)
Ensure that a PSF has odd dimensions by padding with zeros if necessary.
- Parameters:
psf (2D ndarray) – Input PSF image.
- Returns:
psf_padded – PSF with odd dimensions.
- Return type:
2D ndarray
- lightstack.pick_group(filt)
Return a group for a filter.
- lightstack.pick_instrument(filt)
Return a instrument for a filter.
- lightstack.pick_output_group(filt)
Return output grouping for a filter.
- lightstack.plot_datacube_filters(cube_fits_file, ncols=None, figsize=(15, 15), cmap='viridis', norm=None, stretch='log', min_percent=25.0, max_percent=99.98, save_path=None)
Plot all filters from a datacube as a grid of images.
- Parameters:
cube_fits_file (str) – Path to the 3D FITS datacube.
ncols (int or None) – Number of columns in the grid. If None, a near-square layout is used.
figsize (tuple) – Figure size.
cmap (str) – Colormap.
norm (matplotlib.colors.Normalize or None) – Custom normalization. If None, uses simple_norm.
stretch (str) – Stretch for simple_norm (ignored if norm is provided).
min_percent (float) – Percentile limits for normalization.
max_percent (float) – Percentile limits for normalization.
save_path (str or None) – If provided, saves the figure.
- lightstack.plot_psf_grid(psf_dir=None, psf_files=None, ncols=None, figsize=(12, 12), norm=None, stretch='log', percent=99.0, cmap='viridis', save_path=None)
Plot a grid of PSFs from FITS files.
- Parameters:
psf_dir (str, optional) – Directory containing PSF FITS files.
psf_files (list, optional) – List of PSF FITS file paths (overrides psf_dir).
ncols (int or None) – Number of columns in the grid. If None, chosen automatically.
figsize (tuple) – Figure size.
norm (astropy visualization norm, optional) – Custom normalization.
stretch (str) – Stretch for simple_norm if norm is None.
percent (float) – Percentile used in simple_norm.
cmap (str) – Colormap.
save_path (str, optional) – Path to save figure.
- lightstack.psf_match_datacube(cube_path, kernel_dir, ref_filter='F444W', output_path=None, overwrite=True)
Apply PSF matching to a datacube using precomputed convolution kernels.
Each slice is convolved to match the PSF of a reference filter.
- Parameters:
cube_path (str) – Path to input datacube FITS.
kernel_dir (str) – Directory containing kernel FITS files.
ref_filter (str) – Reference filter (e.g., “F444W”).
output_path (str or None) – Output FITS file. If None, adds ‘_psfmatched’.
overwrite (bool) – Overwrite output file.
- Returns:
output_path – Path to saved PSF-matched datacube.
- Return type:
str
- lightstack.remove_filter(cube_fits_file, output_cube, filter_to_remove)
Removes a specific filter from a 3D datacube.
- Parameters:
cube_fits_file (str) – Path to the original datacube.
output_cube (str) – Path to save the new datacube.
filter_to_remove (str) – Name of the filter to be removed.
- lightstack.resample_psf(input_path, output_path, zoom_factor=None, psf_pixel_scale=None, target_pixel_scale=None, order=3, normalize=True, make_odd_shape=True, header_comment=True)
Resample a PSF to match a target pixel scale, by directly providing a zoom factor or by specifying the original and target pixel scales. Always downsample to the worst resolution. This code has not been tested for upsampling, so it is not recommended!
- Parameters:
input_path (str) – Path to input PSF FITS file.
output_path (str) – Path to save the resampled PSF.
zoom_factor (float, optional) – Zoom factor to apply. If None, it will be computed from pixel scales.
psf_pixel_scale (float, optional) – Original PSF pixel scale (arcsec/pixel).
target_pixel_scale (float, optional) – Target pixel scale (arcsec/pixel).
order (int, optional) – Interpolation order for scipy.ndimage.zoom. Default is 3 (cubic).
normalize (bool, optional) – If True, normalize PSF to unit sum. Default is True.
make_odd_shape (bool, optional) – If True, pad PSF to have odd dimensions. Default is True.
header_comment (bool, optional) – If True, add history information to FITS header.
- Returns:
psf_resampled – Resampled PSF array.
- Return type:
2D ndarray
- lightstack.save_fits(data, header, path)
Saves a FITS file to disk.
- Parameters:
data (numpy.ndarray) – Image data.
header (astropy.io.fits.Header) – FITS header.
path (str) – Output FITS path.
- lightstack.save_kernel(kernel, output_path, header=None)
Save a convolution kernel to a FITS file.
- Parameters:
kernel (2D array) – Convolution kernel.
output_path (str) – Output FITS path.
header (fits.Header or None) – Optional header to attach to the kernel.
- lightstack.sort_filters(filters)
Sort filters by wavelength.
- lightstack.update_cube_header(cube_fits_file, output_file=None, redshift=None, ra_center=None, dec_center=None, use_brightest_pixel=False, overwrite=False)
Update a datacube header with astrophysical metadata.
By default, creates a new file with suffix ‘_more.fits’ instead of overwriting the original.
- Parameters:
cube_fits_file (str) – Path to input datacube.
output_file (str or None) – Output FITS file. If None, creates ‘<original>_more.fits’.
redshift (float or None) – Galaxy redshift.
ra_center (float or None) – Galaxy center coordinates (deg).
dec_center (float or None) – Galaxy center coordinates (deg).
use_brightest_pixel (bool) – If True, estimate center from brightest pixel.
overwrite (bool) – Overwrite output file if it already exists.
- lightstack.visualize_fits(fits_path, save_path=None, stretch='log', min_percent=25.0, max_percent=99.98, cmap='viridis', xlim=None, ylim=None)
Visualizes a FITS file with both pixel and RA/Dec axes.
- Parameters:
fits_path (str) – Path to the FITS file.
save_path (str or None) – Path to save the output image. If None, the figure is shown but not saved.
stretch (str) – Stretch type for simple_norm (e.g., ‘linear’, ‘log’, ‘sqrt’).
min_percent (float) – Percentile limits for normalization.
max_percent (float) – Percentile limits for normalization.
cmap (str) – Colormap name.
xlim (tuple or None) – Pixel axis limits.
ylim (tuple or None) – Pixel axis limits.