Unverified Commit aab45637 authored by acpaquette's avatar acpaquette Committed by GitHub
Browse files

Kernel Timing Update (#4806)



* Added Ckwriter to write Timing Offset to Comments (#4720)

* ckwriter adds timing offset to kernel's comments.

* account for timing padding.

* kerneldbgen adds timing offset if found in comments.

* Added documentation.

* Updated ckwriter offset calculations and added spkwriter calculations (#4722)

* Corrected time offset calculations in ckwriter. Added time offset calculations to spkwriter. Added end time offsets.

* Fixed padding checks.

* Fixes ckwriter and spkwriter test failures. (#4726)

* Kerneldb changes for spice kernel timing (#4728)

* Added checks for instruments and spice kernel timing offsets

* Addressed PR feedback

* Addressed PR feedback

* Removed extra whitespace

* Kernel Timing Tests (#4729)

* Added tests for ckwriter and spkwriter. Converted kerneldbgen tests to GTests and added tests.

* Small updates

* Fixes mex module timeout errors.

* Removed large kernel files from ck tests.

* KernelDB Tests (#4807)

* Added tests for ckwriter and spkwriter. Converted kerneldbgen tests to GTests and added tests.

* Removed large kernel files from ck tests.

* KernelDB test.

* Added comments and use sc clock count for offset

* Reverted logic back to start/stop time

* Fixed syntax errors

* Added local sclks

* Modified sclk path to point to local data area

Co-authored-by: default avatarAmy Stamile <74275278+amystamile-usgs@users.noreply.github.com>
Co-authored-by: default avatarAustinSanders <arsanders@usgs.gov>
Co-authored-by: default avatarAustin Sanders <austinsanders1993@gmail.com>
parent e0868b9b
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -158,7 +158,6 @@ Keywords when running CAMSTATS. [#3605](https://github.com/USGS-Astrogeology/IS
- Fixed issue where serial numbers for Kaguya TC and MI image could not be generated. [4235](https://github.com/USGS-Astrogeology/ISIS3/issues/4235)
- Fixed hardcoded file naming in the hijitter app dealing with output from pipeline. [#4372](https://github.com/USGS-Astrogeology/ISIS3/pull/4372)
- Fixed "About Qview" to point to website documentation. [4333](https://github.com/USGS-Astrogeology/ISIS3/issues/4333)
- Fixed bug where the time bias was not being added to the ephemeris times in ckwriter. [4129](https://github.com/USGS-Astrogeology/ISIS3/issues/4129)

### Changed

+55 −3
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
#include "FileName.h"
#include "IException.h"
#include "IString.h"
#include "iTime.h"
#include "NaifStatus.h"
#include "CkSpiceSegment.h"
#include "Table.h"
@@ -210,13 +211,25 @@ void CkSpiceSegment::import(Cube &cube, const QString &tblname) {
    if (!value.isEmpty()) { _target = value; }
     _camVersion = _kernels.CameraVersion();

    QString labStartTime = getKeyValue(*label, "StartTime");
    QString labEndTime;
    value = getKeyValue(*label, "StopTime");
    if (!value.isEmpty()) {
      labEndTime = value;
    }
    else {
      labEndTime = labStartTime;
    }
    iTime etLabStart(labStartTime);
    iTime etLabEnd(labEndTime);

    //  Get the SPICE data
    Table ckCache = camera->instrumentRotation()->LineCache(tblname);
    SMatrix spice = load(ckCache);

    _quats = getQuaternions(spice);
    _avvs = getAngularVelocities(spice);
    _times = getTimes(spice, camera->instrumentRotation()->TimeBias());
    _times = getTimes(spice);

    _startTime = _times[0];
    _endTime = _times[size(_times)-1];
@@ -260,6 +273,33 @@ void CkSpiceSegment::import(Cube &cube, const QString &tblname) {

    _utcStartTime = toUTC(startTime());
    _utcEndTime   = toUTC(endTime());

    // These offsets are absolute values. If there is a StartOffset, then this
    // must be subtracted from the label's original start time and if there is
    // an EndOffset, then the offset must be added to the label's original end
    // time.
    _startOffset =  etLabStart.Et() - startTime();
    _endOffset =  etLabEnd.Et() - endTime();


    // Label start/end times are 3 decimal places, so round offsets to match.
    _startOffset = qRound(_startOffset * 1000.0) / 1000.0;
    _endOffset = qRound(_endOffset * 1000.0) / 1000.0;

    // account for padding
    if (_startOffset >= 0.003) {
      _startOffset = 0.0;
    }
    else {
      _startOffset = fabs(_startOffset);
    }
    if (_endOffset <= 0.003) {
      _endOffset = 0.0;
    }
    else {
      _endOffset = fabs(_endOffset);
    }

    _kernels.UnLoad("CK,FK,SCLK,LSK,IAK");

  } catch ( IException &ie  ) {
@@ -303,13 +343,13 @@ CkSpiceSegment::SMatrix CkSpiceSegment::getAngularVelocities(const SMatrix &spic
}


CkSpiceSegment::SVector CkSpiceSegment::getTimes(const SMatrix &spice, const double timeBias) const {
CkSpiceSegment::SVector CkSpiceSegment::getTimes(const SMatrix &spice) const {
  int nrecs = size(spice);
  SVector etdp(nrecs);
  int tcol = spice.dim2() - 1;

  for ( int i = 0 ; i < nrecs ; i++ ) {
    etdp[i] = spice[i][tcol] + timeBias;
    etdp[i] = spice[i][tcol];
  }
  return (etdp);
}
@@ -688,6 +728,16 @@ QString CkSpiceSegment::getComment() const {
"  RefFrame:   " << _refFrame << endl <<
"  Records:    " << size() << endl;

  if (_startOffset != 0) {
    comment <<
"  StartOffset: " << _startOffset << endl;
  }

  if (_endOffset != 0) {
    comment <<
"  EndOffset: " << _endOffset << endl;
  }

  QString hasAV = (size(_avvs) > 0) ? "YES" : "NO";
  comment <<
"  HasAV:      " << hasAV << endl;
@@ -715,6 +765,8 @@ void CkSpiceSegment::init() {
  _instId = _target = "UNKNOWN";
  _instCode = 0;
  _instFrame = _refFrame = "";
  _startOffset = 0.0;
  _endOffset = 0.0;
  _quats = _avvs = SMatrix(0,0);
  _times = SVector(0);
  _tickRate = 0.0;
+16 −11
Original line number Diff line number Diff line
@@ -87,7 +87,10 @@ class PvlObject;
 * @history 2019-12-05 Adam Paquette - Changed how kernels are loaded so CkSpiceSegment
 *                          no longer needs to use the Spice class.
 *
 * @history 2021-03-23 Kaitlyn Lee - Added time bias to ET times in getTimes(). Fixes #4129
 * @history 2021-12-22 Amy Stamile - Added timing offset information to kernel comments
 *                          by calculating difference between label StartTime and camera model
 *                          StartTime. This is to allow for spiceinit to handle offsets
 *                          when finding associated smithed kernels. References #3363.
 */
class CkSpiceSegment {
  public:
@@ -156,6 +159,8 @@ class CkSpiceSegment {
    QString     _utcEndTime;   //  requires leap seconds kernel
    QString     _instId;       //  Instrument ID
    QString     _target;       //  Target name
    double      _startOffset;  // time offset between camera model and label start time
    double      _endOffset;    // time offset between camera model and label end time
    int         _instCode;     //  NAIF instrument code of the SPICE segment
    QString     _instFrame;    //  NAIF instrument frame
    QString     _refFrame;     //  NAIF reference frame
@@ -174,7 +179,7 @@ class CkSpiceSegment {
    SMatrix load(Table &cache);
    SMatrix getQuaternions(const SMatrix &spice) const;
    SMatrix getAngularVelocities(const SMatrix &spice) const;
    SVector getTimes(const SMatrix &spice, const double timeBias) const;
    SVector getTimes(const SMatrix &spice) const;

    bool getTimeDependentFrameIds(Table &table, int &toId, int &fromId) const;
    bool getFrameChains(Table &table, const int &leftBase,
+52 −0
Original line number Diff line number Diff line
@@ -37,7 +37,9 @@
#include "FileName.h"
#include "IException.h"
#include "IString.h"
#include "iTime.h"
#include "NaifStatus.h"
#include "Spice.h"
#include "SpkSegment.h"
#include "Table.h"

@@ -168,6 +170,43 @@ void SpkSegment::import(Cube &cube) {
    setStartTime(m_epochs[0]);
    setEndTime(m_epochs[size(m_epochs)-1]);

    Pvl *label = cube.label();
    QString labStartTime = getKeyValue(*label, "StartTime");
    QString labEndTime;
    QString value = getKeyValue(*label, "StopTime");
    if (!value.isEmpty()) {
      labEndTime = value;
    }
    else {
      labEndTime = labStartTime;
    }

    iTime etLabStart(labStartTime);
    iTime etLabEnd(labEndTime);

    m_startOffset = etLabStart.Et() - m_epochs[0];
    m_endOffset = etLabEnd.Et() - m_epochs[size(m_epochs)-1];

    // Label start/end times are 3 decimal places, so round offsets to match.
    m_startOffset = qRound(m_startOffset * 1000.0) / 1000.0;
    m_endOffset = qRound(m_endOffset * 1000.0) / 1000.0;

    // account for padding
    if (m_startOffset >= 0.003) {
      m_startOffset = 0.0;
    }
    else {
      m_startOffset = fabs(m_startOffset);
    }
    if (m_endOffset <= 0.003) {
      m_endOffset = 0.0;
    }
    else {
      m_endOffset = fabs(m_endOffset);
    }

    m_instId = getKeyValue(*label, "InstrumentId");

  } catch ( IException &ie  ) {
    ostringstream mess;
    mess << "Failed to construct SPK content from ISIS file " << Source();
@@ -291,11 +330,22 @@ QString SpkSegment::getComment() const {
"  Segment ID:  " << Id() << " (ProductId)" << endl <<
"  StartTime:   " << utcStartTime() << endl <<
"  EndTime:     " << utcEndTime() << endl <<
"  Instrument:  " << m_instId << endl <<
"  Target Body: " << "Body " << m_body << ", " << m_bodyFrame << endl <<
"  Center Body: " << "Body " << m_center << ", " << m_centerFrame << endl <<
"  RefFrame:    " << m_refFrame << endl <<
"  Records:     " << size() << endl;

  if (m_startOffset != 0) {
    comment <<
"  StartOffset: " << m_startOffset << endl;
  }

  if (m_endOffset != 0) {
    comment <<
"  EndOffset:   " << m_endOffset << endl;
  }

  string hasVV = (m_hasVV) ? "YES" : "NO";
  comment <<
"  HasVV:       " << hasVV << endl;
@@ -358,10 +408,12 @@ void SpkSegment::init(const int spkType) {
  m_spkType = spkType;
  m_body = m_center = 1;
  m_bodyFrame = m_centerFrame = m_refFrame = "";
  m_instId = "UNKNOWN";
  m_states = SMatrix(0,0);
  m_epochs = SVector(0);
  m_hasVV = false;
  m_degree = 1;
  m_startOffset = 0.0;
  return;
}

+3 −0
Original line number Diff line number Diff line
@@ -108,12 +108,15 @@ class SpkSegment : public SpkSpiceSegment {
    int         m_body;         //  NAIF body code of the SPICE segment
    QString     m_bodyFrame;    //  NAIF body frame
    int         m_center;       //  NAIF center code of the SPICE segment
    QString     m_instId;       //  Instrument ID
    QString     m_centerFrame;  //  NAIF center frame
    QString     m_refFrame;     //  NAIF reference frame
    SMatrix     m_states;       //  Position states
    SVector     m_epochs;       //  ET times of records
    bool        m_hasVV;        //  Has velocity vectors?
    int         m_degree;       //  Degree of polynomial to fit in NAIF kernel
    double      m_startOffset;  // time offset between camera model and label start time
    double      m_endOffset;    // time offset between camera model and label end time

    // Internal processing methods
    void init(const int spkType = 13);
Loading