Skip to content

Commit

Permalink
Used prerelease version of pyo3_stub_gen to ensure Chrono::FixedTimeO…
Browse files Browse the repository at this point in the history
…ffset can have a stub generated in MetafitsContext
  • Loading branch information
gsleap committed Nov 8, 2024
2 parents c07e9b9 + 8b02237 commit 2188509
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 323 deletions.
19 changes: 13 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@

Changes in each release are listed below.

## 1.7.2 ???????????
## 1.8.0 8-Nov-2024

* Fixed pyo3 decorators to allow stub_gen to work properly- generating python stubs correctly.
* (TODO) - used new future version of pyo3_stub_gen to ensure Chrono::FixedTimeOffset can have a stub generated in `MetafitsContext`.
* Fixed pyo3 decorators to allow stub_gen to work properly / generate python stubs correctly.
* Used prerelease version of pyo3_stub_gen to ensure Chrono::FixedTimeOffset can have a stub generated in `MetafitsContext`.
*

## 1.7.1 23-Oct-2024

## 1.7.2 8-Nov-2024

* Update to fitsio 0.21.6 - provides FitsFile.file_path() method.
* Reverted MWAFitsFile to FitsFile as the subclass is no longer required.

## 1.7.1 23-Oct-2024 (Yanked- MWAFitsFile is no longer to be used)

* Release to fix issue generating Rust docs.

## 1.7.0 23-Oct-2024
## 1.7.0 23-Oct-2024 (Yanked- MWAFitsFile is no longer to be used)

* Bumped MSRV to 1.65.
* Update fitsio to 0.21 and fitsio-sys to 0.5.
* Update fitsio to 0.21 and fitsio-sys to 0.5. To make v0.21 work, a new struct, MWAFitsFile is used inplace of FitsFile, as FitsFile no longer carries the `filename` property which is needed by mwalib.
* Removed Rust Report Card from README status badges. Looks like this service is abandonded.
* Added Python .pyi stub generation to provide mwalib Python users with type and docstring information. The mwalib.pyi should get baked into the python wheels released to github and Pypi. See `bin/README.md` for caveats and more details.
* Added CI to test compilation against cfitsio 3.x and 4.x when not using the `cfitsio-static` feature.
Expand Down
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mwalib"
version = "1.7.2"
version = "1.7.3"
homepage = "https://github.com/MWATelescope/mwalib"
repository = "https://github.com/MWATelescope/mwalib"
readme = "README.md"
Expand Down Expand Up @@ -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"
Expand All @@ -54,7 +54,9 @@ env_logger = { version = "~0.10", optional = true }
ndarray = { version = "~0.16", optional = true }
numpy = { version = "~0.22", optional = true }
pyo3 = { version = "~0.22", features = ["chrono", "extension-module", "macros"], optional = true }
pyo3-stub-gen = { version = "~0.6", optional = true }
# pyo3-stub-gen = { version = "~0.6", optional = true }
# The below pyo3-stub-gen branch has not been merged with main as of 8-Nov-2024. once it has been it should be fine to go back to using the main branch again.
pyo3-stub-gen = { branch = "chrono_feature", optional = true, git = "https://github.com/ThatOneShortGuy/pyo3-stub-gen" }
pyo3-stub-gen-derive = { version = "~0.6", optional = true }

# "examples" feature.
Expand Down Expand Up @@ -95,4 +97,4 @@ required-features = ["examples"]

[[example]]
name = "mwalib-sum-first-fine-channel-gpubox-hdus"
required-features = ["examples"]
required-features = ["examples"]
20 changes: 3 additions & 17 deletions bin/stub_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,6 @@ fn fix_stubs() -> anyhow::Result<()> {
// After the stub is generated, we have some "manual" fixes to do
let stubfile = String::from("mwalib.pyi");

// Import datetime
insert_stub_below(&stubfile, "import typing\n", "import datetime\n")?;

// Add sched_start_utc (Chrono::DateTime<FixedOffset> is not supported yet)
insert_stub_below(
&stubfile,
" sched_end_unix_time_ms: int\n",
" sched_start_utc: datetime.datetime\n",
)?;

// Add sched_end_utc (Chrono::DateTime<FixedOffset> is not supported yet)
insert_stub_below(
&stubfile,
" sched_start_utc: datetime.datetime\n",
" sched_end_utc: datetime.datetime\n",
)?;

// Replace the constructors as pyo3_stub_gen seems to ignore the text_signature
replace_stub(&stubfile,"def __new__(cls,metafits_filename,mwa_version = ...): ...","def __new__(cls, metafits_filename: str, mwa_version: typing.Optional[MWAVersion]=None)->MetafitsContext:\n ...\n",)?;

Expand Down Expand Up @@ -87,6 +70,8 @@ fn fix_stubs() -> anyhow::Result<()> {
/// Inserts new items in the stubfile for when pyo3 cant do it
/// properly.
///
/// Currently this function is not used, but kept in case it is needed later!
///
/// This will:
/// * Open the created stubfile
/// * Find the line in `string_to_find` (fails if not found)
Expand All @@ -106,6 +91,7 @@ fn fix_stubs() -> anyhow::Result<()> {
/// * Result Ok if stub file was modified successfully.
///
///
#[allow(dead_code)]
#[cfg(feature = "python")]
fn insert_stub_below<P: AsRef<Path>>(
stubfile: P,
Expand Down
21 changes: 11 additions & 10 deletions src/coarse_channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -110,10 +111,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)
///
Expand All @@ -123,8 +124,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<usize>, u32), FitsError> {
// The coarse-channels string uses the FITS "CONTINUE" keywords. The
Expand All @@ -148,7 +149,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.
///
Expand All @@ -163,7 +164,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(
Expand Down Expand Up @@ -314,11 +315,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
///
Expand Down Expand Up @@ -346,7 +347,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.
///
Expand Down
13 changes: 7 additions & 6 deletions src/correlator_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

//! The main interface to MWA data.
use fitsio::FitsFile;
use std::collections::BTreeMap;
use std::fmt;
use std::path::Path;
Expand Down Expand Up @@ -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<u64, BTreeMap<usize, (usize, usize)>>,
/// 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<LegacyConversionBaseline>,
}

Expand All @@ -141,7 +142,7 @@ impl CorrelatorContext {
///
/// * Result containing a populated CorrelatorContext object if Ok.
///
///
///
pub fn new<P: AsRef<Path>, P2: AsRef<Path>>(
metafits_filename: P,
gpubox_filenames: &[P2],
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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},
Expand All @@ -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},
Expand Down
Loading

0 comments on commit 2188509

Please sign in to comment.