Skip to content

Commit

Permalink
extra averaging tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d3v-null committed Oct 11, 2024
1 parent f4beded commit b74adde
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion src/averaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ pub fn average_visibilities(
mod tess {
use crate::Complex;
use approx::assert_abs_diff_eq;
use ndarray::{Array3, Array4};
use ndarray::prelude::*;

use super::{average_visibilities, Jones};

Expand Down Expand Up @@ -431,5 +431,55 @@ mod tess {
assert_abs_diff_eq!(averaged_weight_array[(2, 3, 2, 3)], expected_weight_2_3_2_3);
}

#[test]
/// birli issue 162 https://github.com/MWATelescope/Birli/issues/162
fn test_averaging_birli_162() {
let n_timesteps = 4;
let n_channels = 64;
let n_pols = 4;
let n_baselines = 1;
let shape = (n_timesteps, n_channels, n_baselines, n_pols);
let time_factor = 2;
let frequency_factor = 1;

let jones_id: Jones<f32> = Jones::identity();
let mut vis_array = Array3::from_elem((n_timesteps, n_channels, n_baselines), jones_id);
let mut weight_array = Array4::from_elem(shape, 1_f32);
let mut flag_array = Array4::from_elem(shape, false);

// simulate missing timestep idx 3, second half of channels
let half_chan = n_channels / 2;
vis_array
.slice_mut(s![3, half_chan.., 0])
.fill(jones_id * -99999.0);
weight_array
.slice_mut(s![3, half_chan.., 0, ..])
.fill(-99999.0);
flag_array.slice_mut(s![3, half_chan.., 0, ..]).fill(true);

let (averaged_vis_array, averaged_weight_array, averaged_flag_array) =
average_visibilities(
vis_array.view(),
weight_array.view(),
flag_array.view(),
time_factor,
frequency_factor,
)
.unwrap();

// despite the missing value, it should still average to identity.
averaged_vis_array.for_each(|&v| assert_abs_diff_eq!(v, jones_id));
averaged_weight_array
.slice(s![.., ..half_chan, 0, ..])
.for_each(|&v| assert_abs_diff_eq!(v, 2.0));
averaged_weight_array
.slice(s![0, half_chan.., 0, ..])
.for_each(|&v| assert_abs_diff_eq!(v, 2.0));
averaged_weight_array
.slice(s![1, half_chan.., 0, ..])
.for_each(|&v| assert_abs_diff_eq!(v, 1.0));
averaged_flag_array.for_each(|&v| assert!(!v));
}

// TODO: test unflagged with zero weight.
}

0 comments on commit b74adde

Please sign in to comment.