Skip to content

Commit b73ba59

Browse files
author
MariusWiggert
committed
Added comment to prevent weird behavior when initial_set is smaller than grid_resolution
1 parent 45f10f7 commit b73ba59

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

configs/reach_controller.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ planner:
88
'direction': 'forward'
99
'fwd_back_buffer_in_h': 1 # this is the time added to the earliest_to_reach as buffer for forward-backward
1010
'T_goal_in_h': 65
11-
'initial_set_radii': [0.03, 0.03]
11+
'initial_set_radii': [0.03, 0.03] # this is in deg lat, lon
1212
'n_time_vector': 60 # Note that this is the number of time-intervals, the vector is +1 longer because of init_time
13-
'grid_res': !!python/tuple [100, 100]
14-
'deg_around_xt_xT_box': 0.8
13+
# Note: grid_res should alwas be bigger than initial_set_radii, otherwise reachability behaves weirdly.
14+
'grid_res': !!python/tuple [0.02, 0.02] # Note: this is in deg lat, lon (HYCOM Global is 0.083 and Mexico 0.04)
15+
'deg_around_xt_xT_box': 0.8 # area over which to run HJ_reachability
1516
'accuracy': 'high'
1617
'artificial_dissipation_scheme': 'local_local'
1718
dt_replanning: 864000000. # right now very high as only tested open-loop control once

ocean_navigation_simulator/planners/hj_reachability_planners/hj_reachability_planner.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from ocean_navigation_simulator.utils import simulation_utils
44
from ocean_navigation_simulator.planners.hj_reachability_planners.platform_2D_for_sim import Platform2D_for_sim
55
import os
6-
from scipy.interpolate import interp1d
7-
import bisect
86
import sys
97
# Note: if you develop on hj_reachability and this library simultaneously uncomment this line
108
# sys.path.extend([os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))) + 'hj_reachability_c3'])
@@ -49,7 +47,7 @@ def __init__(self, problem, gen_settings, specific_settings):
4947
# this is just a variable that persists after planning for plotting/debugging
5048
self.x_t = None
5149
# initializes variables needed for planning, they will be filled in the plan method
52-
self.reach_times, self.all_values, self.times_abs, self.grid, self.diss_scheme = [None]*5
50+
self.reach_times, self.all_values, self.grid, self.diss_scheme = [None]*4
5351
self.x_traj, self.contr_seq, self.distr_seq = [None]*3
5452
# initialize variables needed for solving the PDE in non_dimensional terms
5553
self.characteristic_vec, self.offset_vec, self.nonDimGrid, self.nondim_dynamics = [None] * 4
@@ -213,9 +211,13 @@ def update_current_data(self, x_t):
213211
t_interval, lat_bnds, lon_bnds,
214212
file_dicts=self.cur_forecast_dicts)
215213

214+
# calculate target shape of the grid
215+
x_n_res = int((grids_dict['x_grid'][-1] - grids_dict['x_grid'][0])/self.specific_settings['grid_res'][0])
216+
y_n_res = int((grids_dict['y_grid'][-1] - grids_dict['y_grid'][0])/self.specific_settings['grid_res'][1])
217+
216218
# do spatial interpolation to the desired resolution to run HJ_reachability
217219
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')
220+
grids_dict, water_u, water_v, target_shape=(x_n_res, y_n_res), kind='linear')
219221

220222
# set absolute time in UTC Posix time
221223
self.current_data_t_0 = grids_dict['t_grid'][0]
@@ -327,11 +329,12 @@ def get_dim_dynamical_system(self):
327329

328330
def initialize_hj_grid(self, grids_dict):
329331
"""Initialize the dimensional grid in degrees lat, lon"""
332+
# initialize grid using the grids_dict x-y shape as shape
330333
self.grid = hj.Grid.from_grid_definition_and_initial_values(
331334
domain=hj.sets.Box(
332335
lo=np.array([grids_dict['x_grid'][0], grids_dict['y_grid'][0]]),
333336
hi=np.array([grids_dict['x_grid'][-1], grids_dict['y_grid'][-1]])),
334-
shape=self.specific_settings['grid_res'])
337+
shape=(len(grids_dict['x_grid']), len(grids_dict['y_grid'])))
335338

336339
def get_initial_values(self, center):
337340
return hj.shapes.shape_ellipse(grid=self.nonDimGrid,

ocean_navigation_simulator/utils/plotting_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import numpy as np
21
import matplotlib.pyplot as plt
32
import cartopy.crs as ccrs
43
import cartopy.feature as cfeature

0 commit comments

Comments
 (0)