In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [2]:
meetbrief = pd.read_excel('cephei_II_polar_2018.xlsx',sheet_name='Calculations')
In [3]:
meetbrief
Out[3]:
WindVelocity 6 8 10 12 14 16 20
0 BeatAngles 42.6 41.100000 40.600000 39.600000 39.000000 38.800000 38.700000
1 BeatVMG 3.61 4.370000 4.960000 5.300000 5.440000 5.490000 5.620000
2 BeatSpeed 4.90424 5.799114 6.532579 6.878532 6.999972 7.044441 7.201155
3 aws 10.1672 12.944100 15.552318 17.846966 19.932878 21.938645 26.012624
4 awa 23.5436 23.971717 24.736260 25.378312 26.232051 27.192812 28.732599
5 52 5.48 6.540000 7.290000 7.620000 7.740000 7.800000 7.890000
6 60 5.77 6.860000 7.510000 7.820000 7.960000 8.030000 8.090000
7 75 6.01 7.090000 7.680000 7.990000 8.210000 8.370000 8.510000
8 90 6.01 7.240000 7.820000 8.010000 8.290000 8.560000 9.000000
9 110 6.06 7.330000 7.950000 8.340000 8.640000 8.870000 9.280000
10 120 5.89 7.150000 7.850000 8.280000 8.710000 9.150000 9.700000
11 135 5.3 6.520000 7.480000 7.990000 8.400000 8.860000 9.910000
12 150 4.46 5.580000 6.630000 7.480000 7.960000 8.340000 9.210000
13 aws 3.76069 4.333877 5.472570 6.253688 7.049482 8.280000 11.520000
14 awa 85.9836 105.314280 110.216846 126.107576 152.597247 180.000000 180.000000
15 RunSpeed 4.94599 5.676486 6.689471 7.199210 7.360380 7.720000 8.480000
16 RunVMG 3.86 4.840000 5.740000 6.530000 7.160000 7.720000 8.480000
17 GybeAngles 141.3 148.500000 149.100000 155.100000 166.600000 180.000000 180.000000
18 NaN NaN NaN NaN NaN NaN NaN NaN
19 year ORC 2018 NaN NaN NaN NaN NaN NaN
In [4]:
df = pd.read_excel('cephei_II_polar_2018.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.7 NaN NaN NaN NaN NaN NaN NaN 7.201155
1 38.8 NaN NaN NaN NaN NaN NaN 7.044441 NaN
2 39.0 NaN NaN NaN NaN NaN 6.999972 NaN NaN
3 39.6 NaN NaN NaN NaN 6.878532 NaN NaN NaN
4 40.6 NaN NaN NaN 6.532579 NaN NaN NaN NaN
5 41.1 NaN NaN 5.799114 NaN NaN NaN NaN NaN
6 42.6 NaN 4.904244 NaN NaN NaN NaN NaN NaN
7 52.0 NaN 5.480000 6.540000 7.290000 7.620000 7.740000 7.800000 7.890000
8 60.0 NaN 5.770000 6.860000 7.510000 7.820000 7.960000 8.030000 8.090000
9 75.0 NaN 6.010000 7.090000 7.680000 7.990000 8.210000 8.370000 8.510000
10 90.0 NaN 6.010000 7.240000 7.820000 8.010000 8.290000 8.560000 9.000000
11 110.0 NaN 6.060000 7.330000 7.950000 8.340000 8.640000 8.870000 9.280000
12 120.0 NaN 5.890000 7.150000 7.850000 8.280000 8.710000 9.150000 9.700000
13 135.0 NaN 5.300000 6.520000 7.480000 7.990000 8.400000 8.860000 9.910000
14 150.0 NaN 4.460000 5.580000 6.630000 7.480000 7.960000 8.340000 9.210000
15 141.3 NaN 4.945989 NaN NaN NaN NaN NaN NaN
16 148.5 NaN NaN 5.676486 NaN NaN NaN NaN NaN
17 149.1 NaN NaN NaN 6.689471 NaN NaN NaN NaN
18 155.1 NaN NaN NaN NaN 7.199210 NaN NaN NaN
19 166.6 NaN NaN NaN NaN NaN 7.360380 NaN NaN
20 180.0 NaN NaN NaN NaN NaN NaN 7.720000 NaN
21 180.0 NaN NaN NaN NaN NaN NaN NaN 8.480000
22 NaN NaN NaN NaN NaN NaN NaN NaN NaN
23 35.0 NaN 4.000000 4.800000 5.600000 6.200000 6.500000 6.600000 6.800000
24 180.0 NaN 3.000000 4.300000 5.100000 6.200000 7.000000 NaN NaN
25 160.0 NaN 3.900000 NaN 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[:-2]
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 42.6 4.904244
7 52.0 5.480000
8 60.0 5.770000
9 75.0 6.010000
10 90.0 6.010000
11 110.0 6.060000
12 120.0 5.890000
13 135.0 5.300000
15 141.3 4.945989
14 150.0 4.460000
25 160.0 3.900000
24 180.0 3.000000
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("Cephei II 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]:
angles_x = {}
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
    angles_x.update({knot:angle_x})
    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("Cephei II Polar", va="bottom")
ax.set_theta_zero_location('N', offset=0)
ax.set_rlabel_position(-11.25) 
ax.grid(True)
ax.set_rmin(0)
ax.set_rmax(10)
plt.show()
In [15]:
step = 5
angles_csv = {}
speeds_csv = {}
csv = []
for knot in knots:
    angle_csv = []
    speed_csv = []
    for i in range(0,20,step):
        angle_csv.append(i)
        speed_csv.append(0.0)
    angle_x, speed_x = angles_x[knot], speeds_x[knot]    
    for i , angle in enumerate(angle_x):
        if angle % step == 0:
            angle_csv.append(int(round(angle_x[i],0)))
            speed_csv.append(int(round(100 * abs(speed_x[i])))/100)
    if knot == knots[0]:
        tpl = ('TWA/TWS',angle_csv)
        csv.append(tpl)
        zerolist = [0] * len(angle_csv)
        tpl = (str(0), zerolist)
        csv.append(tpl)
    tpl = (str(knot),speed_csv)    
    csv.append(tpl)
In [16]:
csvdf = pd.DataFrame.from_items(csv)
In [17]:
csvdf
Out[17]:
TWA/TWS 0 6 8 10 12 14 16 20
0 0 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
1 5 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
2 10 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
3 15 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
4 20 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
5 25 0 1.72 1.89 2.46 2.97 3.33 3.47 3.23
6 30 0 3.04 3.53 4.29 4.96 5.37 5.52 5.50
7 35 0 4.00 4.80 5.60 6.20 6.50 6.60 6.80
8 40 0 4.66 5.66 6.46 6.92 7.09 7.15 7.30
9 45 0 5.09 6.17 6.95 7.33 7.45 7.50 7.61
10 50 0 5.39 6.45 7.22 7.56 7.67 7.73 7.82
11 55 0 5.60 6.67 7.39 7.70 7.83 7.89 7.97
12 60 0 5.77 6.86 7.51 7.82 7.96 8.03 8.09
13 65 0 5.89 6.99 7.59 7.91 8.07 8.16 8.22
14 70 0 5.97 7.05 7.64 7.96 8.15 8.27 8.35
15 75 0 6.01 7.09 7.68 7.99 8.21 8.37 8.51
16 80 0 6.02 7.13 7.72 7.99 8.24 8.45 8.68
17 85 0 6.01 7.18 7.77 7.98 8.26 8.51 8.86
18 90 0 6.01 7.24 7.82 8.01 8.29 8.56 9.00
19 95 0 6.03 7.30 7.87 8.09 8.36 8.61 9.08
20 100 0 6.06 7.34 7.92 8.19 8.45 8.66 9.11
21 105 0 6.08 7.35 7.95 8.28 8.55 8.74 9.16
22 110 0 6.06 7.33 7.95 8.34 8.64 8.87 9.28
23 115 0 6.00 7.26 7.91 8.33 8.70 9.03 9.48
24 120 0 5.89 7.15 7.85 8.28 8.71 9.15 9.70
25 125 0 5.74 6.99 7.77 8.20 8.65 9.14 9.86
26 130 0 5.54 6.78 7.65 8.10 8.54 9.03 9.94
27 135 0 5.30 6.52 7.48 7.99 8.40 8.86 9.91
28 140 0 5.02 6.22 7.24 7.86 8.26 8.68 9.74
29 145 0 4.74 5.90 6.95 7.69 8.12 8.51 9.47
30 150 0 4.46 5.58 6.63 7.48 7.96 8.34 9.21
31 155 0 4.19 5.27 6.30 7.21 7.78 8.18 8.99
32 160 0 3.90 4.99 5.97 6.90 7.60 8.04 8.81
33 165 0 3.59 4.74 5.67 6.61 7.42 7.92 8.67
34 170 0 3.29 4.55 5.41 6.37 7.25 7.82 8.57
35 175 0 3.05 4.40 5.21 6.22 7.10 7.75 8.50
36 180 0 3.00 4.30 5.10 6.20 7.00 7.72 8.48
In [18]:
csvdf.to_csv('cephei_II_polar.csv', index=False)