Skip to content

Commit

Permalink
use mwalib bscale
Browse files Browse the repository at this point in the history
  • Loading branch information
d3v-null committed Nov 11, 2024
1 parent 95687f5 commit 22b1251
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 53 deletions.
54 changes: 2 additions & 52 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ use log::{trace, warn};
use crate::{
marlu::{
constants::MWA_LAT_RAD,
fitsio,
hifitime::Duration,
io::{ms::MeasurementSetWriter, uvfits::UvfitsWriter, VisWrite},
mwalib,
mwalib::{
CorrelatorContext, MwalibError, _get_optional_fits_key, _open_hdu, fits_open_hdu,
get_optional_fits_key,
},
mwalib::{CorrelatorContext, MwalibError},
rayon::prelude::*,
Jones, LatLngHeight, MwaObsContext, ObsContext, RADec, SelectionError, VisContext,
VisSelection, ENH,
Expand Down Expand Up @@ -56,59 +52,13 @@ pub struct IOContext {
}

impl IOContext {
// get the scale factor for the raw files
// will be deprecated after <https://github.com/MWATelescope/mwalib/issues/85> is resolved
fn get_raw_scale_factor(&self) -> f32 {
let mut meta_fptr = fitsio::FitsFile::open(&self.metafits_in).unwrap();
let hdu0 = fits_open_hdu!(&mut meta_fptr, 1).unwrap();
let mut scale_factor: Option<f32> =
get_optional_fits_key!(&mut meta_fptr, &hdu0, "RAWSCALE").unwrap();
let gpstime: Option<i32> =
get_optional_fits_key!(&mut meta_fptr, &hdu0, "GPSTIME").unwrap();
for raw_path in &self.gpufits_in {
let mut fptr = fitsio::FitsFile::open(raw_path).unwrap();
let hdu1 = fits_open_hdu!(&mut fptr, 1).unwrap();
for key in ["SCALEFAC", "BSCALE"] {
let this_scale_factor: Option<f32> =
get_optional_fits_key!(&mut fptr, &hdu1, key).unwrap();
match (scale_factor, this_scale_factor) {
(Some(sf), Some(this_sf)) => {
assert!(
((sf - this_sf).abs() < f32::EPSILON),
"Different scale factors found in raw files: {} and {}",
sf,
this_sf
);
}
(None, Some(this_sf)) => {
scale_factor = Some(this_sf);
}
_ => {}
}
}
}
match (scale_factor, gpstime) {
(Some(sf), _) => sf,
// according to pyuvdata "correlator did a divide by 4 before october 2014"
// https://github.com/RadioAstronomySoftwareGroup/pyuvdata/blob/05ee100af2e4e11c9d291c9eafc937578ef01763/src/pyuvdata/uvdata/mwa_corr_fits.py#L1464
(None, Some(t)) if t < 1096160568 => 0.25,
_ => {
warn!("No scale factor found in metafits or gpufits files, defaulting to 1.0");
1.0
}
}
}

/// Get the `mwalib::CorrelatorContext` from metafits and gpufits
///
/// # Errors
///
/// see `mwalib::CorrelatorContext::new`
pub fn get_corr_ctx(&self) -> Result<CorrelatorContext, MwalibError> {
CorrelatorContext::new(&self.metafits_in, &self.gpufits_in).map(|mut corr_ctx| {
corr_ctx.metafits_context.corr_raw_scale_factor = self.get_raw_scale_factor();
corr_ctx
})
CorrelatorContext::new(&self.metafits_in, &self.gpufits_in)
}

// TODO: pub fn validate_params(&self), checks permissions
Expand Down
2 changes: 1 addition & 1 deletion src/van_vleck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub fn correct_van_vleck(
nsamples: n2samples,
});
}
let sample_scale = n2samples as f64 * corr_ctx.metafits_context.corr_raw_scale_factor as f64;
let sample_scale = n2samples as f64 * corr_ctx.bscale as f64;

// ant_pair indices which are unflagged autocorrelations, list of corresponding antenna indices
let (unflagged_auto_mask, unflagged_autos): (Vec<_>, Vec<_>) = ant_pairs
Expand Down

0 comments on commit 22b1251

Please sign in to comment.