Request Roll damping API
I implemented a REST API for one of the methods to predict ship roll damping during my PHD project. Here is a brief explanation of how this API can be used.
More detailed information about this API can also be found here.
And if you want to know more about what a roll decay test and roll damping is you can have a look at:
#collapse
import requests
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#plt.style.use('dark_background')
from collections import OrderedDict
from rolldecayestimators.polynom_estimator import Polynom
#collapse
file_path = 'polynom_complex.sym'
polynom = Polynom.load(file_path=file_path)
polynom.equation
#collapse
url = r'http://marale.pythonanywhere.com/api/roll_damping'
request = url + r'?lpp=100&beam=10&T=2&BK_L=0&BK_B=0&OG=0&omega0_hat=0.1&C_b=0.7&A_0=0.97&V=10&phi_a=0.1'
r = requests.get(request)
assert r.status_code is 200
result = r.json()
result
result['B_e_hat']
#collapse
def get_rolldamping(row):
r = requests.get(url, params=dict(row))
assert r.status_code is 200
result = r.json()
result_ = pd.Series(result, name=row.name)
return result_
#collapse
N=10
index = np.arange(0,N)
inputs = pd.DataFrame(index=index)
inputs['lpp']=100
inputs['beam']=10
inputs['T']=2
inputs['BK_L']=0
inputs['BK_B']=0
inputs['OG']=0
inputs['omega0_hat']=0.5
inputs['C_b']=0.8
inputs['A_0']=0.96
inputs['V']=np.linspace(0,10,N)
inputs['phi_a']=np.deg2rad(3)
result = inputs.apply(func=get_rolldamping, axis=1)
result.head()
fig,ax=plt.subplots()
result.plot(x='V',y='B_e_hat', ax=ax)
inputs2 = inputs.copy()
inputs2['V']=5
inputs2['phi_a']=np.deg2rad(np.linspace(0,10,N))
result2 = inputs2.apply(func=get_rolldamping, axis=1)
fig,ax=plt.subplots()
result2.plot(x='phi_a',y='B_e_hat', ax=ax);
#collapse
def get_rolldampings(inputs):
input_list = [record for record in inputs.to_dict('records')]
response = requests.post(url=url,
json=input_list)
outputs = response.json()
outputs
result = pd.DataFrame(outputs)
return result
result3 = get_rolldampings(inputs=inputs)
fig,ax=plt.subplots()
result3.plot(x='V',y='B_e_hat', ax=ax);
X=polynom.X
X.head()
#collapse
input_ranges = OrderedDict()
input_parameters=[
'beam', 'T', 'BK_L', 'BK_B', 'OG', 'omega0_hat', 'C_b', 'A_0', 'V', 'phi_a'
]
for input_parameter in input_parameters:
x=X[input_parameter]
input_ranges[input_parameter]=(x.min(),x.max())
mean_ship = pd.Series()
for parameter, limits in input_ranges.items():
mean_ship[parameter]=np.mean(limits)
mean_ship['lpp']=1
N=10
df_results=pd.DataFrame()
axes = []
for parameter, limits in input_ranges.items():
repeats = np.tile(mean_ship, (N,1))
df = pd.DataFrame(repeats, columns=mean_ship.index)
df[parameter] = np.linspace(limits[0],limits[1],N)
result4 = get_rolldampings(inputs=df)
df_results=df_results.append(result4, ignore_index=True)
fig,ax=plt.subplots()
axes.append(ax)
result4.plot(x=parameter, y='B_e_hat', ax=ax)
for ax in axes:
ax.set_ylim(df_results['B_e_hat'].min(), df_results['B_e_hat'].max())