-
Notifications
You must be signed in to change notification settings - Fork 9
ISD to Kernel support #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2d08cd4
wip
chkim-usgs 28ff7b7
Merge branch 'DOI-USGS:main' into isd_to_kern
chkim-usgs b99b28a
rename io.py to ck_writer.py
chkim-usgs 4f36e66
Merge branch 'DOI-USGS:main' into isd_to_kern
chkim-usgs e0a9fa4
rename
chkim-usgs 6264fb9
remove comment
chkim-usgs 7f3c545
update changelog
chkim-usgs 86a0378
add kernel ext support
chkim-usgs 8ea9ecb
fix
chkim-usgs cb337ff
updated aliasMap
chkim-usgs d2a1373
remove ck_writer
chkim-usgs 3c076bf
fix tests
chkim-usgs 7e546aa
Merge branch 'main' into isd_to_kern
chkim-usgs 3398db3
fix msi db
chkim-usgs 1c275ab
search ik and iak too for translateCodeToName
chkim-usgs 1b2c11e
update aliasMap
chkim-usgs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| }, | ||
| "iak" : { | ||
| "kernels" : ["msiAddendum[0-9]{3}.ti$"] | ||
| } | ||
| }, | ||
| "deps": ["/near"] | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| * | ||
| **/ | ||
|
|
||
| #include <cstddef> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| #include <iostream> | ||
| #include <fstream> | ||
| #include <memory> | ||
| #include <sstream> | ||
|
|
||
| #include <fmt/format.h> | ||
| #include <ghc/fs_std.hpp> | ||
|
|
@@ -10,6 +12,8 @@ | |
| #include "io.h" | ||
| #include "utils.h" | ||
|
|
||
| #include <spdlog/spdlog.h> | ||
|
|
||
|
|
||
| using namespace std; | ||
|
|
||
|
|
@@ -74,7 +78,7 @@ namespace SpiceQL { | |
| this->angularVelocities = angularVelocities; | ||
| this->comment = comment; | ||
| } | ||
|
|
||
|
|
||
| void writeCk(string path, | ||
| vector<vector<double>> quats, | ||
|
|
@@ -90,9 +94,15 @@ namespace SpiceQL { | |
| SpiceInt handle; | ||
|
|
||
| // convert times, but first, we need SCLK+LSK kernels | ||
| Kernel sclkKernel(sclk); | ||
| Kernel lskKernel(lsk); | ||
|
|
||
| // allow and furnish multiple sclks | ||
| std::vector<std::unique_ptr<Kernel>> sclkKernels; | ||
| if (!sclk.empty()) { | ||
| for (const std::string& sclkPath : split(sclk, ',')) | ||
| sclkKernels.push_back(std::make_unique<Kernel>(sclkPath)); | ||
| } | ||
| Kernel lskKernel(lsk); | ||
|
|
||
| for(auto &et : times) { | ||
| double sclkdp; | ||
| checkNaifErrors(); | ||
|
|
@@ -109,6 +119,33 @@ namespace SpiceQL { | |
| ckopn_c(path.c_str(), "CK", comment.size(), &handle); | ||
| checkNaifErrors(); | ||
|
|
||
| // Flatten the nested quaternions into a single contiguous array. | ||
| // CSPICE functions (like ckw03_c) are C-based and expect a pointer to a | ||
| // contiguous block of memory (SpiceDouble quats[][4]). | ||
| // A std::vector<std::vector<double>> stores inner vectors in fragmented | ||
| // locations on the heap; we must "flatten" them into a single ribbon | ||
| // of doubles so that pointer arithmetic works correctly inside SPICE. | ||
| vector<double> flatQuats; | ||
| flatQuats.reserve(quats.size() * 4); | ||
| for (const auto& q : quats) { | ||
| for (double d : q) { | ||
| flatQuats.push_back(d); | ||
| } | ||
| } | ||
|
|
||
| // Flatten angular velocities if they exist. | ||
| // Similar to quaternions, AV data must be contiguous (SpiceDouble av[][3]). | ||
| // We check if the input nested vector is non-empty before proceeding. | ||
| vector<double> flatAv; | ||
| if (!angularVelocities.empty()) { | ||
| flatAv.reserve(angularVelocities.size() * 3); | ||
| for (const auto& a : angularVelocities) { | ||
| for (double d : a) { | ||
| flatAv.push_back(d); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+139
to
+147
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
|
|
||
| ckw03_c (handle, | ||
| times.at(0), | ||
| times.at(times.size()-1), | ||
|
|
@@ -118,8 +155,8 @@ namespace SpiceQL { | |
| segmentId.c_str(), | ||
| times.size(), | ||
| times.data(), | ||
| quats.data(), | ||
| (!angularVelocities.empty()) ? angularVelocities.data() : nullptr, | ||
| flatQuats.data(), | ||
| (!angularVelocities.empty()) ? flatAv.data() : nullptr, | ||
| times.size(), | ||
| times.data()); | ||
| checkNaifErrors(); | ||
|
|
@@ -141,6 +178,22 @@ namespace SpiceQL { | |
| vector<vector<double>> stateVelocities, | ||
| string segmentComment) { | ||
|
|
||
| if (stateTimes.empty() || statePositions.empty()) { | ||
| throw runtime_error("writeSpk: stateTimes and statePositions must be non-empty."); | ||
| } | ||
|
|
||
| // NAIF spkw13_c requires segment start time < end time. Single-epoch (e.g. from ISD) has start == end. | ||
| if (stateTimes.size() == 1) { | ||
| stateTimes.push_back(stateTimes.front() + 1E-6); | ||
| statePositions.push_back(statePositions.front()); | ||
| if (!stateVelocities.empty()) { | ||
| stateVelocities.push_back(stateVelocities.front()); | ||
| } | ||
| } else if (stateTimes.front() >= stateTimes.back()) { | ||
| throw runtime_error( | ||
| "writeSpk: segment start time must be less than end time (got start == end or reversed order)."); | ||
| } | ||
|
|
||
| vector<vector<double>> states; | ||
|
|
||
| if (stateVelocities.empty()) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a TODO to use std::move instead, will be faster but idk if it matters until we start using it.