Function birli::flags::write_flags
source · [−]pub fn write_flags(
context: &CorrelatorContext,
flag_array: &Array3<bool>,
filename_template: &str,
mwalib_coarse_chan_range: &Range<usize>
) -> Result<(), IOError>
Expand description
Write flags to disk, given an observation’s [mwalib::CorrelatorContext
], a vector of
CxxFlagMask
s 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
[flag_io::FlagFileSet::new
] for more details.
Examples
Here’s an example of how to flag some visibility files
use birli::{
context_to_jones_array, write_flags, mwalib::CorrelatorContext,
init_flag_array, get_antenna_flags, get_baseline_flags};
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 context = CorrelatorContext::new(&metafits_path, &gpufits_paths).unwrap();
// Determine which timesteps and coarse channels we want to use
let img_coarse_chan_idxs = &context.common_coarse_chan_indices;
let img_timestep_idxs = &context.common_timestep_indices;
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);
// Prepare our flagmasks with known bad antennae
let flag_array = init_flag_array(
&context,
&img_timestep_range,
&img_coarse_chan_range,
None,
None,
None,
Some(&get_baseline_flags(&context, &get_antenna_flags(&context))),
);
// read visibilities out of the gpubox files
let (jones_array, flag_array) = context_to_jones_array(
&context,
&img_timestep_range,
&img_coarse_chan_range,
Some(flag_array),
false,
).unwrap();
// write the flags to disk as .mwaf
write_flags(&context, &flag_array, flag_template.to_str().unwrap(), &img_coarse_chan_range).unwrap();
Errors
- Will error with IOError::FitsOpen if there are files already present at the paths specified in filename template.
- Will error with IOError::InvalidFlagFilenameTemplate if an invalid flag filename template is provided (wrong number of percents).