Skip to content
Snippets Groups Projects
Unverified Commit 783b9133 authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by GitHub
Browse files

Ale changes (#36)

* added health check

* cleaned up returns

* added spiceql function

* changes for ALE
parent c1a7c840
No related branches found
No related tags found
No related merge requests found
...@@ -354,6 +354,20 @@ namespace SpiceQL { ...@@ -354,6 +354,20 @@ namespace SpiceQL {
*/ */
double doubleSclkToEt(int frameCode, double sclk, std::string mission, bool searchKernels=true); double doubleSclkToEt(int frameCode, double sclk, std::string mission, bool searchKernels=true);
/**
* @brief Converts a given double ephemeris time to an sclk string
*
*
* @param frameCode int Frame id to use
* @param et ephemeris time
* @param mission string Mission name as it relates to the config files
* @param searchKernels bool Whether to search the kernels for the user
* @return string
*/
std::string doubleEtToSclk(int frameCode, double et, std::string mission, bool searchKernels);
/** /**
* @brief Get the center, class id, and class of a given frame * @brief Get the center, class id, and class of a given frame
* *
......
...@@ -282,6 +282,7 @@ namespace SpiceQL { ...@@ -282,6 +282,7 @@ namespace SpiceQL {
**/ **/
std::vector<std::vector<int>> frameTrace(double et, int initialFrame, std::string mission="", std::string ckQuality="reconstructed", bool searchKernels=true); std::vector<std::vector<int>> frameTrace(double et, int initialFrame, std::string mission="", std::string ckQuality="reconstructed", bool searchKernels=true);
/** /**
* @brief finds key:values in kernel pool * @brief finds key:values in kernel pool
* *
......
...@@ -258,6 +258,26 @@ namespace SpiceQL { ...@@ -258,6 +258,26 @@ namespace SpiceQL {
return et; return et;
} }
string doubleEtToSclk(int frameCode, double et, string mission, bool searchKernels) {
Config missionConf;
json sclks;
if (searchKernels) {
sclks = loadSelectKernels("sclk", mission);
}
KernelSet sclkSet(sclks);
SpiceChar sclk[100];
checkNaifErrors();
sce2s_c(frameCode, et, 100, sclk);
checkNaifErrors();
SPDLOG_DEBUG("strsclktoet({}, {}, {}) -> {}", frameCode, mission, sclk, et);
return string(sclk);
}
json findMissionKeywords(string key, string mission, bool searchKernels) { json findMissionKeywords(string key, string mission, bool searchKernels) {
json translationKernels = {}; json translationKernels = {};
......
...@@ -399,33 +399,30 @@ namespace SpiceQL { ...@@ -399,33 +399,30 @@ namespace SpiceQL {
// First try getting the entire state matrix (6x6), which includes CJ and the angular velocity // First try getting the entire state matrix (6x6), which includes CJ and the angular velocity
checkNaifErrors(); checkNaifErrors();
frmchg_((int *) &refFrame, (int *) &toFrame, &et, (doublereal *) stateCJ); frmchg_((int *) &refFrame, (int *) &toFrame, &et, (doublereal *) stateCJ);
checkNaifErrors(); SpiceBoolean ckfailure = failed_c();
reset_c(); // Reset Naif error system to allow caller to recover
if (!failed_c()) { if (!ckfailure) {
// Transpose and isolate CJ and av // Transpose and isolate CJ and av
checkNaifErrors();
xpose6_c(stateCJ, stateCJ); xpose6_c(stateCJ, stateCJ);
xf2rav_c(stateCJ, CJ_spice, av_spice); xf2rav_c(stateCJ, CJ_spice, av_spice);
checkNaifErrors();
// Convert to std::array for output // Convert to std::array for output
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
orientation.push_back(av_spice[i]); orientation.push_back(av_spice[i]);
} }
} }
else { // TODO This case is untested else { // TODO This case is untested
// Recompute CJ_spice ignoring av // Recompute CJ_spice ignoring av
checkNaifErrors();
reset_c(); // reset frmchg_ failure reset_c(); // reset frmchg_ failure
refchg_((int *) &refFrame, (int *) &toFrame, &et, (doublereal *) CJ_spice); refchg_((int *) &refFrame, (int *) &toFrame, &et, (doublereal *) CJ_spice);
xpose_c(CJ_spice, CJ_spice); xpose_c(CJ_spice, CJ_spice);
checkNaifErrors();
has_av = false; has_av = false;
} }
checkNaifErrors();
// Translate matrix to std:array quaternion // Translate matrix to std:array quaternion
m2q_c(CJ_spice, quat_spice); m2q_c(CJ_spice, quat_spice);
...@@ -610,8 +607,8 @@ namespace SpiceQL { ...@@ -610,8 +607,8 @@ namespace SpiceQL {
json findKeywords(string keytpl) { json findKeywords(string keytpl) {
// Define gnpool i/o // Define gnpool i/o
const SpiceInt START = 0; const SpiceInt START = 0;
const SpiceInt ROOM = 50; const SpiceInt ROOM = 200;
const SpiceInt LENOUT = 100; const SpiceInt LENOUT = 200;
ConstSpiceChar *cstr = keytpl.c_str(); ConstSpiceChar *cstr = keytpl.c_str();
SpiceInt nkeys; SpiceInt nkeys;
SpiceChar kvals [ROOM][LENOUT]; SpiceChar kvals [ROOM][LENOUT];
...@@ -664,7 +661,6 @@ namespace SpiceQL { ...@@ -664,7 +661,6 @@ namespace SpiceQL {
if (!gdfound) { if (!gdfound) {
gipool_c(fkey, START, ROOM, &nvals, ivals, &gifound); gipool_c(fkey, START, ROOM, &nvals, ivals, &gifound);
checkNaifErrors(); checkNaifErrors();
} }
if (gifound) { if (gifound) {
......
...@@ -6,7 +6,11 @@ from fastapi import FastAPI, Query ...@@ -6,7 +6,11 @@ from fastapi import FastAPI, Query
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from starlette.responses import RedirectResponse from starlette.responses import RedirectResponse
import numpy as np import numpy as np
import os
import pyspiceql import pyspiceql
import logging
logger = logging.getLogger('uvicorn.error')
SEARCH_KERNELS_BOOL = True SEARCH_KERNELS_BOOL = True
...@@ -32,11 +36,16 @@ app = FastAPI() ...@@ -32,11 +36,16 @@ app = FastAPI()
async def root(): async def root():
return RedirectResponse(url="/docs") return RedirectResponse(url="/docs")
@app.post("/customMessage") @app.get("/healthCheck")
async def message( async def message():
message_item: MessageItem try:
): data_dir_exists = os.path.exists(pyspiceql.getDataDirectory())
return {"message": message_item.message} return {"data_content": os.listdir(pyspiceql.getDataDirectory()),
"data_dir_exists": data_dir_exists,
"is_healthy": data_dir_exists}
except Exception as e:
logger.error(f"ERROR: {e}")
return {"is_healthy": False}
# SpiceQL endpoints # SpiceQL endpoints
...@@ -125,6 +134,21 @@ async def doubleSclkToEt( ...@@ -125,6 +134,21 @@ async def doubleSclkToEt(
body = ErrorModel(error=str(e)) body = ErrorModel(error=str(e))
return ResponseModel(statusCode=500, body=body) return ResponseModel(statusCode=500, body=body)
@app.get("/doubleEtToSclk")
async def strSclkToEt(
frameCode: int,
et: float,
mission: str):
try:
result = pyspiceql.doubleEtToSclk(frameCode, et, mission, SEARCH_KERNELS_BOOL)
body = ResultModel(result=result)
return ResponseModel(statusCode=200, body=body)
except Exception as e:
body = ErrorModel(error=str(e))
return ResponseModel(statusCode=500, body=body)
@app.get("/utcToEt") @app.get("/utcToEt")
async def utcToEt( async def utcToEt(
utc: str): utc: str):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment