pub fn flag_jones_array_existing(
    aoflagger: &CxxAOFlagger,
    strategy_filename: &str,
    jones_array: &Array3<Jones<f32>>,
    flag_array: Option<Array3<bool>>,
    re_apply_existing: bool,
    draw_progress: bool
) -> Array3<bool>
Expand description

Flag an ndarray of Jones visibilities, given a CxxAOFlagger instance, a [CxxStrategy] filename, returning an [ndarray::Array3] of boolean flags.

Providing some existing flags is optional, however these flags must be the same dimension as the provided Jones array. If these are not provided, an empty flag array is created instead

if [re_apply_existing] is true, then the new flags are binary or’d with the existing flags, otherwise they overwrite them.

Performance

Because of all the memory juggling required to use aoflagger flagmasks, providing existing flagmasks is slower.

Examples

use birli::{context_to_jones_array, init_flag_array, flag_jones_array_existing, write_flags,
    get_antenna_flags, get_flaggable_timesteps, mwalib::CorrelatorContext, cxx_aoflagger_new};
use tempfile::tempdir;

// define our input files
let metafits_path = "tests/data/1297526432_mwax/1297526432.metafits";
let gpufits_paths = vec![
    "tests/data/1297526432_mwax/1297526432_20210216160014_ch117_000.fits",
    "tests/data/1297526432_mwax/1297526432_20210216160014_ch117_001.fits",
    "tests/data/1297526432_mwax/1297526432_20210216160014_ch118_000.fits",
    "tests/data/1297526432_mwax/1297526432_20210216160014_ch118_001.fits",
];

// Create an mwalib::CorrelatorContext for accessing visibilities.
let context = CorrelatorContext::new(&metafits_path, &gpufits_paths).unwrap();

// create a CxxAOFlagger object to perform AOFlagger operations
let aoflagger = unsafe { cxx_aoflagger_new() };

// specify which coarse_chan and timestep indices we want to load into an image.
let img_coarse_chan_idxs = &context.common_coarse_chan_indices;
let img_timestep_idxs = get_flaggable_timesteps(&context).unwrap();

let img_timestep_range =
    *img_timestep_idxs.first().unwrap()..(*img_timestep_idxs.last().unwrap() + 1);
let img_coarse_chan_range =
    *img_coarse_chan_idxs.first().unwrap()..(*img_coarse_chan_idxs.last().unwrap() + 1);

// read visibilities out of the gpubox files
let (jones_array, flag_array) = context_to_jones_array(
    &context,
    &img_timestep_range,
    &img_coarse_chan_range,
    None,
    false,
).unwrap();

// use the default strategy file location for MWA
let strategy_filename = &aoflagger.FindStrategyFileMWA();

// run the strategy on the imagesets, and get the resulting flagmasks for each baseline
let flag_array = flag_jones_array_existing(
   &aoflagger,
   &strategy_filename,
   &jones_array,
   Some(flag_array),
   true,
   false,
);