Skip to content

Commit

Permalink
Closes #45 - Issue where where mwalib would panic when creating Corre…
Browse files Browse the repository at this point in the history
…latorContext with only gpubox file(s) from the second or higher batch. Added tests and test file
  • Loading branch information
gsleap committed Nov 29, 2021
1 parent 6af4738 commit 50194c3
Show file tree
Hide file tree
Showing 5 changed files with 27,496 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Changes in each release are listed below.

## 0.12.1 29-Nov-2021 (Pre-release)
* Fixed issue and covered with tests the case where mwalib would panic when creating `CorrelatorContext` with only gpubox file(s) from the second or higher batch (e.g. 001,002...).

## 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)
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.12.0"
version = "0.12.1"
homepage = "https://github.com/MWATelescope/mwalib"
repository = "https://github.com/MWATelescope/mwalib"
readme = "README.md"
Expand Down
22 changes: 12 additions & 10 deletions src/correlator_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,19 @@ impl CorrelatorContext {
);
let num_provided_coarse_chan_indices = provided_coarse_chan_indices.len();

// We have enough information to validate HDU matches metafits for the first batch/first coarse channel we have data for
// We have enough information to validate HDU matches metafits for the each gpubox file we have data for
if !gpubox_filenames.is_empty() {
let mut fptr = fits_open!(&gpubox_info.batches[0].gpubox_files[0].filename)?;

CorrelatorContext::validate_first_hdu(
gpubox_info.mwa_version,
metafits_context.num_corr_fine_chans_per_coarse,
metafits_context.num_baselines,
metafits_context.num_visibility_pols,
&mut fptr,
)?;
for g in gpubox_filenames.iter() {
let mut fptr = fits_open!(&g)?;

CorrelatorContext::validate_first_hdu(
gpubox_info.mwa_version,
metafits_context.num_corr_fine_chans_per_coarse,
metafits_context.num_baselines,
metafits_context.num_visibility_pols,
&mut fptr,
)?;
}
}

// Populate the start and end times of the observation based on common channels.
Expand Down
50 changes: 50 additions & 0 deletions src/correlator_context/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,56 @@ Unit tests for correlator context
use super::*;
use float_cmp::*;

#[test]
fn test_context_new_with_only_non000_batch() {
// The _001 fits file contains 1 timestep too- it is at time index 1560938480 / marker 10 (so the 10th timestep - zero indexed!)
let metafits_filename = "test_files/1244973688_1_timestep/1244973688.metafits";
let mut gpuboxfiles = Vec::new();
gpuboxfiles.push("test_files/1244973688_1_timestep/1244973688_20190619100110_ch114_001.fits");

// No gpubox files provided
let context_result = CorrelatorContext::new(&metafits_filename, &gpuboxfiles);

assert!(context_result.is_ok());

let context = context_result.unwrap();
println!("{:?}", context.gpubox_time_map);
let data_result = context.read_by_baseline(10, 10);
assert!(data_result.is_ok(), "Error was {:?}", data_result);
}

#[test]
fn test_context_new_with_000_and_001_batch() {
// The _001 fits file contains 1 timestep too- it is at time index 1560938480 / marker 10 (so the 10th timestep - zero indexed!)
let metafits_filename = "test_files/1244973688_1_timestep/1244973688.metafits";
let mut gpuboxfiles = Vec::new();
gpuboxfiles.push("test_files/1244973688_1_timestep/1244973688_20190619100110_ch114_000.fits");
gpuboxfiles.push("test_files/1244973688_1_timestep/1244973688_20190619100110_ch114_001.fits");

// No gpubox files provided
let context_result = CorrelatorContext::new(&metafits_filename, &gpuboxfiles);

assert!(context_result.is_ok());

let context = context_result.unwrap();
println!("{:?}", context.gpubox_time_map);
// Read from batch 0
let data_result1 = context.read_by_baseline(0, 10);
assert!(data_result1.is_ok(), "Error was {:?}", data_result1);
// Read from batch 1
let data_result2 = context.read_by_baseline(10, 10);
assert!(data_result2.is_ok(), "Error was {:?}", data_result2);
// Read from a timestep that does not exist
let data_result3 = context.read_by_baseline(15, 10);
assert!(matches!(
data_result3.unwrap_err(),
GpuboxError::NoDataForTimeStepCoarseChannel {
timestep_index: _,
coarse_chan_index: _
}
));
}

#[test]
fn test_context_new_missing_gpubox_files() {
let metafits_filename = "test_files/1101503312_1_timestep/1101503312.metafits";
Expand Down
Loading

0 comments on commit 50194c3

Please sign in to comment.