astrophot.utils package
Subpackages
- astrophot.utils.conversions package
- astrophot.utils.initialize package
- astrophot.utils.isophote package
Submodules
astrophot.utils.angle_operations module
- astrophot.utils.angle_operations.Angle_Average(a)[source]
Compute the average for a list of angles, which may wrap around a cyclic boundary.
a: list of angles in the range [0,2pi]
- astrophot.utils.angle_operations.Angle_COM_PA(flux, X=None, Y=None)[source]
Performs a center of angular mass calculation by using the flux as weights to compute a position angle which accounts for the general “direction” of the light. This PA is computed mod pi since these are 180 degree rotation symmetric.
- Parameters:
flux – the weight values for each element (by assumption, pixel fluxes) in a 2D array
X – x coordinate of the flux points. Assumed centered pixel indices if not given
Y – y coordinate of the flux points. Assumed centered pixel indices if not given
astrophot.utils.decorators module
- astrophot.utils.decorators.default_internal(func)[source]
This decorator inspects the input parameters for a function which expects to recieve image and parameters arguments. If either of these are not given, then the model can use its default values for the parameters assuming the image is the internal target object and the parameters are the internally stored parameters.
- astrophot.utils.decorators.ignore_numpy_warnings(func)[source]
This decorator is used to turn off numpy warnings. This should only be used in initialize scripts which often run heuristic code to determine initial parameter values. These heuristics may encounter log(0) or sqrt(-1) or other numerical artifacts and should handle them before returning. This decorator simply cleans up that processes to minimize clutter in the output.
astrophot.utils.interpolate module
- astrophot.utils.interpolate.Lanczos_kernel(dx, dy, scale)[source]
Kernel function for Lanczos interpolation, defines the interpolation behavior between pixels.
- astrophot.utils.interpolate.Lanczos_kernel_np(dx, dy, scale)[source]
convolution kernel for shifting all pixels in a grid by some sub-pixel length.
- astrophot.utils.interpolate.cubic_spline_torch(x: Tensor, y: Tensor, xs: Tensor, extend: str = 'const') Tensor [source]
Compute the 1D cubic spline interpolation for the given data points using PyTorch.
- Parameters:
x (Tensor) – A 1D tensor representing the x-coordinates of the known data points.
y (Tensor) – A 1D tensor representing the y-coordinates of the known data points.
xs (Tensor) – A 1D tensor representing the x-coordinates of the positions where the cubic spline function should be evaluated.
extend (str, optional) – The method for handling extrapolation, either “const” or “linear”. Default is “const”. “const”: Use the value of the last known data point for extrapolation. “linear”: Use linear extrapolation based on the last two known data points.
- Returns:
A 1D tensor representing the interpolated values at the specified positions (xs).
- Return type:
Tensor
- astrophot.utils.interpolate.interp2d(im: Tensor, x: Tensor, y: Tensor) Tensor [source]
Interpolates a 2D image at specified coordinates. Similar to torch.nn.functional.grid_sample with align_corners=False.
- Parameters:
im (Tensor) – A 2D tensor representing the image.
x (Tensor) – A tensor of x coordinates (in pixel space) at which to interpolate.
y (Tensor) – A tensor of y coordinates (in pixel space) at which to interpolate.
- Returns:
Tensor with the same shape as x and y containing the interpolated values.
- Return type:
Tensor
- astrophot.utils.interpolate.interpolate_Lanczos(img, X, Y, scale)[source]
Perform Lanczos interpolation on an image at a series of specified points. https://pixinsight.com/doc/docs/InterpolationAlgorithms/InterpolationAlgorithms.html
- astrophot.utils.interpolate.interpolate_Lanczos_grid(img, X, Y, scale)[source]
Perform Lanczos interpolation at a grid of points. https://pixinsight.com/doc/docs/InterpolationAlgorithms/InterpolationAlgorithms.html
- astrophot.utils.interpolate.interpolate_bicubic(img, X, Y)[source]
wrapper for scipy bivariate spline interpolation
- astrophot.utils.interpolate.point_Lanczos(I, X, Y, scale)[source]
Apply Lanczos interpolation to evaluate a single point.
- astrophot.utils.interpolate.shift_Lanczos_np(I, dx, dy, scale)[source]
Apply Lanczos interpolation to shift by less than a pixel in x and y.
I: the image dx: amount by which the grid will be moved in the x-axis (the “data” is fixed and the grid moves). Should be a value from (-0.5,0.5) dy: amount by which the grid will be moved in the y-axis (the “data” is fixed and the grid moves). Should be a value from (-0.5,0.5) scale: dictates size of the Lanczos kernel. Full kernel size is 2*scale+1
astrophot.utils.operations module
- astrophot.utils.operations.displacement_grid(Nx, Ny, pixelscale=None, dtype=torch.float64, device='cpu')[source]
- astrophot.utils.operations.fft_convolve_multi_torch(img, kernels, kernel_fft=False, img_prepadded=False, dtype=None, device=None)[source]
- astrophot.utils.operations.fft_convolve_torch(img, psf, psf_fft=False, img_prepadded=False)[source]
- astrophot.utils.operations.grid_integrate(X, Y, image_header, eval_brightness, eval_parameters, dtype, device, quad_level=3, gridding=5, _current_depth=1, max_depth=2, reference=None)[source]
The grid_integrate function performs adaptive quadrature integration over a given pixel grid, offering precision control where it is needed most.
- Parameters:
X (torch.Tensor) – A 2D tensor representing the x-coordinates of the grid on which the function will be integrated.
Y (torch.Tensor) – A 2D tensor representing the y-coordinates of the grid on which the function will be integrated.
image_header (ImageHeader) – An object containing meta-information about the image.
eval_brightness (callable) – A function that evaluates the brightness at each grid point. This function should be compatible with PyTorch tensor operations.
eval_parameters (Parameter_Group) – An object containing parameters that are passed to the eval_brightness function.
dtype (torch.dtype) – The data type of the output tensor. The dtype argument should be a valid PyTorch data type.
device (torch.device) – The device on which to perform the computations. The device argument should be a valid PyTorch device.
quad_level (int, optional) – The initial level of quadrature used in the integration. Defaults to 3.
gridding (int, optional) – The factor by which the grid is subdivided when the integration error for a pixel is above the allowed threshold. Defaults to 5.
_current_depth (int, optional) – The current depth level of the grid subdivision. Used for recursive calls to the function. Defaults to 1.
max_depth (int, optional) – The maximum depth level of grid subdivision. Once this level is reached, no further subdivision is performed. Defaults to 2.
reference (torch.Tensor or None, optional) – A scalar value that represents the allowed threshold for the integration error.
- Returns:
A tensor of the same shape as X and Y that represents the result of the integration on the grid.
- Return type:
torch.Tensor
This function operates by first performing a quadrature integration over the given pixels. If the maximum depth level has been reached, it simply returns the result. Otherwise, it calculates the integration error for each pixel and selects those that have an error above the allowed threshold. For pixels that have low error, the result is set as computed. For those with high error, it sets up a finer sampling grid and recursively evaluates the quadrature integration on it. Finally, it integrates the results from the finer sampling grid back to the current resolution.
- astrophot.utils.operations.quad_table(n, p, dtype, device)[source]
from: https://pomax.github.io/bezierinfo/legendre-gauss.html
astrophot.utils.optimization module
astrophot.utils.parametric_profiles module
- astrophot.utils.parametric_profiles.exponential_np(R, Ie, Re)[source]
Exponential 1d profile function, works more generally with numpy operations.
- Parameters:
R – Radii array at which to evaluate the sersic function
Re – Effective radius in the same units as R
Ie – Effective surface density
- astrophot.utils.parametric_profiles.exponential_torch(R, Re, Ie)[source]
Exponential 1d profile function, specifically designed for pytorch operations.
- Parameters:
R – Radii tensor at which to evaluate the sersic function
Re – Effective radius in the same units as R
Ie – Effective surface density
- astrophot.utils.parametric_profiles.gaussian_np(R, sigma, I0)[source]
Gaussian 1d profile function, works more generally with numpy operations.
- Parameters:
R – Radii array at which to evaluate the sersic function
sigma – standard deviation of the gaussian in the same units as R
I0 – central surface density
- astrophot.utils.parametric_profiles.gaussian_torch(R, sigma, I0)[source]
Gaussian 1d profile function, specifically designed for pytorch operations.
- Parameters:
R – Radii tensor at which to evaluate the sersic function
sigma – standard deviation of the gaussian in the same units as R
I0 – central surface density
- astrophot.utils.parametric_profiles.moffat_np(R, n, Rd, I0)[source]
Moffat 1d profile function, works with numpy operations.
- Parameters:
R – Radii tensor at which to evaluate the moffat function
n – concentration index
Rd – scale length in the same units as R
I0 – central surface density
- astrophot.utils.parametric_profiles.moffat_torch(R, n, Rd, I0)[source]
Moffat 1d profile function, specifically designed for pytorch operations
- Parameters:
R – Radii tensor at which to evaluate the moffat function
n – concentration index
Rd – scale length in the same units as R
I0 – central surface density
- astrophot.utils.parametric_profiles.nuker_np(R, Rb, Ib, alpha, beta, gamma)[source]
Nuker 1d profile function, works with numpy functions
- Parameters:
R – Radii tensor at which to evaluate the nuker function
Ib – brightness at the scale length, represented as the log of the brightness divided by pixel scale squared.
Rb – scale length radius
alpha – sharpness of transition between power law slopes
beta – outer power law slope
gamma – inner power law slope
- astrophot.utils.parametric_profiles.nuker_torch(R, Rb, Ib, alpha, beta, gamma)[source]
Nuker 1d profile function, specifically designed for pytorch operations
- Parameters:
R – Radii tensor at which to evaluate the nuker function
Ib – brightness at the scale length, represented as the log of the brightness divided by pixel scale squared.
Rb – scale length radius
alpha – sharpness of transition between power law slopes
beta – outer power law slope
gamma – inner power law slope
- astrophot.utils.parametric_profiles.sersic_np(R, n, Re, Ie)[source]
Sersic 1d profile function, works more generally with numpy operations. In the event that impossible values are passed to the function it returns large values to guide optimizers away from such values.
- Parameters:
R – Radii array at which to evaluate the sersic function
n – sersic index restricted to n > 0.36
Re – Effective radius in the same units as R
Ie – Effective surface density
- astrophot.utils.parametric_profiles.sersic_torch(R, n, Re, Ie)[source]
Seric 1d profile function, specifically designed for pytorch operations
- Parameters:
R – Radii tensor at which to evaluate the sersic function
n – sersic index restricted to n > 0.36
Re – Effective radius in the same units as R
Ie – Effective surface density
- astrophot.utils.parametric_profiles.spline_torch(R, profR, profI, extend)[source]
Spline 1d profile function, cubic spline between points up to second last point beyond which is linear, specifically designed for pytorch.
- Parameters:
R – Radii tensor at which to evaluate the sersic function
profR – radius values for the surface density profile in the same units as R
profI – surface density values for the surface density profile