diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fd8c1c..f6581e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ Changes in each release are listed below. +## 0.6.1 08-Mar-2021 (Pre-release) + +* Fixed za (zenith angle) calculation. +* Added more comprehensive testing for some coarse_channel methods. +* Addressed many clippy lints. + ## 0.6.0 05-Mar-2021 (Pre-release) * Minor updates to enable packaging and deployment to crates.io. diff --git a/Cargo.toml b/Cargo.toml index 11fd690..49783bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mwalib" -version = "0.6.0" +version = "0.6.1" homepage = "https://github.com/MWATelescope/mwalib" repository = "https://github.com/MWATelescope/mwalib" readme = "README.md" diff --git a/src/coarse_channel/test.rs b/src/coarse_channel/test.rs index 6341423..6a238d9 100644 --- a/src/coarse_channel/test.rs +++ b/src/coarse_channel/test.rs @@ -259,6 +259,15 @@ fn test_process_coarse_chans_no_time_maps_legacy() { let coarse_chan_array = result.unwrap(); assert_eq!(coarse_chan_array.len(), 3); + assert_eq!(coarse_chan_array[0].rec_chan_number, 133); + assert_eq!(coarse_chan_array[0].corr_chan_number, 2); + assert_eq!(coarse_chan_array[0].gpubox_number, 3); + assert_eq!(coarse_chan_array[1].rec_chan_number, 134); + assert_eq!(coarse_chan_array[1].corr_chan_number, 1); + assert_eq!(coarse_chan_array[1].gpubox_number, 2); + assert_eq!(coarse_chan_array[2].rec_chan_number, 135); + assert_eq!(coarse_chan_array[2].corr_chan_number, 0); + assert_eq!(coarse_chan_array[2].gpubox_number, 1); } #[test] @@ -280,6 +289,15 @@ fn test_process_coarse_chans_no_time_maps_mwax_v2() { let coarse_chan_array = result.unwrap(); assert_eq!(coarse_chan_array.len(), 3); + assert_eq!(coarse_chan_array[0].rec_chan_number, 133); + assert_eq!(coarse_chan_array[0].corr_chan_number, 0); + assert_eq!(coarse_chan_array[0].gpubox_number, 133); + assert_eq!(coarse_chan_array[1].rec_chan_number, 134); + assert_eq!(coarse_chan_array[1].corr_chan_number, 1); + assert_eq!(coarse_chan_array[1].gpubox_number, 134); + assert_eq!(coarse_chan_array[2].rec_chan_number, 135); + assert_eq!(coarse_chan_array[2].corr_chan_number, 2); + assert_eq!(coarse_chan_array[2].gpubox_number, 135); } #[test] diff --git a/src/correlator_context/mod.rs b/src/correlator_context/mod.rs index f29f729..dfd28c9 100644 --- a/src/correlator_context/mod.rs +++ b/src/correlator_context/mod.rs @@ -61,7 +61,7 @@ pub struct CorrelatorContext { /// corresponds directly to other gpubox-related objects /// (e.g. `gpubox_hdu_limits`). Structured: /// `gpubox_batches[batch][filename]`. - pub(crate) gpubox_batches: Vec, + pub(crate) gpubox_batches: Vec, /// We assume as little as possible about the data layout in the gpubox /// files; here, a `BTreeMap` contains each unique UNIX time from every /// gpubox, which is associated with another `BTreeMap`, associating each diff --git a/src/correlator_context/test.rs b/src/correlator_context/test.rs index c85082d..69fe473 100644 --- a/src/correlator_context/test.rs +++ b/src/correlator_context/test.rs @@ -338,6 +338,7 @@ fn test_validate_hdu_axes_naxis_mismatches_oldlegacy() { let metafits_fine_chans_per_coarse = 128; let metafits_baselines = 8256; let visibility_pols = 4; + let values = 1; // Check for NAXIS1 mismatch let result_bad1 = CorrelatorContext::validate_hdu_axes( @@ -345,7 +346,7 @@ fn test_validate_hdu_axes_naxis_mismatches_oldlegacy() { metafits_fine_chans_per_coarse, metafits_baselines, visibility_pols, - 8256 * 4 * 1, + metafits_baselines * visibility_pols * values, 128, ); @@ -385,6 +386,7 @@ fn test_validate_hdu_axes_naxis_mismatches_legacy() { let metafits_fine_chans_per_coarse = 128; let metafits_baselines = 8256; let visibility_pols = 4; + let values = 1; // Check for NAXIS1 mismatch let result_bad1 = CorrelatorContext::validate_hdu_axes( @@ -392,7 +394,7 @@ fn test_validate_hdu_axes_naxis_mismatches_legacy() { metafits_fine_chans_per_coarse, metafits_baselines, visibility_pols, - 8256 * 4 * 1, + metafits_baselines * visibility_pols * values, 128, ); @@ -432,6 +434,7 @@ fn test_validate_hdu_axes_naxis_mismatches_v2() { let metafits_fine_chans_per_coarse = 128; let metafits_baselines = 8256; let visibility_pols = 4; + let values = 2; // Check for NAXIS1 mismatch let result_bad1 = CorrelatorContext::validate_hdu_axes( @@ -439,7 +442,7 @@ fn test_validate_hdu_axes_naxis_mismatches_v2() { metafits_fine_chans_per_coarse, metafits_baselines, visibility_pols, - 128 * 4 * 1, + metafits_fine_chans_per_coarse * visibility_pols, 8256, ); @@ -460,7 +463,7 @@ fn test_validate_hdu_axes_naxis_mismatches_v2() { metafits_fine_chans_per_coarse, metafits_baselines, visibility_pols, - 128 * 4 * 2, + metafits_fine_chans_per_coarse * visibility_pols * values, 8257, ); diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index 491bc96..8e8757f 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -1847,7 +1847,6 @@ pub unsafe extern "C" fn mwalib_coarse_channels_free( /// Representation in C of an `RFInput` struct #[repr(C)] -#[allow(clippy::upper_case_acronyms)] pub struct RFInput { /// This is the metafits order (0-n inputs) pub input: u32, diff --git a/src/fits_read/test.rs b/src/fits_read/test.rs index ef353ed..20e12af 100644 --- a/src/fits_read/test.rs +++ b/src/fits_read/test.rs @@ -12,6 +12,7 @@ use crate::*; use fitsio::images::{ImageDescription, ImageType}; use fitsio::tables::{ColumnDataType, ColumnDescription}; use fitsio_sys::ffpkls; +use float_cmp::*; #[test] fn test_get_hdu_image_size_image() { @@ -296,7 +297,7 @@ fn test_1101503312_metafits() -> Result<(), FitsError> { let mut fptr = fits_open!(&metafits)?; let hdu = fits_open_hdu!(&mut fptr, 0)?; let freq_centre: f64 = get_required_fits_key!(&mut fptr, &hdu, "FREQCENT")?; - assert_eq!(freq_centre, 154.24); + assert!(approx_eq!(f64, freq_centre, 154.24, F64Margin::default())); let fine_chan_width: u8 = get_required_fits_key!(&mut fptr, &hdu, "FINECHAN")?; assert_eq!(fine_chan_width, 10); @@ -311,7 +312,7 @@ fn test_1101503312_metafits() -> Result<(), FitsError> { let hdu = fits_open_hdu!(&mut fptr, 1)?; let east: Vec = get_fits_col!(&mut fptr, &hdu, "East")?; - assert_eq!(east[0], -585.675); + assert!(approx_eq!(f32, east[0], -585.675, F32Margin::default())); let doesnt_exist: Result, FitsError> = get_fits_col!(&mut fptr, &hdu, "South"); assert!(doesnt_exist.is_err()); Ok(()) @@ -323,7 +324,7 @@ fn test_1244973688_metafits() -> Result<(), FitsError> { let mut fptr = fits_open!(&metafits)?; let hdu = fits_open_hdu!(&mut fptr, 0)?; let freq_centre: f64 = get_required_fits_key!(&mut fptr, &hdu, "FREQCENT")?; - assert_eq!(freq_centre, 147.84); + assert!(approx_eq!(f64, freq_centre, 147.84, F64Margin::default())); let fine_chan_width: u8 = get_required_fits_key!(&mut fptr, &hdu, "FINECHAN")?; assert_eq!(fine_chan_width, 10); @@ -338,7 +339,7 @@ fn test_1244973688_metafits() -> Result<(), FitsError> { let hdu = fits_open_hdu!(&mut fptr, 1)?; let east: Vec = get_fits_col!(&mut fptr, &hdu, "East")?; - assert_eq!(east[0], -585.675); + assert!(approx_eq!(f32, east[0], -585.675, F32Margin::default())); let doesnt_exist: Result, FitsError> = get_fits_col!(&mut fptr, &hdu, "South"); assert!(doesnt_exist.is_err()); Ok(()) diff --git a/src/gpubox_files/error.rs b/src/gpubox_files/error.rs index 7290b08..28b35a2 100644 --- a/src/gpubox_files/error.rs +++ b/src/gpubox_files/error.rs @@ -9,7 +9,6 @@ Errors associated with reading in gpubox files. use thiserror::Error; #[derive(Error, Debug)] -#[allow(clippy::upper_case_acronyms)] pub enum GpuboxError { #[error("Invalid timestep index provided. The timestep index must be between 0 and {0}")] InvalidTimeStepIndex(usize), diff --git a/src/gpubox_files/mod.rs b/src/gpubox_files/mod.rs index c1048a4..0b082fc 100644 --- a/src/gpubox_files/mod.rs +++ b/src/gpubox_files/mod.rs @@ -30,13 +30,12 @@ pub(crate) struct ObsTimes { /// This represents one group of gpubox files with the same "batch" identitifer. /// e.g. obsid_datetime_chan_batch -#[allow(clippy::upper_case_acronyms)] -pub(crate) struct GPUBoxBatch { +pub(crate) struct GpuBoxBatch { pub batch_number: usize, // 00,01,02..n - pub gpubox_files: Vec, // Vector storing the details of each gpubox file in this batch + pub gpubox_files: Vec, // Vector storing the details of each gpubox file in this batch } -impl GPUBoxBatch { +impl GpuBoxBatch { pub fn new(batch_number: usize) -> Self { Self { batch_number, @@ -45,7 +44,7 @@ impl GPUBoxBatch { } } -impl fmt::Debug for GPUBoxBatch { +impl fmt::Debug for GpuBoxBatch { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, @@ -56,15 +55,14 @@ impl fmt::Debug for GPUBoxBatch { } /// This represents one gpubox file -#[allow(clippy::upper_case_acronyms)] -pub(crate) struct GPUBoxFile { +pub(crate) struct GpuBoxFile { /// Filename of gpubox file pub filename: String, /// channel number (Legacy==gpubox host number 01..24; V2==receiver channel number 001..255) pub channel_identifier: usize, } -impl fmt::Debug for GPUBoxFile { +impl fmt::Debug for GpuBoxFile { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, @@ -74,13 +72,13 @@ impl fmt::Debug for GPUBoxFile { } } -impl std::cmp::PartialEq for GPUBoxBatch { +impl std::cmp::PartialEq for GpuBoxBatch { fn eq(&self, other: &Self) -> bool { self.batch_number == other.batch_number && self.gpubox_files == other.gpubox_files } } -impl std::cmp::PartialEq for GPUBoxFile { +impl std::cmp::PartialEq for GpuBoxFile { fn eq(&self, other: &Self) -> bool { self.filename == other.filename && self.channel_identifier == other.channel_identifier } @@ -88,8 +86,7 @@ impl std::cmp::PartialEq for GPUBoxFile { /// A temporary representation of a gpubox file #[derive(Clone, Debug)] -#[allow(clippy::upper_case_acronyms)] -struct TempGPUBoxFile<'a> { +struct TempGpuBoxFile<'a> { /// Filename of gpubox file filename: &'a str, /// Channel number (Legacy==gpubox host number 01..24; V2==receiver channel number 001..255) @@ -98,7 +95,7 @@ struct TempGPUBoxFile<'a> { batch_number: usize, } -impl<'a> std::cmp::PartialEq for TempGPUBoxFile<'a> { +impl<'a> std::cmp::PartialEq for TempGpuBoxFile<'a> { fn eq(&self, other: &Self) -> bool { self.filename == other.filename && self.channel_identifier == other.channel_identifier @@ -135,7 +132,7 @@ pub(crate) type GpuboxTimeMap = BTreeMap>; /// A little struct to help us not get confused when dealing with the returned /// values from complex functions. pub(crate) struct GpuboxInfo { - pub batches: Vec, + pub batches: Vec, pub corr_format: CorrelatorVersion, pub time_map: GpuboxTimeMap, pub hdu_size: usize, @@ -161,17 +158,17 @@ pub(crate) struct GpuboxInfo { /// * A Result containing a vector of `GPUBoxBatch`. /// /// -fn convert_temp_gpuboxes(temp_gpuboxes: Vec) -> Vec { +fn convert_temp_gpuboxes(temp_gpuboxes: Vec) -> Vec { // unwrap is safe as a check is performed above to ensure that there are // some files present. let num_batches = temp_gpuboxes.iter().map(|g| g.batch_number).max().unwrap() + 1; - let mut gpubox_batches: Vec = Vec::with_capacity(num_batches); + let mut gpubox_batches: Vec = Vec::with_capacity(num_batches); for b in 0..num_batches { - gpubox_batches.push(GPUBoxBatch::new(b)); + gpubox_batches.push(GpuBoxBatch::new(b)); } for temp_g in temp_gpuboxes.into_iter() { - let g = GPUBoxFile { + let g = GpuBoxFile { filename: temp_g.filename.to_string(), channel_identifier: temp_g.channel_identifier, }; @@ -309,12 +306,12 @@ pub(crate) fn examine_gpubox_files>( /// fn determine_gpubox_batches>( gpubox_filenames: &[T], -) -> Result<(Vec, CorrelatorVersion, usize), GpuboxError> { +) -> Result<(Vec, CorrelatorVersion, usize), GpuboxError> { if gpubox_filenames.is_empty() { return Err(GpuboxError::NoGpuboxes); } let mut format = None; - let mut temp_gpuboxes: Vec = Vec::with_capacity(gpubox_filenames.len()); + let mut temp_gpuboxes: Vec = Vec::with_capacity(gpubox_filenames.len()); for g_path in gpubox_filenames { // So that we can pass along useful error messages, convert the input @@ -338,7 +335,7 @@ fn determine_gpubox_batches>( // The following unwraps are safe, because the regex wouldn't // work if they couldn't be parsed into ints. - temp_gpuboxes.push(TempGPUBoxFile { + temp_gpuboxes.push(TempGpuBoxFile { filename: g, channel_identifier: caps["channel"].parse().unwrap(), batch_number: caps["batch"].parse().unwrap(), @@ -354,7 +351,7 @@ fn determine_gpubox_batches>( _ => return Err(GpuboxError::Mixture), } - temp_gpuboxes.push(TempGPUBoxFile { + temp_gpuboxes.push(TempGpuBoxFile { filename: g, channel_identifier: caps["band"].parse().unwrap(), batch_number: caps["batch"].parse().unwrap(), @@ -370,7 +367,7 @@ fn determine_gpubox_batches>( _ => return Err(GpuboxError::Mixture), } - temp_gpuboxes.push(TempGPUBoxFile { + temp_gpuboxes.push(TempGpuBoxFile { filename: g, channel_identifier: caps["band"].parse().unwrap(), // There's only one batch. @@ -596,7 +593,7 @@ fn validate_gpubox_metadata_obs_id( /// /// fn create_time_map( - gpuboxes: &[TempGPUBoxFile], + gpuboxes: &[TempGpuBoxFile], correlator_version: CorrelatorVersion, ) -> Result { // Ugly hack to open up all the HDUs of the gpubox files in parallel. We diff --git a/src/gpubox_files/test.rs b/src/gpubox_files/test.rs index c3a6f5e..27de260 100644 --- a/src/gpubox_files/test.rs +++ b/src/gpubox_files/test.rs @@ -25,17 +25,17 @@ fn test_determine_gpubox_batches_proper_format() { assert_eq!(num_batches, 3); let expected_gpuboxes = vec![ - TempGPUBoxFile { + TempGpuBoxFile { filename: "1065880128_20131015134930_gpubox01_00.fits", channel_identifier: 1, batch_number: 0, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "1065880128_20131015134930_gpubox20_01.fits", channel_identifier: 20, batch_number: 1, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "1065880128_20131015134930_gpubox15_02.fits", channel_identifier: 15, batch_number: 2, @@ -58,17 +58,17 @@ fn test_determine_gpubox_batches_proper_format2() { assert_eq!(corr_format, CorrelatorVersion::Legacy); assert_eq!(num_batches, 3); let expected_batches = vec![ - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134930_gpubox01_00.fits", channel_identifier: 1, batch_number: 0, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/gs/1065880128_20131015134930_gpubox20_01.fits", channel_identifier: 20, batch_number: 1, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "/var/cache/1065880128_20131015134930_gpubox15_02.fits", channel_identifier: 15, batch_number: 2, @@ -95,32 +95,32 @@ fn test_determine_gpubox_batches_proper_format3() { assert_eq!(num_batches, 3); let expected_batches = vec![ - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134930_gpubox01_00.fits", channel_identifier: 1, batch_number: 0, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134930_gpubox02_00.fits", channel_identifier: 2, batch_number: 0, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134930_gpubox19_01.fits", channel_identifier: 19, batch_number: 1, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134930_gpubox20_01.fits", channel_identifier: 20, batch_number: 1, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134930_gpubox14_02.fits", channel_identifier: 14, batch_number: 2, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134930_gpubox15_02.fits", channel_identifier: 15, batch_number: 2, @@ -147,32 +147,32 @@ fn test_determine_gpubox_batches_proper_format4() { assert_eq!(num_batches, 3); let expected_batches = vec![ - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134930_gpubox01_00.fits", channel_identifier: 1, batch_number: 0, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134929_gpubox02_00.fits", channel_identifier: 2, batch_number: 0, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134930_gpubox19_01.fits", channel_identifier: 19, batch_number: 1, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134929_gpubox20_01.fits", channel_identifier: 20, batch_number: 1, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134931_gpubox14_02.fits", channel_identifier: 14, batch_number: 2, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "/home/chj/1065880128_20131015134930_gpubox15_02.fits", channel_identifier: 15, batch_number: 2, @@ -242,17 +242,17 @@ fn test_determine_gpubox_batches_old_format() { assert_eq!(num_batches, 1); let expected_batches = vec![ - TempGPUBoxFile { + TempGpuBoxFile { filename: "1065880128_20131015134930_gpubox01.fits", channel_identifier: 1, batch_number: 0, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "1065880128_20131015134930_gpubox15.fits", channel_identifier: 15, batch_number: 0, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "1065880128_20131015134930_gpubox20.fits", channel_identifier: 20, batch_number: 0, @@ -277,22 +277,22 @@ fn test_determine_gpubox_batches_new_format() { assert_eq!(num_batches, 2); let expected_batches = vec![ - TempGPUBoxFile { + TempGpuBoxFile { filename: "1065880128_20131015134930_ch101_000.fits", channel_identifier: 101, batch_number: 0, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "1065880128_20131015134930_ch102_000.fits", channel_identifier: 102, batch_number: 0, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "1065880128_20131015135030_ch101_001.fits", channel_identifier: 101, batch_number: 1, }, - TempGPUBoxFile { + TempGpuBoxFile { filename: "1065880128_20131015135030_ch102_001.fits", channel_identifier: 102, batch_number: 1, diff --git a/src/misc/test.rs b/src/misc/test.rs index 12759ef..88d411b 100644 --- a/src/misc/test.rs +++ b/src/misc/test.rs @@ -44,25 +44,25 @@ where #[test] fn test_convert_gpstime_to_unixtime() { // Tested using https://www.andrews.edu/~tzs/timeconv/timedisplay.php - let gpstime_ms = 1298013490_000; - let mwa_start_gpstime_ms = 1242552568_000; - let mwa_start_unixtime_ms = 1558517350_000; + let gpstime_ms = 1_298_013_490_000; + let mwa_start_gpstime_ms = 1_242_552_568_000; + let mwa_start_unixtime_ms = 1_558_517_350_000; let new_unixtime_ms = convert_gpstime_to_unixtime(gpstime_ms, mwa_start_gpstime_ms, mwa_start_unixtime_ms); - assert_eq!(new_unixtime_ms, 1613978272_000); + assert_eq!(new_unixtime_ms, 1_613_978_272_000); } #[test] fn test_convert_unixtime_to_gpstime() { // Tested using https://www.andrews.edu/~tzs/timeconv/timedisplay.php - let unixtime_ms = 1613978272_000; - let mwa_start_gpstime_ms = 1242552568_000; - let mwa_start_unixtime_ms = 1558517350_000; + let unixtime_ms = 1_613_978_272_000; + let mwa_start_gpstime_ms = 1_242_552_568_000; + let mwa_start_unixtime_ms = 1_558_517_350_000; let new_unixtime_ms = convert_unixtime_to_gpstime(unixtime_ms, mwa_start_gpstime_ms, mwa_start_unixtime_ms); - assert_eq!(new_unixtime_ms, 1298013490_000); + assert_eq!(new_unixtime_ms, 1_298_013_490_000); } #[test] diff --git a/src/rfinput/mod.rs b/src/rfinput/mod.rs index 1771921..877d7cd 100644 --- a/src/rfinput/mod.rs +++ b/src/rfinput/mod.rs @@ -106,8 +106,7 @@ impl fmt::Display for Pol { } /// Structure to hold one row of the metafits tiledata table -#[allow(clippy::upper_case_acronyms)] -struct RFInputMetafitsTableRow { +struct RfInputMetafitsTableRow { /// This is the ordinal index of the rf_input in the metafits file input: u32, /// This is the antenna number. @@ -152,7 +151,6 @@ struct RFInputMetafitsTableRow { // Structure for storing MWA rf_chains (tile with polarisation) information from the metafits file #[derive(Clone)] -#[allow(clippy::upper_case_acronyms)] pub struct RFInput { /// This is the metafits order (0-n inputs) pub input: u32, @@ -220,7 +218,7 @@ impl RFInput { metafits_fptr: &mut fitsio::FitsFile, metafits_tile_table_hdu: &fitsio::hdu::FitsHdu, row: usize, - ) -> Result { + ) -> Result { let input = read_cell_value(metafits_fptr, metafits_tile_table_hdu, "Input", row)?; let antenna = read_cell_value(metafits_fptr, metafits_tile_table_hdu, "Antenna", row)?; let tile_id = read_cell_value(metafits_fptr, metafits_tile_table_hdu, "Tile", row)?; @@ -269,7 +267,7 @@ impl RFInput { .map(|&delay| if delay == 32 { 0.0 } else { 1.0 }) .collect(); - Ok(RFInputMetafitsTableRow { + Ok(RfInputMetafitsTableRow { input, antenna, tile_id, diff --git a/src/rfinput/test.rs b/src/rfinput/test.rs index d23926f..daec828 100644 --- a/src/rfinput/test.rs +++ b/src/rfinput/test.rs @@ -10,6 +10,7 @@ use super::*; use crate::misc::test::*; use crate::*; use fitsio::tables::{ColumnDataType, ColumnDescription}; +use float_cmp::*; #[test] fn test_get_vcs_order() { @@ -83,7 +84,7 @@ fn test_read_metafits_values_from_row_0() { let metafits_tile_table_hdu = fits_open_hdu!(&mut metafits_fptr, 1).unwrap(); // Get values from row 1 - let row: RFInputMetafitsTableRow = + let row: RfInputMetafitsTableRow = RFInput::read_metafits_values(&mut metafits_fptr, &metafits_tile_table_hdu, 0).unwrap(); assert_eq!(row.input, 0); assert_eq!(row.antenna, 75); @@ -94,19 +95,19 @@ fn test_read_metafits_values_from_row_0() { assert!(float_cmp::approx_eq!( f64, row.north_m, - -101.529_998_779_296_88 as f64, + -101.529_998_779_296_88, float_cmp::F64Margin::default() )); assert!(float_cmp::approx_eq!( f64, row.east_m, - -585.674_987_792_968_8 as f64, + -585.674_987_792_968_8, float_cmp::F64Margin::default() )); assert!(float_cmp::approx_eq!( f64, row.height_m, - 375.212_005_615_234_4 as f64, + 375.212_005_615_234_4, float_cmp::F64Margin::default() )); assert_eq!(row.flag, 1); @@ -167,23 +168,29 @@ fn test_populate_rf_inputs() { assert_eq!(rfinput[0].tile_id, 104); assert_eq!(rfinput[0].tile_name, "Tile104"); assert_eq!(rfinput[0].pol, Pol::Y); - assert_eq!(rfinput[0].electrical_length_m, -756.49); + assert!(approx_eq!( + f64, + rfinput[0].electrical_length_m, + -756.49, + F64Margin::default() + )); + assert!(float_cmp::approx_eq!( f64, rfinput[0].north_m, - -101.529_998_779_296_88 as f64, + -101.529_998_779_296_88, float_cmp::F64Margin::default() )); assert!(float_cmp::approx_eq!( f64, rfinput[0].east_m, - -585.674_987_792_968_8 as f64, + -585.674_987_792_968_8, float_cmp::F64Margin::default() )); assert!(float_cmp::approx_eq!( f64, rfinput[0].height_m, - 375.212_005_615_234_4 as f64, + 375.212_005_615_234_4, float_cmp::F64Margin::default() )); assert_eq!(rfinput[0].flagged, true); diff --git a/src/timestep/test.rs b/src/timestep/test.rs index 7ea5ddd..4cbcbdd 100644 --- a/src/timestep/test.rs +++ b/src/timestep/test.rs @@ -32,8 +32,8 @@ fn test_populate_correlator_timesteps() { } // Get a vector timesteps - let scheduled_start_gpstime_ms = 1065880139_000; - let scheduled_start_unix_ms = 1381844923_000; + let scheduled_start_gpstime_ms = 1_065_880_139_000; + let scheduled_start_unix_ms = 1_381_844_923_000; let timesteps = TimeStep::populate_correlator_timesteps( &gpubox_time_map, scheduled_start_gpstime_ms,