Skip to content

Commit

Permalink
cleanup unused code, fix coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
d3v-null committed Nov 20, 2024
1 parent 18513e7 commit c82b9c5
Show file tree
Hide file tree
Showing 17 changed files with 568 additions and 1,698 deletions.
97 changes: 3 additions & 94 deletions src/averaging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,9 @@ pub(super) fn unflag_spw(spw: Spw) -> Spw {
&all_freqs,
spw.freq_res as u64,
NonZeroUsize::new(1).unwrap(),
&HashSet::new()
).swap_remove(0)
&HashSet::new(),
)
.swap_remove(0)
}

/// Determine a time average factor given a time resolution and user input. Use
Expand Down Expand Up @@ -638,95 +639,3 @@ fn vis_average_weights_non_zero(
}
*weight_to = weight_sum as f32;
}

/// This function is the same as `vis_average`, except it assumes that any
/// flagged visibilities are indicated by weights equal to 0.0 (or -0.0). This
/// allows the code to be more efficient.
pub(crate) fn vis_average_no_negative_weights(
jones_from_tfb: ArrayView3<Jones<f32>>,
mut jones_to_fb: ArrayViewMut2<Jones<f32>>,
weight_from_tfb: ArrayView3<f32>,
mut weight_to_fb: ArrayViewMut2<f32>,
flagged_chan_indices: &HashSet<u16>,
) {
let avg_time = jones_from_tfb.len_of(Axis(0));
let avg_freq = (jones_from_tfb.len_of(Axis(1)) as f64 / jones_to_fb.len_of(Axis(0)) as f64)
.ceil() as usize;

// iterate along time axis in chunks of avg_time
jones_from_tfb
.axis_chunks_iter(Axis(0), avg_time)
.zip(weight_from_tfb.axis_chunks_iter(Axis(0), avg_time))
.for_each(|(jones_chunk_tfb, weight_chunk_tfb)| {
jones_chunk_tfb
.axis_iter(Axis(2))
.zip(weight_chunk_tfb.axis_iter(Axis(2)))
.zip(jones_to_fb.axis_iter_mut(Axis(1)))
.zip(weight_to_fb.axis_iter_mut(Axis(1)))
.for_each(
|(((jones_chunk_tf, weight_chunk_tf), mut jones_to_f), mut weight_to_f)| {
jones_chunk_tf
.axis_chunks_iter(Axis(1), avg_freq)
.zip(weight_chunk_tf.axis_chunks_iter(Axis(1), avg_freq))
.enumerate()
.filter(|(i, _)| !flagged_chan_indices.contains(&(*i as u16)))
.map(|(_, d)| d)
.zip(jones_to_f.iter_mut())
.zip(weight_to_f.iter_mut())
.for_each(
|(((jones_chunk_tf, weight_chunk_tf), jones_to), weight_to)| {
vis_average_weights_are_zero(
jones_chunk_tf,
weight_chunk_tf,
jones_to,
weight_to,
);
},
);
},
);
});
}

/// Average a chunk of visibilities and weights (both must have the same
/// dimensions) into an output vis and weight. This function needs the input
/// weights to be 0 or greater; this allows the averaging algorithm to be
/// simpler (as well as hopefully being faster), while also allowing further
/// averaging of the output visibilities without complicated logic.
#[inline]
fn vis_average_weights_are_zero(
jones_chunk_tf: ArrayView2<Jones<f32>>,
weight_chunk_tf: ArrayView2<f32>,
jones_to: &mut Jones<f32>,
weight_to: &mut f32,
) {
let mut jones_weighted_sum = Jones::default();
let mut weight_sum = 0.0;

// iterate through time chunks
jones_chunk_tf
.outer_iter()
.zip_eq(weight_chunk_tf.outer_iter())
.for_each(|(jones_chunk_f, weights_chunk_f)| {
jones_chunk_f
.iter()
.zip_eq(weights_chunk_f.iter())
.for_each(|(jones, weight)| {
// Any flagged visibilities would have a weight <= 0, but
// we've already capped them to 0. This means we don't need
// to check the value of the weight when accumulating
// unflagged visibilities; the flagged ones contribute
// nothing.

let jones = Jones::<f64>::from(*jones);
let weight = *weight as f64;
jones_weighted_sum += jones * weight;
weight_sum += weight;
});
});

if weight_sum > 0.0 {
*jones_to = Jones::from(jones_weighted_sum / weight_sum);
*weight_to = weight_sum as f32;
}
}
89 changes: 8 additions & 81 deletions src/cli/peel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ use super::common::{BeamArgs, InputVisArgs, ModellingArgs, SkyModelWithVetoArgs,
use crate::{
averaging::{
channels_to_chanblocks, parse_freq_average_factor, parse_time_average_factor,
timesteps_to_timeblocks, AverageFactorError, unflag_spw,
timesteps_to_timeblocks, unflag_spw, AverageFactorError,
},
cli::{
common::{display_warnings, InfoPrinter, OutputVisArgs},
Warn,
},
io::write::{VisOutputType, VIS_OUTPUT_EXTENSIONS},
math::div_ceil,
params::{ModellingParams, PeelParams},
unit_parsing::{parse_wavelength, WavelengthUnit, WAVELENGTH_FORMATS},
HyperdriveError,
math::div_ceil,
};

const DEFAULT_OUTPUT_PEEL_FILENAME: &str = "hyperdrive_peeled.uvfits";
Expand Down Expand Up @@ -79,8 +79,8 @@ pub(crate) struct PeelCliArgs {
/// "ionospherically subtracted" sources, except before subtracting, a "DI
/// calibration" is done between the iono-rotated model and the data. This
/// allows for scintillation and any other phase shift to be corrected.
#[clap(long = "peel", help_heading = "PEELING")]
pub(super) num_sources_to_peel: Option<usize>,
// #[clap(long = "peel", help_heading = "PEELING")]
// pub(super) num_sources_to_peel: Option<usize>,

/// The number of sources to "ionospherically subtract". That is, a λ²
/// dependence is found for each of these sources and removed. The number of
Expand Down Expand Up @@ -219,7 +219,6 @@ impl PeelArgs {
beam_args,
peel_args:
PeelCliArgs {
num_sources_to_peel,
num_sources_to_iono_subtract,
num_sources_to_subtract,
num_passes,
Expand Down Expand Up @@ -395,49 +394,6 @@ impl PeelArgs {
iono_freq_average_factor
};

// let mut iono_spws = {
// let all_freqs = {
// let n = input_vis_params.spw.chanblocks.len()
// + input_vis_params.spw.flagged_chanblock_indices.len();
// let mut freqs = Vec::with_capacity(n);
// let first_freq = input_vis_params.spw.first_freq.round() as u64;
// let freq_res = input_vis_params.spw.freq_res.round() as u64;
// for i in 0..n as u64 {
// freqs.push(first_freq + freq_res * i);
// }
// freqs
// };

// channels_to_chanblocks(
// &all_freqs,
// input_vis_params.spw.freq_res,
// freq_average_factor,
// &input_vis_params.spw.flagged_chanblock_indices,
// )
// };
// // There must be at least one chanblock to do anything.
// let iono_spw = match iono_spws.as_slice() {
// // No spectral windows is the same as no chanblocks.
// [] => return Err(PeelArgsError::NoChannels.into()),
// [f] => {
// // Check that the chanblocks aren't all flagged.
// if f.chanblocks.is_empty() {
// return Err(PeelArgsError::NoChannels.into());
// }
// iono_spws.swap_remove(0)
// }
// [f, ..] => {
// // Check that the chanblocks aren't all flagged.
// if f.chanblocks.is_empty() {
// return Err(PeelArgsError::NoChannels.into());
// }
// // TODO: Allow picket fence.
// eprintln!("\"Picket fence\" data detected. hyperdrive does not support this right now -- exiting.");
// eprintln!("See for more info: https://MWATelescope.github.io/mwa_hyperdrive/defs/mwa/picket_fence.html");
// std::process::exit(1);
// }
// };

let low_res_freq_average_factor = {
let default_iono_freq_average_factor = parse_freq_average_factor(
Some(input_vis_params.spw.freq_res),
Expand Down Expand Up @@ -595,31 +551,6 @@ impl PeelArgs {
let short_baseline_sigma = short_baseline_sigma.unwrap_or(DEFAULT_SHORT_BASELINE_SIGMA);
let convergence = convergence.unwrap_or(DEFAULT_CONVERGENCE);

// let (baseline_weights, num_flagged_baselines) = {
// let mut baseline_weights = Vec1::try_from_vec(vec![
// 1.0;
// tile_baseline_flags
// .unflagged_cross_baseline_to_tile_map
// .len()
// ])
// .map_err(|_| PeelError::NoTiles)?;
// let uvws = xyzs_to_cross_uvws(
// &unflagged_tile_xyzs,
// obs_context.phase_centre.to_hadec(lmst),
// );
// assert_eq!(baseline_weights.len(), uvws.len());
// let uvw_min = uvw_min_metres.powi(2);
// let uvw_max = uvw_max_metres.powi(2);
// let mut num_flagged_baselines = 0;
// for (uvw, baseline_weight) in uvws.into_iter().zip_eq(baseline_weights.iter_mut()) {
// let uvw_length = uvw.u.powi(2) + uvw.v.powi(2) + uvw.w.powi(2);
// if uvw_length < uvw_min || uvw_length > uvw_max {
// *baseline_weight = 0.0;
// num_flagged_baselines += 1;
// }
// }
// (baseline_weights, num_flagged_baselines)
// };
let num_unflagged_baselines = {
let uvws = xyzs_to_cross_uvws(
&unflagged_tile_xyzs,
Expand All @@ -640,10 +571,6 @@ impl PeelArgs {

let num_sources_to_iono_subtract =
num_sources_to_iono_subtract.unwrap_or(source_list.len());
if num_sources_to_peel.is_some() {
"No sources are being peeled; this is not working yet".warn()
}
let num_sources_to_peel = 0;

let mut peel_printer = InfoPrinter::new("Peeling set up".into());
peel_printer.push_block(vec![
Expand All @@ -653,7 +580,6 @@ impl PeelArgs {
num_sources_to_iono_subtract
)
.into(),
format!("Peeling {} sources", num_sources_to_peel).into(),
]);
if num_sources_to_iono_subtract > 0 {
let mut block = vec![];
Expand Down Expand Up @@ -695,7 +621,10 @@ impl PeelArgs {
);
}
block.push(
format!("- {num_passes} passes of {num_loops} loops at {convergence:.2} convergence").into()
format!(
"- {num_passes} passes of {num_loops} loops at {convergence:.2} convergence"
)
.into(),
);
peel_printer.push_block(block);
}

Check warning on line 630 in src/cli/peel/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/cli/peel/mod.rs#L630

Added line #L630 was not covered by tests
Expand All @@ -718,7 +647,6 @@ impl PeelArgs {
short_baseline_sigma,
convergence,
num_sources_to_iono_subtract,
num_sources_to_peel,
num_passes,
num_loops,
})
Expand All @@ -742,7 +670,6 @@ impl PeelArgs {
impl PeelCliArgs {
fn merge(self, other: Self) -> Self {
Self {
num_sources_to_peel: self.num_sources_to_peel.or(other.num_sources_to_peel),
num_sources_to_iono_subtract: self
.num_sources_to_iono_subtract
.or(other.num_sources_to_iono_subtract),
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/model_double.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* automatically generated by rust-bindgen 0.68.1 */
/* automatically generated by rust-bindgen 0.69.4 */

pub const POWER_LAW_FD_REF_FREQ: f64 = 150000000.0;
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/model_single.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* automatically generated by rust-bindgen 0.68.1 */
/* automatically generated by rust-bindgen 0.69.4 */

pub const POWER_LAW_FD_REF_FREQ: f32 = 150000000.0;
extern "C" {
Expand Down
Loading

0 comments on commit c82b9c5

Please sign in to comment.