hyri.interface.spectral_index#
Fit clean beams and estimate spectral-index maps from image cubes.
This file provides the PSF-to-beam fitting step and the per-pixel spectral index estimation used by the hyperspectral imaging pipeline.
Functions
Fit an elliptical Gaussian clean beam to a point-spread function. |
|
Evaluate an unnormalised 2D Gaussian on coordinate samples. |
|
Estimate a spectral-index map from an image cube. |
- hyri.interface.spectral_index.gaussian2D(coords, sigma_x, sigma_y, theta) ndarray#
Evaluate an unnormalised 2D Gaussian on coordinate samples.
- Parameters:
- Returns:
Gaussian values for each input coordinate.
- Return type:
np.ndarray
- hyri.interface.spectral_index.fit_clean_beam(psf, verbose=True) tuple[ndarray, float, float, float]#
Fit an elliptical Gaussian clean beam to a point-spread function.
The PSF is normalised before fitting, a compact PSF may fall back to a delta-function beam, and the fitted Gaussian kernel is normalised to unit sum.
- Parameters:
psf (np.ndarray) – Point-spread function image.
verbose (bool, optional) – Whether to print fit diagnostics. Default: True.
- Returns:
(kernel, sigma_x, sigma_y, theta)wherekernelis the fitted clean-beam kernel.- Return type:
- Raises:
ValueError – If
psfhas no positive finite peak.
Note
The Gaussian fit uses the region where
psf > 0.5to seed the initial guess.Examples
>>> yy, xx = np.mgrid[-8:9, -8:9] >>> psf = np.exp(-0.5 * ((xx / 2.5) ** 2 + (yy / 1.8) ** 2)) >>> kernel, sigma_x, sigma_y, theta = fit_clean_beam(psf, verbose=False) >>> kernel.ndim 2 >>> np.isclose(kernel.sum(), 1.0) True >>> sigma_x > 0 and sigma_y > 0 True
- hyri.interface.spectral_index.get_spec_idx(img_cube, freqs, kernel=None, threshold=1e-05, crop_roi=None) ndarray#
Estimate a spectral-index map from an image cube.
The function optionally crops the cube, optionally smooths it with a clean beam, and fits a log-log slope at each pixel above a threshold.
- Parameters:
img_cube (np.ndarray) – Image cube with frequency as the first axis.
freqs (np.ndarray) – Frequency samples corresponding to the cube.
kernel (np.ndarray, optional) – Optional convolution kernel used to smooth each frequency slice before fitting. Default: None.
threshold (float, optional) – Minimum per-pixel value across all frequencies required to fit a spectral index. Default: 1e-5.
crop_roi (Tuple[int, int, int, int], optional) – Optional crop region as
(x_start, x_end, y_start, y_end). Default: None.
- Returns:
Spectral-index map with positive values clipped to zero and invalid pixels set to
NaN.- Return type:
np.ndarray
Note
Pixels below
thresholdat any frequency are excluded from fitting.Examples
>>> cube = np.ones((2, 4, 4)) >>> alpha = get_spec_idx(cube, np.array([1.0, 2.0]), threshold=0.5) >>> alpha.shape (4, 4)