Isis 3 Programmer Reference
SpicePosition.h
1 #ifndef SpicePosition_h
2 #define SpicePosition_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 #include <string>
10 #include <vector>
11 
12 #include <SpiceUsr.h>
13 #include <SpiceZfc.h>
14 #include <SpiceZmc.h>
15 
16 #include "Table.h"
17 #include "PolynomialUnivariate.h"
18 
19 // ale includes
20 #include "ale/States.h"
21 
22 #include <nlohmann/json.hpp>
23 
24 namespace Isis {
25  class NumericalApproximation;
26 
174  public:
175  //??? jw
180  enum Source { Spice,
185  // table and adding nth degree polynomial
186  };
187 
188  SpicePosition(int targetCode, int observerCode);
189 
191  virtual ~SpicePosition();
192 
193  void SetTimeBias(double timeBias);
194  double GetTimeBias() const;
195 
196  virtual void SetAberrationCorrection(const QString &correction);
197  virtual QString GetAberrationCorrection() const;
198  double GetLightTime() const;
199 
200  const std::vector<double> &SetEphemerisTime(double et);
201  enum PartialType {WRT_X, WRT_Y, WRT_Z};
202 
204  double EphemerisTime() const {
205  return p_et;
206  };
207 
208  const std::vector<double> &GetCenterCoordinate();
209 
211  const std::vector<double> &Coordinate() {
212  return p_coordinate;
213  };
214 
216  const std::vector<double> &Velocity();
217 
219  bool HasVelocity() {
220  return p_hasVelocity;
221  };
222 
223  void LoadCache(double startTime, double endTime, int size);
224  void LoadCache(double time);
225  void LoadCache(Table &table);
226  void LoadCache(nlohmann::json &isd);
227 
228  Table LineCache(const QString &tableName);
229  Table LoadHermiteCache(const QString &tableName);
230 
231  void ReloadCache();
232  void ReloadCache(Table &table);
233 
234  Table Cache(const QString &tableName);
235 
237  bool IsCached() const {
238  return (m_state != NULL);
239  };
240 
242  int cacheSize() const {
243  if (m_state) {
244  return m_state->getStates().size();
245  }
246  return 0;
247  };
248 
249  void SetPolynomial(const Source type = PolyFunction);
250 
251  void SetPolynomial(const std::vector<double>& XC,
252  const std::vector<double>& YC,
253  const std::vector<double>& ZC,
254  const Source type = PolyFunction);
255 
256  void GetPolynomial(std::vector<double>& XC,
257  std::vector<double>& YC,
258  std::vector<double>& ZC);
259 
261  void SetPolynomialDegree(int degree);
262 
265  return p_source;
266  };
267 
268  void ComputeBaseTime();
269 
271  double GetBaseTime() {
272  return p_baseTime;
273  };
274 
275  void SetOverrideBaseTime(double baseTime, double timeScale);
276 
278  double GetTimeScale() {
279  return p_timeScale;
280  };
281 
282  double DPolynomial(const int coeffIndex);
283 
284  std::vector<double> CoordinatePartial(SpicePosition::PartialType partialVar, int coeffIndex);
285 
286  std::vector<double> VelocityPartial(SpicePosition::PartialType partialVar, int coeffIndex);
287  enum OverrideType {NoOverrides, ScaleOnly, BaseAndScale};
288  void Memcache2HermiteCache(double tolerance);
289  std::vector<double> Extrapolate(double timeEt);
290  std::vector<double> HermiteCoordinate();
291  protected:
294  virtual void SetEphemerisTimeSpice();
297 
298  //======================================================================
299  // New methods support for light time correction and swap of observer/target
300  SpicePosition(int targetCode, int observerCode, bool swapObserverTarget);
301  int getObserverCode() const;
302  int getTargetCode() const;
303  double getAdjustedEphemerisTime() const;
304  void computeStateVector(double et, int target, int observer,
305  const QString &refFrame,
306  const QString &abcorr,
307  double state[6], bool &hasVelocity,
308  double &lightTime) const;
309  void setStateVector(const double state[6], const bool &hasVelocity);
310  void setLightTime(const double &lightTime);
311  //======================================================================
312 
313  private:
314  void init(int targetCode, int observerCode,
315  const bool &swapObserverTarget = false);
316  void ClearCache();
317  void LoadTimeCache();
318  void CacheLabel(Table &table);
319  double ComputeVelocityInTime(PartialType var);
320 
323 
324  double p_timeBias;
326 
327  double p_et;
328  std::vector<double> p_coordinate;
329  std::vector<double> p_velocity;
330 
332  std::vector<double> p_cacheTime;
333  std::vector<double> p_coefficients[3];
334 
335  double p_baseTime;
336  double p_timeScale;
338  // of degree p_degree has been created and
339  // used to fill the cache
340  int p_degree;
345  OverrideType p_override;
348 
349  // Variables support observer/target swap and light time correction
350  bool m_swapObserverTarget;
351  double m_lt;
352 
353  ale::States *m_state;
354  };
355 };
356 
357 #endif
Isis::SpicePosition::p_degreeApplied
bool p_degreeApplied
Flag indicating whether or not a polynomial.
Definition: SpicePosition.h:337
Isis::SpicePosition::HermiteCache
@ HermiteCache
Object is reading from splined table.
Definition: SpicePosition.h:182
Isis::SpicePosition::GetPolynomial
void GetPolynomial(std::vector< double > &XC, std::vector< double > &YC, std::vector< double > &ZC)
Return the coefficients of a polynomial fit to each of the three coordinates of the position for the ...
Definition: SpicePosition.cpp:1103
Isis::SpicePosition::p_aberrationCorrection
QString p_aberrationCorrection
Light time correction to apply.
Definition: SpicePosition.h:325
Isis::SpicePosition
Obtain SPICE position information for a body.
Definition: SpicePosition.h:173
Isis::SpicePosition::p_coordinate
std::vector< double > p_coordinate
J2000 position at time et.
Definition: SpicePosition.h:328
Isis::SpicePosition::SetEphemerisTimePolyFunction
void SetEphemerisTimePolyFunction()
This is a protected method that is called by SetEphemerisTime() when Source type is PolyFunction.
Definition: SpicePosition.cpp:1355
Isis::SpicePosition::ClearCache
void ClearCache()
Removes the entire cache from memory.
Definition: SpicePosition.cpp:1484
Isis::SpicePosition::p_overrideBaseTime
double p_overrideBaseTime
Value set by caller to override computed base time.
Definition: SpicePosition.h:346
Isis::SpicePosition::p_targetCode
int p_targetCode
target body code
Definition: SpicePosition.h:321
Isis::SpicePosition::SetEphemerisTimeSpice
virtual void SetEphemerisTimeSpice()
This is a protected method that is called by SetEphemerisTime() when Source type is Spice.
Definition: SpicePosition.cpp:1432
Isis::SpicePosition::computeStateVector
void computeStateVector(double et, int target, int observer, const QString &refFrame, const QString &abcorr, double state[6], bool &hasVelocity, double &lightTime) const
Computes the state vector of the target w.r.t observer.
Definition: SpicePosition.cpp:1742
Isis::SpicePosition::GetAberrationCorrection
virtual QString GetAberrationCorrection() const
Returns current state of stellar aberration correction.
Definition: SpicePosition.cpp:213
Isis::SpicePosition::SetAberrationCorrection
virtual void SetAberrationCorrection(const QString &correction)
Set the aberration correction (light time)
Definition: SpicePosition.cpp:186
Isis::SpicePosition::SetPolynomial
void SetPolynomial(const Source type=PolyFunction)
Set the coefficients of a polynomial fit to each of the components (X, Y, Z) of the position vector f...
Definition: SpicePosition.cpp:930
Isis::SpicePosition::~SpicePosition
virtual ~SpicePosition()
Destructor.
Definition: SpicePosition.cpp:133
Isis::SpicePosition::GetSource
Source GetSource()
Return the source of the position.
Definition: SpicePosition.h:264
Isis::SpicePosition::HermiteCoordinate
std::vector< double > HermiteCoordinate()
This method returns the Hermite coordinate for the current time for PolyFunctionOverHermiteConstant f...
Definition: SpicePosition.cpp:1646
Isis::SpicePosition::CoordinatePartial
std::vector< double > CoordinatePartial(SpicePosition::PartialType partialVar, int coeffIndex)
Set the coefficients of a polynomial fit to each of the three coordinates of the position vector for ...
Definition: SpicePosition.cpp:1167
Isis::SpicePosition::GetBaseTime
double GetBaseTime()
Return the base time for the position.
Definition: SpicePosition.h:271
Isis::SpicePosition::p_velocity
std::vector< double > p_velocity
J2000 velocity at time et.
Definition: SpicePosition.h:329
Isis::SpicePosition::p_hasVelocity
bool p_hasVelocity
Flag to indicate velocity is available.
Definition: SpicePosition.h:344
Isis::SpicePosition::getAdjustedEphemerisTime
double getAdjustedEphemerisTime() const
Returns adjusted ephemeris time.
Definition: SpicePosition.cpp:1705
Isis::SpicePosition::Coordinate
const std::vector< double > & Coordinate()
Return the current J2000 position.
Definition: SpicePosition.h:211
Isis::SpicePosition::SetTimeBias
void SetTimeBias(double timeBias)
Apply a time bias when invoking SetEphemerisTime method.
Definition: SpicePosition.cpp:150
Isis::SpicePosition::getTargetCode
int getTargetCode() const
Returns target code.
Definition: SpicePosition.cpp:1689
Isis::SpicePosition::ComputeBaseTime
void ComputeBaseTime()
Compute the base time using cached times.
Definition: SpicePosition.cpp:1116
Isis::SpicePosition::GetTimeBias
double GetTimeBias() const
Returns the value of the time bias added to ET.
Definition: SpicePosition.cpp:161
Isis::SpicePosition::p_et
double p_et
Current ephemeris time.
Definition: SpicePosition.h:327
Isis::SpicePosition::setStateVector
void setStateVector(const double state[6], const bool &hasVelocity)
Sets the state of target relative to observer.
Definition: SpicePosition.cpp:1794
Isis::SpicePosition::SetEphemerisTimeMemcache
void SetEphemerisTimeMemcache()
This is a protected method that is called by SetEphemerisTime() when Source type is Memcache.
Definition: SpicePosition.cpp:1294
Isis::SpicePosition::SpicePosition
SpicePosition(int targetCode, int observerCode)
Construct an empty SpicePosition class using valid body codes.
Definition: SpicePosition.cpp:37
Isis::SpicePosition::p_timeBias
double p_timeBias
iTime bias when reading kernels
Definition: SpicePosition.h:324
Isis::SpicePosition::LineCache
Table LineCache(const QString &tableName)
Return a table with J2000 to reference positions.
Definition: SpicePosition.cpp:704
Isis::SpicePosition::SetEphemerisTime
const std::vector< double > & SetEphemerisTime(double et)
Return J2000 coordinate at given time.
Definition: SpicePosition.cpp:249
Isis::SpicePosition::SetEphemerisTimePolyFunctionOverHermiteConstant
void SetEphemerisTimePolyFunctionOverHermiteConstant()
This is a protected method that is called by SetEphemerisTime() when Source type is PolyFunctionOverH...
Definition: SpicePosition.cpp:1403
Isis::SpicePosition::SetEphemerisTimeHermiteCache
void SetEphemerisTimeHermiteCache()
This is a protected method that is called by SetEphemerisTime() when Source type is HermiteCache.
Definition: SpicePosition.cpp:1324
Isis::SpicePosition::Spice
@ Spice
Object is reading directly from the kernels.
Definition: SpicePosition.h:180
Isis::SpicePosition::p_baseTime
double p_baseTime
Base time used in fit equations.
Definition: SpicePosition.h:335
Isis::SpicePosition::GetCenterCoordinate
const std::vector< double > & GetCenterCoordinate()
Compute and return the coordinate at the center time.
Definition: SpicePosition.cpp:1586
Isis::SpicePosition::HasVelocity
bool HasVelocity()
Return the flag indicating whether the velocity exists.
Definition: SpicePosition.h:219
Isis::SpicePosition::p_source
Source p_source
Enumerated value for the location of the SPK information used.
Definition: SpicePosition.h:331
Isis::SpicePosition::PolyFunctionOverHermiteConstant
@ PolyFunctionOverHermiteConstant
Object is reading from splined.
Definition: SpicePosition.h:184
Isis::SpicePosition::getObserverCode
int getObserverCode() const
Returns observer code.
Definition: SpicePosition.cpp:1675
Isis::SpicePosition::p_degree
int p_degree
Degree of polynomial function fit to the coordinates of the position.
Definition: SpicePosition.h:340
Isis::SpicePosition::LoadHermiteCache
Table LoadHermiteCache(const QString &tableName)
Cache J2000 position over existing cached time range using polynomials stored as Hermite cubic spline...
Definition: SpicePosition.cpp:793
Isis::SpicePosition::p_overrideTimeScale
double p_overrideTimeScale
Value set by caller to override computed time scale.
Definition: SpicePosition.h:347
Isis::SpicePosition::PolyFunction
@ PolyFunction
Object is calculated from nth degree polynomial.
Definition: SpicePosition.h:183
Isis::SpicePosition::LoadCache
void LoadCache(double startTime, double endTime, int size)
Cache J2000 position over a time range.
Definition: SpicePosition.cpp:297
Isis::SpicePosition::GetLightTime
double GetLightTime() const
Return the light time coorection value.
Definition: SpicePosition.cpp:230
Isis::SpicePosition::cacheSize
int cacheSize() const
Get the size of the current cached positions.
Definition: SpicePosition.h:242
Isis::SpicePosition::p_timeScale
double p_timeScale
Time scale used in fit equations.
Definition: SpicePosition.h:336
Isis::Table
Class for storing Table blobs information.
Definition: Table.h:61
Isis::SpicePosition::p_observerCode
int p_observerCode
observer body code
Definition: SpicePosition.h:322
Isis::SpicePosition::Source
Source
This enum indicates the status of the object.
Definition: SpicePosition.h:180
Isis::SpicePosition::setLightTime
void setLightTime(const double &lightTime)
Inheritors can set the light time if indicated.
Definition: SpicePosition.cpp:1824
Isis::SpicePosition::Extrapolate
std::vector< double > Extrapolate(double timeEt)
Extrapolate position for a given time assuming a constant velocity.
Definition: SpicePosition.cpp:1626
Isis::SpicePosition::EphemerisTime
double EphemerisTime() const
Return the current ephemeris time.
Definition: SpicePosition.h:204
Isis::SpicePosition::CacheLabel
void CacheLabel(Table &table)
Add labels to a SpicePosition table.
Definition: SpicePosition.cpp:658
Isis::SpicePosition::LoadTimeCache
void LoadTimeCache()
Load the time cache.
Definition: SpicePosition.cpp:1568
Isis::SpicePosition::Memcache2HermiteCache
void Memcache2HermiteCache(double tolerance)
This method reduces the cache for position, time and velocity to the minimum number of values needed ...
Definition: SpicePosition.cpp:1463
Isis::SpicePosition::p_coefficients
std::vector< double > p_coefficients[3]
Coefficients of polynomials fit to 3 coordinates.
Definition: SpicePosition.h:333
Isis::SpicePosition::m_lt
double m_lt
!< Swap traditional order
Definition: SpicePosition.h:351
Isis::SpicePosition::p_fullCacheSize
double p_fullCacheSize
Orignial size of the complete cache after spiceinit.
Definition: SpicePosition.h:343
Isis::SpicePosition::p_fullCacheStartTime
double p_fullCacheStartTime
Original start time of the complete cache after spiceinit.
Definition: SpicePosition.h:341
Isis::SpicePosition::SetOverrideBaseTime
void SetOverrideBaseTime(double baseTime, double timeScale)
Set an override base time to be used with observations on scanners to allow all images in an observat...
Definition: SpicePosition.cpp:1147
Isis::SpicePosition::Velocity
const std::vector< double > & Velocity()
Return the current J2000 velocity.
Definition: SpicePosition.cpp:1269
Isis::SpicePosition::p_override
OverrideType p_override
Time base and scale override options;.
Definition: SpicePosition.h:345
Isis::SpicePosition::p_fullCacheEndTime
double p_fullCacheEndTime
Original end time of the complete cache after spiceinit.
Definition: SpicePosition.h:342
Isis::SpicePosition::IsCached
bool IsCached() const
Is this position cached.
Definition: SpicePosition.h:237
Isis::SpicePosition::Cache
Table Cache(const QString &tableName)
Return a table with J2000 positions.
Definition: SpicePosition.cpp:549
Isis::SpicePosition::Memcache
@ Memcache
Object is reading from cached table.
Definition: SpicePosition.h:181
Isis::SpicePosition::ComputeVelocityInTime
double ComputeVelocityInTime(PartialType var)
Compute the velocity with respect to time instead of scaled time.
Definition: SpicePosition.cpp:1603
Isis::SpicePosition::ReloadCache
void ReloadCache()
Cache J2000 positions over existing cached time range using polynomials.
Definition: SpicePosition.cpp:729
Isis::SpicePosition::p_cacheTime
std::vector< double > p_cacheTime
iTime for corresponding position
Definition: SpicePosition.h:332
Isis::SpicePosition::GetTimeScale
double GetTimeScale()
Return the time scale for the position.
Definition: SpicePosition.h:278
Isis::SpicePosition::DPolynomial
double DPolynomial(const int coeffIndex)
Evaluate the derivative of the fit polynomial (parabola) defined by the given coefficients with respe...
Definition: SpicePosition.cpp:1244
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::SpicePosition::m_state
ale::States * m_state
!< Light time correction
Definition: SpicePosition.h:353
Isis::SpicePosition::init
void init(int targetCode, int observerCode, const bool &swapObserverTarget=false)
Internal initialization of the object support observer/target swap.
Definition: SpicePosition.cpp:87
Isis::SpicePosition::VelocityPartial
std::vector< double > VelocityPartial(SpicePosition::PartialType partialVar, int coeffIndex)
Compute the derivative of the velocity with respect to the specified variable.
Definition: SpicePosition.cpp:1208
Isis::SpicePosition::SetPolynomialDegree
void SetPolynomialDegree(int degree)
Set the polynomial degree.
Definition: SpicePosition.cpp:1502