Skip to content

Target and Cutout

Once the image is open (see Opening an Image), BayMorph finds the target, cuts out a square around it and prepares the cutout for the fit.

The target

data.target_position is the centre of the galaxy to fit, in zero-based pixel coordinates of the full image, x along the columns and y along the rows, so that the pixel is image[y, x]; center uses the centre of the image. BayMorph detects the sources in the image and takes as the target the one that contains this position, or the nearest one when the position lies on no source.

The fit samples the centre of the galaxy, x0 and y0, within a window about this position: three times the FWHM of the PSF in a proposal of the observation advisor, 8 pixels by default. The window stays about the position you give, so that no prior is taken from the image it fits: give the centre of the galaxy, as a catalogue gives it, or click on its centre. Before it proposes or fits anything, BayMorph measures the centre of the detected target, from the moments of its light, and stops when that centre lies outside the window, with the distance and the remedy. A galaxy whose centre of light lies away from its catalogue position, such as a disturbed or blended system, needs wider priors of x0 and y0, declared in fit.priors. The summary of the observation advisor gives the measured centre and its distance from the position you gave.

The position from a catalogue can be given on the sky instead, to baymorph config with --target-ra and --target-dec, or to the advisor as target_position={"ra": 3.5237, "dec": -30.37241}: degrees in the ICRS, or texts with their units such as "00h14m05.69s". BayMorph converts it to pixels through the celestial WCS of the header and writes the pixels in the configuration. When the header carries SIP distortion terms without the -SIP suffix in its CTYPE, as some drizzled images do, the conversion leaves them out, as the SIP convention requires: drizzling has already corrected the distortion, and applying the terms would move the target by up to a few arcseconds. The header report says so in the note of the pixel scale.

The cutout

The fit does not see the whole image, only a square cutout around the target. The cutout must contain the whole galaxy and enough empty sky around it, where BayMorph measures the sky and the noise.

data:
  cutout:
    mode: fixed
    size: 251        # pixels

A square of size pixels centred on the target position. Choose it from the extent of the galaxy: the light of the galaxy must reach the sky well inside the cutout. BayMorph measures on the cutout the radius where the radial profile of the galaxy flattens into the sky, the plateau, and stops the preparation with an error when the plateau plus a margin of sky_margin pixels, 20 by default, does not fit inside it.

data:
  cutout:
    mode: auto
    sky_margin: 20   # pixels added beyond the edge of the galaxy

BayMorph cuts a large preliminary region, measures the radius where the radial profile of the galaxy flattens into the sky, the plateau, and cuts the plateau radius plus sky_margin pixels on each side. min_size and max_size bound the result. The plateau is then measured again on this cutout, and it can come out larger there. When the cutout cannot contain it and its margin, preparation stops with an error rather than fitting a galaxy that does not fit in its cutout; a fixed cutout is then the remedy.

The cutout, together with the mask, is the part of the image the likelihood uses. A different cutout is a different scientific problem: results from two cutouts are not directly comparable, and neither are their evidences.

Preparing the image

from baymorph import BayMorphRunner

runner = BayMorphRunner("configs/galaxy.yaml")
image = runner.prepare_image()

prepare_image() cuts out the target, detects and masks the other sources, subtracts the sky and measures the noise. It returns the prepared observation:

image.prepared_data.shape    # (251, 251): the cutout, sky subtracted
image.cutout_mode            # 'fixed'
image.cutout_bounds          # {'xmin': 375, 'xmax': 626, 'ymin': 375, 'ymax': 626}
image.target_x, image.target_y   # (125, 125): the target in the cutout
Attribute Content
prepared_data The cutout with the sky subtracted: the data of the fit.
cutout The same cutout before sky subtraction.
cutout_bounds Where the cutout lies in the full image.
fitting_mask True where a pixel is excluded from the fit; see Masks.
noise The noise scale of the sky in each pixel; see Sky and Noise.
background The sky level that was subtracted.
segmentation, target_segment, contaminant_mask The detected sources, the target, and the other sources that the contaminant rule masks.
sky_gradient The gradient of the sky across the cutout, a diagnostic.

Positions in the results, such as the fitted centre x0, y0, are in pixels of the cutout. Add cutout_bounds["xmin"] and cutout_bounds["ymin"] to place them in the full image.

To look at the prepared cutout:

from baymorph.plotting import plot_log_image

fig, ax = plot_log_image(image.prepared_data, title="Prepared cutout", show=True)

The products are also written to disk, under image_preparation/ in the run directory; a later run of the same configuration reuses them.