Skip to content

Commit 37d0fd4

Browse files
Kelvinrrchkim-usgs
andauthored
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: Christine Kim <[email protected]>
1 parent 41df37e commit 37d0fd4

33 files changed

+3899
-966
lines changed

CMakeLists.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ if(SPICEQL_BUILD_LIB)
6868
${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/memoized_functions.cpp
6969
${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/config.cpp
7070
${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/inventory.cpp
71-
${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/inventoryimpl.cpp)
71+
${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/inventoryimpl.cpp
72+
${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/api.cpp)
7273

7374

7475
set(SPICEQL_HEADER_FILES ${SPICEQL_BUILD_INCLUDE_DIR}/spiceql.h
@@ -79,9 +80,11 @@ if(SPICEQL_BUILD_LIB)
7980
${SPICEQL_BUILD_INCLUDE_DIR}/query.h
8081
${SPICEQL_BUILD_INCLUDE_DIR}/config.h
8182
${SPICEQL_BUILD_INCLUDE_DIR}/inventory.h
82-
${SPICEQL_BUILD_INCLUDE_DIR}/inventoryimpl.h)
83+
${SPICEQL_BUILD_INCLUDE_DIR}/inventoryimpl.h
84+
${SPICEQL_BUILD_INCLUDE_DIR}/api.h)
8385

84-
set(SPICEQL_PRIVATE_HEADER_FILES ${SPICEQL_BUILD_INCLUDE_DIR}/memo.h)
86+
set(SPICEQL_PRIVATE_HEADER_FILES ${SPICEQL_BUILD_INCLUDE_DIR}/memo.h
87+
${SPICEQL_BUILD_INCLUDE_DIR}/restincurl.h)
8588

8689
set(SPICEQL_CONFIG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/apollo15.json
8790
${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/apollo16.json

SpiceQL/db/lro.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
},
99
"sclk" : {
1010
"kernels" : ["lro_clkcor_[0-9]{7}_v[0-9]{2}.tsc$"]
11+
},
12+
"tspk" : {
13+
"noquality" : {
14+
"kernels" : "^de421.bsp$"
15+
}
1116
}
1217
},
1318
"moc" : {
@@ -29,7 +34,7 @@
2934
"lroc" : {
3035
"ck" : {
3136
"reconstructed" : {
32-
"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$"]
37+
"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$"]
3338
}
3439
},
3540
"ik" : {

SpiceQL/include/api.h

+224
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <vector>
5+
#include <nlohmann/json.hpp>
6+
7+
namespace SpiceQL {
8+
std::string url_encode(const std::string &value);
9+
nlohmann::json spiceAPIQuery(std::string functionName, nlohmann::json args, std::string method="GET");
10+
11+
/**
12+
* @brief Gives the positions and velocities for a given frame given a set of ephemeris times
13+
*
14+
* Mostly a C++ wrap for NAIF's spkezr_c
15+
*
16+
* @param ets ephemeris times at which you want to obtain the target state
17+
* @param target NAIF ID for the target frame
18+
* @param observer NAIF ID for the observing frame
19+
* @param frame The reference frame in which to get the positions in
20+
* @param abcorr aborration correction flag, default it NONE.
21+
* This can set to:
22+
* "NONE" - No correction
23+
* For the "reception" case, i.e. photons from the target being recieved by the observer at the given time.
24+
* "LT" - One way light time correction
25+
* "LT+S" - Correct for one-way light time and stellar aberration correction
26+
* "CN" - Converging Newtonian light time correction
27+
* "CN+S" - Converged Newtonian light time correction and stellar aberration correction
28+
* For the "transmission" case, i.e. photons emitted from the oberver hitting at target at the given time
29+
* "XLT" - One-way light time correction using a newtonian formulation
30+
* "XLT+S" - One-way light time and stellar aberration correction using a newtonian formulation
31+
* "XCN" - converged Newtonian light time correction
32+
* "XCN+S" - converged Newtonian light time correction and stellar aberration correction.
33+
* @param mission Config subset as it relates to the mission
34+
* @param ckQualities vector of strings describing the quality of cks to try and obtain
35+
* @param spkQualities string of strings describing the quality of spks to try and obtain
36+
* @param searchKernels bool Whether to search the kernels for the user
37+
*
38+
* @see SpiceQL::getTargetState
39+
* @see Kernel::Quality
40+
*
41+
* @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.
42+
**/
43+
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={});
44+
45+
/**
46+
* @brief Gives quaternion and angular velocity for a given frame at a set of ephemeris times
47+
*
48+
* Gets orientations for an input frame in some reference frame.
49+
* The orientations returned from this function can be used to transform a position
50+
* in the source frame to the ref frame.
51+
*
52+
* @param ets ephemeris times at which you want to optain the target pointing
53+
* @param toframe the source frame's NAIF code.
54+
* @param refframe the reference frame's NAIF code, orientations are relative to this reference frame
55+
* @param mission Config subset as it relates to the mission
56+
* @param ckQualities vector of string describing the quality of cks to try and obtain
57+
* @param searchKernels bool Whether to search the kernels for the user
58+
*
59+
* @see SpiceQL::getTargetOrientation
60+
*
61+
* @returns Vector of SPICE-style quaternions (w,x,y,z) and optional angular velocity (4 element without angular velocity, 7 element with)
62+
**/
63+
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={});
64+
65+
/**
66+
* @brief Converts a given string spacecraft clock time to an ephemeris time
67+
*
68+
* Given a known frame code strSclkToEt converts a given spacecraft clock time as a string
69+
* to an ephemeris time. Call this function if your clock time looks something like:
70+
* 1/281199081:48971
71+
*
72+
* @param frameCode int Frame id to use
73+
* @param sclk string Spacecraft Clock formatted as a string
74+
* @param mission string Mission name as it relates to the config files
75+
* @param searchKernels bool Whether to search the kernels for the user
76+
* @return double
77+
*/
78+
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={});
79+
80+
/**
81+
* @brief Converts a given double spacecraft clock time to an ephemeris time
82+
*
83+
* Given a known frame code doubleSclkToEt converts a given spacecraft clock time as a double
84+
* to an ephemeris time. Call this function if your clock time looks something like:
85+
* 922997380.174174
86+
*
87+
* @param frameCode int Frame id to use
88+
* @param sclk int Spacecraft Clock formatted as an int
89+
* @param mission string Mission name as it relates to the config files
90+
* @param searchKernels bool Whether to search the kernels for the user
91+
* @return double
92+
*/
93+
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={});
94+
95+
/**
96+
* @brief convert a UTC string to an ephemeris time
97+
*
98+
* Basically a wrapper around NAIF's cspice str2et function except it also temporarily loads the required kernels.
99+
* See Also: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/str2et_c.html
100+
*
101+
* @param et UTC string, e.g. "1988 June 13, 12:29:48 TDB"
102+
* @param searchKernels bool Whether to search the kernels for the user
103+
* @returns double precision ephemeris time
104+
**/
105+
std::pair<double, nlohmann::json> utcToEt(std::string utc, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});
106+
107+
/**
108+
* @brief convert et string to a UTC string
109+
*
110+
* Basically a wrapper around NAIF's cspice et2utc_c function except it also temporarily loads the required kernels.
111+
* See Also: https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/et2utc_c.html
112+
*
113+
* @param et ephemeris time
114+
* @param precision number of decimal
115+
* @param searchKernels bool Whether to search the kernels for the user
116+
* @returns double precision ephemeris time
117+
**/
118+
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={});
119+
120+
/**
121+
* @brief Switch between NAIF frame string name to integer frame code
122+
*
123+
* 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
124+
*
125+
* @param frame String frame name to translate to a NAIF code
126+
* @param mission Mission name as it relates to the config files
127+
* @param searchKernels bool Whether to search the kernels for the user
128+
* @return integer Naif frame code
129+
**/
130+
std::pair<int, nlohmann::json> translateNameToCode(std::string frame, std::string mission, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});
131+
132+
/**
133+
* @brief Switch between NAIF frame integer code to string frame name
134+
*
135+
* 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
136+
*
137+
* @param frame int NAIF frame code to translate
138+
* @param searchKernels bool Whether to search the kernels for the user
139+
* @param mission Mission name as it relates to the config files
140+
* @return string Naif frame name
141+
**/
142+
std::pair<std::string, nlohmann::json> translateCodeToName(int frame, std::string mission, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});
143+
144+
/**
145+
* @brief Get the center, class id, and class of a given frame
146+
*
147+
* 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
148+
*
149+
* @param frame String frame name to translate to a NAIF code
150+
* @param mission Mission name as it relates to the config files
151+
* @param searchKernels bool Whether to search the kernels for the user
152+
* @return 3 element vector of the given frames center, class id, and class
153+
**/
154+
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={});
155+
156+
/**
157+
* @brief returns frame name and frame code associated to the target ID.
158+
*
159+
* Takes in a target id and returns the frame name and frame code in json format
160+
*
161+
* @param targetId target ID
162+
* @param mission mission name as it relates to the config files
163+
* @param searchKernels bool Whether to search the kernels for the user
164+
* @returns json of frame name and frame code
165+
**/
166+
std::pair<nlohmann::json, nlohmann::json> getTargetFrameInfo(int targetId, std::string mission, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernel_list={});
167+
168+
/**
169+
* @brief returns kernel values for a specific mission in the form of a json
170+
*
171+
* Takes in a kernel key and returns the value associated with the inputted mission as a json
172+
*
173+
* @param key key - Kernel to get values from
174+
* @param mission mission name
175+
* @param searchKernels bool Whether to search the kernels for the user
176+
* @returns json of values
177+
**/
178+
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={});
179+
180+
/**
181+
* @brief returns Target values in the form of a vector
182+
*
183+
* Takes in a target and key and returns the value associated in the form of vector.
184+
* Note: This function is mainly for obtaining target keywords. For obtaining other values, use findMissionKeywords.
185+
*
186+
* @param key keyword for desired values
187+
* @param mission mission name as it relates to the config files
188+
* @param searchKernels bool Whether to search the kernels for the user
189+
* @returns vector of values
190+
**/
191+
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={});
192+
193+
/**
194+
* @brief Given an ephemeris time and a starting frame, find the path from that starting frame to J2000 (1)
195+
*
196+
* This function uses NAIF routines and builds a path from the initalframe to J2000 making
197+
* note of all the in between frames
198+
*
199+
* @param et ephemeris times at which you want to optain the frame trace
200+
* @param initialFrame the initial frame's NAIF code.
201+
* @param mission Config subset as it relates to the mission
202+
* @param ckQualities vector of strings describing the quality of cks to try and obtain
203+
* @param searchKernels bool Whether to search the kernels for the user
204+
*
205+
* @returns A two element vector of vectors ints, where the first element is the sequence of time dependent frames
206+
* and the second is the sequence of constant frames
207+
**/
208+
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={});
209+
210+
/**
211+
* @brief Extracts all segment times between observStart and observeEnd
212+
*
213+
* Givven an observation start and observation end, extract all times assocaited
214+
* with segments in a CK file. The times returned are all times assocaited with
215+
* concrete CK segment times with no interpolation.
216+
*
217+
* @param observStart Ephemeris time to start searching at
218+
* @param observEnd Ephemeris time to stop searching at
219+
* @param targetFrame Target reference frame to get ephemeris data in
220+
* @param ckQualities vector of string describing the quality of cks to try and obtain
221+
* @returns A list of times
222+
**/
223+
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={});
224+
}

SpiceQL/include/inventory.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
namespace SpiceQL {
1919
namespace Inventory {
2020
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(),
21-
std::string ckQuality="smithed", std::string spkQuality="smithed", bool enforce_quality=false);
21+
std::vector<std::string> ckQualities={"smithed", "reconstructed"}, std::vector<std::string> spkQualities={"smithed", "reconstructed"}, bool enforce_quality=false);
2222
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(),
23-
std::string ckQuality="smithed", std::string spkQuality="smithed", bool enforce_quality=false, bool overwrite=false);
23+
std::vector<std::string> ckQualities={"smithed", "reconstructed"}, std::vector<std::string> spkQualities={"smithed", "reconstructed"}, bool enforce_quality=false, bool overwrite=false);
24+
nlohmann::json search_for_kernelset_from_regex(std::vector<std::string> list);
25+
2426
std::string getDbFilePath();
2527

26-
void create_database();
28+
void create_database(std::vector<std::string> mlist = {});
2729
}
2830
}

SpiceQL/include/inventoryimpl.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace SpiceQL {
2323
extern std::string DB_STOP_TIME_KEY;
2424
extern std::string DB_TIME_FILES_KEY;
2525
extern std::string DB_SS_TIME_INDICES_KEY;
26+
extern std::string DB_SPICE_ROOT_KEY;
2627

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

3839
class InventoryImpl {
3940
public:
40-
InventoryImpl(bool force_regen=false);
41+
InventoryImpl(bool force_regen=false, std::vector<std::string> mlist = {});
4142
template<class T> T getKey(std::string key);
4243
void write_database();
4344
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(),
44-
Kernel::Quality ckQuality=Kernel::Quality::SMITHED, Kernel::Quality spkQuality=Kernel::Quality::SMITHED, bool enforce_quality=false);
45+
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);
4546
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(),
46-
Kernel::Quality ckQuality=Kernel::Quality::SMITHED, Kernel::Quality spkQuality=Kernel::Quality::SMITHED, bool enforce_quality=false, bool overwrite=false);
47+
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);
4748
nlohmann::json m_json_inventory;
4849

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

0 commit comments

Comments
 (0)