disco.core.fits_utils
This module provides all FITS-level I/O functions and astrometric utilities used by the CLI pipeline and, indirectly, by the GUI backend. It handles beam convolution kernels, robust centroid detection, parameter auto-detection, radial profile extraction, WCS conversions, and Gaia DR3 proper-motion retrieval.
The availability of astroquery is detected at import time and stored in
the module-level flag _ASTROQUERY_AVAILABLE. When astroquery is
absent, the Gaia-related functions are no-ops returning (None, None, None).
Beam Utilities
- disco.core.fits_utils.get_alma_beam(sigma_maj, sigma_min, bpa_rad, size=15)[source]
Construct a 2D elliptical Gaussian beam kernel on a grid of half-width
size.- Parameters:
- Returns:
Normalised 2D kernel array.
- Return type:
- disco.core.fits_utils.deconvolve_beams(bmaj_t, bmin_t, pa_t, bmaj_i, bmin_i, pa_i)[source]
Compute the convolution kernel required to convolve an image with beam \((b_{\rm maj,i}, b_{\rm min,i}, \phi_i)\) to the target beam \((b_{\rm maj,t}, b_{\rm min,t}, \phi_t)\).
The deconvolution is performed analytically via covariance matrix subtraction: \(\Sigma_c = \Sigma_t - \Sigma_i\), followed by eigendecomposition to recover the convolution kernel axes.
- Parameters:
bmaj_t (float) – Target beam major axis in arcseconds.
bmin_t (float) – Target beam minor axis in arcseconds.
pa_t (float) – Target beam position angle in degrees.
bmaj_i (float) – Input beam major axis in arcseconds.
bmin_i (float) – Input beam minor axis in arcseconds.
pa_i (float) – Input beam position angle in degrees.
- Returns:
(bmaj_c, bmin_c, pa_c)— the convolution kernel major axis (arcsec), minor axis (arcsec), and position angle (degrees). Returns(None, None, None)if the covariance difference has a negative eigenvalue (target beam smaller than input beam).- Return type:
- disco.core.fits_utils.make_gaussian_kernel_casa(bmaj_c, bmin_c, pa_c, pixel_scale)[source]
Build a 2D elliptical Gaussian convolution kernel in pixel space from beam parameters in arcseconds.
The kernel size is \(\lceil 5\sigma_{\rm maj} \rceil\) pixels (odd-sized). Normalised to unit sum.
- Parameters:
- Returns:
Normalised 2D kernel array.
- Return type:
Centroid and Parameter Detection
- disco.core.fits_utils.find_center_robust(data, pixel_scale, header)[source]
Robustly estimate the disk centroid by Gaussian-smoothing a central crop of the image and computing the centre of mass of the thresholded (> 20% of peak) emission region. If the filled region is significantly larger than the detected region (indicating a cavity), the geometric bounding-box midpoint is used instead.
The search radius is fixed at 3 arcsec from the array centre.
- disco.core.fits_utils.auto_detect_parameters(data, header, pixel_scale, cx, cy)[source]
Automatically estimate the inner radius, outer radius, and beam major axis from the image data and FITS header.
The outer radius is determined by scanning the azimuthally-averaged (non-deprojected) radial profile for the last bin exceeding \(3\sigma_{\rm edge}\), with a gap tolerance of 0.3 arcsec.
- disco.core.fits_utils.refine_center_local(data, header, pixel_scale, cx_init, cy_init)[source]
Refine a centroid estimate by Gaussian-smoothing a small crop around the initial position and computing the centre of mass of the thresholded emission. The search radius is \(0.6\,b_{\rm maj}\) or a minimum of 0.15 arcsec. If the refined position moves by more than the search radius, the initial estimate is returned unchanged.
Profile Extraction
- disco.core.fits_utils.extract_profile(data, header, incl, pa, pixel_scale, cx, cy, limit_arcsec)[source]
Extract the azimuthally-averaged brightness temperature radial profile from a FITS image, given the disk geometry.
The procedure is:
A \(1000 \times 1000\) deprojected image is generated by bilinear resampling (
map_coordinates, order 3) applying the inclination and position angle transform.The deprojected image is resampled into polar coordinates (\(R \in [0, 500\,\text{pix}]\), \(\theta \in [-180°, 180°]\)).
The azimuthal mean and standard deviation are computed.
The uncertainty profile accounts for the effective number of independent beams per annulus.
If a valid rest frequency and beam geometry are available, the profile is converted to brightness temperature \(T_b\) [K].
- Parameters:
data (numpy.ndarray) – 2D image array (in mJy/beam or equivalent).
header (dict) – FITS header (used for
BMAJ,BMIN,RESTFRQ).incl (float) – Inclination in degrees.
pa (float) – Position angle in degrees.
pixel_scale (float) – Arcsec per pixel.
cx (float) – Centroid x in pixels.
cy (float) – Centroid y in pixels.
limit_arcsec (float) – Maximum radius for the returned profile.
- Returns:
(r_arcsec, tb_prof, tb_err)— radius array, brightness temperature profile, and 1-sigma uncertainty, all clipped tolimit_arcsec.- Return type:
- disco.core.fits_utils.measure_rout_deproj(data, header, pixel_scale, cx, cy, incl, pa, rmin=0.0)[source]
Estimate the outer disk radius from the deprojected azimuthally-averaged profile. The profile is computed in pixel bins of width one pixel scale. The outer radius is defined as the last bin where the smoothed profile exceeds
2 × RMS, with a gap tolerance of 0.5 arcsec, plus a margin of \(\max(b_{\rm maj}, 3\,\delta_{\rm pix}, 0.03\,\text{arcsec})\).- Parameters:
data (numpy.ndarray) – 2D image array.
header (dict) – FITS header.
pixel_scale (float) – Arcsec per pixel.
cx (float) – Centroid x in pixels.
cy (float) – Centroid y in pixels.
incl (float) – Inclination in degrees.
pa (float) – Position angle in degrees.
rmin (float) – Inner radius in arcseconds (bins below this are skipped).
- Returns:
Estimated outer radius in arcseconds, clipped to [0.10, 8.0].
- Return type:
- disco.core.fits_utils.save_debug_deproj_center(image, cx, cy, incl, pa, rout_arcsec, pixel_scale, out_png, title)[source]
Save a diagnostic PNG showing the deprojected image with the optimised centroid (cross marker) and outer radius (dashed cyan circle) overlaid. Generated when
--debug onis specified.- Parameters:
image (numpy.ndarray) – 2D image array.
cx (float) – Centroid x in pixels.
cy (float) – Centroid y in pixels.
incl (float) – Inclination in degrees.
pa (float) – Position angle in degrees.
rout_arcsec (float) – Outer radius in arcseconds.
pixel_scale (float) – Arcsec per pixel.
out_png (str) – Output file path.
title (str) – Plot title string.
WCS and Coordinate Utilities
- disco.core.fits_utils.deg_to_sex(deg)[source]
Convert a decimal degree value to a sexagesimal string of the form
±DDD:MM:SS.sss.
- disco.core.fits_utils.pixel_to_icrs(header, cx, cy)[source]
Convert pixel coordinates to ICRS (RA, Dec) using the FITS WCS. Uses
astropy.wcs.WCS.celestialto handle cubes with degenerate axes.
- disco.core.fits_utils.icrs_to_pixel(header, ra_deg, dec_deg)[source]
Convert ICRS sky coordinates to pixel coordinates using the FITS WCS.
- disco.core.fits_utils.get_obs_epoch(header)[source]
Extract the observation epoch from the FITS header. Reads
DATE-OBS(ISO-T format) orMJD-OBS(Modified Julian Date).- Parameters:
header (dict) – FITS header.
- Returns:
Observation epoch as an
astropy.time.Timeobject, orNoneif neither keyword is present or parseable.- Return type:
astropy.time.Time or None
Gaia Proper Motion
- disco.core.fits_utils.query_gaia_proper_motion(ra_deg, dec_deg, search_radius_arcsec=3.0)[source]
Query the Gaia DR3 catalogue (
gaiadr3.gaia_source) for the nearest source withinsearch_radius_arcsecarcseconds of the supplied position. Returns the proper motion of the nearest source with validpmraandpmdecvalues.Requires
astroqueryto be installed. Returns(None, None, None)if the library is unavailable or no match is found.- Parameters:
- Returns:
(pmra_masyr, pmdec_masyr, separation_arcsec)for the nearest matched Gaia source, or(None, None, None).- Return type:
- disco.core.fits_utils.apply_proper_motion_correction(ra_deg, dec_deg, pmra_masyr, pmdec_masyr, dt_yr)[source]
Apply a proper-motion correction to a sky position, propagating it by
dt_yryears.\[\Delta\alpha = \frac{\mu_\alpha^* \, \Delta t}{\cos\delta \times 3.6 \times 10^6}, \qquad \Delta\delta = \frac{\mu_\delta \, \Delta t}{3.6 \times 10^6}\]- Parameters:
- Returns:
(ra_corrected_deg, dec_corrected_deg).- Return type: