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

Feature: abstract timelapse endpoint #113

Merged
merged 10 commits into from
Jun 10, 2021

Conversation

leothomas
Copy link
Contributor

Closes #110

What I did:

I made the /timelapse endpoint work for any global, raster dataset (as opposed to just no2-mean and no2-diff).

How I did it:

I added a field for datasetId in the query parameters. The API validate that the dataset indeed a raster dataset.

I added a field for spotlightId in the query parameters in order to make the /timelapse endpoint also work with non-global datasets. This functionality is not currently supported by the frontend, since the timelapse requests are generated by drawing a bounding box on the map - which has no knowledge of which "spotlight" it might be over. A potential workaround is for the API to calculate if the bounding box supplied fits within a spotlight's tile, returning an error if it does not. For the time being, the endpoint will only support global datasets.

**Note: the field month is now date in order to support both monthly datasets and daily datasets

How you can test it:

Executing the following query:

curl 'http://localhost:8000/v1/timelapse' --data-raw '{"datasetId":"no2","date":"202004","geojson":{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[77.695,17.978],[90.351,17.978],[90.351,28.304],[77.695,28.304],[77.695,17.978]]]}}}'

returns:

{"mean":2271165821222912.0,"median":2252534253092864.0}%

Example of a spotlight-specific dataset query:

curl 'http://localhost:8000/v1/timelapse' --data-raw '{"datasetId":"nightlights-viirs","spotlightId":"la", "date":"2020_04_01","geojson":{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[
          [
            [
              -118.74847412109375,
              33.55512901742288
            ],
            [
              -117.35595703124999,
              33.55512901742288
            ],
            [
              -117.35595703124999,
              34.420504880133834
            ],
            [
              -118.74847412109375,
              34.420504880133834
            ],
            [
              -118.74847412109375,
              33.55512901742288
            ]
          ]
        ]}}}'

returns:

{"mean":20.382328097428335,"median":2.8000000000000003}%

Note the field spotlightId in the request.

Examples of handled failures:

**Invalid date format: **

curl 'http://localhost:8000/v1/timelapse' --data-raw '{"datasetId":"no2","date":"2020","geojson":{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[
          [
            [
              -118.74847412109375,
              33.55512901742288
            ],
            [
              -117.35595703124999,
              33.55512901742288
            ],
            [
              -117.35595703124999,
              34.420504880133834
            ],
            [
              -118.74847412109375,
              34.420504880133834
            ],
            [
              -118.74847412109375,
              33.55512901742288
            ]
          ]
        ]}}}'

returns:

{"detail":"Invalid date format. 2020 should be either YYYY_MM_DD or YYYYMM"}%

Other handled failures include:

  • Malformed spotlightId or datasetId's
  • Bounding box that extends past the tile boundaries (for spotlight datasets)

@leothomas leothomas merged commit 19f7d88 into develop Jun 10, 2021
@leothomas leothomas deleted the feature/abstract-timelapse-endpoint branch June 10, 2021 14:02
@leothomas leothomas restored the feature/abstract-timelapse-endpoint branch June 10, 2021 14:07
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.

Abstract timelapse endpoint to work for all datasets
1 participant