16 #include "NumericalApproximation.h" 30 init(targetCode, observerCode,
false);
63 bool swapObserverTarget) {
64 init(targetCode, observerCode, swapObserverTarget);
80 const bool &swapObserverTarget) {
106 m_swapObserverTarget = swapObserverTarget;
110 if ( m_swapObserverTarget ) {
180 QString abcorr(correction);
181 abcorr.remove(QChar(
' '));
182 abcorr = abcorr.toUpper();
184 validAbcorr <<
"NONE" <<
"LT" <<
"LT+S" <<
"CN" <<
"CN+S" 185 <<
"XLT" <<
"XLT+S" <<
"XCN" <<
"XCN+S";
187 if (validAbcorr.indexOf(abcorr) >= 0) {
191 QString msg =
"Invalid abberation correction [" + correction +
"]";
290 QString msg =
"A SpicePosition cache has already been created";
294 if(startTime > endTime) {
295 QString msg =
"Argument startTime must be less than or equal to endTime";
299 if((startTime != endTime) && (size == 1)) {
300 QString msg =
"Cache size must be more than 1 if startTime endTime differ";
311 for(
int i = 0; i < size; i++) {
366 QString msg =
"A SpicePosition cache has already been created";
399 "Invalid value for CacheType keyword in the table " 406 for (
int r = 0; r < table.
Records(); r++) {
411 else if (rec.
Fields() == 4) {
415 QString msg =
"Expecting four or seven fields in the SpicePosition table";
419 std::vector<double> j2000Coord;
420 j2000Coord.push_back((
double)rec[0]);
421 j2000Coord.push_back((
double)rec[1]);
422 j2000Coord.push_back((
double)rec[2]);
427 std::vector<double> j2000Velocity;
428 j2000Velocity.push_back((
double)rec[3]);
429 j2000Velocity.push_back((
double)rec[4]);
430 j2000Velocity.push_back((
double)rec[5]);
440 std::vector<double> coeffX, coeffY, coeffZ;
442 for (
int r = 0; r < table.
Records() - 1; r++) {
448 coeffX.push_back((
double)rec[0]);
449 coeffY.push_back((
double)rec[1]);
450 coeffZ.push_back((
double)rec[2]);
454 double baseTime = (double)rec[0];
455 double timeScale = (double)rec[1];
456 double degree = (double)rec[2];
515 Table table(tableName, record);
519 for (
int i = 0; i < (int)
p_cache.size(); i++) {
520 record[inext++] =
p_cache[i][0];
521 record[inext++] =
p_cache[i][1];
522 record[inext++] =
p_cache[i][2];
549 record += spacecraftX;
550 record += spacecraftY;
551 record += spacecraftZ;
553 Table table(tableName, record);
555 for(
int cindex = 0; cindex <
p_degree + 1; cindex++) {
575 "Cannot create Table, no Cache is loaded.",
591 QString tabletype =
"";
594 tabletype =
"Linear";
597 tabletype =
"HermiteSpline";
600 tabletype =
"PolyFunction";
641 QString msg =
"Only cached positions can be returned as a line cache of positions and time";
645 return Cache(tableName);
668 QString msg =
"The SpicePosition has not yet been fit to a function";
687 for (std::vector<double>::size_type pos = 0; pos <
p_cacheTime.size(); pos++) {
727 if(cacheTimeSize == 1)
return Cache(tableName);
731 return Cache(tableName);
736 QString msg =
"A SpicePosition polynomial function has not been created yet";
772 double extremumXtime = -b1 / (2.*c1) +
p_baseTime;
774 if(extremumXtime < firstTime) {
775 extremumXtime = firstTime;
777 if(extremumXtime > lastTime) {
778 extremumXtime = lastTime;
783 double extremumYtime = -b2 / (2.*c2) +
p_baseTime;
785 if(extremumYtime < firstTime) {
786 extremumYtime = firstTime;
788 if(extremumYtime > lastTime) {
789 extremumYtime = lastTime;
794 double extremumZtime = -b3 / (2.*c3) +
p_baseTime;
796 if(extremumZtime < firstTime) {
797 extremumZtime = firstTime;
799 if(extremumZtime > lastTime) {
800 extremumZtime = lastTime;
824 for(
int i = 0; i < (int)
p_cacheTime.size(); i++) {
845 return Cache(tableName);
856 std::vector<double> XC, YC, ZC;
866 else if (
p_cache.size() == 2) {
885 std::vector<double> time;
908 for(
int cIndex = 0; cIndex < 3; cIndex++) {
910 slope[cIndex] = posline.
Slope();
913 XC.push_back(intercept[0]);
914 XC.push_back(slope[0]);
915 YC.push_back(intercept[1]);
916 YC.push_back(slope[1]);
917 ZC.push_back(intercept[2]);
918 ZC.push_back(slope[2]);
926 for(std::vector<double>::size_type pos = 0; pos <
p_cacheTime.size(); pos++) {
979 const std::vector<double>& YC,
980 const std::vector<double>& ZC,
1028 std::vector<double>& YC,
1029 std::vector<double>& ZC) {
1092 SpicePosition::PartialType partialVar,
int coeffIndex) {
1095 std::vector<double> coordinate(3, 0);
1098 int coordIndex = partialVar;
1133 SpicePosition::PartialType partialVar,
int coeffIndex) {
1136 std::vector<double> dvelocity(3, 0);
1139 int coordIndex = partialVar;
1142 double derivative = 0.;
1145 double Epsilon = 1.0e-15;
1146 if (fabs(time) <= Epsilon) time = 0.0;
1150 derivative = coeffIndex * pow(time, coeffIndex-1) /
p_timeScale;
1153 dvelocity[coordIndex] = derivative;
1169 double derivative = 1.;
1172 if(coeffIndex > 0 && coeffIndex <=
p_degree) {
1173 derivative = pow(time, coeffIndex);
1175 else if(coeffIndex == 0) {
1179 QString msg =
"Unable to evaluate the derivative of the SPICE position fit polynomial for " 1180 "the given coefficient index [" +
toString(coeffIndex) +
"]. " 1181 "Index is negative or exceeds degree of polynomial [" 1198 QString msg =
"No velocity vector available";
1234 std::vector<double>::iterator pos;
1246 if(cacheIndex < 0) cacheIndex = 0;
1251 std::vector<double> p2 =
p_cache[cacheIndex+1];
1252 std::vector<double> p1 =
p_cache[cacheIndex];
1261 p_velocity[0] = (p2[0] - p1[0]) * mult + p1[0];
1262 p_velocity[1] = (p2[1] - p1[1]) * mult + p1[1];
1263 p_velocity[2] = (p2[2] - p1[2]) * mult + p1[2];
1299 vector<double> xvalues(
p_cache.size());
1300 vector<double> xhermiteYValues(
p_cache.size());
1301 vector<double> yhermiteYValues(
p_cache.size());
1302 vector<double> zhermiteYValues(
p_cache.size());
1304 vector<double> xhermiteVelocities(
p_cache.size());
1305 vector<double> yhermiteVelocities(
p_cache.size());
1306 vector<double> zhermiteVelocities(
p_cache.size());
1308 for(
unsigned int i = 0; i <
p_cache.size(); i++) {
1309 vector<double> &cache =
p_cache[i];
1313 xhermiteYValues[i] = cache[0];
1314 yhermiteYValues[i] = cache[1];
1315 zhermiteYValues[i] = cache[2];
1319 xhermiteVelocities[i] = cacheVelocity[0];
1320 yhermiteVelocities[i] = cacheVelocity[1];
1321 zhermiteVelocities[i] = cacheVelocity[2];
1424 std::vector<double> hermiteVelocity =
p_velocity;
1427 for (
int index = 0; index < 3; index++) {
1486 "Source type is not Memcache, cannot convert.",
1499 vector <int> inputIndices;
1500 inputIndices.push_back(0);
1501 inputIndices.push_back(n / 2);
1502 inputIndices.push_back(n);
1505 vector <int> indexList =
HermiteIndices(tolerance, inputIndices);
1508 for(
int i = n; i >= 0; i--) {
1509 if(!binary_search(indexList.begin(), indexList.end(), i)) {
1542 unsigned int n = indexList.size();
1548 for(
unsigned int i = 0; i < indexList.size(); i++) {
1568 for(
unsigned int i = indexList.size() - 1; i > 0; i--) {
1574 for(
int line = indexList[i-1] + 1; line < indexList[i]; line++) {
1582 if(xerror > tolerance || yerror > tolerance || zerror > tolerance) {
1588 if(xerror < tolerance && yerror < tolerance && zerror < tolerance) {
1594 indexList.push_back((indexList[i] + indexList[i-1]) / 2);
1598 if(indexList.size() > n) {
1599 sort(indexList.begin(), indexList.end());
1659 for(
int icoef =
p_degree + 1; icoef <= degree; icoef++) {
1660 coefX.push_back(0.);
1661 coefY.push_back(0.);
1662 coefZ.push_back(0.);
1669 std::vector<double> coefX(degree + 1),
1673 for(
int icoef = 0; icoef <= degree; icoef++) {
1708 double cacheSlope = 0.0;
1741 double velocity = 0.;
1743 for (
int icoef=1; icoef <=
p_degree; icoef++) {
1766 double diffTime = timeEt -
p_et;
1767 std::vector<double> extrapPos(3, 0.);
1786 "Hermite coordinates only available for PolyFunctionOverHermiteConstant",
1795 return hermiteCoordinate;
1880 const QString &refFrame,
1881 const QString &abcorr,
1882 double state[6],
bool &hasVelocity,
1883 double &lightTime)
const {
1889 spkez_c((SpiceInt) target, (SpiceDouble) et, refFrame.toLatin1().data(),
1890 abcorr.toLatin1().data(), (SpiceInt) observer, state, &lightTime);
1895 SpiceBoolean spfailure = failed_c();
1898 hasVelocity =
false;
1900 spkezp_c((SpiceInt) target, (SpiceDouble) et, refFrame.toLatin1().data(),
1901 abcorr.toLatin1().data(), (SpiceInt) observer, state, &lightTime);
1932 const bool &hasVelocity) {
1938 if ( hasVelocity ) {
1952 if (m_swapObserverTarget) {
int Records() const
Returns the number of records.
int getObserverCode() const
Returns observer code.
double p_timeScale
Time scale used in fit equations.
Object is reading from splined table.
void CacheLabel(Table &table)
Add labels to a SpicePosition table.
const std::vector< double > & GetCenterCoordinate()
Compute and return the coordinate at the center time.
double p_timeBias
iTime bias when reading kernels
Source p_source
Enumerated value for the location of the SPK information used.
double GetLightTime() const
Return the light time coorection value.
virtual ~SpicePosition()
Destructor.
void SetCoefficients(const std::vector< double > &coefs)
Set the coefficients for the equation.
Object is calculated from nth degree polynomial.
int p_degree
Degree of polynomial function fit to the coordinates of the position.
virtual void SetAberrationCorrection(const QString &correction)
Set the aberration correction (light time)
std::vector< double > Extrapolate(double timeEt)
Extrapolate position for a given time assuming a constant velocity.
Utility class for creating and using cartesean line equations.
void SetTimeBias(double timeBias)
Apply a time bias when invoking SetEphemerisTime method.
int p_targetCode
target body code
double Intercept()
Compute the intercept of the line.
OverrideType p_override
Time base and scale override options;.
double p_fullCacheStartTime
Original start time of the complete cache after spiceinit.
Nth degree Polynomial with one variable.
Object is reading from cached table.
double EphemerisTime() const
Return the current ephemeris time.
int getTargetCode() const
Returns target code.
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 ...
void ComputeBaseTime()
Compute the base time using cached times.
NumericalApproximation provides various numerical analysis methods of interpolation, extrapolation and approximation of a tabulated set of x, y data.
double ComputeVelocityInTime(PartialType var)
Compute the velocity with respect to time instead of scaled time.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
void SetEphemerisTimePolyFunctionOverHermiteConstant()
This is a protected method that is called by SetEphemerisTime() when Source type is PolyFunctionOverH...
double toDouble(const QString &string)
Global function to convert from a string to a double.
This error is for when a programmer made an API call that was illegal.
A type of error that occurred when performing an actual I/O operation.
double p_fullCacheEndTime
Original end time of the complete cache after spiceinit.
double EvaluateCubicHermiteFirstDeriv(const double a)
Approximates the first derivative of the data set function evaluated at the given domain value for Cu...
void LoadCache(double startTime, double endTime, int size)
Cache J2000 position over a time range.
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.
void init(int targetCode, int observerCode, const bool &swapObserverTarget=false)
Internal initialization of the object support observer/target swap.
void LoadTimeCache()
Load the time cache.
void AddCubicHermiteDeriv(unsigned int n, double *fprimeOfx)
Adds values for the first derivatives of the data points.
double p_fullCacheSize
Orignial size of the complete cache after spiceinit.
bool hasKeyword(const QString &kname, FindOptions opts) const
See if a keyword is in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within ...
void ReloadCache()
Cache J2000 positions over existing cached time range using polynomials.
Table Cache(const QString &tableName)
Return a table with J2000 positions.
Cubic Spline interpolation using the Hermite cubic polynomial.
void SetEphemerisTimePolyFunction()
This is a protected method that is called by SetEphemerisTime() when Source type is PolyFunction...
double Evaluate(const double a, const ExtrapType &etype=ThrowError)
Calculates interpolated or extrapolated value of tabulated data set for given domain value...
std::vector< double > p_coordinate
J2000 position at time et.
NumericalApproximation * p_xhermite
Hermite spline for x coordinate if Source == HermiteCache.
Object is reading from splined.
std::vector< double > p_coefficients[3]
Coefficients of polynomials fit to 3 coordinates.
virtual QString GetAberrationCorrection() const
Returns current state of stellar aberration correction.
double p_baseTime
Base time used in fit equations.
double getAdjustedEphemerisTime() const
Returns adjusted ephemeris time.
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
void ClearCache()
Removes the entire cache from memory.
ExtrapType
This enum defines the manner in which a value outside of the domain should be handled if passed to th...
#define _FILEINFO_
Macro for the filename and line number.
bool p_hasVelocity
Flag to indicate velocity is available.
QString p_aberrationCorrection
Light time correction to apply.
A single keyword-value pair.
void setStateVector(const double state[6], const bool &hasVelocity)
Sets the state of target relative to observer.
const std::vector< double > & Coordinate()
Return the current J2000 position.
void SetPolynomialDegree(int degree)
Set the polynomial degree.
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...
int p_observerCode
observer body code
std::vector< int > HermiteIndices(double tol, std::vector< int > indexList)
This method is called by Memcache2HermiteCache() to determine which indices from the orginal cache sh...
double p_overrideBaseTime
Value set by caller to override computed base time.
NumericalApproximation * p_zhermite
Hermite spline for z coordinate if Source == HermiteCache.
Generic least square fitting class.
void SetEphemerisTimeHermiteCache()
This is a protected method that is called by SetEphemerisTime() when Source type is HermiteCache...
The values in the field are 8 byte doubles.
void Memcache2HermiteCache(double tolerance)
This method reduces the cache for position, time and velocity to the minimum number of values needed ...
double p_et
Current ephemeris time.
double DPolynomial(const int coeffIndex)
Evaluate the derivative of the fit polynomial (parabola) defined by the given coefficients with respe...
void AddKnown(const std::vector< double > &input, double expected, double weight=1.0)
Invoke this method for each set of knowns.
double Coefficient(int i) const
Returns the ith coefficient.
void SetEphemerisTimeMemcache()
This is a protected method that is called by SetEphemerisTime() when Source type is Memcache...
QString Name() const
Accessor method that returns a string containing the Blob name.
std::vector< double > p_velocity
J2000 velocity at time et.
bool p_degreeApplied
Flag indicating whether or not a polynomial.
Class for storing Table blobs information.
NumericalApproximation * p_yhermite
Hermite spline for y coordinate if Source == HermiteCache.
void AddData(const double x, const double y)
Add a datapoint to the set.
double Evaluate(const std::vector< double > &vars)
Compute the equation using the input variables.
std::vector< double > VelocityPartial(SpicePosition::PartialType partialVar, int coeffIndex)
Compute the derivative of the velocity with respect to the specified variable.
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
const std::vector< double > & Velocity()
Return the current J2000 velocity.
Namespace for ISIS/Bullet specific routines.
Table LineCache(const QString &tableName)
Return a table with J2000 to reference positions.
int Fields() const
Returns the number of fields that are currently in the record.
void setLightTime(const double &lightTime)
Inheritors can set the light time if indicated.
Table LoadHermiteCache(const QString &tableName)
Cache J2000 position over existing cached time range using polynomials stored as Hermite cubic spline...
const std::vector< double > & SetEphemerisTime(double et)
Return J2000 coordinate at given time.
Class for storing an Isis::Table's field information.
PvlObject & Label()
Accessor method that returns a PvlObject containing the Blob label.
double m_lt
!< Swap traditional order
Evaluate() attempts to extrapolate if a is outside of the domain. This is only valid for NumericalApp...
std::vector< std::vector< double > > p_cacheVelocity
Cached velocities.
std::vector< double > HermiteCoordinate()
This method returns the Hermite coordinate for the current time for PolyFunctionOverHermiteConstant f...
SpicePosition(int targetCode, int observerCode)
Construct an empty SpicePosition class using valid body codes.
Object is reading directly from the kernels.
std::vector< double > p_cacheTime
iTime for corresponding position
double p_overrideTimeScale
Value set by caller to override computed time scale.
double Slope()
Compute the slope of the line.
virtual void SetEphemerisTimeSpice()
This is a protected method that is called by SetEphemerisTime() when Source type is Spice...
double GetTimeBias() const
Returns the value of the time bias added to ET.
int Solve(Isis::LeastSquares::SolveMethod method=SVD)
After all the data has been registered through AddKnown, invoke this method to solve the system of eq...
int Coefficients() const
Returns the number of coefficients for the equation.
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 ...
std::vector< std::vector< double > > p_cache
Cached positions.
Source
This enum indicates the status of the object.
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...