diff --git a/SpiceQL/include/api.h b/SpiceQL/include/api.h index 722185573d4c533f8c57f0615ec4b6f77608c378..1c552a9e39f29cded2e39eab2a4be9039cf35d4d 100644 --- a/SpiceQL/include/api.h +++ b/SpiceQL/include/api.h @@ -5,6 +5,9 @@ #include <nlohmann/json.hpp> namespace SpiceQL { + + extern std::map<std::string, std::string> spiceql_mission_map; + std::string url_encode(const std::string &value); nlohmann::json spiceAPIQuery(std::string functionName, nlohmann::json args, std::string method="GET"); @@ -34,7 +37,8 @@ namespace SpiceQL { * @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 - * + * @param kernelList vector<string> vector of additional kernels to load + * * @see SpiceQL::getTargetState * @see Kernel::Quality * @@ -55,6 +59,7 @@ namespace SpiceQL { * @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 + * @param kernelList vector<string> vector of additional kernels to load * * @see SpiceQL::getTargetOrientation * @@ -73,6 +78,7 @@ namespace SpiceQL { * @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 + * @param kernelList vector<string> vector of additional kernels to load * @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={}); @@ -88,10 +94,29 @@ namespace SpiceQL { * @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 + * @param kernelList vector<string> vector of additional kernels to load * @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 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 et double Spacecraft ephemeris time to convert to an SCLK + * @param mission string Mission name as it relates to the config files + * @param searchKernels bool Whether to search the kernels for the user + * @param kernelList vector<string> vector of additional kernels to load + * @return double + */ + std::pair<std::string, nlohmann::json> doubleEtToSclk(int frameCode, double et, std::string mission, bool useWeb=false, bool searchKernels=true, std::vector<std::string> kernelList={}); + + /** * @brief convert a UTC string to an ephemeris time * @@ -113,6 +138,8 @@ namespace SpiceQL { * @param et ephemeris time * @param precision number of decimal * @param searchKernels bool Whether to search the kernels for the user + * @param kernelList vector<string> vector of additional kernels to load + * * @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={}); @@ -125,6 +152,8 @@ namespace SpiceQL { * @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 + * @param kernelList vector<string> vector of additional kernels to load + * * @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={}); @@ -137,6 +166,8 @@ namespace SpiceQL { * @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 + * @param kernelList vector<string> vector of additional kernels to load + * * @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={}); @@ -149,6 +180,8 @@ namespace SpiceQL { * @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 + * @param kernelList vector<string> vector of additional kernels to load + * * @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={}); @@ -161,6 +194,8 @@ namespace SpiceQL { * @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 + * @param kernelList vector<string> vector of additional kernels to load + * * @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={}); @@ -186,6 +221,8 @@ namespace SpiceQL { * @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 + * @param kernelList vector<string> vector of additional kernels to load + * * @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={}); @@ -201,6 +238,7 @@ namespace SpiceQL { * @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 + * @param kernelList vector<string> vector of additional kernels to load * * @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 @@ -218,6 +256,8 @@ namespace SpiceQL { * @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 + * @param kernelList vector<string> vector of additional kernels to load + * * @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={}); diff --git a/SpiceQL/src/api.cpp b/SpiceQL/src/api.cpp index aa1edf60dd1d54f472771cedb54aedc2628e9f07..f43d97ac3e23ca984047c1c5fe74aa51ecf589c5 100644 --- a/SpiceQL/src/api.cpp +++ b/SpiceQL/src/api.cpp @@ -24,104 +24,104 @@ using json = nlohmann::json; using namespace std; -std::map<std::string, std::string> spiceql_mission_map = { - {"AMICA", "amica"}, - {"CHANDRAYAAN-1_M3", "m3"}, - {"CHANDRAYAAN-1_MRFFR", "mrffr"}, - {"CASSINI_ISS_NAC", "cassini"}, - {"CASSINI_ISS_WAC", "cassini"}, - {"DAWN_FC2_FILTER_1", "fc2"}, - {"DAWN_FC2_FILTER_2", "fc2"}, - {"DAWN_FC2_FILTER_3", "fc2"}, - {"DAWN_FC2_FILTER_4", "fc2"}, - {"DAWN_FC2_FILTER_5", "fc2"}, - {"DAWN_FC2_FILTER_6", "fc2"}, - {"DAWN_FC2_FILTER_7", "fc2"}, - {"DAWN_FC2_FILTER_8", "fc2"}, - {"GLL_SSI_PLATFORM", "galileo"}, - {"HAYABUSA_AMICA", "amica"}, - {"HAYABUSA_NIRS", "nirs"}, - {"HAYABUSA2_ONC-W2", ""}, - {"JUNO_JUNOCAM", "juno"}, - {"JUPITER", "voyager1"}, - {"LRO_LROCNACL", "lroc"}, - {"LRO_LROCNACR", "lroc"}, - {"LRO_LROCWAC_UV", "lroc"}, - {"LRO_LROCWAC_VIS", "lroc"}, - {"LRO_MINIRF", ""}, - {"M10_VIDICON_A", "m10_vidicon_a"}, - {"M10_VIDICON_B", "m10_vidicon_b"}, - {"MARS", "mro"}, - {"MSGR_MDIS_WAC", "mdis"}, - {"MSGR_MDIS_NAC", "mdis"}, - {"MEX_HRSC_SRC", "src"}, - {"MEX_HRSC_IR", "hrsc"}, - {"MGS_MOC_NA", "mgs"}, - {"MGS_MOC_WA_RED", "mgs"}, - {"MGS_MOC_WA_BLUE", "mgs"}, - {"MOON", "apollo15"}, - {"MRO_MARCI_VIS", "marci"}, - {"MRO_MARCI_UV", "marci"}, - {"MRO_CTX", "ctx"}, - {"MRO_HIRISE", "hirise"}, - {"MRO_CRISM_VNIR", "crism"}, - {"NEAR EARTH ASTEROID RENDEZVOUS", ""}, - {"MSL_MASTCAM_RIGHT", ""}, - {"MSL_MASTCAM_LEFT", ""}, - {"NH_LORRI", "lorri"}, - {"NH_RALPH_LEISA", "leisa"}, - {"NH_MVIC", "mvic_tdi"}, - {"ISIS_NH_RALPH_MVIC_METHANE", "mvic_framing"}, - {"THEMIS_IR", "odyssey"}, - {"THEMIS_VIS", "odyssey"}, - {"ORX_OCAMS_MAPCAM", ""}, - {"ORX_OCAMS_POLYCAM", ""}, - {"ORX_OCAMS_SAMCAM", ""}, - {"LISM_MI-VIS1", "kaguya"}, - {"LISM_MI-VIS2", "kaguya"}, - {"LISM_MI-VIS3", "kaguya"}, - {"LISM_MI-VIS4", "kaguya"}, - {"LISM_MI-VIS5", "kaguya"}, - {"LISM_MI-NIR1", "kaguya"}, - {"LISM_MI-NIR2", "kaguya"}, - {"LISM_MI-NIR3", "kaguya"}, - {"LISM_MI-NIR4", "kaguya"}, - {"LISM_TC1_WDF", "kaguya"}, - {"LISM_TC1_WTF", "kaguya"}, - {"LISM_TC1_SDF", "kaguya"}, - {"LISM_TC1_STF", "kaguya"}, - {"LISM_TC1_WDN", "kaguya"}, - {"LISM_TC1_WTN", "kaguya"}, - {"LISM_TC1_SDN", "kaguya"}, - {"LISM_TC1_STN", "kaguya"}, - {"LISM_TC1_WDH", "kaguya"}, - {"LISM_TC1_WTH", "kaguya"}, - {"LISM_TC1_SDH", "kaguya"}, - {"LISM_TC1_STH", "kaguya"}, - {"LISM_TC1_SSH", "kaguya"}, - {"LO1_HIGH_RESOLUTION_CAMERA", ""}, - {"LO2_HIGH_RESOLUTION_CAMERA", ""}, - {"LO3_HIGH_RESOLUTION_CAMERA", ""}, - {"LO4_HIGH_RESOLUTION_CAMERA", ""}, - {"LO5_HIGH_RESOLUTION_CAMERA", ""}, - {"NEPTUNE", "voyager1"}, - {"SATURN", "voyager1"}, - {"TGO_CASSIS", "cassis"}, - {"VIKING ORBITER 1", "viking1"}, - {"VIKING ORBITER 2", "viking2"}, - {"VG1_ISSNA", ""}, - {"VG1_ISSWA", ""}, - {"VG2_ISSNA", ""}, - {"VG2_ISSWA", ""}, - {"ULTRAVIOLET/VISIBLE CAMERA", "uvvis"}, - {"Near Infrared Camera", "nir"}, - {"High Resolution Camera", "clementine1"}, - {"Long Wave Infrared Camera", "clementine1"}, - {"Visual and Infrared Spectrometer", "vir"} - }; - namespace SpiceQL { + map<string, string> spiceql_mission_map = { + {"AMICA", "amica"}, + {"CHANDRAYAAN-1_M3", "m3"}, + {"CHANDRAYAAN-1_MRFFR", "mrffr"}, + {"CASSINI_ISS_NAC", "cassini"}, + {"CASSINI_ISS_WAC", "cassini"}, + {"DAWN_FC2_FILTER_1", "fc2"}, + {"DAWN_FC2_FILTER_2", "fc2"}, + {"DAWN_FC2_FILTER_3", "fc2"}, + {"DAWN_FC2_FILTER_4", "fc2"}, + {"DAWN_FC2_FILTER_5", "fc2"}, + {"DAWN_FC2_FILTER_6", "fc2"}, + {"DAWN_FC2_FILTER_7", "fc2"}, + {"DAWN_FC2_FILTER_8", "fc2"}, + {"GLL_SSI_PLATFORM", "galileo"}, + {"HAYABUSA_AMICA", "amica"}, + {"HAYABUSA_NIRS", "nirs"}, + {"HAYABUSA2_ONC-W2", ""}, + {"JUNO_JUNOCAM", "juno"}, + {"JUPITER", "voyager1"}, + {"LRO_LROCNACL", "lroc"}, + {"LRO_LROCNACR", "lroc"}, + {"LRO_LROCWAC_UV", "lroc"}, + {"LRO_LROCWAC_VIS", "lroc"}, + {"LRO_MINIRF", ""}, + {"M10_VIDICON_A", "m10_vidicon_a"}, + {"M10_VIDICON_B", "m10_vidicon_b"}, + {"MARS", "mro"}, + {"MSGR_MDIS_WAC", "mdis"}, + {"MSGR_MDIS_NAC", "mdis"}, + {"MEX_HRSC_SRC", "src"}, + {"MEX_HRSC_IR", "hrsc"}, + {"MGS_MOC_NA", "mgs"}, + {"MGS_MOC_WA_RED", "mgs"}, + {"MGS_MOC_WA_BLUE", "mgs"}, + {"MOON", "apollo15"}, + {"MRO_MARCI_VIS", "marci"}, + {"MRO_MARCI_UV", "marci"}, + {"MRO_CTX", "ctx"}, + {"MRO_HIRISE", "hirise"}, + {"MRO_CRISM_VNIR", "crism"}, + {"NEAR EARTH ASTEROID RENDEZVOUS", ""}, + {"MSL_MASTCAM_RIGHT", ""}, + {"MSL_MASTCAM_LEFT", ""}, + {"NH_LORRI", "lorri"}, + {"NH_RALPH_LEISA", "leisa"}, + {"NH_MVIC", "mvic_tdi"}, + {"ISIS_NH_RALPH_MVIC_METHANE", "mvic_framing"}, + {"THEMIS_IR", "odyssey"}, + {"THEMIS_VIS", "odyssey"}, + {"ORX_OCAMS_MAPCAM", ""}, + {"ORX_OCAMS_POLYCAM", ""}, + {"ORX_OCAMS_SAMCAM", ""}, + {"LISM_MI-VIS1", "kaguya"}, + {"LISM_MI-VIS2", "kaguya"}, + {"LISM_MI-VIS3", "kaguya"}, + {"LISM_MI-VIS4", "kaguya"}, + {"LISM_MI-VIS5", "kaguya"}, + {"LISM_MI-NIR1", "kaguya"}, + {"LISM_MI-NIR2", "kaguya"}, + {"LISM_MI-NIR3", "kaguya"}, + {"LISM_MI-NIR4", "kaguya"}, + {"LISM_TC1_WDF", "kaguya"}, + {"LISM_TC1_WTF", "kaguya"}, + {"LISM_TC1_SDF", "kaguya"}, + {"LISM_TC1_STF", "kaguya"}, + {"LISM_TC1_WDN", "kaguya"}, + {"LISM_TC1_WTN", "kaguya"}, + {"LISM_TC1_SDN", "kaguya"}, + {"LISM_TC1_STN", "kaguya"}, + {"LISM_TC1_WDH", "kaguya"}, + {"LISM_TC1_WTH", "kaguya"}, + {"LISM_TC1_SDH", "kaguya"}, + {"LISM_TC1_STH", "kaguya"}, + {"LISM_TC1_SSH", "kaguya"}, + {"LO1_HIGH_RESOLUTION_CAMERA", ""}, + {"LO2_HIGH_RESOLUTION_CAMERA", ""}, + {"LO3_HIGH_RESOLUTION_CAMERA", ""}, + {"LO4_HIGH_RESOLUTION_CAMERA", ""}, + {"LO5_HIGH_RESOLUTION_CAMERA", ""}, + {"NEPTUNE", "voyager1"}, + {"SATURN", "voyager1"}, + {"TGO_CASSIS", "cassis"}, + {"VIKING ORBITER 1", "viking1"}, + {"VIKING ORBITER 2", "viking2"}, + {"VG1_ISSNA", ""}, + {"VG1_ISSWA", ""}, + {"VG2_ISSNA", ""}, + {"VG2_ISSWA", ""}, + {"ULTRAVIOLET/VISIBLE CAMERA", "uvvis"}, + {"Near Infrared Camera", "nir"}, + {"High Resolution Camera", "clementine1"}, + {"Long Wave Infrared Camera", "clementine1"}, + {"Visual and Infrared Spectrometer", "vir"} + }; + std::string url_encode(const std::string &value) { std::ostringstream escaped; escaped.fill('0'); @@ -165,19 +165,21 @@ namespace SpiceQL { queryString+= x.value().dump(); queryString+= "&"; } + std::string encodedString = url_encode(queryString); - std::cout << "[RestfulSpice] spiceAPIQuery encodedString = " << encodedString << std::endl; + SPDLOG_TRACE("spiceAPIQuery encodedString = {}", encodedString); client.Build()->Get(encodedString).Option(CURLOPT_FOLLOWLOCATION, 1L).AcceptJson().WithCompletion([&](const restincurl::Result& result) { - std::cout << "[RestfulSpice] spiceAPIQuery GET result body = " << result.body << std::endl; + SPDLOG_TRACE("spiceAPIQuery GET result body = {}", result.body); j = json::parse(result.body); }).ExecuteSynchronous(); - }else{ - std::cout << "[RestfulSpice] spiceAPIQuery POST" << std::endl; + } else { + SPDLOG_TRACE("spiceAPIQuery POST"); client.Build()->Post(queryString).Option(CURLOPT_FOLLOWLOCATION, 1L).AcceptJson().WithJson(args.dump()).WithCompletion([&](const restincurl::Result& result) { - std::cout << "[RestfulSpice] spiceAPIQuery POST result = " << result.body << std::endl; + SPDLOG_TRACE("spiceAPIQuery POST result = {}", result.body); j = json::parse(result.body); }).ExecuteSynchronous(); } + client.CloseWhenFinished(); client.WaitForFinish(); @@ -186,10 +188,10 @@ namespace SpiceQL { } - pair<vector<vector<double>>, json> getTargetStates(vector<double> ets, string target, string observer, string frame, string abcorr, string mission, vector<string> ckQualities, vector<string> spkQualities, bool useWeb, bool searchKernels, vector<string> kernel_list) { - SPDLOG_TRACE("Calling getTargetStates with {}, {}, {}, {}, {}, {}, {}, {}, {}, {}", ets.size(), target, observer, frame, abcorr, mission, ckQualities.size(), spkQualities.size(), useWeb, searchKernels, kernel_list.size()); + pair<vector<vector<double>>, json> getTargetStates(vector<double> ets, string target, string observer, string frame, string abcorr, string mission, vector<string> ckQualities, vector<string> spkQualities, bool useWeb, bool searchKernels, vector<string> kernelList) { + SPDLOG_TRACE("Calling getTargetStates with {}, {}, {}, {}, {}, {}, {}, {}, {}, {}", ets.size(), target, observer, frame, abcorr, mission, ckQualities.size(), spkQualities.size(), useWeb, searchKernels, kernelList.size()); - if (useWeb){ + if (useWeb) { // @TODO validity checks json args = json::object({ {"target", target}, @@ -200,9 +202,8 @@ namespace SpiceQL { {"mission", mission}, {"ckQualities", ckQualities}, {"spkQualities", spkQualities}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); // @TODO check that json exists / contains what we're looking for json out = spiceAPIQuery("getTargetStates", args); @@ -221,8 +222,8 @@ namespace SpiceQL { SPDLOG_DEBUG("{} Kernels : {}", mission, ephemKernels.dump(4)); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(ephemKernels, regexk); } @@ -250,8 +251,8 @@ namespace SpiceQL { } - pair<vector<vector<double>>, json> getTargetOrientations(vector<double> ets, int toFrame, int refFrame, string mission, vector<string> ckQualities, bool useWeb, bool searchKernels, vector<string> kernel_list) { - SPDLOG_TRACE("Calling getTargetOrientations with {}, {}, {}, {}, {}, {}, {}, {}", ets.size(), toFrame, refFrame, mission, ckQualities.size(), useWeb, searchKernels, kernel_list.size()); + pair<vector<vector<double>>, json> getTargetOrientations(vector<double> ets, int toFrame, int refFrame, string mission, vector<string> ckQualities, bool useWeb, bool searchKernels, vector<string> kernelList) { + SPDLOG_TRACE("Calling getTargetOrientations with {}, {}, {}, {}, {}, {}, {}, {}", ets.size(), toFrame, refFrame, mission, ckQualities.size(), useWeb, searchKernels, kernelList.size()); if (useWeb){ json args = json::object({ @@ -260,9 +261,8 @@ namespace SpiceQL { {"refFrame", refFrame}, {"mission", mission}, {"ckQualities", ckQualities}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("getTargetOrientations", args); vector<vector<double>> kvect = json2DFloatArrayTo2DVector(out["body"]["return"]); @@ -279,8 +279,8 @@ namespace SpiceQL { ephemKernels = Inventory::search_for_kernelsets({mission, "base"}, {"sclk", "ck", "pck", "fk", "tspk", "lsk", "tspk"}, ets.front(), ets.back(), ckQualities, {"noquality"}); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(ephemKernels, regexk); } @@ -306,17 +306,16 @@ namespace SpiceQL { } - pair<double, json> strSclkToEt(int frameCode, string sclk, string mission, bool useWeb, bool searchKernels, vector<string> kernel_list) { - SPDLOG_TRACE("calling strSclkToEt({}, {}, {}, {}, {}, {})", frameCode, sclk, mission, useWeb, searchKernels, kernel_list.size()); + pair<double, json> strSclkToEt(int frameCode, string sclk, string mission, bool useWeb, bool searchKernels, vector<string> kernelList) { + SPDLOG_TRACE("calling strSclkToEt({}, {}, {}, {}, {}, {})", frameCode, sclk, mission, useWeb, searchKernels, kernelList.size()); - if (useWeb){ + if (useWeb) { json args = json::object({ {"frameCode", frameCode}, {"sclk", sclk}, {"mission", mission}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("strSclkToEt", args); double result = out["body"]["return"].get<double>(); @@ -328,8 +327,8 @@ namespace SpiceQL { ephemKernels = Inventory::search_for_kernelsets({"base", mission}, {"lsk", "fk", "sclk"}); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(ephemKernels, regexk); } @@ -354,15 +353,68 @@ namespace SpiceQL { } - pair<double, json> doubleSclkToEt(int frameCode, double sclk, string mission, bool useWeb, bool searchKernels, vector<string> kernel_list) { + pair<string, json> doubleEtToSclk(int frameCode, double et, string mission, bool useWeb, bool searchKernels, vector<string> kernelList) { + SPDLOG_TRACE("calling strSclkToEt({}, {}, {}, {}, {}, {})", frameCode, et, mission, useWeb, searchKernels, kernelList.size()); + + Config missionConf; + json ephemKernels; + + if (useWeb) { + json args = json::object({ + {"frameCode", frameCode}, + {"et", et}, + {"mission", mission}, + {"searchKernels", searchKernels}, + {"kernelList", kernelList} + }); + json out = spiceAPIQuery("doubleEtToSclk", args); + string result = out["body"]["return"].get<string>(); + return make_pair(result, out["body"]["kernels"]); + } + + if (searchKernels) { + ephemKernels = Inventory::search_for_kernelsets({"base", "mission"}, {"fk", "lsk", "sclk"}); + } + + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); + // merge them into the ephem kernels overwriting anything found in the query + merge_json(ephemKernels, regexk); + } + + KernelSet sclkSet(ephemKernels); + + SpiceChar sclk[100]; + checkNaifErrors(); + sce2s_c(frameCode, et, 100, sclk); + checkNaifErrors(); + SPDLOG_DEBUG("strsclktoet({}, {}, {}) -> {}", frameCode, mission, sclk, et); + + return make_pair(string(sclk), ephemKernels); + } + + + json findMissionKeywords(string key, string mission, bool searchKernels) { + json translationKernels = {}; + + if (mission != "" && searchKernels) { + translationKernels = Inventory::search_for_kernelset(mission, {"iak", "fk", "ik"}); + } + + KernelSet kset(translationKernels); + + return findKeywords(key); + } + + + pair<double, json> doubleSclkToEt(int frameCode, double sclk, string mission, bool useWeb, bool searchKernels, vector<string> kernelList) { if (useWeb){ json args = json::object({ {"frameCode", frameCode}, {"sclk", sclk}, {"mission", mission}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("doubleSclkToEt", args); double result = out["body"]["return"].get<double>(); @@ -375,8 +427,8 @@ namespace SpiceQL { sclks = Inventory::search_for_kernelset(mission, {"lsk", "fk", "sclk"}); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(sclks, regexk); } @@ -396,13 +448,12 @@ namespace SpiceQL { } - pair<double, json> utcToEt(string utc, bool useWeb, bool searchKernels, vector<string> kernel_list) { + pair<double, json> utcToEt(string utc, bool useWeb, bool searchKernels, vector<string> kernelList) { if (useWeb){ json args = json::object({ {"utc", utc}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("utcToEt", args); double result = out["body"]["return"].get<double>(); @@ -417,8 +468,8 @@ namespace SpiceQL { if (searchKernels) { lsks = conf.getLatest("lsk"); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(lsks, regexk); } @@ -434,15 +485,14 @@ namespace SpiceQL { } - pair<string, json> etToUtc(double et, string format, double precision, bool useWeb, bool searchKernels, vector<string> kernel_list) { + pair<string, json> etToUtc(double et, string format, double precision, bool useWeb, bool searchKernels, vector<string> kernelList) { if (useWeb){ json args = json::object({ {"et", et}, {"format", format}, {"precision", precision}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("etToUtc", args); string result = out["body"]["return"].get<string>(); @@ -457,8 +507,8 @@ namespace SpiceQL { if (searchKernels) { lsks = Inventory::search_for_kernelset("base", {"lsk"}); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(lsks, regexk); } @@ -474,14 +524,13 @@ namespace SpiceQL { } - pair<int, json> translateNameToCode(string frame, string mission, bool useWeb, bool searchKernels, vector<string> kernel_list) { + pair<int, json> translateNameToCode(string frame, string mission, bool useWeb, bool searchKernels, vector<string> kernelList) { if (useWeb){ json args = json::object({ {"frame", frame}, {"mission", mission}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("translateNameToCode", args); int result = out["body"]["return"].get<int>(); @@ -496,8 +545,8 @@ namespace SpiceQL { kernelsToLoad = Inventory::search_for_kernelset(mission, {"fk"}); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(kernelsToLoad, regexk); } @@ -521,14 +570,13 @@ namespace SpiceQL { } - pair<string, json> translateCodeToName(int frame, string mission, bool useWeb, bool searchKernels, vector<string> kernel_list) { + pair<string, json> translateCodeToName(int frame, string mission, bool useWeb, bool searchKernels, vector<string> kernelList) { if (useWeb){ json args = json::object({ {"frame", frame}, {"mission", mission}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("translateCodeToame", args); string result = out["body"]["return"].get<string>(); @@ -542,8 +590,8 @@ namespace SpiceQL { if (mission != "" && searchKernels){ kernelsToLoad = Inventory::search_for_kernelset(mission, {"fk"}); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(kernelsToLoad, regexk); } @@ -567,14 +615,13 @@ namespace SpiceQL { } - pair<vector<int>, json> getFrameInfo(int frame, string mission, bool useWeb, bool searchKernels, vector<string> kernel_list) { + pair<vector<int>, json> getFrameInfo(int frame, string mission, bool useWeb, bool searchKernels, vector<string> kernelList) { if (useWeb){ json args = json::object({ {"frame", frame}, {"mission", mission}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("getFrameInfo", args); vector<int> result = jsonIntArrayToVector(out["body"]["return"]); @@ -592,8 +639,8 @@ namespace SpiceQL { // Load only the FKs kernelsToLoad = Inventory::search_for_kernelset(mission, {"fk"}); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(kernelsToLoad, regexk); } @@ -612,14 +659,13 @@ namespace SpiceQL { } - pair<json, json> getTargetFrameInfo(int targetId, string mission, bool useWeb, bool searchKernels, vector<string> kernel_list) { + pair<json, json> getTargetFrameInfo(int targetId, string mission, bool useWeb, bool searchKernels, vector<string> kernelList) { if (useWeb){ json args = json::object({ {"targetId", targetId}, {"mission", mission}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("getTargetFrameInfo", args); json result = out["body"]["return"]; @@ -637,8 +683,8 @@ namespace SpiceQL { kernelsToLoad = Inventory::search_for_kernelsets({mission, "base"}, {"fk"}); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(kernelsToLoad, regexk); } @@ -660,14 +706,13 @@ namespace SpiceQL { } - pair<json, json> findMissionKeywords(string key, string mission, bool useWeb, bool searchKernels, vector<string> kernel_list) { + pair<json, json> findMissionKeywords(string key, string mission, bool useWeb, bool searchKernels, vector<string> kernelList) { if (useWeb){ json args = json::object({ {"key", key}, {"mission", mission}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("findMissionKeywords", args); json result = out["body"]["return"]; @@ -680,8 +725,8 @@ namespace SpiceQL { translationKernels = Inventory::search_for_kernelset(mission, {"iak", "fk", "ik"}); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(translationKernels, regexk); } @@ -692,14 +737,13 @@ namespace SpiceQL { } - pair<json, json> findTargetKeywords(string key, string mission, bool useWeb, bool searchKernels, vector<string> kernel_list) { + pair<json, json> findTargetKeywords(string key, string mission, bool useWeb, bool searchKernels, vector<string> kernelList) { if (useWeb){ json args = json::object({ {"key", key}, {"mission", mission}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("findTargetKeywords", args); json result = out["body"]["return"]; @@ -712,8 +756,8 @@ namespace SpiceQL { kernelsToLoad = Inventory::search_for_kernelsets({mission, "base"}, {"pck"}); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(kernelsToLoad, regexk); } @@ -723,7 +767,7 @@ namespace SpiceQL { } - pair<vector<vector<int>>, json> frameTrace(double et, int initialFrame, string mission, vector<string> ckQualities, bool useWeb, bool searchKernels, vector<string> kernel_list) { + pair<vector<vector<int>>, json> frameTrace(double et, int initialFrame, string mission, vector<string> ckQualities, bool useWeb, bool searchKernels, vector<string> kernelList) { checkNaifErrors(); if (useWeb){ @@ -732,9 +776,8 @@ namespace SpiceQL { {"initialFrame", initialFrame}, {"mission", mission}, {"ckQualities", ckQualities}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("frameTrace", args); vector<vector<int>> kvect = json2DIntArrayTo2DVector(out["body"]["return"]); @@ -747,8 +790,8 @@ namespace SpiceQL { ephemKernels = Inventory::search_for_kernelsets({mission, "base"}, {"sclk", "ck", "pck", "fk", "lsk", "tspk"}, et, et, ckQualities, {"noquality"}); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(ephemKernels, regexk); } @@ -873,7 +916,7 @@ namespace SpiceQL { } - pair<vector<double>, json> extractExactCkTimes(double observStart, double observEnd, int targetFrame, string mission, vector<string> ckQualities, bool useWeb, bool searchKernels, vector<string> kernel_list) { + pair<vector<double>, json> extractExactCkTimes(double observStart, double observEnd, int targetFrame, string mission, vector<string> ckQualities, bool useWeb, bool searchKernels, vector<string> kernelList) { SPDLOG_TRACE("Calling extractExactCkTimes with {}, {}, {}, {}, {}, {}, {}", observStart, observEnd, targetFrame, mission, ckQualities.size(), useWeb, searchKernels); if (useWeb){ @@ -883,9 +926,8 @@ namespace SpiceQL { {"targetFrame",targetFrame}, {"mission", mission}, {"ckQualities", ckQualities}, - {"useWeb", false}, {"searchKernels", searchKernels}, - {"kernelList", kernel_list} + {"kernelList", kernelList} }); json out = spiceAPIQuery("extractExactCkTimes", args); vector<double> kvect = jsonDoubleArrayToVector(out["body"]["return"]); @@ -899,8 +941,8 @@ namespace SpiceQL { ephemKernels = Inventory::search_for_kernelsets({mission, "base"}, {"ck", "sclk", "lsk"}, observStart, observEnd, ckQualities, {"noquality"}); } - if (!kernel_list.empty()) { - json regexk = Inventory::search_for_kernelset_from_regex(kernel_list); + if (!kernelList.empty()) { + json regexk = Inventory::search_for_kernelset_from_regex(kernelList); // merge them into the ephem kernels overwriting anything found in the query merge_json(ephemKernels, regexk); }