Function birli::flags::write_flags

source ·
pub fn write_flags(
    filename_template: &str,
    corr_ctx: &CorrelatorContext,
    vis_sel: &VisSelection,
    flag_array: ArrayView3<'_, bool>,
    draw_progress: bool,
    aoflagger_version: Option<String>,
    aoflagger_strategy: Option<String>
) -> Result<(), IOError>
Expand description

Write flags to disk, given an observation’s marlu::mwalib::CorrelatorContext, a vector of CxxFlagMasks for each baseline in the observation, a filename template and a vector of gpubox IDs.

The filename template should contain two or 3 percentage (%) characters which will be replaced by the gpubox id or channel number (depending on correlator type) provided in gpubox_ids. See crate::io::mwaf::FlagFileSet for more details.

Examples

Here’s an example of how to flag some visibility files

use birli::{FlagContext, write_flags, mwalib::CorrelatorContext, VisSelection, io::read_mwalib};
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",
];

// define a temporary directory for output files
let tmp_dir = tempdir().unwrap();

// define our output flag file template
let flag_template = tmp_dir.path().join("Flagfile%%%.mwaf");

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

// Determine which timesteps and coarse channels we want to use
let vis_sel = VisSelection::from_mwalib(&corr_ctx).unwrap();

// Get the GPS time of the first timestep
let gps_start = corr_ctx.timesteps[vis_sel.timestep_range.start].gps_time_ms as f64 / 1e3;

// Prepare our flagmasks with known bad antennae
let mut flag_ctx = FlagContext::from_mwalib(&corr_ctx);

// Create a blank array to store flags and visibilities
let fine_chans_per_coarse = corr_ctx.metafits_context.num_corr_fine_chans_per_coarse;
let mut flag_array = vis_sel.allocate_flags(fine_chans_per_coarse).unwrap();
flag_ctx.set_flags(
    flag_array.view_mut(),
    &vis_sel.timestep_range,
    &vis_sel.coarse_chan_range,
    &vis_sel.get_ant_pairs(&corr_ctx.metafits_context)
);
let mut jones_array = vis_sel.allocate_jones(fine_chans_per_coarse).unwrap();

// read visibilities out of the gpubox files
read_mwalib(&vis_sel, &corr_ctx, jones_array.view_mut(), flag_array.view_mut(), false)
    .unwrap();

// write the flags to disk as .mwaf
write_flags(flag_template.to_str().unwrap(),
            &corr_ctx,
            &vis_sel,
            flag_array.view(),
            true,
            None,
            None,
).unwrap();

Errors