muse_origin.gen_source_mask(source_id, ra, dec, lines, detection_cube, threshold, cont_sky, fwhm, out_dir, *, mask_size=25, seg_npixel=5, min_sky_npixels=100, fwhm_factor=2, verbose=False, unit_center=None, unit_size=None)[source]

Generate a mask for the source segmenting the detection cube.

This function generates a mask for a source by combining the masks of each of its lines. The mask of a line is created by segmenting the max image extracted from the detection cube around the line wavelength. For primary ORIGIN sources, the correlation cube should be used, for complementary sources, the STD cube should be used.

For each line, a disk with a diameter of the FWHM at the line position, multiplied by fwhm_factor, is added to the mask.

The sky mask of each source is computed by intersecting the reverse of the source mask and the continuum sky mask.

The size of the returned mask may be larger than the requested mask_size so that: - the source mask does not touch the edge of the mask - the number of sky pixels is at least min_sky_npixels

If that’s not possible, source_id is returned, else nothing is returned (i.e. None).

source_id: str or int

Source identifier used in file names.

ra, dec: float

Right Ascension and declination of the source (or pixel position if radec_is_xy is true). The mask will be centred on this position.

lines: astropy.table.Table

Table containing all the lines associated to the source. This table must contain these columns: - num_line: the identifier of the line (for verbose output) - ra, dec: the position of the line in degrees - z: the pixel position of the line in the wavelength axis - fwhm: the full with at half maximum of the line in pixels

detection_cube: mpdaf.obj.Cube

Cube the lines where detected in.

threshold: float

Threshold used for segmentation. Should be lower (e.g. 50%) than the threshold used for source detection.

cont_sky: mpdaf.obj.Image

Sky mask obtained from a segmentation of the continuum. Must be on the same spatial WCS as the detection cube. The pixels must have a value of 1 at the sky positions, 0 otherwise.

fwhm: numpy array of floats

Value of the spatial FWHM in pixels at each wavelength of the detection cube.

out_dir: string

Name of the output directory to create the masks in.

mask_size: int

Minimal size in pixels of the (square) masks.

seg_npixel: int

Minimum number of pixels used by photutils for the segmentation.

min_sky_npixels: int

Minimum number of sky pixels in the mask.

fwhm_factor: float

Factor applied to the FWHM when adding a disk at the line position.

verbose: true

If true, the correlation map and the segmentation map images associated to each line will also be saved in the output directory.