starred.utils package
Submodules
starred.utils.ds9_reg module
- starred.utils.generic_utils.Downsample(image, factor=1, conserve_flux=False)[source]
Resizes an image from dimensions (nx, ny) to (nx/factor, ny/factor).
- Parameters:
image – 2D array with shape (nx, ny)
factor (int) – downsampling factor, which must be greater than or equal to 1
- Returns:
2D array
- starred.utils.generic_utils.Upsample(image, factor=1)[source]
Resizes an image without interpolation.
- Parameters:
image – 2D array with shape (nx, ny)
factor (int) – upsampling factor, which must be greater than or equal to 1
- Returns:
2D array
- starred.utils.generic_utils.fft_convolve2d(x, y)[source]
2D convolution using the Fast Fourier Transform (FFT).
- Parameters:
x – first 2D array
y – second 2D array
- Returns:
2D array
- starred.utils.generic_utils.fourier_division(a, b)[source]
Divides two arrays in Fourier space. Work much better with even kernel. To obtain the narrow PSF, a should be the full PSF and b a gaussian with 2pix FWHM. This function makes use of scipy if the kernel are even, and is not yet jaxified
- Parameters:
a – first array
b – second array
- starred.utils.generic_utils.fwhm2sigma(fwhm)[source]
Converts the FWHM (Full Width at Half Maximum) to the Gaussian sigma.
- Parameters:
fwhm (float) – the full width at half maximum value
- Returns:
Gaussian standard deviation, i.e., sqrt(var)
- starred.utils.generic_utils.gaussian_function(x, y, amp, sigma_x, sigma_y, center_x, center_y)[source]
- Parameters:
- Returns:
2D Gaussian
- starred.utils.generic_utils.gaussian_function_batched(x, y, amp, sigma_x, sigma_y, center_x, center_y)[source]
adjusted gaussian_function to accept and process batches for center_x and center_y. amp, sigma_x, sigma_y can also be vectors. but won’t be needed in starred, as we scale the PSF at the moffat step.
x and y: 2d arrays of coordinates made by make_grid and reshaped.
- starred.utils.generic_utils.make_grid(numPix, deltapix, subgrid_res=1)[source]
Creates pixel grid as 1D arrays of x and y positions. The default coordinate frame is such that (0,0) is at the center of the coordinate grid.
- Parameters:
numPix – number of pixels per axis. Provide an integer for a square grid
deltapix – pixel size
subgrid_res – sub-pixel resolution
- Returns:
x and y position information given as two 1D arrays
- starred.utils.generic_utils.moffat_elliptical_function(x, y, amp, fwhm_x, fwhm_y, phi, beta, center_x, center_y)[source]
- Parameters:
x – 1D array of x positions
y – 1D array of y positions
amp (float) – the amplitude coefficient
fwhm_x (float) – the full width at half maximum value in the x direction
fwhm_y (float) – the full width at half maximum value in the y direction
phi (float) – orientation angle
beta (float) – the Moffat beta parameter
center_x (float) – x position of the center
center_y (float) – y position of the center
- Returns:
2D Elliptical Moffat
- starred.utils.generic_utils.moffat_function(x, y, amp, fwhm, beta, center_x, center_y)[source]
- Parameters:
- Returns:
2D Moffat
- starred.utils.generic_utils.pad_and_convolve(x, y, padding=True)[source]
Lax convolution is performed after an optional padding.
- Parameters:
x – first array
y – second array
padding (bool) – padding
- Returns:
output array
- starred.utils.generic_utils.pad_and_convolve_fft(x, y, padding=True)[source]
FFT (Fast Fourier Transform) convolution is performed after an optional padding.
- Parameters:
x – first array
y – second array
padding (bool) – padding
- Returns:
Output array
- starred.utils.generic_utils.save_fits(array, path, header=None)[source]
Saves
.fitsfile of an array to a specifiedpath.
- starred.utils.generic_utils.save_npy(array, path, header=None)[source]
Saves
.npyfile of an array to a specifiedpath. Header is not used in this format.
- starred.utils.generic_utils.scipy_convolve(data, kernel)[source]
FFT-based Scipy convolution.
- Parameters:
data – first array
kernel – second array
- Returns:
output array
- starred.utils.generic_utils.timer_func(func)[source]
This function shows the execution time of the provided function object.
- starred.utils.generic_utils.twoD_Gaussian(x, y, amplitude, xo, yo, sigma_x, sigma_y, theta)[source]
Analytical 2D Gaussian function
- Parameters:
x – array containing x-axis variable
y – array containing y-axis variable
amplitude – amplitude of the Gaussian
xo – center x coordinate
yo – center y coordinate
sigma_x – standard deviation of x variable
sigma_y – standard deviation of y variable
theta – ellongation angle
starred.utils.generic_utils module
- starred.utils.generic_utils.Downsample(image, factor=1, conserve_flux=False)[source]
Resizes an image from dimensions (nx, ny) to (nx/factor, ny/factor).
- Parameters:
image – 2D array with shape (nx, ny)
factor (int) – downsampling factor, which must be greater than or equal to 1
- Returns:
2D array
- starred.utils.generic_utils.Upsample(image, factor=1)[source]
Resizes an image without interpolation.
- Parameters:
image – 2D array with shape (nx, ny)
factor (int) – upsampling factor, which must be greater than or equal to 1
- Returns:
2D array
- starred.utils.generic_utils.fft_convolve2d(x, y)[source]
2D convolution using the Fast Fourier Transform (FFT).
- Parameters:
x – first 2D array
y – second 2D array
- Returns:
2D array
- starred.utils.generic_utils.fourier_division(a, b)[source]
Divides two arrays in Fourier space. Work much better with even kernel. To obtain the narrow PSF, a should be the full PSF and b a gaussian with 2pix FWHM. This function makes use of scipy if the kernel are even, and is not yet jaxified
- Parameters:
a – first array
b – second array
- starred.utils.generic_utils.fwhm2sigma(fwhm)[source]
Converts the FWHM (Full Width at Half Maximum) to the Gaussian sigma.
- Parameters:
fwhm (float) – the full width at half maximum value
- Returns:
Gaussian standard deviation, i.e., sqrt(var)
- starred.utils.generic_utils.gaussian_function(x, y, amp, sigma_x, sigma_y, center_x, center_y)[source]
- Parameters:
- Returns:
2D Gaussian
- starred.utils.generic_utils.gaussian_function_batched(x, y, amp, sigma_x, sigma_y, center_x, center_y)[source]
adjusted gaussian_function to accept and process batches for center_x and center_y. amp, sigma_x, sigma_y can also be vectors. but won’t be needed in starred, as we scale the PSF at the moffat step.
x and y: 2d arrays of coordinates made by make_grid and reshaped.
- starred.utils.generic_utils.make_grid(numPix, deltapix, subgrid_res=1)[source]
Creates pixel grid as 1D arrays of x and y positions. The default coordinate frame is such that (0,0) is at the center of the coordinate grid.
- Parameters:
numPix – number of pixels per axis. Provide an integer for a square grid
deltapix – pixel size
subgrid_res – sub-pixel resolution
- Returns:
x and y position information given as two 1D arrays
- starred.utils.generic_utils.moffat_elliptical_function(x, y, amp, fwhm_x, fwhm_y, phi, beta, center_x, center_y)[source]
- Parameters:
x – 1D array of x positions
y – 1D array of y positions
amp (float) – the amplitude coefficient
fwhm_x (float) – the full width at half maximum value in the x direction
fwhm_y (float) – the full width at half maximum value in the y direction
phi (float) – orientation angle
beta (float) – the Moffat beta parameter
center_x (float) – x position of the center
center_y (float) – y position of the center
- Returns:
2D Elliptical Moffat
- starred.utils.generic_utils.moffat_function(x, y, amp, fwhm, beta, center_x, center_y)[source]
- Parameters:
- Returns:
2D Moffat
- starred.utils.generic_utils.pad_and_convolve(x, y, padding=True)[source]
Lax convolution is performed after an optional padding.
- Parameters:
x – first array
y – second array
padding (bool) – padding
- Returns:
output array
- starred.utils.generic_utils.pad_and_convolve_fft(x, y, padding=True)[source]
FFT (Fast Fourier Transform) convolution is performed after an optional padding.
- Parameters:
x – first array
y – second array
padding (bool) – padding
- Returns:
Output array
- starred.utils.generic_utils.save_fits(array, path, header=None)[source]
Saves
.fitsfile of an array to a specifiedpath.
- starred.utils.generic_utils.save_npy(array, path, header=None)[source]
Saves
.npyfile of an array to a specifiedpath. Header is not used in this format.
- starred.utils.generic_utils.scipy_convolve(data, kernel)[source]
FFT-based Scipy convolution.
- Parameters:
data – first array
kernel – second array
- Returns:
output array
- starred.utils.generic_utils.timer_func(func)[source]
This function shows the execution time of the provided function object.
- starred.utils.generic_utils.twoD_Gaussian(x, y, amplitude, xo, yo, sigma_x, sigma_y, theta)[source]
Analytical 2D Gaussian function
- Parameters:
x – array containing x-axis variable
y – array containing y-axis variable
amplitude – amplitude of the Gaussian
xo – center x coordinate
yo – center y coordinate
sigma_x – standard deviation of x variable
sigma_y – standard deviation of y variable
theta – ellongation angle
starred.utils.jax_utils module
- starred.utils.jax_utils.convolveSeparableDilated(image2D, kernel1D, dilation=1)[source]
Convolves an image contained in
image2Dwith the 1D kernelkernel1D. The operation is blured2D = image2D * (kernel1D ∧ kernel1D), where ∧ is a wedge product, here a tensor product.- Parameters:
kernel1D – 1D array to convolve the image with
image2D – 2D array
dilation – makes the spacial extent of the kernel bigger. The default is 1.
- Returns:
2D array
- starred.utils.jax_utils.decompose(image, n_scales)[source]
Decomposes an image into a chosen wavelet basis.
- starred.utils.jax_utils.reconstruct(coeffs)[source]
Reconstructs an image from wavelet decomposition coefficients.
- starred.utils.jax_utils.rotate_array(array, angle_deg)[source]
rotates a 2D array by angle_deg degrees. We are using bilinear interpolation (higher orders not implemented in jax yet)
- Parameters:
array – 2D array to be rotated
angle_deg – float, rotation in degrees.
- Returns:
2D array - a rotated version of the input array
starred.utils.light_profile_analytical module
- starred.utils.light_profile_analytical.R_stable(R)[source]
Floor R_ at self._smoothing for numerical stability :param R: radius :return: smoothed and stabilized radius
- starred.utils.light_profile_analytical.b_n(n)[source]
b(n) computation. This is the approximation of the exact solution to the relation, 2*incomplete_gamma_function(2n; b_n) = Gamma_function(2*n). :param n: the sersic index :return:
- starred.utils.light_profile_analytical.ellipticity2phi_q(e1, e2)[source]
Transform complex ellipticity components to position angle and axis ratio.
- starred.utils.light_profile_analytical.get_distance_from_center(x, y, phi_G, q, center_x, center_y)[source]
Get the distance from the center of Sersic, accounting for orientation and axis ratio :param x: :param y: :param phi_G: orientation angle in rad :param q: axis ratio :param center_x: center x of sersic :param center_y: center y of sersic
- starred.utils.light_profile_analytical.phi_q2_ellipticity(phi, q)[source]
transforms orientation angle and axis ratio into complex ellipticity moduli e1, e2
- Parameters:
phi – angle of orientation (in radian)
q – axis ratio minor axis / major axis
- Returns:
eccentricities e1 and e2 in complex ellipticity moduli
- starred.utils.light_profile_analytical.r_sersic(R, R_sersic, n_sersic, max_R_frac=100.0)[source]
- Parameters:
R – radius (array or float)
R_sersic – Sersic radius (half-light radius)
n_sersic – Sersic index (float)
max_R_frac – maximum window outside of which the mass is zeroed, in units of R_sersic (float)
- Returns:
kernel of the Sersic surface brightness at R
- starred.utils.light_profile_analytical.sersic_ellipse(x, y, R_sersic, n_sersic, e1, e2, center_x, center_y, amp, max_R_frac=100.0)[source]
- Parameters:
x
y
amp – surface brightness/amplitude value at the half light radius
R_sersic – semi-major axis half light radius, in pixel
n_sersic – Sersic index
e1 – eccentricity parameter
e2 – eccentricity parameter
center_x – center in x-coordinate
center_y – center in y-coordinate
max_R_frac – truncation radius, in units of R_sersic (float)
- Returns:
Sersic profile value at (x, y)
starred.utils.noise_utils module
- starred.utils.noise_utils.dirac_impulse(num_pix)[source]
Returns a 2D array with a Dirac impulse at its center.
- Parameters:
num_pix (int) – number of pixels per axis
- Returns:
2D array
- starred.utils.noise_utils.propagate_noise(model, noise_maps, kwargs, masks=None, wavelet_type_list=['starlet'], method='MC', num_samples=100, seed=None, likelihood_type='chi2', verbose=False, upsampling_factor=1, scaling_noise_ref=None)[source]
Performs noise propagation using MC or SLIT methods.
- Parameters:
model – array containing the model
noise_maps – array containing the noise maps
kwargs – dictionary containing the parameters of the model
masks – array containing the masks
wavelet_type_list – list with the appropriate wavelet families
method – method for noise propagation. Choose ‘MC’ for an empirical propagation of the noise or ‘SLIT’ for analytical propagation.
num_samples (int) – number of realizations for the MC method. Not used if `method`=’SLIT’.
upsampling_factor (int) – the upsampling factor
scaling_noise_ref – index position of the reference noise map (lambda is given in the unit of standard deviation for this noise map).
Leave it to None to take the mean of all provided noise maps (recommended). This only works for the PSF reconstruction. For the deconvolution, the reference image’s noise map is always used, so lambda is given in unit of noise level, according to this noise map. :type scaling_noise_ref: integer
starred.utils.parameters module
- class starred.utils.parameters.Parameters(kwargs_init, kwargs_fixed, kwargs_up=None, kwargs_down=None)[source]
Bases:
objectParameters class.
- Parameters:
kwargs_init – dictionary with information on the initial values of the parameters
kwargs_fixed – dictionary containing the fixed parameters
kwargs_up – dictionary with information on the upper bounds of the parameters
kwargs_down – dictionary with information on the lower bounds of the parameters
- current_values(as_kwargs=False, restart=False, copy=False)[source]
Returns the current values of the parameters.
- property optimized
Checks whether a function is optimized.
Module contents
This subpackage contains generic and optimization functions