ScienceImageο
- class ScienceImage[source]ο
Class representing a science FITS image.
Inherits from BaseImage and includes extended support for tracking processing status, managing file paths, saving metadata, and handling associated files such as background maps, error maps, masks, and source catalogs.
- __init__(path, telinfo=None, status=None, load=True)[source]ο
Initialize a ScienceImage instance.
- Parameters:
path (str or Path) β Path to the science FITS image.
telinfo (dict, optional) β Telescope metadata dictionary.
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.
Methodsο
- show(self, coord_type='coord', cmap='gray', scale='zscale', downsample=4, figsize=(8, 6), title=None, save_path=False, close_fig=False)ο
Visualize the FITS image with optional WCS overlay and downsampling.
- run_ds9(self)ο
Open the image with SAOImage DS9.
- Parameters:
None
- Return type:
None
- show_position(self, x, y, coord_type='coord', radius_arcsec=None, a_arcsec=None, b_arcsec=None, theta_deg=None, aperture_linewidth=1.0, aperture_color='red', aperture_label='detected', downsample=4, zoom_radius_pixel=100, cmap='gray', scale='zscale', figsize=(6, 6), title=None, title_fontsize=18, ax=None, save_path=None)ο
Display a zoomed-in view around a given (x, y) or (RA, Dec) position.
- Parameters:
x (float) β X-coordinate (pixel or RA)
y (float) β Y-coordinate (pixel or Dec)
radius_arcsec (float, optional) β Radius of the circle in arcseconds. Default is None.
a_arcsec (float, optional) β Semi-major axis of the ellipse in arcseconds. Default is None.
b_arcsec (float, optional) β Semi-minor axis of the ellipse in arcseconds. Default is None.
theta_deg (float, optional) β Position angle of the ellipse in degrees. Default is None.
coord_type (str, optional) β βpixelβ or βcoordβ. Default is βpixelβ.
downsample (int, optional) β Step size for downsampling via slicing. Default is 4.
zoom_radius_pixel (int, optional) β Radius of the zoom-in region in pixels. Default is 100.
cmap (str, optional) β Matplotlib colormap. Default is βgrayβ.
scale (str, optional) β Scaling method. Default is βzscaleβ.
figsize (tuple, optional) β Matplotlib figure size. Default is (6, 6).
ax (matplotlib Axes object, optional) β If provided, the image will be plotted on this axis. Default is None.
save_path (str, optional) β Path to save the figure. Default is None.
title (bool, optional) β Whether to display the title. Default is True.
- calculate_invalidmask(self, threshold_invalid_connection=100000, save=False, verbose=True, visualize=True, save_fig=False)ο
Calculate the invalid mask for this ScienceImage. The invalid mask is a mask of pixels that are invalid (zero or nan value). If save is True, the invalid mask is saved. Then, you can load the invalid mask with self.invalidmask.
- Parameters:
threshold_invalid_connection (int) β The threshold for invalid connection.
save (bool) β If True, save the invalid mask.
verbose (bool) β If True, print verbose output.
visualize (bool) β If True, visualize the invalid mask.
save_fig (bool) β If True, save the figure of the invalid mask.
- Returns:
target_ivpmask β The invalid mask.
- Return type:
- calculate_sourcemask(self, target_srcmask=None, sigma=5.0, mask_radius_factor=3, saturation_level=50000, save=False, verbose=True, visualize=True, save_fig=False)ο
Calculate the source mask for this ScienceImage. The source mask is a mask of pixels that are sources. Detection is made with global background and background RMS map. If save is True, the source mask is saved. Then, you can load the source mask with self.sourcemask.
- Parameters:
target_srcmask (Mask) β The source mask.
sigma (float) β The sigma for the source detection.
mask_radius_factor (float) β The radius factor for the source detection.
saturation_level (float) β The saturation level for the source detection.
save (bool) β If True, save the source mask.
verbose (bool) β If True, print verbose output.
visualize (bool) β If True, visualize the source mask.
save_fig (bool) β If True, save the figure of the source mask.
- Returns:
target_sourcemask β The source mask.
- Return type:
- calculate_bkg(self, target_srcmask=None, target_ivpmask=None, is_2D_bkg=True, box_size=64, filter_size=3, correct_global_offset=True, save=False, verbose=True, visualize=True, save_fig=False)ο
Calculate the background map for this ScienceImage. The background map is a map of the background level of the image. If save is True, the background map is saved. Then, you can load the background map with self.bkgmap.
- Parameters:
target_srcmask (Mask) β The source mask.
target_ivpmask (Mask) β The invalid mask.
is_2D_bkg (bool) β If True, use 2D background estimation.
box_size (int) β The box size for the background estimation.
filter_size (int) β The filter size for the background estimation.
correct_global_offset (bool) β If True, correct the global offset of the background map.
save (bool) β If True, save the background map.
verbose (bool) β If True, print verbose output.
visualize (bool) β If True, visualize the background map.
save_fig (bool) β If True, save the figure of the background map.
- Returns:
target_bkg β The calculated background map.
- Return type:
- calculate_bkgrms(self, target_srcmask=None, target_ivpmask=None, box_size=64, filter_size=3, save=False, verbose=True, visualize=True, save_fig=False)ο
Calculate the background RMS map for this ScienceImage. The background RMS map is a map of the background RMS level of the image. If save is True, the background RMS map is saved. Then, you can load the background RMS map with self.bkgrms.
- Parameters:
target_srcmask (Mask) β The source mask.
target_ivpmask (Mask) β The invalid mask.
box_size (int) β The box size for the background RMS estimation.
filter_size (int) β The filter size for the background RMS estimation.
save (bool) β If True, save the background RMS map.
verbose (bool) β If True, print verbose output.
visualize (bool) β If True, visualize the background RMS map.
save_fig (bool) β If True, save the figure of the background RMS map.
- Returns:
target_bkgrms β The background RMS map.
- Return type:
- calculate_errormap(self, target_srcmask=None, target_ivpmask=None, box_size=64, filter_size=3, save=False, verbose=True, visualize=True, save_fig=False)ο
Calculate the source RMS map for this ScienceImage. The source RMS map is a map of the source RMS level of the image. If save is True, the source RMS map is saved. Then, you can load the source RMS map with self.sourcerms.
- Parameters:
target_srcmask (Mask) β The source mask.
target_ivpmask (Mask) β The invalid mask.
box_size (int) β The box size for the source RMS estimation.
filter_size (int) β The filter size for the source RMS estimation.
save (bool) β If True, save the source RMS map.
verbose (bool) β If True, print verbose output.
visualize (bool) β If True, visualize the source RMS map.
save_fig (bool) β If True, save the figure of the source RMS map.
- Returns:
target_sourcerms β The source RMS map.
- Return type:
- calculate_bkgrms_from_propagation(self, target_bkg=None, mbias=None, mdark=None, mflat=None, mflaterr=None, save=False, verbose=True, visualize=True, save_fig=False)ο
Calculate the background RMS map for this ScienceImage from the background map, bias frame, dark frame, and flat frame. The background RMS map is a map of the background RMS level of the image. If save is True, the background RMS map is saved. Then, you can load the background RMS map with self.bkgrms.
- Parameters:
target_srcmask (Mask) β The source mask.
target_ivpmask (Mask) β The invalid mask.
mbias (CalibrationImage) β The bias frame.
mdark (CalibrationImage) β The dark frame.
mflat (CalibrationImage) β The flat frame.
mflaterr (Errormap) β The flat error map.
save (bool) β If True, save the background RMS map.
verbose (bool) β If True, print verbose output.
visualize (bool) β If True, visualize the background RMS map.
save_fig (bool) β If True, save the figure of the background RMS map.
- Returns:
target_bkgrms β The background RMS map.
- Return type:
- calculate_errormap_from_propagation(self, mbias=None, mdark=None, mflat=None, mflaterr=None, save=False, verbose=True, visualize=True, save_fig=False)ο
Calculate the source RMS map for this ScienceImage from the background map, bias frame, dark frame, and flat frame. The source RMS map is a map of the source RMS level of the image. If save is True, the source RMS map is saved. Then, you can load the source RMS map with self.sourcerms.
- Parameters:
target_srcmask (Mask) β The source mask.
target_ivpmask (Mask) β The invalid mask.
mbias (CalibrationImage) β The bias frame.
mdark (CalibrationImage) β The dark frame.
mflat (CalibrationImage) β The flat frame.
mflaterr (Errormap) β The flat error map.
save (bool) β If True, save the source RMS map.
verbose (bool) β If True, print verbose output.
visualize (bool) β If True, visualize the source RMS map.
save_fig (bool) β If True, save the figure of the source RMS map.
- Returns:
target_sourcerms β The source RMS map.
- Return type:
- get_masterframe(self, imagetyp, max_days=10)ο
Get master frame from the image.
This method will search for the master frame in the master frame directory.
- Parameters:
imagetyp (str) β The type of image to get the master frame from. (BIAS, DARK, FLAT)
max_days (float, optional) β The maximum number of days to search for the master frame.
- Returns:
master_img (CalibrationImage) β The master frame image.
master_frames_tbl (Table) β Metadata of the master frame(s) found.
- get_referenceframe(self, telname=None, min_obsdate=None, max_obsdate=None, sort_key=['fraction', 'depth'], overlap_threshold=0.5, return_groups=True, group_overlap_threshold=0.8, verbose=True)ο
Get the reference frame from the target image.
- Parameters:
telname (str, optional) β The telescope name.
min_obsdate (Union[str, float, Time], optional) β The minimum observation date.
max_obsdate (Union[str, float, Time], optional) β The maximum observation date.
sort_key (Union[str, List[str]], optional) β The sort key.
overlap_threshold (float, optional) β The overlap threshold.
return_groups (bool, optional) β Whether to return the groups.
group_overlap_threshold (float, optional) β The group overlap threshold.
- Returns:
reference_img (ReferenceImage) β The reference image.
reference_frames (Table) β The metadata of the reference frames matched the criteria.
- query_referenceframe(self, save_path=None, verbose=True, n_processes=4)ο
Query the reference frame from the target image.
- Parameters:
save_path (str, optional) β The save path of the reference frame.
verbose (bool, optional) β The verbose flag.
n_processes (int, optional) β The number of processes.
- Returns:
reference_img β The reference image.
- Return type:
- load(self)ο
Load both image data and header from disk.
- Parameters:
None
- Return type:
None
- write(self, verbose=True)ο
Write ScienceImage 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 ScienceImage instance,
- Parameters:
None
- Returns:
copied_image β A deep copy of the ScienceImage instance.
- Return type:
- 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
- to_referenceimage(self)ο
Convert this ScienceImage to a ReferenceImage
- Parameters:
None
- Return type:
- 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
- update_status(self, process_name)ο
Mark a process as completed and update time
- Parameters:
process_name (str) β Name of the process to update.
- save_info(self)ο
Save processing info to a JSON file
- Parameters:
None
- Return type:
None
Propertiesο
Key Properties
Property |
Description |
|---|---|
|
Altitude of the telescope. |
|
Return a list of available telescope keys. |
|
Azimuth of the telescope. |
|
Path to the bias image. |
|
Binning of the image. |
|
Background map of the image. If not exists, return None. |
|
Background RMS map of the image. If not exists, return None. |
|
Type of the background image. |
|
Source catalog of the image. If not exists, return None. |
|
Name of the CCD. |
|
CCD temperature. |
|
Center pixel (0-based) and its world coordinates (RA, Dec). |
|
Return all associated files that would be deleted in remove() if remove_connected_files=True, |
|
Path to the dark image. |
|
Image data array. |
|
Declination of the target. |
|
Depth of the image. |
|
Electron gain of the image. |
|
Type of the emap image. |
|
Exposure time of the image. |
|
Filter name. |
|
Path to the flat image. |
|
Field of view along the first axis. |
|
Field of view along the second axis. |
|
Gain of the image. |
|
FITS header object. |
|
Type of the image. Among BIAS, DARK, FLAT, LIGHT, OBJECT, UNKNOWN. |
|
Information instance of the image. Info is defined in Info class. |
|
Invalid mask of the image. If not exists, return None. |
|
Whether the image data is loaded. |
|
Whether the image file exists. |
|
Whether the image header is loaded. |
|
Check if the image has been saved |
|
Julian date of the observation. |
|
Type of the mask image. |
|
Modified Julian date of the observation. |
|
Number of pixels along the first axis. |
|
Number of pixels along the second axis. |
|
Number of combined images. |
|
Object name. |
|
Observation date in UTC. |
|
Name of the observatory. |
|
Observation mode. |
|
Pixel scale of the image. |
|
Right ascension of the target. |
|
Reference catalog of the image. If not exists, return None. |
|
Return the directory where this image and associated files will be saved. |
|
Dynamically builds save paths based on current header info |
|
Seeing of the image. |
|
Source mask of the image. If not exists, return None. |
|
Spectroscopic mode. |
|
Name of the telescope. |
|
WCS information of the image. |
|
Zero point of the image. |
|
Zero point error of the image. |