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_2017.xlsx',sheet_name='Calculations')
In [3]:
meetbrief
Out[3]:
WindVelocity 6 8 10 12 14 16 20
0 BeatAngles 44.4 43.900000 43.900000 42.300000 41.000000 40.000000 38.900000
1 BeatVMG 3.82 4.510000 5.050000 5.410000 5.630000 5.780000 5.940000
2 BeatSpeed 5.3466 6.259098 7.008524 7.314457 7.459823 7.545254 7.632576
3 aws 10.5084 13.241462 15.815164 18.092575 20.230891 22.313468 26.379087
4 awa 23.5462 24.766905 26.004461 26.511616 27.000617 27.446136 28.431435
5 52 5.91 6.970000 7.690000 7.980000 8.140000 8.230000 8.330000
6 60 6.3 7.420000 7.990000 8.240000 8.380000 8.470000 8.570000
7 75 6.69 7.740000 8.210000 8.480000 8.690000 8.820000 8.970000
8 90 6.74 7.800000 8.270000 8.570000 8.830000 9.070000 9.420000
9 110 6.32 7.650000 8.290000 8.640000 8.830000 9.020000 9.370000
10 120 6.17 7.490000 8.200000 8.610000 8.990000 9.270000 9.650000
11 135 5.62 6.830000 7.830000 8.320000 8.700000 9.080000 9.910000
12 150 4.77 5.880000 6.920000 7.790000 8.290000 8.640000 9.380000
13 aws 3.69945 4.186826 5.359992 6.108966 6.885215 7.960000 11.230000
14 awa 82.6633 103.430188 107.729120 122.587665 146.147768 180.000000 180.000000
15 RunSpeed 5.21976 5.913502 6.966313 7.549799 7.746366 8.040000 8.770000
16 RunVMG 4.13 5.090000 5.990000 6.820000 7.450000 8.040000 8.770000
17 GybeAngles 142.3 149.400000 149.300000 154.600000 164.100000 180.000000 180.000000
18 NaN NaN NaN NaN NaN NaN NaN NaN
19 year ORC 2017 NaN NaN NaN NaN NaN NaN
In [4]:
df = pd.read_excel('/Users/nosinga/workspaces/encountersailing/crewmanual/docs/070_navigation/encounter_polar_2017.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 38.9 NaN NaN NaN NaN NaN NaN NaN 7.632576
1 40.0 NaN NaN NaN NaN NaN NaN 7.545254 NaN
2 41.0 NaN NaN NaN NaN NaN 7.459823 NaN NaN
3 42.3 NaN NaN NaN NaN 7.314457 NaN NaN NaN
4 43.9 NaN NaN NaN 7.008524 NaN NaN NaN NaN
5 43.9 NaN NaN 6.259098 NaN NaN NaN NaN NaN
6 44.4 NaN 5.346601 NaN NaN NaN NaN NaN NaN
7 52.0 NaN 5.910000 6.970000 7.690000 7.980000 8.140000 8.230000 8.330000
8 60.0 NaN 6.300000 7.420000 7.990000 8.240000 8.380000 8.470000 8.570000
9 75.0 NaN 6.690000 7.740000 8.210000 8.480000 8.690000 8.820000 8.970000
10 90.0 NaN 6.740000 7.800000 8.270000 8.570000 8.830000 9.070000 9.420000
11 110.0 NaN 6.320000 7.650000 8.290000 8.640000 8.830000 9.020000 9.370000
12 120.0 NaN 6.170000 7.490000 8.200000 8.610000 8.990000 9.270000 9.650000
13 135.0 NaN 5.620000 6.830000 7.830000 8.320000 8.700000 9.080000 9.910000
14 150.0 NaN 4.770000 5.880000 6.920000 7.790000 8.290000 8.640000 9.380000
15 142.3 NaN 5.219764 NaN NaN NaN NaN NaN NaN
16 149.4 NaN NaN 5.913502 NaN NaN NaN NaN NaN
17 149.3 NaN NaN NaN 6.966313 NaN NaN NaN NaN
18 154.6 NaN NaN NaN NaN 7.549799 NaN NaN NaN
19 164.1 NaN NaN NaN NaN NaN 7.746366 NaN NaN
20 180.0 NaN NaN NaN NaN NaN NaN 8.040000 NaN
21 180.0 NaN NaN NaN NaN NaN NaN NaN 8.770000
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.4 5.346601
7 52.0 5.910000
8 60.0 6.300000
9 75.0 6.690000
10 90.0 6.740000
11 110.0 6.320000
12 120.0 6.170000
13 135.0 5.620000
15 142.3 5.219764
14 150.0 4.770000
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()