Skip to content

Commit 627262a

Browse files
Merge pull request #407 from nyx-space/bug/gh-339
Unit test showing convert_tpc not working with gm_de440.tpc
2 parents 8b5f9fc + 15a9d1c commit 627262a

File tree

15 files changed

+352
-30
lines changed

15 files changed

+352
-30
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolver = "2"
33
members = ["anise", "anise-cli", "anise-gui", "anise-py", "anise/fuzz"]
44

55
[workspace.package]
6-
version = "0.5.3"
6+
version = "0.5.4"
77
edition = "2021"
88
authors = ["Christopher Rabotin <christopher.rabotin@gmail.com>"]
99
description = "ANISE provides a toolkit and files for Attitude, Navigation, Instrument, Spacecraft, and Ephemeris data. It's a modern replacement of NAIF SPICE file."
@@ -45,7 +45,7 @@ pyo3-log = "0.12"
4545
numpy = "0.23"
4646
ndarray = ">= 0.15, < 0.17"
4747

48-
anise = { version = "0.5.3", path = "anise", default-features = false }
48+
anise = { version = "0.5.4", path = "anise", default-features = false }
4949

5050
[profile.bench]
5151
debug = true

anise-py/tests/test_almanac.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import os
12
from pathlib import Path
23
import pickle
34

4-
from anise import Almanac, MetaAlmanac
5+
from anise import Almanac, MetaAlmanac, MetaFile
56
from anise.astro import *
67
from anise.astro.constants import Frames
78
from anise.rotation import DCM
89
from anise.time import Epoch
10+
from anise.utils import convert_tpc
911

1012
from os import environ
1113

@@ -126,6 +128,29 @@ def test_state_transformation():
126128
# cf. https://github.com/nyx-space/hifitime/issues/270
127129

128130

131+
def test_convert_tpc():
132+
"""Attempt to reproduce GH issue #339"""
133+
try:
134+
os.remove("test_constants.tpc")
135+
except FileNotFoundError:
136+
pass
137+
138+
# First call to convert_tpc works
139+
convert_tpc("data/pck00011.tpc", "data/gm_de440.tpc", "test_constants.tpc")
140+
141+
# Second call, with overwrite enabled, also works
142+
convert_tpc("data/pck00011.tpc", "data/gm_de440.tpc", "test_constants.tpc", overwrite=True)
143+
144+
# Try to load the constants file
145+
constants_file = MetaFile("test_constants.tpc")
146+
new_meta = MetaAlmanac()
147+
new_meta.files = [constants_file,]
148+
almanac = new_meta.process()
149+
150+
earth_j2k = almanac.frame_info(Frames.EARTH_J2000)
151+
assert earth_j2k.mu_km3_s2 != None
152+
almanac.describe()
153+
129154
def test_meta_load():
130155
data_path = Path(__file__).parent.joinpath("..", "..", "data", "local.dhall")
131156
meta = MetaAlmanac(str(data_path))

anise/src/almanac/metaload/metafile.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ impl MetaFile {
7474
return Ok(());
7575
}
7676
// Build the path for this file.
77-
match url.path_segments().and_then(|segments| segments.last()) {
77+
match url
78+
.path_segments()
79+
.and_then(|mut segments| segments.next_back())
80+
{
7881
Some(remote_file_path) => {
7982
match Path::new(remote_file_path).file_name() {
8083
Some(file_name) => {

anise/src/almanac/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use core::fmt;
3232
pub const MAX_LOADED_SPKS: usize = 32;
3333
pub const MAX_LOADED_BPCS: usize = 8;
3434
pub const MAX_SPACECRAFT_DATA: usize = 16;
35-
pub const MAX_PLANETARY_DATA: usize = 64;
35+
pub const MAX_PLANETARY_DATA: usize = 128;
3636

3737
pub mod aer;
3838
pub mod bpc;

anise/src/math/interpolation/hermite.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ pub fn hermite_eval(
172172
/* physical XVALS array, in which the abscissa values are not */
173173
/* repeated. */
174174

175-
let xi = (i + 1) / 2;
176-
let xij = (i + j + 1) / 2;
175+
let xi = i.div_ceil(2);
176+
let xij = (i + j).div_ceil(2);
177177
let c1 = xs[xij - 1] - x_eval;
178178
let c2 = x_eval - xs[xi - 1];
179179
let denom = xs[xij - 1] - xs[xi - 1];

anise/src/naif/daf/file_record.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl FileRecord {
9292
}
9393

9494
pub fn summary_size(&self) -> usize {
95-
(self.nd + (self.ni + 1) / 2) as usize
95+
(self.nd + self.ni.div_ceil(2)) as usize
9696
}
9797

9898
pub fn identification(&self) -> Result<&str, FileRecordError> {

anise/src/naif/kpl/parser.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl Assignment {
7070
// We have exactly one item, let's try to convert it as an integer first
7171
if let Ok(as_int) = vec[0].parse::<i32>() {
7272
KPLValue::Integer(as_int)
73-
} else if let Ok(as_f64) = vec[0].parse::<f64>() {
73+
} else if let Ok(as_f64) = vec[0].trim().replace("D", "E").parse::<f64>() {
7474
KPLValue::Float(as_f64)
7575
} else {
7676
// Darn, let's default to string
@@ -191,7 +191,13 @@ pub fn convert_tpc_items(
191191
}),
192192
_ => unreachable!(),
193193
},
194-
_ => panic!("radii_km should be float or matrix, got {radii_km:?}"),
194+
_ => {
195+
return Err(DataSetError::Conversion {
196+
action: format!(
197+
"radii_km should be float or matrix, got {radii_km:?}"
198+
),
199+
})
200+
}
195201
},
196202
None => None,
197203
};
@@ -303,17 +309,17 @@ pub fn convert_tpc_items(
303309
info!("Added {object_id}");
304310
}
305311
_ => error!(
306-
"expected gravity parameter to be a float but got {mu_km3_s2_value:?}"
312+
"skipping {object_id}: gravity data is {mu_km3_s2_value:?} (want float)"
307313
),
308314
}
309315
}
310316
None => {
311-
warn!("Skipping {object_id}: no gravity data")
317+
warn!("skipping {object_id}: no gravity data")
312318
}
313319
}
314320
}
315321

316-
println!("Added {} items", dataset.lut.by_id.len());
322+
info!("added {} items", dataset.lut.by_id.len());
317323

318324
dataset.set_crc32();
319325
dataset.metadata = Metadata::default();

anise/src/structure/dataset/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub enum DataSetError {
2424
action: &'static str,
2525
source: DecodingError,
2626
},
27-
#[snafu(display("input/output error while {action}"))]
27+
#[snafu(display("input/output error while {action}, {source}"))]
2828
IO {
2929
action: &'static str,
3030
source: IOError,

data/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
!pck08.pca
22
!pck11.pca
33
!moon_fk.epa
4-
!moon_fk_de440.epa
4+
!moon_fk_de440.epa
5+
de*.bsp

data/de421.bsp

Lines changed: 0 additions & 3 deletions
This file was deleted.

data/de430.bsp

Lines changed: 0 additions & 3 deletions
This file was deleted.

data/de440.bsp

Lines changed: 0 additions & 3 deletions
This file was deleted.

data/de440_type3.bsp

Lines changed: 0 additions & 3 deletions
This file was deleted.

data/de440s.bsp

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)