Commit 341d8ed0 authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Merged SpiceRotation changes (target body support, documentation and testing)...

Merged SpiceRotation changes (target body support, documentation and testing) from IPCE (r6874,5) to trunk. Fixes #4097, #3972.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6877 41f8697f-d340-4b68-9986-7bafba869bb8
parent 16292cbd
Loading
Loading
Loading
Loading
+506 −311

File changed.

Preview size limit exceeded, changes collapsed.

+104 −98
Original line number Diff line number Diff line
@@ -25,14 +25,14 @@
#include <string>
#include <vector>

#include <SpiceUsr.h>
#include <SpiceZfc.h>
#include <SpiceZmc.h>
//#include <SpiceUsr.h>
//#include <SpiceZfc.h>
//#include <SpiceZmc.h>

#include "Angle.h"
#include "Table.h"
#include "Quaternion.h"
#include "PolynomialUnivariate.h"
#include "Quaternion.h"

#define J2000Code    1

@@ -49,7 +49,7 @@ namespace Isis {
   * loaded prior to using this class.  A position can be returned in either
   * the J2000 frame or the selected reference frame.  See NAIF required
   * reading for more information regarding this subject at
   * ftp://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/ascii/individual_docs/spk.req
   * ftp://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/spk.html
   * <p>
   * An important functionality of this class is the ability to cache the
   * rotations so they do not have to be constantly read from the NAIF kernels
@@ -192,7 +192,7 @@ namespace Isis {
   *                           Added new methods 
   *                           loadPCFromSpice, loadPCFromTable, toJ2000Partial, poleRaCoefs,
   *                           poleDecCoefs, pmCoefs, poleRaNutPrecCoefs, poleDecNutPrecCoefs, 
   *                           mNutPrecCoefs, sysNutPrecConstants, sysNutPrecCoefs,
   *                           pmNutPrecCoefs, sysNutPrecConstants, sysNutPrecCoefs,
   *                           usePckPolynomial, setPckPolynomial(raCoef, decCoef, pmCoef),
   *                           getPckPolynomial, setEphemerisTimePckPolyFunction, getFrameType
   *                           and members m_frameType, m_tOrientationAvailable, 
@@ -200,11 +200,12 @@ namespace Isis {
   *                           m_sysNutPrec0, m_sysNutPrec1, m_dscale, m_Tscale to support request for 
   *                           solving for target body parameters.
   *                           Also added a new enumerated value for Source, PckPolyFunction, 
   *                            and 
   *                           PartialType, WRT_RotationRate.
   *                           and PartialType, WRT_RotationRate.
   *   @history 2016-02-15 Debbie A. Cook - Programmer notes - Added private method
   *                           setFrameType to set the frame type.  It also loads the planetary 
   *                           constants for a PCK type. 
   *   @history 2016-06-28 Ian Humphrey - Updated documentation and coding standards. Added new
   *                           tests to unit test. Fixes #3972.
   *
   *  @todo Downsize using Hermite cubic spline and allow Nadir tables to be downsized again.
   *  @todo Consider making this a base class with child classes based on frame type or 
@@ -245,36 +246,39 @@ namespace Isis {
       *       PckPolyFunction - The rotation is calculated using the IAU fit 
       *                  polynomials in one variable (time in Julian centuries and days).
       */
      enum Source { Spice,                              //!< Directly from the kernels 
      enum Source {            
        Spice,                   //!< Directly from the kernels 
        Nadir,                   //!< Nadir pointing
        Memcache,                //!< From cached table
        PolyFunction,            //!< From nth degree polynomial
        PolyFunctionOverSpice ,  //!< Kernels plus nth degree polynomial 
                               PckPolyFunction          //!< Quadratic polynomial function with
                                                        //   linear trignometric terms
        PckPolyFunction          //!< Quadratic polynomial function with linear trignometric terms
      };            

      /** 
       * This enumeration indicates whether the partial derivative is taken with 
       * respect to Right Ascension, Declination, or Twist (or Rotation). 
       */ 
      enum PartialType { WRT_RightAscension, //!< With respect to Right Ascension
      enum PartialType { 
        WRT_RightAscension, //!< With respect to Right Ascension
        WRT_Declination,    //!< With respect to Declination
        WRT_Twist           //!< With respect to Twist or Prime Meridian Rotation
      };

      /** 
       *  
       * Status of downsizing the cache
       */ 
      enum DownsizeStatus { Yes,  //!< 
                            Done, //!< 
                            No    //!< 
      enum DownsizeStatus { 
        Yes,  //!< Downsize the cache 
        Done, //!< Cache is downsized
        No    //!< Do not downsize the cache 
      };

      /** 
       *  
       * Enumeration for the frame type of the rotation  
       */ 
      enum FrameType {UNKNOWN = 0,  // Isis specific code for unknown frame type
      enum FrameType {
        UNKNOWN = 0,      //!< Isis specific code for unknown frame type
        INERTL = 1,       //!< See Naif Frames.req document for 
        PCK  = 2,         //!< definitions
        CK = 3,           //!< 
@@ -470,8 +474,7 @@ namespace Isis {
                                          (after all time-based rotations in frame chain from
                                           J2000 to target) to the target frame*/
      std::vector<double> p_CJ;           /**< Rotation matrix from J2000 to first constant 
                                               rotation after all the time-based rotations 
                                               in frame chain from*/
                                               rotation*/
      std::vector<std::vector<double> > p_cacheAv;
      //!< Cached angular velocities for corresponding rotactions in p_cache
      std::vector<double> p_av;           //!< Angular velocity for rotation at time p_et
@@ -559,9 +562,9 @@ namespace Isis {
      //                and pmNutPrec).
      //
      // The next three vectors will have length 3 (for a quadratic polynomial) if used.
      std::vector<Angle>m_raPole;        //!< Coefficients of a quadratic polynomial fitting pole ra
      std::vector<Angle>m_decPole;      //!< Coefficients of a quadratic polynomial fitting pole dec
      std::vector<Angle>m_pm ;             //!< Coefficients of a quadratic polynomial fitting pole pm
      std::vector<Angle>m_raPole;       //!< Coefficients of a quadratic polynomial fitting pole ra.
      std::vector<Angle>m_decPole;      //!< Coefficients of a quadratic polynomial fitting pole dec.
      std::vector<Angle>m_pm ;          //!< Coefficients of a quadratic polynomial fitting pole pm.
      //
      // Currently multiples (terms with periods matching other terms but varying amplitudes) 
      // are handled as additional terms added to the end of the vector as Naif does (see 
@@ -574,10 +577,13 @@ namespace Isis {
      std::vector<Angle>m_sysNutPrec0; //!< Constants of planetary system nut/prec periods
      std::vector<Angle>m_sysNutPrec1; //!< Linear terms of planetary system nut/prec periods

      // The following scalers are used in the IAU equations to convert p_et to the appropriate time
      // units for calculating target body ra, dec, and w.  These need to be initialized in every constructor.
      static const double m_centScale;   //!<  Seconds per Julian century for scaling time in seconds *** may need to put static in front of const
      static const double m_dayScale;    //!< Seconds per day for scaling time in seconds to get target body w
      // The following scalars are used in the IAU equations to convert p_et to the appropriate time
      // units for calculating target body ra, dec, and w.  These need to be initialized in every 
      // constructor.
      //! Seconds per Julian century for scaling time in seconds
      static const double m_centScale;
      //! Seconds per day for scaling time in seconds to get target body w
      static const double m_dayScale;
  };
};

+219 −47
Original line number Diff line number Diff line
Unit test for SpiceRotation
Naif code = -94031
Testing without cache ... 
Testing without cache (from SPICE)... 
CJ(0) = -0.87506927 0.25477955 -0.41151081
         0.011442263 0.86088548 0.50867009
         0.48386242 0.44041295 -0.75624969
@@ -151,107 +151,107 @@ Testing with polynomial functions over Spice ...
Source = 4
Time           = -69382819
CJ(0) = -0.87809698 0.25267525 -0.40632612
         0.01085749 0.85950052 0.51101954
         0.010857485 0.85950052 0.51101953
         0.4783595 0.44431303 -0.75746823
av(0) = 3.6136802e-05 -0.001148937 -0.0007178313
av(0) = 3.6136802e-05 -0.001148937 -0.00071783127
Time           = -69382785
CJ(1) = -0.85534528 0.27482047 -0.43915619
         0.013830533 0.85950782 0.51093545
         0.01383053 0.85950782 0.51093544
         0.5178737 0.43095246 -0.73897687
av(1) = 2.6818529e-05 -0.0011482899 -0.00072824247
av(1) = 2.6818529e-05 -0.0011482899 -0.00072824243
Time           = -69382751
CJ(2) = -0.83089148 0.29534676 -0.47158206
         0.015622985 0.85955538 0.51080376
         0.015622983 0.85955538 0.51080376
         0.55621513 0.41705497 -0.71881144
av(2) = 1.5045992e-05 -0.0011468841 -0.00073507985
av(2) = 1.5045992e-05 -0.0011468841 -0.00073507982
Time           = -69382717
CJ(3) = -0.80487479 0.31420086 -0.50344253
         0.016285301 0.8597142 0.5105157
         0.0162853 0.8597142 0.5105157
         0.59322117 0.40270251 -0.69707915
av(3) = 6.7201932e-06 -0.00114088 -0.00073822293
av(3) = 6.7201932e-06 -0.00114088 -0.0007382229
Time           = -69382683
CJ(4) = -0.77730696 0.33143284 -0.53473934
         0.015873612 0.86003946 0.50998054
         0.015873612 0.86003947 0.50998054
         0.62892123 0.38792318 -0.6737757
av(4) = -5.6601096e-06 -0.0011345655 -0.00074475062
av(4) = -5.6601096e-06 -0.0011345655 -0.00074475059
Time           = -69382648
CJ(5) = -0.74837985 0.34697393 -0.56527576
         0.014476129 0.86059696 0.50908086
         0.01447613 0.86059696 0.50908086
         0.66311239 0.37280285 -0.64907626
av(5) = -1.3898006e-05 -0.001126288 -0.00074801569
av(5) = -1.3898006e-05 -0.001126288 -0.00074801566
Time           = -69382614
CJ(6) = -0.71811664 0.36084246 -0.59506403
         0.012135219 0.86143483 0.50772312
CJ(6) = -0.71811664 0.36084247 -0.59506403
         0.012135221 0.86143483 0.50772312
         0.69581695 0.35738319 -0.62298959
av(6) = -2.1224594e-05 -0.0011158407 -0.00075276265
av(6) = -2.1224594e-05 -0.0011158407 -0.00075276262
Time           = -69382580
CJ(7) = -0.68675883 0.37311393 -0.62381752
         0.0090314639 0.86251995 0.50594245
         0.0090314657 0.86251995 0.50594245
         0.72682924 0.34182646 -0.59571296
av(7) = -3.5938808e-05 -0.0011049021 -0.0007547869
av(7) = -3.5938808e-05 -0.0011049021 -0.00075478687
Time           = -69382546
CJ(8) = -0.65434784 0.38366055 -0.65163908
         0.0051328027 0.86396924 0.50351842
CJ(8) = -0.65434784 0.38366056 -0.65163908
         0.005132805 0.86396924 0.50351842
         0.75617628 0.32613145 -0.56730566
av(8) = -4.4387854e-05 -0.0010910882 -0.00075256003
av(8) = -4.4387854e-05 -0.0010910882 -0.00075255999
Time           = -69382512
CJ(9) = -0.62100725 0.39254656 -0.67842258
         0.00050302029 0.86574982 0.50047676
CJ(9) = -0.62100725 0.39254656 -0.67842257
         0.00050302319 0.86574982 0.50047677
         0.78380466 0.31045844 -0.53783438
av(9) = -5.6369117e-05 -0.0010744677 -0.00075515741
av(9) = -5.6369117e-05 -0.0010744677 -0.00075515738

Test fitting polynomial function over cache to new cache
Source = 2
Time           = -69382819
CJ(0) = -0.87809698 0.25267525 -0.40632612
         0.01085749 0.85950052 0.51101954
         0.010857485 0.85950052 0.51101953
         0.4783595 0.44431303 -0.75746823
av(0) = 3.6136802e-05 -0.001148937 -0.0007178313
av(0) = 3.6136802e-05 -0.001148937 -0.00071783127
Time           = -69382785
CJ(1) = -0.85534528 0.27482047 -0.43915619
         0.013830533 0.85950782 0.51093545
         0.01383053 0.85950782 0.51093544
         0.5178737 0.43095246 -0.73897687
av(1) = 2.6818529e-05 -0.0011482899 -0.00072824247
av(1) = 2.6818529e-05 -0.0011482899 -0.00072824243
Time           = -69382751
CJ(2) = -0.83089148 0.29534676 -0.47158206
         0.015622985 0.85955538 0.51080376
         0.015622983 0.85955538 0.51080376
         0.55621513 0.41705497 -0.71881144
av(2) = 1.5045992e-05 -0.0011468841 -0.00073507985
av(2) = 1.5045992e-05 -0.0011468841 -0.00073507982
Time           = -69382717
CJ(3) = -0.80487479 0.31420086 -0.50344253
         0.016285301 0.8597142 0.5105157
         0.0162853 0.8597142 0.5105157
         0.59322117 0.40270251 -0.69707915
av(3) = 6.7201932e-06 -0.00114088 -0.00073822293
av(3) = 6.7201932e-06 -0.00114088 -0.0007382229
Time           = -69382683
CJ(4) = -0.77730696 0.33143284 -0.53473934
         0.015873612 0.86003946 0.50998054
         0.015873612 0.86003947 0.50998054
         0.62892123 0.38792318 -0.6737757
av(4) = -5.6601096e-06 -0.0011345655 -0.00074475062
av(4) = -5.6601096e-06 -0.0011345655 -0.00074475059
Time           = -69382648
CJ(5) = -0.74837985 0.34697393 -0.56527576
         0.014476129 0.86059696 0.50908086
         0.01447613 0.86059696 0.50908086
         0.66311239 0.37280285 -0.64907626
av(5) = -1.3898006e-05 -0.001126288 -0.00074801569
av(5) = -1.3898006e-05 -0.001126288 -0.00074801566
Time           = -69382614
CJ(6) = -0.71811664 0.36084246 -0.59506403
         0.012135219 0.86143483 0.50772312
CJ(6) = -0.71811664 0.36084247 -0.59506403
         0.012135221 0.86143483 0.50772312
         0.69581695 0.35738319 -0.62298959
av(6) = -2.1224594e-05 -0.0011158407 -0.00075276265
av(6) = -2.1224594e-05 -0.0011158407 -0.00075276262
Time           = -69382580
CJ(7) = -0.68675883 0.37311393 -0.62381752
         0.0090314639 0.86251995 0.50594245
         0.0090314657 0.86251995 0.50594245
         0.72682924 0.34182646 -0.59571296
av(7) = -3.5938808e-05 -0.0011049021 -0.0007547869
av(7) = -3.5938808e-05 -0.0011049021 -0.00075478687
Time           = -69382546
CJ(8) = -0.65434784 0.38366055 -0.65163908
         0.0051328027 0.86396924 0.50351842
CJ(8) = -0.65434784 0.38366056 -0.65163908
         0.005132805 0.86396924 0.50351842
         0.75617628 0.32613145 -0.56730566
av(8) = -4.4387854e-05 -0.0010910882 -0.00075256003
av(8) = -4.4387854e-05 -0.0010910882 -0.00075255999
Time           = -69382512
CJ(9) = -0.62100725 0.39254656 -0.67842258
         0.00050302029 0.86574982 0.50047676
CJ(9) = -0.62100725 0.39254656 -0.67842257
         0.00050302319 0.86574982 0.50047677
         0.78380466 0.31045844 -0.53783438
av(9) = -5.6369117e-05 -0.0010744677 -0.00075515741
av(9) = -5.6369117e-05 -0.0010744677 -0.00075515738

Testing ToReferencePartial method
For angles (ra,dec,twist) = 1.9429654 2.1356375 -0.92665897
@@ -481,3 +481,175 @@ Testing angle wrapping...
   Using anchor angle of 30, -10 changes to -10
   Using anchor angle of 30, -180 changes to 180
   Using anchor angle of 30, 90 changes to 90


Begin tests for PCK data...

Test LoadPCFromSpice and all the coefficient accessors...
Test CacheLabel for PCK data...
Test LoadPCFromTable...
Io Pole RA coefficients = 268.05,-0.009,0
Io Pole DEC coefficients = 64.5,0.003,0
Io PM coefficients = 200.39,203.48895,0
Io Pole RA Nutation/Precession coefficients = 0,0,0.094,0.024,0,0,0,0,0,0,0,0,0,0,0,
Io Pole DEC Nutation/Precession coefficients = 0,0,0.04,0.011,0,0,0,0,0,0,0,0,0,0,0,
Io PM Nutation/Precession coefficients = 0,0,-0.085,-0.022,0,0,0,0,0,0,0,0,0,0,0,
Io System Nutation/Precession constants = 73.32,24.62,283.9,355.8,119.9,229.8,352.25,113.35,146.64,49.24,99.360714,175.89537,300.32316,114.0123,49.511251,
Io System Nutation/Precession coefficients = 91472.9,45137.2,4850.7,1191.3,262.1,64.3,2382.6,6070,182945.8,90274.4,4850.4046,1191.9605,262.5475,6070.2476,64.3,

Testing with PCK polynomial ... 
Io    Angles = -2.0466383,25.496441,-24.093155


  Mars original SPICE values for target body orientation unadjusted
  Source = 2
    Time           = -69382819
CJ(0) = 0.65330574 -0.46117449 -0.60042459
         0.61166293 0.78886884 0.059619006
         0.44616149 -0.4062069 0.79745588
    Time           = -69382785
CJ(1) = 0.65478275 -0.45926576 -0.60027869
         0.61008153 0.78998159 0.061070579
         0.44616149 -0.4062069 0.79745588
    Time           = -69382751
CJ(2) = 0.65625594 -0.45735435 -0.60012927
         0.60849657 0.79108972 0.062521795
         0.44616149 -0.4062069 0.79745588
    Time           = -69382717
CJ(3) = 0.65772528 -0.45544026 -0.59997635
         0.60690805 0.79219323 0.063972645
         0.44616149 -0.4062069 0.79745588
    Time           = -69382683
CJ(4) = 0.65919078 -0.45352351 -0.59981992
         0.60531598 0.79329211 0.065423122
         0.44616149 -0.4062069 0.79745588
    Time           = -69382648
CJ(5) = 0.66065243 -0.45160411 -0.59965998
         0.60372038 0.79438635 0.066873216
         0.44616149 -0.4062069 0.79745588
    Time           = -69382614
CJ(6) = 0.66211021 -0.44968207 -0.59949654
         0.60212124 0.79547595 0.068322919
         0.44616149 -0.4062069 0.79745588
    Time           = -69382580
CJ(7) = 0.66356413 -0.4477574 -0.59932959
         0.60051859 0.7965609 0.069772222
         0.44616149 -0.4062069 0.79745588
    Time           = -69382546
CJ(8) = 0.66501416 -0.44583011 -0.59915914
         0.59891242 0.79764119 0.071221118
         0.44616149 -0.4062069 0.79745588
    Time           = -69382512
CJ(9) = 0.66646031 -0.44390022 -0.59898518
         0.59730276 0.79871681 0.072669597
         0.44616149 -0.4062069 0.79745588


Now PCK polynomial values for angles unadjusted ...
  Io PCK polynomial output
  Source = 5
    Angles = -2.0466383,25.496441,-24.093155

  Mars PCK polynomial output
  Source = 5
    Time           = -69382819
CJ(0) = 0.65330574 -0.46117449 -0.60042459
         0.61166293 0.78886884 0.059619006
         0.44616149 -0.4062069 0.79745588
    Time           = -69382785
CJ(1) = 0.65478275 -0.45926576 -0.60027869
         0.61008153 0.78998159 0.061070579
         0.44616149 -0.4062069 0.79745588
    Time           = -69382751
CJ(2) = 0.65625594 -0.45735435 -0.60012927
         0.60849657 0.79108972 0.062521795
         0.44616149 -0.4062069 0.79745588
    Time           = -69382717
CJ(3) = 0.65772528 -0.45544026 -0.59997635
         0.60690805 0.79219323 0.063972645
         0.44616149 -0.4062069 0.79745588
    Time           = -69382683
CJ(4) = 0.65919078 -0.45352351 -0.59981992
         0.60531598 0.79329211 0.065423122
         0.44616149 -0.4062069 0.79745588
    Time           = -69382648
CJ(5) = 0.66065243 -0.45160411 -0.59965998
         0.60372038 0.79438635 0.066873216
         0.44616149 -0.4062069 0.79745588
    Time           = -69382614
CJ(6) = 0.66211021 -0.44968207 -0.59949654
         0.60212124 0.79547595 0.068322919
         0.44616149 -0.4062069 0.79745588
    Time           = -69382580
CJ(7) = 0.66356413 -0.4477574 -0.59932959
         0.60051859 0.7965609 0.069772222
         0.44616149 -0.4062069 0.79745588
    Time           = -69382546
CJ(8) = 0.66501416 -0.44583011 -0.59915914
         0.59891242 0.79764119 0.071221118
         0.44616149 -0.4062069 0.79745588
    Time           = -69382512
CJ(9) = 0.66646031 -0.44390022 -0.59898518
         0.59730276 0.79871681 0.072669597
         0.44616149 -0.4062069 0.79745588


Testing angular velocity with Io data ...
SpiceRotation av = -6.3193326e-07 -1.7682968e-05 3.7102704e-05
J2000 to body-fixed Naif av = -6.3193326e-07 -1.7682968e-05 3.7102704e-05



Testing partials for target body parameters...
For angles (ra,dec,rotation) = 1.9429654 2.1356375 -0.92665897
Beginning with J2000 vector 0.78673052 0.30824564 -0.53482681
lookB = 0.69294371 0.69249343 -0.20070344

 dLookB with respect to ra = 0.56419869 -0.43208476 0.4571027
  Right ascension partial on A applied to dlookB =:  0.78673052 0.30824564 0

 dLookB with respect to dec = -0.19972128 0.019831273 -0.62112827
  Declination partial on A applied to dlookB =:  0.27671521 -0.25193486 -0.53482681

 dLookB with respect to rotation rate = -556.10123 556.46282 0
  Rotation rate partial on A applied to dlookB =:  565090.03 146205.39 -241683.3

 dLookB with respect to rotation = 0.69249343 -0.69294371 0
  Rotation partial on A applied to dlookB =:  0.87627666 0.22671852 -0.37477468


... Testing failure of body rotation with binary PCK
 Source = 0
Frame type is binary PCK and cannot be updated
End of PCK testing


Testing exceptions...

**I/O ERROR** Cannot find [INS-99999_TRANSX] in text kernels.

**PROGRAMMER ERROR** Argument cacheSize must not be less or equal to zero.

**PROGRAMMER ERROR** Argument startTime must be less than or equal to endTime.

**PROGRAMMER ERROR** Cache size must be more than 1 if startTime and endTime differ.

**PROGRAMMER ERROR** A SpiceRotation cache has already been created.

**PROGRAMMER ERROR** The SpiceRotation has not yet been fit to a function.

**PROGRAMMER ERROR** Only cached rotations can be returned as a line cache of quaternions and time.

**PROGRAMMER ERROR** To create table source of data must be either Memcache or PolyFunction.

**USER ERROR** Target body orientation information not available.  Rerun spiceinit.

**PROGRAMMER ERROR** Unable to evaluate the derivative of the SPICE rotation fit polynomial for the given coefficient index [-1]. Index is negative or exceeds degree of polynomial [2].

**PROGRAMMER ERROR** Unable to evaluate the derivative of the target body rotation fit polynomial for the given coefficient index [100]. Index is negative or exceeds degree of polynomial [2].

**PROGRAMMER ERROR** A rotation axis is outside the valid range of 1 to 3.

**USER ERROR** Time cache not available -- rerun spiceinit.

**PROGRAMMER ERROR** The SpiceRotation pointing angles must be fit to polynomials in order to compute angular velocity.
+476 −87

File changed.

Preview size limit exceeded, changes collapsed.