astrophot.utils.initialize package#

Submodules#

astrophot.utils.initialize.center module#

astrophot.utils.initialize.center.GaussianDensity_Peak(center, image, window=10, std=0.5)[source]#
astrophot.utils.initialize.center.Lanczos_peak(center, image, Lanczos_scale=3)[source]#
astrophot.utils.initialize.center.center_of_mass(center, image, window=None)[source]#

Iterative light weighted center of mass optimization. Each step determines the light weighted center of mass within a small window. The new center is used to create a new window. This continues until the center no longer updates or an image boundary is reached.

astrophot.utils.initialize.construct_psf module#

astrophot.utils.initialize.construct_psf.construct_psf(stars, image, sky_est, size=51, mask=None, keep_init=False, Lanczos_scale=3)[source]#

Given a list of initial guesses for star center locations, finds the interpolated flux peak, re-centers the stars such that they are exactly on a pixel center, then median stacks the normalized stars to determine an average PSF.

Note that all coordinates in this function are pixel coordinates. That is, the image[0][0] pixel is at location (0,0) and the image[2][7] pixel is at location (2,7) in this coordinate system.

astrophot.utils.initialize.construct_psf.gaussian_psf(sigma, img_width, pixelscale, upsample=4)[source]#
astrophot.utils.initialize.construct_psf.moffat_psf(n, Rd, img_width, pixelscale, upsample=4)[source]#

astrophot.utils.initialize.initialize module#

astrophot.utils.initialize.initialize.isophotes(image, center, threshold=None, pa=None, q=None, R=None, n_isophotes=3, more=False)[source]#

Method for quickly extracting a small number of elliptical isophotes for the sake of initializing other models.

astrophot.utils.initialize.segmentation_map module#

astrophot.utils.initialize.segmentation_map.PA_from_segmentation_map(seg_map: ndarray | str, image: ndarray | str, centroids=None, hdul_index_seg: int = 0, hdul_index_img: int = 0, skip_index: tuple = (0,), north=1.5707963267948966)[source]#
astrophot.utils.initialize.segmentation_map.centroids_from_segmentation_map(seg_map: ndarray | str, image: ndarray | str, hdul_index_seg: int = 0, hdul_index_img: int = 0, skip_index: tuple = (0,))[source]#

identify centroid centers for all segments in a segmentation map

For each segment in the map, computes a flux weighted centroid in pixel space. A dictionary of pixel centers is produced where the keys of the dictionary correspond to the segment id’s.

Parameters:#

seg_map (Union[np.ndarray, str]): A segmentation map which gives the object identity for each pixel image (Union[np.ndarray, str]): An Image which will be used in the light weighted center of mass calculation hdul_index_seg (int): If reading from a fits file this is the hdu list index at which the map is found. Default: 0 hdul_index_img (int): If reading from a fits file this is the hdu list index at which the image is found. Default: 0 skip_index (tuple): Lists which identities (if any) in the segmentation map should be ignored. Default (0,)

returns:

dictionary of centroid positions matched to each segment ID. The centroids are in pixel coordinates

rtype:

centroids (dict)

astrophot.utils.initialize.segmentation_map.filter_windows(windows, min_size=None, max_size=None, min_area=None, max_area=None, min_flux=None, max_flux=None, image=None)[source]#

Filter a set of windows based on a set of criteria.

Parameters:
  • min_size (minimum size of the window in pixels) –

  • max_size (maximum size of the window in pixels) –

  • min_area (minimum area of the window in pixels) –

  • max_area (maximum area of the window in pixels) –

  • min_flux (minimum flux of the window in ADU) –

  • max_flux (maximum flux of the window in ADU) –

  • image (the image from which the flux is calculated for min_flux and max_flux) –

astrophot.utils.initialize.segmentation_map.q_from_segmentation_map(seg_map: ndarray | str, image: ndarray | str, centroids=None, PAs=None, hdul_index_seg: int = 0, hdul_index_img: int = 0, skip_index: tuple = (0,), north=1.5707963267948966)[source]#
astrophot.utils.initialize.segmentation_map.scale_windows(windows, image_shape=None, expand_scale=1.0, expand_border=0.0)[source]#
astrophot.utils.initialize.segmentation_map.transfer_windows(windows, base_image, new_image)[source]#

Convert a set of windows from one image object to another. This will account for the relative adjustments in origin, pixelscale, and rotation between the two images.

Parameters:
  • windows (dict) – A dictionary of windows to be transferred. Each window is formatted as a list of lists with: window = [[xmin,xmax],[ymin,ymax]]

  • base_image (Image) – The image object from which the windows are being transferred.

  • new_image (Image) – The image object to which the windows are being transferred.

astrophot.utils.initialize.segmentation_map.windows_from_segmentation_map(seg_map, hdul_index=0, skip_index=(0,))[source]#

Convert a segmentation map into boinding boxes

Takes a segmentation map as input and uses the segmentation ids to determine bounding boxes for every object. Scales the bounding boxes according to given factors and returns the coordinates.

each window is formatted as a list of lists with: window = [[xmin,xmax],[ymin,ymax]]

expand_scale changes the base window by the given factor. expand_border is added afterwards on all sides (so an expand border of 1 will add 2 to the total width of the window.

Module contents#

astrophot.utils.initialize.GaussianDensity_Peak(center, image, window=10, std=0.5)[source]#
astrophot.utils.initialize.Lanczos_peak(center, image, Lanczos_scale=3)[source]#
astrophot.utils.initialize.PA_from_segmentation_map(seg_map: ndarray | str, image: ndarray | str, centroids=None, hdul_index_seg: int = 0, hdul_index_img: int = 0, skip_index: tuple = (0,), north=1.5707963267948966)[source]#
astrophot.utils.initialize.center_of_mass(center, image, window=None)[source]#

Iterative light weighted center of mass optimization. Each step determines the light weighted center of mass within a small window. The new center is used to create a new window. This continues until the center no longer updates or an image boundary is reached.

astrophot.utils.initialize.centroids_from_segmentation_map(seg_map: ndarray | str, image: ndarray | str, hdul_index_seg: int = 0, hdul_index_img: int = 0, skip_index: tuple = (0,))[source]#

identify centroid centers for all segments in a segmentation map

For each segment in the map, computes a flux weighted centroid in pixel space. A dictionary of pixel centers is produced where the keys of the dictionary correspond to the segment id’s.

Parameters:#

seg_map (Union[np.ndarray, str]): A segmentation map which gives the object identity for each pixel image (Union[np.ndarray, str]): An Image which will be used in the light weighted center of mass calculation hdul_index_seg (int): If reading from a fits file this is the hdu list index at which the map is found. Default: 0 hdul_index_img (int): If reading from a fits file this is the hdu list index at which the image is found. Default: 0 skip_index (tuple): Lists which identities (if any) in the segmentation map should be ignored. Default (0,)

returns:

dictionary of centroid positions matched to each segment ID. The centroids are in pixel coordinates

rtype:

centroids (dict)

astrophot.utils.initialize.construct_psf(stars, image, sky_est, size=51, mask=None, keep_init=False, Lanczos_scale=3)[source]#

Given a list of initial guesses for star center locations, finds the interpolated flux peak, re-centers the stars such that they are exactly on a pixel center, then median stacks the normalized stars to determine an average PSF.

Note that all coordinates in this function are pixel coordinates. That is, the image[0][0] pixel is at location (0,0) and the image[2][7] pixel is at location (2,7) in this coordinate system.

astrophot.utils.initialize.filter_windows(windows, min_size=None, max_size=None, min_area=None, max_area=None, min_flux=None, max_flux=None, image=None)[source]#

Filter a set of windows based on a set of criteria.

Parameters:
  • min_size (minimum size of the window in pixels) –

  • max_size (maximum size of the window in pixels) –

  • min_area (minimum area of the window in pixels) –

  • max_area (maximum area of the window in pixels) –

  • min_flux (minimum flux of the window in ADU) –

  • max_flux (maximum flux of the window in ADU) –

  • image (the image from which the flux is calculated for min_flux and max_flux) –

astrophot.utils.initialize.gaussian_psf(sigma, img_width, pixelscale, upsample=4)[source]#
astrophot.utils.initialize.isophotes(image, center, threshold=None, pa=None, q=None, R=None, n_isophotes=3, more=False)[source]#

Method for quickly extracting a small number of elliptical isophotes for the sake of initializing other models.

astrophot.utils.initialize.moffat_psf(n, Rd, img_width, pixelscale, upsample=4)[source]#
astrophot.utils.initialize.q_from_segmentation_map(seg_map: ndarray | str, image: ndarray | str, centroids=None, PAs=None, hdul_index_seg: int = 0, hdul_index_img: int = 0, skip_index: tuple = (0,), north=1.5707963267948966)[source]#
astrophot.utils.initialize.scale_windows(windows, image_shape=None, expand_scale=1.0, expand_border=0.0)[source]#
astrophot.utils.initialize.transfer_windows(windows, base_image, new_image)[source]#

Convert a set of windows from one image object to another. This will account for the relative adjustments in origin, pixelscale, and rotation between the two images.

Parameters:
  • windows (dict) – A dictionary of windows to be transferred. Each window is formatted as a list of lists with: window = [[xmin,xmax],[ymin,ymax]]

  • base_image (Image) – The image object from which the windows are being transferred.

  • new_image (Image) – The image object to which the windows are being transferred.

astrophot.utils.initialize.windows_from_segmentation_map(seg_map, hdul_index=0, skip_index=(0,))[source]#

Convert a segmentation map into boinding boxes

Takes a segmentation map as input and uses the segmentation ids to determine bounding boxes for every object. Scales the bounding boxes according to given factors and returns the coordinates.

each window is formatted as a list of lists with: window = [[xmin,xmax],[ymin,ymax]]

expand_scale changes the base window by the given factor. expand_border is added afterwards on all sides (so an expand border of 1 will add 2 to the total width of the window.