From 243e40ab09134499e98ab26b333a3e4d578f4e5d Mon Sep 17 00:00:00 2001 From: Greg Sleap Date: Fri, 12 Nov 2021 15:42:22 +0800 Subject: [PATCH] Reverted efa8ca41edccbe15079642b26ed5049a8656e3a9; Added calibrator and calibrator_source to metafits context; Bumped to v0.12.0 --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- src/coarse_channel/mod.rs | 3 ++- src/coarse_channel/test.rs | 38 +++++++++++------------------------- src/ffi/mod.rs | 11 +++++++++++ src/metafits_context/mod.rs | 21 ++++++++++++++++++++ src/metafits_context/test.rs | 4 ++++ 7 files changed, 55 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 240166a..066650d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Change Log Changes in each release are listed below. + +## 0.12.0 12-Nov-2021 (Pre-release) +* Added calibrator and calibrator_source to `metafits_context` +* Reverted efa8ca41edccbe15079642b26ed5049a8656e3a9 (behaviour of coarse_chan.gpubox_number for VoltageContext LegacyVCS use-case) + ## 0.11.0 28-Oct-2021 (Pre-release) * Added new metafits key RAWSCALE to metafits context * Made gridnum and global_analogue_attenuation_db optional (since they are not in every historical metafits) diff --git a/Cargo.toml b/Cargo.toml index 39f377c..08b46a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mwalib" -version = "0.11.0" +version = "0.12.0" homepage = "https://github.com/MWATelescope/mwalib" repository = "https://github.com/MWATelescope/mwalib" readme = "README.md" diff --git a/src/coarse_channel/mod.rs b/src/coarse_channel/mod.rs index 7dedb56..9e61552 100644 --- a/src/coarse_channel/mod.rs +++ b/src/coarse_channel/mod.rs @@ -25,6 +25,7 @@ pub struct CoarseChannel { pub rec_chan_number: usize, /// gpubox channel number + /// This is better described as the identifier which would be in the filename of visibility files /// Legacy e.g. obsid_datetime_gpuboxXX_00 /// v2 e.g. obsid_datetime_gpuboxXXX_00 pub gpubox_number: usize, @@ -229,7 +230,7 @@ impl CoarseChannel { coarse_chans.push(CoarseChannel::new( correlator_chan_number, *rec_chan_number, - gpubox_chan_number, + *rec_chan_number, metafits_coarse_chan_width_hz, )) } diff --git a/src/coarse_channel/test.rs b/src/coarse_channel/test.rs index 3c95323..7c9a7dd 100644 --- a/src/coarse_channel/test.rs +++ b/src/coarse_channel/test.rs @@ -123,18 +123,11 @@ fn test_process_coarse_chans_vcs_legacy_middle_two_channels() { assert_eq!(coarse_chan_array.len(), 2); assert_eq!(coarse_chan_array[0].corr_chan_number, 1); assert_eq!(coarse_chan_array[0].rec_chan_number, 110); - if mwa_version == MWAVersion::VCSLegacyRecombined { - assert_eq!(coarse_chan_array[0].gpubox_number, 2); - } else { - assert_eq!(coarse_chan_array[0].gpubox_number, 110); - } + assert_eq!(coarse_chan_array[0].gpubox_number, 110); + assert_eq!(coarse_chan_array[1].corr_chan_number, 2); assert_eq!(coarse_chan_array[1].rec_chan_number, 111); - if mwa_version == MWAVersion::VCSLegacyRecombined { - assert_eq!(coarse_chan_array[1].gpubox_number, 3); - } else { - assert_eq!(coarse_chan_array[1].gpubox_number, 111); - } + assert_eq!(coarse_chan_array[1].gpubox_number, 111); } } @@ -216,19 +209,19 @@ fn test_process_coarse_chans_vcs_legacy_chan_reversal() { assert_eq!(coarse_chan_array.len(), 5); assert_eq!(coarse_chan_array[0].corr_chan_number, 0); assert_eq!(coarse_chan_array[0].rec_chan_number, 126); - assert_eq!(coarse_chan_array[0].gpubox_number, 1); + assert_eq!(coarse_chan_array[0].gpubox_number, 126); assert_eq!(coarse_chan_array[1].corr_chan_number, 1); assert_eq!(coarse_chan_array[1].rec_chan_number, 127); - assert_eq!(coarse_chan_array[1].gpubox_number, 2); + assert_eq!(coarse_chan_array[1].gpubox_number, 127); assert_eq!(coarse_chan_array[2].corr_chan_number, 2); assert_eq!(coarse_chan_array[2].rec_chan_number, 128); - assert_eq!(coarse_chan_array[2].gpubox_number, 3); + assert_eq!(coarse_chan_array[2].gpubox_number, 128); assert_eq!(coarse_chan_array[3].corr_chan_number, 4); assert_eq!(coarse_chan_array[3].rec_chan_number, 129); - assert_eq!(coarse_chan_array[3].gpubox_number, 5); + assert_eq!(coarse_chan_array[3].gpubox_number, 129); assert_eq!(coarse_chan_array[4].corr_chan_number, 3); assert_eq!(coarse_chan_array[4].rec_chan_number, 130); - assert_eq!(coarse_chan_array[4].gpubox_number, 4); + assert_eq!(coarse_chan_array[4].gpubox_number, 130); } #[test] @@ -326,7 +319,7 @@ fn test_process_coarse_chans_corr_legacy_first_and_last() { /// 110 == missing /// 111 == missing /// 112 == index 3 -fn test_process_coarse_chans_vcs_legacy_first_and_last() { +fn test_process_coarse_chans_vcs_legacy_mwax_first_and_last() { test(MWAVersion::VCSLegacyRecombined); test(MWAVersion::VCSMWAXv2); @@ -353,20 +346,11 @@ fn test_process_coarse_chans_vcs_legacy_first_and_last() { assert_eq!(coarse_chan_array.len(), 2); assert_eq!(coarse_chan_array[0].corr_chan_number, 0); assert_eq!(coarse_chan_array[0].rec_chan_number, 109); - if mwa_version == MWAVersion::VCSLegacyRecombined { - assert_eq!(coarse_chan_array[0].gpubox_number, 1); - } else { - assert_eq!(coarse_chan_array[0].gpubox_number, 109); - } + assert_eq!(coarse_chan_array[0].gpubox_number, 109); assert_eq!(coarse_chan_array[1].corr_chan_number, 3); assert_eq!(coarse_chan_array[1].rec_chan_number, 112); - - if mwa_version == MWAVersion::VCSLegacyRecombined { - assert_eq!(coarse_chan_array[1].gpubox_number, 4); - } else { - assert_eq!(coarse_chan_array[1].gpubox_number, 112); - } + assert_eq!(coarse_chan_array[1].gpubox_number, 112); } } diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index b5fab1c..b05381e 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -1369,6 +1369,10 @@ pub struct MetafitsMetadata { pub delays: *mut u32, /// Number of beamformer delays pub num_delays: usize, + /// Intended for calibration + pub calibrator: bool, + /// Calibrator source + pub calibrator_source: *mut c_char, /// Scheduled start (UTC) of observation as a time_t (unix timestamp) pub sched_start_utc: libc::time_t, /// Scheduled end (UTC) of observation as a time_t (unix timestamp) @@ -1696,6 +1700,8 @@ pub unsafe extern "C" fn mwalib_metafits_metadata_get( num_receivers, delays, num_delays, + calibrator, + calibrator_source, global_analogue_attenuation_db, quack_time_duration_ms, good_time_unix_ms, @@ -1761,6 +1767,10 @@ pub unsafe extern "C" fn mwalib_metafits_metadata_get( num_receivers: *num_receivers, delays: ffi_array_to_boxed_slice(delays.clone()), num_delays: *num_delays, + calibrator: *calibrator, + calibrator_source: CString::new(String::from(&*calibrator_source)) + .unwrap() + .into_raw(), sched_start_utc: sched_start_utc.timestamp(), sched_end_utc: sched_end_utc.timestamp(), sched_start_mjd: *sched_start_mjd, @@ -2716,6 +2726,7 @@ pub struct CoarseChannel { /// Receiver channel is 0-255 in the RRI recivers pub rec_chan_number: usize, /// gpubox channel number + /// This is better described as the identifier which would be in the filename of visibility files /// Legacy e.g. obsid_datetime_gpuboxXX_00 /// v2 e.g. obsid_datetime_gpuboxXXX_00 pub gpubox_number: usize, diff --git a/src/metafits_context/mod.rs b/src/metafits_context/mod.rs index 596f539..278f1a4 100644 --- a/src/metafits_context/mod.rs +++ b/src/metafits_context/mod.rs @@ -353,6 +353,10 @@ pub struct MetafitsContext { pub delays: Vec, /// Number of beamformer delays pub num_delays: usize, + /// Intended for calibration + pub calibrator: bool, + /// Calibrator source + pub calibrator_source: String, /// ATTEN_DB // global analogue attenuation, in dB pub global_analogue_attenuation_db: f64, /// Seconds of bad data after observation starts @@ -691,6 +695,17 @@ impl MetafitsContext { let num_delays = delays.len(); + // CALIBRAT - defalut to F if not found + let calibration_string: String = + get_optional_fits_key!(&mut metafits_fptr, &metafits_hdu, "CALIBRAT")? + .unwrap_or(String::from("F")); + let calibrator: bool = calibration_string == String::from("T"); + + // CALIBSRC - default to empty string if not found + let calibrator_source: String = + get_optional_fits_key!(&mut metafits_fptr, &metafits_hdu, "CALIBSRC")? + .unwrap_or(String::from("")); + // ATTEN_DB is not garaunteed to be in the metafits. Default to 0 let global_analogue_attenuation_db: f64 = get_optional_fits_key!(&mut metafits_fptr, &metafits_hdu, "ATTEN_DB")?.unwrap_or(0.0); @@ -787,6 +802,8 @@ impl MetafitsContext { num_receivers, delays, num_delays, + calibrator, + calibrator_source, global_analogue_attenuation_db, quack_time_duration_ms, good_time_unix_ms, @@ -984,6 +1001,8 @@ impl fmt::Display for MetafitsContext { Observation Name: {obs_name}, Receivers: {receivers:?}, Delays: {delays:?}, + Calibration: {calib}, + Calibrator Source: {calsrc}, Global attenuation: {atten} dB, Scheduled start (UNIX) {sched_start_unix}, @@ -1084,6 +1103,8 @@ impl fmt::Display for MetafitsContext { Some(g) => g.to_string(), None => String::from("None"), }, + calib = self.calibrator, + calsrc = self.calibrator_source, n_ants = self.num_ants, ants = self.antennas, rfs = self.rf_inputs, diff --git a/src/metafits_context/test.rs b/src/metafits_context/test.rs index caa7f81..85aced8 100644 --- a/src/metafits_context/test.rs +++ b/src/metafits_context/test.rs @@ -90,6 +90,10 @@ fn test_metafits_context_new_corrlegacy_valid() { assert_eq!(context.delays[0], 0); assert_eq!(context.delays[15], 0); + // Calibrator + assert_eq!(context.calibrator, false); + assert_eq!(context.calibrator_source, ""); + // Global attenuation: 1 dB, assert_eq!(context.global_analogue_attenuation_db as i16, 1);