Skip to content

Commit

Permalink
allow negative array coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev McElhinney committed Apr 4, 2022
1 parent 323ee16 commit c778841
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/calibrate/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ pub struct CalibrateUserArgs {
#[clap(long, help = SOURCE_LIST_TYPE_HELP.as_str(), help_heading = "INPUT FILES")]
pub source_list_type: Option<String>,

#[clap(short, long, multiple_values(true), help = DI_CALIBRATE_OUTPUT_HELP.as_str(), help_heading = "OUTPUT FILES")]
#[clap(
short, long, multiple_values(true), help = DI_CALIBRATE_OUTPUT_HELP.as_str(),
help_heading = "OUTPUT FILES"
)]
pub outputs: Option<Vec<PathBuf>>,

#[clap(short, long, help = MODEL_FILENAME_HELP.as_str(), help_heading = "OUTPUT FILES")]
Expand Down Expand Up @@ -203,7 +206,12 @@ pub struct CalibrateUserArgs {
#[clap(long, help = MIN_THRESHOLD_HELP.as_str(), help_heading = "CALIBRATION")]
pub min_thresh: Option<f64>,

#[clap(long, help = ARRAY_POSITION_HELP.as_str(), help_heading = "CALIBRATION", number_of_values=3)]
#[clap(
long, help = ARRAY_POSITION_HELP.as_str(), help_heading = "CALIBRATION",
number_of_values = 3,
allow_hyphen_values = true,
value_names = &["LONG_RAD", "LAT_RAD", "HEIGHT_M"]
)]
pub array_position: Option<Vec<f64>>,

#[cfg(feature = "cuda")]
Expand Down
3 changes: 1 addition & 2 deletions src/calibrate/params/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ pub(crate) struct CalibrateParams {
/// layout.
pub(crate) unflagged_tile_xyzs: Vec<XyzGeodetic>,

/// The Earth latitude, longitude and height of the array. This is populated by user
/// input or the input data.
/// The Earth position of the array. This is populated by user input or the input data.
pub(crate) array_position: LatLngHeight,

/// The maximum number of times to iterate when performing "MitchCal".
Expand Down
71 changes: 71 additions & 0 deletions tests/integration/calibrate/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

//! Tests against the command-line interface for calibration.

use approx::assert_abs_diff_eq;
use mwa_hyperdrive_common::{
clap::{ErrorKind::WrongNumberOfValues, Parser},
marlu::constants::{MWA_HEIGHT_M, MWA_LAT_DEG, MWA_LONG_DEG},
};

use crate::*;

#[test]
Expand All @@ -24,3 +30,68 @@ fn test_calibrate_help_is_correct() {
assert!(stdout.contains("di-calibrate"));
assert!(stdout.contains("Perform direction-independent calibration on the input MWA data"));
}

#[test]
fn test_1090008640_di_calibrate_uses_array_position() {
let tmp_dir = TempDir::new().expect("couldn't make tmp dir").into_path();
let args = get_reduced_1090008640(true, false);
let data = args.data.unwrap();
let metafits = &data[0];
let gpufits = &data[1];
let sols = tmp_dir.join("sols.fits");
let cal_model = tmp_dir.join("hyp_model.uvfits");

// with non-default array position
let exp_lat_deg = MWA_LAT_DEG - 1.;
let exp_long_deg = MWA_LONG_DEG - 1.;
let exp_height_m = MWA_HEIGHT_M - 1.;

#[rustfmt::skip]
let cal_args = CalibrateUserArgs::parse_from(&[
"di-calibrate",
"--data", metafits, gpufits,
"--source-list", args.source_list.as_ref().unwrap(),
"--outputs", &format!("{}", sols.display()),
"--model-filename", &format!("{}", cal_model.display()),
"--array-position",
&format!("{}", exp_long_deg),
&format!("{}", exp_lat_deg),
&format!("{}", exp_height_m),
]);

let pos = cal_args.array_position.unwrap();

assert_abs_diff_eq!(pos[0], exp_long_deg);
assert_abs_diff_eq!(pos[1], exp_lat_deg);
assert_abs_diff_eq!(pos[2], exp_height_m);
}

#[test]
fn test_1090008640_di_calibrate_array_pos_requires_3_args() {
let tmp_dir = TempDir::new().expect("couldn't make tmp dir").into_path();
let args = get_reduced_1090008640(true, false);
let data = args.data.unwrap();
let metafits = &data[0];
let gpufits = &data[1];
let sols = tmp_dir.join("sols.fits");
let cal_model = tmp_dir.join("hyp_model.uvfits");

// no height specified
let exp_lat_deg = MWA_LAT_DEG - 1.;
let exp_long_deg = MWA_LONG_DEG - 1.;

#[rustfmt::skip]
let result = CalibrateUserArgs::try_parse_from(&[
"di-calibrate",
"--data", metafits, gpufits,
"--source-list", args.source_list.as_ref().unwrap(),
"--outputs", &format!("{}", sols.display()),
"--model-filename", &format!("{}", cal_model.display()),
"--array-position",
&format!("{}", exp_long_deg),
&format!("{}", exp_lat_deg),
]);

assert!(result.is_err());
assert!(matches!(result.err().unwrap().kind(), WrongNumberOfValues));
}

0 comments on commit c778841

Please sign in to comment.