Skip to content

Commit

Permalink
Hardcode element84 STAC server
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandenburgh committed Sep 4, 2024
1 parent ba378d8 commit 9270a85
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 36 deletions.
13 changes: 1 addition & 12 deletions rdwatch/core/utils/satellite_bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from datetime import datetime, timedelta
from typing import cast

from django.conf import settings

from rdwatch.core.models.lookups import CommonBand, ProcessingLevel
from rdwatch.core.utils.stac_search import stac_search

Expand All @@ -24,16 +22,7 @@ class Band:
collection: str


COLLECTIONS: list[str] = []

if settings.STAC_URL:
COLLECTIONS = ['sentinel-2-c1-l2a', 'sentinel-2-l2a', 'landsat-c2-l2']
elif settings.settings.ACCENTURE_VERSION is not None:
COLLECTIONS = [
f'ta1-s2-acc-{settings.ACCENTURE_VERSION}',
f'ta1-ls-acc-{settings.ACCENTURE_VERSION}',
f'ta1-pd-acc-{settings.ACCENTURE_VERSION}',
]
COLLECTIONS: list[str] = ['sentinel-2-c1-l2a', 'sentinel-2-l2a', 'landsat-c2-l2']


def get_bands(
Expand Down
26 changes: 5 additions & 21 deletions rdwatch/core/utils/stac_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from pystac_client import Client

from django.conf import settings

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -52,22 +50,11 @@ def _fmt_time(time: datetime):

COLLECTIONS: dict[str, list[str]] = {
'L8': [],
'S2': [],
'S2': ['sentinel-2-c1-l2a', 'sentinel-2-l2a'],
'PL': [],
}

STAC_URL = ''
STAC_HEADERS = {}
if settings.STAC_URL:
COLLECTIONS['S2'] += ['sentinel-2-c1-l2a', 'sentinel-2-l2a']
COLLECTIONS['L8'].append('landsat-c2-l2')
STAC_URL = settings.STAC_URL
elif settings.settings.ACCENTURE_VERSION is not None:
COLLECTIONS['S2'].append(f'ta1-s2-acc-{settings.ACCENTURE_VERSION}')
COLLECTIONS['L8'].append(f'ta1-ls-acc-{settings.ACCENTURE_VERSION}')
COLLECTIONS['PL'].append(f'ta1-pd-acc-{settings.ACCENTURE_VERSION}')
STAC_URL = settings.SMART_STAC_URL
STAC_HEADERS = {'x-api-key': settings.SMART_STAC_KEY}
STAC_URL = 'https://earth-search.aws.element84.com/v1/'


def stac_search(
Expand All @@ -76,26 +63,23 @@ def stac_search(
bbox: tuple[float, float, float, float],
timebuffer: timedelta | None = None,
) -> Results:
stac_catalog = Client.open(STAC_URL, headers=STAC_HEADERS)
stac_catalog = Client.open(STAC_URL)

if timebuffer is not None:
min_time = timestamp - timebuffer
max_time = timestamp + timebuffer
time_str = f'{_fmt_time(min_time)}/{_fmt_time(max_time)}'
else:
time_str = f'{_fmt_time(timestamp)}Z'
if source not in COLLECTIONS:
logger.warning(
'Source {source} not in Collections: {COLLECTIONS} returning empty list'
)
return {'features': [], 'links': []}

results = stac_catalog.search(
method='GET',
bbox=bbox,
datetime=time_str,
collections=COLLECTIONS[source],
limit=100,
)

# TODO: return `results` directly instead of converting to a dict.
# Before that can happen, the callers need to be updated to handle
# an `ItemSearch` object.
Expand Down
1 change: 0 additions & 1 deletion rdwatch/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def DATABASES(self):
environ_required=True, environ_prefix=_ENVIRON_PREFIX
)

STAC_URL = values.URLValue(environ_required=False, environ_prefix=_ENVIRON_PREFIX)
SMART_STAC_URL = values.URLValue(
environ_required=True, environ_prefix=_ENVIRON_PREFIX
)
Expand Down
2 changes: 0 additions & 2 deletions template.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# URL pointing to the SMART STAC server
RDWATCH_SMART_STAC_URL=

RDWATCH_STAC_URL="https://earth-search.aws.element84.com/v1/"

# API key for the SMART STAC server
RDWATCH_SMART_STAC_KEY=

Expand Down

0 comments on commit 9270a85

Please sign in to comment.