Setting an ellipse through orbital data

I created a bunch of data for the coordinates (x, y, z) of the planet when it revolves around the Sun. Now I want to put an ellipse through this data.

What I tried to do:

I created a fictitious ellipse based on five parameters: a semi-basic axis and an eccentricity, which determines the size and shape, and three angles of Eulers that rotate around the ellipse. Since my data is not always concentrated at the origin, I also need to translate an ellipse that requires three additional variables (dx, dy, dz). As soon as I initialize this function with these eight variables, I return N the number of points that lie on this ellipse. (N = number of data points through which I draw an ellipse) I calculate the deviation of these dummy points from the actual data, and then minimize this deviation using some minimization method to find the best suitable values ​​for these eight variables.

My problem is the very last part: minimizing deviation and finding variable values.

To minimize deviation, I use scipy.optimize.minimize to try to approximate the best suitable variables, but it just doesn't do a good enough job:

Here is an imageHere is an image from which one of my best fit looks and that with a very generous accurate initial guess. (blue = data, red = suitable)

Here is the whole code. (No data, it generates its own fake data)

In short , I use this scipy function:

initial_guess = [0.3,0.2,0.1,0.7,3,0.0,-0.1,0.0]
bnds = ((0.2, 0.5), (0.1, 0.3), (0, 2*np.pi), (0, 2*np.pi), (0, 2*np.pi), (-0.5,0.5), (-0.5,0.5), (-0.3,0.3)) #reasonable bounds for the variables
result = optimize.minimize(deviation, initial_guess, args=(data,), method='L-BFGS-B', bounds=bnds, tol=1e-8) #perform minimalisation
semi_major,eccentricity,inclination,periapsis,longitude,dx,dy,dz = result["x"]

To minimize this feature (or deviation):

    def deviation(variables, data):
    """
    This function calculates the cumulative seperation between the ellipse fit points and data points and returns it
    """
    num_pts = len(data[:,0])
    semi_major,eccentricity,inclination,periapsis,longitude,dx,dy,dz = variables
    dummy_ellipse = generate_ellipse(num_pts,semi_major,eccentricity,inclination,periapsis,longitude,dz,dy,dz)
    deviations = np.zeros(len(data[:,0]))
    pair_deviations = np.zeros(len(data[:,0]))
    # Calculate separation between each pair of points
    for j in range(len(data[:,0])):
        for i in range(len(data[:,0])):
            pair_deviations[i] = np.sqrt((data[j,0]-dummy_ellipse[i,0])**2 + (data[j,1]-dummy_ellipse[i,1])**2 + (data[j,2]-dummy_ellipse[i,2])**2)
            deviations[j] = min(pair_deviations) # only pick the closest point to the data point j.
    total_deviation = sum(deviations)
    return total_deviation

(My code may be a little dirty and inefficient, I'm new to this)

, , scipy.minimize.optimize. , . -, . , .

+4
1

-, , :

dummy_ellipse = generate_ellipse(...,dz,dy,dz)

dummy_ellipse = generate_ellipse(...,dx,dy,dz)

, sqrt .

- min(), BFGS, .

, : 3d

f1(x,y,z,p) = 0
f2(x,y,z,p) = 0

p - . , ,

F(p) = sum_{j=1}^N [f1(x_j,y_j,z_j,p)**2 + f2(x_j,y_j,z_j,p)**2]

.

, optimize.leastsq, .

+1

All Articles