Skip to content

Trainingset_utils

Adrien Anthore edited this page Mar 12, 2024 · 8 revisions

make_cat.py

fill_im_hole(image)
Fill the NaN values inside an image with the median value of the image.
If the image is full of NaN, fill the image with 0 only.

  Args:
  
		* image (ndarray(dtype=float)): A 2D array of flux/beam values.

  Returns:
  
		* fill_image (ndarray(dtype=float)): A 2D array with NaN values replaced by
						`the overall background signal.

patch_gen(image, wcs, patch_size=512, patch_shift=480, orig_offset=60)
Divide an image from a fits file into patches with respect to its wcs.

Args:

	* image (ndarray(dtype=float)): The image from the fits file.
 
	* wcs (astropy object wcs): The wcs corresponding to the fits header.
 
	* patch_size (int, optional, default=512): Size of the image patches to be generated.
 
	* patch_shift (int, optional, default=480): Amount to shift each patch by.
 
	* orig_offset (int, optional, default=60): Offset to the original image.

Returns:

	* patches (list[astropy object Cutout2D]): List of patches, each element is an
						astropy object from which you can get attributes
						such as data (patches[i].data)
						or wcs (patches[i].wcs).

crea_dendrogram(fits_file, delta, promt=False)
Generate dendrograms and catalogs from a FITS file using the AstroDendro package.
    
Args:

	* fits_file (str): Path to the FITS file.

	* params (tuple): Tuple containing parameters for dendrogram computation:
		- res (float): Resolution of the instrument.
		- delta (float): Parameter from the AstroDendro package. Step between iterations of the detection.
		- R1 (float): Parameter for cleaning the catalog.
		- P1 (float): Parameter for cleaning the catalog.
		- R2 (float): Parameter for cleaning the catalog.
		- P2 (float): Parameter for cleaning the catalog.

	* p (int, optional): Percentile value for minimum pixel value taken for detection. The default is 85.

Returns:

	* None.


coor_cat.py

Rexcl(flux, P1, R1, P2, R2)
Rejection radius function:
Around bright sources, we often find artifacts due to interferometry.
To reject those artifacts, we defined a radius that is a function of
the integrated flux of the source studied. As the extent of the artifacts
seems to scale very fast with the integrated flux, we chose an exponential
law which is parameterized by typical integrated flux values "P" (low and high)
with their expected rejection radius "R". The parameters P and R are
chosen from guesses by analyzing the fields studied.

Args:

	* flux (float): Integrated flux value for which the rejection radius is calculated.
 
	* P1 (float): Typical low integrated flux (sources with no artifacts).
 
	* R1 (float): Typical exclusion radius for the low integrated flux.
 
	* P2 (float): Typical high integrated flux (sources with a lot of artifacts).
 
	* R2 (float): Typical exclusion radius for high integrated flux sources.

Returns:

	* float: Rejection radius calculated based on the input parameters.

clean_cat(name_file, res, R1, P1, R2, P2, survey)
Clean the catalog by removing overlapping sources, detected artifacts, and sources with low significance.
All the removed sources are returned and to be tested with IR/optical counterparts.

Args:

	* data (numpy.ndarray): Array containing catalog data, with columns representing:
		- Column 0: Right Ascension (RA) in degrees
		- Column 1: Declination (DEC) in degrees
		- Column 2: Flux of the source
		- Column 3: Surface flux density
		- Column 4: Major axis of the source
		- Column 5: Minor axis of the source
		- Column 6: Position angle of the source

	* min_val (float): Minimum pixel value for detection.

	* res (float): Resolution of the instrument.

	* R1 (float): Parameter for cleaning the catalog.

	* P1 (float): Parameter for cleaning the catalog.

	* R2 (float): Parameter for cleaning the catalog.

	* P2 (float): Parameter for cleaning the catalog.


Returns:

	* final_data (numpy.ndarray): Cleaned catalog data containing sources.

	* final_ttsc (numpy.ndarray): Excluded sources to be matched with optical/IR counterparts.

check_overlap(file1, file2)
Check if two FITS files have spatial overlap.

Args:

	* file1 (str): File path of the first FITS file.
 
	* file2 (str): File path of the second FITS file.

Returns:

	* bool: True if the two files have spatial overlap, False otherwise.

This function checks whether two FITS files have spatial overlap. It computes
the diagonal distance of the images and compares it with the separation between
their central coordinates. If the separation is less than or equal to the diagonal
distance, it indicates that the images overlap.

get_overlap_sources(cat, field_fits)
Extract sources from a catalog that overlap and do not overlap with a field.

Args:

	* cat (numpy.ndarray): Input catalog containing source positions.
 
	* field_fits (str): File path of the FITS file representing the field.

Returns:

	* tuple: Two numpy arrays - the first containing sources that overlap with the field,
		and the second contains sources that do not overlap.

This function extracts sources from a catalog based on whether they overlap with
a specified field represented by a FITS file. It calculates the diagonal distance
of the field and compares it with the separation between the center of the field
and the positions of sources in the catalog.

clean_overlap(data, res, R1, P1, R2, P2, survey)
Clean a catalog by removing multiple detections and excluding artifacts
around bright sources based on spatial overlap.
This function has the same process as "clean_cat" but is 
specific for the case when we clean overlapping regions.
The expected data in output is typically the output "cat_overlaped"
from the function "get_overlap_sources".

Args:

	* data (numpy.ndarray): Input catalog containing source information.
 
	* res (float): Resolution of the instrument.
 
	* R1 (float): Parameter R1 for rejection radius calculation.
 
	* P1 (float): Parameter P1 for rejection radius calculation.
 
	* R2 (float): Parameter R2 for rejection radius calculation.
 
	* P2 (float): Parameter P2 for rejection radius calculation.
 
	* survey (str): Name of the survey.

Returns:

	* numpy.ndarray: Cleaned catalog containing sources that pass the cleaning criteria.

third_NMS(cat, reject, col=2)
Perform third non-maximum suppression (NMS) on the catalog to remove nearby duplicate sources.

Args:

	* cat (numpy.ndarray): Array containing catalog data.

	* reject (float): Threshold distance to reject nearby sources, in arcseconds.

	* col (int, optional): Index of the column representing the significance of sources. The default is 2.
				If col=-1, don't sort the catalog.


Returns:

	* numpy.ndarray: Catalog data after third NMS.


CrossMatch.py

match_coord(cat2cross, refcoord, sep)
Perform coordinate matching between two catalogs.

Args:

	* cat2cross (numpy.ndarray): Catalog to cross-match.
 
	* refcoord (numpy.ndarray): Reference catalog for cross-matching.
 
	* sep (float): Separation threshold for matching in radians.

Returns:

	* Tuple[numpy.ndarray, numpy.ndarray]: Matched indices in 'cat2cross' and corresponding indices in 'refcoord'.

This function performs coordinate matching between two catalogs using the Haversine formula.
It compares the celestial coordinates of sources in 'cat2cross' with the coordinates in 'refcoord'.
If the separation between a source in 'cat2cross' and any source in 'refcoord' is within the specified
separation threshold ('sep'), the indices of the matched sources in 'cat2cross' and 'refcoord' are returned.

NN_Xmatch(cat_test, cat_ref, maxsep, colRA_test, colDec_test, colRA_ref, colDec_ref, sort_test_by="")
Perform nearest-neighbor cross-matching between two catalogs.

Args:

	* cat_test (astropy.table.Table): Catalog to be tested.
 
	* cat_ref (astropy.table.Table): Reference catalog for cross-matching.
 
	* maxsep (Quantity): Maximum separation allowed for matching. (dimension of an angle)
 
	* colRA_test (str): Column name containing Right Ascension in the catalog to be tested.
 
	* colDec_test (str): Column name containing Declination in the catalog to be tested.
 
	* colRA_ref (str): Column name containing Right Ascension in the reference catalog.
 
	* colDec_ref (str): Column name containing Declination in the reference catalog.
 
	* sort_test_by (str, optional): Column name for sorting the catalog to be tested. Defaults to "".

Returns:

	* Tuple[astropy.table.Table, astropy.table.Table]: Matched sub-catalogs from the test and reference catalogs.

This function performs nearest-neighbor cross-matching between a catalog and a reference catalog.
The catalogs are assumed to be Astropy Tables, and the matching is done based on Right Ascension (RA) and Declination (Dec).
The 'maxsep' parameter specifies the maximum separation allowed for a match.

Clone this wiki locally