Unverified Commit 9cb89d41 authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by GitHub
Browse files

fixing bugs in the time search (#41)

* merge conflicts

* test fixes

* forgot to update kernel list
parent a793fdb9
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
{
  "lro" : {
    "ik" : {
      "kernels" : ["lro_instruments_v[0-9]{2}.ti$"]
    },
    "iak" : {
      "kernels" : ["lro_instrumentAddendum_v[0-9]{2}.ti$"]
    },
+32 −17
Original line number Diff line number Diff line
@@ -42,7 +42,9 @@ namespace SpiceQL {
  string DB_START_TIME_KEY = "starttime"; 
  string DB_STOP_TIME_KEY = "stoptime"; 
  string DB_TIME_FILES_KEY = "path_index"; 
  string DB_SS_TIME_INDICES_KEY = "ss_index"; 
  string DB_START_TIME_INDICES_KEY = "start_kindex"; 
  string DB_STOP_TIME_INDICES_KEY = "stop_kindex"; 


  string getCacheDir() { 
      static std::string  CACHE_DIRECTORY = "";
@@ -141,15 +143,19 @@ namespace SpiceQL {
      json json_kernels = getLatestKernels(config.get()); 

      // load time kernels for creating the timed kernel DataBase 
      json sclk_json = getLatestKernels(config.getRecursive("sclk")); 
      json lsk_json = getLatestKernels(config.getRecursive("lsk")); 
      json lsk_json = getLatestKernels(config["base"].getRecursive("lsk")); 

      SPDLOG_TRACE("InventoryImpl LSKs: {}", lsk_json.dump(4));

      m_required_kernels.load(sclk_json); 
      m_required_kernels.load(lsk_json); 

      for (auto &[mission, kernels] : json_kernels.items()) {
        fmt::print("mission: {}\n", mission);    

        json sclk_json = getLatestKernels(config[mission].getRecursive("sclk")); 
        SPDLOG_TRACE("{} SCLKs: {}", mission, sclk_json.dump(4)); 
        KernelSet sclks_ks(sclk_json); 

        for(auto &[kernel_type, kernel_obj] : kernels.items()) { 
          if (kernel_type == "ck" || kernel_type == "spk") { 
            // we need to log the times
@@ -272,15 +278,18 @@ namespace SpiceQL {

              vector<double> start_times_v = getKey<vector<double>>(DB_SPICE_ROOT_KEY+"/"+key+"/"+DB_START_TIME_KEY); 
              vector<double> stop_times_v = getKey<vector<double>>(DB_SPICE_ROOT_KEY+"/"+key+"/"+DB_STOP_TIME_KEY);
              vector<size_t> file_index_v = getKey<vector<size_t>>(DB_SPICE_ROOT_KEY+"/"+key+"/"+DB_SS_TIME_INDICES_KEY); 
              vector<size_t> start_file_index_v = getKey<vector<size_t>>(DB_SPICE_ROOT_KEY+"/"+key+"/"+DB_START_TIME_INDICES_KEY); 
              vector<size_t> stop_file_index_v = getKey<vector<size_t>>(DB_SPICE_ROOT_KEY+"/"+key+"/"+DB_STOP_TIME_INDICES_KEY); 
              vector<string> file_paths_v = getKey<vector<string>>(DB_SPICE_ROOT_KEY+"/"+key+"/"+DB_TIME_FILES_KEY); 

              time_indices->file_paths = file_paths_v;
              SPDLOG_TRACE("Index, start time, stop time sizes: {}, {}, {}", file_index_v.size(), start_times_v.size(), stop_times_v.size());
              SPDLOG_TRACE("Index, start time, stop time sizes: {}, {}, {}", start_file_index_v.size(), start_times_v.size(), stop_times_v.size());
              // load start_times 
              for(size_t i = 0; i < start_times_v.size(); i++) {
                time_indices->start_times[start_times_v[i]] = file_index_v[i];
                time_indices->stop_times[stop_times_v[i]] = file_index_v[i];
                time_indices->start_times[start_times_v[i]] = start_file_index_v[i];
              }
              for(size_t i = 0; i < stop_times_v.size(); i++) {
                time_indices->stop_times[stop_times_v[i]] = stop_file_index_v[i];
              }
            }
            catch (runtime_error &e) { 
@@ -313,6 +322,7 @@ namespace SpiceQL {
          }
          for(auto it = time_indices->start_times.begin() ;it != start_upper_bound; it++) {
            iterations++;
            SPDLOG_TRACE("Inserting {} with the start time {}", time_indices->file_paths.at(it->second), it->first);
            start_time_kernels.insert(it->second);             
          }

@@ -320,15 +330,15 @@ namespace SpiceQL {

          // Get everything stopping after the start_time; 
          auto stop_lower_bound = time_indices->stop_times.lower_bound(start_time);
          SPDLOG_TRACE("IS {} in the array? {}", stop_lower_bound->second, start_time_kernels.contains(stop_lower_bound->second)); 
          if(time_indices->stop_times.end() == stop_lower_bound && stop_lower_bound->first >= stop_time && start_time_kernels.contains(stop_lower_bound->second)) { 
            SPDLOG_TRACE("Is {} in the array? {}", stop_lower_bound->second, start_time_kernels.contains(stop_lower_bound->second)); 
            final_time_kernels.push_back(time_indices->file_paths.at(stop_lower_bound->second));
          }
          else { 
            for(auto &it = stop_lower_bound;it != time_indices->stop_times.end(); it++) { 
            for(auto it = stop_lower_bound;it != time_indices->stop_times.end(); it++) { 
              // if it's also in the start_time set, add it to the list
              iterations++;
              SPDLOG_TRACE("IS {} in the array? {}", it->second, start_time_kernels.contains(it->second)); 
              SPDLOG_TRACE("Is {} with stop time {} in the array? {}", time_indices->file_paths.at(it->second), it->first, start_time_kernels.contains(it->second)); 
              if (start_time_kernels.contains(it->second)) {
                final_time_kernels.push_back(data_dir / time_indices->file_paths.at(it->second));
              }
@@ -394,21 +404,26 @@ namespace SpiceQL {
        start_times_v.reserve(kernels->start_times.size());
        vector<double> stop_times_v;
        stop_times_v.reserve(kernels->stop_times.size());
        vector<size_t> indices_v;
        indices_v.reserve(kernels->start_times.size());
        vector<size_t> start_indices_v;
        start_indices_v.reserve(kernels->start_times.size());
        vector<size_t> stop_indices_v;
        stop_indices_v.reserve(kernels->stop_times.size());


        for (const auto &[k, v] : kernels->start_times) { 
          start_times_v.push_back(k);
          indices_v.push_back(v);
          start_indices_v.push_back(v);
        }

        for (const auto &[k, v] : kernels->stop_times) { 
          stop_times_v.push_back(k);
          stop_indices_v.push_back(v);
        } 

        H5Easy::dump(file, DB_SPICE_ROOT_KEY + "/"+kernel_key+"/"+DB_START_TIME_KEY, start_times_v, H5Easy::DumpMode::Overwrite);
        H5Easy::dump(file, DB_SPICE_ROOT_KEY + "/"+kernel_key+"/"+DB_STOP_TIME_KEY, stop_times_v, H5Easy::DumpMode::Overwrite);
        H5Easy::dump(file, DB_SPICE_ROOT_KEY + "/"+kernel_key+"/"+DB_SS_TIME_INDICES_KEY, indices_v, H5Easy::DumpMode::Overwrite);
        H5Easy::dump(file, DB_SPICE_ROOT_KEY + "/"+kernel_key+"/"+DB_START_TIME_INDICES_KEY, start_indices_v, H5Easy::DumpMode::Overwrite);
        H5Easy::dump(file, DB_SPICE_ROOT_KEY + "/"+kernel_key+"/"+DB_STOP_TIME_INDICES_KEY, stop_indices_v, H5Easy::DumpMode::Overwrite);
      }
    }

+17 −0
Original line number Diff line number Diff line
@@ -230,6 +230,13 @@ namespace SpiceQL {
    }
    if (pointers.empty() && kernels.is_object()) { 
      // Assume it's in the format {"sclk" : ["path1", "path2"], "ck" : ["path1"], ...}  
      
      json iaks = {};
      // we want to furnish them last
      if(kernels.contains("iak")) { 
        iaks = kernels["iak"]; 
        kernels.erase("iak");
      }
      for (auto& [key, val] : kernels.items()) { 
        SPDLOG_TRACE("Getting Kernels of Type: {}", key);
        if(!val.empty()) { 
@@ -240,6 +247,16 @@ namespace SpiceQL {
          } 
        }
      }

      // add iaks at the end
      if(!iaks.empty()) { 
        vector<string> ks = jsonArrayToVector(iaks);
        for (auto &kernel : ks) { 
            SPDLOG_TRACE("Adding: {}", kernel);
            kernelVect.push_back(kernel);
        }  
      }

    }
    else {
      for (auto & p : pointers) {
+1 −2
Original line number Diff line number Diff line
@@ -80,8 +80,7 @@ namespace SpiceQL {
      return static_cast<Kernel::Quality>(res.second);
    }

    std::string qualities = std::accumulate(Kernel::QUALITIES.begin(), Kernel::QUALITIES.end(), std::string(", "));
    throw invalid_argument(fmt::format("{} is not a valid kernel type, available types are: {}", qa, qualities));
    throw invalid_argument(fmt::format("{} is not a valid kernel type, available types are: {}", qa, fmt::join(Kernel::QUALITIES, ", ")));
  }


+9 −15
Original line number Diff line number Diff line
@@ -176,6 +176,8 @@ namespace SpiceQL {


  vector<double> getTargetState(double et, string target, string observer, string frame, string abcorr) {
    SPDLOG_TRACE("getTargetState(et={}, target={}, observer={}, frame={}, abcorr={})", et, target, observer, frame, abcorr);

    // convert params to spice types
    ConstSpiceChar *target_spice = target.c_str();  // better way to do this?
    ConstSpiceChar *observer_spice = observer.c_str();
@@ -185,7 +187,6 @@ namespace SpiceQL {
    // define outputs
    SpiceDouble lt;
    SpiceDouble starg_spice[6];

    checkNaifErrors();
    spkezr_c( target_spice, et, frame_spice, abcorr_spice, observer_spice, starg_spice, &lt );
    checkNaifErrors();
@@ -208,26 +209,19 @@ namespace SpiceQL {
    }

    json ephemKernels = {};
    json lskKernels = {};
    json pckKernels = {};
    json spkKernels = {};
    json baseKernels = {};

    if (searchKernels) {
      ephemKernels = Inventory::search_for_kernelset(mission, {"sclk", "ck", "spk", "pck", "tspk"}, ets.front(), ets.back(), ckQuality, spkQuality);
      lskKernels = Inventory::search_for_kernelset("base", {"lsk"});
      pckKernels = Inventory::search_for_kernelset("base", {"pck"});
      spkKernels = Inventory::search_for_kernelset("base", {"spk"});
      SPDLOG_DEBUG("LSK Kernels : {}", lskKernels.dump(4));
      ephemKernels = Inventory::search_for_kernelset(mission, {"sclk", "ck", "spk", "pck", "tspk", "fk"}, ets.front(), ets.back(), ckQuality, spkQuality);
      baseKernels = Inventory::search_for_kernelset("base", {"lsk", "pck", "spk"});
      SPDLOG_DEBUG("Base Kernels : {}", baseKernels.dump(4));
      SPDLOG_DEBUG("{} Kernels : {}", mission, ephemKernels.dump(4));
      SPDLOG_DEBUG("PCK Kernels : {}", pckKernels.dump(4));
      SPDLOG_DEBUG("SPK Kernels : {}", spkKernels.dump(4)); 
    }

    auto start = high_resolution_clock::now();
    KernelSet baseSet(baseKernels);
    KernelSet ephemSet(ephemKernels);
    KernelSet lskSet(lskKernels);
    KernelSet pckSet(pckKernels);
    KernelSet spkSet(spkKernels);

    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    SPDLOG_INFO("Time in microseconds to furnish kernel sets: {}", duration.count());
@@ -1102,7 +1096,7 @@ namespace SpiceQL {
          ssize_c(200000, &cover);

          // A SPICE SEGMENT is composed of SPICE INTERVALS
          ckcov_c(kpath.c_str(), body, SPICEFALSE, "SEGMENT", 0.0, "TDB", &cover);
          ckcov_c(kpath.c_str(), body, SPICEFALSE, "INTERVAL", 0.0, "TDB", &cover);

          getStartStopFromInterval(cover);
        }
Loading