In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [2]:
meetbrief = pd.read_excel('/Users/nosinga/workspaces/encountersailing/crewmanual/docs/070_navigation/encounter_polar_2016.xlsx',sheet_name='Calculations')
In [3]:
meetbrief
Out[3]:
WindVelocity 6 8 10 12 14 16 20
0 BeatAngles 44.8 44.000000 44.000000 42.600000 41.100000 39.900000 39.000000
1 BeatVMG 3.76 4.450000 4.990000 5.370000 5.600000 5.770000 5.900000
2 BeatSpeed 5.29898 6.186228 6.936916 7.295233 7.431359 7.521197 7.591881
3 aws 10.4498 13.170779 15.745501 18.058251 20.199631 22.298170 26.336983
4 awa 23.8649 24.957073 26.179127 26.730534 27.104507 27.404576 28.548247
5 52 5.84 6.890000 7.630000 7.950000 8.110000 8.210000 8.320000
6 60 6.23 7.350000 7.940000 8.210000 8.350000 8.450000 8.560000
7 75 6.61 7.680000 8.160000 8.440000 8.650000 8.790000 8.950000
8 90 6.65 7.730000 8.220000 8.520000 8.770000 9.000000 9.370000
9 110 6.1 7.390000 8.160000 8.550000 8.780000 8.970000 9.320000
10 120 5.95 7.240000 8.070000 8.510000 8.880000 9.200000 9.600000
11 135 5.4 6.640000 7.700000 8.250000 8.620000 8.980000 9.790000
12 150 4.59 5.730000 6.770000 7.680000 8.210000 8.560000 9.260000
13 aws 3.65238 4.216363 5.514237 6.243546 7.088598 8.070000 11.330000
14 awa 86.1775 105.637150 106.601262 121.616498 141.673939 180.000000 180.000000
15 RunSpeed 5.00998 5.756537 6.914247 7.484776 7.730991 7.930000 8.670000
16 RunVMG 3.98 4.960000 5.870000 6.710000 7.340000 7.930000 8.670000
17 GybeAngles 142.6 149.500000 148.100000 153.700000 161.700000 180.000000 180.000000
18 NaN NaN NaN NaN NaN NaN NaN NaN
19 year ORC 2016 NaN NaN NaN NaN NaN NaN
In [4]:
df = pd.read_excel('/Users/nosinga/workspaces/encountersailing/crewmanual/docs/070_navigation/encounter_polar_2016.xlsx',sheet_name='pandas_polar')
In [5]:
df
Out[5]:
TWA TWS 6 kn 8 kn 10 kn 12 kn 14 kn 16 kn 20 kn
0 39.0 NaN NaN NaN NaN NaN NaN NaN 7.591881
1 39.9 NaN NaN NaN NaN NaN NaN 7.521197 NaN
2 41.1 NaN NaN NaN NaN NaN 7.431359 NaN NaN
3 42.6 NaN NaN NaN NaN 7.295233 NaN NaN NaN
4 44.0 NaN NaN NaN 6.936916 NaN NaN NaN NaN
5 44.0 NaN NaN 6.186228 NaN NaN NaN NaN NaN
6 44.8 NaN 5.298978 NaN NaN NaN NaN NaN NaN
7 52.0 NaN 5.840000 6.890000 7.630000 7.950000 8.110000 8.210000 8.320000
8 60.0 NaN 6.230000 7.350000 7.940000 8.210000 8.350000 8.450000 8.560000
9 75.0 NaN 6.610000 7.680000 8.160000 8.440000 8.650000 8.790000 8.950000
10 90.0 NaN 6.650000 7.730000 8.220000 8.520000 8.770000 9.000000 9.370000
11 110.0 NaN 6.100000 7.390000 8.160000 8.550000 8.780000 8.970000 9.320000
12 120.0 NaN 5.950000 7.240000 8.070000 8.510000 8.880000 9.200000 9.600000
13 135.0 NaN 5.400000 6.640000 7.700000 8.250000 8.620000 8.980000 9.790000
14 150.0 NaN 4.590000 5.730000 6.770000 7.680000 8.210000 8.560000 9.260000
15 142.6 NaN 5.009978 NaN NaN NaN NaN NaN NaN
16 149.5 NaN NaN 5.756537 NaN NaN NaN NaN NaN
17 148.1 NaN NaN NaN 6.914247 NaN NaN NaN NaN
18 153.7 NaN NaN NaN NaN 7.484776 NaN NaN NaN
19 161.7 NaN NaN NaN NaN NaN 7.730991 NaN NaN
20 180.0 NaN NaN NaN NaN NaN NaN 7.930000 NaN
21 180.0 NaN NaN NaN NaN NaN NaN NaN 8.670000
22 NaN NaN NaN NaN NaN NaN NaN NaN NaN
23 35.0 NaN 4.000000 4.800000 5.600000 6.200000 6.600000 6.900000 7.100000
24 180.0 NaN 2.800000 3.900000 5.100000 6.200000 7.000000 NaN NaN
25 170.0 NaN NaN 4.350000 NaN NaN NaN NaN NaN
26 20.0 NaN 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
In [6]:
#df = df[:-4]
knots = [6,8,10,12,14,16,20]
In [7]:
def clean_kn_set(df, knot):
    columns_index = range(1,9)
    for index, item in enumerate(knots):
        if item == knot:
            column = columns_index[index + 1]
    result = df.iloc[:,[0,column]]
    result = result.dropna()
    result = result.sort_values('TWA')
    result['speed'] = result.iloc[:,1]
    result.drop(result.columns[[1]],axis=1,inplace=True)
    return result
In [8]:
clean_kn_set(df,6)
Out[8]:
TWA speed
26 20.0 0.000000
23 35.0 4.000000
6 44.8 5.298978
7 52.0 5.840000
8 60.0 6.230000
9 75.0 6.610000
10 90.0 6.650000
11 110.0 6.100000
12 120.0 5.950000
13 135.0 5.400000
15 142.6 5.009978
14 150.0 4.590000
24 180.0 2.800000
In [9]:
import matplotlib as mpl
mpl.rcParams['figure.figsize'] = (15,15)
In [10]:
import numpy as np
import matplotlib.pyplot as plt

ax = plt.subplot(111, projection='polar')
angles = {}
thetas = {}
speeds = {}
for knot in knots:
    angle = clean_kn_set(df, knot)['TWA']
    theta, speed = np.radians( clean_kn_set(df, knot)['TWA']),  clean_kn_set(df, knot)['speed'] 
    ax.plot(theta, speed)    
    # voor het volgende programma
    angles.update({knot:angle})
    thetas.update({knot:theta})
    speeds.update({knot:speed})
ax.set_title("Encounter Polar", va="bottom")
ax.set_theta_zero_location('N', offset=0)
ax.set_rlabel_position(-22.5)  # get radial labels away from plotted line
ax.grid(True)
ax.set_rmax(10)
plt.show()
In [11]:
for knot in knots:
    angle = angles[knot]
    speed = speeds[knot]
    plt.plot(angle, speed)
plt.show()
In [12]:
import scipy.interpolate as interpolate
In [13]:
thetas_x = {}
speeds_x = {}
for i, knot in enumerate(knots):
    angle, speed = angles[knot], speeds[knot]
    angle = np.array(angle)
    angle = angle.astype('float64')
    speed = np.array(speed)
    speed = speed.astype('float64')
    angle_x = np.linspace(angle.min(),angle.max(),(10 * (angle.max() - angle.min())).astype('int') + 1)
    theta_x = np.radians(angle_x)
    k_factor = [5,4,3,3,3,3,2]
    print('knot = ' + str(knot) + ' : k = ' + str(k_factor[i]) )
    t, c, k = interpolate.splrep(angle, speed, s=0, k=k_factor[i])
    spline = interpolate.BSpline(t, c, k, extrapolate=False)
    speed_x = spline(angle_x)
    plt.plot(angle_x, speed_x)
    plt.plot(angle, speed, 'bo')
    #plt.plot(angle, speed)
    # voor het volgende programma
    thetas_x.update({knot:theta_x})
    speeds_x.update({knot:speed_x})
plt.show()
knot = 6 : k = 5
knot = 8 : k = 4
knot = 10 : k = 3
knot = 12 : k = 3
knot = 14 : k = 3
knot = 16 : k = 3
knot = 20 : k = 2
In [14]:
import numpy as np
import matplotlib.pyplot as plt

ax = plt.subplot(111, projection='polar')
for knot in knots:
    theta_x , speed_x = thetas_x[knot], speeds_x[knot]
    theta_x2 = []
    for x in theta_x:
        theta_x2.append(2*np.pi - x)
    theta_x2 = theta_x2[::-1]
    theta_x360 = np.append(theta_x, theta_x2)
    speed_x2 = speed_x[::-1]
    speed_x360 = np.append(speed_x, speed_x2)
    ax.plot(theta_x360, speed_x360)
    theta , speed = thetas[knot], speeds[knot]
    ax.plot(theta, speed, 'bo')
ax.set_title("Encounter Polar", va="bottom")
ax.set_theta_zero_location('N', offset=0)
ax.set_rlabel_position(-11.25) 
ax.grid(True)
ax.set_rmax(10)
plt.show()