diff --git a/doc/src/conf.py b/doc/src/conf.py index 3bd3b2b1..37c31cd9 100644 --- a/doc/src/conf.py +++ b/doc/src/conf.py @@ -40,6 +40,7 @@ "sphinx_rtd_theme", "myst_parser", "sphinx.ext.githubpages", + "sphinx.ext.napoleon", ] source_suffix = { diff --git a/doc/src/index.rst b/doc/src/index.rst index efa0d4f3..032abe58 100644 --- a/doc/src/index.rst +++ b/doc/src/index.rst @@ -33,7 +33,7 @@ Modules main_features/base_imaging.rst main_features/oskar_imaging.rst main_features/rascil_imaging.rst - + main_features/wsclean_imaging.rst .. toctree:: :maxdepth: 2 diff --git a/doc/src/main_features/oskar_imaging.rst b/doc/src/main_features/oskar_imaging.rst index 64e95044..aa30cc6d 100644 --- a/doc/src/main_features/oskar_imaging.rst +++ b/doc/src/main_features/oskar_imaging.rst @@ -1,9 +1,9 @@ karabo.imaging.imager_oskar -================= +=========================== Overview ------------ -This package summerizes tools and functions to be used with the imager +This package summarizes tools and functions to be used with the imager from the OSKAR backend. This backend does not offer functionality to calculate a cleaned image. You must use RASCIL or WSClean. diff --git a/doc/src/main_features/wsclean_imaging.rst b/doc/src/main_features/wsclean_imaging.rst new file mode 100644 index 00000000..41050435 --- /dev/null +++ b/doc/src/main_features/wsclean_imaging.rst @@ -0,0 +1,34 @@ +karabo.imaging.imager_wsclean +============================= + +Overview +------------ +This package summarizes tools and functions to be used with the imager +based on the WSClean algorithm. + + +Classes +------- + +.. autoclass:: karabo.imaging.imager_wsclean.WscleanDirtyImager + :members: + :special-members: __init__ + :exclude-members: + + +.. autoclass:: karabo.imaging.imager_wsclean.WscleanImageCleanerConfig + :members: + :special-members: __init__ + :exclude-members: + + +.. autoclass:: karabo.imaging.imager_wsclean.WscleanImageCleaner + :members: + :special-members: __init__ + :exclude-members: + + +Functions +--------- + +.. autofunction:: karabo.imaging.imager_wsclean.create_image_custom_command \ No newline at end of file diff --git a/karabo/imaging/image.py b/karabo/imaging/image.py index ed0b8a84..d2718977 100644 --- a/karabo/imaging/image.py +++ b/karabo/imaging/image.py @@ -145,7 +145,13 @@ def write_to_file( path: FilePathType, overwrite: bool = False, ) -> None: - """Write an `Image` to `path` as .fits""" + """Write an `Image` to `path` as .fits + + Args: + path: Full path of the file + overwrite: Overwrite the file if it already exists? Defaults to False + + """ assert_valid_ending(path=path, ending=".fits") dir_name = os.path.abspath(os.path.dirname(path)) os.makedirs(dir_name, exist_ok=True) @@ -178,8 +184,9 @@ def resample( for bilinear interpolation. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.RegularGridInterpolator.html - :param shape: The desired shape of the image - :param kwargs: Keyword arguments for the interpolation function + Args: + shape: The desired shape of the image + kwargs: Keyword arguments for the interpolation function """ new_data = np.empty( @@ -221,9 +228,13 @@ def cutout( """ Cutout the image to the given size and center. - :param center_xy: Center of the cutout in pixel coordinates - :param size_xy: Size of the cutout in pixel coordinates - :return: Cutout of the image + Args: + center_xy: Center of the cutout in pixel coordinates + size_xy: Size of the cutout in pixel coordinates + + Returns: + Image: Cutout of the image + """ cut = Cutout2D( self.data[0, 0, :, :], @@ -241,7 +252,9 @@ def circle(self) -> None: at the center of the image. This is an in-place transformation of the data. - :return: None (data of current Image instance is transformed in-place) + Returns: + None (data of current Image instance is transformed in-place) + """ def circle_pixels(pixels: NDArray[np.float_]) -> NDArray[np.float_]: @@ -289,48 +302,45 @@ def split_image(self, N: int, overlap: int = 0) -> List[Image]: """ Split the image into N x N equal-sized sections with optional overlap. - Parameters - ---------- - N : int - The number of sections to split the image into along one axis. The - total number of image sections will be N^2. - It is assumed that the image can be divided into N equal parts along - both axes. If this is not the case (e.g., image size is not a - multiple of N), the sections on the edges will have fewer pixels. - - overlap : int, optional - The number of pixels by which adjacent image sections will overlap. - Default is 0, meaning no overlap. Negative overlap means that there - will be empty sections between the cutouts. - - Returns - ------- - cutouts : list - A list of cutout sections of the image. Each element in the list is - a 2D array representing a section of the image. - - Notes - ----- - The function calculates the step size for both the x and y dimensions - by dividing the dimension size by N. It then iterates over N steps - in both dimensions to generate starting and ending indices for each - cutout section, taking the overlap into account. - - The `cutout` function (not shown) is assumed to take the center - (x, y) coordinates and the (width, height) of the desired cutout - section and return the corresponding 2D array from the image. - - The edge sections will be equal to or smaller than the sections in - the center of the image if the image size is not an exact multiple of N. - - Examples - -------- - >>> # Assuming `self.data` is a 4D array with shape (C, Z, X, Y) - >>> # and `self.cutout` method is defined - >>> image = Image() - >>> cutouts = image.split_image(4, overlap=10) - >>> len(cutouts) - 16 # because 4x4 grid + Args: + N (int): The number of sections to split the image into along + one axis. The total number of image sections will be N^2. + It is assumed that the image can be divided into N equal parts + along both axes. If this is not the case (e.g., image size is + not a multiple of N), the sections on the edges will have + fewer pixels. + + overlap (int, optional): The number of pixels by which adjacent + image sections will overlap. Default is 0, meaning no overlap. + Negative overlap means that there will be empty sections between + the cutouts. + + Returns: + List[Image]: A list of cutout sections of the image. Each element in\ + the list is a 2D array representing a section of the image. + + Notes: + The function calculates the step size for both the x and y dimensions + by dividing the dimension size by N. It then iterates over N steps + in both dimensions to generate starting and ending indices for each + cutout section, taking the overlap into account. + + The `cutout` function (not shown) is assumed to take the center + (x, y) coordinates and the (width, height) of the desired cutout + section and return the corresponding 2D array from the image. + + The edge sections will be equal to or smaller than the sections in + the center of the image if the image size is not an exact multiple of N. + + Examples: + + >>> # Assuming `self.data` is a 4D array with shape (C, Z, X, Y) + >>> # and `self.cutout` method is defined + >>> image = Image() + >>> cutouts = image.split_image(4, overlap=10) + >>> len(cutouts) + 16 # because 4x4 grid + """ if N < 1: raise ValueError("N must be >= 1") @@ -382,23 +392,25 @@ def plot( ) -> None: """Plots the image - :param title: the title of the colormap - :param xlim: RA-limit of plot - :param ylim: DEC-limit of plot - :param figsize: figsize as tuple - :param title: plot title - :param xlabel: xlabel - :param ylabel: ylabel - :param cmap: matplotlib color map - :param origin: place the [0, 0] index of the array in - the upper left or lower left corner of the Axes - :param wcs_enabled: Use wcs transformation? - :param invert_xaxis: Do you want to invert the xaxis? - :param filename: Set to path/fname to save figure - (set extension to fname to overwrite .png default) - :param block: Whether plotting should block the remaining of the script - :param kwargs: matplotlib kwargs for scatter & Collections, - e.g. customize `s`, `vmin` or `vmax` + Args: + title: the title of the colormap + xlim: RA-limit of plot + ylim: DEC-limit of plot + figsize: figsize as tuple + title: plot title + xlabel: xlabel + ylabel: ylabel + cmap: matplotlib color map + origin: place the [0, 0] index of the array in + the upper left or lower left corner of the Axes + wcs_enabled: Use wcs transformation? Default is True + invert_xaxis: Do you want to invert the xaxis? Default is False + filename: Set to path/fname to save figure + (set extension to fname to overwrite .png default) + block: Whether plotting should block the remaining of the script + **kwargs: matplotlib kwargs for scatter & Collections, + e.g. customize `s`, `vmin` or `vmax` + """ if wcs_enabled: @@ -462,15 +474,17 @@ def overplot_with_skymodel( """Create a plot with the current image data, as well as an overlay of sources from a given SkyModel instance. - :param sky: a SkyModel instance, with sources to be plotted. - :param filename: path to the file where the final plot will be saved. - If None, the plot is not saved. - :param block: whether plotting should block the remaining of the script. - :param channel_index: Which frequency channel to show in the plot. - Defaults to 0. - :param stokes_index: Which polarisation to show in the plot. - Defaults to 0 (stokesI). - :param vmin_image, vmax_image: Limits for colorbar of Image plot. + Args: + sky: a SkyModel instance, with sources to be plotted. + filename: path to the file where the final plot will be saved. + If None, the plot is not saved. + block: whether plotting should block the remaining of the script. + channel_index: Which frequency channel to show in the plot. + Defaults to 0. + stokes_index: Which polarisation to show in the plot. + Defaults to 0 (stokesI). + vmin_image, vmax_image: Limits for colorbar of Image plot. + """ # wcs.wcs_world2pix expects a FITS header with only 2 coordinates (x, y). # For this plot, we temporarily remove the 3rd and 4th axes from the image @@ -524,19 +538,23 @@ def plot_side_by_side_with_skymodel( vmax_image: float = np.inf, ) -> None: """Create a plot with two panels: + 1. the current image data, and + 2. a scatter plot of sources from a given SkyModel instance. - :param sky: a SkyModel instance, with sources to be plotted. - :param filename: path to the file where the final plot will be saved. - If None, the plot is not saved. - :param block: whether plotting should block the remaining of the script. - :param channel_index: Which frequency channel to show in the plot. - Defaults to 0. - :param stokes_index: Which polarisation to show in the plot. - Defaults to 0 (stokesI). - :param vmin_sky, vmax_sky: Limits for colorbar of SkyModel scatter plot. - :param vmin_image, vmax_image: Limits for colorbar of Image plot. + Args: + sky: a SkyModel instance, with sources to be plotted. + filename: path to the file where the final plot will be saved. + If None, the plot is not saved. + block: whether plotting should block the remaining of the script. + channel_index: Which frequency channel to show in the plot. + Defaults to 0. + stokes_index: Which polarisation to show in the plot. + Defaults to 0 (stokesI). + vmin_sky, vmax_sky: Limits for colorbar of SkyModel scatter plot. + vmin_image, vmax_image: Limits for colorbar of Image plot. + """ wcs = WCS(self.header) slices = get_slices(wcs) @@ -587,8 +605,11 @@ def plot_side_by_side_with_skymodel( def get_dimensions_of_image(self) -> List[int]: """ - Get the sizes of the dimensions of this Image in an array. - :return: list with the dimensions. + Get the dimensions of this Image as an array. + + Returns: + List[int]: List with the dimensions. + """ result = [] dimensions = self.header["NAXIS"] @@ -602,8 +623,13 @@ def get_phase_center(self) -> Tuple[float, float]: def has_beam_parameters(self) -> bool: """ Check if the image has the beam parameters in the header. - :param image: Image to check - :return: True if the image has the beam parameters in the header + + Args: + image: Image to check + + Returns: + True if the image has the beam parameters in the header + """ return self.header_has_parameters( ["BMAJ", "BMIN", "BPA"], @@ -619,6 +645,7 @@ def get_beam_parameters(self) -> BeamType: Returns: "bmaj" (arcsec), "bmin" (arcsec), "bpa" (deg) + """ try: bmaj = float(self.header["BMAJ"]) @@ -652,7 +679,9 @@ def get_quality_metric(self) -> Dict[str, Any]: - Median --> 'median' - Mean --> 'mean' - :return: Dictionary holding all image statistics + Returns: + Dictionary holding all image statistics + """ # same implementation as RASCIL image_stats = { @@ -680,13 +709,16 @@ def get_power_spectrum( """ Calculate the power spectrum of this image. - :param resolution: Resolution in radians needed for conversion from Jy to Kelvin - :param signal_channel: channel containing both signal and noise \ - (arr of same shape as nchan of Image), optional + Args: + resolution: Resolution in radians needed for conversion from Jy to Kelvin + signal_channel: channel containing both signal and noise + (arr of same shape as nchan of Image), optional + + Returns: + (profile, theta_axis): + - profile: Brightness temperature for each angular scale in Kelvin + - theta_axis: Angular scale data in degrees - :return (profile, theta_axis): - - profile: Brightness temperature for each angular scale in Kelvin - - theta_axis: Angular scale data in degrees """ profile, theta = power_spectrum(self.path, resolution, signal_channel) return profile, theta @@ -701,11 +733,13 @@ def plot_power_spectrum( """ Plot the power spectrum of this image. - :param resolution: Resolution in radians needed for conversion from Jy to Kelvin - :param signal_channel: channel containing both signal and noise \ - (arr of same shape as nchan of Image), optional - :param save_png: True if result should be saved, default = False - :param block: Whether plotting should block the remaining of the script + Args: + resolution: Resolution in radians needed for conversion from Jy to Kelvin + signal_channel: channel containing both signal and noise + (arr of same shape as nchan of Image), optional + save_png: True if result should be saved, default = False + block: Whether plotting should block the remaining of the script + """ profile, theta = self.get_power_spectrum(resolution, signal_channel) plt.clf() @@ -760,6 +794,7 @@ def get_corners_in_world(cls, header: Header) -> NDArray[np.float64]: Returns: Corners in world coordinates [deg] with shape 4x2. + """ wcs = WCS(header) if wcs.naxis < 2: @@ -797,31 +832,21 @@ class ImageMosaicker: A class to handle the combination of multiple images into a single mosaicked image. See: https://reproject.readthedocs.io/en/stable/mosaicking.html - Parameters More information on the parameters can be found in the documentation: - https://reproject.readthedocs.io/en/stable/api/reproject.mosaicking.reproject_and_coadd.html # noqa: E501 + https://reproject.readthedocs.io/en/stable/api/reproject.mosaicking.reproject_and_coadd.html However, here the most common to tune are explained. - ---------- - reproject_function : callable, optional - The function to use for the reprojection. - combine_function : {'mean', 'sum'} - The type of function to use for combining the values into the final image. - match_background : bool, optional - Whether to match the backgrounds of the images. - background_reference : None or int, optional - If None, the background matching will make it so that the average of the - corrections for all images is zero. - If an integer, this specifies the index of the image to use as a reference. - - Methods - ------- - get_optimal_wcs(images, projection='SIN', **kwargs) - Get the optimal WCS for the given images. See: - https://reproject.readthedocs.io/en/stable/api/reproject.mosaicking.find_optimal_celestial_wcs.html # noqa: E501 - process( - images - ) - Combine the provided images into a single mosaicked image. + + Args: + reproject_function (callable, optional): The function to use for the + reprojection. + combine_function ({'mean', 'sum'}): The type of function to use for + combining the values into the final image. + match_background (bool, optional): Whether to match the backgrounds + of the images. + background_reference (None or int, optional): If None, the background + matching will make it so that the average of the corrections for + all images is zero. If an integer, this specifies the index of the image + to use as a reference. """ @@ -847,21 +872,16 @@ def get_optimal_wcs( Set the optimal WCS for the given images. See: https://reproject.readthedocs.io/en/stable/api/reproject.mosaicking.find_optimal_celestial_wcs.html # noqa: E501 - Parameters - ---------- - images : list - A list of images to combine. - projection : str, optional - Three-letter code for the WCS projection, such as 'SIN' or 'TAN'. - **kwargs : dict, optional - Additional keyword arguments to be passed to the reprojection function. - - Returns - ------- - WCS - The optimal WCS for the given images. - tuple - The shape of the optimal WCS. + Args: + images (list): A list of images to combine. + projection (str, optional): Three-letter code for + the WCS projection, such as 'SIN' or 'TAN'. + **kwargs (dict, optional): Additional keyword arguments to be passed + to the reprojection function. + + Returns: + Tuple[WCS, tuple[int, int]]: The optimal WCS for the given images and\ + the size of this WCS """ optimal_wcs = find_optimal_celestial_wcs( @@ -890,41 +910,30 @@ def mosaic( """ Combine the provided images into a single mosaicked image. - Parameters - ---------- - images : list - A list of images to combine. - wcs : tuple, optional - The WCS to use for the mosaicking. Will be calculated with `get_optimal_wcs` - if not passed. - input_weights : list, optional - If specified, an iterable with the same length as images, containing weights - for each image. - shape_out : tuple, optional - The shape of the output data. If None, it will be computed from the images. - hdu_in : int or str, optional - If one or more items in input_data is a FITS file or an HDUList instance, - specifies the HDU to use. - hdu_weights : int or str, optional - If one or more items in input_weights is a FITS file or an HDUList instance, - specifies the HDU to use. - image_for_header : Image, optional - From which image the header should be used to readd the lost information - by the mosaicking because some information is not propagated. - **kwargs : dict, optional - Additional keyword arguments to be passed to the reprojection function. - - Returns - ------- - fits.PrimaryHDU - The final mosaicked image as a FITS HDU. - np.ndarray - The footprint of the final mosaicked image. - - Raises - ------ - ValueError - If less than two images are provided. + Args: + images (list): A list of images to combine. + wcs (tuple, optional): The WCS to use for the mosaicking. + Will be calculated with `get_optimal_wcs` if not passed. + input_weights (list, optional): If specified, an iterable with the + same length as images, containing weights for each image. + shape_out (tuple, optional): The shape of the output data. If None, + it will be computed from the images. + hdu_in (int or str, optional): If one or more items in input_data is + a FITS file or an HDUList instance, specifies the HDU to use. + hdu_weights (int or str, optional): If one or more items in input_weights + is a FITS file or an HDUList instance, specifies the HDU to use. + image_for_header (Image, optional): From which image the header should + be used to readd the lost information by the mosaicking because some + information is not propagated. + **kwargs (dict, optional): Additional keyword arguments to be passed + to the reprojection function. + + Returns: + Tuple[Image, NDArray[np.float64]]: The final mosaicked image as a FITS HDU \ + and the footprint of the final mosaicked image. + + Raises: + ValueError: If less than two images are provided. """ diff --git a/karabo/imaging/imager_base.py b/karabo/imaging/imager_base.py index b057f0ee..aa47de38 100644 --- a/karabo/imaging/imager_base.py +++ b/karabo/imaging/imager_base.py @@ -26,6 +26,7 @@ class DirtyImagerConfig: imaging_cellsize (float): Scale of a pixel in radians combine_across_frequencies (bool): Whether or not to combine images across all frequency channels into one image. Defaults to True. + """ imaging_npixel: int @@ -37,6 +38,7 @@ class DirtyImager(ABC): """Abstract base class for a dirty imager. A dirty imager creates dirty images from visibilities. + """ config: DirtyImagerConfig @@ -62,6 +64,7 @@ def create_dirty_image( Returns: Image: Dirty image + """ ... @@ -80,6 +83,7 @@ class ImageCleanerConfig: Attributes: imaging_npixel (int): Image size imaging_cellsize (float): Scale of a pixel in radians + """ imaging_npixel: int @@ -92,6 +96,7 @@ class ImageCleaner(ABC): An image cleaner creates clean images from dirty images or directly from visibilities, in that case including the dirty imaging process. + """ @abstractmethod @@ -117,6 +122,7 @@ def create_cleaned_image( Returns: Image: Clean image + """ ... diff --git a/karabo/imaging/imager_oskar.py b/karabo/imaging/imager_oskar.py index 9d57d0b7..bc221574 100644 --- a/karabo/imaging/imager_oskar.py +++ b/karabo/imaging/imager_oskar.py @@ -31,6 +31,7 @@ class OskarDirtyImagerConfig(DirtyImagerConfig): combine_across_frequencies (bool): see DirtyImagerConfig imaging_phase_centre (Optional[str]): Phase centre (in SkyCoord string format). Defaults to None. + """ imaging_phase_centre: Optional[str] = None @@ -42,6 +43,7 @@ class OskarDirtyImager(DirtyImager): Attributes: config (OskarDirtyImagerConfig): Config containing parameters for OSKAR dirty imaging. + """ def __init__(self, config: OskarDirtyImagerConfig) -> None: @@ -49,6 +51,7 @@ def __init__(self, config: OskarDirtyImagerConfig) -> None: Args: config (OskarDirtyImagerConfig): see config attribute + """ super().__init__() self.config: OskarDirtyImagerConfig = config diff --git a/karabo/imaging/imager_rascil.py b/karabo/imaging/imager_rascil.py index 8d4cf26c..b6e4b248 100644 --- a/karabo/imaging/imager_rascil.py +++ b/karabo/imaging/imager_rascil.py @@ -50,6 +50,7 @@ class RascilDirtyImagerConfig(DirtyImagerConfig): combine_across_frequencies (bool): see DirtyImagerConfig override_cellsize (bool): Override the cellsize if it is above the critical cellsize. Defaults to False. + """ override_cellsize: bool = False @@ -61,6 +62,7 @@ class RascilDirtyImager(DirtyImager): Attributes: config (RascilDirtyImagerConfig): Config containing parameters for RASCIL dirty imaging. + """ def __init__(self, config: RascilDirtyImagerConfig) -> None: @@ -68,6 +70,7 @@ def __init__(self, config: RascilDirtyImagerConfig) -> None: Args: config (RascilDirtyImagerConfig): see config attribute + """ super().__init__() self.config: RascilDirtyImagerConfig = config @@ -155,65 +158,65 @@ class RascilImageCleanerConfig(ImageCleanerConfig): Adds parameters specific to RascilImageCleaner. - :param imaging_npixel: see ImageCleanerConfig - :param imaging_cellsize: see ImageCleanerConfig - :param ingest_dd: Data descriptors in MS to read (all must have the same \ - number of channels). Defaults to [0]. - :param ingest_vis_nchan: Number of channels in a single data \ - descriptor in the MS. Defaults to None. - :param ingest_chan_per_vis: Number of channels per blockvis (before any average). \ - Defaults to 1. - :param imaging_nchan: Number of channels per image. Defaults to 1. - :param imaging_w_stacking: Use the improved w stacking method \ - in Nifty Gridder. Defaults to True. - :param imaging_flat_sky: If using a primary beam, normalise to \ - flat sky. Defaults to False. - :param override_cellsize: Override the cellsize if it is above \ - the critical cellsize. Defaults to False. - :param imaging_uvmax: TODO. Defaults to None. - :param imaging_uvmin: TODO. Defaults to 0. - :param imaging_dft_kernel: DFT kernel: cpu_looped | gpu_raw.\ - Defaults to None. - :param client: Dask client. Defaults to None. - :param use_dask: Use dask? Defaults to False. - :param n_threads: n_threads per worker. Defaults to 1. - :param use_cuda: Use CUDA for Nifty Gridder? Defaults to False. - :param img_context: Which nifty gridder to use. Defaults to "ng". - :param clean_algorithm: Deconvolution algorithm \ - (hogbom or msclean or mmclean). Defaults to "hogbom". - :param clean_beam: major axis, minor axis,\ - position angle (deg). Defaults to None. - :param clean_scales: Scales for multiscale clean (pixels) e.g. [0, 6, 10].\ - Defaults to [0]. - :param clean_nmoment: Number of frequency moments in mmclean\ - (1=constant, 2=linear). Defaults to 4. - :param clean_nmajor: Number of major cycles in cip or ical. Defaults to 5. - :param clean_niter: Number of minor cycles in CLEAN. Defaults to 1000. - :param clean_psf_support: Half-width of psf used in cleaning (pixels).\ - Defaults to 256. - :param clean_gain: Clean loop gain. Defaults to 0.1. - :param clean_threshold: Clean stopping threshold (Jy/beam). Defaults to 1e-4. - :param clean_component_threshold: Sources with absolute flux \ - > this level (Jy) are fit or extracted using skycomponents.\ - Defaults to None. - :param clean_component_method: Method to convert sources \ - in image to skycomponents: "fit" in frequency or "extract" actual values. \ - Defaults to "fit". - :param clean_fractional_threshold: Fractional stopping threshold for major \ - cycle. Defaults to 0.3. - :param clean_facets: Number of overlapping facets in faceted clean along each\ - axis. Defaults to 1. - :param clean_overlap: Overlap of facets in clean (pixels). Defaults to 32. - :param clean_taper: Type of interpolation between facets in \ - deconvolution: none or linear or tukey. Defaults to "tukey". - :param clean_restore_facets: Number of overlapping facets in restore step \ - along each axis. Defaults to 1. - :param clean_restore_overlap: Overlap of facets in restore step (pixels). \ - Defaults to 32. - :param clean_restore_taper: Type of interpolation between facets in \ - restore step (none, linear or tukey). Defaults to "tukey". - :param clean_restored_output: Type of restored image output:\ - taylor, list, or integrated. Defaults to "list". + Attributes: + ingest_dd (List[int]): Data descriptors in MS to read (all must have the same + number of channels). Defaults to [0]. + ingest_vis_nchan (Optional[int]): Number of channels in a single data + descriptor in the MS. Defaults to None. + ingest_chan_per_vis (int): Number of channels per blockvis (before any average). + Defaults to 1. + imaging_nchan (int): Number of channels per image. Defaults to 1. + imaging_w_stacking (Union[bool, str]): Use the improved w stacking method + in Nifty Gridder?. Defaults to True. + imaging_flat_sky (Union[bool, str]): If using a primary beam, normalise to + flat sky? Defaults to False. + override_cellsize (bool): Override the cellsize if it is above + the critical cellsize? Defaults to False. + imaging_uvmax (Optional[float]): TODO. Defaults to None. + imaging_uvmin (float): TODO. Defaults to 0. + imaging_dft_kernel (Optional[DftKernelType]): DFT kernel: cpu_looped | gpu_raw. + Defaults to None. + client (Optional[Client]): Dask client. Defaults to None. + use_dask (bool): Use dask? Defaults to False. + n_threads (int): n_threads per worker. Defaults to 1. + use_cuda (bool): Use CUDA for Nifty Gridder? Defaults to False. + img_context (ImageContextType): Which nifty gridder to use. Defaults to "ng". + clean_algorithm (CleanAlgorithmType): Deconvolution algorithm + (hogbom or msclean or mmclean). Defaults to "hogbom". + clean_beam (Optional[Dict[CleanBeamInDegType, float]]): major axis, minor axis, + position angle (deg). Defaults to None. + clean_scales (List[int]): Scales for multiscale clean (pixels) e.g. [0, 6, 10]. + Defaults to [0]. + clean_nmoment (int): Number of frequency moments in mmclean + (1=constant, 2=linear). Defaults to 4. + clean_nmajor (int): Number of major cycles in cip or ical. Defaults to 5. + clean_niter (int): Number of minor cycles in CLEAN. Defaults to 1000. + clean_psf_support (int): Half-width of psf used in cleaning (pixels). + Defaults to 256. + clean_gain (float): Clean loop gain. Defaults to 0.1. + clean_threshold (float): Clean stopping threshold (Jy/beam). Defaults to 1e-4. + clean_component_threshold (Optional[float]): Sources with absolute flux + > this level (Jy) are fit or extracted using skycomponents. + Defaults to None. + clean_component_method (CleanComponentMethodType): Method to convert sources + in image to skycomponents: "fit" in frequency or "extract" actual values. + Defaults to "fit". + clean_fractional_threshold (float): Fractional stopping threshold for major + cycle. Defaults to 0.3. + clean_facets (int) Number of overlapping facets in faceted clean along each + axis. Defaults to 1. + clean_overlap (int): Overlap of facets in clean (pixels). Defaults to 32. + clean_taper (CleanTaperType): Type of interpolation between facets in + deconvolution: none or linear or tukey. Defaults to "tukey". + clean_restore_facets (int): Number of overlapping facets in restore step + along each axis. Defaults to 1. + clean_restore_overlap (int): Overlap of facets in restore step (pixels). + Defaults to 32. + clean_restore_taper (CleanTaperType): Type of interpolation between facets in + restore step (none, linear or tukey). Defaults to "tukey". + clean_restored_output (CleanRestoredOutputType): Type of restored image output: + taylor, list, or integrated. Defaults to "list". + """ ingest_dd: List[int] = field(default_factory=_create_ingest_dd_default_value) @@ -258,6 +261,7 @@ class RascilImageCleaner(ImageCleaner): Attributes: config (RascilImageCleanerConfig): Config containing parameters for RASCIL image cleaning. + """ def __init__(self, config: RascilImageCleanerConfig) -> None: @@ -265,6 +269,7 @@ def __init__(self, config: RascilImageCleanerConfig) -> None: Args: config (RascilImageCleanerConfig): see config attribute + """ super().__init__() self.config = config @@ -335,6 +340,7 @@ def create_cleaned_image_variants( Returns: A tuple (deconvolved, restored, residual) of images + """ if visibility.format != "MS": raise NotImplementedError( diff --git a/karabo/imaging/imager_wsclean.py b/karabo/imaging/imager_wsclean.py index 360e418f..bb76190c 100644 --- a/karabo/imaging/imager_wsclean.py +++ b/karabo/imaging/imager_wsclean.py @@ -48,6 +48,7 @@ class WscleanDirtyImager(DirtyImager): Attributes: config (DirtyImagerConfig): Config containing parameters for dirty imaging + """ TMP_PREFIX_DIRTY = "WSClean-dirty-" @@ -60,6 +61,7 @@ def __init__(self, config: DirtyImagerConfig) -> None: Args: config (DirtyImagerConfig): see config attribute + """ super().__init__() self.config = config @@ -132,6 +134,7 @@ class WscleanImageCleanerConfig(ImageCleanerConfig): a good value. Defaults to 0.8. auto_threshold (Optional[int]): Relative clean threshold. Estimate noise level using a robust estimator and stop at sigma x stddev. Defaults to 3. + """ niter: Optional[int] = 50000 @@ -153,6 +156,7 @@ class WscleanImageCleaner(ImageCleaner): Attributes: config (WscleanImageCleanerConfig): Config containing parameters for WSClean image cleaning. + """ TMP_PREFIX_CLEANED = "WSClean-cleaned-" @@ -165,6 +169,7 @@ def __init__(self, config: WscleanImageCleanerConfig) -> None: Args: config (WscleanImageCleanerConfig): see config attribute + """ super().__init__() self.config = config @@ -244,8 +249,9 @@ def create_image_custom_command( Use absolute paths to reference files or directories like the measurement set. Args: - command: Command to execute. Example: wsclean -size 2048 2048 - -scale 0.0022222222222222222deg -niter 50000 -mgain 0.8 + command: Command to execute. + Example: wsclean -size 2048 2048 + -scale 0.00222222deg -niter 50000 -mgain 0.8 -abs-threshold 100µJy /tmp/measurements.MS output_filenames: WSClean output filename(s) (relative to the working directory) that should be returned @@ -255,10 +261,12 @@ def create_image_custom_command( Example 2: ['wsclean-image.fits', 'wsclean-residual.fits'] Returns: - If output_filenames is a string, returns an Image object of the file + + - If output_filenames is a **string**, returns an Image object of the file \ output_filenames. - If output_filenames is a list of strings, returns a list of Image objects, - one object per filename in output_filenames. + - If output_filenames is a **list of strings**, returns a list of \ + Image objects, one object per filename in output_filenames. + """ tmp_dir = FileHandler().get_tmp_dir(