Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ release.
### Added
- Added kernel intervals to spiceqldb.hdf [#165](https://github.com/DOI-USGS/SpiceQL/pull/165)
- Added overloaded API functions to use the struct `QueryOpts` for common parameters [#168](https://github.com/DOI-USGS/SpiceQL/pull/168)
- Added getKernelIntervals API call to retrieve intervals given a list of kernels and updated searchForKernelsets with `getIntervals` bool param to return intervals alongside kernels [#166](https://github.com/DOI-USGS/SpiceQL/pull/166)

## 1.8.0 - 2026-10-01

Expand Down
28 changes: 27 additions & 1 deletion SpiceQL/include/SpiceQL/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@ namespace SpiceQL {
* @param limitCk limitCk int number of cks to limit to, default is -1 to retrieve all
* @param limitSpk int number of spks to limit to, default is 1 to retrieve only one
* @param overwrite subkernels will take precedent over parent mission kernels if true
* @param getIntervals if true, the coverage intervals of the found CKs and SPKs are added
* under the "intervals" key, in the same format as getKernelIntervals
*
* @returns An empty return and list of kernels
**/
Expand All @@ -729,7 +731,31 @@ namespace SpiceQL {
bool fullKernelPath=false,
int limitCk=-1,
int limitSpk=1,
bool overwrite=false);
bool overwrite=false,
bool getIntervals=false);

/**
* @brief Returns the coverage intervals of CKs and SPKs.
*
* Looks the kernels up in the SpiceQL database and returns their coverage
* intervals, one per NAIF ID covered. For CKs, gaps between interpolation
* intervals within a segment show up as separate intervals.
*
* A kernel can be named by its bare filename, its path relative to the data
* dir (or a full path ending in it), or its SpiceQL key
* (/<mission>/<type>/<quality>/<filename>). A kernel in more than one
* mission or quality gets an entry for each. Kernels that are not CKs or
* SPKs in the database are skipped.
*
* @param kernels vector of kernels to get intervals for
* @param useWeb whether to use web SpiceQL
*
* @returns json object of SpiceQL key (e.g. /lro/ck/reconstructed/kernel.bc) to an
* array of start and stop times in ET and body code
**/
std::pair<nlohmann::json, nlohmann::json> getKernelIntervals(
std::vector<std::string> kernels,
bool useWeb=false);

#ifndef SWIG
// Overloads taking a QueryOpts instead of the individual option params.
Expand Down
18 changes: 16 additions & 2 deletions SpiceQL/include/SpiceQL/inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,26 @@
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::vector<std::string> ckQualities={"smithed", "reconstructed"}, std::vector<std::string> spkQualities={"smithed", "reconstructed"}, bool full_kernel_path=false, int limit_ck=-1, int limit_spk=1);
std::vector<std::string> ckQualities={"smithed", "reconstructed"}, std::vector<std::string> spkQualities={"smithed", "reconstructed"}, bool full_kernel_path=false, int limit_ck=-1, int limit_spk=1,
bool get_intervals=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::vector<std::string> ckQualities={"smithed", "reconstructed"}, std::vector<std::string> spkQualities={"smithed", "reconstructed"}, bool full_kernel_path=false, int limit_ck=-1, int limit_spk=1,
bool overwrite=false);
bool overwrite=false, bool get_intervals=false);
nlohmann::json search_for_kernelset_from_regex(std::vector<std::string> list, bool full_kernel_path=false);

/**
* @brief Get the coverage intervals of CKs and SPKs from the database.
*
* A kernel can be named by its bare filename, its path relative to the
* data dir (or a full path ending in it), or its SpiceQL key
* (/<mission>/<type>/<quality>/<filename>).
*
* @param kernels the kernels to get intervals for
* @return json object of SpiceQL key to an array of
* {"start", "stop", "body_code"}
*/
nlohmann::json get_kernel_intervals(std::vector<std::string> kernels);

std::string getDbFilePath();
void setDbFilePath(std::string db_file_path, bool override=false);

Expand Down
43 changes: 41 additions & 2 deletions SpiceQL/include/SpiceQL/inventoryimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,49 @@ namespace SpiceQL {
int getFrameCode(std::string name);
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(),
std::vector<Kernel::Quality> ckQualities={Kernel::Quality::SMITHED, Kernel::Quality::RECONSTRUCTED}, std::vector<Kernel::Quality> spkQualities={Kernel::Quality::SMITHED, Kernel::Quality::RECONSTRUCTED},
bool full_kernel_path=false, int limit_ck=-1, int limit_spk=1);
bool full_kernel_path=false, int limit_ck=-1, int limit_spk=1, bool get_intervals=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(),
std::vector<Kernel::Quality> ckQualities={Kernel::Quality::SMITHED, Kernel::Quality::RECONSTRUCTED}, std::vector<Kernel::Quality> spkQualities={Kernel::Quality::SMITHED, Kernel::Quality::RECONSTRUCTED},
bool full_kernel_path=false, int limit_ck=-1, int limit_spk=1, bool overwrite=false);
bool full_kernel_path=false, int limit_ck=-1, int limit_spk=1, bool overwrite=false, bool get_intervals=false);

/**
* @brief Get the coverage intervals of kernels in one CK or SPK group.
*
* Used when the group is already known, e.g. by search_for_kernelset. To
* search every group, use get_kernel_intervals.
*
* A kernel can be named by its bare filename, its path relative to the data
* dir (or a full path ending in it), or its SpiceQL key
* (/<mission>/<type>/<quality>/<filename>). Kernels not in the group are
* skipped.
*
* @param key the group, as <mission>/<type>/<quality>/
* @param kernels the kernels to get intervals for
* @returns json object of SpiceQL key to an array of
* {"start", "stop", "body_code"} intervals
*/
nlohmann::json get_group_intervals(std::string key, std::vector<std::string> kernels);

/**
* @brief Get the coverage intervals of kernels from any CK or SPK group.
*
* Calls get_group_intervals on every time dependent group in the DB,
* so a kernel in more than one group gets an entry for each.
*
* @param kernels the kernels to get intervals for
* @returns json object of SpiceQL key to an array of intervals
*/
nlohmann::json get_kernel_intervals(std::vector<std::string> kernels);

/**
* @brief Makes sure a group's interval rows are usable, reading them from
* the DB if from_db is set.
*
* @param group_key the group's full DB key, spice/<mission>/<type>/<quality>/
* @returns false if the group has no interval rows (e.g. a DB built before
* intervals were stored) or the datasets don't line up
*/
bool load_group_intervals(const std::string &group_key, TimeIndexedKernels &time_indices, bool from_db);
nlohmann::json m_json_inventory;

std::map<std::string, std::vector<std::string>> m_nontimedep_kerns;
Expand Down
24 changes: 21 additions & 3 deletions SpiceQL/src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,8 @@ namespace SpiceQL {
bool fullKernelPath,
int limitCk,
int limitSpk,
bool overwrite) {
bool overwrite,
bool getIntervals) {
SPDLOG_TRACE("Calling searchForKernelsets with {}, {}, {}, {}, {}, {}, {}", spiceqlNames, types, startTime, stopTime, ckQualities.size(), spkQualities.size(), useWeb);

if (useWeb){
Expand All @@ -1475,13 +1476,30 @@ namespace SpiceQL {
{"fullKernelPath", fullKernelPath},
{"limitCk", limitCk},
{"limitSpk", limitSpk},
{"overwrite", overwrite}
{"overwrite", overwrite},
{"getIntervals", getIntervals}
});
json out = spiceAPIQuery("searchForKernelsets", args);
string kvect = out["body"]["return"];
return make_pair(kvect, out["body"]["kernels"]);
}
json kernels = Inventory::search_for_kernelsets(spiceqlNames, types, startTime, stopTime, ckQualities, spkQualities, fullKernelPath, limitCk, limitSpk, overwrite);
json kernels = Inventory::search_for_kernelsets(spiceqlNames, types, startTime, stopTime, ckQualities, spkQualities, fullKernelPath, limitCk, limitSpk, overwrite, getIntervals);
return {"", kernels};
}


pair<json, json> getKernelIntervals(vector<string> kernels, bool useWeb) {
SPDLOG_TRACE("Calling getKernelIntervals with {}, {}", kernels, useWeb);

if (useWeb){
json args = json::object({
{"kernels", kernels}
});
json out = spiceAPIQuery("getKernelIntervals", args);
json result = out["body"]["return"];
return make_pair(result, out["body"]["kernels"]);
}
json intervals = Inventory::get_kernel_intervals(kernels);
return {intervals, json::object()};
}
}
14 changes: 10 additions & 4 deletions SpiceQL/src/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace SpiceQL {
namespace Inventory {
json search_for_kernelset(string instrument, vector<string> types, double start_time, double stop_time,
vector<string> ckQualities, vector<string> spkQualities, bool full_kernel_path,
int limit_ck, int limit_spk) {
int limit_ck, int limit_spk, bool get_intervals) {
InventoryImpl impl;

vector<Kernel::Quality> enum_ck_qualities = Kernel::translateQualities(ckQualities);
Expand All @@ -31,12 +31,12 @@ namespace SpiceQL {
enum_types.push_back(Kernel::translateType(e));
}

return impl.search_for_kernelset(instrument, enum_types, start_time, stop_time, enum_ck_qualities, enum_spk_qualities, full_kernel_path, limit_ck, limit_spk);
return impl.search_for_kernelset(instrument, enum_types, start_time, stop_time, enum_ck_qualities, enum_spk_qualities, full_kernel_path, limit_ck, limit_spk, get_intervals);
}

json search_for_kernelsets(vector<string> spiceql_names, vector<string> types, double start_time, double stop_time,
vector<string> ckQualities, vector<string> spkQualities, bool full_kernel_path,
int limit_ck, int limit_spk, bool overwrite) {
int limit_ck, int limit_spk, bool overwrite, bool get_intervals) {
InventoryImpl impl;

vector<Kernel::Quality> enum_ck_qualities = Kernel::translateQualities(ckQualities);
Expand All @@ -47,11 +47,17 @@ namespace SpiceQL {
enum_types.push_back(Kernel::translateType(e));
}

json kernels = impl.search_for_kernelsets(spiceql_names, enum_types, start_time, stop_time, enum_ck_qualities, enum_spk_qualities, full_kernel_path, limit_ck, limit_spk, overwrite);
json kernels = impl.search_for_kernelsets(spiceql_names, enum_types, start_time, stop_time, enum_ck_qualities, enum_spk_qualities, full_kernel_path, limit_ck, limit_spk, overwrite, get_intervals);
return kernels;
}


json get_kernel_intervals(vector<string> kernels) {
InventoryImpl impl;
return impl.get_kernel_intervals(kernels);
}



json search_for_kernelset_from_regex(vector<string> list, bool full_kernel_path) {
// strings should be formatted similar to the hdf keys e.g.
Expand Down
13 changes: 9 additions & 4 deletions SpiceQL/src/inventory_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* 2. kernels already furnished into CSPICE by the caller.
*
* Accordingly:
* - The time-indexed DB searches (search_for_kernelset / search_for_kernelsets)
* throw a clear error telling the caller to pass an explicit kernelList with
* - The time-indexed DB searches (search_for_kernelset / search_for_kernelsets
* / get_kernel_intervals) throw a clear error telling the caller to pass an explicit kernelList with
* searchKernels=false.
* - search_for_kernelset_from_regex, which api.cpp calls whenever a non-empty
* kernelList is supplied, is reimplemented to treat each list entry as a path
Expand Down Expand Up @@ -46,15 +46,20 @@ namespace SpiceQL {
json search_for_kernelset(string /*spiceql_name*/, vector<string> /*types*/,
double /*start_time*/, double /*stop_time*/,
vector<string> /*ckQualities*/, vector<string> /*spkQualities*/,
bool /*full_kernel_path*/, int /*limit_ck*/, int /*limit_spk*/) {
bool /*full_kernel_path*/, int /*limit_ck*/, int /*limit_spk*/,
bool /*get_intervals*/) {
throw runtime_error(kSearchUnavailableMsg);
}

json search_for_kernelsets(vector<string> /*spiceql_names*/, vector<string> /*types*/,
double /*start_time*/, double /*stop_time*/,
vector<string> /*ckQualities*/, vector<string> /*spkQualities*/,
bool /*full_kernel_path*/, int /*limit_ck*/, int /*limit_spk*/,
bool /*overwrite*/) {
bool /*overwrite*/, bool /*get_intervals*/) {
throw runtime_error(kSearchUnavailableMsg);
}

json get_kernel_intervals(vector<string> /*kernels*/) {
throw runtime_error(kSearchUnavailableMsg);
}

Expand Down
Loading
Loading