Commit 13d63d32 authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by GitHub
Browse files

Updated isd (#345)

* before merge storm

* std::invalid_arg doesn't exist?

* added more std except for linux

* we ❤️ C++ OOP, now featuring 100% more boilerplate

* tests

* comments

* FromThis to_this thanks to VIM shortcuts because damn

* miniconda download for mac seems to have died

* comments

* more consistant tabbing
parent 40898dd2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ install:
    if [ "$TRAVIS_OS_NAME" == "linux" ]; then
      wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
    else
      curl -o miniconda.sh  https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh;
      curl -o miniconda.sh  https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh;
    fi
  - bash miniconda.sh -b -p $HOME/miniconda
  - export PATH="$HOME/miniconda/bin:$PATH"
+45 −36
Original line number Diff line number Diff line
@@ -26,10 +26,10 @@ def to_isd(driver):

    meta_data = {}

    meta_data['IsisCameraVersion'] = driver.sensor_model_version
    meta_data['isis_camera_version'] = driver.sensor_model_version

    # interiror orientation
    meta_data['NaifKeywords'] = driver.naif_keywords
    meta_data['naif_keywords'] = driver.naif_keywords
    meta_data['detector_sample_summing'] = driver.sample_summing
    meta_data['detector_line_summing'] = driver.line_summing
    meta_data['focal_length_model'] = {
@@ -89,21 +89,24 @@ def to_isd(driver):

    # Reverse the frame order because ISIS orders frames as
    # (destination, intermediate, ..., intermediate, source)
    instrument_pointing['TimeDependentFrames'] = shortest_path(frame_chain, destination_frame, 1)
    instrument_pointing['time_dependent_frames'] = shortest_path(frame_chain, destination_frame, 1)
    time_dependent_rotation = frame_chain.compute_rotation(1, destination_frame)
    instrument_pointing['CkTableStartTime'] = time_dependent_rotation.times[0]
    instrument_pointing['CkTableEndTime'] = time_dependent_rotation.times[-1]
    instrument_pointing['CkTableOriginalSize'] = len(time_dependent_rotation.times)
    instrument_pointing['EphemerisTimes'] = time_dependent_rotation.times
    instrument_pointing['Quaternions'] = time_dependent_rotation.quats[:, [3, 0, 1, 2]]
    instrument_pointing['AngularVelocity'] = time_dependent_rotation.av
    instrument_pointing['ck_table_start_time'] = time_dependent_rotation.times[0]
    instrument_pointing['ck_table_end_time'] = time_dependent_rotation.times[-1]
    instrument_pointing['ck_table_original_size'] = len(time_dependent_rotation.times)
    instrument_pointing['ephemeris_times'] = time_dependent_rotation.times
    instrument_pointing['quaternions'] = time_dependent_rotation.quats[:, [3, 0, 1, 2]]
    instrument_pointing['angular_velocity'] = time_dependent_rotation.av

    # reference frame should be the last frame in the chain
    instrument_pointing["reference_frame"] = instrument_pointing['time_dependent_frames'][-1]

    # Reverse the frame order because ISIS orders frames as
    # (destination, intermediate, ..., intermediate, source)
    instrument_pointing['ConstantFrames'] = shortest_path(frame_chain, sensor_frame, destination_frame)
    instrument_pointing['constant_frames'] = shortest_path(frame_chain, sensor_frame, destination_frame)
    constant_rotation = frame_chain.compute_rotation(destination_frame, sensor_frame)
    instrument_pointing['ConstantRotation'] = constant_rotation.rotation_matrix().flatten()
    meta_data['InstrumentPointing'] = instrument_pointing
    instrument_pointing['constant_rotation'] = constant_rotation.rotation_matrix().flatten()
    meta_data['instrument_pointing'] = instrument_pointing

    body_rotation = {}
    source_frame, destination_frame, time_dependent_target_frame = frame_chain.last_time_dependent_frame_between(target_frame, 1)
@@ -111,51 +114,57 @@ def to_isd(driver):
    if source_frame != 1:
        # Reverse the frame order because ISIS orders frames as
        # (destination, intermediate, ..., intermediate, source)
        body_rotation['TimeDependentFrames'] = shortest_path(frame_chain, source_frame, 1)
        body_rotation['time_dependent_frames'] = shortest_path(frame_chain, source_frame, 1)
        time_dependent_rotation = frame_chain.compute_rotation(1, source_frame)
        body_rotation['CkTableStartTime'] = time_dependent_rotation.times[0]
        body_rotation['CkTableEndTime'] = time_dependent_rotation.times[-1]
        body_rotation['CkTableOriginalSize'] = len(time_dependent_rotation.times)
        body_rotation['EphemerisTimes'] = time_dependent_rotation.times
        body_rotation['Quaternions'] = time_dependent_rotation.quats[:, [3, 0, 1, 2]]
        body_rotation['AngularVelocity'] = time_dependent_rotation.av
        body_rotation['ck_table_start_time'] = time_dependent_rotation.times[0]
        body_rotation['ck_table_end_time'] = time_dependent_rotation.times[-1]
        body_rotation['ck_table_original_size'] = len(time_dependent_rotation.times)
        body_rotation['ephemeris_times'] = time_dependent_rotation.times
        body_rotation['quaternions'] = time_dependent_rotation.quats[:, [3, 0, 1, 2]]
        body_rotation['angular_velocity'] = time_dependent_rotation.av

    if source_frame != target_frame:
        # Reverse the frame order because ISIS orders frames as
        # (destination, intermediate, ..., intermediate, source)
        body_rotation['ConstantFrames'] = shortest_path(frame_chain, target_frame, source_frame)
        body_rotation['constant_frames'] = shortest_path(frame_chain, target_frame, source_frame)
        constant_rotation = frame_chain.compute_rotation(source_frame, target_frame)
        body_rotation['ConstantRotation'] = constant_rotation.rotation_matrix().flatten()
        body_rotation['constant_rotation'] = constant_rotation.rotation_matrix().flatten()

    meta_data['BodyRotation'] = body_rotation
    body_rotation["reference_frame"] = destination_frame
    meta_data['body_rotation'] = body_rotation

    j2000_rotation = frame_chain.compute_rotation(target_frame, 1)

    instrument_position = {}
    positions, velocities, times = driver.sensor_position
    instrument_position['SpkTableStartTime'] = times[0]
    instrument_position['SpkTableEndTime'] = times[-1]
    instrument_position['SpkTableOriginalSize'] = len(times)
    instrument_position['EphemerisTimes'] = times
    instrument_position['spk_table_start_time'] = times[0]
    instrument_position['spk_table_end_time'] = times[-1]
    instrument_position['spk_table_original_size'] = len(times)
    instrument_position['ephemeris_times'] = times
    # Rotate positions and velocities into J2000 then scale into kilometers
    velocities = j2000_rotation.rotate_velocity_at(positions, velocities, times)/1000
    positions = j2000_rotation.apply_at(positions, times)/1000
    instrument_position['Positions'] = positions
    instrument_position['Velocities'] = velocities
    meta_data['InstrumentPosition'] = instrument_position
    instrument_position['positions'] = positions
    instrument_position['velocities'] = velocities
    instrument_position["reference_frame"] = destination_frame

    meta_data['instrument_position'] = instrument_position

    sun_position = {}
    positions, velocities, times = driver.sun_position
    sun_position['SpkTableStartTime'] = times[0]
    sun_position['SpkTableEndTime'] = times[-1]
    sun_position['SpkTableOriginalSize'] = len(times)
    sun_position['EphemerisTimes'] = times
    sun_position['spk_table_start_time'] = times[0]
    sun_position['spk_table_end_time'] = times[-1]
    sun_position['spk_table_original_size'] = len(times)
    sun_position['ephemeris_times'] = times
    # Rotate positions and velocities into J2000 then scale into kilometers
    velocities = j2000_rotation.rotate_velocity_at(positions, velocities, times)/1000
    positions = j2000_rotation.apply_at(positions, times)/1000
    sun_position['Positions'] = positions
    sun_position['Velocities'] = velocities
    meta_data['SunPosition'] = sun_position
    sun_position['positions'] = positions
    sun_position['velocities'] = velocities
    sun_position["reference_frame"] = destination_frame

    meta_data['sun_position'] = sun_position


    # check that there is a valid sensor model name
    if 'name_model' not in meta_data:
+49 −2
Original line number Diff line number Diff line
@@ -3,9 +3,25 @@

#include <vector>

#include "Util.h"
#include "Vectors.h"

namespace ale {

  enum RotationInterpolation {
    SLERP, // Spherical interpolation
    NLERP // Normalized linear interpolation
  };

  /// Interpolation enum for defining different methods of interpolation
  enum PositionInterpolation {
    /// Interpolate using linear interpolation
    LINEAR = 0,
    /// Interpolate using a cubic spline
    SPLINE = 1,
    /// Interpolate using Lagrange polynomials up to 8th order
    LAGRANGE = 2,
  };

  /**
   * Linearly interpolate between two values.
   * @param x The first value.
@@ -22,7 +38,7 @@ namespace ale {
   */
  std::vector<double> linearInterpolate(const std::vector<double> &x, const std::vector<double> &y, double t);

  ale::Vec3d linearInterpolate(const ale::Vec3d &x, const ale::Vec3d &y, double t);
  Vec3d linearInterpolate(const Vec3d &x, const Vec3d &y, double t);

  /**
   * Compute the index of the first time to use when interpolating at a given time.
@@ -40,6 +56,37 @@ namespace ale {
   */
   std::vector<double> orderedVecMerge(const std::vector<double> &x, const std::vector<double> &y);


   /** The following helper functions are used to calculate the reduced states cache and cubic hermite
   to interpolate over it. They were migrated, with minor modifications, from
   Isis::NumericalApproximation **/

   /** Evaluates a cubic hermite at time, interpTime, between the appropriate two points in x. **/
   double evaluateCubicHermite(const double interpTime, const std::vector<double>& derivs,
                            const std::vector<double>& x, const std::vector<double>& y);

   /** Evaluate velocities using a Cubic Hermite Spline at a time a, within some interval in x, **/
   double evaluateCubicHermiteFirstDeriv(const double interpTime, const std::vector<double>& deriv,
                                     const std::vector<double>& times, const std::vector<double>& y);

   double lagrangeInterpolate(const std::vector<double>& times, const std::vector<double>& values,
                           double time, int order=8);
   double lagrangeInterpolateDerivative(const std::vector<double>& times, const std::vector<double>& values,
                                     double time, int order=8);

   /**
    *@brief Interpolates the spacecrafts position along a path generated from a set of points,
              times, and a time of observation
    *@param points A double vector of points
    *@param times A double vector of times
    *@param time A double to use as the time of observation
    *@param interp An interpolation enum dictating what type of interpolation to use
    *@param d The order of the derivative to generate when interpolating
                    (Currently supports 0, 1, and 2)
    *@return
   */
   double interpolate(std::vector<double> points, std::vector<double> times, double time, PositionInterpolation interp, int d);

}

#endif
+14 −14
Original line number Diff line number Diff line
@@ -5,11 +5,13 @@
#include <vector>
#include <map>

#include "Util.h"
#include <nlohmann/json.hpp>

#include "Distortion.h"

//#include "Rotation.h"
//#include "State.h"
#include "Rotation.h"
#include "States.h"
#include "Orientations.h"

namespace ale {

@@ -59,19 +61,17 @@ namespace ale {
    double starting_ephemeris_time;
    double center_ephemeris_time;

    double t0_ephemeris_time;
    double dt_ephemeris_time;
    json naif_keywords;
    
    double t0_quaternions;
    double dt_quaternions;
    PositionInterpolation interpMethod;
    
    json naif_keywords;
    Rotation const_rotation; 

    //Positions sensor_pos;
    //Positions sun_pos;
    States inst_pos;
    States sun_pos;

    //Rotation sensor_orientation;
    //Rotation body_orientaion;
    Orientations inst_pointing;
    Orientations body_rotation;
  };
}

+19 −4
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ namespace ale {
     * Construct a default empty orientation object
     */
    Orientations() {};
    
    /**
     * Construct an orientation object give a set of rotations
     * and optionally angular velocities at specific times.
@@ -19,8 +20,13 @@ namespace ale {
    Orientations(
      const std::vector<Rotation> &rotations,
      const std::vector<double> &times,
      const std::vector<Vec3d> &avs = std::vector<ale::Vec3d>()
      const std::vector<Vec3d> &avs = std::vector<ale::Vec3d>(),
      const int refFrame = 1, 
      const Rotation &constRot = Rotation(1, 0, 0, 0),
      const std::vector<int> const_frames = std::vector<int>(), 
      const std::vector<int> time_dependent_frames = std::vector<int>() 
    );

    /**
     * Orientations destructor
     */
@@ -29,9 +35,13 @@ namespace ale {
    /**
     * Const accessor methods
     */
    std::vector<Rotation> rotations() const;
    std::vector<ale::Vec3d> angularVelocities() const;
    std::vector<double> times() const;
    std::vector<Rotation> getRotations() const;
    std::vector<ale::Vec3d> getAngularVelocities() const;
    std::vector<double> getTimes() const;
    std::vector<int> getConstantFrames() const; 
    std::vector<int> getTimeDependentFrames() const;
    int getReferenceFrame() const;
    Rotation getConstantRotation() const; 

    /**
     * Get the interpolated rotation at a specific time.
@@ -40,6 +50,7 @@ namespace ale {
      double time,
      RotationInterpolation interpType=SLERP
    ) const;
    
    /**
     * Get the interpolated angular velocity at a specific time
     */
@@ -75,6 +86,10 @@ namespace ale {
    std::vector<Rotation> m_rotations;
    std::vector<ale::Vec3d> m_avs;
    std::vector<double> m_times;
    std::vector<int> m_timeDepFrames; 
    std::vector<int> m_constFrames; 
    Rotation m_constRotation;
    int m_refFrame; 
  };
}

Loading