Skip to content

Commit f8db67e

Browse files
AustinSanderschkim-usgsKelvinrr
authored
Replace cspice calls with spiceql and add api accessor function (#5545)
* Added findspiceql to build system * Added spiceql * Initial isis/spiceql wrapped functions * added todo * merge dev * Replaced apollopaninit cspice calls with spiceql * Updated local spice calls with searchkernels=true * Replaced voyager2isis cspice calls with spiceql calls * Replaced vikcal calparameters cspice calls with spiceql calls * Updated rosvirtis2isis cspice calls with spiceql calls * Replaced newhorizons cspice calls with spiceql calls * Replaced lronaccal cspice calls with spiceql calls * Replaced chan1m32isis cspice calls with spiceql calls * Replaced gllssical cspice calls with spiceql calls * Replaced lrowaccal cspice calls with spiceql calls * Replaced amicacal cspice calls with spiceql calls * Replaced hicalconf cspice calls with spiceql calls * Add spiceql to environment * Replaced mical cspice calls with spiceql calls * Replaced moccal cspice calls with spiceql calls * Replaced moclabels cspice calls with spiceql calls * Replaced ctxcal cspice calls with spiceql calls * Replaced hijitcube cspice calls with spiceql calls * Replaced sumfinder cspice calls with spiceql calls * Removed unused variables and added TODO * Replaced hicrop cspice calls with spiceql calls * Added mission map * Updated getTargetStates vector to include velocities * Replaced mdiscal cspice calls with spiceql calls * Removed unused variables * Removed test couts * Added uri encoding function * Converted shadow cspice calls to spiceql calls * Converted spiceql ettosclk call to upstream version * Removed useweb argument in favor of isis preference * Changed functions with large param lists to POST * Added useweb argument * trigger build * Capitalize SpiceQL * Update spiceql path_suffix * Update spiceql library name * Change SpiceQL.h to spiceql.h * Remove KernelPool * Remove KernelPool * Remove KernelPool in shadow * Remove false bools in apollopaninit * Movie Isis import to top * Replace furnsh_c with load * Replace base in sumspice * Replace post with get calls * Lowercase mars * Turn off web spice for tests * Pin spiceql to 1.0.1 * Remove defaults channel * Update apollopaninit call * Add back spiceql dep * Update load kernels for apollopaninit * Remove gmock-global * Remove protobuf config * trigger build * Set webspice to false * Remove non-existent test cube file for lrowaccal-mono * updated preferences * Update two lronaccal tests * fixed some calibratation tests * api updates * updated spiceql version * trigger build * Add back channel * Add useWeb to SpiceQL calls * Update spiceql to 1.1.3 * Update tests * fix shadow test --------- Co-authored-by: Christine Kim <[email protected]> Co-authored-by: Christine Kim <[email protected]> Co-authored-by: kelvinrr <[email protected]>
1 parent afaa218 commit f8db67e

File tree

45 files changed

+2611
-679
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2611
-679
lines changed

environment.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
channels:
22
- conda-forge
33
- usgs-astrogeology
4-
4+
55
dependencies:
66
- ale =0.11.0,<1
77
- aom
@@ -63,6 +63,7 @@ dependencies:
6363
- qhull
6464
- qt-main>=5.15, <5.16
6565
- qwt <6.3.0
66+
- spiceql >=1.1.3
6667
- sqlite >=3.46.0,<3.47
6768
- suitesparse <7.7.0
6869
- superlu

isis/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ find_package(PCL REQUIRED)
305305
find_package(Protobuf REQUIRED)
306306
find_package(Qwt 6 REQUIRED)
307307
find_package(SuperLU 4.3 REQUIRED)
308+
find_package(SpiceQL REQUIRED)
308309
find_package(TIFF 4.0.0 REQUIRED)
309310
find_package(TNT 126 REQUIRED)
310311
find_package(XercesC 3.1.2 REQUIRED)

isis/IsisPreferences

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,17 @@ Group = Plugins
186186
"$HOME/.Isis/csm3.0.3/")
187187
EndGroup
188188

189+
########################################################
190+
#
191+
# Set whether spice calls use the SpiceQL web API or
192+
# local kernels.
193+
#
194+
########################################################
195+
196+
Group = WebSpice
197+
UseWebSpice = "false"
198+
EndGroup
199+
189200
########################################################
190201
# Customize the location of mission specific data
191202
# files (calibration and spice kernels). Usually this

isis/TestPreferences

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ Group = Plugins
184184
"$HOME/.Isis/csm3.0.3/")
185185
EndGroup
186186

187+
########################################################
188+
#
189+
# Set whether spice calls use the SpiceQL web API or
190+
# local kernels.
191+
#
192+
########################################################
193+
194+
Group = WebSpice
195+
UseWebSpice = "false"
196+
EndGroup
197+
198+
187199
########################################################
188200
# Customize the location of mission specific data
189201
# files (calibration and spice kernels). Usually this

isis/cmake/FindSpiceQL.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# CMake module for find_package(SpiceQL)
2+
# Finds include directory and all applicable libraries
3+
#
4+
# Sets the following:
5+
# SpiceQL_INCLUDE_DIR
6+
# SpiceQL_LIBRARY
7+
8+
find_path(SPICEQL_INCLUDE_DIR
9+
NAME spiceql.h
10+
PATH_SUFFIXES "SpiceQL"
11+
)
12+
13+
find_library(SPICEQL_LIBRARY
14+
NAMES SpiceQL
15+
)
16+
17+
get_filename_component(SUPERLU_ROOT_INCLUDE_DIR "${SUPERLU_INCLUDE_DIR}" DIRECTORY)
18+
19+
20+
message(STATUS "SPICEQL INCLUDE DIR: " ${SPICEQL_INCLUDE_DIR} )
21+
message(STATUS "SPICEQL LIB: " ${SPICEQL_LIBRARY} )
22+
23+
get_filename_component(SPICEQL_ROOT_INCLUDE_DIR "${SPICEQL_INCLUDE_DIR}" DIRECTORY)

isis/src/apollo/apps/apollopaninit/main.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,20 @@ find files of those names at the top level of this repository. **/
3232
#include "IString.h"
3333
#include "iTime.h"
3434
#include "JP2Decoder.h"
35+
#include "Preference.h"
3536
#include "ProcessImport.h"
3637
#include "Pvl.h"
3738
#include "PvlGroup.h"
3839
#include "PvlKeyword.h"
3940
#include "PvlObject.h"
4041
#include "PvlTranslationTable.h"
42+
#include "spiceql.h"
4143
#include "Spice.h"
4244
#include "SpicePosition.h"
4345
#include "SpiceRotation.h"
4446
#include "Table.h"
4547
#include "UserInterface.h"
48+
#include "spiceql.h"
4649

4750

4851
#define FIDL 26.72093 //spacing between fiducial marks in mm
@@ -228,25 +231,34 @@ void IsisMain() {
228231

229232
panCube.putGroup(kernels_pvlG);
230233

231-
//Load all the kernels
234+
// Load kernels
232235
Load_Kernel(kernels_pvlG["TargetPosition"]);
233236
Load_Kernel(kernels_pvlG["TargetAttitudeShape"]);
237+
// Load_Kernel(kernels_pvlG["InstrumentPointing"]);
238+
// Load_Kernel(kernels_pvlG["InstrumentPosition"]);
234239
Load_Kernel(kernels_pvlG["LeapSecond"]);
240+
// Load_Kernel(kernels_pvlG["InstrumentAddendum"]);
241+
235242

236243
//////////////////////////////////////////attach a target rotation table
237-
char frameName[32];
238-
SpiceInt frameCode;
239-
SpiceBoolean found;
240-
//get the framecode from the body code (301=MOON)
241-
cidfrm_c(301, sizeof(frameName), &frameCode, frameName, &found);
242-
if(!found) {
243-
QString naifTarget = QString("IAU_MOOM");
244-
namfrm_c(naifTarget.toLatin1().data(), &frameCode);
245-
if(frameCode == 0) {
246-
QString msg = "Can not find NAIF code for [" + naifTarget + "]";
247-
throw IException(IException::Io, msg, _FILEINFO_);
248-
}
249-
}
244+
bool useWeb = QString(Preference::Preferences().findGroup("WebSpice")["UseWebSpice"]).toUpper() == "TRUE";
245+
std::string frameName;
246+
SpiceInt frameCode = 0;
247+
try {
248+
auto [output, kernels] = SpiceQL::getTargetFrameInfo(301, mission.toLower().toStdString(), useWeb);
249+
cout << output << endl;
250+
frameCode = output["frameCode"].get<SpiceInt>();
251+
frameName = output["frameName"].get<std::string>();
252+
} catch(std::invalid_argument) {
253+
std::string naifTarget = "IAU_MOON";
254+
auto [frameCode, kernels] = SpiceQL::translateNameToCode(naifTarget, mission.toLower().toStdString(), useWeb);
255+
if(frameCode == 0) {
256+
QString msg = "Can not find NAIF code for [" + QString::fromStdString(naifTarget) + "]";
257+
throw IException(IException::Io, msg, _FILEINFO_);
258+
}
259+
}
260+
261+
250262
spRot = new SpiceRotation(frameCode);
251263
//create a table from starttime to endtime (streched by 3%) with NODES entries
252264
spRot->LoadCache(time0-0.015*(time1-time0), time1+0.015*(time1-time0), NODES);
@@ -808,7 +820,7 @@ void Load_Kernel(Isis::PvlKeyword &key) {
808820
throw IException(IException::Io, msg, _FILEINFO_);
809821
}
810822
QString fileName(file.expanded());
811-
furnsh_c(fileName.toLatin1().data());
823+
SpiceQL::load(fileName.toLatin1().data());
812824
}
813825

814826
NaifStatus::CheckErrors();

isis/src/base/apps/appjit/LineScanCameraRotation.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#include "LeastSquares.h"
1515
#include "BasisFunction.h"
1616
#include "PolynomialUnivariate.h"
17+
#include "Preference.h"
1718
#include "IString.h"
1819
#include "iTime.h"
1920
#include "IException.h"
21+
#include "spiceql.h"
2022
#include "Table.h"
2123
#include "NaifStatus.h"
2224

@@ -54,8 +56,6 @@ namespace Isis {
5456
p_ckKeyword = kernels["InstrumentPointing"];
5557

5658
p_cacheTime = timeCache;
57-
// std::cout<<std::setprecision(24);
58-
// std::cout<<timeCache.at(0)<<"-"<<timeCache.at(50000)<<std::endl;
5959

6060
InitConstantRotation(p_cacheTime[0]);
6161

@@ -110,8 +110,6 @@ namespace Isis {
110110
// *** May need to do a frame trace and load the frames (at least the constant ones) ***
111111

112112
// Loop and load the cache
113-
double state[6];
114-
double lt;
115113
NaifStatus::CheckErrors();
116114

117115
double R[3]; // Direction of radial axis of line scan camera
@@ -124,15 +122,27 @@ namespace Isis {
124122
SpiceRotation *crot = p_spi->instrumentRotation();
125123

126124
std::vector<ale::Rotation> rotationCache;
125+
126+
bool useWeb = QString(Preference::Preferences().findGroup("WebSpice")["UseWebSpice"]).toUpper() == "TRUE";
127+
auto [sunLt, kernels] = SpiceQL::getTargetStates(p_cacheTime, "MRO", "mars", "IAU_MARS", "NONE", "mro", {"reconstructed"}, {"reconstructed"}, useWeb);
128+
129+
double state[6];
127130
for(std::vector<double>::iterator i = p_cacheTime.begin(); i < p_cacheTime.end(); i++) {
131+
// Clear state array before copying new values
132+
std::fill_n(state, 6, 0);
133+
128134
double et = *i;
129135

136+
// Get the index from the iterator
137+
size_t idx = i - p_cacheTime.begin();
138+
130139
prot->SetEphemerisTime(et);
131140
crot->SetEphemerisTime(et);
132141

133142
// The following code will be put into method LoadIBcache()
134-
spkezr_c("MRO", et, "IAU_MARS", "NONE", "MARS", state, &lt);
135-
NaifStatus::CheckErrors();
143+
144+
std::copy(sunLt[idx].begin(), sunLt[idx].begin()+6, state);
145+
136146

137147
// Compute the direction of the radial axis (3) of the line scan camera
138148
vscl_c(1. / vnorm_c(state), state, R); // vscl and vnorm only operate on first 3 members of state

isis/src/base/apps/shadow/shadow.cpp

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#include "KernelDb.h"
99
#include "NaifStatus.h"
1010
#include "ProcessByBrick.h"
11+
#include "spiceql.h"
1112
#include "ShadowFunctor.h"
1213
#include "SpicePosition.h"
14+
#include "spiceql.h"
1315

1416
namespace Isis {
1517
QStringList kernels(QString kernelType,
@@ -46,11 +48,12 @@ namespace Isis {
4648
allKernelFiles.append(kernels("PCK", &KernelDb::targetAttitudeShape, *demCube->label(), ui));
4749
allKernelFiles.append(kernels("SPK", &KernelDb::targetPosition, *demCube->label(), ui));
4850

51+
4952
NaifStatus::CheckErrors();
5053

5154
foreach (QString kernelFile, allKernelFiles) {
5255
kernelsUsed += kernelFile;
53-
furnsh_c(FileName(kernelFile).expanded().toLatin1().data());
56+
SpiceQL::load(FileName(kernelFile).expanded().toLatin1().data());
5457
}
5558

5659
// Find the NAIF target code for the DEM's target
@@ -63,28 +66,49 @@ namespace Isis {
6366

6467
// Get actual sun position, relative to target
6568
QString bodyFixedFrame = QString("IAU_%1").arg(name.toUpper());
66-
spkpos_c("SUN", time.Et(), bodyFixedFrame.toLatin1().data(), "NONE",
67-
name.toUpper().toLatin1().data(), sunPosition, &lightTime);
69+
std::vector<double> etStart = {time.Et()};
70+
std::string observer = name.toUpper().toLatin1().data();
71+
std::string bff = bodyFixedFrame.toLatin1().data();
72+
std::vector<std::vector<double>> sunLt;
73+
// If kernels are specified
74+
bool userKernels = false;
75+
76+
if (ui.WasEntered("PCK") || ui.WasEntered("SPK")){
77+
userKernels = true;
78+
}
79+
80+
bool useWeb = QString(Preference::Preferences().findGroup("WebSpice")["UseWebSpice"]).toUpper() == "TRUE";
81+
82+
if (userKernels) {
83+
auto [output, kernels] = SpiceQL::getTargetStates(etStart, "sun", observer, bff, "NONE", "base", {"reconstructed"}, {"reconstructed"}, useWeb, true);
84+
sunLt = output;
85+
} else {
86+
auto [output, kernels] = SpiceQL::getTargetStates(etStart, "sun", observer, bff, "NONE", SpiceQL::spiceql_mission_map[observer], {"reconstructed"}, {"reconstructed"}, useWeb);
87+
sunLt = output;
88+
}
6889

6990
NaifStatus::CheckErrors();
7091

71-
// Adjusted for light time
72-
spkpos_c("SUN", time.Et() - lightTime, bodyFixedFrame.toLatin1().data(), "NONE",
73-
name.toUpper().toLatin1().data(), sunPosition, &lightTime);
92+
// Adjust for light time
93+
lightTime = sunLt[0][6];
94+
etStart = {time.Et() - lightTime};
7495

96+
if (userKernels){
97+
auto [output, kernels] = SpiceQL::getTargetStates(etStart, "sun", observer, bff, "NONE", "base", {"reconstructed"}, {"reconstructed"}, useWeb, true);
98+
sunLt = output;
99+
}else{
100+
auto [output, kernels] =SpiceQL::getTargetStates(etStart, "sun", observer, bff, "NONE", SpiceQL::spiceql_mission_map[observer], {"reconstructed"}, {"reconstructed"}, useWeb);
101+
sunLt = output;
102+
}
103+
104+
std::copy(sunLt[0].begin(), sunLt[0].begin()+3, sunPosition);
75105
NaifStatus::CheckErrors();
76-
77-
106+
78107
// Convert sun position units: KM -> M
79108
sunPosition[0] *= 1000;
80109
sunPosition[1] *= 1000;
81110
sunPosition[2] *= 1000;
82111

83-
foreach (QString kernelFile, allKernelFiles) {
84-
unload_c(FileName(kernelFile).expanded().toLatin1().data());
85-
}
86-
87-
NaifStatus::CheckErrors();
88112
functor.setSunPosition(sunPosition);
89113
}
90114

isis/src/base/objs/Kernels/Kernels.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ find files of those names at the top level of this repository. **/
2323
#include "NaifStatus.h"
2424
#include "PvlKeyword.h"
2525
#include "Pvl.h"
26+
#include "spiceql.h"
2627

2728
using namespace std;
2829

@@ -776,7 +777,7 @@ namespace Isis {
776777
if (!kfile.loaded) {
777778
NaifStatus::CheckErrors();
778779
try {
779-
furnsh_c(kfile.fullpath.toLatin1().data());
780+
SpiceQL::load(kfile.fullpath.toLatin1().data());
780781
NaifStatus::CheckErrors();
781782
kfile.loaded = true;
782783
kfile.managed = true;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ifeq ($(ISISROOT), $(BLANK))
2+
.SILENT:
3+
error:
4+
echo "Please set ISISROOT";
5+
else
6+
include $(ISISROOT)/make/isismake.apps
7+
endif

0 commit comments

Comments
 (0)