Unverified Commit 37d0fd4e authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by GitHub
Browse files

Search Fixes (#53)



* fixed bug where cks were using interval scope

* added a fix for conda-forge

* fixes

* readded prefixes

* Update getTargetStates and getTargetOrientations endpoints

* added ability to pass in kernels on top of searches

* Update quality params to list type

* trigger pipeline

* Update test

* Add kernelList param to fastapi endpoints

* Add kernelList and searchKernels params

* Return kernels as part of pair

* Fix typo

* updated tests

* fixed python tests

* fixed lro test

* Add cpp api framework

* Update tests

* changed cache behavior

* missed a spot

* fixed tests

---------

Co-authored-by: default avatarChristine Kim <chkim@usgs.gov>
parent 41df37e0
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -68,7 +68,8 @@ if(SPICEQL_BUILD_LIB)
                          ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/memoized_functions.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/config.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/inventory.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/inventoryimpl.cpp)
                          ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/inventoryimpl.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/api.cpp)


  set(SPICEQL_HEADER_FILES ${SPICEQL_BUILD_INCLUDE_DIR}/spiceql.h
@@ -79,9 +80,11 @@ if(SPICEQL_BUILD_LIB)
                           ${SPICEQL_BUILD_INCLUDE_DIR}/query.h
                           ${SPICEQL_BUILD_INCLUDE_DIR}/config.h
                           ${SPICEQL_BUILD_INCLUDE_DIR}/inventory.h
                           ${SPICEQL_BUILD_INCLUDE_DIR}/inventoryimpl.h)
                           ${SPICEQL_BUILD_INCLUDE_DIR}/inventoryimpl.h
                           ${SPICEQL_BUILD_INCLUDE_DIR}/api.h)

  set(SPICEQL_PRIVATE_HEADER_FILES ${SPICEQL_BUILD_INCLUDE_DIR}/memo.h)
  set(SPICEQL_PRIVATE_HEADER_FILES ${SPICEQL_BUILD_INCLUDE_DIR}/memo.h
                                   ${SPICEQL_BUILD_INCLUDE_DIR}/restincurl.h)

  set(SPICEQL_CONFIG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/apollo15.json 
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/apollo16.json
+6 −1
Original line number Diff line number Diff line
@@ -8,6 +8,11 @@
    },
    "sclk" : {
      "kernels" : ["lro_clkcor_[0-9]{7}_v[0-9]{2}.tsc$"]
    },
    "tspk" : { 
       "noquality" : { 
        "kernels" : "^de421.bsp$"
       }
    }
  },
  "moc" : {
@@ -29,7 +34,7 @@
  "lroc" : {
    "ck" : {
      "reconstructed" : {
        "kernels" : ["lrolc_[0-9]{7}_[0-9]{7}_v[0-9]{2}.bc$", "soc31_[0-9]{7}_[0-9]{7}_v[0-9]{2}.bc$"]
        "kernels" : [ "soc31_[0-9]{7}_[0-9]{7}_v[0-9]{2}.bc$", "lrolc_[0-9]{7}_[0-9]{7}_v[0-9]{2}.bc$"]
      }
    },
    "ik" : {

SpiceQL/include/api.h

0 → 100644
+224 −0
Original line number Diff line number Diff line
#pragma once

#include <string>
#include <vector>
#include <nlohmann/json.hpp>

namespace SpiceQL {
    std::string url_encode(const std::string &value);
    nlohmann::json spiceAPIQuery(std::string functionName, nlohmann::json args, std::string method="GET");
    
    /**
     * @brief Gives the positions and velocities for a given frame given a set of ephemeris times
     *
     * Mostly a C++ wrap for NAIF's spkezr_c
     *
     * @param ets ephemeris times at which you want to obtain the target state
     * @param target NAIF ID for the target frame
     * @param observer NAIF ID for the observing frame
     * @param frame The reference frame in which to get the positions in
     * @param abcorr aborration correction flag, default it NONE.
     *        This can set to:
     *           "NONE" - No correction
     *        For the "reception" case, i.e. photons from the target being recieved by the observer at the given time.
     *           "LT"   - One way light time correction
     *           "LT+S" - Correct for one-way light time and stellar aberration correction
     *           "CN"   - Converging Newtonian light time correction
     *           "CN+S" - Converged Newtonian light time correction and stellar aberration correction
     *        For the "transmission" case, i.e. photons emitted from the oberver hitting at target at the given time
     *           "XLT"   - One-way light time correction using a newtonian formulation
     *           "XLT+S" - One-way light time and stellar aberration correction using a newtonian formulation
     *           "XCN"   - converged Newtonian light time correction
     *           "XCN+S" - converged Newtonian light time correction and stellar aberration correction.
     * @param mission Config subset as it relates to the mission
     * @param ckQualities vector of strings describing the quality of cks to try and obtain
     * @param spkQualities string of strings describing the quality of spks to try and obtain
     * @param searchKernels bool Whether to search the kernels for the user
     *
     * @see SpiceQL::getTargetState
     * @see Kernel::Quality
     *
     * @return A vector of vectors with a Nx7 state vector of positions and velocities in x,y,z,vx,vy,vz format followed by the light time adjustment.
     **/
    std::pair<std::vector<std::vector<double>>, nlohmann::json> getTargetStates(std::vector<double> ets, std::string target, std::string observer, std::string frame, std::string abcorr, std::string mission, std::vector<std::string> ckQualities={"smithed", "reconstructed"}, std::vector<std::string> spkQualities={"smithed", "reconstructed"}, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});
    
    /**
     * @brief Gives quaternion and angular velocity for a given frame at a set of ephemeris times
     *
     * Gets orientations for an input frame in some reference frame.
     * The orientations returned from this function can be used to transform a position
     * in the source frame to the ref frame.
     *
     * @param ets ephemeris times at which you want to optain the target pointing
     * @param toframe the source frame's NAIF code.
     * @param refframe the reference frame's NAIF code, orientations are relative to this reference frame
     * @param mission Config subset as it relates to the mission
     * @param ckQualities vector of string describing the quality of cks to try and obtain
     * @param searchKernels bool Whether to search the kernels for the user
     *
     * @see SpiceQL::getTargetOrientation
     *
     * @returns Vector of SPICE-style quaternions (w,x,y,z) and optional angular velocity (4 element without angular velocity, 7 element with)
     **/
    std::pair<std::vector<std::vector<double>>, nlohmann::json> getTargetOrientations(std::vector<double> ets, int toFrame, int refFrame, std::string mission, std::vector<std::string> ckQualities={"smithed", "reconstructed"}, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});
    
    /**
     * @brief Converts a given string spacecraft clock time to an ephemeris time
     *
     * Given a known frame code strSclkToEt converts a given spacecraft clock time as a string
     * to an ephemeris time. Call this function if your clock time looks something like:
     * 1/281199081:48971
     *
     * @param frameCode int Frame id to use
     * @param sclk string Spacecraft Clock formatted as a string
     * @param mission string Mission name as it relates to the config files
     * @param searchKernels bool Whether to search the kernels for the user
     * @return double
     */
    std::pair<double, nlohmann::json> strSclkToEt(int frameCode, std::string sclk, std::string mission, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});

    /**
     * @brief Converts a given double spacecraft clock time to an ephemeris time
     *
     * Given a known frame code doubleSclkToEt converts a given spacecraft clock time as a double
     * to an ephemeris time. Call this function if your clock time looks something like:
     * 922997380.174174
     *
     * @param frameCode int Frame id to use
     * @param sclk int Spacecraft Clock formatted as an int
     * @param mission string Mission name as it relates to the config files
     * @param searchKernels bool Whether to search the kernels for the user
     * @return double
     */
    std::pair<double, nlohmann::json> doubleSclkToEt(int frameCode, double sclk, std::string mission, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});

    /**
     * @brief convert a UTC string to an ephemeris time
     *
     * Basically a wrapper around NAIF's cspice str2et function except it also temporarily loads the required kernels.
     * See Also: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/str2et_c.html
     *
     * @param et UTC string, e.g. "1988 June 13, 12:29:48 TDB"
     * @param searchKernels bool Whether to search the kernels for the user
     * @returns double precision ephemeris time
     **/
    std::pair<double, nlohmann::json> utcToEt(std::string utc, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});

    /**
     * @brief convert et string to a UTC string
     *
     * Basically a wrapper around NAIF's cspice et2utc_c function except it also temporarily loads the required kernels.
     * See Also: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/et2utc_c.html
     *
     * @param et ephemeris time
     * @param precision number of decimal 
     * @param searchKernels bool Whether to search the kernels for the user
     * @returns double precision ephemeris time
     **/
    std::pair<std::string, nlohmann::json> etToUtc(double et, std::string format, double precision, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});

    /**
     * @brief Switch between NAIF frame string name to integer frame code
     *
     * See <a href="https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/naif_ids.html">NAIF's Docs on frame codes</a> for more information
     *
     * @param frame String frame name to translate to a NAIF code
     * @param mission Mission name as it relates to the config files
     * @param searchKernels bool Whether to search the kernels for the user
     * @return integer Naif frame code
     **/
    std::pair<int, nlohmann::json> translateNameToCode(std::string frame, std::string mission, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});

    /**
     * @brief Switch between NAIF frame integer code to string frame name
     *
     * See <a href="https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/naif_ids.html">NAIF's Docs on frame codes</a> for more information
     *
     * @param frame int NAIF frame code to translate
     * @param searchKernels bool Whether to search the kernels for the user
     * @param mission Mission name as it relates to the config files
     * @return string Naif frame name
     **/
    std::pair<std::string, nlohmann::json> translateCodeToName(int frame, std::string mission, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});

    /**
     * @brief Get the center, class id, and class of a given frame
     *
     * See <a href="https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/naif_ids.html">NAIF's Docs on frame codes</a> for more information
     *
     * @param frame String frame name to translate to a NAIF code
     * @param mission Mission name as it relates to the config files
     * @param searchKernels bool Whether to search the kernels for the user
     * @return 3 element vector of the given frames center, class id, and class
     **/
    std::pair<std::vector<int>, nlohmann::json> getFrameInfo(int frame, std::string mission, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});

     /**
    * @brief returns frame name and frame code associated to the target ID.
    *
    *  Takes in a target id and returns the frame name and frame code in json format
    * 
    * @param targetId target ID
    * @param mission mission name as it relates to the config files
    * @param searchKernels bool Whether to search the kernels for the user
    * @returns json of frame name and frame code
    **/
    std::pair<nlohmann::json, nlohmann::json> getTargetFrameInfo(int targetId, std::string mission, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});

    /**
    * @brief returns kernel values for a specific mission in the form of a json
    *
    *  Takes in a kernel key and returns the value associated with the inputted mission as a json
    * 
    * @param key key - Kernel to get values from 
    * @param mission mission name
    * @param searchKernels bool Whether to search the kernels for the user
    * @returns json of values
    **/
    std::pair<nlohmann::json, nlohmann::json> findMissionKeywords(std::string key, std::string mission, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});

    /**
    * @brief returns Target values in the form of a vector
    *
    *  Takes in a target and key and returns the value associated in the form of vector.
    *  Note: This function is mainly for obtaining target keywords. For obtaining other values, use findMissionKeywords.
    * 
    * @param key keyword for desired values
    * @param mission mission name as it relates to the config files
    * @param searchKernels bool Whether to search the kernels for the user
    * @returns vector of values
    **/
    std::pair<nlohmann::json, nlohmann::json> findTargetKeywords(std::string key, std::string mission, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});

    /**
     * @brief Given an ephemeris time and a starting frame, find the path from that starting frame to J2000 (1)
     *
     * This function uses NAIF routines and builds a path from the initalframe to J2000 making
     * note of all the in between frames
     *
     * @param et ephemeris times at which you want to optain the frame trace
     * @param initialFrame the initial frame's NAIF code.
     * @param mission Config subset as it relates to the mission
     * @param ckQualities vector of strings describing the quality of cks to try and obtain
     * @param searchKernels bool Whether to search the kernels for the user
     *
     * @returns A two element vector of vectors ints, where the first element is the sequence of time dependent frames
     * and the second is the sequence of constant frames
     **/
    std::pair<std::vector<std::vector<int>>, nlohmann::json> frameTrace(double et, int initialFrame, std::string mission, std::vector<std::string> ckQualities={"smithed", "reconstructed"}, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});

    /**
     * @brief Extracts all segment times between observStart and observeEnd
     *
     * Givven an observation start and observation end, extract all times assocaited
     * with segments in a CK file. The times returned are all times assocaited with
     * concrete CK segment times with no interpolation.
     *
     * @param observStart Ephemeris time to start searching at
     * @param observEnd Ephemeris time to stop searching at
     * @param targetFrame Target reference frame to get ephemeris data in
     * @param ckQualities vector of string describing the quality of cks to try and obtain
     * @returns A list of times
     **/
    std::pair<std::vector<double>, nlohmann::json> extractExactCkTimes(double observStart, double observEnd, int targetFrame, std::string mission, std::vector<std::string> ckQualities={"smithed", "reconstructed"}, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});
}
 No newline at end of file
+5 −3
Original line number Diff line number Diff line
@@ -18,11 +18,13 @@
namespace SpiceQL {
    namespace Inventory { 
        nlohmann::json search_for_kernelset(std::string spiceql_name, std::vector<std::string> types=KERNEL_TYPES, double start_time=-std::numeric_limits<double>::max(), double stop_time=std::numeric_limits<double>::max(), 
                                      std::string ckQuality="smithed", std::string spkQuality="smithed", bool enforce_quality=false);
                                      std::vector<std::string> ckQualities={"smithed", "reconstructed"}, std::vector<std::string> spkQualities={"smithed", "reconstructed"}, bool enforce_quality=false);
        nlohmann::json search_for_kernelsets(std::vector<std::string> spiceql_names, std::vector<std::string> types=KERNEL_TYPES, double start_time=-std::numeric_limits<double>::max(), double stop_time=std::numeric_limits<double>::max(), 
                                      std::string ckQuality="smithed", std::string spkQuality="smithed", bool enforce_quality=false,  bool overwrite=false);  
                                      std::vector<std::string> ckQualities={"smithed", "reconstructed"}, std::vector<std::string> spkQualities={"smithed", "reconstructed"}, bool enforce_quality=false, bool overwrite=false);    
        nlohmann::json search_for_kernelset_from_regex(std::vector<std::string> list);

        std::string getDbFilePath();

        void create_database(); 
        void create_database(std::vector<std::string> mlist = {}); 
    }    
}
 No newline at end of file
+4 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ namespace SpiceQL {
  extern std::string DB_STOP_TIME_KEY; 
  extern std::string DB_TIME_FILES_KEY; 
  extern std::string DB_SS_TIME_INDICES_KEY; 
  extern std::string DB_SPICE_ROOT_KEY;

  std::string getCacheDir(); 
  std::string getHdfFile();
@@ -37,13 +38,13 @@ namespace SpiceQL {

  class InventoryImpl {
    public:
    InventoryImpl(bool force_regen=false); 
    InventoryImpl(bool force_regen=false, std::vector<std::string> mlist = {}); 
    template<class T> T getKey(std::string key);
    void write_database();
    nlohmann::json search_for_kernelset(std::string spiceql_name, std::vector<Kernel::Type> types, double start_time=-std::numeric_limits<double>::max(), double stop_time=std::numeric_limits<double>::max(),
                                            Kernel::Quality ckQuality=Kernel::Quality::SMITHED, Kernel::Quality spkQuality=Kernel::Quality::SMITHED,  bool enforce_quality=false);
                                            std::vector<Kernel::Quality> ckQualities={Kernel::Quality::SMITHED, Kernel::Quality::RECONSTRUCTED}, std::vector<Kernel::Quality> spkQualities={Kernel::Quality::SMITHED, Kernel::Quality::RECONSTRUCTED},  bool enforce_quality=false);
    nlohmann::json search_for_kernelsets(std::vector<std::string> spiceql_names, std::vector<Kernel::Type> types, double start_time=-std::numeric_limits<double>::max(), double stop_time=std::numeric_limits<double>::max(),
                                            Kernel::Quality ckQuality=Kernel::Quality::SMITHED, Kernel::Quality spkQuality=Kernel::Quality::SMITHED,  bool enforce_quality=false, bool overwrite=false);
                                            std::vector<Kernel::Quality> ckQualities={Kernel::Quality::SMITHED, Kernel::Quality::RECONSTRUCTED}, std::vector<Kernel::Quality> spkQualities={Kernel::Quality::SMITHED, Kernel::Quality::RECONSTRUCTED},  bool enforce_quality=false, bool overwrite=false);
    nlohmann::json m_json_inventory; 

    std::map<std::string, std::vector<std::string>> m_nontimedep_kerns;  
Loading