Skip to content

Commit

Permalink
formatting, linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev McElhinney committed Mar 31, 2022
1 parent 15e9f65 commit 075ebf0
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 107 deletions.
2 changes: 1 addition & 1 deletion src/bin/hyperdrive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ fn try_main() -> Result<(), HyperdriveError> {
args,
#[cfg(feature = "cuda")]
cpu,
dry_run
dry_run,
)?;

info!("hyperdrive simulate-vis complete.");
Expand Down
5 changes: 1 addition & 4 deletions src/calibrate/solutions/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ fn make_solutions() -> CalibrationSolutions {
CalibrationSolutions {
di_jones,
flagged_tiles: flagged_tiles.into_iter().collect(),
flagged_chanblocks: flagged_chanblocks
.into_iter()
.map(|i| i as u16)
.collect(),
flagged_chanblocks: flagged_chanblocks.into_iter().map(|i| i as u16).collect(),
obsid: Some(1090008640),
start_timestamps: vec![
Epoch::from_gpst_seconds(1090008640.0),
Expand Down
2 changes: 1 addition & 1 deletion src/data_formats/uvfits/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ pub enum UvfitsReadError {
/// An IO error.
#[error("{0}")]
IO(#[from] std::io::Error),
}
}
35 changes: 21 additions & 14 deletions srclist/src/veto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

use std::collections::BTreeMap;

use log::{debug, trace, log_enabled, Level::Trace};
use log::{debug, log_enabled, trace, Level::Trace};
use marlu::{Jones, RADec};
use rayon::{iter::Either, prelude::*};
use thiserror::Error;
use marlu::{RADec, Jones};

use crate::{FluxDensity, SourceList, constants::*};
use mwa_hyperdrive_beam::{BeamError, Beam};
use mwa_hyperdrive_common::{log, rayon, thiserror, marlu};
use crate::{constants::*, FluxDensity, SourceList};
use mwa_hyperdrive_beam::{Beam, BeamError};
use mwa_hyperdrive_common::{log, marlu, rayon, thiserror};

/// This function mutates the input source list, removing any sources that have
/// components below the elevation limit, components that are too far from the
Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn veto_sources(
// `fd` is the sum of the source's component XX+YY flux
// densities at this coarse-channel frequency.
let mut fd = 0.0;

for (comp, azel) in source.components.iter().zip(azels.iter()) {
// Get the beam response at this source position and
// frequency.
Expand All @@ -110,7 +110,7 @@ pub fn veto_sources(
let comp_fd = comp.estimate_at_freq(cc_freq);
fd += get_beam_attenuated_flux_density(&comp_fd, j);
}

if fd < veto_threshold {
if log_enabled!(Trace) {
trace!(
Expand Down Expand Up @@ -143,7 +143,8 @@ pub fn veto_sources(
source_list.par_sort_unstable_by(|a_key, _, b_key, _| {
let a_brightness = not_vetoed_sources[a_key];
let b_brightness = not_vetoed_sources[b_key];
b_brightness.partial_cmp(&a_brightness)
b_brightness
.partial_cmp(&a_brightness)
// No NaNs should be here.
.unwrap()
});
Expand All @@ -153,7 +154,9 @@ pub fn veto_sources(
if let Some(n) = num_sources {
if source_list.len() > n {
// Add the not-top-N sources into `vetoed_sources`.
source_list.drain(n..).for_each(|(name, _)| vetoed_sources.push(name));
source_list
.drain(n..)
.for_each(|(name, _)| vetoed_sources.push(name));
}
}

Expand Down Expand Up @@ -212,14 +215,16 @@ pub enum VetoError {
mod tests {
use std::ops::Deref;

use mwa_hyperdrive_beam::{Delays, create_fee_beam_object, create_no_beam_object};
use marlu::{AzEl, constants::MWA_LAT_RAD};
use approx::assert_abs_diff_eq;
use marlu::{constants::MWA_LAT_RAD, AzEl};
use mwa_hyperdrive_beam::{create_fee_beam_object, create_no_beam_object, Delays};
use serial_test::*;
use vec1::vec1;

use super::*;
use crate::{ComponentType, FluxDensityType, Source, SourceComponent, read::read_source_list_file};
use crate::{
read::read_source_list_file, ComponentType, FluxDensityType, Source, SourceComponent,
};
use mwa_hyperdrive_common::vec1;

#[test]
Expand Down Expand Up @@ -249,7 +254,8 @@ mod tests {
#[serial]
fn test_beam_attenuated_flux_density_fee_beam() {
let beam_file: Option<&str> = None;
let beam = create_fee_beam_object(beam_file, 1, Delays::Partial(vec![0; 16]), None).unwrap();
let beam =
create_fee_beam_object(beam_file, 1, Delays::Partial(vec![0; 16]), None).unwrap();
let jones_pointing_centre = beam
.calc_jones(AzEl::new_degrees(0.0, 89.0), 180e6, 0)
.unwrap();
Expand All @@ -274,7 +280,8 @@ mod tests {
#[serial]
fn veto() {
let beam_file: Option<&str> = None;
let beam = create_fee_beam_object(beam_file, 1, Delays::Partial(vec![0; 16]), None).unwrap();
let beam =
create_fee_beam_object(beam_file, 1, Delays::Partial(vec![0; 16]), None).unwrap();
let (mut source_list, _) = read_source_list_file("../test_files/1090008640/srclist_pumav3_EoR0aegean_EoR1pietro+ForA_1090008640_peel100.txt", None).unwrap();

// For testing's sake, keep only the following bright sources.
Expand Down
46 changes: 18 additions & 28 deletions tests/integration/calibrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
mod cli_args;

use approx::assert_abs_diff_eq;
use mwa_hyperdrive_beam::Delays;
use mwa_hyperdrive_common::{
clap::Parser,
mwalib::{fitsio_sys, *}, hifitime::Epoch,
};
use mwa_hyperdrive_common::{clap::Parser, mwalib::*};
use serial_test::serial;

use crate::*;
Expand All @@ -25,16 +21,13 @@ fn test_no_stderr() {
let args = get_reduced_1090008640(true, false);
let data = args.data.unwrap();

#[rustfmt::skip]
let cmd = hyperdrive()
.args(&[
"di-calibrate",
"--data",
&data[0],
&data[1],
"--source-list",
&args.source_list.unwrap(),
"--outputs",
&format!("{}", sols.display()),
"--data", &data[0], &data[1],
"--source-list", &args.source_list.unwrap(),
"--outputs", &format!("{}", sols.display()),
])
.ok();
assert!(cmd.is_ok(), "di-calibrate failed on simple test data!");
Expand All @@ -53,17 +46,13 @@ fn test_1090008640_di_calibrate_writes_solutions() {
let sols = tmp_dir.join("sols.fits");
let cal_model = tmp_dir.join("hyp_model.uvfits");

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

// Run di-cal and check that it succeeds
Expand All @@ -83,14 +72,12 @@ fn test_1090008640_woden() {

// Reading from a uvfits file without a metafits file should fail because
// there's no beam information.
#[rustfmt::skip]
let cal_args = CalibrateUserArgs::parse_from(&[
"di-calibrate",
"--data",
"test_files/1090008640_WODEN/output_band01.uvfits",
"--source-list",
"test_files/1090008640_WODEN/srclist_3x3_grid.txt",
"--outputs",
&format!("{}", solutions_path.display()),
"--data", "test_files/1090008640_WODEN/output_band01.uvfits",
"--source-list", "test_files/1090008640_WODEN/srclist_3x3_grid.txt",
"--outputs", &format!("{}", solutions_path.display()),
]);

// Run di-cal and check that it fails
Expand Down Expand Up @@ -233,7 +220,10 @@ fn test_1090008640_di_calibrate_writes_vis_uvfits_noautos() {
let mut out_vis = fits_open!(&out_vis_path).unwrap();
let hdu0 = fits_open_hdu!(&mut out_vis, 0).unwrap();
let gcount: String = get_required_fits_key!(&mut out_vis, &hdu0, "GCOUNT").unwrap();
assert_eq!(gcount.parse::<usize>().unwrap(), exp_timesteps * exp_baselines);
assert_eq!(
gcount.parse::<usize>().unwrap(),
exp_timesteps * exp_baselines
);
// let pcount: String = get_required_fits_key!(&mut out_vis, &hdu0, "PCOUNT").unwrap();
// assert_eq!(pcount.parse::<usize>().unwrap(), 5);
// let floats_per_pol: String = get_required_fits_key!(&mut out_vis, &hdu0, "NAXIS2").unwrap();
Expand Down
30 changes: 11 additions & 19 deletions tests/integration/modelling/calibrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@ fn test_1090008640_calibrate_model() {
let args = get_reduced_1090008640(true, false);
let metafits = &args.data.as_ref().unwrap()[0];
let srclist = args.source_list.unwrap();
#[rustfmt::skip]
let sim_args = SimulateVisArgs::parse_from(&[
"simulate-vis",
"--metafits",
metafits,
"--source-list",
&srclist,
"--output-model-file",
&format!("{}", model.display()),
"--num-timesteps",
&format!("{}", num_timesteps),
"--num-fine-channels",
&format!("{}", num_chans),
"--metafits", metafits,
"--source-list", &srclist,
"--output-model-file", &format!("{}", model.display()),
"--num-timesteps", &format!("{}", num_timesteps),
"--num-fine-channels", &format!("{}", num_chans),
]);

// Run simulate-vis and check that it succeeds
Expand All @@ -60,17 +56,13 @@ fn test_1090008640_calibrate_model() {
let mut cal_model = temp_dir;
cal_model.push("cal_model.uvfits");

#[rustfmt::skip]
let cal_args = CalibrateUserArgs::parse_from(&[
"di-calibrate",
"--data",
&format!("{}", model.display()),
metafits,
"--source-list",
&srclist,
"--outputs",
&format!("{}", sols.display()),
"--model-filename",
&format!("{}", cal_model.display()),
"--data", &format!("{}", model.display()), metafits,
"--source-list", &srclist,
"--outputs", &format!("{}", sols.display()),
"--model-filename", &format!("{}", cal_model.display()),
"--ignore-autos",
]);

Expand Down
64 changes: 24 additions & 40 deletions tests/integration/modelling/simulate_vis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,15 @@ fn test_no_stderr() {
let args = get_reduced_1090008640(true, false);
let metafits = args.data.as_ref().unwrap()[0].clone();

#[rustfmt::skip]
let cmd = hyperdrive()
.args(&[
"simulate-vis",
"--metafits",
&metafits,
"--source-list",
&args.source_list.unwrap(),
"--output-model-file",
&format!("{}", output_path.display()),
"--num-timesteps",
&format!("{}", num_timesteps),
"--num-fine-channels",
&format!("{}", num_chans),
"--metafits", &metafits,
"--source-list", &args.source_list.unwrap(),
"--output-model-file", &format!("{}", output_path.display()),
"--num-timesteps", &format!("{}", num_timesteps),
"--num-fine-channels", &format!("{}", num_chans),
])
.ok();
assert!(cmd.is_ok(), "simulate-vis failed on simple test data!");
Expand All @@ -95,18 +91,14 @@ fn test_1090008640_simulate_vis() {
let args = get_reduced_1090008640(true, false);
let metafits = args.data.as_ref().unwrap()[0].clone();

#[rustfmt::skip]
let sim_args = SimulateVisArgs::parse_from(&[
"simulate-vis",
"--metafits",
&metafits,
"--source-list",
&args.source_list.unwrap(),
"--output-model-file",
&format!("{}", output_path.display()),
"--num-timesteps",
&format!("{}", num_timesteps),
"--num-fine-channels",
&format!("{}", num_chans),
"--metafits", &metafits,
"--source-list", &args.source_list.unwrap(),
"--output-model-file", &format!("{}", output_path.display()),
"--num-timesteps", &format!("{}", num_timesteps),
"--num-fine-channels", &format!("{}", num_chans),
]);

// Run simulate-vis and check that it succeeds
Expand Down Expand Up @@ -306,18 +298,14 @@ fn test_1090008640_simulate_vis_cpu_gpu_match() {
output_path.push("model.uvfits");
let args = get_reduced_1090008640(true, false);
let metafits = args.data.as_ref().unwrap()[0].clone();
#[rustfmt::skip]
let sim_args = SimulateVisArgs::parse_from(&[
"simulate-vis",
"--metafits",
&metafits,
"--source-list",
&args.source_list.unwrap(),
"--output-model-file",
&format!("{}", output_path.display()),
"--num-timesteps",
&format!("{}", num_timesteps),
"--num-fine-channels",
&format!("{}", num_chans),
"--metafits", &metafits,
"--source-list", &args.source_list.unwrap(),
"--output-model-file", &format!("{}", output_path.display()),
"--num-timesteps", &format!("{}", num_timesteps),
"--num-fine-channels", &format!("{}", num_chans),
"--cpu",
]);
let result = simulate_vis(sim_args, true, false);
Expand Down Expand Up @@ -356,18 +344,14 @@ fn test_1090008640_simulate_vis_cpu_gpu_match() {

let args = get_reduced_1090008640(true, false);
let metafits = args.data.as_ref().unwrap()[0].clone();
#[rustfmt::skip]
let sim_args = SimulateVisArgs::parse_from(&[
"simulate-vis",
"--metafits",
&metafits,
"--source-list",
&args.source_list.unwrap(),
"--output-model-file",
&format!("{}", output_path.display()),
"--num-timesteps",
&format!("{}", num_timesteps),
"--num-fine-channels",
&format!("{}", num_chans),
"--metafits", &metafits,
"--source-list", &args.source_list.unwrap(),
"--output-model-file", &format!("{}", output_path.display()),
"--num-timesteps", &format!("{}", num_timesteps),
"--num-fine-channels", &format!("{}", num_chans),
]);

// Run simulate-vis and check that it succeeds
Expand Down

0 comments on commit 075ebf0

Please sign in to comment.