Skip to content

Commit

Permalink
saved battery maps in yaml files, updated set_default_xd_interp to us…
Browse files Browse the repository at this point in the history
…e from_resource
  • Loading branch information
robinsteuteville committed Nov 19, 2024
1 parent 994f4f6 commit 512601f
Show file tree
Hide file tree
Showing 9 changed files with 786 additions and 268 deletions.
29 changes: 29 additions & 0 deletions .subtrees/ninterp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ pub enum Interpolator {
}

impl Interpolator {
const ACCEPTED_BYTE_FORMATS: &'static [&'static str] = &[
// #[cfg(feature = "yaml")]
"yaml",
];
const ACCEPTED_STR_FORMATS: &'static [&'static str] = &[
// #[cfg(feature = "yaml")]
"yaml",
];
// #[cfg(feature = "resources")]
const RESOURCE_PREFIX: &'static str = "cycles";

/// Interpolate at supplied point, after checking point validity.
/// Length of supplied point must match interpolator dimensionality.
pub fn interpolate(&self, point: &[f64]) -> Result<f64, InterpolationError> {
Expand Down Expand Up @@ -535,6 +546,24 @@ impl Interpolator {
_ => Err(Error::NoSuchField),
}
}

// Read (deserialize) an object from a resource file packaged with the `fastsim-core` crate
//
// # Arguments:
//
// * `filepath` - Filepath, relative to the top of the `resources` folder (excluding any relevant prefix), from which to read the object
// #[cfg(feature = "resources")]
// fn from_resource<P: AsRef<Path>>(filepath: P, skip_init: bool) -> anyhow::Result<Self> {
// let filepath = Path::new(Self::RESOURCE_PREFIX).join(filepath);
// let extension = filepath
// .extension()
// .and_then(OsStr::to_str)
// .with_context(|| format!("File extension could not be parsed: {filepath:?}"))?;
// let file = crate::resources::RESOURCES_DIR
// .get_file(&filepath)
// .with_context(|| format!("File not found in resources: {filepath:?}"))?;
// Self::from_reader(&mut file.contents(), extension, skip_init)
// }
}

/// Interpolation strategy.
Expand Down
28 changes: 28 additions & 0 deletions fastsim-core/resources/interpolators/res/default_1d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
Interp1D:
x:
- -5.0
- -3.0
- -1.0
- -0.5
- -0.1
- 0.1
- 0.5
- 1.0
- 2.0
- 3.0
- 5.0
f_x:
- 0.892085814015878
- 0.935630351894604
- 0.978612548997097
- 0.989309767361546
- 0.997862182940346
- 0.997883658588665
- 0.989234853052088
- 0.977987897893482
- 0.953873809588552
- 0.927243266086586
- 0.864025853742296
strategy: Linear
extrapolate: Error
150 changes: 150 additions & 0 deletions fastsim-core/resources/interpolators/res/default_2d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
Interp2D:
x:
- -5.0
- -3.0
- -1.0
- -0.5
- -0.1
- 0.1
- 0.5
- 1.0
- 2.0
- 3.0
- 5.0
y:
- 0.0
- 0.1
- 0.2
- 0.3
- 0.4
- 0.5
- 0.6
- 0.7
- 0.8
- 0.9
- 1.0
f_xy:
- - 0.7607187
- 0.81966529
- 0.8611263
- 0.87869186
- 0.88613198
- 0.89208581
- 0.89683263
- 0.89357529
- 0.90125565
- 0.91020575
- 0.91979128
- - 0.85965783
- 0.89333392
- 0.91743447
- 0.9277388
- 0.93211889
- 0.93563035
- 0.93843387
- 0.93650968
- 0.94104921
- 0.94635013
- 0.95203966
- - 0.95383795
- 0.96473403
- 0.9726188
- 0.97600916
- 0.97745343
- 0.97861255
- 0.97953876
- 0.97890298
- 0.9804034
- 0.98215759
- 0.98404277
- - 0.97695222
- 0.9823822
- 0.98631663
- 0.98800948
- 0.9887308
- 0.98930977
- 0.98977244
- 0.98945485
- 0.9902044
- 0.99108084
- 0.99202285
- - 0.99539269
- 0.99647745
- 0.9972638
- 0.99760222
- 0.99774643
- 0.99786218
- 0.99795469
- 0.99789119
- 0.99804106
- 0.9982163
- 0.99840467
- - 0.99619981
- 0.99686932
- 0.99736582
- 0.99764729
- 0.9977849
- 0.99788366
- 0.99797273
- 0.99800143
- 0.99818886
- 0.99830355
- 0.99835808
- - 0.98039606
- 0.98394049
- 0.98654322
- 0.98800913
- 0.98872331
- 0.98923485
- 0.98969547
- 0.98984376
- 0.99081042
- 0.99140046
- 0.99168058
- - 0.95914034
- 0.96678736
- 0.97232604
- 0.97541778
- 0.97691694
- 0.9779879
- 0.97895023
- 0.97925963
- 0.98127177
- 0.9824959
- 0.98307598
- - 0.91045761
- 0.92856982
- 0.94125462
- 0.94818756
- 0.95151271
- 0.95387381
- 0.95598541
- 0.95666232
- 0.96104109
- 0.96368544
- 0.96493344
- - 0.85049607
- 0.88369073
- 0.90589834
- 0.91771248
- 0.92330271
- 0.92724327
- 0.93074753
- 0.93186694
- 0.9390631
- 0.94337174
- 0.94539568
- - 0.66282253
- 0.76132337
- 0.81648094
- 0.84336438
- 0.85558664
- 0.86402585
- 0.87141433
- 0.8737522
- 0.88853401
- 0.89718896
- 0.90120638
strategy: Linear
extrapolate: Error
Loading

0 comments on commit 512601f

Please sign in to comment.