Skip to content

Commit

Permalink
Merge pull request #243 from nyx-space/176-modify-and-truncate-daf-files
Browse files Browse the repository at this point in the history
Modify and truncate DAF files
  • Loading branch information
ChristopherRabotin committed May 22, 2024
2 parents 81d534a + 4b07d7b commit 47c4f21
Show file tree
Hide file tree
Showing 105 changed files with 839 additions and 248 deletions.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ assignees: ''
---

# Bug report
_Bug reports will lead to a stakeholder need report, and will need to be linked to this issue_

## Describe the bug
A clear and concise description of what the bug is.
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ jobs:
wget -O data/pck08.pca http://public-data.nyxspace.com/anise/v0.3/pck08.pca
wget -O data/pck11.pca http://public-data.nyxspace.com/anise/v0.3/pck11.pca
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Build wheels
uses: PyO3/maturin-action@v1
continue-on-error: ${{ matrix.target == 's390x' }}
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
Expand Down Expand Up @@ -117,7 +118,7 @@ jobs:
with:
lfs: true

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
architecture: ${{ matrix.target }}
Expand Down Expand Up @@ -156,7 +157,7 @@ jobs:
with:
lfs: true

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
RUST_BACKTRACE=1 cargo test de440s_translation_verif_venus2emb --release --workspace --exclude anise-gui --exclude anise-py -- --nocapture --include-ignored --test-threads 1
# Now analyze the results and create pretty plots
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["anise", "anise-cli", "anise-gui", "anise-py"]

[workspace.package]
version = "0.3.2-alpha"
version = "0.3.2"
edition = "2021"
authors = ["Christopher Rabotin <[email protected]>"]
description = "ANISE provides a toolkit and files for Attitude, Navigation, Instrument, Spacecraft, and Ephemeris data. It's a modern replacement of NAIF SPICE file."
Expand Down Expand Up @@ -50,7 +50,7 @@ serde = "1"
serde_derive = "1"
serde_dhall = "0.12"

anise = { version = "0.3.2-alpha", path = "anise", default-features = false }
anise = { version = "0.3.2", path = "anise", default-features = false }

[profile.bench]
debug = true
Expand Down
26 changes: 26 additions & 0 deletions anise-cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use clap::{Parser, Subcommand};
use hifitime::Epoch;

#[derive(Parser, Debug)]
#[clap(name="ANISE", author="Rabotin and ANISE contributors", version, about, long_about = None)]
Expand Down Expand Up @@ -39,4 +40,29 @@ pub enum Actions {
/// Output ANISE binary file
outfile: PathBuf,
},
/// Truncate the segment of the provided ID of the input NAIF DAF file to the provided start and end epochs
/// Limitation: this may not work correctly if there are several segments with the same ID.
/// Only works with Chebyshev Type 2 data types (i.e. planetary ephemerides).
TruncDAFById {
/// Input DAF file, SPK or BPC
input: PathBuf,
/// Output DAF file path
output: PathBuf,
/// ID of the segment to truncate
id: i32,
/// New start epoch of the segment
start: Option<Epoch>,
/// New end epoch of the segment
end: Option<Epoch>,
},
/// Remove the segment of the provided ID of the input NAIF DAF file.
/// Limitation: this may not work correctly if there are several segments with the same ID.
RmDAFById {
/// Input DAF file, SPK or BPC
input: PathBuf,
/// Output DAF file path
output: PathBuf,
/// ID of the segment to truncate
id: i32,
},
}
175 changes: 175 additions & 0 deletions anise-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
extern crate pretty_env_logger;
use std::collections::HashSet;
use std::env::{set_var, var};
use std::io;

use anise::naif::daf::datatypes::Type2ChebyshevSet;
use anise::naif::daf::{DafDataType, NAIFDataSet};
use clap::Parser;
use log::info;
use snafu::prelude::*;
Expand Down Expand Up @@ -176,5 +179,177 @@ fn main() -> Result<(), CliErrors> {

Ok(())
}
Actions::TruncDAFById {
input,
output,
id,
start,
end,
} => {
ensure!(
start.is_some() || end.is_some(),
ArgumentSnafu {
arg: "you must provide either START or END, or both"
}
);

let path_str = input.clone();
let bytes = file2heap!(input).with_context(|_| AniseSnafu)?;
// Load the header only
let file_record = FileRecord::read_from(&bytes[..FileRecord::SIZE]).unwrap();

match file_record
.identification()
.with_context(|_| CliFileRecordSnafu)?
{
"PCK" => {
info!("Loading {path_str:?} as DAF/PCK");
let pck = BPC::parse(bytes).with_context(|_| CliDAFSnafu)?;

let mut ids = HashSet::new();
for summary in pck.data_summaries().with_context(|_| CliDAFSnafu)? {
ids.insert(summary.id());
}

info!("IDs present in file: {ids:?}");

let (summary, idx) = pck.summary_from_id(id).with_context(|_| CliDAFSnafu)?;

let data_type =
DafDataType::try_from(summary.data_type_i).with_context(|_| CliDAFSnafu)?;
ensure!(
data_type == DafDataType::Type2ChebyshevTriplet,
ArgumentSnafu {
arg: format!("{path_str:?} is of type {data_type:?}, but operation is only valid for Type2ChebyshevTriplet")
}
);

let segment = pck.nth_data::<Type2ChebyshevSet>(idx).unwrap();

let updated_segment = segment.truncate(summary, start, end).unwrap();

let mut my_pck_mut = pck.to_mutable();
assert!(my_pck_mut
.set_nth_data(
0,
updated_segment,
start.or_else(|| Some(summary.start_epoch())).unwrap(),
end.or_else(|| Some(summary.end_epoch())).unwrap(),
)
.is_ok());

info!("Saving file to {output:?}");
my_pck_mut.persist(output).unwrap();

Ok(())
}
"SPK" => {
info!("Loading {path_str:?} as DAF/PCK");
let spk = SPK::parse(bytes).with_context(|_| CliDAFSnafu)?;

let mut ids = HashSet::new();
for summary in spk.data_summaries().with_context(|_| CliDAFSnafu)? {
ids.insert(summary.id());
}

info!("IDs present in file: {ids:?}");

let (summary, idx) = spk.summary_from_id(id).with_context(|_| CliDAFSnafu)?;
info!("Modifying {summary}");

let data_type =
DafDataType::try_from(summary.data_type_i).with_context(|_| CliDAFSnafu)?;
ensure!(
data_type == DafDataType::Type2ChebyshevTriplet,
ArgumentSnafu {
arg: format!("{path_str:?} is of type {data_type:?}, but operation is only valid for Type2ChebyshevTriplet")
}
);

let segment = spk.nth_data::<Type2ChebyshevSet>(idx).unwrap();

let updated_segment = segment.truncate(summary, start, end).unwrap();

let mut my_spk_mut = spk.to_mutable();
assert!(my_spk_mut
.set_nth_data(
idx,
updated_segment,
start.or_else(|| Some(summary.start_epoch())).unwrap(),
end.or_else(|| Some(summary.end_epoch())).unwrap(),
)
.is_ok());

info!("Saving file to {output:?}");
my_spk_mut.persist(output).unwrap();

Ok(())
}
fileid => Err(CliErrors::ArgumentError {
arg: format!("{fileid} is not supported yet"),
}),
}
}
Actions::RmDAFById { input, output, id } => {
let path_str = input.clone();
let bytes = file2heap!(input).with_context(|_| AniseSnafu)?;
// Load the header only
let file_record = FileRecord::read_from(&bytes[..FileRecord::SIZE]).unwrap();

match file_record
.identification()
.with_context(|_| CliFileRecordSnafu)?
{
"PCK" => {
info!("Loading {path_str:?} as DAF/PCK");
let pck = BPC::parse(bytes).with_context(|_| CliDAFSnafu)?;

let mut ids = HashSet::new();
for summary in pck.data_summaries().with_context(|_| CliDAFSnafu)? {
ids.insert(summary.id());
}

info!("IDs present in file: {ids:?}");

let (_, idx) = pck.summary_from_id(id).with_context(|_| CliDAFSnafu)?;

let mut my_pck_mut = pck.to_mutable();
my_pck_mut
.delete_nth_data(idx)
.with_context(|_| CliDAFSnafu)?;

info!("Saving file to {output:?}");
my_pck_mut.persist(output).unwrap();

Ok(())
}
"SPK" => {
info!("Loading {path_str:?} as DAF/PCK");
let spk = SPK::parse(bytes).with_context(|_| CliDAFSnafu)?;

let mut ids = HashSet::new();
for summary in spk.data_summaries().with_context(|_| CliDAFSnafu)? {
ids.insert(summary.id());
}

info!("IDs present in file: {ids:?}");

let (_, idx) = spk.summary_from_id(id).with_context(|_| CliDAFSnafu)?;

let mut my_spk_mut = spk.to_mutable();
my_spk_mut
.delete_nth_data(idx)
.with_context(|_| CliDAFSnafu)?;

info!("Saving file to {output:?}");
my_spk_mut.persist(output).unwrap();

Ok(())
}
fileid => Err(CliErrors::ArgumentError {
arg: format!("{fileid} is not supported yet"),
}),
}
}
}
}
2 changes: 1 addition & 1 deletion anise-py/src/astro.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
2 changes: 1 addition & 1 deletion anise-py/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
2 changes: 1 addition & 1 deletion anise-py/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
2 changes: 1 addition & 1 deletion anise-py/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/aer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/bpc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/metaload/metaalmanac.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/metaload/metafile.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/metaload/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/planetary.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/python.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
2 changes: 1 addition & 1 deletion anise/src/almanac/solar.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ANISE Toolkit
* Copyright (C) 2021-2023 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2021-onward Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* 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 https://mozilla.org/MPL/2.0/.
Expand Down
Loading

0 comments on commit 47c4f21

Please sign in to comment.