{"id":735,"date":"2018-06-11T02:32:03","date_gmt":"2018-06-11T00:32:03","guid":{"rendered":"https:\/\/aerospaceresearch.net\/?p=735"},"modified":"2018-06-11T12:18:13","modified_gmt":"2018-06-11T10:18:13","slug":"least-squares-fit-to-cartesian-positions-as-a-function-of-time","status":"publish","type":"post","link":"https:\/\/aerospaceresearch.net\/?p=735","title":{"rendered":"[GSoC2018|OrbitDeterminator|Jorge] Week #3-4 \u2013 Least squares fit to cartesian positions as a function of time"},"content":{"rendered":"<div>\n<h2>Introduction<\/h2>\n<div>An orbital fit by least-squares is a technique for computing the set of six Keplerian elements which best describe an orbit with respect to a *<strong>whole<\/strong>* set of observations.<\/div>\n<div><\/div>\n<div>As the set of Keplerian elements we choose semimajor axis <em>a<\/em>, eccentricity <em>e<\/em>, time of perigee passage \u03c4\u00a0(i.e., how much time has elapsed since the last perigee), as well as the standard Euler angles which describe the orientation of the orbital plane with respecto to the inertial frame: argument of pericenter \u03c9, inclination <em>I<\/em> and longitude of ascending node \u03a9. We denote by <em>X<\/em> the set of these six Keplerian elements; that is, <em>X<\/em> = (a, e, \u03c4, \u03c9, <em>I<\/em>, \u03a9).<\/div>\n<div><\/div>\n<div>A least-squares fit is simply to look the minimum of a scalar (i.e., real-valued) &#8222;cost&#8220; function <em>Q(X)<\/em>. The <em>Q<\/em> function is simply a measure of how well our theoretical predictions, for a given set <em>X<\/em> of orbital elements, depart from observations. In an ideal world, we could find a set of orbital elements such that it perfectly matched the observations and thus <em>Q(X)=0<\/em>. Nevertheless, real-world measures carry uncertainties, and we can only hope to find orbital elements <em>X<\/em> which make <em>Q<\/em> attain its minimum possible value with respect to all the observations we have made.<\/div>\n<div>The values of the cost function <em>Q(X)<\/em> for a least-squared problem are constructed the following way: take *<strong>all<\/strong>* the values you observed (call them <code>v_i<\/code>), and substract from each of those the values you were expecting to measure for a given set of orbital elements <em>X<\/em> (say, <code>V_i(X)<\/code> ). Call each of these differences the residuals, <code>xi_i(X) = v_i-V_i(X)<\/code> . Then, square the residuals, and sum all the squared residuals. The value you obtain following this recipe, is the value of <em>Q(X)<\/em>.<\/div>\n<div>In practice, the least-squares method finds a local minimum of the cost function by performing an iterative procedure, which needs a good initial &#8222;guess&#8220; solution <code>X0<\/code>; otherwise the procedure may converge to non-feasible results. Hence, it is necessary that the &#8222;good&#8220; initial guess be provided by a preliminary orbit determination method.<\/div>\n<p><!--more--><\/p>\n<div><\/div>\n<h2>Implementation<\/h2>\n<div>We consider the concrete case of having <em>m<\/em> observations of the cartesian coordinates of the position vector <em>(x,y,z)<\/em> referred to the center of attraction (the Earth for artificial satellites, or the Sun for asteroids, etc.) at a given time <em>t<\/em>. That is, for a time <em>t1<\/em> we have <em>(x1,y1,z1)<\/em>; for <em>t2<\/em> we have <em>(x2,y2,z2)<\/em>; etc.<\/div>\n<div>For this particular case, we assumed the motion to be Keplerian and we wrote the function <code>orbel2xyz<\/code>, which takes as arguments the time <code>t<\/code>, the mass parameter <code>mu<\/code> (<code>mu<\/code> =<em>G \u00d7<\/em>\u00a0<em>m<\/em>) of the center of attraction, the semimajor axis <code>a<\/code>, the eccentricity <code>e<\/code>, the time of pericenter passage <code>tau<\/code>, the argument of pericenter <code>omega<\/code>, the inclination <code>I<\/code> and the longitude of ascending node <code>Omega<\/code>. The output of <code>orbel2xyz<\/code> is the expected value at time <code>t<\/code> of the cartesian positions <code>x<\/code>, <code>y<\/code>, <code>z<\/code>, for a given set of orbital elements. The cartesian position vector is returned as a 1-dim <code>numpy.array<\/code> of length <code>3<\/code>. Is is constructed by first computing, from the time, the corresponding true anomaly by inverting the Kepler equation <em>n(t-\u03c4)=E-e\u00a0\u00b7 sin(E)<\/em> using a modified version of Newton&#8217;s method, as described by Murray and Dermott in their book &#8222;Solar System Dynamics&#8220;; our implementation is focused on both accuracy and speed and is able to invert Kepler&#8217;s equation in 5 iterations to almost machine accuracy, even for high eccentricities (for details, see `time2truean` and related functions). Then, as a second step, we compute the position of the observed object in its orbital frame using standard formulae (this was done in function <code>xyz_orbplane_<\/code>). Finally, using the Euler angles <code>omega<\/code> , <code>I<\/code>\u00a0and <code>Omega<\/code>, we rotate from the orbital frame to the inertial frame using the <code>orbplane2frame_<\/code> function. This allows us to compute our predicted values for the observations, which were denoted by <code>V_i(X)<\/code>\u00a0in the previous section.<\/div>\n<div>The next step is to retrieve the observed values <code>v_i<\/code> \u00a0from a data file. We do this using the <code>numpy.loadtxt<\/code>\u00a0function.<\/div>\n<div>The vector of residuals <code>xi_i<\/code> \u00a0is computed via the <code>res_vec<\/code> \u00a0function, which takes as input the set of orbital elements <code>x<\/code>\u00a0as well as a 2-dim <code>numpy.array<\/code> \u00a0called <code>my_data<\/code> , as well as the mass parameter of the Earth in appropriate units, <code>my_mu_Earth<\/code> . Note that if the lengths are, for example, in meters and the times in seconds, then the Earth&#8217;s mass parameter has to be given in meters\u00b3\/seconds\u00b2.<\/div>\n<div>Next, the cost function <em>Q<\/em> is automatically optimized using the <code>scipy.optimize.least_squares<\/code> \u00a0function, taking as input the <code>res_vec<\/code> \u00a0function, an initial guess for the orbital elements <code>x0<\/code> , the complementary arguments for the <code>res_vec<\/code> \u00a0function which in this particular case are the input data <code>data<\/code> \u00a0and the mass parameter of Earth <code>mu_Earth<\/code> . First I thought of using the <code>scipy.optimize.minimize<\/code> \u00a0function; but SciPy&#8217;s <code>least_squares<\/code> \u00a0function was chosen because of its access to the Levenberg-Marquardt algorithm, which is quite robust for this kind of problems. The method for nonlinear least squares fitting was the Levenberg-Marquardt algorithm. The output of the <code>least_squares<\/code> \u00a0function is a data structure labeled as <code>Q_ls<\/code>, which among other things, provides the solution to the least-squares problem for the given observational data and associated parameters.<\/div>\n<h2>Results<\/h2>\n<div>Some results are presented using the <code>determine_kep<\/code> \u00a0method from <code>ellipse_fit<\/code> . For the example file <code>orbit.csv<\/code> , we see an improvement of more than 25% with respect to the initial orbit. Even though the orbital elements are corrected by relatively small quantities, it is sufficient to get a 25% better solution for the orbital elements, in the sense that the cost function attains a lower value with respect to the initial set of elements.<\/div>\n<\/div>\n<p><!--more--><\/p>\n<p><!--more--><\/p>\n<div><\/div>\n<div>\n<figure id=\"attachment_736\" aria-describedby=\"caption-attachment-736\" style=\"width: 2704px\" class=\"wp-caption alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-736 size-full\" src=\"https:\/\/aerospaceresearch.net\/wp-content\/uploads\/2018\/06\/Screen-Shot-2018-06-08-at-16.15.25.png\" alt=\"\" width=\"2704\" height=\"1324\" \/><figcaption id=\"caption-attachment-736\" class=\"wp-caption-text\">Least-squares fitting of (t,x,y,z) observations.<\/figcaption><\/figure>\n<\/div>\n<div><\/div>\n<div>\n<h2>Discussion and future work<\/h2>\n<div>Using well established tools, an implementation of a least-squares orbital determinator for the case of <em>t,x,y,z<\/em> data was implemented. In preliminary tests, we see improvements of around 25% with respect to existing methods. Although execution times are around a couple of seconds, the obtained improvement helps increase the accuracy of the fitted orbital elements, which is essential to orbit propagation.<\/div>\n<div>Furthermore, although the particular scenario of having observed values of <em>t,x,y,z<\/em> might not be of general use, the tools developed here will help attain least-squares orbit determinators for objects which are observed with optical instruments (telescopes) and range\/range-rate radar astrometry. Indeed, using the code what has been done in this work, it will be feasible to construct an orbit fitter which will handle optical observations. To achieve this, the immediate solutions which must be provided to handle, for example, the optical observations case are the following:<\/div>\n<\/div>\n<div><\/div>\n<ul>\n<li>Conversion from topocentric right ascension\/declination to geocentric equatorial celestial coordinates.<\/li>\n<li>Computation of atmospheric aberration to optical observations.<\/li>\n<li>Correction for light-time travel.<\/li>\n<li>Allow for non-homogeneous weighting of observations in least-squares (i.e., insert weights in residuals-computing function).<\/li>\n<li>A preliminary orbit determinator for optical observations which will seed the least-squares fitter (e.g., Gauss&#8216; method).<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction An orbital fit by least-squares is a technique for computing the set of six Keplerian elements which best describe an orbit with respect to a *whole* set of observations. As the set of Keplerian elements we choose semimajor axis a, eccentricity e, time of perigee passage \u03c4\u00a0(i.e., how much time has elapsed since the &hellip; <a href=\"https:\/\/aerospaceresearch.net\/?p=735\" class=\"more-link\"><span class=\"screen-reader-text\">\u201e[GSoC2018|OrbitDeterminator|Jorge] Week #3-4 \u2013 Least squares fit to cartesian positions as a function of time\u201c<\/span> weiterlesen<\/a><\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/posts\/735"}],"collection":[{"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=735"}],"version-history":[{"count":5,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/posts\/735\/revisions"}],"predecessor-version":[{"id":779,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/posts\/735\/revisions\/779"}],"wp:attachment":[{"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}