Skip to content

Commit

Permalink
Fixed bug where the num_metafits_fine_chan_freqs and metafits_fine_ch…
Browse files Browse the repository at this point in the history
…an_freqs_hz were not being populated correctly for a stand-alone MetafitsContext usecase
  • Loading branch information
gsleap committed Aug 20, 2021
1 parent 44c3834 commit cc7a974
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 39 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Changes in each release are listed below.

## 0.10.0 20-Aug-2021 (Pre-release)
* Fixed bug where the `num_metafits_fine_chan_freqs` and `metafits_fine_chan_freqs_hz` were not being populated correctly for a stand-alone `MetafitsContext` usecase.
* Fixed attribute name `metafits_fine_chan_freqs` to `metafits_fine_chan_freqs_hz` in FFI `MetafitsMetadata`to be consistent with the rest of the library.
* Removed constants `SPEED_OF_LIGHT_IN_VACUUM_M_PER_S`, `MWA_LATITUDE_RADIANS`, `MWA_LONGITUDE_RADIANS`, `MWA_ALTITUDE_METRES` as these are now provided by the [mwa_rust_core](https://github.com/MWATelescope/mwa_rust_core) repo.
* Simplified the dependency rules for `regex` and `rayon` crates.

## 0.9.4 19-Aug-2021 (Pre-release)

## 0.9.3 10-Aug-2021 (Pre-release)
* Antenna rf_input_x and rf_input_y are now correctly indexed/sorted for the VCSLegacyRecombined case.

Expand Down
6 changes: 4 additions & 2 deletions src/coarse_channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl CoarseChannel {
};

// Return a vector of f64s which are the fine channel centre frequencies for all the fine channels in [coarse_channels]
coarse_channels
let return_vec: Vec<f64> = coarse_channels
.iter()
.flat_map(|coarse_chan| {
(0..num_fine_chans_per_coarse).map(move |fine_chan_idx| {
Expand All @@ -389,7 +389,9 @@ impl CoarseChannel {
+ offset_hz
})
})
.collect()
.collect();

return_vec
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/metafits_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ impl MetafitsContext {
}
},
);
new_context.num_metafits_fine_chan_freqs = new_context.metafits_fine_chan_freqs_hz.len();

// Populate the timesteps
new_context.populate_expected_timesteps(new_context.mwa_version.unwrap())?;
Expand Down Expand Up @@ -708,9 +709,9 @@ impl MetafitsContext {
Vec::with_capacity(metafits_coarse_chan_vec.len());
let num_metafits_coarse_chans: usize = 0;

// Populate fine channel frequencies- we know enough to do this now
let num_metafits_fine_chan_freqs: usize = metafits_coarse_chan_vec.len();
let metafits_fine_chan_freqs: Vec<f64> = Vec::with_capacity(num_metafits_fine_chan_freqs);
// Placeholder values- we work these out once we know the mwa_version
let num_metafits_fine_chan_freqs: usize = 0;
let metafits_fine_chan_freqs: Vec<f64> = Vec::new();

// Fine-channel resolution. The FINECHAN value in the metafits is in units
// of kHz - make it Hz.
Expand Down
84 changes: 50 additions & 34 deletions src/metafits_context/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn test_metafits_context_new_invalid() {
}

#[test]
fn test_metafits_context_new_vcslegacy_valid() {
fn test_metafits_context_new_vcs_legacy_valid() {
// Open the test mwa v 1 metafits file
let metafits_filename = "test_files/1101503312_1_timestep/1101503312.metafits";

Expand All @@ -33,23 +33,25 @@ fn test_metafits_context_new_vcslegacy_valid() {
let context = MetafitsContext::new(&metafits_filename, Some(MWAVersion::VCSLegacyRecombined))
.expect("Failed to create MetafitsContext");

// Test the properties of the context object match what we expect

// obsid: 1101503312,
assert_eq!(context.obs_id, 1_101_503_312);

assert_eq!(context.volt_fine_chan_width_hz, 10_000);
assert_eq!(context.num_volt_fine_chans_per_coarse, 128);
// rf_inputs: [Tile104Y, ..., Tile055X],
assert_eq!(context.num_rf_inputs, 256);
assert_eq!(context.rf_inputs[0].pol, Pol::Y);
assert_eq!(context.rf_inputs[0].tile_name, "Tile104");
assert_eq!(context.rf_inputs[255].pol, Pol::X);
assert_eq!(context.rf_inputs[255].tile_name, "Tile055");

for i in 0..128 {
if context.antennas[i].tile_id == 154 {
assert_eq!(context.antennas[i].rfinput_y.vcs_order, 1);
}
// Test the properties of the context object match what we expect
// antennas: [Tile011, Tile012, ... Tile167, Tile168],
// NOTE: since in Legacy VCS the VCS order may look like Tile104Y, Tile103Y, Tile102Y, Tile104X, ...
// so the order of antennas makes no sense, since 104 needs to be first AND further down the list!, so we leave it in the MWAX order.
assert_eq!(context.antennas[0].tile_name, "Tile011");
assert_eq!(context.antennas[127].tile_name, "Tile168");

if context.antennas[i].tile_id == 104 {
assert_eq!(context.antennas[i].rfinput_y.vcs_order, 0);
}
}
assert_eq!(context.metafits_fine_chan_freqs_hz.len(), 3072);
assert_eq!(
context.metafits_fine_chan_freqs_hz.len(),
context.num_metafits_fine_chan_freqs
);
}

#[test]
Expand Down Expand Up @@ -231,54 +233,68 @@ fn test_metafits_context_new_corrlegacy_valid() {
assert_eq!(VisPol::XY.to_string(), "XY");
assert_eq!(VisPol::YX.to_string(), "YX");
assert_eq!(VisPol::YY.to_string(), "YY");

// Check correlator mode
assert_eq!(context.corr_fine_chan_width_hz, 10_000);
assert_eq!(context.corr_int_time_ms, 2_000);

// Check metafits fine chan freqs
assert_eq!(context.metafits_fine_chan_freqs_hz.len(), 3072);
assert_eq!(
context.metafits_fine_chan_freqs_hz.len(),
context.num_metafits_fine_chan_freqs
);
}

#[test]
fn test_metafits_context_new_vcsmwax2_valid() {
fn test_metafits_context_new_corrmwaxv2_valid() {
// Open the test mwa v 1 metafits file
let metafits_filename = "test_files/1101503312_1_timestep/1101503312.metafits";

//
// Read the observation using mwalib
//
// Open a context and load in a test metafits
let context = MetafitsContext::new(&metafits_filename, Some(MWAVersion::VCSMWAXv2))
let context = MetafitsContext::new(&metafits_filename, Some(MWAVersion::CorrMWAXv2))
.expect("Failed to create MetafitsContext");

// Test the properties of the context object match what we expect

// obsid: 1101503312,
assert_eq!(context.obs_id, 1_101_503_312);

assert_eq!(context.volt_fine_chan_width_hz, 1_280_000);
assert_eq!(context.num_volt_fine_chans_per_coarse, 1);
assert_eq!(context.metafits_fine_chan_freqs_hz.len(), 3072);
assert_eq!(
context.metafits_fine_chan_freqs_hz.len(),
context.num_metafits_fine_chan_freqs
);
}

#[test]
fn test_metafits_context_new_vcs_legacy_valid() {
fn test_metafits_context_new_vcsmwax2_valid() {
// Open the test mwa v 1 metafits file
let metafits_filename = "test_files/1101503312_1_timestep/1101503312.metafits";

//
// Read the observation using mwalib
//
// Open a context and load in a test metafits
let context = MetafitsContext::new(&metafits_filename, Some(MWAVersion::VCSLegacyRecombined))
let context = MetafitsContext::new(&metafits_filename, Some(MWAVersion::VCSMWAXv2))
.expect("Failed to create MetafitsContext");

// rf_inputs: [Tile104Y, ..., Tile055X],
assert_eq!(context.num_rf_inputs, 256);
assert_eq!(context.rf_inputs[0].pol, Pol::Y);
assert_eq!(context.rf_inputs[0].tile_name, "Tile104");
assert_eq!(context.rf_inputs[255].pol, Pol::X);
assert_eq!(context.rf_inputs[255].tile_name, "Tile055");

// Test the properties of the context object match what we expect
// antennas: [Tile011, Tile012, ... Tile167, Tile168],
// NOTE: since in Legacy VCS the VCS order may look like Tile104Y, Tile103Y, Tile102Y, Tile104X, ...
// so the order of antennas makes no sense, since 104 needs to be first AND further down the list!, so we leave it in the MWAX order.
assert_eq!(context.antennas[0].tile_name, "Tile011");
assert_eq!(context.antennas[127].tile_name, "Tile168");

// obsid: 1101503312,
assert_eq!(context.obs_id, 1_101_503_312);

assert_eq!(context.volt_fine_chan_width_hz, 1_280_000);
assert_eq!(context.num_volt_fine_chans_per_coarse, 1);

assert_eq!(context.metafits_fine_chan_freqs_hz.len(), 24);
assert_eq!(
context.metafits_fine_chan_freqs_hz.len(),
context.num_metafits_fine_chan_freqs
);
}

#[test]
Expand Down

0 comments on commit cc7a974

Please sign in to comment.