Skip to content

Commit

Permalink
Use hacked Marlu
Browse files Browse the repository at this point in the history
This stops us from writing out precessed UVWs and speeds up IO because we're
only writing out one polarisation.
  • Loading branch information
cjordan committed Aug 14, 2023
1 parent 0285759 commit 390395d
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 87 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ harness = false
# birli = { git = "https://github.com/MWATelescope/Birli" }
# marlu = { path = "../Marlu" }
# marlu = { git = "https://github.com/MWATelescope/Marlu", branch = "v0.9.0" }
marlu = { git = "https://github.com/cjordan/Marlu", branch = "hacks" }
# mwalib = { path = "../mwalib" }
# mwalib = { git = "https://github.com/MWATelescope/mwalib" }
# mwa_hyperbeam = { path = "../mwa_hyperbeam" }
Expand Down
12 changes: 6 additions & 6 deletions src/cli/common/input_vis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ impl InputVisArgs {
.expect("raw reader always has data corrections");
match raw_data_corrections.pfb_flavour {
PfbFlavour::None => block.push("Not doing any PFB correction".into()),
PfbFlavour::Jake => {
block.push("Correcting PFB gains with 'Jake Jones' gains".into())
}
PfbFlavour::Cotter2014 => {
block.push("Correcting PFB gains with 'Cotter 2014' gains".into())
}
//PfbFlavour::Jake => {
// block.push("Correcting PFB gains with 'Jake Jones' gains".into())
//}
//PfbFlavour::Cotter2014 => {
// block.push("Correcting PFB gains with 'Cotter 2014' gains".into())
//}
PfbFlavour::Empirical => {
block.push("Correcting PFB gains with 'RTS empirical' gains".into())
}
Expand Down
1 change: 1 addition & 0 deletions src/io/read/ms/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ fn test_timestep_reading() {
ant_positions_xyz,
Duration::from_seconds(0.0),
true,
1,
);
writer.initialize(&vis_ctx, &marlu_obs_ctx, None).unwrap();

Expand Down
5 changes: 2 additions & 3 deletions src/io/read/raw/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub enum RawReadError {

#[error(transparent)]
Selection(#[from] Box<marlu::SelectionError>),

#[error(transparent)]
Birli(#[from] Box<birli::BirliError>),
// #[error(transparent)]
// Birli(#[from] Box<birli::BirliError>),
}
89 changes: 43 additions & 46 deletions src/io/read/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ use std::{
path::{Path, PathBuf},
};

use birli::PreprocessContext;
//use birli::PreprocessContext;
use hifitime::{Duration, Epoch};
use itertools::Itertools;
use log::{debug, trace};
use marlu::{math::baseline_to_tiles, Jones, LatLngHeight, RADec, VisSelection, XyzGeodetic};
use mwalib::{
CorrelatorContext, GeometricDelaysApplied, GpuboxError, MWAVersion, MetafitsContext,
MwalibError, Pol,
};
use marlu::{math::baseline_to_tiles, Jones, LatLngHeight, RADec, XyzGeodetic};
use mwalib::{CorrelatorContext, GpuboxError, MWAVersion, MetafitsContext, MwalibError, Pol};
use ndarray::prelude::*;
use vec1::Vec1;

Expand Down Expand Up @@ -561,6 +558,8 @@ impl RawDataReader {
/// An internal method for reading visibilities. Cross- and/or
/// auto-correlation visibilities and weights are written to the supplied
/// arrays.
#[allow(dead_code)]
#[allow(unreachable_code)]
pub fn read_inner(
&self,
crosses: Option<CrossData>,
Expand Down Expand Up @@ -670,48 +669,46 @@ impl RawDataReader {
Array3::from_shape_vec(shape, jones_array_tfb).expect("correct shape");
let mut flag_array_tfb =
Array3::from_shape_vec(shape, flag_array_tfb).expect("correct shape");
let mut weight_array_tfb = Array3::from_elem(
shape,
birli::flags::get_weight_factor(&self.mwalib_context) as f32,
);
let mut weight_array_tfb = Array3::from_elem(shape, 1.0_f32);

// Correct the raw data.
if !self.corrections.nothing_to_do() {
let prep_ctx = PreprocessContext {
array_pos: self.obs_context.array_position,
phase_centre: self.obs_context.phase_centre,
correct_cable_lengths: self.corrections.cable_length
&& match metafits_context.cable_delays_applied {
mwalib::CableDelaysApplied::NoCableDelaysApplied => true,
mwalib::CableDelaysApplied::CableAndRecClock
| mwalib::CableDelaysApplied::CableAndRecClockAndBeamformerDipoleDelays => {
false
}
},
correct_digital_gains: self.corrections.digital_gains,
passband_gains: self.pfb_gains,
correct_geometry: self.corrections.geometric
&& matches!(
metafits_context.geometric_delays_applied,
GeometricDelaysApplied::No
),
..PreprocessContext::default()
};
let vis_sel = VisSelection {
timestep_range: timestep..timestep + 1,
coarse_chan_range,
baseline_idxs: (0..self.all_baseline_tile_pairs.len()).collect(),
};
prep_ctx
.preprocess(
&self.mwalib_context,
jones_array_tfb.view_mut(),
weight_array_tfb.view_mut(),
flag_array_tfb.view_mut(),
&vis_sel,
)
.map_err(Box::new)?;
}
unimplemented!("raw data shouldn't be processed on the SDC3 branch");
// if !self.corrections.nothing_to_do() {
// let prep_ctx = PreprocessContext {
// array_pos: self.obs_context.array_position,
// phase_centre: self.obs_context.phase_centre,
// correct_cable_lengths: self.corrections.cable_length
// && match metafits_context.cable_delays_applied {
// mwalib::CableDelaysApplied::NoCableDelaysApplied => true,
// mwalib::CableDelaysApplied::CableAndRecClock
// | mwalib::CableDelaysApplied::CableAndRecClockAndBeamformerDipoleDelays => {
// false
// }
// },
// correct_digital_gains: self.corrections.digital_gains,
// passband_gains: self.pfb_gains,
// correct_geometry: self.corrections.geometric
// && matches!(
// metafits_context.geometric_delays_applied,
// GeometricDelaysApplied::No
// ),
// ..PreprocessContext::default()
// };
// let vis_sel = VisSelection {
// timestep_range: timestep..timestep + 1,
// coarse_chan_range,
// baseline_idxs: (0..self.all_baseline_tile_pairs.len()).collect(),
// };
// prep_ctx
// .preprocess(
// &self.mwalib_context,
// jones_array_tfb.view_mut(),
// weight_array_tfb.view_mut(),
// flag_array_tfb.view_mut(),
// &vis_sel,
// )
// .map_err(Box::new)?;
// }

// Convert the data array into a vector so we can use `chunks_exact`
// below (this is 0 cost). This is measurably faster than using
Expand Down
56 changes: 27 additions & 29 deletions src/io/read/raw/pfb_gains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter, EnumString};
use thiserror::Error;

pub(crate) const DEFAULT_PFB_FLAVOUR: PfbFlavour = PfbFlavour::Jake;
pub(crate) const DEFAULT_PFB_FLAVOUR: PfbFlavour = PfbFlavour::Levine;

lazy_static::lazy_static! {
// Useful for help texts.
Expand All @@ -26,14 +26,13 @@ lazy_static::lazy_static! {
/// All available kinds of PFB gains.
#[derive(Debug, Display, Clone, Copy, EnumIter, EnumString, PartialEq, Eq)]
pub(crate) enum PfbFlavour {
/// Use the "Jake Jones" gains (200 Hz).
#[strum(serialize = "jake")]
Jake,

/// Use the "Cotter 2014" gains (10 kHz).
#[strum(serialize = "cotter2014")]
Cotter2014,
// /// Use the "Jake Jones" gains (200 Hz).
// #[strum(serialize = "jake")]
// Jake,

// /// Use the "Cotter 2014" gains (10 kHz).
// #[strum(serialize = "cotter2014")]
// Cotter2014,
/// Use the "RTS empirical" gains (40 kHz).
#[strum(serialize = "empirical")]
Empirical,
Expand All @@ -59,10 +58,9 @@ impl PfbFlavour {
// Not using any gains.
PfbFlavour::None => None,

PfbFlavour::Jake => Some(birli::passband_gains::PFB_JAKE_2022_200HZ),

PfbFlavour::Cotter2014 => Some(birli::passband_gains::PFB_COTTER_2014_10KHZ),
// PfbFlavour::Jake => Some(birli::passband_gains::PFB_JAKE_2022_200HZ),

// PfbFlavour::Cotter2014 => Some(birli::passband_gains::PFB_COTTER_2014_10KHZ),
PfbFlavour::Empirical => Some(EMPIRICAL_40KHZ.as_slice()),

PfbFlavour::Levine => Some(LEVINE_40KHZ.as_slice()),
Expand Down Expand Up @@ -150,21 +148,21 @@ pub(crate) const LEVINE_40KHZ: [f64; 32] = [
0.5082890508180502,
];

#[cfg(test)]
mod tests {
use super::PfbFlavour;

#[test]
fn test_handle_pfb() {
let result = PfbFlavour::parse("invalid_pfb");
assert!(result.is_err());

let result = PfbFlavour::parse("Cotter2014");
assert!(result.is_ok());
let flavour = result.unwrap();
assert!(matches!(flavour, PfbFlavour::Cotter2014));

let gains = flavour.get_gains().unwrap();
assert_eq!(&gains[..2], &[0.5002092286_f64, 0.5025463233]);
}
}
//#[cfg(test)]
//mod tests {
// use super::PfbFlavour;
//
// #[test]
// fn test_handle_pfb() {
// let result = PfbFlavour::parse("invalid_pfb");
// assert!(result.is_err());
//
// let result = PfbFlavour::parse("Cotter2014");
// assert!(result.is_ok());
// let flavour = result.unwrap();
// assert!(matches!(flavour, PfbFlavour::Cotter2014));
//
// let gains = flavour.get_gains().unwrap();
// assert_eq!(&gains[..2], &[0.5002092286_f64, 0.5025463233]);
// }
//}
3 changes: 2 additions & 1 deletion src/io/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub(crate) fn write_vis(
sel_baselines: unflagged_baseline_tile_pairs.to_vec(),
avg_time: time_average_factor.get(),
avg_freq: freq_average_factor.get(),
num_vis_pols: 4,
num_vis_pols: 1,
};

let sched_start_timestamp = match obsid {
Expand Down Expand Up @@ -260,6 +260,7 @@ pub(crate) fn write_vis(
tile_positions.to_vec(),
dut1,
true,
1,
);
if let Some(marlu_mwa_obs_context) = marlu_mwa_obs_context {
ms.initialize_mwa(
Expand Down
4 changes: 2 additions & 2 deletions src/solutions/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn make_solutions() -> CalibrationSolutions {
stop_threshold: Some(1e-10),
min_threshold: Some(1e-5),
raw_data_corrections: Some(RawDataCorrections {
pfb_flavour: PfbFlavour::Cotter2014,
pfb_flavour: PfbFlavour::Levine,
digital_gains: true,
cable_length: false,
geometric: false,
Expand Down Expand Up @@ -117,7 +117,7 @@ fn test_write_and_read_hyperdrive_solutions() {

assert_eq!(
sols_from_disk.raw_data_corrections.unwrap().pfb_flavour,
PfbFlavour::Cotter2014
PfbFlavour::Levine
);
assert!(sols_from_disk.raw_data_corrections.unwrap().digital_gains);
assert!(!sols_from_disk.raw_data_corrections.unwrap().cable_length);
Expand Down

0 comments on commit 390395d

Please sign in to comment.