galfitools.sim package¶
Submodules¶
galfitools.sim.MakeSim module¶
galfitools.sim.create_galfit_mocks module¶
Create mock galaxy images from a GALFIT model and residual image.
- galfitools.sim.create_galfit_mocks.clean_extension_header(header: Header) Header[source]¶
Convert an image-extension header into a primary-HDU-compatible header.
- galfitools.sim.create_galfit_mocks.create_mock_images(galfit_file: Path, output_directory: Path, number: int, prefix: str | None = None, seed: int | None = None, rotate: bool = True, reflect: bool = True) list[Path][source]¶
Create mock galaxy images from a GALFIT output cube.
- galfitools.sim.create_galfit_mocks.parse_arguments() Namespace[source]¶
Parse command-line arguments.
- galfitools.sim.create_galfit_mocks.transform_residual(residual: ndarray, rng: Generator, rotate: bool = True, reflect: bool = True) tuple[ndarray, int, int, int, bool][source]¶
Randomly transform and circularly shift a residual image.
Circular shifts preserve the residual pixel values and much of the spatially correlated noise structure.
galfitools.sim.create_galfit_sky_mocks module¶
Create GALFIT mock images using sky blocks and an optional sigma image.
The GALFIT output file is assumed to contain, by default:
HDU 1: original galaxy image HDU 2: GALFIT model image
Sky-only pixels are selected with DS9 physical or image box regions.
The script constructs a full-size correlated sky realization by resampling
square blocks from those regions and adds it to the GALFIT model.
When --sigma-image is supplied, the sigma map is interpreted as the total
per-pixel uncertainty. The script estimates the sky RMS from the selected sky
boxes and adds only the remaining variance:
sigma_extra^2 = max(sigma_total^2 - sigma_sky^2, 0)
Thus, the mock image is approximately:
mock = model + correlated_sky + Gaussian(0, sigma_extra)
Without --sigma-image, the behavior is unchanged:
mock = model + correlated_sky
- galfitools.sim.create_galfit_sky_mocks.box_vertices(x_center: float, y_center: float, width: float, height: float, angle_degrees: float) ndarray[source]¶
Return the four vertices of a DS9 box.
- galfitools.sim.create_galfit_sky_mocks.clean_extension_header(header: Header) Header[source]¶
Return a primary-HDU-compatible copy of an extension header.
- galfitools.sim.create_galfit_sky_mocks.compute_extra_sigma_map(total_sigma: ndarray, valid_sigma: ndarray, sky_rms: float) tuple[ndarray, int, int][source]¶
Compute the non-sky sigma after subtracting sky variance.
The calculation is
sigma_extra = sqrt(max(sigma_total**2 - sky_rms**2, 0)).
Invalid sigma-map pixels receive zero extra noise.
- galfitools.sim.create_galfit_sky_mocks.convert_noise_map_to_sigma(data: ndarray, kind: str) tuple[ndarray, ndarray][source]¶
Convert a sigma or inverse-variance image into a sigma map.
- Returns:
sigma_map – Sigma values. Invalid pixels are set to zero.
valid_mask – True where the original noise-map value was valid.
- galfitools.sim.create_galfit_sky_mocks.create_mock_images(galfit_file: Path, region_file: Path, output_directory: Path, number: int = 100, block_size: int = 16, image_extension: int = 1, model_extension: int = 2, prefix: str | None = None, seed: int | None = None, keep_sky_level: bool = False, transform_blocks: bool = False, save_sky: bool = True, sigma_image: Path | None = None, sigma_extension: int | None = None, sigma_kind: str = 'auto', sigma_max_factor: float = 100.0) list[Path][source]¶
Create mock images from a GALFIT model and sampled sky noise.
- galfitools.sim.create_galfit_sky_mocks.create_sky_realization(noise_source: ndarray, output_shape: tuple[int, int], block_size: int, y_origins: ndarray, x_origins: ndarray, rng: Generator, transform_blocks: bool = False) ndarray[source]¶
Fill an image using randomly sampled correlated-noise blocks.
- galfitools.sim.create_galfit_sky_mocks.estimate_sky_level(image: ndarray, sky_mask: ndarray, sigma: float = 3.0, maxiters: int = 5) tuple[float, float, int][source]¶
Estimate the sky level and RMS from sigma-clipped sky pixels.
- galfitools.sim.create_galfit_sky_mocks.find_valid_block_origins(valid_mask: ndarray, block_size: int) tuple[ndarray, ndarray][source]¶
Find top-left positions of square blocks fully inside valid pixels.
- galfitools.sim.create_galfit_sky_mocks.infer_noise_map_kind(filename: Path, header: Header) str[source]¶
Infer whether a noise map contains sigma or inverse variance.
- galfitools.sim.create_galfit_sky_mocks.load_2d_fits_image(filename: Path, extension: int | None = None) tuple[ndarray, Header, int][source]¶
Load a 2D FITS image from a specified HDU or the first 2D HDU.
- galfitools.sim.create_galfit_sky_mocks.mainGalfitSkyMock() None[source]¶
Run the command-line program.
- galfitools.sim.create_galfit_sky_mocks.parse_arguments() Namespace[source]¶
Parse command-line arguments.
- galfitools.sim.create_galfit_sky_mocks.parse_ds9_box_regions(region_file: Path) list[tuple[bool, str, ndarray]][source]¶
Read DS9 box regions in physical or image coordinates.
A minus sign before
boxmarks an excluded region. Examples:physical box(108,383.5,38,41,0) -box(108,383.5,5,5,0)
- galfitools.sim.create_galfit_sky_mocks.physical_to_image_coordinates(points: ndarray, header: Header) ndarray[source]¶
Convert DS9 physical coordinates to FITS image coordinates.
DS9 physical coordinates use the IRAF LTM/LTV linear transformation:
image = LTM @ physical + LTV
The returned coordinates remain in the one-based FITS/DS9 convention.
- galfitools.sim.create_galfit_sky_mocks.polygon_to_mask(vertices: ndarray, shape: tuple[int, int]) ndarray[source]¶
Rasterize a convex polygon using NumPy pixel-center coordinates.
- galfitools.sim.create_galfit_sky_mocks.read_region_mask(region_file: Path, shape: tuple[int, int], header: Header) ndarray[source]¶
Create a Boolean mask from DS9 physical or image box regions.