galight.tools package¶
Submodules¶
galight.tools.astro_tools module¶
Created on Mon Sep 7 14:32:21 2020
@author: Xuheng Ding
- galight.tools.astro_tools.plt_fits(img, norm='log', figsize=None, colorbar=False, savename=None, vmin=None, vmax=None, cmap='gist_heat', hold=False)[source]¶
Directly plot a 2D image using imshow.
- galight.tools.astro_tools.plt_many_fits(imgs, texts=None, prop=None, savename=None, labels=None, hide_axes=False, if_plot=True, cmap=None, label_size=17, norm=<matplotlib.colors.LogNorm object>)[source]¶
Plot many fits in a row
imgs: Input of a list of images to show texts: measured properties prop: name of the properties labels: string to show
A sth sth
galight.tools.cutout_tools module¶
Created on Fri Sep 4 15:12:15 2020
@author: Xuheng Ding
- galight.tools.cutout_tools.cut_center_auto(image, center, radius, kernel='center_bright', return_center=False, if_plot=False)[source]¶
Automaticlly cutout out a image, so that the central pixel is either the “center_bright” or “center_gaussian”.
- image:
Large frame 2D image data.
- center:
The center position to cutout.
- kernel: the way to define the central pixel, with choices:
-‘center_bright’: Cutout at the brightest pixel as center -‘center_gaussian’: Cutout at the Gaussian center
- radius:
The cutout box size.
- return_center:
If return the finally used center value.
- if_plot:
If plot the zoom in center of the cutout stamp.
Frame size shouldn’t be too larger that exceed the target’s frame otherwise the Gaussion fitting and the max pixel could miss targets.
A cutout image; (if return_center= True, a central pixel position used for the cutout would be returned)
- galight.tools.cutout_tools.cutout(image, center, radius)[source]¶
Cutout a stamp image from a large frame image.
- image:
Large frame 2D image data.
- center:
The center position to cutout.
- radius:
The cutout box size.
A cutout image stamp, frame size in odd number.
- galight.tools.cutout_tools.exp_grid(img, nums, drc)[source]¶
- expand the image frame with zero, with nums, direct to expand
- img:
2d array_like
- num:
number of pixels to input
- drc:
direction. 1: -x 2: -y 3: x 4: -y (i.e.: from -x, anticlockwise)
- galight.tools.cutout_tools.pix_region(center=[49.0, 49.0], radius=5, q=None, theta=None)[source]¶
Creat a region file, in pixel units.
- center:
The center of the region, with [reg_x, reg_y].
- radius:
The radius of the region.
A region which is ds9-like.
- galight.tools.cutout_tools.plot_overview(img, center_target=None, target_label=None, c_psf_list=None, label=None, ifsave=False, filename='filename', if_plot=True)[source]¶
Plot the overview of the image, highlight the location of the QSO and PSFs.
- img:
A FOV image.
- center_target:
The central position of the pixels of the QSO.
- c_psf_list:
A list of PSF positions.
- label:
Define label if want to lable this plot.
galight.tools.measure_tools module¶
Created on Mon Sep 7 14:38:27 2020
@author: Xuheng Ding
A group of function to measure the photometry.
- galight.tools.measure_tools.SB_profile(image, center, radius=35, start_p=1.5, grids=20, x_gridspace=None, if_plot=False, fits_plot=False, if_annuli=False, mask_image=None, q=None, theta=None)[source]¶
Derive the SB profile of one image start at the center.
- image:
2-D array image.
- center:
The center point of the profile.
- radius:
The radius of the profile favourable with default equals to 35.
- grids:
The number of points to sample the flux with default equals to 20.
- if_plot:
if plot the profile.
- fits_plot:
if plot the fits file with the regions.
- if_annuli:
if False: The overall surface brightness with a circle. True, return annuli surface brightness between i and i-1 cirle.
- mask_image:
if is not None, will use this image as mask.
A 1-D array of the SB value of each ‘grids’ in the profile with the sampled radius.
- galight.tools.measure_tools.cr_mask(image, filename='test_circle.reg')[source]¶
The creat a mask using a DS9 .reg file. The pixels in the region are 0, ouside ones are 1.
- image:
A 2D array image as a template frame.
- filename:
Full name of the region file.
A image.shape array. Pixels in the region is 0, otherwise 1.
- galight.tools.measure_tools.detect_obj(image, detect_tool='phot', exp_sz=1.2, if_plot=False, auto_sort_center=True, nsigma=2.8, npixels=15, contrast=0.001, nlevels=25, use_moments=True, thresh=2.8, err=None, mask=None, minarea=5, filter_kernel=None, filter_type='matched', deblend_nthresh=32, deblend_cont=0.005, clean=True, clean_param=1.0)[source]¶
Define the apeatures for all the objects in the image.
- img2-D array type image.
The input image
- exp_szfloat.
The level to expand the mask region.
- nsigmafloat.
The number of standard deviations per pixel above the
backgroundfor which to consider a pixel as possibly being part of a source.- npixels: int.
The number of connected pixels, each greater than
threshold, that an object must have to be detected.npixelsmust be a positive integer.- if_plot: bool.
If ture, plot the detection figure.
A list of photutils defined apeatures that cover the detected objects.
- galight.tools.measure_tools.esti_bgkstd(image, nsigma=2, exp_sz=1.5, npixels=15, if_plot=False)[source]¶
Estimate the value of the background rms, by first block all the light and measure empty regions.
- galight.tools.measure_tools.find_loc_max(image, neighborhood_size=8, threshold=5)[source]¶
Find all the local maximazation in a 2D array, used to search the targets such as QSOs and PSFs. This function is created and inspired based on:
- image:
2D array type image.
- neighborhood_size: digit.
Define the region size to filter the local minima.
- threshold: digit.
Define the significance (flux value) of the maximazation point. The lower, the more would be found.
A list of x and y of the searched local maximazations.
- galight.tools.measure_tools.fit_data_oneD_gaussian(data, ifplot=False)[source]¶
Fit data as 1D gaussion
- galight.tools.measure_tools.fit_data_twoD_Gaussian(data, popt_ini=None, if_plot=False)[source]¶
Fit the data as twoD_Gaussian() and return parameters
- data:
the data should be put in the center.
Parameters in twoD_Gaussian, i.e., amplitude, xo, yo, sigma_x, sigma_y, theta, offset
- galight.tools.measure_tools.flux_in_region(image, region, mode='exact')[source]¶
Measure the total flux inside a ‘region’.
- image:
2D array type image.
- region:
Region generated by pix_region.
- mode:
- define the mode to measure flux, setting including. Based on region.to_mask()
-‘exact’, -‘center’
default is ‘exact’.
Total flux value.
- galight.tools.measure_tools.flux_profile(image, center, radius=35, start_p=1.5, grids=20, x_gridspace=None, if_plot=False, fits_plot=False, mask_image=None, q=None, theta=None)[source]¶
Obtain the flux profile of a 2D image, region at the center position.
- image:
A 2-D array image.
- center:
Center point of the profile.
- radius:
The radius of the profile edge, default = 35.
- grids:
The Number of points to sample the flux, default = 20.
- if_plot:
If plot the profile.
- fits_plot:
If plot the fits file with the regions.
- mask_list:
A list of reg filenames used to generate a mask.
A 1-D array of the tot_flux value of each ‘grids’ in the profile sampled radius.
The grids of each pixel radius.
The region file for each radius.
- galight.tools.measure_tools.image_moments(image, sexseg, pflag, plot=False)[source]¶
Compute galaxy moments from galaxy pixels in [image]. The target galaxy’s flag in the segmentation image [sexseg] should be [pflag]. All other source flags are irrelevant. The sky pixel flag should be 0. The moments can be computed for all flagged sources in an image iteratively for each [pflag]. Returns dictionary of image moments.
References:
http://raphael.candelier.fr/?blog=Image%20Moments
Image Moments-based Structuring and Tracking of Objects. L. Rocha, L. Velho and P.C.P. Calvalho (2002). URL=http://sibgrapi.sid.inpe.br/col/sid.inpe.br/banon/2002/10.23.11.34/doc/35.pdf
- galight.tools.measure_tools.mask_obj(image, apertures, if_plot=False, sum_mask=False)[source]¶
Automaticlly generate a list of masked based on the input apertures.
- galight.tools.measure_tools.measure_FWHM(image, radius=10)[source]¶
Fit image as 2D gaussion to calculate the FWHM on four directions.
- image:
2D array type image.
- radius:
Define the distance (2*radius) to sample the pixel value and fit Gaussian.
FWHM on four different direcions, i.e., x, y, xy, -xy.
- galight.tools.measure_tools.measure_bkg(img, if_plot=False, nsigma=2, npixels=25, dilate_size=11)[source]¶
Estimate the 2D background of a image, based on photutils.Background2D, with SExtractorBackground. Checkout: https://photutils.readthedocs.io/en/stable/background.html
parameters (including nsigma, npixels and dilate_size) will be passed to photutils.make_source_mask()
A 2D array type of the background light.
- galight.tools.measure_tools.model_flux_cal(params_list, model_list=None, sersic_major_axis=None)[source]¶
Calculate the flux of a Sersic (i.e., itergral to infinite) which is same defination as Galfit.
- params_list:
a list of (Sersic) Soure params defined by Lenstronomy.
- model_list:
a list of names of light profile model.
The flux value of Sersic.
- galight.tools.measure_tools.plot_data_apertures(image, apertures, if_plot=True)[source]¶
Quickly make a image+aperture plot.
- galight.tools.measure_tools.plot_data_apertures_point(image, apertures, ps_center_list, savename=None, show_plot=True)[source]¶
Quickly make a image+aperture+PS plot.
- galight.tools.measure_tools.profiles_compare(prf_list, prf_name_list=None, x_gridspace=None, radius=6, grids=20, norm_pix=3, if_annuli=False, y_log=False, scale_list=None)[source]¶
Compare the SB profile between different images.
- prf_list:
a list of image profiles.
- prf_name_list:
a list of name for each profiles.
- norm_pix:
The x-position (i.e. pixel) to norm the profiles.
- scale_list:
a list for the scaled value for the resultion, default as scale as 1 (set by None), i.e. same resolution.
The plot of SB comparison.
- galight.tools.measure_tools.search_local_max(image, radius=120, view=False, **kwargs)[source]¶
Use ‘find_loc_max()’ to search all the maxs. The edges position with a lot of zeros would be excluded.
- image:
2D array type image.
- radius:
A radius used to test if any empty pixels around.
A list of positions of ‘PSF’
- galight.tools.measure_tools.sort_apertures(image, apertures)[source]¶
Automaticlly sort the apertures based on the positions related to the center.
- galight.tools.measure_tools.stack_PSF(data, psf_POS_list, psf_size=71, oversampling=1, maxiters=10, tool='photutils')[source]¶
- galight.tools.measure_tools.twoD_Gaussian(box_size, amplitude, xo, yo, sigma_x, sigma_y, theta, offset)[source]¶
Function to define a 2-D Gaussian
- amplitude:
amplitude of the 2D gaussian
- xo, yo:
x, y position
- sigma_x, sigma_y:
sigma on x, y
- theta:
orientation
- offset:
offset (baseline, i.e., background)
A 2-D gaussian profile, but use ravel to strech into 1D
galight.tools.plot_tools module¶
Created on Wed Sep 16 20:28:10 2020
@author: Xuheng Ding
- galight.tools.plot_tools.profile_plots(flux_list_2d, label_list_2d, flux_list_1d, label_list_1d, deltaPix=1.0, zp=27.0, target_ID='target_ID', mask_image=None, if_annuli=False, arrows=False, show_plot=True)[source]¶
Similar to total_compare(), i.e., to compare a list of light profiles but without showing normlized residual.
- galight.tools.plot_tools.scale_bar(ax, d, dist=7.692307692307692, text='1"', color='black', flipped=False, fontsize=15)[source]¶
- galight.tools.plot_tools.total_compare(flux_list_2d, label_list_2d, flux_list_1d, label_list_1d, deltaPix=1.0, zp=27.0, target_ID='target_ID', mask_image=None, if_annuli=False, arrows=False, show_plot=True, cmap=None)[source]¶
Make quick plots to compare the flux profiles in a list and show the normalized residual.
- flux_list_2d:
A list of 2D flux array, that will use plt.imshow() to plot and show. e.g., [data, pointsource_list, galaxy_model_list, normalized residual]
- label_list_2d:
A list of lables for flux_list_2d. e.g., [‘data’, ‘model’, ‘point source(s)’, ‘galaxy(s)’]
- flux_list_1d:
A list of 2D flux array, that will be plot as 1D profile in the very right panel.
- label_list_1d:
The labels for flux_list_1d.
- mask_image:
A 2D mask for the flux_list_2d image.
- arrows: bool.
If show the arrows for pointing the North and East.
- if_annuli: bool.
If True, the 1D profile will show the surface brightness in the annuli apertures.