diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d00817..c57f30a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Changes in each release are listed below. +## next + +* Update to fitsio 0.21.6 - provides FitsFile.file_path() method. + ## 1.7.1 23-Oct-2024 * Release to fix issue generating Rust docs. diff --git a/Cargo.toml b/Cargo.toml index 6f1cec5..3c49f9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ python = ["anyhow", "env_logger", "ndarray", "numpy", "pyo3", "pyo3-stub-gen", " [dependencies] chrono = "0.4.38" -fitsio = "~0.21" +fitsio = "0.21.6" fitsio-sys = "~0.5" lazy_static = "~1.5" libc = "~0.2" @@ -95,4 +95,4 @@ required-features = ["examples"] [[example]] name = "mwalib-sum-first-fine-channel-gpubox-hdus" -required-features = ["examples"] \ No newline at end of file +required-features = ["examples"] diff --git a/src/coarse_channel/mod.rs b/src/coarse_channel/mod.rs index 2388fad..3f1a5d2 100644 --- a/src/coarse_channel/mod.rs +++ b/src/coarse_channel/mod.rs @@ -9,6 +9,7 @@ use crate::voltage_files::VoltageFileTimeMap; pub mod error; use crate::*; use error::CoarseChannelError; +use fitsio::{hdu::FitsHdu, FitsFile}; use std::fmt; #[cfg(feature = "python")] @@ -109,10 +110,10 @@ impl CoarseChannel { /// /// # Arguments /// - /// `metafits_fptr` - a reference to a metafits MWAFitsFile object. + /// `metafits_fptr` - a reference to a metafits FitsFile object. /// /// `metafits_hdu` - a reference to a metafits primary HDU. - /// + /// /// `observation_bandwidth_hz` - total bandwidth in Hz of the entire observation. If there are 24 x 1.28 MHz channels /// this would be 30.72 MHz (30,720,000 Hz) /// @@ -122,8 +123,8 @@ impl CoarseChannel { /// The width in Hz of each coarse channel /// pub(crate) fn get_metafits_coarse_channel_info( - metafits_fptr: &mut MWAFitsFile, - hdu: &fitsio::hdu::FitsHdu, + metafits_fptr: &mut FitsFile, + hdu: &FitsHdu, observation_bandwidth_hz: u32, ) -> Result<(Vec, u32), FitsError> { // The coarse-channels string uses the FITS "CONTINUE" keywords. The @@ -147,7 +148,7 @@ impl CoarseChannel { /// * if `voltage_time_map` is supplied, then the coarse channels represent actual coarse channels supplied for a VoltageContext. /// * if neither `gpubox_time_map` nor `voltage_time_map` is supplied, then the coarse channels represent the expected coarse channels supplied for a MetafitsContext. /// - /// # Arguments + /// # Arguments /// /// `mwa_version` - enum representing the version of the correlator this observation was created with. /// @@ -162,7 +163,7 @@ impl CoarseChannel { /// # Returns /// /// * A tuple containing: A vector of CoarseChannel structs (limited to those are supplied by the client and are valid, unless neither `gpubox_time_map` nor - /// `voltage_time_map` are provided, and the it is based on the metafits), + /// `voltage_time_map` are provided, and the it is based on the metafits), /// The width in Hz of each coarse channel /// pub(crate) fn populate_coarse_channels( @@ -313,11 +314,11 @@ impl CoarseChannel { /// This creates a populated vector of indices from the passed in `all_coarse_chans' slice of CoarseChannels based on the /// coarse_chan_identifiers vector of coarse channel identifers we pass in. /// - /// # Arguments + /// # Arguments /// - /// * `all_coarse_chans` - Reference to a slice containing all the coarse channels + /// * `all_coarse_chans` - Reference to a slice containing all the coarse channels /// - /// * `coarse_chan_identifiers` - Vector or coarse channel identifiers we want to find the indices for. + /// * `coarse_chan_identifiers` - Vector or coarse channel identifiers we want to find the indices for. /// /// # Returns /// @@ -345,7 +346,7 @@ impl CoarseChannel { /// Calculate the centre frequency of each fine channel of the provided coarse channels. /// /// - /// # Arguments + /// # Arguments /// /// * `mwa_version` - The version of the MWA is in use. /// diff --git a/src/correlator_context/mod.rs b/src/correlator_context/mod.rs index 816f4b5..ff25885 100644 --- a/src/correlator_context/mod.rs +++ b/src/correlator_context/mod.rs @@ -4,6 +4,7 @@ //! The main interface to MWA data. +use fitsio::FitsFile; use std::collections::BTreeMap; use std::fmt; use std::path::Path; @@ -121,7 +122,7 @@ pub struct CorrelatorContext { /// number, batch number and HDU index are everything needed to find the /// correct HDU out of all gpubox files. pub gpubox_time_map: BTreeMap>, - /// A conversion table to optimise reading of legacy MWA HDUs + /// A conversion table to optimise reading of legacy MWA HDUs pub(crate) legacy_conversion_table: Vec, } @@ -141,7 +142,7 @@ impl CorrelatorContext { /// /// * Result containing a populated CorrelatorContext object if Ok. /// - /// + /// pub fn new, P2: AsRef>( metafits_filename: P, gpubox_filenames: &[P2], @@ -798,7 +799,7 @@ impl CorrelatorContext { metafits_fine_chans_per_coarse: usize, metafits_baselines: usize, visibility_pols: usize, - gpubox_fptr: &mut MWAFitsFile, + gpubox_fptr: &mut FitsFile, ) -> Result<(), GpuboxError> { // Get NAXIS1 and NAXIS2 from a gpubox file first image HDU let hdu = fits_open_hdu!(gpubox_fptr, 1)?; @@ -926,7 +927,7 @@ impl fmt::Display for CorrelatorContext { r#"CorrelatorContext ( Metafits Context: {metafits_context} MWA version: {corr_ver}, - + num timesteps: {n_timesteps}, timesteps: {timesteps:?}, num coarse channels, {n_coarse}, @@ -942,8 +943,8 @@ impl fmt::Display for CorrelatorContext { Common GPS start time: {common_start_gps}, Common GPS end time: {common_end_gps}, Common duration: {common_duration} s, - Common bandwidth: {common_bw} MHz, - + Common bandwidth: {common_bw} MHz, + Common/Good timestep indices: {num_common_good_timesteps}: {common_good_ts:?}, Common/Good coarse chan indices: {num_common_good_coarse_chans}: {common_good_chans:?}, Common/Good UNIX start time: {common_good_start_unix}, diff --git a/src/fits_read/mod.rs b/src/fits_read/mod.rs index 8d84d39..627af16 100644 --- a/src/fits_read/mod.rs +++ b/src/fits_read/mod.rs @@ -5,7 +5,6 @@ //! Helper functions for reading FITS files. pub(crate) mod error; -pub use crate::mwa_fits_file::MWAFitsFile; pub use error::FitsError; use fitsio::{hdu::*, FitsFile}; use log::trace; @@ -293,13 +292,11 @@ pub fn _open_fits>( file: T, source_file: &'static str, source_line: u32, -) -> Result { +) -> Result { match FitsFile::open(&file) { Ok(f) => { trace!("_open_fits() filename: '{}'", file.as_ref().display()); - - // Create the wrapper/MWAFitsFile - Ok(MWAFitsFile::new(file.as_ref().to_path_buf(), f)) + Ok(f) } Err(e) => Err(FitsError::Open { fits_error: e, @@ -315,23 +312,23 @@ pub fn _open_fits>( /// To only be used internally; use the `fits_open_hdu!` macro instead. #[doc(hidden)] pub fn _open_hdu( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, hdu_num: usize, source_file: &'static str, source_line: u32, ) -> Result { - match fits_fptr.fits_file.hdu(hdu_num) { + match fits_fptr.hdu(hdu_num) { Ok(f) => { trace!( "_open_hdu() filename: '{}' hdu: {}", - fits_fptr.filename.display(), + fits_fptr.file_path().display(), hdu_num ); Ok(f) } Err(e) => Err(FitsError::Fitsio { fits_error: e, - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: hdu_num + 1, source_file, source_line, @@ -344,23 +341,23 @@ pub fn _open_hdu( /// To only be used internally; use the `fits_open_hdu_by_name!` macro instead. #[doc(hidden)] pub fn _open_hdu_by_name( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, hdu_name: &'static str, source_file: &'static str, source_line: u32, ) -> Result { - match fits_fptr.fits_file.hdu(hdu_name) { + match fits_fptr.hdu(hdu_name) { Ok(f) => { trace!( "_open_hdu_by_name() filename: '{}' hdu: {}", - fits_fptr.filename.display(), + fits_fptr.file_path().display(), hdu_name ); Ok(f) } Err(e) => Err(FitsError::Fitsio { fits_error: e, - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: 9999, source_file, source_line, @@ -380,13 +377,13 @@ pub fn _open_hdu_by_name( // #[doc(hidden)] pub fn _get_optional_fits_key( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, hdu: &FitsHdu, keyword: &str, source_file: &'static str, source_line: u32, ) -> Result, FitsError> { - let unparsed_value: String = match hdu.read_key(&mut fits_fptr.fits_file, keyword) { + let unparsed_value: String = match hdu.read_key(fits_fptr, keyword) { Ok(key_value) => key_value, Err(e) => match &e { fitsio::errors::Error::Fits(fe) => match fe.status { @@ -394,7 +391,7 @@ pub fn _get_optional_fits_key( _ => { return Err(FitsError::Fitsio { fits_error: e, - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: hdu.number + 1, source_file, source_line, @@ -404,7 +401,7 @@ pub fn _get_optional_fits_key( _ => { return Err(FitsError::Fitsio { fits_error: e, - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: hdu.number + 1, source_file, source_line, @@ -415,7 +412,7 @@ pub fn _get_optional_fits_key( trace!( "_get_optional_fits_key() filename: '{}' hdu: {} keyword: '{}' value: '{}'", - fits_fptr.filename.display(), + fits_fptr.file_path().display(), hdu.number, String::from(keyword), unparsed_value @@ -425,7 +422,7 @@ pub fn _get_optional_fits_key( Ok(parsed_value) => Ok(Some(parsed_value)), Err(_) => Err(FitsError::Parse { key: keyword.to_string(), - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: hdu.number + 1, source_file, source_line, @@ -438,7 +435,7 @@ pub fn _get_optional_fits_key( /// To only be used internally; use the `get_required_fits_key!` macro instead. #[doc(hidden)] pub fn _get_required_fits_key( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, hdu: &FitsHdu, keyword: &str, source_file: &'static str, @@ -448,7 +445,7 @@ pub fn _get_required_fits_key( Ok(Some(value)) => Ok(value), Ok(None) => Err(FitsError::MissingKey { key: keyword.to_string(), - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: hdu.number + 1, source_file, source_line, @@ -462,17 +459,17 @@ pub fn _get_required_fits_key( /// To only be used internally; use the `fits_get_col!` macro instead. #[doc(hidden)] pub fn _get_fits_col( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, hdu: &FitsHdu, keyword: &str, source_file: &'static str, source_line: u32, ) -> Result, FitsError> { - match hdu.read_col(&mut fits_fptr.fits_file, keyword) { + match hdu.read_col(fits_fptr, keyword) { Ok(c) => { trace!( "_get_fits_col() filename: '{}' hdu: {} keyword: '{}' values: {}", - fits_fptr.filename.display(), + fits_fptr.file_path().display(), hdu.number, keyword, c.len() @@ -481,7 +478,7 @@ pub fn _get_fits_col( } Err(fits_error) => Err(FitsError::Fitsio { fits_error, - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: hdu.number + 1, source_file, source_line, @@ -506,7 +503,7 @@ pub fn _get_fits_col( /// This function calls cfitsio. Anything goes! #[doc(hidden)] pub fn _get_optional_fits_key_long_string( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, hdu: &FitsHdu, keyword: &str, source_file: &'static str, @@ -519,7 +516,7 @@ pub fn _get_optional_fits_key_long_string( let mut status = 0; let mut long_string_ptr = ptr::null_mut(); fitsio_sys::ffgkls( - fits_fptr.fits_file.as_raw(), + fits_fptr.as_raw(), keyword_ffi.as_ptr(), &mut long_string_ptr, ptr::null_mut(), @@ -537,7 +534,7 @@ pub fn _get_optional_fits_key_long_string( _ => { return Err(FitsError::LongString { key: keyword.to_string(), - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: hdu.number + 1, source_file, source_line, @@ -548,7 +545,7 @@ pub fn _get_optional_fits_key_long_string( trace!( "_get_optional_fits_key_long_string() filename: {} keyword: '{}' value: '{:?}'", - fits_fptr.filename.display(), + fits_fptr.file_path().display(), keyword, long_string ); @@ -566,7 +563,7 @@ pub fn _get_optional_fits_key_long_string( /// macro instead. #[doc(hidden)] pub fn _get_required_fits_key_long_string( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, hdu: &FitsHdu, keyword: &str, source_file: &'static str, @@ -576,7 +573,7 @@ pub fn _get_required_fits_key_long_string( Ok(Some(value)) => Ok(value), Ok(None) => Err(FitsError::MissingKey { key: keyword.to_string(), - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: hdu.number + 1, source_file, source_line, @@ -590,7 +587,7 @@ pub fn _get_required_fits_key_long_string( /// To only be used internally; use the `get_hdu_image_size!` macro instead. #[doc(hidden)] pub fn _get_hdu_image_size( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, hdu: &FitsHdu, source_file: &'static str, source_line: u32, @@ -599,14 +596,14 @@ pub fn _get_hdu_image_size( HduInfo::ImageInfo { shape, .. } => { trace!( "_get_hdu_image_size() filename: '{}' hdu: {} shape: {:?}", - fits_fptr.filename.display(), + fits_fptr.file_path().display(), hdu.number, shape ); Ok(shape.clone()) } _ => Err(FitsError::NotImage { - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: hdu.number + 1, source_file, source_line, @@ -619,31 +616,31 @@ pub fn _get_hdu_image_size( /// To only be used internally; use the `get_fits_image!` macro instead. #[doc(hidden)] pub fn _get_fits_image( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, hdu: &FitsHdu, source_file: &'static str, source_line: u32, ) -> Result { match &hdu.info { - HduInfo::ImageInfo { .. } => match hdu.read_image(&mut fits_fptr.fits_file) { + HduInfo::ImageInfo { .. } => match hdu.read_image(fits_fptr) { Ok(img) => { trace!( "_get_fits_image() filename: '{}' hdu: {}", - fits_fptr.filename.display(), + fits_fptr.file_path().display(), hdu.number ); Ok(img) } Err(e) => Err(FitsError::Fitsio { fits_error: e, - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: hdu.number + 1, source_file, source_line, }), }, _ => Err(FitsError::NotImage { - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: hdu.number + 1, source_file, source_line, @@ -654,7 +651,7 @@ pub fn _get_fits_image( /// Direct read of FITS HDU #[doc(hidden)] pub fn _get_fits_float_img_into_buf( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, hdu: &FitsHdu, buffer: &mut [f32], source_file: &'static str, @@ -668,7 +665,7 @@ pub fn _get_fits_float_img_into_buf( // Call the underlying cfitsio read function for floats let mut status = 0; fitsio_sys::ffgpv( - fits_fptr.fits_file.as_raw(), + fits_fptr.as_raw(), fitsio_sys::TFLOAT as _, 1, buffer_len, @@ -684,7 +681,7 @@ pub fn _get_fits_float_img_into_buf( Err(e) => { return Err(FitsError::Fitsio { fits_error: e, - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: hdu.number + 1, source_file, source_line, @@ -695,7 +692,7 @@ pub fn _get_fits_float_img_into_buf( trace!( "_get_fits_float_img_into_buf() filename: '{}' hdu: {}", - fits_fptr.filename.display(), + fits_fptr.file_path().display(), hdu.number ); @@ -703,16 +700,16 @@ pub fn _get_fits_float_img_into_buf( } pub fn read_cell_value( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, fits_tile_table_hdu: &fitsio::hdu::FitsHdu, col_name: &str, row: usize, ) -> Result { - match fits_tile_table_hdu.read_cell_value(&mut fits_fptr.fits_file, col_name, row) { + match fits_tile_table_hdu.read_cell_value(fits_fptr, col_name, row) { Ok(c) => { trace!( "read_cell_value() filename: '{}' hdu: {} col_name: '{}' row '{}'", - fits_fptr.filename.display(), + fits_fptr.file_path().display(), fits_tile_table_hdu.number, col_name, row @@ -720,7 +717,7 @@ pub fn read_cell_value( Ok(c) } Err(_) => Err(FitsError::ReadCell { - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: fits_tile_table_hdu.number + 1, row_num: row, col_name: col_name.to_string(), @@ -730,7 +727,7 @@ pub fn read_cell_value( /// Pull out the array-in-a-cell values. T pub fn read_cell_array_u32( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, fits_table_hdu: &fitsio::hdu::FitsHdu, col_name: &str, row: i64, @@ -741,17 +738,11 @@ pub fn read_cell_array_u32( let mut status = 0; let mut col_num = -1; let keyword = std::ffi::CString::new(col_name).unwrap().into_raw(); - fitsio_sys::ffgcno( - fits_fptr.fits_file.as_raw(), - 0, - keyword, - &mut col_num, - &mut status, - ); + fitsio_sys::ffgcno(fits_fptr.as_raw(), 0, keyword, &mut col_num, &mut status); // Check the status. if status != 0 { return Err(FitsError::CellArray { - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: fits_table_hdu.number, row_num: row, col_name: col_name.to_string(), @@ -766,7 +757,7 @@ pub fn read_cell_array_u32( array.shrink_to_fit(); let array_ptr = array.as_mut_ptr(); fitsio_sys::ffgcv( - fits_fptr.fits_file.as_raw(), + fits_fptr.as_raw(), 31, col_num, row + 1, @@ -786,7 +777,7 @@ pub fn read_cell_array_u32( trace!( "read_cell_array_u32() filename: '{}' hdu: {} col_name: '{}' row '{}'", - fits_fptr.filename.display(), + fits_fptr.file_path().display(), fits_table_hdu.number, col_name, row @@ -798,14 +789,14 @@ pub fn read_cell_array_u32( println!( "ERROR {} read_cell_array_u32() filename: '{}' hdu: {} col_name: '{}' row '{}'", status, - fits_fptr.filename.display(), + fits_fptr.file_path().display(), fits_table_hdu.number, col_name, row ); Err(FitsError::CellArray { - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: fits_table_hdu.number + 1, row_num: row, col_name: col_name.to_string(), @@ -819,7 +810,7 @@ pub fn read_cell_array_u32( /// datatype is f32, and that the fits datatype is E (f32), so it is not to be used /// generally! pub fn read_cell_array_f32( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, fits_table_hdu: &fitsio::hdu::FitsHdu, col_name: &str, row: i64, @@ -830,17 +821,11 @@ pub fn read_cell_array_f32( let mut status = 0; let mut col_num = -1; let keyword = std::ffi::CString::new(col_name).unwrap().into_raw(); - fitsio_sys::ffgcno( - fits_fptr.fits_file.as_raw(), - 0, - keyword, - &mut col_num, - &mut status, - ); + fitsio_sys::ffgcno(fits_fptr.as_raw(), 0, keyword, &mut col_num, &mut status); // Check the status. if status != 0 { return Err(FitsError::CellArray { - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: fits_table_hdu.number, row_num: row, col_name: col_name.to_string(), @@ -859,7 +844,7 @@ pub fn read_cell_array_f32( //let nullval_ptr: *mut c_void = &mut null_replace_value as *mut f32 as *mut c_void; fitsio_sys::ffgcv( - fits_fptr.fits_file.as_raw(), + fits_fptr.as_raw(), 42, col_num, row + 1, @@ -876,7 +861,7 @@ pub fn read_cell_array_f32( 0 => { trace!( "read_cell_array_f32() filename: '{}' hdu: {} col_name: '{}' row '{}'", - fits_fptr.filename.display(), + fits_fptr.file_path().display(), fits_table_hdu.number, col_name, row @@ -889,14 +874,14 @@ pub fn read_cell_array_f32( println!( "ERROR {} read_cell_array_f32() filename: '{}' hdu: {} col_name: '{}' row '{}'", status, - fits_fptr.filename.display(), + fits_fptr.file_path().display(), fits_table_hdu.number, col_name, row ); Err(FitsError::CellArray { - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: fits_table_hdu.number + 1, row_num: row, col_name: col_name.to_string(), @@ -910,7 +895,7 @@ pub fn read_cell_array_f32( /// datatype is f64, and that the fits datatype is D (f64), so it is not to be used /// generally! pub fn read_cell_array_f64( - fits_fptr: &mut MWAFitsFile, + fits_fptr: &mut FitsFile, fits_table_hdu: &fitsio::hdu::FitsHdu, col_name: &str, row: i64, @@ -921,17 +906,11 @@ pub fn read_cell_array_f64( let mut status = 0; let mut col_num = -1; let keyword = std::ffi::CString::new(col_name).unwrap().into_raw(); - fitsio_sys::ffgcno( - fits_fptr.fits_file.as_raw(), - 0, - keyword, - &mut col_num, - &mut status, - ); + fitsio_sys::ffgcno(fits_fptr.as_raw(), 0, keyword, &mut col_num, &mut status); // Check the status. if status != 0 { return Err(FitsError::CellArray { - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: fits_table_hdu.number, row_num: row, col_name: col_name.to_string(), @@ -950,7 +929,7 @@ pub fn read_cell_array_f64( //let nullval_ptr: *mut c_void = &mut null_replace_value as *mut f32 as *mut c_void; fitsio_sys::ffgcv( - fits_fptr.fits_file.as_raw(), + fits_fptr.as_raw(), 82, col_num, row + 1, @@ -967,7 +946,7 @@ pub fn read_cell_array_f64( 0 => { trace!( "read_cell_array_f64() filename: '{}' hdu: {} col_name: '{}' row '{}'", - fits_fptr.filename.display(), + fits_fptr.file_path().display(), fits_table_hdu.number, col_name, row @@ -980,14 +959,14 @@ pub fn read_cell_array_f64( println!( "ERROR {} read_cell_array_f64() filename: '{}' hdu: {} col_name: '{}' row '{}'", status, - fits_fptr.filename.display(), + fits_fptr.file_path().display(), fits_table_hdu.number, col_name, row ); Err(FitsError::CellArray { - fits_filename: fits_fptr.filename.clone(), + fits_filename: fits_fptr.file_path().to_path_buf(), hdu_num: fits_table_hdu.number + 1, row_num: row, col_name: col_name.to_string(), diff --git a/src/fits_read/test.rs b/src/fits_read/test.rs index a174cdb..8052349 100644 --- a/src/fits_read/test.rs +++ b/src/fits_read/test.rs @@ -26,8 +26,7 @@ fn test_get_hdu_image_size_image() { }; // Create a new image HDU - fptr.fits_file - .create_image("EXTNAME".to_string(), &image_description) + fptr.create_image("EXTNAME".to_string(), &image_description) .unwrap(); let hdu = fits_open_hdu!(fptr, 1).expect("Couldn't open HDU 1"); @@ -57,8 +56,7 @@ fn test_get_hdu_image_size_non_image() { .unwrap(); let descriptions = [first_description, second_description]; - fptr.fits_file - .create_table("EXTNAME".to_string(), &descriptions) + fptr.create_table("EXTNAME".to_string(), &descriptions) .unwrap(); let hdu = fits_open_hdu!(fptr, 1).expect("Couldn't open HDU 1"); @@ -80,15 +78,12 @@ fn test_get_fits_image_valid_f32() { }; // Create a new image HDU - fptr.fits_file - .create_image("EXTNAME".to_string(), &image_description) + fptr.create_image("EXTNAME".to_string(), &image_description) .unwrap(); let hdu = fits_open_hdu!(fptr, 1).expect("Couldn't open HDU 1"); // Write some data - assert!(hdu - .write_image(&mut fptr.fits_file, &[1.0, 2.0, 3.0]) - .is_ok()); + assert!(hdu.write_image(fptr, &[1.0, 2.0, 3.0]).is_ok()); // Run our test, check dimensions let size_vec = get_hdu_image_size!(fptr, &hdu).unwrap(); @@ -117,13 +112,12 @@ fn test_get_fits_image_valid_i32() { }; // Create a new image HDU - fptr.fits_file - .create_image("EXTNAME".to_string(), &image_description) + fptr.create_image("EXTNAME".to_string(), &image_description) .unwrap(); let hdu = fits_open_hdu!(fptr, 1).expect("Couldn't open HDU 1"); // Write some data - assert!(hdu.write_image(&mut fptr.fits_file, &[-1, 0, 1]).is_ok()); + assert!(hdu.write_image(fptr, &[-1, 0, 1]).is_ok()); // Run our test, check dimensions let size_vec = get_hdu_image_size!(fptr, &hdu).unwrap(); @@ -152,15 +146,12 @@ fn test_get_fits_image_invalid() { }; // Create a new image HDU - fptr.fits_file - .create_image("EXTNAME".to_string(), &image_description) + fptr.create_image("EXTNAME".to_string(), &image_description) .unwrap(); let hdu = fits_open_hdu!(fptr, 1).expect("Couldn't open HDU 1"); // Write some data - assert!(hdu - .write_image(&mut fptr.fits_file, &[-12345678, 0, 12345678]) - .is_ok()); + assert!(hdu.write_image(fptr, &[-12345678, 0, 12345678]).is_ok()); // Run our test, check dimensions let size_vec = get_hdu_image_size!(fptr, &hdu).unwrap(); @@ -203,8 +194,7 @@ fn test_get_fits_image_not_image() { .unwrap(); let descriptions = [first_description, second_description]; - fptr.fits_file - .create_table("EXTNAME".to_string(), &descriptions) + fptr.create_table("EXTNAME".to_string(), &descriptions) .unwrap(); let hdu = fits_open_hdu!(fptr, 1).expect("Couldn't open HDU 1"); @@ -235,22 +225,22 @@ fn test_get_required_fits_key() { assert!(doesnt_exist.is_err()); // Key types must be i64 to get any sort of sanity. - hdu.write_key(&mut fptr.fits_file, "foo", 10i64) + hdu.write_key(fptr, "foo", 10i64) .expect("Couldn't write key 'foo'"); - hdu.write_key(&mut fptr.fits_file, "bar", -5i64) + hdu.write_key(fptr, "bar", -5i64) .expect("Couldn't write key 'bar'"); // Verify that using the normal `fitsio` gives the wrong result, unless // the type is an i64. - let fits_value_i32 = hdu.read_key::(&mut fptr.fits_file, "FOO"); - let fits_value_i64 = hdu.read_key::(&mut fptr.fits_file, "FOO"); + let fits_value_i32 = hdu.read_key::(fptr, "FOO"); + let fits_value_i64 = hdu.read_key::(fptr, "FOO"); assert!(fits_value_i32.is_ok()); assert!(fits_value_i64.is_ok()); assert_eq!(fits_value_i32.unwrap(), 1); assert_eq!(fits_value_i64.unwrap(), 10); // Despite writing to "fits_value", the key is written as "FOO". - let fits_value_i64 = hdu.read_key::(&mut fptr.fits_file, "FOO"); + let fits_value_i64 = hdu.read_key::(fptr, "FOO"); assert!(fits_value_i64.is_ok()); assert_eq!(fits_value_i64.unwrap(), 10); @@ -274,7 +264,7 @@ fn test_get_required_fits_key() { fn test_get_optional_fits_key() { // with_temp_file creates a temp dir and temp file, then removes them once out of scope with_new_temp_fits_file("test_fits_read_key.fits", |fptr| { - let hdu = fptr.fits_file.hdu(0).expect("Couldn't open HDU 0"); + let hdu = fptr.hdu(0).expect("Couldn't open HDU 0"); // Failure to get a key that doesn't exist is OK if we're using the optional variant. let fits_value: Result, _> = get_optional_fits_key!(fptr, &hdu, "foo"); @@ -282,22 +272,22 @@ fn test_get_optional_fits_key() { assert!(fits_value.unwrap().is_none()); // Key types must be i64 to get any sort of sanity. - hdu.write_key(&mut fptr.fits_file, "foo", 10i64) + hdu.write_key(fptr, "foo", 10i64) .expect("Couldn't write key 'foo'"); - hdu.write_key(&mut fptr.fits_file, "bar", -5i64) + hdu.write_key(fptr, "bar", -5i64) .expect("Couldn't write key 'bar'"); // Verify that using the normal `fitsio` gives the wrong result, unless // the type is an i64. - let fits_value_i32 = hdu.read_key::(&mut fptr.fits_file, "FOO"); - let fits_value_i64 = hdu.read_key::(&mut fptr.fits_file, "FOO"); + let fits_value_i32 = hdu.read_key::(fptr, "FOO"); + let fits_value_i64 = hdu.read_key::(fptr, "FOO"); assert!(fits_value_i32.is_ok()); assert!(fits_value_i64.is_ok()); assert_eq!(fits_value_i32.unwrap(), 1); assert_eq!(fits_value_i64.unwrap(), 10); // Despite writing to "foo", the key is written as "FOO". - let fits_value_i64 = hdu.read_key::(&mut fptr.fits_file, "FOO"); + let fits_value_i64 = hdu.read_key::(fptr, "FOO"); assert!(fits_value_i64.is_ok()); assert_eq!(fits_value_i64.unwrap(), 10); @@ -329,7 +319,7 @@ fn test_get_required_fits_key_string() { assert!(does_not_exist.is_err()); // Add a test string - hdu.write_key(&mut fptr.fits_file, "fits_value", "hello") + hdu.write_key(fptr, "fits_value", "hello") .expect("Couldn't write key 'fits_value'"); // Read fits_value back in @@ -344,7 +334,7 @@ fn test_get_required_fits_key_string() { fn test_get_optional_fits_key_string() { // with_temp_file creates a temp dir and temp file, then removes them once out of scope with_new_temp_fits_file("test_fits_read_key_string.fits", |fptr| { - let hdu = fptr.fits_file.hdu(0).expect("Couldn't open HDU 0"); + let hdu = fptr.hdu(0).expect("Couldn't open HDU 0"); // No Failure to get a key that doesn't exist. let does_not_exist: Result, FitsError> = @@ -354,7 +344,7 @@ fn test_get_optional_fits_key_string() { assert!(does_not_exist.unwrap().is_none()); // Add a test string - hdu.write_key(&mut fptr.fits_file, "fits_value", "hello") + hdu.write_key(fptr, "fits_value", "hello") .expect("Couldn't write key 'fits_value'"); // Read fits_value back in @@ -377,7 +367,7 @@ fn test_get_fits_long_string() { // Sadly, rust's `fitsio` library doesn't support writing long strings // with CONTINUE statements. We have to do it for ourselves. unsafe { - let fptr_ffi = fptr.fits_file.as_raw(); + let fptr_ffi = fptr.as_raw(); let keyword_ffi = CString::new("foo").expect("get_fits_long_string: CString::new() failed for 'foo'"); let value_ffi = CString::new(complete_string) @@ -393,19 +383,19 @@ fn test_get_fits_long_string() { ); } - let hdu = fptr.fits_file.hdu(0).unwrap(); + let hdu = fptr.hdu(0).unwrap(); let fits_value_str = get_required_fits_key_long_string!(fptr, &hdu, "FOO"); assert!(fits_value_str.is_ok()); assert_eq!(fits_value_str.unwrap(), complete_string); // Try out the `fitsio` read key. - let hdu = fptr.fits_file.hdu(0).expect("Couldn't open HDU 0"); - let fitsio_str = hdu.read_key::(&mut fptr.fits_file, "FOO"); + let hdu = fptr.hdu(0).expect("Couldn't open HDU 0"); + let fitsio_str = hdu.read_key::(fptr, "FOO"); assert!(fitsio_str.is_ok()); assert_eq!(fitsio_str.unwrap(), first_string); // A repeated read just returns the first string again. - let fitsio_str = hdu.read_key::(&mut fptr.fits_file, "FOO"); + let fitsio_str = hdu.read_key::(fptr, "FOO"); assert!(fitsio_str.is_ok()); assert_eq!(fitsio_str.unwrap(), first_string); }); @@ -421,7 +411,7 @@ fn test_get_required_fits_long_string() { // Sadly, rust's `fitsio` library doesn't support writing long strings // with CONTINUE statements. We have to do it for ourselves. unsafe { - let fptr_ffi = fptr.fits_file.as_raw(); + let fptr_ffi = fptr.as_raw(); let keyword_ffi = CString::new("foo").expect("get_fits_long_string: CString::new() failed for 'foo'"); let value_ffi = CString::new(complete_string) @@ -437,7 +427,7 @@ fn test_get_required_fits_long_string() { ); } - let hdu = fptr.fits_file.hdu(0).expect("Couldn't open HDU 0"); + let hdu = fptr.hdu(0).expect("Couldn't open HDU 0"); // Check for a valid long string let result1 = get_required_fits_key_long_string!(fptr, &hdu, "FOO"); @@ -445,13 +435,13 @@ fn test_get_required_fits_long_string() { assert_eq!(result1.unwrap(), complete_string); // Try out the `fitsio` read key. - let hdu = fptr.fits_file.hdu(0).expect("Couldn't open HDU 0"); - let fitsio_str = hdu.read_key::(&mut fptr.fits_file, "FOO"); + let hdu = fptr.hdu(0).expect("Couldn't open HDU 0"); + let fitsio_str = hdu.read_key::(fptr, "FOO"); assert!(fitsio_str.is_ok()); assert_eq!(fitsio_str.unwrap(), first_string); // A repeated read just returns the first string again. - let fitsio_str = hdu.read_key::(&mut fptr.fits_file, "FOO"); + let fitsio_str = hdu.read_key::(fptr, "FOO"); assert!(fitsio_str.is_ok()); assert_eq!(fitsio_str.unwrap(), first_string); @@ -480,7 +470,7 @@ fn test_get_optional_fits_long_string() { // Sadly, rust's `fitsio` library doesn't support writing long strings // with CONTINUE statements. We have to do it for ourselves. unsafe { - let fptr_ffi = fptr.fits_file.as_raw(); + let fptr_ffi = fptr.as_raw(); let keyword_ffi = CString::new("foo").expect("get_fits_long_string: CString::new() failed for 'foo'"); let value_ffi = CString::new(complete_string) @@ -496,7 +486,7 @@ fn test_get_optional_fits_long_string() { ); } - let hdu = fptr.fits_file.hdu(0).expect("Couldn't open HDU 0"); + let hdu = fptr.hdu(0).expect("Couldn't open HDU 0"); // Read a key that IS there let result1 = get_optional_fits_key_long_string!(fptr, &hdu, "FOO"); @@ -507,12 +497,12 @@ fn test_get_optional_fits_long_string() { assert_eq!(fits_value1_str.unwrap(), complete_string); // Try out the `fitsio` read key. - let fitsio_str = hdu.read_key::(&mut fptr.fits_file, "FOO"); + let fitsio_str = hdu.read_key::(fptr, "FOO"); assert!(fitsio_str.is_ok()); assert_eq!(fitsio_str.unwrap(), first_string); // A repeated read just returns the first string again. - let fitsio_str = hdu.read_key::(&mut fptr.fits_file, "FOO"); + let fitsio_str = hdu.read_key::(fptr, "FOO"); assert!(fitsio_str.is_ok()); assert_eq!(fitsio_str.unwrap(), first_string); @@ -535,7 +525,7 @@ fn test_get_fits_long_string_failure() { // Sadly, rust's `fitsio` library doesn't support writing long strings // with CONTINUE statements. We have to do it for ourselves. unsafe { - let fptr_ffi = fptr.fits_file.as_raw(); + let fptr_ffi = fptr.as_raw(); let keyword_ffi = CString::new("fits_value") .expect("get_fits_long_string: CString::new() failed for 'fits_value'"); let value_ffi = CString::new(complete_string) @@ -551,7 +541,7 @@ fn test_get_fits_long_string_failure() { ); } - let hdu = fptr.fits_file.hdu(0).unwrap(); + let hdu = fptr.hdu(0).unwrap(); let fits_value_str = get_required_fits_key_long_string!(fptr, &hdu, "NOTfits_value"); assert!(fits_value_str.is_err()); }); diff --git a/src/gpubox_files/mod.rs b/src/gpubox_files/mod.rs index e513ca5..85eb786 100644 --- a/src/gpubox_files/mod.rs +++ b/src/gpubox_files/mod.rs @@ -18,6 +18,8 @@ use regex::Regex; use crate::*; pub use error::GpuboxError; +use fitsio::FitsFile; + #[cfg(feature = "python")] use pyo3_stub_gen_derive::gen_stub_pyclass; @@ -258,7 +260,7 @@ pub(crate) fn examine_gpubox_files>( // Check that there are some HDUs (apart from just the primary) // Assuming it does have some, open the first one - let hdu = match fptr.fits_file.iter().count() { + let hdu = match fptr.iter().count() { 1 => { return Err(GpuboxError::NoDataHDUsInGpuboxFile { gpubox_filename: g.filename.clone(), @@ -418,7 +420,7 @@ fn determine_gpubox_batches>( /// /// # Arguments /// -/// * `gpubox_fptr` - An MWAFitsFile reference to this gpubox file. +/// * `gpubox_fptr` - a FitsFile reference to this gpubox file. /// /// * `gpubox_hdu_fptr` - A reference to the HDU we are finding the time of. /// @@ -429,7 +431,7 @@ fn determine_gpubox_batches>( /// /// fn determine_hdu_time( - gpubox_fptr: &mut MWAFitsFile, + gpubox_fptr: &mut FitsFile, gpubox_hdu_fptr: &FitsHdu, ) -> Result { let start_unix_time: u64 = get_required_fits_key!(gpubox_fptr, gpubox_hdu_fptr, "TIME")?; @@ -444,7 +446,7 @@ fn determine_hdu_time( /// /// # Arguments /// -/// * `gpubox_fptr` - An MWAFitsFile reference to this gpubox file. +/// * `gpubox_fptr` - a FitsFile reference to this gpubox file. /// /// * `mwa_version` - enum telling us which correlator version the observation was created by. /// @@ -455,11 +457,11 @@ fn determine_hdu_time( /// /// fn map_unix_times_to_hdus( - gpubox_fptr: &mut MWAFitsFile, + gpubox_fptr: &mut FitsFile, mwa_version: MWAVersion, ) -> Result, FitsError> { let mut map = BTreeMap::new(); - let last_hdu_index = gpubox_fptr.fits_file.iter().count(); + let last_hdu_index = gpubox_fptr.iter().count(); // The new correlator has a "weights" HDU in each alternating HDU. Skip // those. let step_size = if mwa_version == MWAVersion::CorrMWAXv2 { @@ -484,7 +486,7 @@ fn map_unix_times_to_hdus( /// /// # Arguments /// -/// * `gpubox_fptr` - An MWAFitsFile reference to this gpubox file. +/// * `gpubox_fptr` - a FitsFile reference to this gpubox file. /// /// * `gpubox_primary_hdu` - The primary HDU of the gpubox file. /// @@ -499,7 +501,7 @@ fn map_unix_times_to_hdus( /// /// fn validate_gpubox_metadata_mwa_version( - gpubox_fptr: &mut MWAFitsFile, + gpubox_fptr: &mut FitsFile, gpubox_primary_hdu: &FitsHdu, gpubox_filename: &str, mwa_version: MWAVersion, @@ -537,7 +539,7 @@ fn validate_gpubox_metadata_mwa_version( /// /// # Arguments /// -/// * `gpubox_fptr` - An MWAFitsFile reference to this gpubox file. +/// * `gpubox_fptr` - a FitsFile reference to this gpubox file. /// /// * `gpubox_primary_hdu` - The primary HDU of the gpubox file. /// @@ -552,7 +554,7 @@ fn validate_gpubox_metadata_mwa_version( /// /// fn validate_gpubox_metadata_obs_id( - gpubox_fptr: &mut MWAFitsFile, + gpubox_fptr: &mut FitsFile, gpubox_primary_hdu: &FitsHdu, gpubox_filename: &str, metafits_obs_id: u32, @@ -620,7 +622,7 @@ fn create_time_map( } } - // Get the UNIX times from each of the HDUs of this `MWAFitsFile`. + // Get the UNIX times from each of the HDUs of this `FitsFile`. map_unix_times_to_hdus(&mut fptr, mwa_version).map_err(GpuboxError::from) }) .collect::, GpuboxError>>>(); diff --git a/src/gpubox_files/test.rs b/src/gpubox_files/test.rs index 559fae3..04175c4 100644 --- a/src/gpubox_files/test.rs +++ b/src/gpubox_files/test.rs @@ -371,13 +371,13 @@ fn test_no_hdus() { fn test_determine_hdu_time_test1() { // with_temp_file creates a temp dir and temp file, then removes them once out of scope with_new_temp_fits_file("determine_hdu_time_test1.fits", |fptr| { - let hdu = fptr.fits_file.hdu(0).expect("Couldn't open HDU 0"); + let hdu = fptr.hdu(0).expect("Couldn't open HDU 0"); // Write the TIME and MILLITIM keys. Key types must be i64 to get any // sort of sanity. - hdu.write_key(&mut fptr.fits_file, "TIME", 1_434_494_061) + hdu.write_key(fptr, "TIME", 1_434_494_061) .expect("Couldn't write key 'TIME'"); - hdu.write_key(&mut fptr.fits_file, "MILLITIM", 0) + hdu.write_key(fptr, "MILLITIM", 0) .expect("Couldn't write key 'MILLITIM'"); let result = determine_hdu_time(fptr, &hdu); @@ -390,11 +390,11 @@ fn test_determine_hdu_time_test1() { fn test_determine_hdu_time_test2() { // with_temp_file creates a temp dir and temp file, then removes them once out of scope with_new_temp_fits_file("determine_hdu_time_test2.fits", |fptr| { - let hdu = fptr.fits_file.hdu(0).expect("Couldn't open HDU 0"); + let hdu = fptr.hdu(0).expect("Couldn't open HDU 0"); - hdu.write_key(&mut fptr.fits_file, "TIME", 1_381_844_923) + hdu.write_key(fptr, "TIME", 1_381_844_923) .expect("Couldn't write key 'TIME'"); - hdu.write_key(&mut fptr.fits_file, "MILLITIM", 500) + hdu.write_key(fptr, "MILLITIM", 500) .expect("Couldn't write key 'MILLITIM'"); let result = determine_hdu_time(fptr, &hdu); @@ -413,11 +413,11 @@ fn test_determine_hdu_time_test3() { // with_temp_file creates a temp dir and temp file, then removes them once out of scope with_new_temp_fits_file("determine_hdu_time_test3.fits", |fptr| { - let hdu = fptr.fits_file.hdu(0).expect("Couldn't open HDU 0"); + let hdu = fptr.hdu(0).expect("Couldn't open HDU 0"); - hdu.write_key(&mut fptr.fits_file, "TIME", current) + hdu.write_key(fptr, "TIME", current) .expect("Couldn't write key 'TIME'"); - hdu.write_key(&mut fptr.fits_file, "MILLITIM", 500) + hdu.write_key(fptr, "MILLITIM", 500) .expect("Couldn't write key 'MILLITIM'"); let result = determine_hdu_time(fptr, &hdu); @@ -439,12 +439,11 @@ fn test_map_unix_times_to_hdus_test() { }; for (i, (time, millitime)) in times.iter().enumerate() { let hdu = fptr - .fits_file .create_image("EXTNAME".to_string(), &image_description) .expect("Couldn't create image"); - hdu.write_key(&mut fptr.fits_file, "TIME", *time) + hdu.write_key(fptr, "TIME", *time) .expect("Couldn't write key 'TIME'"); - hdu.write_key(&mut fptr.fits_file, "MILLITIM", *millitime) + hdu.write_key(fptr, "MILLITIM", *millitime) .expect("Couldn't write key 'MILLITIM'"); expected.insert(time * 1000 + millitime, i + 1); @@ -553,7 +552,7 @@ fn test_determine_common_times_test_one_timestep() { fn test_validate_gpubox_metadata_mwa_version() { // with_temp_file creates a temp dir and temp file, then removes them once out of scope with_new_temp_fits_file("test_validate_gpubox_metadata_mwa_version.fits", |fptr| { - let hdu = fptr.fits_file.hdu(0).expect("Couldn't open HDU 0"); + let hdu = fptr.hdu(0).expect("Couldn't open HDU 0"); // This should succeed- LegacyOld should NOT have CORR_VER key assert!(validate_gpubox_metadata_mwa_version( @@ -583,7 +582,7 @@ fn test_validate_gpubox_metadata_mwa_version() { .is_err()); // Now put in a corr version - hdu.write_key(&mut fptr.fits_file, "CORR_VER", 2) + hdu.write_key(fptr, "CORR_VER", 2) .expect("Couldn't write key 'CORR_VER'"); // This should succeed- V2 should have CORR_VER key @@ -617,12 +616,12 @@ fn test_validate_gpubox_metadata_mwa_version() { // with_temp_file creates a temp dir and temp file, then removes them once out of scope // This section tests CORR_VER where it is != 2 with_new_temp_fits_file("test_validate_gpubox_metadata_mwa_version.fits", |fptr| { - let hdu = fptr.fits_file.hdu(0).expect("Couldn't open HDU 0"); + let hdu = fptr.hdu(0).expect("Couldn't open HDU 0"); // This should not succeed- CORR_VER key if it exists should be 2 // CORR_VER did not exist in OldLegacy or Legacy correlator // Now put in a corr version - hdu.write_key(&mut fptr.fits_file, "CORR_VER", 1) + hdu.write_key(fptr, "CORR_VER", 1) .expect("Couldn't write key 'CORR_VER'"); assert!(validate_gpubox_metadata_mwa_version( @@ -639,7 +638,7 @@ fn test_validate_gpubox_metadata_mwa_version() { fn test_validate_gpubox_metadata_obsid() { // with_temp_file creates a temp dir and temp file, then removes them once out of scope with_new_temp_fits_file("test_validate_gpubox_metadata_mwa_version.fits", |fptr| { - let hdu = fptr.fits_file.hdu(0).expect("Couldn't open HDU 0"); + let hdu = fptr.hdu(0).expect("Couldn't open HDU 0"); // OBSID is not there, this should be an error assert!(validate_gpubox_metadata_obs_id( @@ -651,7 +650,7 @@ fn test_validate_gpubox_metadata_obsid() { .is_err()); // Now add the key - hdu.write_key(&mut fptr.fits_file, "OBSID", 1_234_567_890) + hdu.write_key(fptr, "OBSID", 1_234_567_890) .expect("Couldn't write key 'OBSID'"); // OBSID is there, but does not match metafits- this should be an error diff --git a/src/lib.rs b/src/lib.rs index 4bebbb9..78e228d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,6 @@ mod fits_read; mod gpubox_files; mod metafits_context; mod misc; -mod mwa_fits_file; mod rfinput; mod signal_chain_correction; mod timestep; diff --git a/src/metafits_context/mod.rs b/src/metafits_context/mod.rs index 7ce8487..6d9b1f3 100644 --- a/src/metafits_context/mod.rs +++ b/src/metafits_context/mod.rs @@ -8,7 +8,7 @@ use std::fmt; use std::path::Path; use chrono::{DateTime, Duration, FixedOffset}; -use fitsio::hdu::HduInfo; +use fitsio::{hdu::HduInfo, FitsFile}; use num_derive::FromPrimitive; use num_traits::ToPrimitive; @@ -363,7 +363,7 @@ pub struct MetafitsContext { pub sched_end_unix_time_ms: u64, /// Scheduled start (UTC) of observation pub sched_start_utc: DateTime, - /// Scheduled end (UTC) of observation + /// Scheduled end (UTC) of observation pub sched_end_utc: DateTime, /// Scheduled start (MJD) of observation pub sched_start_mjd: f64, @@ -422,7 +422,7 @@ pub struct MetafitsContext { pub mode: MWAMode, /// Which Geometric delays have been applied to the data? pub geometric_delays_applied: GeometricDelaysApplied, - /// Have cable delays been applied to the data? + /// Have cable delays been applied to the data? pub cable_delays_applied: CableDelaysApplied, /// Have calibration delays and gains been applied to the data? pub calibration_delays_and_gains_applied: bool, @@ -462,7 +462,7 @@ pub struct MetafitsContext { pub num_ants: usize, /// We also have just the antennas pub antennas: Vec, - /// Total number of rf_inputs (tiles * 2 pols X&Y) + /// Total number of rf_inputs (tiles * 2 pols X&Y) pub num_rf_inputs: usize, /// The Metafits defines an rf chain for antennas(tiles) * pol(X,Y) pub rf_inputs: Vec, @@ -490,7 +490,7 @@ pub struct MetafitsContext { pub num_baselines: usize, /// Baslines pub baselines: Vec, - /// Number of polarisation combinations in the visibilities e.g. XX,XY,YX,YY == 4 + /// Number of polarisation combinations in the visibilities e.g. XX,XY,YX,YY == 4 pub num_visibility_pols: usize, /// Filename of the metafits we were given pub metafits_filename: String, @@ -1083,7 +1083,7 @@ impl MetafitsContext { /// /// # Arguments /// - /// * `metafits_fptr` - reference to the MWAFitsFile representing the metafits file. + /// * `metafits_fptr` - reference to the FitsFile representing the metafits file. /// /// * `sig_chain_hdu` - The FitsHdu containing valid signal chain corrections data. /// @@ -1092,7 +1092,7 @@ impl MetafitsContext { /// * Result containing a vector of signal chain corrections read from the sig_chain_hdu HDU. /// fn populate_signal_chain_corrections( - metafits_fptr: &mut MWAFitsFile, + metafits_fptr: &mut FitsFile, sig_chain_hdu: &fitsio::hdu::FitsHdu, ) -> Result, FitsError> { // Find out how many rows there are in the table @@ -1138,7 +1138,7 @@ impl MetafitsContext { /// Given a hint at the expected `MWAVersion`, populate the coarse_channel vector with the expected /// coarse channels for an existing populated MetafitsContext. /// - /// # Arguments + /// # Arguments /// /// * `mwa_version` - Hint, providing the `MWAVersion` info, so the expected `CoarseChannel`s can be returned. /// @@ -1182,7 +1182,7 @@ impl MetafitsContext { /// Given a hint at the expected `MWAVersion`, populate the timesteps vector with the expected /// timesteps for an existing populated MetafitsContext. /// - /// # Arguments + /// # Arguments /// /// * `mwa_version` - Hint, providing the `MWAVersion` info, so the expected `TimeStep`s can be returned. /// @@ -1213,11 +1213,11 @@ impl MetafitsContext { /// Return an expected voltage filenames for the input timestep and coarse channel indices. /// - /// # Arguments + /// # Arguments /// - /// * `metafits_timestep_index` - the timestep index. + /// * `metafits_timestep_index` - the timestep index. /// - /// * `metafits_coarse_chan_index` - the coarse channel index. + /// * `metafits_coarse_chan_index` - the coarse channel index. /// /// /// # Returns @@ -1317,7 +1317,7 @@ impl fmt::Display for MetafitsContext { Scheduled duration {sched_duration} s, Quack time: {quack_duration} s, Good UNIX start time: {good_time}, - + Num timesteps: {nts}, Timesteps: {ts:?}, diff --git a/src/misc/test.rs b/src/misc/test.rs index c2073ed..b6c2891 100644 --- a/src/misc/test.rs +++ b/src/misc/test.rs @@ -9,7 +9,6 @@ use core::f32; #[cfg(test)] use super::*; use crate::antenna::*; -use crate::fits_read::*; use crate::rfinput::*; use float_cmp::*; @@ -28,7 +27,7 @@ use float_cmp::*; #[cfg(test)] pub fn with_new_temp_fits_file(filename: &str, callback: F) where - F: for<'a> Fn(&'a mut MWAFitsFile), + F: for<'a> Fn(&'a mut fitsio::FitsFile), { let tdir = tempdir::TempDir::new("fitsio-").unwrap(); let tdir_path = tdir.path(); @@ -36,13 +35,11 @@ where let filename_str = filename.to_str().expect("cannot create string filename"); - let fptr = fitsio::FitsFile::create(filename_str) + let mut fptr = fitsio::FitsFile::create(filename_str) .open() .expect("Couldn't open tempfile"); - let mut mwa_fits_file = MWAFitsFile::new(filename_str.into(), fptr); - - callback(&mut mwa_fits_file); + callback(&mut fptr); } #[test] diff --git a/src/mwa_fits_file/mod.rs b/src/mwa_fits_file/mod.rs deleted file mode 100644 index 0e597fc..0000000 --- a/src/mwa_fits_file/mod.rs +++ /dev/null @@ -1,47 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -//! Encapsulating filename and FitsFile - -// This struct encapsulates the fitsio::FitsFile struct and adds back -// the 'filename' property that was removed in v0.21.0 of the fitsio crate -// -use fitsio::FitsFile; -use std::path::PathBuf; - -#[cfg(test)] -mod test; - -pub struct MWAFitsFile { - /// FitsFile struct - pub fits_file: FitsFile, - - /// Filename (filename, including - /// the full or relative path to the file) - pub filename: PathBuf, -} - -impl MWAFitsFile { - /// Creates an encapsulating struct to hold a FitsFile object and - /// it's filename. Filename was removed from fitsio in 0.21, so - /// this is a way to retain that property since we use it in error - /// messages and debug. - /// - /// # Arguments - /// - /// * `filename` - filename of FITS file as a path or string. - /// - /// * `fits_file` - an already created fitsio::FitsFile struct - /// - /// # Returns - /// - /// * A populated MWAFits object - /// - pub fn new(filename: PathBuf, fits_file: FitsFile) -> Self { - MWAFitsFile { - fits_file, - filename, - } - } -} diff --git a/src/mwa_fits_file/test.rs b/src/mwa_fits_file/test.rs deleted file mode 100644 index fd6a42c..0000000 --- a/src/mwa_fits_file/test.rs +++ /dev/null @@ -1,38 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -//! Unit tests for the mwa_fits_file module -#[cfg(test)] -use fitsio::FitsFile; - -#[test] -fn test_mwa_fits_file_new() { - use super::MWAFitsFile; - - let metafits_filename = "test_files/1101503312_1_timestep/1101503312.metafits"; - - let fptr = FitsFile::open(metafits_filename).expect("Could not open fits file!"); - - let mut mwa_fits_file = MWAFitsFile::new(metafits_filename.into(), fptr); - - // Check it works! - assert_eq!( - mwa_fits_file.filename.display().to_string(), - metafits_filename - ); - - // Open a hdu - let hdu = mwa_fits_file - .fits_file - .hdu(0) - .expect("Could not open PRIMARY HDU"); - - // Read the obs_id from the fits file - let obs_id = hdu - .read_key::(&mut mwa_fits_file.fits_file, "GPSTIME") - .expect("Cannot read key"); - - // Ensure it is what is expected - assert_eq!(obs_id, 1101503312); -} diff --git a/src/rfinput/mod.rs b/src/rfinput/mod.rs index 50b2070..e14de2b 100644 --- a/src/rfinput/mod.rs +++ b/src/rfinput/mod.rs @@ -10,6 +10,7 @@ use crate::signal_chain_correction::SignalChainCorrection; use crate::{fits_open_hdu_by_name, fits_read::*}; use core::f32; use error::RfinputError; +use fitsio::FitsFile; use std::fmt; #[cfg(feature = "python")] @@ -374,7 +375,7 @@ impl Rfinput { /// /// # Arguments /// - /// * `metafits_fptr` - reference to the MWAFitsFile representing the metafits file. + /// * `metafits_fptr` - reference to the FitsFile representing the metafits file. /// /// * `metafits_tile_table_hdu` - reference to the HDU containing the TILEDATA table. /// @@ -388,7 +389,7 @@ impl Rfinput { /// * An Result containing a populated vector of RFInputMetafitsTableRow structss or an Error /// fn read_metafits_tiledata_values( - metafits_fptr: &mut MWAFitsFile, + metafits_fptr: &mut FitsFile, metafits_tile_table_hdu: &fitsio::hdu::FitsHdu, row: usize, num_coarse_chans: usize, @@ -404,7 +405,7 @@ impl Rfinput { "Y" => Pol::Y, _ => { return Err(RfinputError::UnrecognisedPol { - fits_filename: metafits_fptr.filename.clone(), + fits_filename: metafits_fptr.file_path().to_path_buf(), hdu_num: metafits_tile_table_hdu.number + 1, row_num: row, got: p, @@ -502,7 +503,7 @@ impl Rfinput { /// /// # Arguments /// - /// * `metafits_fptr` - reference to the MWAFitsFile representing the metafits file. + /// * `metafits_fptr` - reference to the FitsFile representing the metafits file. /// /// * `metafits_calibdata_table_hdu` - reference to the HDU containing the CALIBDATA table. /// @@ -516,7 +517,7 @@ impl Rfinput { /// * An Result containing a populated vector of RFInputMetafitsTableRow structss or an Error /// fn read_metafits_calibdata_values( - metafits_fptr: &mut MWAFitsFile, + metafits_fptr: &mut FitsFile, metafits_calibdata_table_hdu: &Option, row: usize, num_coarse_chans: usize, @@ -532,7 +533,7 @@ impl Rfinput { "Y" => Pol::Y, _ => { return Err(RfinputError::UnrecognisedPol { - fits_filename: metafits_fptr.filename.clone(), + fits_filename: metafits_fptr.file_path().to_path_buf(), hdu_num: metafits_cal_hdu.number + 1, row_num: row, got: p, @@ -573,7 +574,7 @@ impl Rfinput { /// /// * `num_inputs` - number of rf_inputs to read from the metafits TILEDATA bintable. /// - /// * `metafits_fptr` - reference to the MWAFitsFile representing the metafits file. + /// * `metafits_fptr` - reference to the FitsFile representing the metafits file. /// /// * `metafits_tile_table_hdu` - reference to the HDU containing the TILEDATA table. /// @@ -587,7 +588,7 @@ impl Rfinput { /// pub(crate) fn populate_rf_inputs( num_inputs: usize, - metafits_fptr: &mut MWAFitsFile, + metafits_fptr: &mut FitsFile, metafits_tile_table_hdu: fitsio::hdu::FitsHdu, coax_v_factor: f64, num_coarse_chans: usize, diff --git a/src/rfinput/test.rs b/src/rfinput/test.rs index cd1ecaa..549f65e 100644 --- a/src/rfinput/test.rs +++ b/src/rfinput/test.rs @@ -113,7 +113,6 @@ fn test_read_metafits_tiledata_values_from_invalid_metafits() { let descriptions = [first_description, second_description]; metafits_fptr - .fits_file .create_table("TILEDATA".to_string(), &descriptions) .unwrap(); @@ -178,12 +177,10 @@ fn test_read_metafits_calibdata_values_from_invalid_metafits() { let descriptions = [first_description, second_description]; metafits_fptr - .fits_file .create_table("TILEDATA".to_string(), &descriptions) .unwrap(); metafits_fptr - .fits_file .create_table("CALIBDATA".to_string(), &descriptions) .unwrap();