Program Listing for File sp3_loader.h

Return to documentation for file (interfaces/sp3_loader.h)

#pragma once

#include <filesystem>
#include <map>
#include <string>
#include <vector>

#include "lupnt/core/constants.h"
#include "lupnt/core/definitions.h"
#include "lupnt/numerics/cheby_fit.h"

namespace lupnt {

  class Sp3Loader {
  public:
    Sp3Loader() = default;

    explicit Sp3Loader(const std::filesystem::path& filepath);

    explicit Sp3Loader(const std::vector<std::filesystem::path>& filepaths);

    void LoadFile(const std::filesystem::path& filepath);

    static std::string FilenameForEpoch(Real epoch, Time time_scale = Time::UTC);

    static std::string UrlForEpoch(Real epoch, Time time_scale = Time::UTC);

    static std::filesystem::path DownloadFileForEpoch(Real epoch, Time time_scale = Time::UTC,
                                                      const std::filesystem::path& cache_dir
                                                      = std::filesystem::path());

    const std::vector<std::string>& GetSatellites() const { return sats_; }

    bool HasSatellite(const std::string& sat_id) const;

    void GetPosVelClock(const std::string& sat_id, Real t_tai, Vec6& rv_ecef,
                        Real& clock_bias_s) const;

    Vec6 GetPosVel(const std::string& sat_id, Real t_tai) const;

    std::pair<double, double> GetTimeSpan(const std::string& sat_id) const;

  private:
    std::vector<std::string> sats_;            // SP3 identifiers, e.g. "G01"
    std::map<std::string, VecXd> epochs_tai_;  // sat -> [N] epochs (TAI seconds, sorted)
    std::map<std::string, MatXd> pos_clock_;   // sat -> [N x 4] ECEF (x,y,z) [m], clock [s]
    std::map<std::string, ChebyshevFitModel> pos_clock_cheby_;  // sat -> [x,y,z,clock] fit

    void ParseFile(const std::filesystem::path& filepath);
    void RebuildChebyshevModels();
  };

}  // namespace lupnt