WeatherRoutingTool.algorithms package

Submodules

WeatherRoutingTool.algorithms.data_utils module

class WeatherRoutingTool.algorithms.data_utils.GridMixin(grid, *args, **kwargs)[source]

Bases: object

TODO: add class description _summary_

coords_to_index(points_as_coords)[source]
get_shuffled_cost()[source]
grid: Dataset
index_to_coords(points_as_indices)[source]
WeatherRoutingTool.algorithms.data_utils.distance(route)[source]

TODO: Where is this function used? Calculates the accumulated distance along a route

Parameters:

route (TODO: add type of route) – Some kind of route

Returns:

Accumulated distance along a route

Return type:

np.array

WeatherRoutingTool.algorithms.data_utils.get_closest(array, value)[source]

Determine and return index of the value in the array which is closest to the given value. If there are multiple values in the array with the same distance to the value, the first/smallest index is used. :param array: array used to search in :type array: numpy.ndarray :param value: value for which the closest value in the array should be found :type value: numeric :return: index :rtype: numpy.int64

WeatherRoutingTool.algorithms.data_utils.time_diffs(speed, route)[source]

WeatherRoutingTool.algorithms.genetic module

class WeatherRoutingTool.algorithms.genetic.Genetic(config)[source]

Bases: RoutingAlg

Extends RoutingAlg to a genetic algorithm using pymoo

check_destination()[source]
check_positive_power()[source]
default_map: Map
execute_routing(boat: Boat, wt: WeatherCond, constraints_list: ConstraintsList, verbose=False)[source]

TODO: More detailed description? Central method for calculating the route

Parameters:
  • boat (Boat) – Boat profile

  • wt (WeatherCond) – Weather data

  • constraints_list (ConstraintsList) – List of constraints on the routing

  • verbose (bool, optional) – sets verbosity, defaults to False

Returns:

calculated route

Return type:

RouteParams

fig: <module 'matplotlib.figure' from '/opt/hostedtoolcache/Python/3.13.6/x64/lib/python3.13/site-packages/matplotlib/figure.py'>
n_offsprings: int
optimize(problem, initial_population, crossover, mutation, duplicates)[source]

Optimize the routing problem by using the pymoo method minimize TODO: add description to parameters :param problem: _description_ :type problem: _type_ :param initial_population: _description_ :type initial_population: _type_ :param crossover: _description_ :type crossover: _type_ :param mutation: _description_ :type mutation: _type_ :param duplicates: _description_ :type duplicates: _type_ :return: _description_ :rtype: pymoo.core.result.Result

path_to_route_folder: str
plot_convergence(res)[source]

Plot the convergence curve (best objective value per generation).

plot_population_per_generation(res, best_route)[source]

create figures for every generation of routes TODO: add description for parameters :param res: _description_ :type res: pymoo.core.result.Result :param best_route: _description_ :type best_route: _type_

plot_running_metric(res)[source]

TODO: add description _summary_

Parameters:

res (_type_) – _description_

pop_size: int
print_current_status()[source]
print_init()[source]
terminate(**kwargs)[source]

TODO: add description _summary_

Returns:

Calculated route as a RouteParams object ready to be returned to the user

Return type:

RouteParams

weather_path: str

WeatherRoutingTool.algorithms.genetic_utils module

WeatherRoutingTool.algorithms.isobased module

class WeatherRoutingTool.algorithms.isobased.IsoBased(config)[source]

Bases: RoutingAlg

All variables that are named *_per_step constitute (M,N) arrays, whereby N corresponds to the number of courses (plus 1) and M corresponds to the number of routing steps. At the start of each routing step ‘count’, the element(s) at the position ‘count’ of the following arrays correspond to properties of the point of departure of the respective routing step. This means that for ‘count = 0’ the elements of lats_per_step and lons_per_step correspond to the coordinates of the departure point of the whole route. The first elements of the attributes

  • course_per_step

  • dist_per_step

  • speed_per_step

are 0 to satisfy this definition.

absolutefuel_per_step: ndarray
branch_based_pruning()[source]

TODO: add description _summary_

Returns:

_description_

Return type:

_type_

check_bearing(dist)[source]

TODO: add description _summary_

Parameters:

dist (float) – _description_

check_constraints(move, constraint_list)[source]
check_course_def()[source]
check_destination()[source]
check_for_positive_constraints(constraint_list)[source]
check_positive_power()[source]
check_settings()[source]
check_status(shipparams_per_step_status, route_name)[source]
count: int
course_increments_deg: int
course_per_step: ndarray
course_segments: int
courses_based_pruning(bins)[source]

TODO: add description _summary_

Parameters:

bins (_type_) – _description_

Returns:

_description_

Return type:

_type_

current_course: ndarray
current_number_of_routes: int
current_position()[source]
current_step_routes: DataFrame
define_courses()[source]

TODO: add description _summary_

define_courses_per_step()[source]
define_initial_variants()[source]
desired_number_of_routes: int
dist_per_step: ndarray
execute_routing(boat: Boat, wt: WeatherCond, constraints_list: ConstraintsList, verbose=False)[source]

Progress one isochrone with pruning/optimising route for specific time segment

Parameters:
  • boat (Boat) – Boat profile

  • wt (WeatherCond) – Weather data

  • constraints_list (ConstraintsList) – List of constraints on the routing

  • verbose (bool, optional) – sets verbosity, defaults to False

Returns:

Calculated route

Return type:

RouteParams

expand_axis_for_intermediate()[source]
final_pruning()[source]
find_every_route_reaching_destination()[source]

This function finds routes reaching the destination in the current last step of routing. First, it creates a dataframe with origin point of the current route segments. The route segments are grouped according to the origin point. ‘dist’ is the distance that could be travelled with available amount of fuel. ‘dist_dest’ is the distance from origin point to the destination. ‘st_index’ is storing the same index order of other nd arrays such as self.lats_per_step before grouping. So that, later it is referred in find_routes_reaching_destination_in_current_step function. (acts as a key from the dataframe to other arrays such as self.lats_per_step )

Routes from the current step reaching the destination are stored in ‘current_step_routes’ dataframe. Only the one route segment per branch originating from the same origin point that minimize the fuel is stored in current_step_routes. Routes which are not reaching the destination in the current step are stored in ‘next_step_routes’ dataframe. In this case, all routes originating from the same origin point are stored in the dataframe.

find_routes_reaching_destination_in_current_step(remaining_routes=0)[source]

In this function, different routes obtained from ‘find_every_route_reaching_destination’ and stored in current_step_routes dataframe are sorted by minimum fuel. The number of routes that are selected is specified by the variable remaining_routes.

Parameters:

remaining_routes (int, optional) – Variable for saving routes meeting fuel consumption criteria, defaults to 0

finish_temp: tuple
full_dist_traveled: ndarray
full_time_traveled: ndarray
gcr_course_temp: tuple
get_current_course()[source]
get_current_lats()[source]
get_current_lons()[source]
get_current_speed()[source]
get_delta_variables(boat, wind, bs)[source]
get_delta_variables_netCDF_last_step(boat, wind, bs)[source]
get_final_index()[source]
get_pruned_indices_statistics(bin_stat, bin_edges, bin_number, trim)[source]
get_wind_functions(wt)[source]
init_fig(water_depth, map_size, showDepth=True)[source]
larger_direction_based_pruning(bins)[source]

TODO: add description _summary_

Parameters:

bins (_type_) – _description_

Returns:

_description_

Return type:

_type_

lats_per_step: ndarray
lons_per_step: ndarray
make_route_object(idxs)[source]
minimisation_criterion: str
move_boat_direct(wt: WeatherCond, boat: Boat, constraint_list: ConstraintsList)[source]

Calculate new boat position for current time step based on wind and boat function

Parameters:
ncount: int
next_step_routes: DataFrame
plot_routes(idxs)[source]

Plot every complete individual route that is reaching the destination

Parameters:

idxs (int) – loop index

print_current_status()[source]
print_init()[source]
print_shape()[source]
prune_groups: str
prune_sector_deg_half: int
prune_segments: int
prune_symmetry_axis: str
pruning(trim, bins)[source]

TODO: add description _summary_

Parameters:
  • trim (_type_) – _description_

  • bins (_type_) – _description_

Raises:
  • ValueError – _description_

  • Exception – _description_

pruning_error: bool
pruning_gcr_centered(trim=True)[source]

For every pruning segment, select the route that maximises the distance towards the starting point (or last intermediate waypoint). All other routes are discarded. The symmetry axis of the pruning segments is defined based on the gcr of the current ‘mean’ position towards the (temporary) destination.

Parameters:

trim (bool, optional) – TODO: add _description_, defaults to True

pruning_headings_centered(trim=True)[source]

For every pruning segment, select the route that maximises the distance towards the starting point (or last intermediate waypoint). All other routes are discarded. The symmetry axis of the pruning segments is given by the median of all considered courses.

Parameters:

trim (bool, optional) – _description_, defaults to True

pruning_per_step(trim=True)[source]
revert_to_previous_step()[source]

In this function, when all routes are constrained, the arrays are set back to previous step to provide meaningful error message.

route_list: list
route_reached_destination: bool
route_reached_waypoint: bool
routes_from_previous_step()[source]

When all routes are constrained, unique routes until the current constrained routing step are found here. Then, the unique routes are written into json files and plotted.

set_course_segments(seg, inc)[source]
set_minimisation_criterion(min_str)[source]
set_next_step_routes()[source]

Updating all arrays according to the indices of the routes that need to be further processed in the next routing step

set_pruning_settings(sector_deg_half, seg, prune_groups, prune_symmetry_axis='gcr')[source]
shipparams_per_step: ShipParams
start_temp: tuple
starttime_per_step: ndarray
terminate(**kwargs)[source]

TODO: add description

Returns:

Calculated route as a RouteParams object ready to be returned to the user

Return type:

RouteParams

time: ndarray
update_dist(delta_time, bs)[source]
update_fig(status)[source]
update_fuel(delta_fuel, fuel_rate)[source]
update_position(move, is_constrained, dist)[source]

Update the current position of the ship TODO: add parameter description :param move: _description_ :type move: {‘lat2’: lat2, ‘lon2’: lon2, ‘azi2’: azi2, ‘iterations’: iterations} :param is_constrained: _description_ :type is_constrained: np.ndarray[bool] :param dist: _description_ :type dist: float

update_shipparams(ship_params_single_step)[source]
update_time(delta_time)[source]

WeatherRoutingTool.algorithms.isochrone module

class WeatherRoutingTool.algorithms.isochrone.IsoChrone(start, finish, time, delta_time)[source]

Bases: IsoBased

TODO: add description (Is this algorithm in use? It is not possible to choose it in the config.) _summary_

check_isochrones(route: RouteParams)[source]

Check route for equal time intervals

Parameters:

route (RouteParams) – Currently considered routes

Raises:

ValueError – If time intervall between every step of the route isn’t 3600 s

delta_time: int
get_delta_variables(boat, wind, bs)[source]
get_dist(bs)[source]

WeatherRoutingTool.algorithms.isofuel module

class WeatherRoutingTool.algorithms.isofuel.IsoFuel(config)[source]

Bases: IsoBased

IsoFuel inherits from IsoBased and is based on the principle of routing steps that are equal in fuel consumption

check_isochrones(route: RouteParams)[source]
delta_fuel: float
determine_timespread(delta_time)[source]

TODO: add description _summary_

Parameters:

delta_time (_type_) – _description_

final_pruning()[source]

TODO: add description _summary_

Raises:

Exception – _description_

get_delta_variables(boat, wind, bs)[source]

returns fuel (= power) [W], dist [m], delta_time [s], delta_fuel [Ws]

Parameters:
  • boat (Boat) – boat object

  • wind – wind

  • bs (numeric) – boat speed

Returns:

Return type:

tuple

get_delta_variables_netCDF(ship_params, bs)[source]

returns fuel (= power) [W], dist [m], delta_time [s], delta_fuel [Ws]

Parameters:
  • ship_params – ShipParams

  • bs (numeric) – boat speed

Returns:

Return type:

tuple

get_delta_variables_netCDF_last_step(ship_params, bs)[source]

returns fuel (= power) [W], dist [m], delta_time [s], delta_fuel [Ws]

Parameters:
  • ship_params – ShipParams

  • bs (numeric) – boat speed

Returns:

Return type:

tuple

get_dist(bs, delta_time)[source]
get_time(bs, dist)[source]

Calculate time [s] from boat speed and distance

Parameters:
  • bs (numeric) – boat speed

  • dist (numeric) – distance

Returns:

time needed to travel the given distance with the given speed

Return type:

numeric

print_init()[source]
update_time(delta_time)[source]

WeatherRoutingTool.algorithms.routingalg module

class WeatherRoutingTool.algorithms.routingalg.RoutingAlg(config)[source]

Bases: object

Mother class of all routing algorithms defining basic attributes and methods

calculate_gcr(start, finish)[source]

Calculate distance between start and end according to Vincenty’s approach, return dictionary

check_destination()[source]
check_for_positive_constraints(constraint_list)[source]
check_positive_power()[source]
departure_time: datetime
execute_routing(boat: Boat, wt: WeatherCond, constraints_list: ConstraintsList, verbose=False)[source]
fig: <module 'matplotlib.figure' from '/opt/hostedtoolcache/Python/3.13.6/x64/lib/python3.13/site-packages/matplotlib/figure.py'>
figure_path: str
finish: tuple
gcr_course: float
init_fig(**kwargs)[source]
print_current_status()[source]
print_init()[source]
route_ensemble: list
start: tuple
terminate(**kwargs)[source]
update_fig()[source]

WeatherRoutingTool.algorithms.routingalg_factory module

class WeatherRoutingTool.algorithms.routingalg_factory.RoutingAlgFactory[source]

Bases: object

Class for generating a routing algorithm object based on the ALGORITHM_TYPE defined in the config

static get_routing_alg(config)[source]

Module contents