WeatherRoutingTool package

Subpackages

Submodules

WeatherRoutingTool.config module

class WeatherRoutingTool.config.Config(*, ALGORITHM_TYPE: ~typing.Literal['isofuel', 'genetic', 'speedy_isobased'] = 'isofuel', BOAT_TYPE: ~typing.Literal['CBT', 'SAL', 'speedy_isobased', 'direct_power_method'] = 'direct_power_method', CONSTRAINTS_LIST: ~typing.List[~typing.Literal['land_crossing_global_land_mask', 'land_crossing_polygons', 'seamarks', 'water_depth', 'on_map', 'via_waypoints', 'status_error']], DEFAULT_ROUTE: ~typing.Annotated[list[int | float], ~annotated_types.MinLen(min_length=4), ~annotated_types.MaxLen(max_length=4)], DEFAULT_MAP: ~typing.Annotated[list[int | float], ~annotated_types.MinLen(min_length=4), ~annotated_types.MaxLen(max_length=4)], DELTA_FUEL: float = 3000, DELTA_TIME_FORECAST: float = 3, DEPARTURE_TIME: ~datetime.datetime, GENETIC_MUTATION_TYPE: ~typing.Literal['grid_based'] = 'grid_based', GENETIC_NUMBER_GENERATIONS: int = 20, GENETIC_NUMBER_OFFSPRINGS: int = 2, GENETIC_POPULATION_SIZE: int = 20, GENETIC_POPULATION_TYPE: ~typing.Literal['grid_based', 'from_geojson'] = 'grid_based', GENETIC_POPULATION_PATH: str | None = None, INTERMEDIATE_WAYPOINTS: list[~typing.Annotated[list[int | float], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=2), MaxLen(max_length=2)])]] = <factory>, ISOCHRONE_MAX_ROUTING_STEPS: int = 100, ISOCHRONE_MINIMISATION_CRITERION: ~typing.Literal['dist', 'squareddist_over_disttodest'] = 'squareddist_over_disttodest', ISOCHRONE_NUMBER_OF_ROUTES: int = 1, ISOCHRONE_PRUNE_GROUPS: ~typing.Literal['courses', 'larger_direction', 'branch'] = 'larger_direction', ISOCHRONE_PRUNE_SECTOR_DEG_HALF: int = 91, ISOCHRONE_PRUNE_SEGMENTS: int = 20, ISOCHRONE_PRUNE_SYMMETRY_AXIS: ~typing.Literal['gcr', 'headings_based'] = 'gcr', ROUTER_HDGS_SEGMENTS: int = 30, ROUTER_HDGS_INCREMENTS_DEG: int = 6, ROUTE_POSTPROCESSING: bool = False, ROUTING_STEPS: int = 60, TIME_FORECAST: float = 90, COURSES_FILE: str = None, DEPTH_DATA: str = None, WEATHER_DATA: str = None, ROUTE_PATH: str, CONFIG_PATH: str = None)[source]

Bases: BaseModel

Central configuration class of the Weather Routing Tool. Parameters are validated using pydantic.

ALGORITHM_TYPE: Literal['isofuel', 'genetic', 'speedy_isobased']
BOAT_TYPE: Literal['CBT', 'SAL', 'speedy_isobased', 'direct_power_method']
CONFIG_PATH: str
CONSTRAINTS_LIST: List[Literal['land_crossing_global_land_mask', 'land_crossing_polygons', 'seamarks', 'water_depth', 'on_map', 'via_waypoints', 'status_error']]
COURSES_FILE: str
DEFAULT_MAP: Annotated[list[int | float], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=4), MaxLen(max_length=4)])]
DEFAULT_ROUTE: Annotated[list[int | float], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=4), MaxLen(max_length=4)])]
DELTA_FUEL: float
DELTA_TIME_FORECAST: float
DEPARTURE_TIME: datetime
DEPTH_DATA: str
GENETIC_MUTATION_TYPE: Literal['grid_based']
GENETIC_NUMBER_GENERATIONS: int
GENETIC_NUMBER_OFFSPRINGS: int
GENETIC_POPULATION_PATH: str | None
GENETIC_POPULATION_SIZE: int
GENETIC_POPULATION_TYPE: Literal['grid_based', 'from_geojson']
INTERMEDIATE_WAYPOINTS: Annotated[list[Annotated[list[int | float], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=2), MaxLen(max_length=2)])]], FieldInfo(annotation=NoneType, required=False, default_factory=list)]
ISOCHRONE_MAX_ROUTING_STEPS: int
ISOCHRONE_MINIMISATION_CRITERION: Literal['dist', 'squareddist_over_disttodest']
ISOCHRONE_NUMBER_OF_ROUTES: int
ISOCHRONE_PRUNE_GROUPS: Literal['courses', 'larger_direction', 'branch']
ISOCHRONE_PRUNE_SECTOR_DEG_HALF: int
ISOCHRONE_PRUNE_SEGMENTS: int
ISOCHRONE_PRUNE_SYMMETRY_AXIS: Literal['gcr', 'headings_based']
ROUTER_HDGS_INCREMENTS_DEG: int
ROUTER_HDGS_SEGMENTS: int
ROUTE_PATH: str
ROUTE_POSTPROCESSING: bool
ROUTING_STEPS: int
TIME_FORECAST: float
WEATHER_DATA: str
classmethod assign_config(path=None, init_mode='from_json', config_dict=None)[source]

Check input type of config data and run validate_config

Parameters:
  • path (str, optional) – path to json with config data, defaults to None

  • init_mode (str, optional) – _description_, defaults to ‘from_json’

  • config_dict (dict, optional) – dict with config data, defaults to None

Raises:
  • ValueError – Path to json file doesn’t exist although chosen as input type for config

  • ValueError – Dict doesn’t exist although chosen as input type for config

  • ValueError – Mode chosen as input type for config doesn’t exist

Returns:

Validated config

Return type:

WeatherRoutingTool.config.Config

check_boat_algorithm_compatibility() Self[source]

The boat type ‘speedy_isobased’ is configured to run only with the corresponding algorithm type ‘speedy_isobased’

Raises:

ValueError – BOAT_TYPE is not compatible with ALGORITHM_TYPE

Returns:

Config object with validated BOAT_TYPE-ALGORITHM_TYPE-compatibility

Return type:

WeatherRoutingTool.config.Config

classmethod check_constraint_list(v)[source]

Check that the CONSTRAINTS_LIST contains ‘land_crossing_global_land_mask’ else the boat would be allowed to cross land

Raises:

ValueError – CONSTRAINTS_LIST doesn’t contain ‘land_crossing_global_land_mask’

Returns:

Validated CONSTRAINTS_LIST

Return type:

list

classmethod check_numeric_values_positivity(v, info: ValidationInfo)[source]
check_route_depth_data_compatibility() Self[source]

Check that the route runs inside the map that has depth data available considering only place as the depth data is time independent

Raises:

ValueError – Depth data doesn’t cover map

Returns:

Config object with validated DEPTH_DATA regarding place

Return type:

WeatherRoutingTool.config.Config

check_route_on_map() Self[source]

Check that the route runs inside the bounds of the defined map

Raises:

ValueError – Route coordinates are outside the DEFAULT_MAP bounds

Returns:

Config object with validated DEFAULT_ROUTE-DEFAULT_MAP-compatibility

Return type:

WeatherRoutingTool.config.Config

check_route_weather_data_compatibility() Self[source]

Check that the route runs inside the map that has weather data available considering place and time :raises ValueError: Weather data doesn’t cover map :raises ValueError: Weather data doesn’t cover full routing time range :raises ValueError: Weather data has no time dimension :return: Config object with validated WEATHER_DATA regarding place and time :rtype: WeatherRoutingTool.config.Config

classmethod check_router_hdgs_segments_positive_and_even(v)[source]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

classmethod parse_and_validate_datetime(v)[source]
classmethod validate_config(config_data)[source]

Validate the config by creating a Config class object and throw errors if necessary

Parameters:

config_data (dict) – Config data provided by the user in form of a json file or a dict

Returns:

Validated config

Return type:

WeatherRoutingTool.config.Config

classmethod validate_map_coordinates(v, info)[source]

Check if the coordinates of DEFAULT_MAP have values that the program can work with

Raises:
  • ValueError – DEFAULT_MAP doesn’t contain exactly 4 values

  • ValueError – One of the coordinates isn’t in the required range

Returns:

validated DEFAULT_MAP

Return type:

tuple

classmethod validate_path_exists(v, info: ValidationInfo)[source]
classmethod validate_route_coordinates(v)[source]

Check if the coordinates of DEFAULT_ROUTE have values that the program can work with

Raises:
  • ValueError – DEFAULT_ROUTE doesn’t contain exactly 4 values

  • ValueError – One of the coordinates isn’t in the required range

Returns:

Validated DEFAULT_ROUTE

Return type:

tuple

WeatherRoutingTool.config.set_up_logging(info_log_file=None, warnings_log_file=None, debug=False, stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, log_format='%(asctime)s - %(name)-12s: %(levelname)-8s %(message)s')[source]

WeatherRoutingTool.execute_routing module

WeatherRoutingTool.execute_routing.execute_routing(config)[source]

Execute route optimization based on the user-defined configuration. After a successful run the final route is saved into the configured folder.

Parameters:

config (WeatherRoutingTool.config.Config) – validated configuration

Returns:

None

WeatherRoutingTool.execute_routing.merge_figures_to_gif(path, nof_figures)[source]

WeatherRoutingTool.routeparams module

class WeatherRoutingTool.routeparams.RouteParams(count, start, finish, gcr, route_type, time, lats_per_step, lons_per_step, course_per_step, dists_per_step, starttime_per_step, ship_params_per_step)[source]

Bases: object

This is a Container class for route parameters. Parameters are assumed to be constant for every route segment (= distance from one coordinate pair to the following). The parameters for each routing step are tied to the start point of each route segment. Since the number of routing steps is by one smaller than the number of coordinate pairs, the arrays of this container class exhibit different lengths:

  • Type 1: count + 1: dists_per_step, ship_params_per_step, courses_per_step

  • Type 2: count + 2: lats_per_step, lons_per_step, starttime_per_step

When the RouteParams object is written to json file, the full arrays of type 2 are written. The corresponding values from the arrays of type 1 are set to -99 for the last coordinate pair.

convert_to_dict()[source]
count: int
course_per_step: tuple
dists_per_step: tuple
finish: tuple
classmethod from_file(filename)[source]
classmethod from_gzip_file(filename)[source]
gcr: tuple
get_dist_from_coords(lats, lons)[source]
get_fuel_per_dist()[source]
get_full_dist()[source]
get_full_fuel()[source]
get_full_travel_time()[source]
static get_per_waypoint_coords(route_lons, route_lats, start_time, bs)[source]
get_power_type(power_type)[source]
lats_per_step: tuple
lons_per_step: tuple
plot_acc_power_vs_dist(color, label, power_type)[source]
plot_power_vs_coord(ax, color, label, coordstring, power_type)[source]
plot_power_vs_dist(color, label, power_type, ax, bin_center_mean=None, bin_width_mean=None)[source]
plot_power_vs_dist_ratios(denominator, color, label, power_type)[source]
plot_power_vs_dist_with_weather(data_array, label_array, n_datasets)[source]
plot_route(ax, colour, label, linestyle=False)[source]
print_route()[source]
return_route_to_API(filename)[source]
route_type: str
set_ship_params(ship_params)[source]
ship_params_per_step: ShipParams
start: tuple
starttime_per_step: tuple
time: timedelta
write_to_file(filename)[source]

WeatherRoutingTool.test_maripower_settings_for_different_courses module

WeatherRoutingTool.test_maripower_settings_for_specific_route module

WeatherRoutingTool.weather module

class WeatherRoutingTool.weather.FakeWeather(time, hours, time_res, coord_res=0.08333333333333333, var_dict=None)[source]

Bases: WeatherCond

combine_var_dicts(var_dict_manual, var_dict_zero)[source]
read_dataset(filepath=None)[source]
write_data(filepath)[source]
class WeatherRoutingTool.weather.WeatherCond(time, hours, time_res)[source]

Bases: object

check_units()[source]
ds: Dataset
get_map_size()[source]
map_size: Map
read_dataset(filepath=None)[source]
set_map_size(map)[source]
property time_end
property time_res
property time_start
time_steps: int
class WeatherRoutingTool.weather.WeatherCondEnvAutomatic(time, hours, time_res)[source]

Bases: WeatherCond

check_data_consistency(ds_CMEMS_phys, ds_CMEMS_wave, ds_CMEMS_curr, ds_GFS)[source]
read_dataset(filepath=None)[source]
write_data(filepath)[source]
class WeatherRoutingTool.weather.WeatherCondFromFile(time, hours, time_res)[source]

Bases: WeatherCond

add_depth_to_EnvData(depth_path, bWriteEnvData=False)[source]
adjust_depth_format(depth_path)[source]
calculate_wind_function(time)[source]
close_env_file()[source]
get_time_step_index(time)[source]
get_twatws_from_uv(u, v)[source]
get_wind_vector(time)[source]
init_wind_vectors()[source]

Set wind vectors for given number of hours.

manipulate_dataset()[source]
plot_weather_map(fig, ax, time, varname, rebinx=5, rebiny=5, **kwargs)[source]
read_dataset(filepath=None)[source]
read_wind_functions(iTime)[source]
read_wind_vectors(time)[source]

Return u-v components for given rect for visualization.

wind_functions: None
wind_vectors: None
class WeatherRoutingTool.weather.WeatherCondODC(time, hours, time_res)[source]

Bases: WeatherCond

load_odc_product(product_name, res_x, res_y, output_crs='EPSG:4326', measurements=None)[source]
read_dataset(filepath=None)[source]
write_data(filepath)[source]

WeatherRoutingTool.weather_factory module

class WeatherRoutingTool.weather_factory.WeatherFactory[source]

Bases: object

static get_weather(data_mode, file_path, departure_time, time_forecast, time_resolution, default_map, **kwargs)[source]

Module contents