API Design of ISIS Dependency Libraries - PSMRTS #5309
Replies: 5 comments 10 replies
-
I gave a talk this week at the ADASS 2023 Conference here at the University of Arizona titled Cartographic Mapping using High Resolution Shape Models. It highlights the features and capabilities of the PSMRTS system. The slides are available here. And there will be a paper available soon. Also, for those interested, we have recently published a paper about the OSIRIS-APEX mission titled OSIRIS-APEX: An OSIRIS-REx Extended Mission to Asteroid Apophis. |
Beta Was this translation helpful? Give feedback.
-
@KrisBecker So I've been looking through the code on the repo. From looking it seems you have some of the proposed PSMRTS functionality working already using the bullet shape model? That is, within the existing ISIS shape model factory and plugin paradigm. I think there is an important question here of: does this absolutely need to be a separate library with a different API? In other words, shape models already have a relatively well-defined API, is there a way to re-purpose that API and make a component that can also be installed on its own? I am not saying this is necessarily the best route but maybe something worth considering as it could potentially require less work. To get at some of the questions proposed, I'm going to leave the more in the-weeds questions without obvious answers for later. How should strings be handled?AFAIK, sticking with C++ strings is the way to go. SWIG handles string conversions pretty well when wrapping C++ in other languages. I understand the number of string conversions being a performance concern, but I don't know a convenient way to solve this problem, personally. For clarity, all the Qt dependencies will be removed in favor of C++ standards to minimize dependencies and target standardized constructs. What other standards/approaches should be used?I'm generally in favor of sticking with std C++ whenever possible. It's not the most performant but makes things simpler to manage. The newer C++ standards cover a lot of what boost and QT used to do for us before, and what hasn't been implemented yet may have third party implementations that are designed to be replaced with the standard implementation (e.g. https://github.com/gulrak/filesystem). What is the best way to specify the list of (prioritized) shape models and which ray tracing engine is preferred by the (ISIS, specifically, but not exclusive) user?Configuration has always been a pain, with our newer libraries we have tried a priority list like: parameter, env var, user config file, default config. Where the setting passed in one is prioritized over the next. I think this is more or less a duplicate of question 10 other than ISIS might have to forward these preferences. What type/level of debugging and threading control do users want/need?I think this is really a question for users (obviously), but in our newer libraries we have moved to having obnoxiously dense logging with fine controls over what level the user wants. I would suggest this route. How does an ISIS user specify which ray trace engine to use?I think the implementation as I you describe and I see it in the code, using the kernels group, is reasonable. I imagine, at least within the ISIS environment, the best user-facing way to switch shape models outside of spiceinit would have to use a separate app (shapeinit?) How should multiple shape model files be provided in spiceinit?I would avoid extra configs if possible. I don't see why it couldn't be passed in? Maybe a system to pick the optimum shape models similar to kernels. If the models are shipped with ISISDATA, having portable paths should be possible. The IsisPreferences file can also be used to further parameterize... How else can we accomplish this?I think within ISIS, re-using the ISIS preferences file is a good idea. We should be able to overwrite with passed parameters, etc, similar to how I mention in the other question about params. |
Beta Was this translation helpful? Give feedback.
-
I have a number of questions that relate to the governance, lifecycle, and funding of this library. As this discussion is on the ISIS repository, I assume that a primary consumer of the proposed library is intended to be ISIS. As we are all well aware, ISIS is an infrastructural piece of software for the community and any dependencies to ISIS need to be equally well supported. To get the discussion started, here are some high-level questions:
|
Beta Was this translation helpful? Give feedback.
-
To wrap up the rest of the questions for completion.
I am more biased towards:
Would it be possible to enable spawning single threaded tasks that spread large jobs over multiple processes instead?
I imagine the minimum would be everything that ISIS supports now, except for what is exclusive to ISIS like cube-based 2.5D models.
The best I can imagine accelerating an "extremely large" number of ray-tracing operations is to consider GPU acceleration (I think this is supported experimentally by bullet?). But, from previous experience, a "lazier" approach of enabling multi-processing, following some commonsense practices to prevent redundant operations (idk enough about the intricacies of bullet to know exactly what this would require, maybe you can give some more insight here), and throwing it on a cluster seems to work better and is less of a headache to implement. |
Beta Was this translation helpful? Give feedback.
-
The UA ISIS (including the PSMRTS library) archival effort is funded by an overguide within the OSIRIS-APEX proposal at 1.0 FTE through ~FY25. That overguide funds only the archival effort itself (preparation of the code for submission, iteration with USGS during submission, and documentation of the code). All anticipated releases and reviews of the library will occur during this period. However, OSIRIS-APEX will naturally continue to use ISIS and the PSMRTS library during cruise to prepare for asteroid operations and throughout the Apophis encounter. The University of Arizona will continue to fund an employee at >=0.5 FTE to support operations and data product processing. That FTE will support the PSMRTS library, including bug fixes and feature expansions if necessary, for APEX mission goals. If/when the community identifies bugs or other required changes to the library during this period, it will be in APEX's best interest to address those issues, particularly during cruise. Once operations begins, critical bugs will be addressed to achieve missions requirements, but other support will be of lower priority. |
Beta Was this translation helpful? Give feedback.
-
Introduction
The University of Arizona (UA) has been funded to deliver ISIS software developed during the OSIRIS-REx encounter at asteroid 101955 Bennu to the USGS ISIS repository for distribution to the science community. This effort has been funded as part of the OREX extended mission now called OSIRIS-APophis EXplorer (APEX), which will orbit the asteroid 99942 Apophis shortly after a close Earth flyby in 2029.
We intend to provide much of this work in the form of a shared library, called the
Planetary Shape Model and Ray Tracing System
, (PSMRTS), that will serve as an external ISIS build and runtime dependency. Our goal is to design the library such that it has utility and value outside of ISIS as a standalone package that can be used by the scientific community to aid in other research and development activities. This includes the USGS CSM environment among others. As such, we would like to solicit feedback and recommendations on best practices for design and implementation strategies that will help guide the development of this library.Section 1 will describe the features provided by
PSMRTS
. Section 2 describes the library API design detail and provides examples of potential architectures. Section 3 lists a number of questions and discussion items where we request feedback from USGS and the community at large.1. Enhanced Support for Small Body Cartography in the ISIS System
The features and capabilities in this library were essential modifications and additions to the ISIS system that were required to meet the cartographic and mapping objectives of OSIRIS-REx. While there were some basic capabilities in ISIS for support of small, irregular body cartography, further evaluation and testing identified additional requirements. New features were added to the ISIS 3.6 version and maintained and tested by OREX during three years of proximity operations at Bennu. These features and capabilities were also used in additional projects that involved mapping of 433 Eros (NEAR), 67P Churyumov-Gerasimenko (Rosetta), 19P Borrelly (Deep Space 1), 81P Wild 2 (Stardust), 9P Tempel 1 (Stardust-NExT, Deep Impact) and 103P Hartley 2 (EPOXI (Deep Impact)). The following is a summary of these features and capabilities enabled by this contribution:
These additions enabled the following capabilities and improvements in ISIS processing and mapping techniques.
1.i Implications for ISIS System
Upon completion and inclusion in the current ISIS version, this library will be used in an implementation of a new shape model class derived from the base class ShapeModel. This new shape model will fully replace and incorporate the functionality of the NaifDskShape, BulletShapeModel and EmbreeShapeModel classes into a single ShapeModel class implementation. This will significantly reduce external build/runtime dependencies, code volume, and reduce maintenance costs of enhanced cartographic and geometric support for small irregularly shaped celestial bodies in the ISIS system.
In general, there will be several categories of contributions that the APEX team will deliver to the USGS/ISIS repository:
Item 1 will consist of normal Issues/PR cycles as they are completed and prepared for inclusion into the ISIS system. In addition to software documentation, item 3 will provide tutorials focused on the UA/ISIS enhancements that were used to process image data of Bennu from the OREX OCAMS and NAVCAM instruments. Item 2 is the main topic of this document. This is a standalone shared library that incorporates all of ISIS' current small, irregular body shape model cartography features and capabilities. This includes support for the NAIF digital shape kernels (DSK), Bullet Physics SDK, Intel Embree ray tracing libraries. These libraries are specifically designed for specialized ray tracing of high resolution object (or shape) models that are essentially tessellated plate models.
Tessellated plate models consist of a set of floating point 3D vectors that represent surface points from the object body origin and a set of 3D integer indexes that refer to these vectors in the order in which they are stored (in memory). This configuration formulates interconnected triangles (commonly referred to as facets) which describe the topography of an object's surface. These models can be stored in files in a variety of forms including NAIF DSK, Wavefront's OBJ, PLY and various other 3D shape model formats. This system will not support ISIS 2.5D digital elevation models (DEM) directly and will not have an ISIS dependency. However, ISIS DEM ShapeModel classes exist to support these shape models.
2. The Planetary Shape Model and Ray Tracing System Library
The new
PSMRTS
library will provide a C-based application programming interface (API) that is also application binary interface (ABI) compatible. Through abstraction and foreign function interfaces (FFI), this shared library will provide the high precision cartographic capabilities in the UA/ISIS system that were developed for the OREX encounter at Bennu. UA/ISIS mainly used the Bullet ray tracing system for cartographic processing of OCAMS images. However the NAIF and Embree systems were also useful for a variety of activities during the mission. Hence, support for these systems will also be included in thePSMRTS
library.PSMRTS
will focus primarily on support for small irregularly shaped celestial bodies.PSMRTS
will be provided as an external dependency similar to ALE, SpiceQL and other third party libraries ISIS uses for build and runtime requirements. Internally in ISIS, we will provide a ShapeModel class that encapsulates thePSMRTS
usage which will minimize the scope of required changes and ease maintenance. As per the build and installation requirements for ISIS, thePSMRTS
shared library will be available on Anaconda as a conda-forge install package.2.i PSMRTS Objectives and Design Specifications
The objective of this document regarding
PSMRTS
is to solicit feedback on design and implementation strategies that will help guide the development of this library. The goal is to provide a versatile and feature rich system that can maximize utility in many computing environments.PSMRTS
will be a pure C++ system that provides a C-based API/ABI. Our main focus will be to determine and implement the best FFI design that offers the most utility, versatility and ease of adaptability of C-like wrappers in programming languages such as Python, Java, TypeScript, Rust, and others. We do not intend to provide or maintain any other wrappers other than the C API wrapper and will therefore rely on other contributors to provide these interfaces. We aspire to make development and maintenance of these FFIs as easy and simple as possible.2.ii PSMRTS Features and Capabilities
The
PSMRTS
system is intended to replace the ISIS small body cartography features and capabilities that currently exist in the system. During the OREX encounter at Bennu, the UA/IPWG significantly modified and enhanced support in an early version of the ISIS system. New capabilities were added in ISIS version 3.5.2 but for various reasons, were not at that time ported into any subsequent ISIS release.Below are some of the capabilities and features of UA/ISIS that will be included in PSMRTS. The FFI will require APIs/ABIs that expose and/or make use of these utilities.
2.iii Examples of Existing Popular APIs
We have examples of various varieties of existing APIs in popular and widely used software systems. Many of these systems contain elements of FFI component design, and do not strictly adhere to or utilize a single feature of many possible FFI options. Most common FFI design/implementations use handles or opaque pointers. Each type has strengths and weaknesses, but we would like to hear from those who have experience with FFIs and help us make informed decisions that maximize usefulness and scope of
PSMRTS
.Below are some examples of software systems that demonstrate uses of different forms and combinations of FFIs. We provide these as an example of existing libraries/APIs some that are incorporated into the ISIS ecosystem. These examples are intended to start the conversation as to how the PSMRTS API should be designed in a way that is most accessible and useful to ISIS and other ecosystems. It doesn’t have to be exact, the point is to communicate that we are giving these not as direct design guides or even because they matter individually, but because they are examples of how people currently do it and we want to hear if people like how they do it, or if they’d prefer something else.
2.iii.a NAIF SPICE Toolkit
The NAIF SPICE APIs uses handles to refer to certain file references and objects utilized in a global parameter, variable and object pool. There are several language wrapper implementations provided with this toolkit. The Python spiceypy wrapper is a widely used, independent wrapper of the NAIF C API toolkit.
The fundamental mechanism of the NAIF SPICE toolkit C API uses file handles to opened DSK shape models. All operations for ray tracing use the DSK file handle in its interface. Below is a small code example that issues a ray trace of a DSK.
The function dasopr_c opens a DSK shape model and establishes a reference using a
handle
. Thehandle
is an integer value that serves as a reference to a structure internal to the NAIF SPICE toolkit library that is used in all subsequent operations related to the ray tracing using this DSK file. The ISIS class NaifDskPlateModel shows the current implementation that will be replaced by thePSMRTS
library.2.iii.b GEOS Computational Geometry
The GEOS computational geometry C-API/ABI uses structs and objects allocated on the heap and referenced using opaque pointers to these objects. This FFI is used to create the Python library shapely wrap the GEOS library.
The following small code example demonstrates use of the GEOS C-API that is based upon
opaque
pointers. This C-API is used in the ISIS system by the GisTopology and GisGeometry classes. Use of these classes is demonstrated in the GisIntersectStrategy class.This approach is being considered for maintaining results of ray traces where the returned constructs contain details such as the observer, look direction, status and surface intersections and normals from spacecraft instruments and light sources. Further computations can be made with these interfaces such as photometric data (e.g., emission, incidence and phase) as well as topographic occlusions.
2.iii.c TensorFlow Machine Learning Models
The TensorFlow machine learning system is developed mainly in C++. It is an open source platform for machine learning that provides stable Python and C++ APIs. The C API is designed toward simplicity and uniformity instead of convenience.
2.iii.d FFI Concepts
There are many other types of FFIs that can be used to produce C-APIs that are also application binary compatible (ABI). Design guidelines offer some ideas for FFI interfaces using mixed language programming techniques. We also intend to support the Windows platform. String handling is a fundamental need for most implementations and present challenges in mixed language environments.
2.iv PSMRTS Example
The following short code segment is an example of what the
PSMRTS
C-API might look like. The observer is assumed to be provided in body fixed coordinates for a framing camera via thespacecraft_body_fixed_position()
method. The look direction is provided in thebody_fixed_look_direction_vector()
method in theCameraModel
object.The figure below demonstrates the capabilities of the
PSMRTS
system.Figure 1. Eight 5cm tile were used in orthorectified projection of the OCAMS image.
2.iv.a Details/Description of Figure 1.
Image A, 20190404T175836S168_pol_iofL2pan, was acquired of Bennu on January 4, 2019 at a distance of ~5km. It is radiometrically calibrated I/F with an average of ~7cm/pixel. Prior to projecting the image, it was controlled to ground using the shape model.
Image B is an orthorectified projected version of Image A into a equirectangular map using a 80cm global DTM. It has the outline of eight 5cm tessellated/faceted tiles superimposed over the map to provide context for Images C & D. The eight 5cm tiles, minimally and collectively, provide coverage of Image A ground FOV with nearly 35 million facets that are managed in the UA/ISIS Bullet Ray Tracing system for all geometric operations. In comparison, the 80cm global DTM has ~3.36 million facets for all of Bennu’s surface.
Image C is the same projection as Image B, but uses a list of 8 separate 5cm tiles without ray tracing prioritization. In this projection mode, all 8 5cm tiles are checked for surface intersection at each pixel. The tile containing the closest surface intercept is chosen and the body-fixed X, Y, Z coordinate of the DTM is converted to a corresponding latitude/longitude coordinate.
Image D is using the same list of 8 5cm tiles as Image C, but the ray trace from observer to surface is systematically applied to each 5cm tile, in the order provided in the DTM list, until a valid surface intercept is found. When the first valid surface intercept occurs, the other DTMs are not ray traced.
In Image C, you will notice significant anomalies that occurred during orthorectified mapping via ray tracing only in areas of common tile coverage. This indicates very slight (millimeter to centimeter) differences in common overlapping areas of the tiles. These differences are likely due to Poisson reconstruction being applied independently to each tile, resulting in minute differences in common areas, particularly on the edges of boulders and in large areas of differences in topography of the terrain. Image D does not show this same effect because of ray tracing prioritization of the DTM tile list and early termination upon the first surface intercept. It should also be noted that unprioritized processing takes significantly more time. The number of tiles that can be used for any single image is limited to the amount of memory available on the computer system.
3. Objectives of this Discussion
Below are questions and topics of which we are requesting feedback and discussion from the ISIS and scientific community. This identifies the type of information we seek to aid and support the development, utility and adoption of this library.
And some issues specific to ISIS:
Beta Was this translation helpful? Give feedback.
All reactions