flint.imager.wsclean¶
Simple interface into wsclean
Some notes around the file naming.
A certain filenaming scheme is required for FITS files to perform leakage correction
when co-adding them together in the yandasoft linmos application. The stokes field
needs to be encoded as .i.. For example:
>>> `SB1234.RACS_0123+43.beam01.i.image.fits`
The wsclean formatted output string appends something denoted with -. Within
this code there is and attempt to rename the wsclean outputs to replace the -
with a ..
Classes¶
Mapping results to provide to wsclean |
|
A basic container to handle WSClean options. These attributes should |
|
An image wsclean writes, with the fields of its name |
|
Simple container for a wsclean command. |
Functions¶
|
An internal function intended to map a key-value pair to |
|
Call back function used to detect clean divergence |
|
Delete the images this run of wsclean writes that already exist under |
|
|
|
Gather the images wsclean wrote under |
|
Create a wsclean command from a WSCleanOptions container |
|
Create the value that will be provided to wsclean -name argument. This has |
|
The images wsclean writes for |
|
The images this run of wsclean writes that exist under |
|
The flint name of a wsclean image. Its polarisation, if tagged, replaces |
|
|
|
WSClean can produce a text file that describes the components |
|
|
|
Merge the image sets from multiple wsclean results into a single image set. |
|
The polarisations wsclean tags each image with, None when only one is imaged. |
|
Delete the channel images of |
|
Run a provided wsclean command. Optionally will clean up files, |
|
Raise |
|
Create and run a wsclean imager command against a measurement set. |
|
The name wsclean gives an image, |
Module Contents¶
- class flint.imager.wsclean.ResolvedCLIResult[source]¶
Bases:
NamedTupleMapping results to provide to wsclean
- class flint.imager.wsclean.WSCleanOptions(/, **data: Any)[source]¶
Bases:
flint.options.BaseOptionsA basic container to handle WSClean options. These attributes should conform to the same option name in the calling signature of wsclean
Basic support for environment variables is available. Should a value start with $ it is assumed to be a environment variable, it is will be looked up. Some basic attempts to determine if it is a path is made.
Should flint_hold_dir (or, failing that, temp_dir) be specified then all images will be created in this location, and then moved over to the same parent directory as the imaged MS. This is done by setting the wsclean -name argument.
Options that start with flint_ are ignored when generating the wsclean command and generally denote some other flint specific operation.
- check_pol() WSCleanOptions[source]¶
Refuse a
polflint can not image, and a source list asked ofpol: xx,yy
- beam_fitting_size: float | None = 1.25[source]¶
Use a fitting box the size of <factor> times the theoretical beam size for fitting a Gaussian to the PSF.
- channel_division_frequencies: tuple[float, ...] | None = None[source]¶
Frequencies, in Hz, that divide the output channels into groups. Supplying
channels_out - 1values fully specifies the output frequency grid, seeflint.imager.channel_division
- channel_range: tuple[int, int] | None = None[source]¶
Image a channel range between a lower (inclusive) and upper (exclusive) bound
- deconvolution_channels: int | None = None[source]¶
The channels out will be averaged down to this many sub-band images during deconvolution
- deconvolution_threads: int | None = None[source]¶
Number of threads to use during the deconvolution. More may make things faster but can come with a memory hit. If None defaults to -j
- fit_spectral_pol: int | None = None[source]¶
Number of spectral terms to include during sub-band subtraction
- flint_hold_dir: str | pathlib.Path | None = None[source]¶
Directory images are written to before being moved beside the MS. Takes precedence over
temp_dirfor this purpose
- flint_keep_linear_images: bool = False[source]¶
Keep the XX and YY images when
polisxx,yy, rather than deleting them once Stokes I is formed
- flint_name_suffix: str | None[source]¶
An additional trailing token appended to the constructed wsclean
-name, e.g. to disambiguate outputs from different pipelines imaging the same measurement set. Letters and digits only, as that is all the name parser reads back from theprojectfield
- flint_save_mfs_products: bool = False[source]¶
Save the MFS image, model and residual products (co-added and leakage-corrected the same way as the science image), rather than just the image
- gridder: str | None = 'wgridder'[source]¶
Use the wgridder kernel in wsclean (instead of the default w-stacking method)
- interval: tuple[int, int] | None = None[source]¶
Image a set of scans between a lower (inclusive) and upper (exclusive) bound
- join_channels: bool = True[source]¶
Collapse the sub-band images down to an MFS image when peak-finding
- join_polarizations: bool = False[source]¶
Perform deconvolution by searching for peaks in the sum of squares of the polarizations, but subtract components from the individual images. Only possible when imaging two or four Stokes or linear parameters. Default: off.
- maxw: float | None = None[source]¶
A percentage specifying the maximum w-term to be gridded, relative to the max w-term being considered
- minuv_l: float | None = None[source]¶
The minimum lambda length that the visibility data needs to meet for it to be selected for imaging
- minuvw_m: float | None = None[source]¶
A (u,v) selection command, where any baselines shorter than this will be ignored during imaging
- multiscale_fits_mask: pathlib.Path | None = None[source]¶
Path to a FITS file that contains per-scale clean masks encoded as per-pixel bit values
- multiscale_gain: float | None = None[source]¶
Size of step made in the subminor loop of multi-scale. Default currently 0.2, but shows sign of instability. A value of 0.1 might be more stable.
- no_mf_weighting: bool = False[source]¶
Opposite of -ms-weighting; can be used to turn off MF weighting in -join-channels mode
- no_reorder: bool = False[source]¶
If True turn off the reordering of the MS at the beginning of wsclean
- no_small_inversion: bool = False[source]¶
Disables an optimisation of wsclean’s w-gridder mode. This might improve accuracy of the w-gridder.
- no_update_model_required: bool = False[source]¶
Will instruct wsclean not to create the MODEL_DATA column
- parallel_deconvolution: int | None = None[source]¶
If not none, the maximum sub-image size in pixels used during deconvolution (suggestion between to between 1024-4096)
- parallel_gridding: int | None = None[source]¶
If not none, then this is the number of channel images that will be gridded in parallel
- save_source_list: bool = False[source]¶
Saves the found clean components as a BBS/DP3 text sky model
- size: int = 10128[source]¶
Image size, only a single dimension is required. Note that this means images will be squares.
- squared_channel_joining: bool = False[source]¶
Use with -join-channels to perform peak finding in the sum of squared values over channels, instead of the normal sum. This is useful for imaging QU polarizations with non-zero rotation measures, for which the normal sum is insensitive.
- taper_gaussian: float | None = None[source]¶
The size of a Gaussian function applied to the weights, assuming units of arcseconds. Defaults to None.
- class flint.imager.wsclean.WSCleanOutput[source]¶
Bases:
NamedTupleAn image wsclean writes, with the fields of its name
- class flint.imager.wsclean.WSCleanResult(/, **data: Any)[source]¶
Bases:
flint.options.BaseOptionsSimple container for a wsclean command.
- bind_dirs: tuple[pathlib.Path, ...][source]¶
Paths that should be binded to when executing the command
- cleanup: bool = True[source]¶
Will clean up the dirty images/psfs/residuals/models when the imaging has completed
- image_set: flint.imageset.ImageSet | None = None[source]¶
The set of images produced by wsclean
- move_hold_directories: tuple[pathlib.Path, pathlib.Path][source]¶
Paths that should be moved to and from when executing the command
- options: WSCleanOptions[source]¶
The set of wslean options used for imaging
- flint.imager.wsclean._resolve_wsclean_key_value_to_cli_str(key: str, value: Any) ResolvedCLIResult[source]¶
An internal function intended to map a key-value pair to the appropriate form to pass to a CLI call into wsclean.
- Parameters:
key (str) – The wsclean argument name to consider. Underscores will be converted to hyphens, as expected by wsclean
value (Any) – The value of the argument that should be converted to the appropriately formatted string
- Returns:
Converted CLI output, including paths to bind to and unknown conversions
- Return type:
- flint.imager.wsclean._wsclean_output_callback(line: str) None[source]¶
Call back function used to detect clean divergence
- flint.imager.wsclean.clear_wsclean_outputs(prefix: str | pathlib.Path, channels_out: int, pols: tuple[str, ...] | None) list[pathlib.Path][source]¶
Delete the images this run of wsclean writes that already exist under
prefix
- flint.imager.wsclean.collect_wsclean_outputs(wsclean_result: WSCleanResult, prefix: str, make_cube_from_subbands: bool = True, fitscube_options: flint.options.FitsCubeOptions | None = None, extra_output_types: tuple[str, ...] | None = None) flint.imageset.ImageSet[source]¶
Gather the images wsclean wrote under
prefixinto anImageSetwith flint names.With
pol: xx,yythe XX and YY images become Stokes I, and are deleted unlessflint_keep_linear_imagesis set. Images not gathered are renamed too, and left on disk with a warning. Channel images are cubed whenmake_cube_from_subbandsis set and one polarisation remains. RaisesFileNotFoundErrorif an expected image is missing.
- flint.imager.wsclean.create_wsclean_cmd(ms_list: list[flint.ms.MS], wsclean_options: WSCleanOptions) WSCleanResult[source]¶
Create a wsclean command from a WSCleanOptions container
For the most part these are one-to-one mappings to the wsclean CLI with the exceptions being: #. the -name argument will be generated and supplied to the CLI string and will default to the parent directory and name of the supplied measurement set #. If wsclean_options.flint_hold_dir or wsclean_options.temp_dir is specified this directory is used in place of the measurement sets parent directory
If container is supplied to immediately execute this command then the output wsclean image products will be moved from the hold directory to the same directory as the measurement set.
- Parameters:
ms_list (list[MS]) – The measurement sets to be imaged
wsclean_options (WSCleanOptions) – WSClean options to image with
container (Optional[Path], optional) – If a path to a container is provided the command is executed immediately. Defaults to None.
- Raises:
ValueError – Raised when a option has not been successfully processed
- Returns:
The wsclean command to run
- Return type:
- flint.imager.wsclean.create_wsclean_name_argument(wsclean_options: WSCleanOptions, ms: flint.ms.MS | list[flint.ms.MS]) pathlib.Path[source]¶
Create the value that will be provided to wsclean -name argument. This has to be generated. Among things to consider is the desired output directory of imaging files. This by default will be alongside the measurement set, and is overridden by flint_hold_dir, or failing that temp_dir.
If the input
msis an instance ofMSsthen the first measurement set will be used to base the name from.- Parameters:
wsclean_options (WSCleanOptions) – Set of wsclean options to consider
- Returns:
Value of the -name argument to provide to wsclean
- Return type:
Path
- flint.imager.wsclean.expected_wsclean_outputs(prefix: str | pathlib.Path, channels_out: int, pols: tuple[str, ...] | None, image_types: collections.abc.Collection[str] = ('image',)) list[WSCleanOutput][source]¶
The images wsclean writes for
image_types, each channel then the MFS image when there are several. The PSF is shared by every polarisation, so carries none.
- flint.imager.wsclean.find_wsclean_outputs(prefix: str | pathlib.Path, channels_out: int, pols: tuple[str, ...] | None) list[WSCleanOutput][source]¶
The images this run of wsclean writes that exist under
prefix, found by exact name
- flint.imager.wsclean.flint_output_path(output: WSCleanOutput, prefix: str | pathlib.Path, pol_token: str) pathlib.Path[source]¶
The flint name of a wsclean image. Its polarisation, if tagged, replaces
pol_tokeninprefix, and its channel becomes ach<lo>-<hi>field.
- flint.imager.wsclean.get_wsclean_output_source_list_path(name_path: str | pathlib.Path, pol: str | None = None) pathlib.Path[source]¶
WSClean can produce a text file that describes the components that it cleaned, their type, scale and brightness. These are placed in a file that is:
>> {name}.{pol}-sources.txt
where
namerepresented the -name component. Given an input measurement set path or this -name value return the expected source list text file.polis the stokes that the source is expected.- Parameters:
name_path (Union[str,Path]) – Value of the
-nameoption. If str converted to aPathpol (Optional[str], optional) – The polarisation to add to the name. If None the -source.txt suffix is simply appended. Defaults to None.
- Returns:
Path to the source list text file
- Return type:
Path
- flint.imager.wsclean.image_set_from_result(wsclean_result: WSCleanResult) flint.imageset.ImageSet | None[source]¶
- flint.imager.wsclean.merge_image_sets_from_results(wsclean_results: list[WSCleanResult]) flint.imageset.ImageSet[source]¶
Merge the image sets from multiple wsclean results into a single image set.
- Parameters:
wsclean_results (List[WSCleanResult]) – The results of multiple wsclean imaging runs
- Returns:
The merged image set
- Return type:
- flint.imager.wsclean.parse_pols(pol_str: str) tuple[str, ...] | None[source]¶
The polarisations wsclean tags each image with, None when only one is imaged. Raises
NotSupportedErrorfor an empty or unknown part, or a feed product other thanxx,yy.
- flint.imager.wsclean.remove_wsclean_outputs(outputs: list[WSCleanOutput], image_types: collections.abc.Collection[str] = ('dirty', 'psf', 'model', 'residual')) list[pathlib.Path][source]¶
Delete the channel images of
image_types, keeping the MFS images
- flint.imager.wsclean.run_wsclean_imager(wsclean_result: WSCleanResult, container: pathlib.Path, make_cube_from_subbands: bool = True, fitscube_options: flint.options.FitsCubeOptions | None = None, extra_output_types: tuple[str, ...] | None = None) flint.imageset.ImageSet[source]¶
Run a provided wsclean command. Optionally will clean up files, including the dirty beams, psfs and other assorted things.
An ImageSet is constructed that attempts to capture the output wsclean image products. If image_prefix_str is specified the image set will be created by (ordered by preference): #. Adding the image_prefix_str to the move_directory #. Guessing it from the path of the measurement set from wsclean_result.ms.path
- Parameters:
wsclean_result (WSCleanResult) – The command to run, and other properties (cleanup.)
container (Path) – Path to the container with wsclean available in it
bind_dirs (Optional[Tuple[Path, ...]], optional) – Additional directories to include when binding to the wsclean container. Defaults to None.
move_hold_directories (Optional[Tuple[Path,Optional[Path]]], optional) – The move_directory and hold_directory passed to the temporary context manager. If None no hold_then_move_into manager is used. Defaults to None.
make_cube_from_subbands (bool, optional) – Form a single FITS cube from the set of sub-band images wsclean produces. Defaults to False.
image_prefix_str (Optional[str], optional) – The name used to search for wsclean outputs. If None, it is guessed from the name and location of the MS. Defaults to None.
extra_output_types (tuple[str, ...] | None, optional) – Additional output types (beyond
image/residual) to search for and attach to the returnedImageSet, e.g.("model",). Defaults to None.
- Returns:
The executed wsclean output products.
- Return type:
- flint.imager.wsclean.verify_wsclean_outputs(outputs: list[WSCleanOutput], prefix: str | pathlib.Path, channels_out: int, pols: tuple[str, ...] | None) None[source]¶
Raise
FileNotFoundErrorif animagethis run should write is not amongoutputs. Other types are not checked, as cleaning up deletes them.
- flint.imager.wsclean.wsclean_imager(ms: pathlib.Path | flint.ms.MS | tuple[flint.ms.MS | pathlib.Path, ...] | list[flint.ms.MS | pathlib.Path], wsclean_container: pathlib.Path, update_wsclean_options: dict[str, Any] | None = None, update_fitscube_options: dict[str, Any] | None = None, make_cube_from_subbands: bool = True, extra_output_types: tuple[str, ...] | None = None) WSCleanResult[source]¶
Create and run a wsclean imager command against a measurement set.
- Parameters:
ms (Path | MS | tuple[MS | Path, ...] | list[MS | Path]) – Path to the measurement set that will be imaged
wsclean_container (Path) – Path to the container with wsclean installed
update_wsclean_options (Optional[Dict[str, Any]], optional) – Additional options to update the generated WscleanOptions with. Keys should be attributes of WscleanOptions. Defaults to None.
- Returns:
_description_
- Return type: