galmex.Utils_module module
- galmex.Utils_module.extract_cutouts(image, segmask, expansion_factor=1.5, estimate_noise=False)[source]
Extract square cutouts of the image and segmentation mask centered on the galaxy. Optionally, extract a noise image of the same shape from a clean corner.
Parameters: - image: 2D numpy array (galaxy image) - segmask: 2D numpy array (same shape), segmentation mask (galaxy pixels = 1) - expansion_factor: float, multiplier for bounding box size - estimate_noise: bool, if True, also returns a noise image from the corners
Returns: - image_cutout: 2D numpy array - segmask_cutout: 2D numpy array - cutout_coords: (y_min, y_max, x_min, x_max) - noise_image (optional): 2D numpy array (same shape as cutouts) - used_corner (optional): string indicating which corner was used for noise
- galmex.Utils_module.get_files_with_format(folder_path, file_extension)[source]
Gets all files in a folder with the specified file extension.
Parameters:
- folder_pathstr
Path to the folder to search.
- file_extensionstr
File extension to filter by (e.g., “.fits”).
Returns:
- list
A list of file paths with the specified file extension.
Raises:
- ValueError
If no files with the specified extension are found in the folder.
- galmex.Utils_module.open_fits_image(file_path)[source]
Opens a FITS file and returns its image data and header.
Parameters:
- file_pathstr
Path to the FITS file.
Returns:
- tuple
A tuple containing the image data and the header. If the file cannot be opened or lacks data, returns (None, None).
- galmex.Utils_module.recenter_image(image, x, y, final_size=None)[source]
Recenters the image around the coordinates (xm, ym) and returns a square image with odd size.
Parameters: - image: 2D numpy array. - xm, ym: floats or ints. Coordinates to be the new center (in image coordinates). - final_size: optional. Final size of the image. If None, will be the largest odd size possible
that fits in the image given (xm, ym) as center.
Returns: - centered_image: 2D numpy array cropped and centered at (xm, ym).
- galmex.Utils_module.remove_central_region(image, remove_radius, xc, yc)[source]
Removes a circular region centered at
(xc, yc)from a segmentation image.Parameters:
- imagenp.ndarray
The segmentation image. remove_radius : float Radius of the circular region, in pixels, that will be set to zero.
- xc, ycfloat
Coordinates of the center of the region to remove.
Returns:
- image_segmentednp.ndarray
The updated segmentation image with the central region removed.
- galmex.Utils_module.vary_galaxy_image(image, sigma_bkg=None, num_realizations=100)[source]
Generates multiple realizations of an image with Poisson noise (photon noise) and Gaussian background noise.
Parameters: - image (ndarray): Background-subtracted galaxy image. - sigma_bkg (float): Standard deviation of the background noise. - num_realizations (int): Number of noise realizations to generate.
Returns: - noisy_images (ndarray): Stack of noisy images with shape (num_realizations, H, W).