Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
66069ec
refactor weather module into new files and rename folder into
kdemmich Jul 15, 2025
1c983e8
draft get_weather function of weather_facade
kdemmich Jul 15, 2025
50391c0
deletex folder EnvironmentalData
kdemmich Jul 15, 2025
109a4ad
move weather logic from boat class to weather class
kdemmich Jul 23, 2025
5ddae3a
introduced IsoBasedStatus and cleaned up IsoBased.execute_routing() a…
kdemmich Jul 23, 2025
4f7b3b7
draft class IsobasedStatus and further tidy up IsoBased.execute_routing
kdemmich Jul 24, 2025
4579b1b
introduce class RoutingStep in IsoBased
kdemmich Jul 24, 2025
2fca0dc
review RoutingStep.get_point
kdemmich Jul 29, 2025
7b6bdd2
delete obsolete header in isobased.py
kdemmich Jul 29, 2025
450e57e
Merge branch 'main' into GeneraliseEnvironmentalData
kdemmich Jul 29, 2025
f0f7b26
fix unit tests : test_constraints
kdemmich Jul 29, 2025
055f104
fix unit test test_isobased: test_update_position_fail
kdemmich Jul 29, 2025
032ce2c
fix unit test test_isobased: test_check_bearing_true
kdemmich Jul 29, 2025
a7f7417
fix unit test test_isobased: test_check_bearing_false
kdemmich Jul 29, 2025
f268877
fix unit test test_isobased: test_get_delta_variables_last_step
kdemmich Jul 29, 2025
19850f9
fix unit test isobased: test_check_bearing
kdemmich Jul 29, 2025
533041d
Merge branch 'main' into GeneraliseEnvironmentalData
kdemmich Aug 27, 2025
8b9b908
revert changes regarding refactoring of environmental data
kdemmich Aug 27, 2025
67020c5
fix unit tests
kdemmich Sep 4, 2025
7f9d616
tidy up logging in tests_isobased.py
kdemmich Sep 4, 2025
e3180e2
bug fixes such that code executes
kdemmich Sep 4, 2025
76cd358
bug fix: routing terminates when all pruning segments are fully const…
kdemmich Sep 4, 2025
b5a02b9
bug fixes:
kdemmich Sep 4, 2025
b1807e0
bug fix: missing function argument constraint_list & tidy up unused
kdemmich Sep 8, 2025
9799fb8
bug fix: faulty function call for update of IsoBasedStatus
kdemmich Sep 8, 2025
11b6c45
bug fix: fix access of wrong array elements in define_courses
kdemmich Sep 8, 2025
29ee6ac
Merge branch 'main' into RefactorIsoBased
kdemmich Sep 9, 2025
e584451
bug fix: missing brackets in IsoBasedStatus.set_error_str()
kdemmich Sep 9, 2025
2eb2cf7
bug fix: faulty state str in Isobased.check_land_ahoy()
kdemmich Sep 10, 2025
77e1c1d
Add docstrings for class RoutingStep
kdemmich Sep 17, 2025
7ae6279
Add docstrings for class RoutingStep
kdemmich Sep 17, 2025
9af0be6
fix linting
kdemmich Sep 17, 2025
6afbcb3
add type hints to RoutingStep
kdemmich Sep 17, 2025
5e6542f
add docstrings and type hints to IsoBasedStatus
kdemmich Sep 17, 2025
adff325
add docstring for class IsoBased description
kdemmich Sep 17, 2025
3015664
add doc strings to IsoBased class until check_course_def
kdemmich Sep 17, 2025
fd8d57d
Add docstrings in particular to pruning functions
kdemmich Sep 18, 2025
1a913b9
Merge branch 'main' into RefactorIsoBased
kdemmich Sep 18, 2025
6284c0e
fix linting
kdemmich Sep 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,129 changes: 821 additions & 308 deletions WeatherRoutingTool/algorithms/isobased.py

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions WeatherRoutingTool/algorithms/isofuel.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def determine_timespread(self, delta_time):
logger.info('delta_time', delta_time.to('hour'))
logger.info('spread of time: ' + str(mean.to('hour')) + '+-' + str(stddev.to('hour')))

def update_time(self, delta_time):
def update_time(self):
delta_time = self.routing_step.delta_time
if not ((self.full_time_traveled.shape == delta_time.shape) and (self.time.shape == delta_time.shape)):
raise ValueError('shapes of delta_time, time and full_time_traveled not matching!')
for i in range(0, self.full_time_traveled.shape[0]):
Expand All @@ -147,6 +148,7 @@ def final_pruning(self):
idxs = np.argmin(full_fuel_array)

if debug:
print('full_fuel_array: ', full_fuel_array)
print('idxs', idxs)

# Return a trimmed isochrone
Expand All @@ -159,7 +161,6 @@ def final_pruning(self):
self.absolutefuel_per_step = self.absolutefuel_per_step[:, idxs]
self.shipparams_per_step.select(idxs)

self.current_course = self.current_course[idxs]
self.full_dist_traveled = self.full_dist_traveled[idxs]
self.full_time_traveled = self.full_time_traveled[idxs]
self.time = self.time[idxs]
Expand Down
3 changes: 0 additions & 3 deletions WeatherRoutingTool/algorithms/routingalg.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import logging
from datetime import datetime

import matplotlib
from astropy import units as u
from geovectorslib import geod
from matplotlib.figure import Figure

import WeatherRoutingTool.utils.formatting as form
from WeatherRoutingTool.constraints.constraints import *
from WeatherRoutingTool.ship.ship import Boat
from WeatherRoutingTool.utils.graphics import get_figure_path
Expand Down Expand Up @@ -36,7 +34,6 @@ def __init__(self, config):
self.departure_time = config.DEPARTURE_TIME

gcr = self.calculate_gcr(self.start, self.finish)
self.current_course = gcr * u.degree
self.gcr_course = gcr * u.degree

self.figure_path = get_figure_path()
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion WeatherRoutingTool/execute_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def execute_routing(config):

# *******************************************
# routing
min_fuel_route = min_fuel_route.execute_routing(boat, wt, constraint_list)
min_fuel_route, error_code = min_fuel_route.execute_routing(boat, wt, constraint_list)
# min_fuel_route.print_route()
min_fuel_route.return_route_to_API(routepath + '/' + str(min_fuel_route.route_type) + ".json")

Expand Down
48 changes: 24 additions & 24 deletions WeatherRoutingTool/ship/shipparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,33 +134,33 @@ def print(self):
logger.info('salinity: ' + str(self.salinity.value) + ' ' + self.salinity.unit.to_string())
logger.info('water_temperature: ' + str(self.water_temperature.value) + ' ' +
self.water_temperature.unit.to_string())
logger.info('status', self.status)
logger.info('message', self.message)
logger.info('status' + str(self.status))
logger.info('message' + str(self.message))
logger.info('fuel_type: ' + str(self.fuel_type))

def print_shape(self):
logger.info('fuel_rate: ', self.fuel_rate.shape)
logger.info('rpm: ', self.rpm.shape)
logger.info('power: ', self.power.shape)
logger.info('speed: ', self.speed.shape)
logger.info('r_calm: ', self.r_calm.shape)
logger.info('r_wind: ', self.r_wind.shape)
logger.info('r_waves: ', self.r_waves.shape)
logger.info('r_shallow: ', self.r_shallow.shape)
logger.info('r_roughness: ', self.r_roughness.shape)
logger.info('wave_height: ', self.wave_height.shape)
logger.info('wave_direction: ', self.wave_direction.shape)
logger.info('wave_period: ', self.wave_period.shape)
logger.info('u_currents: ', self.u_currents.shape)
logger.info('v_currents: ', self.v_currents.shape)
logger.info('u_wind_speed: ', self.u_wind_speed.shape)
logger.info('v_wind_speed: ', self.v_wind_speed.shape)
logger.info('pressure: ', self.pressure.shape)
logger.info('air_temperature: ', self.air_temperature.shape)
logger.info('salinity: ', self.salinity.shape)
logger.info('water_temperature: ', self.water_temperature.shape)
logger.info('status', self.status)
logger.info('message', self.message)
logger.info('fuel_rate: ' + str(self.fuel_rate.shape))
logger.info('rpm: ' + str(self.rpm.shape))
logger.info('power: ' + str(self.power.shape))
logger.info('speed: ' + str(self.speed.shape))
logger.info('r_calm: ' + str(self.r_calm.shape))
logger.info('r_wind: ' + str(self.r_wind.shape))
logger.info('r_waves: ' + str(self.r_waves.shape))
logger.info('r_shallow: ' + str(self.r_shallow.shape))
logger.info('r_roughness: ' + str(self.r_roughness.shape))
logger.info('wave_height: ' + str(self.wave_height.shape))
logger.info('wave_direction: ' + str(self.wave_direction.shape))
logger.info('wave_period: ' + str(self.wave_period.shape))
logger.info('u_currents: ' + str(self.u_currents.shape))
logger.info('v_currents: ' + str(self.v_currents.shape))
logger.info('u_wind_speed: ' + str(self.u_wind_speed.shape))
logger.info('v_wind_speed: ' + str(self.v_wind_speed.shape))
logger.info('pressure: ' + str(self.pressure.shape))
logger.info('air_temperature: ' + str(self.air_temperature.shape))
logger.info('salinity: ' + str(self.salinity.shape))
logger.info('water_temperature: ' + str(self.water_temperature.shape))
logger.info('status' + str(self.status))
logger.info('message' + str(self.message))

def define_courses(self, courses_segments):
self.speed = np.repeat(self.speed, courses_segments + 1, axis=1)
Expand Down
19 changes: 10 additions & 9 deletions WeatherRoutingTool/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ def read_dataset(self, filepath=None):
time_min_CMEMS_phys = (self.time_start - timedelta(minutes=30)).strftime("%Y-%m-%dT%H:%M:%S")
time_max_CMEMS_phys = (self.time_end + timedelta(minutes=180)).strftime("%Y-%m-%dT%H:%M:%S")

lon_min = self.map_size.lon1
lon_max = self.map_size.lon2
lat_min = self.map_size.lat1
lat_max = self.map_size.lat2
boundary_map = self.map_size.get_widened_map(1)
lon_min = boundary_map.lon1
lon_max = boundary_map.lon2
lat_min = boundary_map.lat1
lat_max = boundary_map.lat2
height_min = 10
height_max = 20

Expand Down Expand Up @@ -658,7 +659,7 @@ def _scale(self, dataset):


class FakeWeather(WeatherCond):
def __init__(self, time, hours, time_res, coord_res=1/12, var_dict=None):
def __init__(self, time, hours, time_res, coord_res=1 / 12, var_dict=None):
super().__init__(time, hours, time_res)
self.var_dict = {}
var_list_zero = {
Expand All @@ -684,14 +685,14 @@ def read_dataset(self, filepath=None):
# initialise coordinates
# round differences to 10^-5 (~1 m for latitude) to prevent shifts due to floating numbers
# interpret the configured map size limits inclusive
n_lat_values = ceil(round(self.map_size.lat2 - self.map_size.lat1, 5)/self.coord_res) + 1
n_lat_values = ceil(round(self.map_size.lat2 - self.map_size.lat1, 5) / self.coord_res) + 1
lat_start = self.map_size.lat1
lat_end = self.map_size.lat1 + self.coord_res * (n_lat_values-1)
lat_end = self.map_size.lat1 + self.coord_res * (n_lat_values - 1)
lat = np.linspace(lat_start, lat_end, n_lat_values)

n_lon_values = ceil(round(self.map_size.lon2 - self.map_size.lon1, 5)/self.coord_res) + 1
n_lon_values = ceil(round(self.map_size.lon2 - self.map_size.lon1, 5) / self.coord_res) + 1
lon_start = self.map_size.lon1
lon_end = self.map_size.lon1 + self.coord_res * (n_lon_values-1)
lon_end = self.map_size.lon1 + self.coord_res * (n_lon_values - 1)
lon = np.linspace(lon_start, lon_end, n_lon_values)

n_time_values = self.time_steps + 1
Expand Down
5 changes: 0 additions & 5 deletions scripts/compare_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

import argparse
import datetime as dt
import logging
import os

import matplotlib.pyplot as plt

import WeatherRoutingTool.utils.graphics as graphics
from WeatherRoutingTool.config import set_up_logging
from WeatherRoutingTool.constraints.constraints import *
from WeatherRoutingTool.routeparams import RouteParams
Expand Down
1 change: 0 additions & 1 deletion scripts/dpm_compared_to_maripower.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import os
from datetime import datetime, timedelta
from matplotlib.offsetbox import (OffsetImage, AnnotationBbox)
from matplotlib.legend_handler import HandlerTuple

from astropy import units as u

Expand Down
26 changes: 17 additions & 9 deletions tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import numpy as np
import xarray as xr
from astropy import units as u

import tests.basic_test_func as basic_test_func
from WeatherRoutingTool.config import set_up_logging
from WeatherRoutingTool.constraints.constraints import (ConstraintsList, ConstraintPars, LandCrossing,
RunTestContinuousChecks, WaterDepth, WaveHeight,
StatusCodeError)
from WeatherRoutingTool.utils.maps import Map

set_up_logging()


def generate_dummy_constraint_list():
pars = ConstraintPars()
Expand Down Expand Up @@ -172,13 +176,17 @@ def test_safe_crossing_shape_return():


def test_check_constraints_land_crossing():
move = {'lat2': np.array([52.70, 53.55]),
# 1st point: land crossing (failure), 2nd point: no land crossing(success)
'lon2': np.array([4.04, 5.45])}

ra = basic_test_func.create_dummy_IsoBased_object()
ra.lats_per_step = np.array([[52.76, 53.45]])
ra.lons_per_step = np.array([[5.40, 3.72]])
ra.routing_step.init_step(
lats_start=np.array([52.76, 53.45]),
lons_start=np.array([5.40, 3.72]),
courses=np.array([99, 99]) * u.degree,
time=None
)
ra.routing_step.update_end_step(
lats=np.array([52.70, 53.55]),
lons=np.array([4.04, 5.45]),
)

land_crossing = LandCrossing()
wave_height = WaveHeight()
Expand All @@ -188,9 +196,9 @@ def test_check_constraints_land_crossing():
constraint_list = generate_dummy_constraint_list()
constraint_list.add_neg_constraint(land_crossing)
constraint_list.add_neg_constraint(wave_height)
is_constrained = ra.check_constraints(move, constraint_list)
assert is_constrained[0] == 1
assert is_constrained[1] == 0
ra.check_constraints(constraint_list)
assert ra.routing_step.is_constrained[0] == 1
assert ra.routing_step.is_constrained[1] == 0


def test_safe_crossing_continuous():
Expand Down
Loading
Loading