I have an alternative approach to this problem using scipy
to interpolate onto a closed curve. First, I converted your data from (deg, ssi) to psuedo cartesian coordinates (x,y) assuming deg
is the polar angle and ssi
is the (negative) of the radial distance. Then you can use the method defined here to interpolate a closed curve onto a set of (x,y) points.
import numpy as np
import pandas
import matplotlib.pyplot as plt
from scipy import interpolate
dic = {'deg': [4.0, 59.0, 162.0, 267.0, 319.0],
'ssi': [-69, -73, -73, -61, -75]}
f44 = pandas.DataFrame(data=dic)
'''
Now, lets do the following. Convert your data from (deg, ssi) to (x,y)
where x = ssi* cosd(deg), y=ssi*sind(deg). Now we need to interpolate a closed
curve onto these set of cartesian points.
'''
f44['x'] = -f44['ssi']*np.cos( np.deg2rad(f44['deg']))
f44['y'] = -f44['ssi']*np.sin( np.deg2rad(f44['deg']))
x = f44.as_matrix(columns=[f44.columns[2]])[:,0]
y = f44.as_matrix(columns=[f44.columns[3]])[:,0]
x = np.r_[x, x[0]]
y = np.r_[y, y[0]]
tck, u = interpolate.splprep([x, y], s=0, per=True)
xi, yi = interpolate.splev(np.linspace(0, 1, 1000), tck)
# Save interpolated data to new dataframe.
f44i = pandas.DataFrame(data = {'x':xi, 'y':yi})
f44i['deg'] = np.rad2deg( np.arctan2(f44i['y'],f44i['x']))
f44i['ssi'] =-np.sqrt( f44i['x']**2 + f44i['y']**2)
for i,l in enumerate(f44i['deg']):
if l < 0:
f44i['deg'][i] = 360 + f44i['deg'][i]
fig, ax = plt.subplots(1, 1)
ax.plot(f44i['deg'], f44i['ssi'], '.', markersize=0.5)
ax.plot(f44['deg'], f44['ssi'], '.', color='red')
plt.show()
Now we get a curve that looks like the one below. (re-converted from the psuedo cartesian coordinates to your preferred (deg, ssi) coordinates). Also, I have created a new dataframe to replace the f44i
you created. You can make this code more suitable for your specific application.
