seignovert / python-webgeocalc

Python package for NAIF WebGeoCalc API
https://webgeocalc.readthedocs.io
MIT License
6 stars 4 forks source link

Adding API for 3rd party WGC instance #2

Closed BaptisteCecconi closed 4 years ago

BaptisteCecconi commented 4 years ago

For a local processing pipeline, we are planning to setup a local instance of WebGeoCalc at Observatoire de Paris. Although that instance would probably not be accessible from the outer internet, we would need to be able to query that API, and so there is a need for a method to set API URL.

I've checked #1 and I would suggest to pass an API object instance in the wgc keyword of Calculation(), rather of the WGC API short name as a string.

This would then give:

from webgeocalc import Calculation
from webgeocalc import WGC_ESA

Calculation(
    wgc = WGC_ESA,
    kernels = 'OPS  --     Rosetta',
    times = '2014-01-01T01:23:45.000',
    calculation_type = 'STATE_VECTOR',
    target = '67P/CHURYUMOV-GERASIMENKO (1969 R1)',
    observer = 'ROSETTA ORBITER',
    reference_frame = '67P/C-G_CK',
    aberration_correction = 'NONE',
    state_representation = 'PLANETOCENTRIC',
).run()

from webgeocalc import Api

WGC_local = Api('https://wgc.obspm.fr/webgeocalc/api')  # NB: fake API URL

Calculation(
    wgc = WGC_local,
    kernels = 'OPS  --     Rosetta',
    times = '2014-01-01T01:23:45.000',
    calculation_type = 'STATE_VECTOR',
    target = '67P/CHURYUMOV-GERASIMENKO (1969 R1)',
    observer = 'ROSETTA ORBITER',
    reference_frame = '67P/C-G_CK',
    aberration_correction = 'NONE',
    state_representation = 'PLANETOCENTRIC',
).run()
seignovert commented 4 years ago

Hi Baptiste,

I wasn't aware that WGC will be used by 3rd party but sure that's completely doable! I think the wgc can be directly use to pass the url string to the actual API endpoint if the value is neither JPL not ESA and if it is not already a Api object (I like the idea to fall back automatically on the JPL endpoint by default).

I will fix soon #1 (I found how to solve the current bug) first, then I will do a new PR for this issue.

Do you think I should also add a parser to load a global variable (like WCG_URL) to setup the default URL endpoint to query?

BaptisteCecconi commented 4 years ago

Hi Benoît,

we have an ongoing action (started with Chuck and Boris a few years ago) to setup an instance of WGC in Paris. We have several tools and pipelines that are planning to use WGC API for ephemeris calculations. We prefer to have a local instance, with up-to-date SPICE kernels, rather than sending requests to JPL or ESA (with the risk of being blacklisted when intensive requests are sent).

To answer your comments:

I think the wgc can be directly use to pass the url string to the actual API endpoint if the value is neither JPL not ESA and if it is not already a Api object (I like the idea to fall back automatically on the JPL endpoint by default).

yes, I think it would be acceptable to provide the url to the API endpoint. However, this means that an Api object would be instantiated together with each Calculation. That might be an issue if many Calculation objects are instantiated. It will increase the load on the WGC server, since a /kernel-set query is done each time, instead of once per API endpoint and session.

Do you think I should also add a parser to load a global variable (like WCG_URL) to setup the default URL endpoint to query?

Yes, that would be useful, but you would lose the "fallback to JPL endpoint" feature.