Skip to content

Commit

Permalink
Make uvfits reading more robust.
Browse files Browse the repository at this point in the history
This commit allows pyuvdata-style uvfits files to be read.

Read in the uvfits ARRAY{X,Y,Z} keys to get the array position.
  • Loading branch information
cjordan committed Aug 23, 2022
1 parent 05fad42 commit 0bf83c8
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 97 deletions.
2 changes: 2 additions & 0 deletions src/calibrate/di/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ fn test_1090008640_calibrate_model_uvfits() {
"--source-list", &srclist,
"--outputs", &format!("{}", sols.display()),
"--model-filenames", &format!("{}", cal_model.display()),
// If we don't give the array position, there's a bit flip in the results. grrr
"--array-position", "116.67081523611111", "-26.703319405555554", "377.827",
"--veto-threshold", "0.0", // Don't complicate things with vetoing
"--no-progress-bars",
]);
Expand Down
24 changes: 23 additions & 1 deletion src/math/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
mod tests;

use hifitime::Epoch;
use marlu::{LatLngHeight, XyzGeocentric};
use std::collections::HashMap;

use crate::time::round_hundredths_of_a_second;
use mwa_hyperdrive_common::{c64, hifitime};
use mwa_hyperdrive_common::{c64, erfa_sys, hifitime, marlu};

// Make traditional trigonometry possible.
/// Sine.
Expand Down Expand Up @@ -138,3 +139,24 @@ impl TileBaselineMaps {
}
}
}

pub(crate) fn geocentric_to_geodetic(xyz: XyzGeocentric) -> LatLngHeight {
let mut earth = LatLngHeight {
longitude_rad: 0.0,
latitude_rad: 0.0,
height_metres: 0.0,
};
unsafe {
let status = erfa_sys::eraGc2gd(
1,
[xyz.x, xyz.y, xyz.z].as_mut_ptr(),
&mut earth.longitude_rad,
&mut earth.latitude_rad,
&mut earth.height_metres,
);
if status != 0 {
panic!("erfa_sys::eraGc2gd");
}
}
earth
}
18 changes: 17 additions & 1 deletion src/vis_io/read/uvfits/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,23 @@ pub(crate) enum UvfitsReadError {
#[error("Could not parse key {key}'s value {value} into a number")]
Parse { key: String, value: String },

/// An error associated with fitsio.
#[error("When attempting to read uvfits baseline metadata, cfitsio gave an error: {0}")]
Metadata(fitsio::errors::Error),

#[error("When attempting to read uvfits column {col_name} from HDU {hdu_num}, cfitsio gave an error: {err}")]
ReadCellArray {
col_name: &'static str,
hdu_num: usize,
err: fitsio::errors::Error,
},

#[error("When attempting to read uvfits row {row_num}, cfitsio gave an error: {err}")]
ReadVis {
row_num: usize,
err: fitsio::errors::Error,
},

/// A generic error associated with fitsio.
#[error(transparent)]
Fitsio(#[from] fitsio::errors::Error),

Expand Down
Loading

0 comments on commit 0bf83c8

Please sign in to comment.