ubc-solar-physics 1.5.0__cp311-cp311-win_amd64.whl → 1.6.0__cp311-cp311-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
core.cp311-win_amd64.pyd CHANGED
Binary file
physics/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '1.5.0'
16
- __version_tuple__ = version_tuple = (1, 5, 0)
15
+ __version__ = version = '1.6.0'
16
+ __version_tuple__ = version_tuple = (1, 6, 0)
@@ -1,5 +1,6 @@
1
1
  from abc import ABC, abstractmethod
2
2
  import numpy as np
3
+ from numpy.typing import ArrayLike, NDArray
3
4
 
4
5
 
5
6
  class BaseGIS(ABC):
@@ -22,3 +23,16 @@ class BaseGIS(ABC):
22
23
  @abstractmethod
23
24
  def get_path(self) -> np.ndarray:
24
25
  raise NotImplementedError
26
+
27
+ @abstractmethod
28
+ def calculate_current_heading_array(self) -> np.ndarray:
29
+ raise NotImplementedError
30
+
31
+ def calculate_driving_speeds(
32
+ self,
33
+ average_lap_speeds: ArrayLike,
34
+ simulation_dt: int,
35
+ driving_allowed: ArrayLike,
36
+ idle_time: int
37
+ ) -> NDArray[float]:
38
+ raise NotImplementedError
@@ -4,6 +4,7 @@ import core
4
4
  import numpy as np
5
5
  import sys
6
6
 
7
+ from numpy.typing import ArrayLike, NDArray
7
8
  from tqdm import tqdm
8
9
  from xml.dom import minidom
9
10
  from haversine import haversine, Unit
@@ -82,6 +83,39 @@ class GIS(BaseGIS):
82
83
  """
83
84
  return core.closest_gis_indices_loop(distances, self.path_distances)
84
85
 
86
+ def calculate_driving_speeds(
87
+ self,
88
+ average_lap_speeds: ArrayLike,
89
+ simulation_dt: int,
90
+ driving_allowed: ArrayLike,
91
+ idle_time: int
92
+ ) -> NDArray[float]:
93
+ """
94
+ Generate valid driving speeds as a simulation-time array given a set of average speeds for each
95
+ simulated lap.
96
+ Driving speeds will only be non-zero when we are allowed to drive, and the speed
97
+ for every tick during a lap will be that lap's corresponding desired average speed for as long
98
+ as it takes to complete the lap.
99
+
100
+ :param average_lap_speeds: An array of average speeds in m/s, one for each simulated lap.
101
+ If there are more speeds given than laps available, the unused speeds will be silently ignored.
102
+ If there are too few, an error will be returned.
103
+ :param simulation_dt: The simulated tick length.
104
+ :param driving_allowed: A simulation-time boolean where the `True` elements are when we
105
+ are allowed to drive, and `False` is when we are not. Requires that (at least) the first element is
106
+ `False` due to the race beginning in the morning before we are allowed to drive.
107
+ :param idle_time: The length of time to pause driving upon processing a "0m/s" average speed.
108
+ :return: A simulation-time array of driving speeds in m/s, or an error if there weren't enough
109
+ laps provided to fill the entire simulation time.
110
+ """
111
+ return core.get_driving_speeds(
112
+ np.array(average_lap_speeds).astype(np.float64),
113
+ simulation_dt,
114
+ np.array(driving_allowed).astype(bool),
115
+ self.path_length,
116
+ idle_time
117
+ )
118
+
85
119
  @staticmethod
86
120
  def _python_calculate_closest_gis_indices(distances, path_distances):
87
121
  """
@@ -1,5 +1,4 @@
1
- use chrono::{Datelike, NaiveDateTime, Timelike};
2
- use numpy::ndarray::{s, Array, Array2, ArrayViewD, ArrayViewMut2, ArrayViewMut3, Axis};
1
+ use numpy::ndarray::{ArrayViewD, ArrayView1};
3
2
 
4
3
  pub fn rust_closest_gis_indices_loop(
5
4
  distances: ArrayViewD<'_, f64>,
@@ -15,6 +14,9 @@ pub fn rust_closest_gis_indices_loop(
15
14
  while distance_travelled > path_distances[current_coord_index] {
16
15
  distance_travelled -= path_distances[current_coord_index];
17
16
  current_coord_index += 1;
17
+ if current_coord_index >= path_distances.len() {
18
+ current_coord_index = 0;
19
+ }
18
20
  }
19
21
 
20
22
  current_coord_index = std::cmp::min(current_coord_index, path_distances.len() - 1);
@@ -22,4 +24,90 @@ pub fn rust_closest_gis_indices_loop(
22
24
  }
23
25
 
24
26
  result
25
- }
27
+ }
28
+
29
+ ///
30
+ /// Generate valid driving speeds as a simulation-time array given a set of average speeds for each
31
+ /// simulated lap.
32
+ /// Driving speeds will only be non-zero when we are allowed to drive, and the speed
33
+ /// for every tick during a lap will be that lap's corresponding desired average speed for as long
34
+ /// as it takes to complete the lap.
35
+ /// An average speed of 0m/s for a lap will be interpreted as "sit and charge" for `idle_time`
36
+ /// ticks.
37
+ ///
38
+ /// # Arguments
39
+ ///
40
+ /// * `average_speeds`: An array of average speeds in m/s, one for each simulated lap. If there are more
41
+ /// speeds given than laps available, the unused speeds will be silently ignored. If there are too
42
+ /// few, an error will be returned.
43
+ /// * `simulation_dt`: The simulated tick length
44
+ /// * `driving_allowed_boolean`: A simulation-time boolean where the `True` elements are when we
45
+ /// are allowed to drive, and `False` is when we are not.
46
+ /// * `track_length`: The length of the track in meters.
47
+ /// * `idle_time`: The number of ticks to "sit and charge" when desired.
48
+ ///
49
+ /// Returns: A simulation-time array of driving speeds in m/s, or an error if there weren't enough
50
+ /// laps provided to fill the entire simulation time.
51
+ ///
52
+ pub fn get_driving_speeds(
53
+ average_speeds: ArrayView1<'_, f64>, // Average speeds in m/s
54
+ simulation_dt: i64, // Time step in seconds
55
+ driving_allowed_boolean: ArrayView1<'_, bool>, // Simulation-time boolean array
56
+ track_length: f64, // Track length in meters
57
+ idle_time: i64 // Time to idle in seconds
58
+ ) -> Result<Vec<f64>, &'static str> {
59
+ let ticks_to_complete_lap: Vec<i64> = average_speeds.iter().map(| &average_speed | {
60
+ if average_speed > 0.0 {
61
+ // The number of ticks is the number of seconds, divided by seconds per tick
62
+ (track_length / average_speed / simulation_dt as f64).ceil() as i64
63
+ } else {
64
+ (idle_time as f64 / simulation_dt as f64).ceil() as i64
65
+ }
66
+ }).collect();
67
+
68
+ let mut lap_index: usize = 0;
69
+ let mut lap_speed: f64 = average_speeds[lap_index];
70
+
71
+ let mut ticks_to_lap_completion: i64 = ticks_to_complete_lap[lap_index];
72
+
73
+ let mut driving_speeds: Vec<f64> = Vec::with_capacity(driving_allowed_boolean.len());
74
+ for driving_allowed in driving_allowed_boolean.iter() {
75
+ if !driving_allowed {
76
+ // If we aren't allowed to drive, speed should be zero. Also, we should mark that we are
77
+ // done our lap since it means we ended the day in the middle of the lap, and we will
78
+ // start the next day at the beginning of a new lap, not where we ended off.
79
+
80
+ // If it's the first lap, we don't want to skip because we are probably in the morning
81
+ // where we haven't begun driving yet.
82
+ if lap_index > 0 {
83
+ ticks_to_lap_completion = 0;
84
+ }
85
+
86
+ driving_speeds.push(0.0)
87
+ } else {
88
+ // If we are driving, we should decrement ticks to lap completion. If its already
89
+ // zero, that means that we are done the lap and should move onto the next lap.
90
+ if ticks_to_lap_completion > 0 {
91
+ ticks_to_lap_completion -= 1;
92
+
93
+ driving_speeds.push(lap_speed)
94
+ } else {
95
+ // To advance to the next lap, increment the index and evaluate new variables
96
+ lap_index += 1;
97
+ if lap_index >= average_speeds.len() {
98
+ return Err("Not enough average speeds!")
99
+ }
100
+
101
+ // We subtract 1 since this iteration counts for the next lap, not the one
102
+ // that we just finished
103
+ ticks_to_lap_completion = ticks_to_complete_lap[lap_index] - 1;
104
+ lap_speed = average_speeds[lap_index];
105
+
106
+ driving_speeds.push(lap_speed)
107
+ }
108
+ }
109
+
110
+ }
111
+
112
+ Ok(driving_speeds)
113
+ }
physics/lib.rs CHANGED
@@ -1,13 +1,12 @@
1
- use chrono::{Datelike, NaiveDateTime, Timelike};
2
- use numpy::ndarray::{s, Array, Array2, ArrayViewD, ArrayViewMut2, ArrayViewMut3, Axis};
3
- use numpy::{PyArray, PyArrayDyn, PyReadwriteArrayDyn};
1
+ use numpy::ndarray::ArrayViewD;
2
+ use numpy::{PyArray, PyArrayDyn, PyReadwriteArrayDyn, PyReadonlyArray1, PyArray1};
4
3
  use pyo3::prelude::*;
5
4
  use pyo3::types::PyModule;
6
5
 
7
6
  pub mod environment;
8
7
  pub mod models;
9
- use crate::environment::gis::gis::rust_closest_gis_indices_loop;
10
- use crate::environment::meteorology::meteorology::{rust_calculate_array_ghi_times, rust_closest_weather_indices_loop, rust_weather_in_time, rust_closest_timestamp_indices};
8
+ use crate::environment::gis::gis::{rust_closest_gis_indices_loop, get_driving_speeds};
9
+ use crate::environment::meteorology::meteorology::{rust_calculate_array_ghi_times, rust_closest_weather_indices_loop, rust_weather_in_time};
11
10
  use crate::models::battery::battery::update_battery_array;
12
11
 
13
12
  fn constrain_speeds(speed_limits: ArrayViewD<f64>, speeds: ArrayViewD<f64>, tick: i32) -> Vec<f64> {
@@ -128,5 +127,30 @@ fn rust_simulation(_py: Python, m: &PyModule) -> PyResult<()> {
128
127
  (py_soc_array, py_voltage_array)
129
128
  }
130
129
 
130
+ #[pyfn(m)]
131
+ #[pyo3(name = "get_driving_speeds")]
132
+ fn py_get_driving_speeds<'py>(
133
+ py: Python<'py>,
134
+ py_average_speeds: PyReadonlyArray1<'py, f64>, // Average speeds in m/s
135
+ simulation_dt: i64, // Time step in seconds
136
+ py_driving_allowed_boolean: PyReadonlyArray1<'py, bool>, // Simulation-time boolean array
137
+ track_length: f64, // Track length in meters
138
+ idle_time: i64 // Time to idle in seconds
139
+ ) -> PyResult<&'py PyArray1<f64>> {
140
+ let average_speeds = py_average_speeds.as_array();
141
+ let driving_allowed_boolean = py_driving_allowed_boolean.as_array();
142
+
143
+ match get_driving_speeds(
144
+ average_speeds,
145
+ simulation_dt,
146
+ driving_allowed_boolean,
147
+ track_length,
148
+ idle_time
149
+ ) {
150
+ Ok(driving_speeds) => Ok(PyArray1::from_vec(py, driving_speeds)),
151
+ Err(error) => Err(pyo3::exceptions::PyValueError::new_err(error))
152
+ }
153
+ }
154
+
131
155
  Ok(())
132
156
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ubc-solar-physics
3
- Version: 1.5.0
3
+ Version: 1.6.0
4
4
  Summary: UBC Solar's Simulation Environment
5
5
  Author: Fisher Xue, Mihir Nimgade, Chris Chang, David Widjaja, Justin Hua, Ilya Veksler, Renu Rajamagesh, Ritchie Xia, Erik Langille, Chris Aung, Nicolas Ric, Ishaan Trivedi, Jason Liang, Felix Toft, Mack Wilson, Jonah Lee, Tamzeed Quazi, Joshua Riefman
6
6
  Author-email: UBC Solar <strategy@ubcsolar.com>
@@ -1,17 +1,17 @@
1
- core.cp311-win_amd64.pyd,sha256=FnVBsOnqKzl90K7wbcdVZqPSkhnSGQxrVm58C7IQ-Dk,382464
1
+ core.cp311-win_amd64.pyd,sha256=uAhz0HtEfHY2pngCPFbtBuNW3EW7ncy0vAW9kXecpc8,397824
2
2
  physics/__init__.py,sha256=jRV9J_eGh0vNXEfFrILqcM6xxVjyqm3XwKAg1B1IPBs,183
3
- physics/_version.py,sha256=4UjV9E97jx3v745ItJ8V4wu9qMyJBqbQIVY74coBkfw,427
3
+ physics/_version.py,sha256=4v6IH9V8ge15MBWToUV3gq5GsQbmUjMF_FNOfe2nmxs,427
4
4
  physics/environment.rs,sha256=OghmBkvHLZvzzuVsXUmV2lR3X_tEwuB9sT2TGZLQC6E,36
5
- physics/lib.rs,sha256=FqnhKkotYKJCu8v1vbov2QW9s0apay7-BnEcUgxOakU,5798
5
+ physics/lib.rs,sha256=ruA2J3n1vmYZPpKqwDm59gqdNVmElYJV1fjc1fvePyA,6852
6
6
  physics/models.rs,sha256=747ABP-D1XKxA6X_MNh1PbmST0zsxpxhP_pEWjbR46c,63
7
7
  physics/environment/__init__.py,sha256=se_LVo4aWZKcZgbbK1KwwhHG8SH2zS1g6TEPw0GOZSs,225
8
8
  physics/environment/environment.rs,sha256=-VztdV2_GSlRbyIV_Pt6gKPVxpuNXpjLgAmoervonLg,34
9
9
  physics/environment/gis.rs,sha256=9R7G0cjf5PxQAz-CSryA6-KGfrh1eSwRhJ6qF8KfjDE,12
10
10
  physics/environment/meteorology.rs,sha256=naWb7qYrtMkCE_tLAkM474fmxaufhCkyhy3TTUQ4Yw4,20
11
11
  physics/environment/gis/__init__.py,sha256=SjqhVjuDbZln636zOFROq1tWPfadghkuYz8aheflyxA,96
12
- physics/environment/gis/base_gis.py,sha256=WJMwpuxjmHuV-dS5HwWvLxARNd7JRQyd3IBptuxNAI0,656
13
- physics/environment/gis/gis.py,sha256=I04ABXsNOmeikCajBtl9a5oW6NzMBPc8nG53oiIicqw,11737
14
- physics/environment/gis/gis.rs,sha256=jMkVmlUNl5cz7GF1QVkMNoRb58YUOe4D95EdhBJ4anM,876
12
+ physics/environment/gis/base_gis.py,sha256=BsrF-r67XMwhjeKqB3zuNOmiC4jFV7HXfpZ_g6ZPASE,1084
13
+ physics/environment/gis/gis.py,sha256=_EtlfuHp_V8pWC0yc-pE_Ym6HtNHVINUvUP76gDYI9Y,13554
14
+ physics/environment/gis/gis.rs,sha256=nyCekzEJCJTpm4Zy6shIm0AEoGsk6TljP-j7KlLn-38,4978
15
15
  physics/environment/meteorology/__init__.py,sha256=mvjJw_0nNLIdh80F_yTaRC3Sw3oI-z1L0J5cOK_ei0k,157
16
16
  physics/environment/meteorology/base_meteorology.py,sha256=n0JsEXQLuciEatQp_S0QBXd_HQzCY5LeIQeVKgl5O-8,2487
17
17
  physics/environment/meteorology/clouded_meteorology.py,sha256=H4jqQmaf1UiARQ4T5HmWE0ChS6IJhlvumj0lfoe52cw,28241
@@ -49,8 +49,8 @@ physics/models/regen/__init__.py,sha256=JzyRYKwT89FQ6_p9ofCqusl2fnWGHulyiK4P4f8L
49
49
  physics/models/regen/base_regen.py,sha256=lY44jrTSHEo8Xv7hKCjo4C3Jx0PUgilyITHwQchT2bM,101
50
50
  physics/models/regen/basic_regen.py,sha256=SZl7nj75w-3uczfNfaZAMtcC4WO8M2mTmwbnB0HmrtU,2402
51
51
  physics/models/regen/regen.rs,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
52
- ubc_solar_physics-1.5.0.dist-info/LICENSE,sha256=1Vq7OikLHh7N0xsmTPHCmPkOxk1AXrMK9k1a1icQFlk,1087
53
- ubc_solar_physics-1.5.0.dist-info/METADATA,sha256=lPvzskWg_fHcp1HetEGYGkYjs8bTaszVfAi1OMl7XYU,5120
54
- ubc_solar_physics-1.5.0.dist-info/WHEEL,sha256=JWgQ-TWZ1n0Iuc5jEQ2YgnMdnD-gLKG4Nf9GekqFXYw,101
55
- ubc_solar_physics-1.5.0.dist-info/top_level.txt,sha256=aws060Zz-1h0Kx76JzcE1gLA_AfS1lrRtTCsyUYwDvM,8
56
- ubc_solar_physics-1.5.0.dist-info/RECORD,,
52
+ ubc_solar_physics-1.6.0.dist-info/LICENSE,sha256=1Vq7OikLHh7N0xsmTPHCmPkOxk1AXrMK9k1a1icQFlk,1087
53
+ ubc_solar_physics-1.6.0.dist-info/METADATA,sha256=l1kc_uYhJntYhiRgBdty2uNeaNBqW081lk0rckZ3iho,5120
54
+ ubc_solar_physics-1.6.0.dist-info/WHEEL,sha256=JWgQ-TWZ1n0Iuc5jEQ2YgnMdnD-gLKG4Nf9GekqFXYw,101
55
+ ubc_solar_physics-1.6.0.dist-info/top_level.txt,sha256=aws060Zz-1h0Kx76JzcE1gLA_AfS1lrRtTCsyUYwDvM,8
56
+ ubc_solar_physics-1.6.0.dist-info/RECORD,,