Skip to content

Commit

Permalink
Revert "Add planet mosaic endpoint, close #41"
Browse files Browse the repository at this point in the history
  • Loading branch information
olafveerman authored Aug 6, 2020
1 parent 2b51a40 commit c767774
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 120 deletions.
2 changes: 0 additions & 2 deletions covid_api/api/api_v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
groups,
tiles,
metadata,
planet,
)

api_router = APIRouter()
Expand All @@ -23,4 +22,3 @@
api_router.include_router(sites.router, tags=["sites"])
api_router.include_router(groups.router, tags=["indicator groups"])
api_router.include_router(detections.router, tags=["detections"])
api_router.include_router(planet.router, tags=["planet"])
81 changes: 0 additions & 81 deletions covid_api/api/api_v1/endpoints/planet.py

This file was deleted.

35 changes: 0 additions & 35 deletions covid_api/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@
import time
import json
import hashlib
import math
import random
from io import BytesIO


import numpy as np
from shapely.geometry import shape, box
from rasterstats.io import bounds_window
from rasterio.io import MemoryFile
import requests

from starlette.requests import Request

Expand All @@ -34,7 +28,6 @@

from covid_api.db.memcache import CacheLayer
from covid_api.models.timelapse import Feature
from covid_api.core.config import PLANET_API_KEY


def get_cache(request: Request) -> CacheLayer:
Expand Down Expand Up @@ -686,31 +679,3 @@ def get_custom_cmap(cname) -> Dict:


ColorMapName = Enum("ColorMapNames", [(a, a) for a in COLOR_MAP_NAMES]) # type: ignore


def planet_mosaic_tile(scenes, x, y, z):
"""return a mosaicked tile for a set of planet scenes"""
mosaic_tile = np.zeros((4, 256, 256), dtype=np.uint8)
for scene in scenes.split(","):
api_num = math.floor(random.random() * 3) + 1
url = f"https://tiles{api_num}.planet.com/data/v1/PSScene3Band/{scene}/{z}/{x}/{y}.png?api_key={PLANET_API_KEY}"
r = requests.get(url)
with MemoryFile(BytesIO(r.content)) as memfile:
with memfile.open() as src:
data = src.read()
# any place we don't have data yet, add some
mosaic_tile = np.where(
mosaic_tile[3] == 0, mosaic_tile + data, mosaic_tile
)

# if the tile is full, stop
if np.count_nonzero(mosaic_tile[3]) == mosaic_tile[3].size:
break

# salt the resulting image
salt = np.random.randint(0, 3, (256, 256), dtype=np.uint8)
mosaic_tile[:3] = np.where(
mosaic_tile[:3] < 254, mosaic_tile[:3] + salt, mosaic_tile[:3]
)

return mosaic_tile[:3], mosaic_tile[3]
2 changes: 0 additions & 2 deletions covid_api/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@

INDICATOR_BUCKET = os.environ.get("INDICATOR_BUCKET", "covid-eo-data")
DT_FORMAT = "%Y-%m-%d"

PLANET_API_KEY = os.getenv("PLANET_API_KEY")

0 comments on commit c767774

Please sign in to comment.