Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python API from OpenAPI endpoints #178

Closed
banesullivan opened this issue Oct 9, 2020 · 3 comments · Fixed by #332
Closed

Python API from OpenAPI endpoints #178

banesullivan opened this issue Oct 9, 2020 · 3 comments · Fixed by #332
Assignees

Comments

@banesullivan
Copy link
Contributor

banesullivan commented Oct 9, 2020

We need to (automatically?) generate a Python API from the OpenAPI endpoints. Or at least provide a way to access those endpoints from a Python client.

One viable option is: https://github.com/OpenAPITools/openapi-generator

Another approach would be to manually create the API... I'm actually leaning towards this to make sure we can design the API in a way that is user friendly and have clear documentation

First, we need a few clear use cases, likely coming from ndsampler

@banesullivan banesullivan self-assigned this Oct 9, 2020
@banesullivan
Copy link
Contributor Author

Another route is: https://github.com/swagger-api/swagger-codegen

@banesullivan
Copy link
Contributor Author

banesullivan commented Mar 10, 2021

We need to be able to perform the following tasks from the Python client:

cc @aashish24 @AlmightyYakob

@banesullivan
Copy link
Contributor Author

banesullivan commented Mar 23, 2021

Use case workflow

  1. Login into RGD via the Python client
  2. Perform a search that returns a list of results
  3. Grab 1 RasterEntry from list of results
  4. Load raster with rasterio and show/plot with matplotlib
  5. Use GeoJSON/BBox to subsample raster (hits the POST endpoint)
  6. Wait until subsampling is completed
  7. Fetch subsampled raster and view next to original raster

Psuedocode

See demos/GeoData-API.ipynb for inspiration.

import rasterio
from rasterio.plot import show
import matplotlib.pyplot as plt

# Define ROI
points = np.array([[-107.08212524738178, 39.01040379702808], 
                   [-106.96182164246767, 39.03110215679572], 
                   [-106.90895466037738, 38.98387516880551], 
                   [-106.9805540376965, 38.91038429753703], 
                   [-107.07130208569401, 38.952157178475225], 
                   [-107.08212524738178, 39.01040379702808]])

shape = {"type": "Polygon", 
         "coordinates": [points.tolist(), ]}

...

q = GeoData.search(geojson=shape, **params)
raster = q[0]  # choose raster from search results

f = GeoData.fetch_raster_file(raster)

src = rasterio.open(f)
show(src) # plots raster

sub = GeoData.subsample_raster(raster, geojson=shape)
src_sub = rasterio.open(sub)

# Show two in same plot
show(src, cmap='Greys')
show(src_sub)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants