Skip to content

Commit

Permalink
HARMPONY-1764: Update pystac and use STAC catalog for sending
Browse files Browse the repository at this point in the history
operation
  • Loading branch information
indiejames committed May 15, 2024
1 parent 63fb8fd commit 94931bc
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lint:
flake8 harmony

test:
pytest --cov=harmony tests
pytest --cov=harmony tests -W ignore::DeprecationWarning

test-no-warnings:
pytest --disable-warnings --cov=harmony tests
Expand Down
2 changes: 1 addition & 1 deletion example/example_message.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../../harmony/app/schemas/data-operation/0.19.0/data-operation-v0.19.0.json",
"$schema": "../../harmony/services/harmony/app/schemas/data-operation/0.19.0/data-operation-v0.19.0.json",
"version": "0.19.0",
"callback": "http://localhost/some-path",
"stagingLocation": "s3://example-bucket/public/some-org/some-service/some-uuid/",
Expand Down
7 changes: 5 additions & 2 deletions example/source/catalog.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"stac_version": "1.0.0-beta.2",
"stac_extensions": [],
"stac_version": "1.0.0",
"stac_extensions": [
"https://harmony.earthdata.nasa.gov/schemas/stac-extension/0.1.0/schema.json"
],
"type": "Catalog",
"id": "d5addf73-6e95-4ba1-a2a6-528de6d3d22c",
"links": [
{
Expand Down
7 changes: 5 additions & 2 deletions example/source/catalog0.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"stac_version": "1.0.0-beta.2",
"stac_extensions": [],
"stac_version": "1.0.0",
"stac_extensions": [
"https://harmony.earthdata.nasa.gov/schemas/stac-extension/0.1.0/schema.json"
],
"type": "Catalog",
"id": "1bd3924c-c0ee-49b7-b9ac-0d295f4bf909",
"links": [
{
Expand Down
7 changes: 5 additions & 2 deletions example/source/catalog1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"stac_version": "1.0.0-beta.2",
"stac_extensions": [],
"stac_version": "1.0.0",
"stac_extensions": [
"https://harmony.earthdata.nasa.gov/schemas/stac-extension/0.1.0/schema.json"
],
"type": "Catalog",
"id": "2bd3924c-c0ee-49b7-b9ac-0d296f4af909",
"links": [
{
Expand Down
2 changes: 1 addition & 1 deletion example/source/granule_0_0000000.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"stac_version": "1.0.0-beta.2",
"stac_version": "1.0.0",
"stac_extensions": [],
"id": "3ca8ec5a-6d1e-4a82-8233-313d73769e7c",
"type": "Feature",
Expand Down
2 changes: 1 addition & 1 deletion example/source/granule_0_0000001.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"stac_version": "1.0.0-beta.2",
"stac_version": "1.0.0",
"stac_extensions": [],
"id": "56e7601d-4ff0-445b-85ee-a0174558853e",
"type": "Feature",
Expand Down
3 changes: 2 additions & 1 deletion example/source/source_0.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"stac_version": "1.0.0-beta.2",
"stac_version": "1.0.0",
"stac_extensions": [],
"type": "Catalog",
"id": "8bd3924c-c0ee-49b7-b9ac-0d296f4bf909",
"links": [
{
Expand Down
6 changes: 3 additions & 3 deletions harmony/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from .adapter import BaseHarmonyAdapter
from .cli import setup_cli, is_harmony_cli, run_cli
from .message import Temporal
from pystac.stac_io import STAC_IO
from pystac.stac_io import StacIO
from .s3_stac_io import read, write

STAC_IO.read_text_method = read
STAC_IO.write_text_method = write
StacIO.read_text_method = read
StacIO.write_text_method = write
3 changes: 3 additions & 0 deletions harmony/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def invoke(self):
# New-style processing using STAC
if self.catalog:
return (self.message, self._process_catalog_recursive(self.catalog))
else:
warn('===========NO CATALOG ==============', DeprecationWarning, stacklevel=2)

# Deprecated, processing using callbacks
self._process_with_callbacks()
Expand Down Expand Up @@ -167,6 +169,7 @@ def _process_catalog_recursive(self, catalog):
pystac.Catalog
A new catalog containing all of the processed results
"""
warn('CLONING THE CATALOG', DeprecationWarning, stacklevel=2)
result = catalog.clone()
result.id = str(uuid.uuid4())

Expand Down
5 changes: 3 additions & 2 deletions harmony/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,13 @@ def run_cli(parser, args, AdapterClass, cfg=None):
if not successful:
raise Exception('Service operation failed')
else:
try:
adapter = _build_adapter(AdapterClass,
adapter = _build_adapter(AdapterClass,
args.harmony_input,
args.harmony_sources,
args.harmony_data_location,
cfg)
try:

adapter.logger.info(f'timing.{cfg.app_name}.start')
_invoke(adapter, args.harmony_metadata_dir)
finally:
Expand Down
6 changes: 3 additions & 3 deletions harmony/s3_stac_io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from urllib.parse import urlparse
import boto3
from pystac import STAC_IO
from pystac.stac_io import DefaultStacIO
from harmony import util
from harmony import aws
from os import environ
Expand Down Expand Up @@ -35,7 +35,7 @@ def read(uri):
obj = s3.Object(bucket, key)
return obj.get()['Body'].read().decode('utf-8')
else:
return STAC_IO.default_read_text_method(uri)
return DefaultStacIO().read_text(uri)


def write(uri, txt):
Expand All @@ -51,4 +51,4 @@ def write(uri, txt):
if parsed.scheme == 's3':
aws.write_s3(uri, txt)
else:
STAC_IO.default_write_text_method(uri, txt)
DefaultStacIO().write_text_to_href(uri, txt)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
boto3 ~= 1.14
deprecation ~= 2.1.0
pynacl ~= 1.4
pystac ~= 0.5.3
pystac ~= 1.10.0
python-json-logger ~= 2.0.1
requests ~= 2.24
urllib3 ~= 1.26.9
8 changes: 5 additions & 3 deletions tests/test_adapter_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_get_all_items_handles_children(self, test_patch):
adapter = AdapterTester(message, catalog, config=self.config)
all_items = list(adapter.get_all_catalog_items(catalog, True))
self.assertEqual(all_items, [ *items_a, *items_b ])


def test_unaltered_ids_are_assigned_new_uuids(self):
catalog = Catalog('0', 'Catalog 0')
Expand Down Expand Up @@ -210,7 +210,8 @@ def test_legacy_invocations_create_stac_catalogs(self):
self.assertEqual(AdapterTester.process_args[2][1], message.sources[1])
self.assertEqual(AdapterTester.process_args[0][0].to_dict(), {
'type': 'Feature',
'stac_version': '1.0.0-beta.2',
'stac_version': '1.0.0',
'stac_extensions': [],
'id': 'G0001-EXAMPLE',
'properties': {
'start_datetime': '2001-01-01T01:01:01Z',
Expand All @@ -230,7 +231,8 @@ def test_legacy_invocations_create_stac_catalogs(self):
})
self.assertEqual(AdapterTester.process_args[1][0].to_dict(), {
'type': 'Feature',
'stac_version': '1.0.0-beta.2',
'stac_version': '1.0.0',
'stac_extensions': [],
'id': 'G0002-EXAMPLE',
'properties': {
'start_datetime': '2003-03-03T03:03:03Z',
Expand Down

0 comments on commit 94931bc

Please sign in to comment.