source_extraction
- trap.source_extraction.rms(data: ndarray) ndarray[source]
Returns the RMS of the data about the median. :param data: a numpy array
- trap.source_extraction.subregion(data: ndarray, reduction_factor: float = 2) ndarray[source]
Take the center region of the data where the size of the center region is defined by reduction_factor.
- Parameters:
data (np.ndarray) – The image data to clip.
reduction_factor (float) – The factor by which to decrease the image. This applies to each axis, so if
reduction_factor=2and the image is of shape 100x100, then the shape of the clipped center region is 50x50. This effectively reduces the image size by a factor 4 (10.000 pixels to 2500 pixels). Ifreduction_factor=1, the original 100x100 pixels are returned. It is also possibly to supply a floating point number. For the same 100x100 image, if areduction_factor=1.5is supplied, the resulting slice is of shape (67,67). The way to make sense of this is that 100/1.5=66.6667.
Examples
>>> import numpy as np >>> data = np.array([ ... [0, 1, 2, 1, 0], ... [1, 2, 3, 2, 1], ... [2, 3, 4, 3, 2], ... [1, 2, 3, 2, 1], ... [0, 1, 2, 1, 0] ... ]) >>> subregion(data, 2) array([[2, 3, 2], [3, 4, 3], [2, 3, 2]])
- Returns:
numpy.ndarray
- Return type:
A slice of the original data at the center of the data.
- trap.source_extraction.clip(data: ndarray, sigma: float = 3) ndarray[source]
Remove all values above a threshold from the array. Uses iterative clipping at sigma value until nothing more is getting clipped.
- Parameters:
data (numpy.ndarray) – The data to clip
sigma (float) – The amount of standard deviations that determine the threshold for clipping
- Returns:
The data with the high values removed
- Return type:
np.ndarray
- trap.source_extraction.read_pyse_image(path: str, freq_bands: FrequencyBands | None = None, margin=0, radius=1500, back_size_x=50, back_size_y=50, reduction_factor_for_rms=4, rms_min=0, rms_max=1, force_beam=True, ew_sys_err=0, ns_sys_err=0, deblend_nthresh=0, **pyse_conf) Tuple[ImageData, dict, bool][source]
Read an image with PySE that can be used in functions like
sources_from_fits_pyse()andforce_fit(). Some basic image metadata is also read and calculated. The metadata fields are:- rms
The rms of the inner region of the image. The size of this inner region is determined by
reduction_factor_for_rms.
- rms_min
Lowest value of the RMS background map. Note that this is different from
rmswhich uses the center region of the image rather than a RMS background map.
- rms_max
Largest value of the RMS background map. Note that this is different from
rmswhich uses the center region of the image rather than a RMS background map.
- freq_eff
Effective frequency of the image in Hz. That is, the mean frequency of all the visibility data which comprises this image.
- freq_bw
The frequency bandwidth of this image in Hz.
- taustart_ts
Timestamp of the start of the observaion.
- url
Location of the image
- rb_smaj
The semi-major axis of the restoring beam, in degrees.
- rb_smin
The semi-minor axis of the restoring beam, in degrees.
- rb_pa
The position angle of the restoring beam (from north to east to the major axis), in degrees.
- centre_ra
The central right-ascention coordinate (J2000) (or pointing centre) of the region, in degrees.
- centre_dec
The central declination coordinate (J2000) (or pointing centre) of the region, in degrees.
- xtr_radius
The radius of the circular mask used for source extraction, in degrees.
The image is also checked for quality. The quality check involves a check for the values where the image is rejected if it has all nodta values (nan, inf, -inf) or if the
rmsis below therms_minor above therms_maxvalues. These min and max values are set in the input arguments.- Parameters:
fits_path (str) – The path to the .fits file containing the image of which the sources are to be extracted.
margin (int) – The margin in pixels from the edge of the image within which sources are ignored. This exclusion area combines with radius.
radius (int,) – The radius in pixels around the center of the image, outside of which sources are ignored. This exclusion area combines with margin.
back_size_x (int) – Widht of the background boxes as uses in SEP. See https://sep.readthedocs.io/en/v1.1.x/api/sep.Background.html#sep.Background
back_size_y (int) – Height of the background boxes as used in SEP. See https://sep.readthedocs.io/en/v1.1.x/api/sep.Background.html#sep.Background
reduction_factor_for_rms (float) – The reduction_factor passed to
subregion()used to slice the data at the center before calculating the rms.ew_sys_err (float) – Systematic errors in units of arcseconds which augment the sourcefinder-measured errors on source positions when performing source association. These variables refer to an absolute angular error along an east-west and north-south axis respectively. (NB Although these values are stored during the source-extraction process, they affect the source-association process.)
ns_sys_err (float) – Same as ew_sys_err but in perpendicular direction
- Returns: (sourcefinder.image.ImageData, dict, bool)
- A tuple containing:
A PySE image that can be used for source extraction
Metadata of the image
Whether the image is rejected or not
- trap.source_extraction.sources_from_fits_pyse(pyse_im: ImageData, *, rejected: bool = False, detection_threshold: float = 8, analysis_threshold: float = 3, deblend_nthresh: float = 0) DataFrame[source]
Extract sources from an image using PySE.
- Parameters:
pyse_im (sourcefinder.image.ImageData) – The pyse image as read using
read_pyse_image()detection_threshold (float) – The detection threshold, as a multiple of the RMS noise. At least one pixel in a source must exceed this value for it to be regarded as significant.
analysis_threshold (float) – Analysis threshold, as a multiple of the RMS noise. All the pixels within the island that exceed this will be used when fitting the source.
deblend_nthresh (int) – Number of subthresholds to use for deblending. Set to 0 to disable.
- Returns:
A dataframe where each row is an obtained source. The columns contain the attributes of the corces.
Column names with explenation:
- ra [deg]: float
Right ascension coordinate of the source
- dec [deg]: float
Declination coordinate of the source
- ra_fit_err [deg]: float
1-sigma error from the gaussian fit in right ascension. Note that for a source located towards the poles the ra_fit_err increases with absolute declination.
- dec_fit_err [deg]: float
1-sigma error from the gaussian fit in declination
peak_flux [Jy]: float peak_flux_err [Jy]: float int_flux [Jy]: float int_flux_err [Jy]: float significance_detection_level: float semimajor_axis [arcsec]: float semiminor_axis [arcsec]: float parallactic_angle [deg]: float ew_sys_err [arcsec]: float
Telescope dependent systematic error in east-west direction.
- ns_sys_err [arcsec]: float
Telescope dependent systematic error in north-south direction.
- error_radius [arcsec]: float
A pessimistic on-sky position error estimate in arcsec.
gaussian_fit: bool chisq: float reduced_chisq: float
- Return type:
pandas.DataFrame
- trap.source_extraction.force_fit(pyse_im: ImageData, positions: ndarray, ew_sys_err: float = 10, ns_sys_err: float = 10) Tuple[DataFrame, ndarray][source]
Fit the specified locations using PySE.
- Parameters:
pyse_im (sourcefinder.image.ImageData) – The pyse image as read using
read_pyse_image()positions (np.ndarray) – A numpy array with the positions of the sources to be force fitted in the form [[ra_1, dec_1], [ra_2, dec_2]]
[arcsec] (ns_sys_err) – Telescope dependent systematic error in east-west direction.
[arcsec] – Telescope dependent systematic error in north-south direction.
- Returns:
A dataframe with the force-fitted sources
- Return type:
pd.DataFrame