Skip to content

Commit

Permalink
Add environmental data to shipparams and write them to geojson
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPontius committed Mar 26, 2024
1 parent 25efd1e commit 7fde391
Show file tree
Hide file tree
Showing 4 changed files with 408 additions and 6 deletions.
32 changes: 32 additions & 0 deletions WeatherRoutingTool/algorithms/isobased.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,27 @@ def update_shipparams(self, ship_params_single_step):
new_rshallow = np.vstack((ship_params_single_step.get_rshallow(), self.shipparams_per_step.get_rshallow()))
new_rroughness = np.vstack(
(ship_params_single_step.get_rroughness(), self.shipparams_per_step.get_rroughness()))
new_wave_height = np.vstack((ship_params_single_step.get_wave_height(),
self.shipparams_per_step.get_wave_height()))
new_wave_direction = np.vstack((ship_params_single_step.get_wave_direction(),
self.shipparams_per_step.get_wave_direction()))
new_wave_period = np.vstack((ship_params_single_step.get_wave_period(),
self.shipparams_per_step.get_wave_period()))
new_u_currents = np.vstack((ship_params_single_step.get_u_currents(),
self.shipparams_per_step.get_u_currents()))
new_v_currents = np.vstack((ship_params_single_step.get_v_currents(),
self.shipparams_per_step.get_v_currents()))
new_u_wind_speed = np.vstack((ship_params_single_step.get_u_wind_speed(),
self.shipparams_per_step.get_u_wind_speed()))
new_v_wind_speed = np.vstack((ship_params_single_step.get_v_wind_speed(),
self.shipparams_per_step.get_v_wind_speed()))
new_pressure = np.vstack((ship_params_single_step.get_pressure(), self.shipparams_per_step.get_pressure()))
new_air_temperature = np.vstack((ship_params_single_step.get_air_temperature(),
self.shipparams_per_step.get_air_temperature()))
new_salinity = np.vstack((ship_params_single_step.get_salinity(),
self.shipparams_per_step.get_salinity()))
new_water_temperature = np.vstack((ship_params_single_step.get_water_temperature(),
self.shipparams_per_step.get_water_temperature()))
new_status = np.vstack((ship_params_single_step.get_status(), self.shipparams_per_step.get_status()))

self.shipparams_per_step.set_rpm(new_rpm)
Expand All @@ -626,6 +647,17 @@ def update_shipparams(self, ship_params_single_step):
self.shipparams_per_step.set_rwaves(new_rwaves)
self.shipparams_per_step.set_rshallow(new_rshallow)
self.shipparams_per_step.set_rroughness(new_rroughness)
self.shipparams_per_step.set_wave_height(new_wave_height)
self.shipparams_per_step.set_wave_direction(new_wave_direction)
self.shipparams_per_step.set_wave_period(new_wave_period)
self.shipparams_per_step.set_u_currents(new_u_currents)
self.shipparams_per_step.set_v_currents(new_v_currents)
self.shipparams_per_step.set_u_wind_speed(new_u_wind_speed)
self.shipparams_per_step.set_v_wind_speed(new_v_wind_speed)
self.shipparams_per_step.set_pressure(new_pressure)
self.shipparams_per_step.set_air_temperature(new_air_temperature)
self.shipparams_per_step.set_salinity(new_salinity)
self.shipparams_per_step.set_water_temperature(new_water_temperature)
self.shipparams_per_step.set_status(new_status)

def check_course_def(self):
Expand Down
75 changes: 71 additions & 4 deletions WeatherRoutingTool/routeparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ def return_route_to_API(self, filename):
properties['wave_resistance'] = {'value': -99, 'unit': 'N'}
properties['shallow_water_resistance'] = {'value': -99, 'unit': 'N'}
properties['hull_roughness_resistance'] = {'value': -99, 'unit': 'N'}
properties['wave_height'] = {'value': -99, 'unit': 'm'}
properties['wave_direction'] = {'value': -99, 'unit': 'radian'}
properties['wave_period'] = {'value': -99, 'unit': 's'}
properties['u_currents'] = {'value': -99, 'unit': 'm/s'}
properties['v_currents'] = {'value': -99, 'unit': 'm/s'}
properties['u_wind_speed'] = {'value': -99, 'unit': 'm/s'}
properties['v_wind_speed'] = {'value': -99, 'unit': 'm/s'}
properties['pressure'] = {'value': -99, 'unit': 'Pa'}
properties['air_temperature'] = {'value': -99, 'unit': '°C'}
properties['salinity'] = {'value': -99, 'unit': '-'}
properties['water_temperature'] = {'value': -99, 'unit': '°C'}
properties['status'] = {'value': -99}
else:
properties['speed'] = {'value': self.ship_params_per_step.speed[i].value, 'unit': 'm/s'}
Expand All @@ -159,12 +170,24 @@ def return_route_to_API(self, filename):
properties['calm_resistance'] = {'value': self.ship_params_per_step.r_calm[i].value, 'unit': 'N'}
properties['wind_resistance'] = {'value': self.ship_params_per_step.r_wind[i].value, 'unit': 'N'}
properties['wave_resistance'] = {'value': self.ship_params_per_step.r_waves[i].value, 'unit': 'N'}
properties['shallow_water_resistance'] = {
'value': self.ship_params_per_step.r_shallow[i].value,
'unit': 'N'
}
properties['shallow_water_resistance'] = {'value': self.ship_params_per_step.r_shallow[i].value,
'unit': 'N'}
properties['hull_roughness_resistance'] = {'value': self.ship_params_per_step.r_roughness[i].value,
'unit': 'N'}
properties['wave_height'] = {'value': self.ship_params_per_step.wave_height[i].value, 'unit': 'm'}
properties['wave_direction'] = {'value': self.ship_params_per_step.wave_direction[i].value,
'unit': 'radian'}
properties['wave_period'] = {'value': self.ship_params_per_step.wave_period[i].value, 'unit': 's'}
properties['u_currents'] = {'value': self.ship_params_per_step.u_currents[i].value, 'unit': 'm/s'}
properties['v_currents'] = {'value': self.ship_params_per_step.v_currents[i].value, 'unit': 'm/s'}
properties['u_wind_speed'] = {'value': self.ship_params_per_step.u_wind_speed[i].value, 'unit': 'm/s'}
properties['v_wind_speed'] = {'value': self.ship_params_per_step.v_wind_speed[i].value, 'unit': 'm/s'}
properties['pressure'] = {'value': self.ship_params_per_step.pressure[i].value, 'unit': 'Pa'}
properties['air_temperature'] = {'value': self.ship_params_per_step.air_temperature[i].value,
'unit': '°C'}
properties['salinity'] = {'value': self.ship_params_per_step.salinity[i].value, 'unit': '-'}
properties['water_temperature'] = {'value': self.ship_params_per_step.water_temperature[i].value,
'unit': '°C'}
properties['status'] = {'value': self.ship_params_per_step.status[i]}

feature['type'] = 'Feature'
Expand Down Expand Up @@ -201,6 +224,17 @@ def from_file(cls, filename):
r_waves = np.full(count, -99.)
r_shallow = np.full(count, -99.)
r_roughness = np.full(count, -99.)
wave_height = np.full(count, -99.)
wave_direction = np.full(count, -99.)
wave_period = np.full(count, -99.)
u_currents = np.full(count, -99.)
v_currents = np.full(count, -99.)
u_wind_speed = np.full(count, -99.)
v_wind_speed = np.full(count, -99.)
pressure = np.full(count, -99.)
air_temperature = np.full(count, -99.)
salinity = np.full(count, -99.)
water_temperature = np.full(count, -99.)
course_per_step = np.full(count - 1, -99.)
status = np.full(count, -99)
fuel_type = np.full(count, "")
Expand All @@ -223,6 +257,17 @@ def from_file(cls, filename):
r_waves[ipoint] = property['wave_resistance']['value']
r_shallow[ipoint] = property['shallow_water_resistance']['value']
r_roughness[ipoint] = property['hull_roughness_resistance']['value']
wave_height[ipoint] = property['wave_height']['value']
wave_direction[ipoint] = property['wave_direction']['value']
wave_period[ipoint] = property['wave_period']['value']
u_currents[ipoint] = property['u_currents']['value']
v_currents[ipoint] = property['v_currents']['value']
u_wind_speed[ipoint] = property['u_wind_speed']['value']
v_wind_speed[ipoint] = property['v_wind_speed']['value']
pressure[ipoint] = property['pressure']['value']
air_temperature[ipoint] = property['air_temperature']['value']
salinity[ipoint] = property['salinity']['value']
water_temperature[ipoint] = property['water_temperature']['value']
status[ipoint] = property['status']['value']

speed = speed[:-1] * u.meter/u.second
Expand All @@ -234,6 +279,17 @@ def from_file(cls, filename):
r_waves = r_waves[:-1] * u.newton
r_shallow = r_shallow[:-1] * u.newton
r_roughness = r_roughness[:-1] * u.newton
wave_height = wave_height[:-1] * u.meter
wave_direction = wave_direction[:-1] * u.radian
wave_period = wave_period[:-1] * u.second
u_currents = u_currents[:-1] * u.meter/u.second
v_currents = v_currents[:-1] * u.meter/u.second
u_wind_speed = u_wind_speed[:-1] * u.meter/u.second
v_wind_speed = v_wind_speed[:-1] * u.meter/u.second
pressure = pressure[:-1] * u.kg/u.meter/u.second**2
air_temperature = air_temperature[:-1] * u.deg_C
salinity = salinity[:-1] * u.dimensionless_unscaled
water_temperature = water_temperature[:-1] * u.deg_C

start = (lats_per_step[0], lons_per_step[0])
finish = (lats_per_step[count - 1], lons_per_step[count - 1])
Expand All @@ -255,6 +311,17 @@ def from_file(cls, filename):
r_waves=r_waves,
r_shallow=r_shallow,
r_roughness=r_roughness,
wave_height=wave_height,
wave_direction=wave_direction,
wave_period=wave_period,
u_currents=u_currents,
v_currents=v_currents,
u_wind_speed=u_wind_speed,
v_wind_speed=v_wind_speed,
pressure=pressure,
air_temperature=air_temperature,
salinity=salinity,
water_temperature=water_temperature,
status=status
)

Expand Down
33 changes: 33 additions & 0 deletions WeatherRoutingTool/ship/ship.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ def get_ship_parameters(self, courses, lats, lons, time, speed=None, unique_coor
r_waves=dummy_array * u.N,
r_shallow=dummy_array * u.N,
r_roughness=dummy_array * u.N,
wave_height=dummy_array * u.meter,
wave_direction=dummy_array * u.radian,
wave_period=dummy_array * u.second,
u_currents=dummy_array * u.meter/u.second,
v_currents=dummy_array * u.meter/u.second,
u_wind_speed=dummy_array * u.meter/u.second,
v_wind_speed=dummy_array * u.meter/u.second,
pressure=dummy_array * u.kg/u.meter/u.second**2,
air_temperature=dummy_array * u.deg_C,
salinity=dummy_array * u.dimensionless_unscaled,
water_temperature=dummy_array * u.deg_C,
status=dummy_array
)

Expand Down Expand Up @@ -402,6 +413,17 @@ def extract_params_from_netCDF(self, ds):
r_waves = ds['Wave_resistance'].to_numpy().flatten() * u.newton
r_shallow = ds['Shallow_water_resistance'].to_numpy().flatten() * u.newton
r_roughness = ds['Hull_roughness_resistance'].to_numpy().flatten() * u.newton
wave_height = ds['VHM0'].to_numpy().flatten() * u.meter
wave_direction = ds['VMDR'].to_numpy().flatten() * u.radian
wave_period = ds['VTPK'].to_numpy().flatten() * u.second
u_currents = ds['utotal'].to_numpy().flatten() * u.meter/u.second
v_currents = ds['vtotal'].to_numpy().flatten() * u.meter/u.second
u_wind_speed = ds['u-component_of_wind_height_above_ground'].to_numpy().flatten() * u.meter/u.second
v_wind_speed = ds['v-component_of_wind_height_above_ground'].to_numpy().flatten() * u.meter/u.second
pressure = ds['Pressure_reduced_to_MSL_msl'].to_numpy().flatten() * u.kg/u.meter/u.second**2
air_temperature = ds['Temperature_surface'].to_numpy().flatten() * u.deg_C
salinity = ds['so'].to_numpy().flatten() * u.dimensionless_unscaled
water_temperature = ds['thetao'].to_numpy().flatten() * u.deg_C
status = ds['Status'].to_numpy().flatten()
speed = np.repeat(self.speed, power.shape)

Expand All @@ -415,6 +437,17 @@ def extract_params_from_netCDF(self, ds):
r_waves=r_waves,
r_shallow=r_shallow,
r_roughness=r_roughness,
wave_height=wave_height,
wave_direction=wave_direction,
wave_period=wave_period,
u_currents=u_currents,
v_currents=v_currents,
u_wind_speed=u_wind_speed,
v_wind_speed=v_wind_speed,
pressure=pressure,
air_temperature=air_temperature,
salinity=salinity,
water_temperature=water_temperature,
status=status
)

Expand Down
Loading

0 comments on commit 7fde391

Please sign in to comment.