Skip to content

Commit

Permalink
Improve config and clean up imports in test_maripower scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPontius committed Jan 25, 2024
1 parent 8778ed1 commit fa74a4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
24 changes: 10 additions & 14 deletions WeatherRoutingTool/test_maripower_settings_for_different_courses.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import argparse
import copy
import math
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime, timedelta

import WeatherRoutingTool.utils.graphics as graphics
from WeatherRoutingTool.config import Config
from WeatherRoutingTool.routeparams import RouteParams
from WeatherRoutingTool.utils.graphics import get_figure_path
from WeatherRoutingTool.utils.maps import Map
from WeatherRoutingTool.ship.ship import Tanker
from WeatherRoutingTool.weather_factory import WeatherFactory


def run_maripower_test_scenario(calmfactor, windfactor, wavefactor, waypoint_dict, filedir, maripower_scenario,
def run_maripower_test_scenario(calmfactor, windfactor, wavefactor, waypoint_dict, maripower_scenario,
weather_scenario, draught):
boat = Tanker(config)
boat.Draugh = draught
Expand Down Expand Up @@ -94,8 +92,6 @@ def plot_polar_power(curve_list, label_list, courses, figuredir, name, fuel_type
parser.add_argument('-out', '--geojson-out', help="Geojson (absolute path)", required=False, type=str)

args = parser.parse_args()
if not args.file:
raise RuntimeError("No config file name provided!")

config = Config(file_name=args.file)
config.print()
Expand All @@ -104,7 +100,7 @@ def plot_polar_power(curve_list, label_list, courses, figuredir, name, fuel_type
windfile = config.WEATHER_DATA
depthfile = config.DEPTH_DATA
coursesfile = config.COURSES_FILE
figurefile = get_figure_path()
figurepath = get_figure_path()
time_resolution = config.DELTA_TIME_FORECAST
time_forecast = config.TIME_FORECAST
departure_time = datetime.strptime(config.DEPARTURE_TIME, '%Y-%m-%dT%H:%MZ')
Expand Down Expand Up @@ -185,37 +181,37 @@ def plot_polar_power(curve_list, label_list, courses, figuredir, name, fuel_type
maripower_test_scenarios_calm[key],
maripower_test_scenarios_wind[key],
maripower_test_scenarios_wave[key],
waypoint_dict, args.geojson_out,
waypoint_dict,
key, weather_type)

plt.rcParams['font.size'] = graphics.get_standard('font_size')

nominator_list = [shipparams_vec['95perc_calm'], shipparams_vec['105perc_calm']]
label_list = ['95% Glattwasserwiderstand', '105% Glattwasserwiderstand']
plot_power_vs_courses(nominator_list, label_list, shipparams_vec['original'], courses, args.geojson_out,
plot_power_vs_courses(nominator_list, label_list, shipparams_vec['original'], courses, figurepath,
'calmwaterres_' + weather_type, 'power', draught)

nominator_list = [shipparams_vec['80perc_wind'], shipparams_vec['120perc_wind']]
label_list = ['80% Zusatzwiderstand Wind', '120% Zusatzwiderstand Wind']
plot_power_vs_courses(nominator_list, label_list, shipparams_vec['original'], courses, args.geojson_out,
plot_power_vs_courses(nominator_list, label_list, shipparams_vec['original'], courses, figurepath,
'windres_' + weather_type, 'power', draught)

nominator_list = [shipparams_vec['80perc_wave'], shipparams_vec['120perc_wave']]
label_list = ['80% Zusatzwiderstand Seegang', '120% Zusatzwiderstand Seegang']
plot_power_vs_courses(nominator_list, label_list, shipparams_vec['original'], courses, args.geojson_out,
plot_power_vs_courses(nominator_list, label_list, shipparams_vec['original'], courses, figurepath,
'waveres_' + weather_type, 'power', draught)

curve_list = [shipparams_vec['original'], shipparams_vec['95perc_calm'], shipparams_vec['105perc_calm']]
label_list = ['original', '95% Glattwasserwiderstand', '105% Glattwasserwiderstand']
plot_polar_power(curve_list, label_list, courses, args.geojson_out,
plot_polar_power(curve_list, label_list, courses, figurepath,
'calmwaterres_' + weather_type, 'power', draught)

curve_list = [shipparams_vec['original'], shipparams_vec['80perc_wind'], shipparams_vec['120perc_wind']]
label_list = ['original', '80% Zusatzwiderstand Wind', '120% Zusatzwiderstand Wind']
plot_polar_power(curve_list, label_list, courses, args.geojson_out,
plot_polar_power(curve_list, label_list, courses, figurepath,
'windres_' + weather_type, 'power', draught)

curve_list = [shipparams_vec['original'], shipparams_vec['80perc_wave'], shipparams_vec['120perc_wave']]
label_list = ['original', '80% Zusatzwiderstand Seegang', '120% Zusatzwiderstand Seegang']
plot_polar_power(curve_list, label_list, courses, args.geojson_out,
plot_polar_power(curve_list, label_list, courses, figurepath,
'waveres_' + weather_type, 'power', draught)
19 changes: 11 additions & 8 deletions WeatherRoutingTool/test_maripower_settings_for_specific_route.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import argparse
import math
import os
from datetime import datetime

import matplotlib.pyplot as plt

import WeatherRoutingTool.utils.graphics as graphics
from WeatherRoutingTool.config import Config
from WeatherRoutingTool.routeparams import RouteParams
from WeatherRoutingTool.utils.graphics import get_figure_path
Expand All @@ -13,7 +13,7 @@
from WeatherRoutingTool.weather_factory import WeatherFactory


def run_maripower_test_scenario(calmfactor, windfactor, wavefactor, waypoint_dict, filedir, maripower_scenario,
def run_maripower_test_scenario(calmfactor, windfactor, wavefactor, waypoint_dict, geojsondir, maripower_scenario,
weather_scenario):
boat = Tanker(config)
# boat.set_ship_property('Draught', [draught.mean()])
Expand Down Expand Up @@ -43,8 +43,8 @@ def run_maripower_test_scenario(calmfactor, windfactor, wavefactor, waypoint_dic
starttime_per_step=time,
ship_params_per_step=ship_params)

if args.geojson_out:
filename = filedir + 'route_' + weather_scenario + '_' + maripower_scenario + '.json'
if geojsondir:
filename = os.path.join(geojsondir, 'route_' + weather_scenario + '_' + maripower_scenario + '.json')
print('Writing file: ', filename)
rp.return_route_to_API(filename)

Expand All @@ -53,18 +53,21 @@ def run_maripower_test_scenario(calmfactor, windfactor, wavefactor, waypoint_dic
parser = argparse.ArgumentParser(description='Weather Routing Tool')
parser.add_argument('-f', '--file', help="Config file name (absolute path)", required=True, type=str)
parser.add_argument('-r', '--route', help="Route file name (absolute path)", required=True, type=str)
parser.add_argument('-out', '--geojson-out', help="Geojson (absolute path)", required=False, type=str)
parser.add_argument('--write-geojson', help="<True|False>. Defaults to 'False'", required=False,
type=str, default='False')

args = parser.parse_args()
if not args.file:
raise RuntimeError("No config file name provided!")

config = Config(file_name=args.file)
config.print()

routename = 'original_resistances_calm_weather'
windfile = config.WEATHER_DATA
depthfile = config.DEPTH_DATA
if str(args.write_geojson).lower() == 'true':
routepath = config.ROUTE_PATH
else:
routepath = None
coursesfile = config.COURSES_FILE
figurefile = get_figure_path()
time_resolution = config.DELTA_TIME_FORECAST
Expand Down Expand Up @@ -134,6 +137,6 @@ def run_maripower_test_scenario(calmfactor, windfactor, wavefactor, waypoint_dic
maripower_test_scenarios_wind[key],
maripower_test_scenarios_wave[key],
waypoint_dict,
args.geojson_out,
routepath,
key,
weather_type)

0 comments on commit fa74a4b

Please sign in to comment.