Skip to content

Commit f584019

Browse files
committed
fix: fix 'in_time' constraint with algorithms that don't use weather data + small clean-ups
1 parent d51f9fa commit f584019

4 files changed

Lines changed: 19 additions & 12 deletions

File tree

WeatherRoutingTool/algorithms/routingalg.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import logging
12
from datetime import datetime
23

3-
import matplotlib
44
from astropy import units as u
55
from geovectorslib import geod
6-
from matplotlib.figure import Figure
6+
from matplotlib import figure, pyplot
77

8-
from WeatherRoutingTool.constraints.constraints import *
8+
import WeatherRoutingTool.utils.formatting as form
9+
from WeatherRoutingTool.constraints.constraints import ConstraintsList
910
from WeatherRoutingTool.routeparams import RouteParams
1011
from WeatherRoutingTool.ship.ship import Boat
1112
from WeatherRoutingTool.utils.graphics import get_figure_path
@@ -27,7 +28,7 @@ class RoutingAlg:
2728
gcr_course: float # azimuthal angle of great circle route (0 - 360°)
2829
gcr_dist: float # distance of great circle route
2930

30-
fig: matplotlib.figure
31+
fig: figure.Figure
3132
route_ensemble: list
3233
figure_path: str
3334
map_ext: Map
@@ -48,7 +49,7 @@ def __init__(self, config):
4849
self.gcr_course = self.gcr_course * u.degree
4950

5051
self.figure_path = get_figure_path()
51-
plt.switch_backend("Agg")
52+
pyplot.switch_backend("Agg")
5253

5354
self.boat_speed = config.BOAT_SPEED
5455
if self.boat_speed is not None:

WeatherRoutingTool/config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ class Config(BaseModel):
6666
'land_crossing_global_land_mask', 'land_crossing_polygons', 'seamarks',
6767
'water_depth', 'on_map', 'in_time', 'via_waypoints', 'status_error'
6868
]]
69-
# options: 'land_crossing_global_land_mask', 'land_crossing_polygons',
70-
# 'seamarks','water_depth', 'on_map', 'in_time', 'via_waypoints', 'status_error'
7169

7270
_DATA_MODE_DEPTH: str = PrivateAttr('from_file') # options: 'automatic', 'from_file', 'odc', 'skip'
7371
_DATA_MODE_WEATHER: str = PrivateAttr('from_file') # options: 'automatic', 'from_file', 'odc', 'skip'

WeatherRoutingTool/constraints/constraints.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,15 +839,15 @@ class StayOnMap(NegativeContraint):
839839

840840
def __init__(self):
841841
NegativeContraint.__init__(self, "StayOnMap")
842-
self.message += "leaving wheather map!" # self.resource_type = 0
842+
self.message += "leaving weather map!" # self.resource_type = 0
843843

844844
def constraint_on_point(self, lat, lon, time):
845845
# self.print_debug('checking point: ' + str(lat) + ',' + str(lon))
846846
is_on_map = ((lat > self.lat2) + (lat < self.lat1) + (lon > self.lon2) + (lon < self.lon1))
847847
return is_on_map
848848

849849
def print_info(self):
850-
logger.info(form.get_log_step("stay on wheather map", 1))
850+
logger.info(form.get_log_step("stay on weather map", 1))
851851

852852
def set_map(self, lat1, lon1, lat2, lon2):
853853
self.lat1 = lat1
@@ -866,7 +866,7 @@ class StayInTime(NegativeContraint):
866866

867867
def __init__(self):
868868
NegativeContraint.__init__(self, "StayInTime")
869-
self.message += "leaving wheather time frame!" # self.resource_type = 0
869+
self.message += "leaving weather time frame!" # self.resource_type = 0
870870

871871
def check_crossing(self, lat_start: np.ndarray, lon_start: np.ndarray, lat_end: np.ndarray, lon_end: np.ndarray,
872872
time_start: np.ndarray = None):
@@ -899,7 +899,7 @@ def check_crossing(self, lat_start: np.ndarray, lon_start: np.ndarray, lat_end:
899899
return is_out_of_time
900900

901901
def print_info(self):
902-
logger.info(form.get_log_step("stay in wheather time frame", 1))
902+
logger.info(form.get_log_step("stay in weather time frame", 1))
903903

904904
def set_time(self, time_start, time_end):
905905
self.time_start = time_start

WeatherRoutingTool/execute_routing.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# import cProfile
2+
import logging
23

34
import WeatherRoutingTool.utils.graphics as graphics
45
from WeatherRoutingTool.ship.ship_factory import ShipFactory
@@ -8,6 +9,8 @@
89
from WeatherRoutingTool.algorithms.routingalg_factory import RoutingAlgFactory
910
from WeatherRoutingTool.utils.maps import Map
1011

12+
logger = logging.getLogger('WRT.execute_routing')
13+
1114

1215
def merge_figures_to_gif(path, nof_figures):
1316
graphics.merge_figs(path, nof_figures)
@@ -42,7 +45,12 @@ def execute_routing(config, ship_config):
4245
# initialise weather
4346
wt = WeatherFactory.get_weather(config._DATA_MODE_WEATHER, windfile, departure_time, time_forecast, time_resolution,
4447
default_map)
45-
time_frame = (wt.time_start, wt.time_end)
48+
if config._DATA_MODE_WEATHER == "skip":
49+
time_frame = None
50+
if "in_time" in config.CONSTRAINTS_LIST:
51+
logger.warning("No weather data used. Ignoring constraint 'in_time'.")
52+
else:
53+
time_frame = (wt.time_start, wt.time_end)
4654

4755
# *******************************************
4856
# initialise boat

0 commit comments

Comments
 (0)