Skip to content

Commit

Permalink
Fixes #55
Browse files Browse the repository at this point in the history
  • Loading branch information
gsleap committed Dec 8, 2022
1 parent d169eb5 commit 2155c19
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 39 deletions.
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Change Log

Changes in each release are listed below.
## 0.16.0 22-Nov-2022 (Pre-release)
* FFI/C: `MetafitsMetadata`->`ra_phase_center_deg` is now NaN not 0 when missing from metafits file
* FFI/C: `MetafitsMetadata`->`dec_phase_center_deg` is now NaN not 0 when missing from metafits file

## 0.16.0 (unreleased)
## 0.16.0 08-Dec-2022 (Pre-release)
* FFI/C: `MetafitsMetadata`->`ra_phase_center_deg` is now NaN not 0 when missing from metafits file.
* FFI/C: `MetafitsMetadata`->`dec_phase_center_deg` is now NaN not 0 when missing from metafits file.
* `MetafitsContext::grid_name` defaults to 'NOGRID' when key is missing from metafits file.
* `MetafitsContext::grid_number` defaults to 0 when key is missing from metafits file.
* `MetafitsContext::sun_alt_deg` is now an Option<f64> to handle cases where key is missing from metafits file. Via FFI/C it is represented by a NaN.
* `MetafitsContext::sun_distance_deg` is now an Option<f64> to handle cases where key is missing from metafits file. Via FFI/C it is represented by a NaN.
* `MetafitsContext::moon_distance_deg` is now an Option<f64> to handle cases where key is missing from metafits file. Via FFI/C it is represented by a NaN.
* `MetafitsContext::jupiter_distance_deg` is now an Option<f64> to handle cases where key is missing from metafits file. Via FFI/C it is represented by a NaN.
* Update module docs.
* Update dependencies.
* Fixed a bunch of clippy lints.
Expand Down
10 changes: 5 additions & 5 deletions src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,17 +1730,17 @@ pub unsafe extern "C" fn mwalib_metafits_metadata_get(
az_rad: *az_rad,
alt_rad: *alt_rad,
za_rad: *za_rad,
sun_alt_deg: *sun_alt_deg,
sun_distance_deg: *sun_distance_deg,
moon_distance_deg: *moon_distance_deg,
jupiter_distance_deg: *jupiter_distance_deg,
sun_alt_deg: (*sun_alt_deg).unwrap_or(f64::NAN),
sun_distance_deg: (*sun_distance_deg).unwrap_or(f64::NAN),
moon_distance_deg: (*moon_distance_deg).unwrap_or(f64::NAN),
jupiter_distance_deg: (*jupiter_distance_deg).unwrap_or(f64::NAN),
lst_deg: *lst_degrees,
lst_rad: *lst_radians,
hour_angle_string: CString::new(String::from(hour_angle_string))
.unwrap()
.into_raw(),
grid_name: CString::new(String::from(grid_name)).unwrap().into_raw(),
grid_number: grid_number.unwrap_or(-1),
grid_number: *grid_number,
creator: CString::new(String::from(creator)).unwrap().into_raw(),
project_id: CString::new(String::from(project_id)).unwrap().into_raw(),
obs_name: CString::new(String::from(obs_name)).unwrap().into_raw(),
Expand Down
58 changes: 35 additions & 23 deletions src/metafits_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,13 @@ pub struct MetafitsContext {
/// Zenith angle of the pointing centre in radians
pub za_rad: f64,
/// Altitude of Sun
pub sun_alt_deg: f64,
pub sun_alt_deg: Option<f64>,
/// Distance from pointing center to Sun
pub sun_distance_deg: f64,
pub sun_distance_deg: Option<f64>,
/// Distance from pointing center to the Moon
pub moon_distance_deg: f64,
pub moon_distance_deg: Option<f64>,
/// Distance from pointing center to Jupiter
pub jupiter_distance_deg: f64,
pub jupiter_distance_deg: Option<f64>,
/// Local Sidereal Time in degrees (at the midpoint of the observation)
pub lst_deg: f64,
/// Local Sidereal Time in radians (at the midpoint of the observation)
Expand All @@ -372,7 +372,7 @@ pub struct MetafitsContext {
/// GRIDNAME
pub grid_name: String,
/// GRIDNUM
pub grid_number: Option<i32>,
pub grid_number: i32,
/// CREATOR
pub creator: String,
/// PROJECT
Expand Down Expand Up @@ -701,18 +701,21 @@ impl MetafitsContext {
let altitude_degrees: f64 =
get_required_fits_key!(&mut metafits_fptr, &metafits_hdu, "ALTITUDE")?;
let zenith_angle_degrees: f64 = 90.0 - altitude_degrees;
let sun_altitude_degrees: f64 =
get_required_fits_key!(&mut metafits_fptr, &metafits_hdu, "SUN-ALT")?;
let sun_distance_degrees: f64 =
get_required_fits_key!(&mut metafits_fptr, &metafits_hdu, "SUN-DIST")?;
let moon_distance_degrees: f64 =
get_required_fits_key!(&mut metafits_fptr, &metafits_hdu, "MOONDIST")?;
let jupiter_distance_degrees: f64 =
get_required_fits_key!(&mut metafits_fptr, &metafits_hdu, "JUP-DIST")?;
let sun_altitude_degrees: Option<f64> =
get_optional_fits_key!(&mut metafits_fptr, &metafits_hdu, "SUN-ALT")?;
let sun_distance_degrees: Option<f64> =
get_optional_fits_key!(&mut metafits_fptr, &metafits_hdu, "SUN-DIST")?;
let moon_distance_degrees: Option<f64> =
get_optional_fits_key!(&mut metafits_fptr, &metafits_hdu, "MOONDIST")?;
let jupiter_distance_degrees: Option<f64> =
get_optional_fits_key!(&mut metafits_fptr, &metafits_hdu, "JUP-DIST")?;
let lst_degrees: f64 = get_required_fits_key!(&mut metafits_fptr, &metafits_hdu, "LST")?;
let hour_angle_string = get_required_fits_key!(&mut metafits_fptr, &metafits_hdu, "HA")?;
let grid_name = get_required_fits_key!(&mut metafits_fptr, &metafits_hdu, "GRIDNAME")?;
let grid_number = get_optional_fits_key!(&mut metafits_fptr, &metafits_hdu, "GRIDNUM")?;
let grid_name: String =
get_optional_fits_key!(&mut metafits_fptr, &metafits_hdu, "GRIDNAME")?
.unwrap_or(String::from("NOGRID"));
let grid_number =
get_optional_fits_key!(&mut metafits_fptr, &metafits_hdu, "GRIDNUM")?.unwrap_or(0);
let creator = get_required_fits_key!(&mut metafits_fptr, &metafits_hdu, "CREATOR")?;
let project_id = get_required_fits_key!(&mut metafits_fptr, &metafits_hdu, "PROJECT")?;
let observation_name =
Expand Down Expand Up @@ -1167,17 +1170,26 @@ impl fmt::Display for MetafitsContext {
dppc = Some(self.dec_phase_center_degrees),
az = self.az_deg,
alt = self.alt_deg,
sun_alt = self.sun_alt_deg,
sun_dis = self.sun_distance_deg,
moon_dis = self.moon_distance_deg,
jup_dis = self.jupiter_distance_deg,
sun_alt = match self.sun_alt_deg {
Some(s) => s.to_string(),
None => String::from("None"),
},
sun_dis = match self.sun_distance_deg {
Some(s) => s.to_string(),
None => String::from("None"),
},
moon_dis = match self.moon_distance_deg {
Some(s) => s.to_string(),
None => String::from("None"),
},
jup_dis = match self.jupiter_distance_deg {
Some(s) => s.to_string(),
None => String::from("None"),
},
lst = self.lst_deg,
ha = self.hour_angle_string,
grid = self.grid_name,
grid_n = match self.grid_number {
Some(g) => g.to_string(),
None => String::from("None"),
},
grid_n = self.grid_number.to_string(),
calib = self.calibrator,
calsrc = self.calibrator_source,
n_ants = self.num_ants,
Expand Down
12 changes: 6 additions & 6 deletions src/metafits_context/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,31 +153,31 @@ fn test_metafits_context_new_corrlegacy_valid() {
// Sun altitude: -1.53222775573148 degrees,
assert!(approx_eq!(
f64,
context.sun_alt_deg,
context.sun_alt_deg.unwrap(),
-1.532_227_755_731_48,
F64Margin::default()
));

// Sun distance: 91.5322277557315 degrees,
assert!(approx_eq!(
f64,
context.sun_distance_deg,
context.sun_distance_deg.unwrap(),
91.532_227_755_731_5,
F64Margin::default()
));

// Moon distance: 131.880015235607 degrees,
assert!(approx_eq!(
f64,
context.moon_distance_deg,
context.moon_distance_deg.unwrap(),
131.880_015_235_607,
F64Margin::default()
));

// Jupiter distance: 41.401684338269 degrees,
assert!(approx_eq!(
f64,
context.jupiter_distance_deg,
context.jupiter_distance_deg.unwrap(),
41.401_684_338_269,
F64Margin::default()
));
Expand All @@ -192,10 +192,10 @@ fn test_metafits_context_new_corrlegacy_valid() {

// Hour angle: -00:00:00.00 degrees,
// Grid name: sweet,
assert_eq!(context.grid_name, "sweet");
assert_eq!(context.grid_name, String::from("sweet"));

// Grid number: 0,
assert_eq!(context.grid_number, Some(0));
assert_eq!(context.grid_number, 0);

// num antennas: 128,
assert_eq!(context.num_ants, 128);
Expand Down

0 comments on commit 2155c19

Please sign in to comment.