shapelets¶
-
class
shapelets.FitShapelets(fits_data=False, shpcoord=False)[source]¶ This class takes in FITS data and fitting parameters, and sets up and performs shapelet model fitting and generation. The main work-horse of the SHAMFI package
Parameters: - fits_data (shamfi.read_FITS_image.FITSInformation instance) – A
FITSInformationclass containing the data to be fit - shpcoord (shamfi.shapelet_coords.ShapeletCoords instance) – A
ShapeletCoordsclass containing the shapelet coordinate system
-
do_grid_search_fit(b1_grid, b2_grid, nmax, pa=False, convolve_kern=False, save_FITS=True, save_tag='shapelet')[source]¶ Do a grid search over all b1, b2 values specified in b1_grid, b2_grid, fitting all basis functions up to nmax, donig a least squares minimisation for each combination of b1, b2 to generate models
Parameters: - b1_grid (array) – A range of major axis beta scaling parameters to fit over
- b2_grid – A range of minor axis beta scaling parameters to fit over
- nmax (int) – The maximum order of basis function to generate up to
- pa (float) – If provided, use this postion angle to rotate the basis functions, instead of that found when fitting a Gaussian using shamfi.shapelet_coords.ShapeletCoords.fit_gauss_and_centre_coords
- convolve_kern (2D numpy array) – If provided, use this convolution kernel instead of the restoring beam of the CLEANed image
- save_FITS (bool) – Save the fitted shapelet model image to a FITS file
- save_tag (string) – A tag to add into the file name to save the plot to
-
do_grid_search_fit_compressed(compress_value, save_FITS=True, save_tag='shapelet')[source]¶ Do a grid search over all b1, b2 values for a given compression value. Can only be run after fitting the full model, via self.do_grid_search_fit so all b1,b2,nmax options have already been set and stored internally to the class.
Parameters: - compress_value (float) – A value to compress (truncate) the fit results to (percentage, e.g. 80 for 80%)
- save_FITS (bool) – Save the fitted shapelet model image to a FITS file
- save_tag (string) – A tag to add into the file name to save the plot to
-
find_flux_order_of_basis_functions()[source]¶ After fitting models, this function orders the fitted basis functions by absolution value in image space, to find those that contribute the most flux. To do this an ‘A’ matrix has to be generated to create an image
Variables: - basis_sums (array) – an array containing the sum of the flux of each basis function
- sums_order (array) – an array of the argsorted index of the sums of the flux of each basis function
-
save_srclist(save_tag='shapelet', rts_srclist=True, woden_srclist=True)[source]¶ Uses the best fitted parameters and creates an RTS/WODEN style srclist with them, saved as text files
Parameters: - save_tag (string) – A tag to add into the file name to save the plot to
- rts_srclist (bool) – If True, save a sky model compatible with the RTS (Mitchell et al, 2008)
- woden_srclist (bool) – If True, save a sky model compatible with WODEN (Line et al, 2020)
- fits_data (shamfi.read_FITS_image.FITSInformation instance) – A
-
shapelets.gen_A_shape_matrix(n1s=None, n2s=None, xrot=None, yrot=None, nmax=None, b1=None, b2=None, convolve_kern=False, shape=False)[source]¶ Generates the ‘A’ matrix in Ax = b when fitting shapelets, where:
- b = 1D matrix of data points to mode
- x = 1D matrix containing coefficients for basis functions
- A = 2D matrix containg shapelet basis function values
Generates basis function values using a lookup table method
Parameters: - n1s (array) – The first orders of the basis functions to generate
- n2s (array) – The second orders of the basis function to generate
- xrot (numpy array) – 1D array of the x-coords to generate the basis functions at
- yrot (numpy array) – 1D array of the y-coords to generate the basis functions at
- b1 (float) – The major axis beta scaling parameter (radians)
- b2 (float) – The minor axis beta scaling parameter (radians)
- convolve_kern (2D numpy array) – A kernel to convolve the basis functions with - if modelling a CLEANed image this should be the restoring beam
- shape (tuple) – The 2D shape of the image being modelled, needed if convolving with a kernel
Returns: - n1s (array) – The first orders of the basis functions to generate
- n2s (array) – The second orders of the basis function to generate
- A_shape_basis (2D array) – The generated 2D ‘A’ matrix
-
shapelets.gen_A_shape_matrix_direct(n1s=None, n2s=None, xrot=None, yrot=None, b1=None, b2=None, convolve_kern=False, shape=False)[source]¶ Generates the ‘A’ matrix in Ax = b when fitting shapelets, where:
- b = 1D matrix of data points to mode
- x = 1D matrix containing coefficients for basis functions
- A = 2D matrix containg shapelet basis function values
Generates the basis functions directly using scipy
Parameters: - n1s (array) – The first orders of the basis functions to generate
- n2s (array) – The second orders of the basis function to generate
- xrot (numpy array) – 1D array of the x-coords to generate the basis functions at
- yrot (numpy array) – 1D array of the y-coords to generate the basis functions at
- b1 (float) – The major axis beta scaling parameter (radians)
- b2 (float) – The minor axis beta scaling parameter (radians)
- convolve_kern (2D numpy array) – A kernel to convolve the basis functions with - if modelling a CLEANed image this should be the restoring beam
- shape (tuple) – The 2D shape of the image being modelled, needed if convolving with a kernel
Returns: - checked_n1s (array) – The first orders of the basis functions to generate - checks for any errors when generating the basis functions and omits those n1,n2 values
- checked_n2s (array) – The second orders of the basis function to generate - checks for any errors when generating the basis functions and omits those n1,n2 values
- A_shape_basis (2D array) – The generated 2D ‘A’ matrix
-
shapelets.gen_shape_basis(n1=None, n2=None, xrot=None, yrot=None, b1=None, b2=None, convolve_kern=False, shape=False)[source]¶ Generates the shapelet basis function for given n1,n2,b1,b2 parameters, using lookup tables and interpolation, at the given coords xrot,yrot. b1,b2 should be in radians.
Parameters: - n1 (int) – The first order of the basis function to generate
- n2 (int) – The second order of the basis function to generate
- xrot (numpy array) – 1D array of the x-coords to generate the basis functions at
- yrot (numpy array) – 1D array of the y-coords to generate the basis functions at
- b1 (float) – The major axis beta scaling parameter (radians)
- b2 (float) – The minor axis beta scaling parameter (radians)
- convolve_kern (2D numpy array) – A kernel to convolve the basis functions with - if modelling a CLEANed image this should be the restoring beam
- shape (tuple) – The 2D shape of the image being modelled, needed if convolving with a kernel
Returns: basis – A 1D array of the values of the basis function
Return type: numpy array
-
shapelets.gen_shape_basis_direct(n1=None, n2=None, xrot=None, yrot=None, b1=None, b2=None, convolve_kern=False, shape=False)[source]¶ Directly generates the shapelet basis function for given n1,n2,b1,b2 parameters, at the given coords xrot,yrot. b1,b2 should be in radians. Uses scipy to generate factorials and hermite polynomials
Parameters: - n1 (int) – The first order of the basis function to generate
- n2 (int) – The second order of the basis function to generate
- xrot (numpy array) – 1D array of the x-coords to generate the basis functions at
- yrot (numpy array) – 1D array of the y-coords to generate the basis functions at
- b1 (float) – The major axis beta scaling parameter (radians)
- b2 (float) – The minor axis beta scaling parameter (radians)
- convolve_kern (2D numpy array) – A kernel to convolve the basis functions with - if modelling a CLEANed image this should be the restoring beam
- shape (tuple) – The 2D shape of the image being modelled, needed if convolving with a kernel
Returns: basis – A 1D array of the values of the basis function
Return type: numpy array
-
shapelets.interp_basis(xrot=None, yrot=None, n1=None, n2=None)[source]¶ Uses basis lookup tables to generate 2D shapelet basis function for given xrot, yrot coords and n1,n2 orders. Does NOT include the b1,b2 normalisation, this is applied by the function gen_shape_basis
Parameters: - n1 (int) – The first order of the basis function to generate
- n2 (int) – The second order of the basis function to generate
- xrot (numpy array) – 1D array of the x-coords to generate the basis functions at
- yrot (numpy array) – 1D array of the y-coords to generate the basis functions at
Returns: basis – A 1D array of the values of the basis function
Return type: numpy array