Commit 66669f63 authored by Christine Kim's avatar Christine Kim
Browse files

First wave of source code

parent 4ff9d7ad
Loading
Loading
Loading
Loading

.gitmodules

0 → 100644
+19 −0
Original line number Diff line number Diff line
[submodule "submodules/gularkfilesystem"]
	path = submodules/gularkfilesystem
	url = https://github.com/gulrak/filesystem.git
[submodule "submodules/googletest"]
	path = submodules/googletest
	url = https://github.com/google/googletest.git
[submodule "submodules/json"]
	path = submodules/json
	url = https://github.com/nlohmann/json.git
[submodule "submodules/hippomocks"]
	path = submodules/hippomocks
	url = https://github.com/dascandy/hippomocks.git
[submodule "extern/pybind11"]
	path = extern/pybind11
	url = ../../pybind/pybind11
	branch = stable
[submodule "submodules/redis-plus-plus"]
	path = submodules/redis-plus-plus
	url = https://github.com/sewenew/redis-plus-plus.git

CMakeLists.txt

0 → 100644
+212 −0
Original line number Diff line number Diff line
include(CMakeDependentOption)
cmake_minimum_required(VERSION 3.10)
project(SpiceQL VERSION 0.0.1 DESCRIPTION "Syntax Sugar for cspice")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

message(STATUS "CMake Module Path: " ${CMAKE_MODULE_PATH})

# A lot of linux OSes do not support C++20
if (APPLE)
  set(CMAKE_CXX_STANDARD 20)
else()
  set(CMAKE_CXX_STANDARD 17)
endif()

set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Set up Anaconda prefix in the case with a non-default conda env is activated
if(EXISTS $ENV{CONDA_PREFIX})
  message("CONDA PREFIX: $ENV{CONDA_PREFIX}")
  list(APPEND CMAKE_FIND_ROOT_PATH $ENV{CONDA_PREFIX}
                                   $ENV{CONDA_PREFIX}/lib/cmake/Qt5)
endif()

list(APPEND CMAKE_FIND_ROOT_PATH /var/lang/)

message(STATUS "find path: " ${CMAKE_FIND_ROOT_PATH})

# Variables required by multiple build options
set(SPICEQL_BUILD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/include/")

set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
  set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
      STRING "Choose the type of build." FORCE)
endif()

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set(CMAKE_INSTALL_PREFIX "$ENV{CONDA_PREFIX}")
endif()
message(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}")

#################
# Library Build #
#################

option (SPICEQL_BUILD_LIB "Build the SpiceQL Library" ON)

if(SPICEQL_BUILD_LIB)

  set(JSON_BuildTests OFF CACHE INTERNAL "")
  set(REDIS_PLUS_PLUS_BUILD_TEST OFF CACHE INTERNAL "")

  add_subdirectory("submodules/redis-plus-plus")
  add_subdirectory("submodules/gularkfilesystem")
  add_subdirectory("submodules/json")

  find_package(CSpice REQUIRED)
  find_package(fmt REQUIRED)
  find_package(cereal REQUIRED)
  find_package(spdlog REQUIRED)

  set(SPICEQL_INSTALL_INCLUDE_DIR "include/SpiceQL")
  set(SPICEQL_SRC_FILES   ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/spiceql.cpp 
                          ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/utils.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/io.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/query.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/spice_types.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/memoized_functions.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/src/config.cpp)

  set(SPICEQL_HEADER_FILES ${SPICEQL_BUILD_INCLUDE_DIR}/spiceql.h
                           ${SPICEQL_BUILD_INCLUDE_DIR}/utils.h
                           ${SPICEQL_BUILD_INCLUDE_DIR}/memoized_functions.h
                           ${SPICEQL_BUILD_INCLUDE_DIR}/io.h
                           ${SPICEQL_BUILD_INCLUDE_DIR}/spice_types.h
                           ${SPICEQL_BUILD_INCLUDE_DIR}/query.h
                           ${SPICEQL_BUILD_INCLUDE_DIR}/config.h)

  set(SPICEQL_PRIVATE_HEADER_FILES ${SPICEQL_BUILD_INCLUDE_DIR}/memo.h)

  set(SPICEQL_CONFIG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/apollo16.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/apollo17.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/base.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/cassini.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/clem1.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/galileo.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/juno.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/kaguya.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/lro.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/mess.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/mex.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/mgs.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/mro.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/odyssey.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/tgo.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/viking1.json
                           ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/viking2.json)

  
  set(SPICEQL_KERNELS ${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/db/kernels/naif0011.tls)

  add_library(SpiceQL SHARED ${SPICEQL_SRC_FILES})

  set_target_properties(SpiceQL PROPERTIES
                                  VERSION ${PROJECT_VERSION}
                                  SOVERSION 0)


  target_compile_definitions(SpiceQL PRIVATE SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE 
                                     PUBLIC -D_SOURCE_PREFIX="${CMAKE_CURRENT_SOURCE_DIR}")
  
  message(STATUS "redis++ inc: "  ${hiredis_INCLUDE_DIRS})
  target_include_directories(SpiceQL
                            PUBLIC
                            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/SpiceQL/include>
                            $<INSTALL_INTERFACE:include>
                            PRIVATE
                            ${CMAKE_CURRENT_SOURCE_DIR}/submodules/redis-plus-plus/src/
                            cereal
                        )

  target_link_libraries(SpiceQL
                        PUBLIC
                        ghc_filesystem
                        fmt::fmt-header-only
                        nlohmann_json::nlohmann_json
                        PRIVATE
                        redis++ 
                        CSpice::cspice
                        spdlog::spdlog_header_only
                        )

  install(TARGETS SpiceQL LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
  install(DIRECTORY ${SPICEQL_INCLUDE_DIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

  # Generate the package config
  configure_file(cmake/config.cmake.in
                ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
                @ONLY)

  # Install the package config
  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
                DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})

  # Install the headers
  install(FILES ${SPICEQL_HEADER_FILES} DESTINATION ${SPICEQL_INSTALL_INCLUDE_DIR})

  # Install the json db files
  install(FILES ${SPICEQL_CONFIG_FILES} DESTINATION "etc/SpiceQL/db")

  # Install the shipped kernels
  install(FILES ${SPICEQL_KERNELS} DESTINATION "etc/SpiceQL/db/kernels")


  # Install the library
  install(TARGETS SpiceQL nlohmann_json
          EXPORT spiceQLTargets
          LIBRARY  DESTINATION ${CMAKE_INSTALL_LIBDIR}
          INCLUDES DESTINATION ${SPICEQL_INSTALL_INCLUDE_DIR})

  # Install the target
  install(EXPORT spiceQLTargets
          NAMESPACE spice::
          DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})

else()
  message(STATUS "Skipping Library")
endif()

###############
# Tests Build #
###############

cmake_dependent_option (SPICEQL_BUILD_TESTS "Build the SpiceQL Tests" ON SPICEQL_BUILD_LIB OFF)

if(SPICEQL_BUILD_TESTS)
  include(GoogleTest)
  include(cmake/gtest.cmake)
  include(CTest)

  find_package (Threads)
  enable_testing()
  add_subdirectory(SpiceQL/tests)
else()
  message(STATUS "Skipping Tests")
endif()

##################
# Bindings Build #
##################

cmake_dependent_option (SPICEQL_BUILD_BINDINGS "Build the SpiceQL Bindings in Other Languages" ON SPICEQL_BUILD_LIB OFF)

if(SPICEQL_BUILD_BINDINGS)
  add_subdirectory(bindings)
else()
  message(STATUS "Skipping Bindings")
endif()

##############
# Docs Build #
##############

option (SPICEQL_BUILD_DOCS "Build the SpiceQL Docs" ON)

if(SPICEQL_BUILD_DOCS)
  add_subdirectory ("docs")
else()
  message(STATUS "Skipping Docs")
endif()

DISCLAIMER.md

0 → 100644
+8 −0
Original line number Diff line number Diff line
This software is preliminary or provisional and is subject to revision. It is
being provided to meet the need for timely best science. The software has not
received final approval by the U.S. Geological Survey (USGS). No warranty,
expressed or implied, is made by the USGS or the U.S. Government as to the
functionality of the software and related material nor shall the fact of release
constitute any such warranty. The software is provided on the condition that
neither the USGS nor the U.S. Government shall be held liable for any damages
resulting from the authorized or unauthorized use of the software.
 No newline at end of file

LICENSE

0 → 100644
+44 −0
Original line number Diff line number Diff line
Unless otherwise noted, this project is in the public domain in the
United States.

It contains materials that originally came from the United States
Geological Survey, an agency of the United States Department of
Interior.  For more information on their copyright policies, see
https://www.usgs.gov/information-policies-and-instructions/copyrights-and-credits

It also contains materials from contributors that have waived their
copyright interest to the public domain.

Additionally, the authors waive copyright and related rights in the
work worldwide through the CC0 1.0 Universal public domain dedication.

CC0 1.0 Universal Summary
-------------------------

This is a human-readable summary of the [Legal Code (read the full
text)](https://creativecommons.org/publicdomain/zero/1.0/legalcode).


### No Copyright

The authors have associated their contributions to the ALE project
with this deed, and have dedicated the work to the public domain
by waiving all of their rights to the work worldwide under copyright
law, including all related and neighboring rights, to the extent
allowed by law.

You can copy, modify, distribute and perform the work, even for
commercial purposes, all without asking permission.


### Other Information

In no way are the patent or trademark rights of any person affected
by CC0, nor are the rights that other persons may have in the work
or in how the work is used, such as publicity or privacy rights.

Unless expressly stated otherwise, the authors who have associated
the ISIS project with this deed make no warranties about the work,
and disclaim liability for all uses of the work, to the fullest
extent permitted by applicable law. When using or citing the work,
you should not imply endorsement by the authors.
 No newline at end of file

README.md

0 → 100644
+97 −0
Original line number Diff line number Diff line
# SpiceQL
[![Documentation Status](https://readthedocs.org/projects/sugar-spice/badge/?version=latest)](http://sugar-spice.readthedocs.io/?badge=latest) [![CMake](https://github.com/DOI-USGS/SpiceQL/actions/workflows/ctests.yml/badge.svg)](https://github.com/DOI-USGS/SpiceQL/actions/workflows/ctests.yml)

This Library provides a C++ interface querying, reading and writing Naif SPICE kernels. Built on the [Naif Toolkit](https://naif.jpl.nasa.gov/naif/toolkit.html).


## Building The Library

The library leverages anaconda to maintain all of it's dependencies. So in order to build SpiceQL, you'll need to have Anaconda installed.

> **NOTE**:If you already have Anaconda installed, skip to step 3.

1. Download either the Anaconda or Miniconda installation script for your OS platform. Anaconda is a much larger distribtion of packages supporting scientific python, while Miniconda is a minimal installation and not as large: Anaconda installer, Miniconda installer
1. If you are running on some variant of Linux, open a terminal window in the directory where you downloaded the script, and run the following commands. In this example, we chose to do a full install of Anaconda, and our OS is Linux-based. Your file name may be different depending on your environment.
   * If you are running Mac OS X, a pkg file (which looks similar to Anaconda3-5.3.0-MacOSX-x86_64.pkg) will be downloaded. Double-click on the file to start the installation process.
1. Open a Command line prompt and run the following commands:

```bash
# Clone the Github repo, note the recursive flag, this library depends on
# submodules that also need to be cloned. --recurse-submodules enables this and
# the -j8 flag parallelizes the cloning process.
git clone --recurse-submodules -j8 https://github.com/DOI-USGS/SpiceQL.git

# cd into repo dir
cd SpiceQL

# Create new environment from the provided dependency file, the -n flag is
# proceded by the name of the new environment, change this to whatever works for you
conda env create -f environment.yml -n ssdev

# activate the new env
conda activate ssdev

# make and cd into the build directory. This can be placed anywhere, but here, we make
# it in the repo (build is in .gitingore, so no issues there)
mkdir build
cd build

# Configure the project, install directory can be anything, here, it's the conda env
cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX

# Optional: DB files are installed by default in $CONDA_PREFIX/etc/SpiceQL/db to 
# use files that are included within the repo, you must create and define 
# an environment variable named SSPICE_DEBUG. 
# note SSPICE_DEBUG can be set to anything as long as it is defined
export SSPICE_DEBUG=True

# Set the environment variable(s) to point to your kernel install 
# The following environment variables are used by default in order of priority: 
# $SPICEROOT, $ALESPICEROOT, $ISISDATA. 
# SPICEROOT is unique to this lib, while ALESPICEROOT, and ISISDATA are used 
# by both ALE and ISIS respectively. 
# note you can set each of these environment variables path to point to the
# correspoding kernels downloaded location, ie 
SPICEROOT=~/spiceQL/Kernals/spiceRootKernel
ALESPICEROOT=~/spiceQL/Kernals/aleSpiceRootKernel
ISISDATA=~/spiceQL/Kernals/isisData

# build and install project
make install

# Optional, Run tests
ctest -j8
```

You can disable different components of the build by setting the CMAKE variables `SPICEQL_BUILD_DOCS`, `SPICEQL_BUILD_TESTS`, `SPICEQL_BUILD_BINDINGS`, or `SPICEQL_BUILD_LIB` to `OFF`. For example, the following cmake configuration command will not build the documentation or the tests:

```
cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DSPICEQL_BUILD_DOCS=OFF -DSPICEQL_BUILD_TESTS=OFF
```

## Bindings

The SpiceQL API is available via Python bindings in the module `pyspiceql`. The bindings are built using SWIG and are on by default. You can disable the bindings in your build by setting `SPICEQL_BUILD_BINDINGS` to `OFF` when configuring your build.

## Memoization Header Library 

SpiceQL has a simple memoization header only library at `Spiceql/include/memo.h`. This can cache function results on disk using a binary archive format mapped using a combined hash of a function ID and it's input parameters. 

TLDR 
```C++
#include "memo.h"

int func(int) { ... }
memoization::disk c("cache_path");

// use case 1: wrap function call
// (function ID, the function to wrap and then params
int result1 = c("func_id", func, 3);

// use case 2: wrap function
// (cache object, function ID, function)
auto func_memoed = memoization::make_memoized(c, "func_id", func);
int result2 = func_memoed(3);

assert(result1 == result2);
```
Loading