Skip to content

Commit 45f10f7

Browse files
author
MariusWiggert
committed
Integrated 1D time-interpolation into the hj_reachability_planner.py
1 parent b218cbf commit 45f10f7

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

ocean_navigation_simulator/planners/hj_reachability_planners/hj_reachability_planner.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,21 @@ def extract_trajectory(self, x_start, traj_rel_times_vector=None):
202202
def update_current_data(self, x_t):
203203
print("Reachability Planner: Loading new current data.")
204204

205+
# get the t, lat, lon bounds for sub-setting the data
205206
t_interval, lat_bnds, lon_bnds = \
206207
simulation_utils.convert_to_lat_lon_time_bounds(x_t.flatten(), self.x_T,
207208
deg_around_x0_xT_box=self.specific_settings['deg_around_xt_xT_box'],
208209
temp_horizon_in_h=self.specific_settings['T_goal_in_h'])
209210

211+
# get the data subset from the file
210212
grids_dict, water_u, water_v = simulation_utils.get_current_data_subset(
211213
t_interval, lat_bnds, lon_bnds,
212214
file_dicts=self.cur_forecast_dicts)
213215

216+
# do spatial interpolation to the desired resolution to run HJ_reachability
217+
grids_dict['x_grid'], grids_dict['y_grid'], water_u, water_v = simulation_utils.spatial_interpolation(
218+
grids_dict, water_u, water_v, target_shape=self.specific_settings['grid_res'], kind='linear')
219+
214220
# set absolute time in UTC Posix time
215221
self.current_data_t_0 = grids_dict['t_grid'][0]
216222

ocean_navigation_simulator/planners/hj_reachability_planners/platform_2D_for_sim.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,10 @@ def update_jax_interpolant(self, x_grid, y_grid, t_grid, water_u, water_v):
4444
Input Params:
4545
- water_u, water_v the array comes in from HYCOM as (T, Y, X)
4646
"""
47-
# need to flip array around to fit with grid_axis in X, Y, T and dynamics
48-
water_u = jnp.swapaxes(water_u, 0, 2)
49-
water_v = jnp.swapaxes(water_v, 0, 2)
50-
self.x_current = lambda point: interpolation.lin_interpo_3D_fields(
51-
point, water_u, x_grid, y_grid, t_grid)
52-
self.y_current = lambda point: interpolation.lin_interpo_3D_fields(
53-
point, water_v, x_grid, y_grid, t_grid)
47+
48+
# create 1D interpolation functions for running in the loop of the dynamics
49+
self.x_current = lambda point: interpolation.lin_interpo_1D(point, water_u, x_grid, y_grid, t_grid)
50+
self.y_current = lambda point: interpolation.lin_interpo_1D(point, water_v, x_grid, y_grid, t_grid)
5451

5552
def __call__(self, state, control, disturbance, time):
5653
"""Implements the continuous-time dynamics ODE."""

scripts/experiments/reachability_planner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@
5454
# planner.plot_ctrl_seq()
5555
#%% Set stuff up
5656
sim = OceanNavSimulator(sim_config_dict="simulator.yaml", control_config_dict='reach_controller.yaml', problem=prob)
57+
start = time.time()
5758
sim.run(T_in_h=70)
59+
print("Took : ", time.time() - start)
60+
# after doing now 1D interpolation in the loop planning time drops from 214, 209s to 46.5s
5861
#%% Step 5: plot from Simulator
5962
# # plot Battery levels over time
6063
sim.plot_trajectory(plotting_type='battery')

0 commit comments

Comments
 (0)