Skip to content

Commit

Permalink
type fixes/spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
tgalvin committed Aug 9, 2024
1 parent c68a1bb commit 1bb7e85
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 138 deletions.
10 changes: 5 additions & 5 deletions flint/bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from flint.calibrate.aocalibrate import AOSolutions, calibrate_apply_ms
from flint.flagging import flag_ms_aoflagger
from flint.logging import logger
from flint.ms import MS, describe_ms, preprocess_askap_ms
from flint.ms import MS, describe_ms, preprocess_askap_ms, get_field_id_for_field
from flint.naming import create_ms_name
from flint.sky_model import KNOWN_1934_FILES, get_1934_model

Expand Down Expand Up @@ -145,10 +145,10 @@ def extract_correct_bandpass_pointing(
return ms.with_options(beam=ms_summary.beam)

good_field_name = f"{source_name_prefix}_beam{ms_summary.beam}"
field_id = ms.get_field_id_for_field(field_name=good_field_name)
field_id = get_field_id_for_field(ms=ms, field_name=good_field_name)

out_name = create_ms_name(ms_path=ms.path, field=f"{source_name_prefix}")

out_path = Path("./")
# Handle writing out to elected output directory.
# TODO: Move this to a helper utility.
if ms_out_dir:
Expand Down Expand Up @@ -185,7 +185,7 @@ def calibrate_bandpass(
set will be created container just the appropriate field to calibrate.
Args:
ms_path (Path): Path the the measurement set containing bandpass obervations of B1934-638
ms_path (Path): Path the the measurement set containing bandpass observations of B1934-638
data_column (str): The column that will be calibrated.
mode (str): The calibration approach to use. Currently only `calibrate` is supported.
calibrate_container (Path): The path to the singularity container that holds the appropriate software.
Expand All @@ -196,7 +196,7 @@ def calibrate_bandpass(
Returns:
MS: The calibrated measurement set with nominated column
"""
logger.info(f"Will calibrate {str(ms_path)}, colum {data_column}")
logger.info(f"Will calibrate {str(ms_path)}, column {data_column}")

# TODO: Check to make sure only 1934-638
model_path: Path = get_1934_model(mode=mode)
Expand Down
29 changes: 15 additions & 14 deletions flint/imager/wsclean.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


class ImageSet(NamedTuple):
"""A structure to represent the images and auxillary products produced by
"""A structure to represent the images and auxiliary products produced by
wsclean"""

prefix: str
Expand All @@ -48,7 +48,7 @@ class WSCleanOptions(NamedTuple):
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 deterimine if it is a path is made.
Some basic attempts to determine if it is a path is made.
Should the `temp_dir` options be specified then all images will be
created in this location, and then moved over to the same parent directory
Expand Down Expand Up @@ -78,7 +78,7 @@ class WSCleanOptions(NamedTuple):
nmiter: int = 15
"""Maximum number of major cycles to perform"""
niter: int = 750000
"""Maximum numer of minor cycles"""
"""Maximum number of minor cycles"""
multiscale: bool = True
"""Enable multiscale deconvolution"""
multiscale_scale_bias: float = 0.75
Expand All @@ -95,7 +95,7 @@ class WSCleanOptions(NamedTuple):
)
"""Scales used for multi-scale deconvolution"""
fit_spectral_pol: int = 2
"""Number of spectral terms to include during sub-band subtractin"""
"""Number of spectral terms to include during sub-band subtraction"""
weight: str = "briggs -0.5"
"""Robustness of the weighting used"""
data_column: str = "CORRECTED_DATA"
Expand Down Expand Up @@ -280,7 +280,7 @@ def delete_wsclean_outputs(
Args:
prefix (str): The prefix of the files to remove. This would correspond to the -name of wsclean.
output_type (str, optional): What type of wsclean output to try to remove. Defaults to 'image'.
ignore_mfs (bool, optional): If True, do not remove MFS outputs (attempt to, atleast). Defaults to True.
ignore_mfs (bool, optional): If True, do not remove MFS outputs (attempt to, at least). Defaults to True.
Returns:
Collection[Path]: The paths that were removed (or at least attempted to be removed)/
Expand Down Expand Up @@ -330,12 +330,13 @@ def create_wsclean_name_argument(wsclean_options: WSCleanOptions, ms: MS) -> Pat
temp_dir = wsclean_options_dict.get("temp_dir", None)
if temp_dir:
# Resolve if environment variable
name_dir = (
name_dir: Union[Path, str, None] = (
get_environment_variable(variable=temp_dir)
if isinstance(temp_dir, str) and temp_dir[0] == "$"
else Path(temp_dir)
)
assert name_dir is not None, f"{name_dir=} is None, which is bad"
name_dir = Path(name_dir)

name_argument_path = Path(name_dir) / name_prefix_str
logger.info(f"Constructed -name {name_argument_path}")
Expand All @@ -359,7 +360,7 @@ def _resolve_wsclean_key_value_to_cli_str(key: str, value: Any) -> ResolvedCLIRe
the appropriate form to pass to a CLI call into wsclean.
Args:
key (str): The wsclean argument name to consider. Underscores will be converted to hypens, as expected by wsclean
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:
Expand Down Expand Up @@ -424,14 +425,14 @@ def create_wsclean_cmd(
#. 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.temp_dir` is specified this directory is used in place of the measurement sets parent directory
If `container` is supplied to immediatedly execute this command then the
If `container` is supplied to immediately execute this command then the
output wsclean image products will be moved from the `temp-dir` to the
same directory as the measurement set.
Args:
ms (MS): The measurement set 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 immediatedly. Defaults to None.
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
Expand Down Expand Up @@ -562,7 +563,7 @@ def combine_subbands_to_cube(
def run_wsclean_imager(
wsclean_cmd: WSCleanCommand,
container: Path,
bind_dirs: Optional[Tuple[Path]] = None,
bind_dirs: Optional[Tuple[Path, ...]] = None,
move_hold_directories: Optional[Tuple[Path, Optional[Path]]] = None,
make_cube_from_subbands: bool = True,
image_prefix_str: Optional[str] = None,
Expand All @@ -578,8 +579,8 @@ def run_wsclean_imager(
Args:
wsclean_cmd (WSCleanCommand): 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 manger. If None no `hold_then_move_into` manager is used. Defaults to None.
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.
Expand Down Expand Up @@ -665,7 +666,7 @@ def wsclean_imager(
Args:
ms (Union[Path,MS]): 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 ot None.
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:
WSCleanCommand: _description_
Expand Down Expand Up @@ -694,7 +695,7 @@ def get_parser() -> ArgumentParser:
subparser = parser.add_subparsers(dest="mode")

wsclean_parser = subparser.add_parser(
"image", help="Attempt to run a wsclean commmand. "
"image", help="Attempt to run a wsclean command. "
)
wsclean_parser.add_argument(
"ms", type=Path, help="Path to a measurement set to image"
Expand Down
30 changes: 15 additions & 15 deletions flint/masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from __future__ import annotations

from argparse import ArgumentParser
from collections import Iterable
from pathlib import Path
from typing import Collection, NamedTuple, Optional, Union

Expand Down Expand Up @@ -45,17 +44,17 @@ class MaskingOptions(NamedTuple):
flood_fill_use_mbc_box_size: int = 75
"""The size of the mbc box size should mbc be used"""
suppress_artefacts: bool = True
"""Whether to attempt artefacts based on the presence of sigificant negatives"""
"""Whether to attempt artefacts based on the presence of significant negatives"""
suppress_artefacts_negative_seed_clip: float = 5
"""The significance level of a negative island for the sidelobe suppresion to be activated. This should be a positive number (the signal map is internally inverted)"""
"""The significance level of a negative island for the sidelobe suppression to be activated. This should be a positive number (the signal map is internally inverted)"""
suppress_artefacts_guard_negative_dilation: float = 40
"""The minimum positive signifance pixels should have to be guarded when attempting to suppress artefacts around bright sources"""
"""The minimum positive significance pixels should have to be guarded when attempting to suppress artefacts around bright sources"""
suppress_artefacts_large_island_threshold: float = 1.0
"""Threshold in units of beams for an island of negative pixels to be considered large"""
grow_low_snr_island: bool = False
"""Whether to attempt to grow a mask to capture islands of low SNR (e.g. diffuse emission)"""
grow_low_snr_island_clip: float = 1.75
"""The minimum signifance levels of pixels to be to seed low SNR islands for consideration"""
"""The minimum significance levels of pixels to be to seed low SNR islands for consideration"""
grow_low_snr_island_size: int = 768
"""The number of pixels an island has to be for it to be accepted"""
minimum_boxcar: bool = True
Expand Down Expand Up @@ -103,8 +102,9 @@ def consider_beam_mask_round(
return mask_rounds is not None and (
(isinstance(mask_rounds, str) and mask_rounds.lower() == "all")
or (isinstance(mask_rounds, int) and current_round >= mask_rounds)
or (isinstance(mask_rounds, Iterable) and current_round in mask_rounds) # type: ignore
)
or (isinstance(mask_rounds, (list, tuple)))
and current_round in mask_rounds
) # type: ignore


def extract_beam_mask_from_mosaic(
Expand All @@ -126,7 +126,7 @@ def extract_beam_mask_from_mosaic(
Returns:
FITSMaskNames: _description_
"""
# TODO: Ideally we can accept an arbitary WCS, or read the wsclean docs to
# TODO: Ideally we can accept an arbitrary WCS, or read the wsclean docs to
# try to construct it ourselves. The last thing that this pirate wants is
# to run the imager in a dry-run type mode n cleaning type mode purely for
# the WCS.
Expand Down Expand Up @@ -198,7 +198,7 @@ def grow_low_snr_mask(
a mask through to the imagery of choice the islands may be larger than the features at their
native resolution, unless some other more sophisticated filtering is performed.
This function attempts to grow masks to capture islands of contigous pixels above a low
This function attempts to grow masks to capture islands of contiguous pixels above a low
SNR cut that would otherwise go uncleaned.
Args:
Expand Down Expand Up @@ -255,13 +255,13 @@ def minimum_boxcar_artefact_mask(
increase_factor: float = 2.0,
) -> np.ndarray:
"""Attempt to remove islands from a potential clean mask by
examining surronding pixels. A boxcar is applied to find the
examining surrounding pixels. A boxcar is applied to find the
minimum signal to noise in a small localised region. For each
island the maximum signal is considered.
If the absolute minimum signal increased by a factor in an
island region is larger to the maximum signal then that island
is ommited.
is omitted.
Args:
Expand Down Expand Up @@ -334,12 +334,12 @@ def suppress_artefact_mask(
- negative islands are around bright sources with deconvolution/calibration errors
- if there are brightish negative islands there is also positive brightish arteefact islands nearby
For this reason the guard mask should be sufficently high to protect the main source but nuke the fask positive islands
For this reason the guard mask should be sufficiently high to protect the main source but nuke the fask positive islands
Args:
signal (np.ndarray): The signal mask,
negative_seed_clip (float): The minimum signficance level to seed. This is a positive number (as it is applied to the inverted signal).
negative_seed_clip (float): The minimum significance level to seed. This is a positive number (as it is applied to the inverted signal).
guard_negative_dilation (float): Regions of positive emission above this are protected. This is positive.
pixels_per_beam (Optional[float], optional): The number of pixels per beam. If not None, seed islands larger than this many pixels are removed. Defaults to None.
large_island_threshold (float, optional): The number of beams required for a large island of negative pixels to be dropped as an artefact seed. Only used if `pixels_per_beam` is set. Defaults to 1.0.
Expand Down Expand Up @@ -433,12 +433,12 @@ def reverse_negative_flood_fill(
"""Attempt to:
* seed masks around bright regions of an image and grow them to lower significance thresholds
* remove regions of negative and positive islands that surrond bright sources.
* remove regions of negative and positive islands that surround bright sources.
An initial set of islands (and masks) are constructed by first
using the `positive_seed_clip` to create an initial SNR based
mask. These islands then are binary dilated to grow the islands
to adjacent pixels at a lower signifcance level (see `scipy.ndimage.binary_dilation`).
to adjacent pixels at a lower significance level (see `scipy.ndimage.binary_dilation`).
Next an attempt is made to remove artefacts around bright sources, where
there are likely to be positive and negative artefacts
Expand Down
Loading

0 comments on commit 1bb7e85

Please sign in to comment.