Skip to content

Commit

Permalink
Reverted efa8ca4; Added calibrator and calibrator_source to metafits …
Browse files Browse the repository at this point in the history
…context; Bumped to v0.12.0
  • Loading branch information
gsleap committed Nov 12, 2021
1 parent 94ca65f commit 243e40a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/coarse_channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
))
}
Expand Down
38 changes: 11 additions & 27 deletions src/coarse_channel/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions src/metafits_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ pub struct MetafitsContext {
pub delays: Vec<u32>,
/// 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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/metafits_context/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 243e40a

Please sign in to comment.