Mask

class Mask[source]

Class representing a mask image for astronomical data processing.

Inherits from DummyImage and provides methods for creating, combining, and managing various types of masks including source masks, bad pixel masks, and cosmic ray masks.

Parameters:
  • path (str or Path) – Path to the mask FITS image.

  • masktype (str, optional) – Type of mask (β€˜none’, β€˜invalid’, β€˜source’, β€˜badpixel’, β€˜cosmicray’, β€˜subtraction’).

  • status (Status, optional) – Initial status object. If not provided, status is loaded from file or initialized.

  • load (bool, optional) – Whether to load status and header upon initialization.

__init__(path, masktype='None', status=None, load=False)[source]

Methods

combine_mask(self, new_mask, operation='or')

Combine the current mask with a new mask.

Parameters:
  • new_mask (str or Path or np.ndarray) – Path to the new mask FITS image or numpy array.

  • operation (str, optional) – Operation to combine the current mask with the new mask.

show(self, cmap='gray', scale='zscale', downsample=4, figsize=(8, 6), title=None, save_path=False, close_fig=False)

Visualize the FITS image using slicing-based downsampling and scaling.

Parameters:
  • cmap (str, optional) – Matplotlib colormap. Default is β€˜gray’.

  • scale (str, optional) – Scaling method. Default is β€˜zscale’.

  • downsample (int, optional) – Step size for downsampling via slicing. Default is 4.

  • figsize (tuple, optional) – Matplotlib figure size. Default is (8, 6).

  • title (str, optional) – Plot title. Default is None.

  • save_path (str, optional) – Path to save the figure. Default is None.

  • close_fig (bool, optional) – If True, close the figure after saving. Default is False.

run_ds9(self)

Open the image with SAOImage DS9.

Parameters:

None

Return type:

None

load(self)

Load both image data and header from disk.

Parameters:

None

Return type:

None

write(self, compress=False, verbose=True)

Write MaskImage data to savepath.

Parameters:

None

Return type:

None

remove(self, remove_main=True, remove_connected_files=True, skip_patterns=[], verbose=True)
Return type:

dict

copy(self)

Return an in-memory deep copy of this Mask instance,

Parameters:

None

Returns:

copied_image – A deep copy of the Mask instance.

Return type:

Mask

rename(self, new_name, verbose=True)

Rename the image file and update the internal path.

Parameters:

new_name (str) – New name of the image file.

Return type:

None

clear(self, clear_data=True, clear_header=False, verbose=True)

Clear the image data and/or header from memory.

Parameters:
  • clear_data (bool, optional) – If True, clear the image data. Default is True.

  • clear_header (bool, optional) – If True, clear the image header. Default is False.

Additional Methods

update_header(self, **kwargs)

Update FITS header values using known key variants.

Parameters:

kwargs (dict) – Keyword arguments to update the FITS header.

Return type:

None

load_status(self)

Load processing status from a JSON file.

Parameters:

None

Returns:

status – Status object loaded from the JSON file.

Return type:

Status

save_status(self)

Save processing status to a JSON file.

Parameters:

None

Return type:

None

add_status(self, event_name, **event_details)

Add a status event to the mask.

Parameters:
  • event_name (str) – Name of the event to add.

  • event_details (dict) – Details of the event to add.

save_info(self)

Save processing info to JSON file.

Parameters:

None

Return type:

None

Properties

Key Properties

Property

Description

available_telescope_keys

Return a list of available telescope keys.

center

Center pixel (0-based) and its world coordinates (RA, Dec).

connected_files

Return all associated files that would be deleted in remove() if remove_connected_files=True,

data

Image data array.

egain

Electron gain of the image.

exptime

Exposure time of the image.

fovx

Field of view along the first axis.

fovy

Field of view along the second axis.

header

FITS header object.

info

Information instance of the mask. Info is defined in Info class.

is_data_loaded

Check if the image data is loaded.

is_exists

Check if the image file exists.

is_header_loaded

Check if the image header is loaded.

is_saved

Check if the image has been saved

naxis1

Number of pixels along the first axis.

naxis2

Number of pixels along the second axis.

pixelscale

Pixel scale of the image.

savedir

Return the directory where this image and associated files will be saved.

savepath

Dynamically builds save paths based on current header info

target_img

Target image of the mask. If not exists, return None.

wcs

WCS information of the image.