Skip to content

Universalize common params in API calls - #168

Merged
Kelvinrr merged 3 commits into
DOI-USGS:mainfrom
chkim-usgs:options
Nov 3, 2026
Merged

Kelvinrr merged 3 commits into
DOI-USGS:mainfrom
chkim-usgs:options

Conversation

@chkim-usgs

@chkim-usgs chkim-usgs commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Overloads api.cpp functions with a version that accepts QueryOpts struct instead of individual params. This struct consolidates the following options in the QueryOpts struct:

bool useWeb=false,
bool searchKernels=true,
bool fullKernelPath=false,
int limitCk=-1, 
int limitSpk=1,
std::vector<std::string> kernelList={}

pyspiceql example:

>>> import pyspiceql as pql

>>> opts = pql.QueryOpts()  # all defaults
>>> opts.toJson()
{'useWeb': False, 'searchKernels': True, 'fullKernelPath': False, 'limitCk': -1, 'limitSpk': 1, 'kernelList': []}

>>> opts = QueryOpts({"useWeb": True, "limitCk": 2})  # missing keys keep defaults
>>> opts.limitCk
2

>>> opts.searchKernels = False  # set fields directly
>>> opts.kernelList = ["/path/to/extra.tf"]
>>> list(opts.kernelList)
['/path/to/extra.tf']

>>> pql.translateNameToCode("MRO", "ctx")
(-74, {'fk': ['mro/kernels/fk/mro_v17.tf'], 'iak': ['mro/kernels/iak/mroctxAddendum005.ti'], 'ik': ['mro/kernels/ik/mro_ctx_v11.ti']})

>>> pql.translateNameToCode("MRO", "ctx", options={"fullKernelPath": True})
(-74, {'fk': ['/Volumes/t7-shield/isis_data/mro/kernels/fk/mro_v17.tf'], 'iak': ['/Volumes/t7-shield/isis_data/mro/kernels/iak/mroctxAddendum005.ti'], 'ik': ['/Volumes/t7-shield/isis_data/mro/kernels/ik/mro_ctx_v11.ti']})

This change was to allow future common params to be more easily added.

Some things to note:

  • options must be passed by keyword (options=...) instead of passing it positionally because Python only sees the original function
  • If both an individual optional param and the options features are used, this raises an error

Licensing

This project is mostly composed of free and unencumbered software released into the public domain, and we are unlikely to accept contributions that are not also released into the public domain. Somewhere near the top of each file should have these words:

This work is free and unencumbered software released into the public domain. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain.

  • I dedicate any and all copyright interest in this software to the public domain. I make this dedication for the benefit of the public at large and to the detriment of my heirs and successors. I intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

@Kelvinrr Kelvinrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the Python case, we should also support a more pythonic approach of passing in an arg dict that matches how the opts work. Should be something at the Python side only. If it complicates things too much let's not and keep the current API you made.

Comment thread SpiceQL/include/SpiceQL/api.h Outdated
* defaults and unrecognized keys are ignored, so a new field only needs to
* be added here and to the NLOHMANN_DEFINE_TYPE call below.
*/
struct SpiceQLOptions {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just stylistic feedback, but can we call it something like QueryOpts? Just to keep it shorter. The namespace can take care of the SpiceQL part e.g. SpiceQL::QueryOpts

@Kelvinrr
Kelvinrr merged commit a10458b into DOI-USGS:main Nov 3, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants