flint.flagging

Utility functions to carry out flagging against ASKAP measurement sets

Classes

AOFlaggerCommand

The command to use when running aoflagger

Functions

_nan_zero_extreme_flag(...)

Used to evaluate the flags that should be applied to the MS based on

cli(→ None)

create_aoflagger_cmd(→ AOFlaggerCommand)

Create a command to run aoflagger against a measurement set

flag_ms_aoflagger(→ flint.options.MS)

Create and run an aoflagger command in a container

flag_ms_by_antenna_ids(→ flint.options.MS)

Set the FLAG to True for a collection of rows where ANTENNA1 or ANTENNA2 is in a set of

flag_ms_zero_uvws(→ flint.options.MS)

Flag out the UVWs in a measurement set that have values of zero.

get_parser(→ argparse.ArgumentParser)

Create the argument parser for the flagging

nan_zero_extreme_flag_ms(→ flint.options.MS)

Will flag a MS based on NaNs or zeros in the nominated data column of a measurement set.

run_aoflagger_cmd(→ None)

Run the aoflagger command constructed in its singularity container

Module Contents

class flint.flagging.AOFlaggerCommand[source]

Bases: NamedTuple

The command to use when running aoflagger

cmd: str[source]

The command that will be executed

ms: flint.options.MS[source]

The MS object that was flagged

ms_path: pathlib.Path[source]

The path to the MS that will be flagged.

strategy_file: pathlib.Path | None = None[source]

The path to the aoflagging strategy file to use

flint.flagging._nan_zero_extreme_flag(data: numpy.typing.NDArray[numpy.complex128], flags: numpy.typing.NDArray[numpy.bool], uvws: numpy.typing.NDArray[numpy.float64], flag_extreme_dxy: bool = True, dxy_thresh: float = 4.0) tuple[numpy.typing.NDArray[numpy.complex128], numpy.typing.NDArray[numpy.bool], numpy.typing.NDArray[numpy.float64]][source]

Used to evaluate the flags that should be applied to the MS based on data values (if there are 0’s or nans), uvw values (which can be 0’s) and extreme stokes-v values.

This is the internal checker for the larger nan_zero_extreme_flags_in_ms function.

Parameters:
  • data (NDArray[np.complex128]) – Data that is being consider drawn from a DATA like column

  • flags (NDArray[np.bool]) – The flags that correspond to the DATA column drawn from the FLAG column

  • uvws (NDArray[np.float64]) – The (U,V,W) coordinates of the data

  • flag_extreme_dxy (bool, optional) – Whether flagging on extreme stokes-v should be consider. Defaults to True.

  • dxy_thresh (float, optional) – The threshold of the stokes-v flagging. Defaults to 4.0.

Returns:

Copies of the input data, flags and uvws. The flags are updated based on the results of the flagging.

Return type:

tuple[NDArray[np.complex128], NDArray[np.bool], NDArray[np.float64]]

flint.flagging.cli() None[source]
flint.flagging.create_aoflagger_cmd(ms: flint.options.MS) AOFlaggerCommand[source]

Create a command to run aoflagger against a measurement set

Parameters:
  • ms (MS) – The measurement set to flag. The column attached to the MS.column

  • flagged. (is)

Raises:

MSError – Raised when the attached column is not found in the MS

Returns:

The aoflagger command that will be run

Return type:

AOFlaggerCommand

flint.flagging.flag_ms_aoflagger(ms: flint.options.MS, container: pathlib.Path) flint.options.MS[source]

Create and run an aoflagger command in a container

Parameters:
  • ms (MS) – The measurement set with nominated column to flag

  • container (Path) – The container with the aoflagger program

Returns:

Measurement set flagged with the appropriate column

Return type:

MS

flint.flagging.flag_ms_by_antenna_ids(ms: pathlib.Path | flint.options.MS, ant_ids: int | Collection[int]) flint.options.MS[source]

Set the FLAG to True for a collection of rows where ANTENNA1 or ANTENNA2 is in a set of antenna IDs to flag. The flagging is performed via the antenna ID as it is in the measurement set - it is not by the antenna name.

Parameters:
  • ms (Union[Path, MS]) – The measurement set that has antennas to flag

  • ant_ids (Union[int,Collection[int]]) – The set of antenna IDs to flag.

Returns:

The measurement set with flagged antennas.

Return type:

MS

flint.flagging.flag_ms_zero_uvws(ms: flint.options.MS, chunk_size: int = 10000) flint.options.MS[source]

Flag out the UVWs in a measurement set that have values of zero. This happens when some data are flagged before it reaches the TOS.

A critical MS interaction scope is created to ensure if things fail they are known.

Parameters:
  • ms (MS) – Measurement set to flag

  • chunk_size (int, optional) – The number of rows to flag at a tim. Defaults to 10000.

Returns:

The flagged measurement set

Return type:

MS

flint.flagging.get_parser() argparse.ArgumentParser[source]

Create the argument parser for the flagging

Returns:

aoflagger argument parser

Return type:

ArgumentParser

flint.flagging.nan_zero_extreme_flag_ms(ms: pathlib.Path | flint.options.MS, data_column: str | None = None, flag_extreme_dxy: bool = True, dxy_thresh: float = 4.0, nan_data_on_flag: bool = False, chunk_size: int = 100000) flint.options.MS[source]

Will flag a MS based on NaNs or zeros in the nominated data column of a measurement set. These NaNs might be introduced into a column via the application of a applysolutions task. Zeros might be introduced by the correlator dropping cycles and not appropriately setting the corresponding FLAG column (although this might have been fixed).

There is also an optional component to flag based on extreme Stokes-V values.

Visibilities that are marked as bad will have the FLAG column updatede appropriately.

Parameters:
  • ms (Union[Path,MS]) – The measurement set that will be processed and have visibilities flagged.

  • data_column (Optional[str], optional) – The column to inspect. This will override the value in the nominated column of the MS. Defaults to None.

  • flag_extreme_dxy (bool, optional) – Whether Stokes-V will be inspected and flagged. Defaults to True.

  • dxy_thresh (float, optional) – Threshold used in the Stokes-V case. Defaults to 4.0.

  • nan_data_on_flag (bool, optional) – If True, data whose FLAG is set to True will become NaNs. Defaults to False.

  • chunk_size (int, optional) – Number of rows to process at a time. Defaults to 100000.

Returns:

The container of the processed MS

Return type:

MS

flint.flagging.run_aoflagger_cmd(aoflagger_cmd: AOFlaggerCommand, container: pathlib.Path) None[source]

Run the aoflagger command constructed in its singularity container

Parameters:
  • aoflagger_cmd (AOFlaggerCommand) – The command that will be executed

  • container (Path) – Path to the container that contains aoflagger