Skip to content

Commit

Permalink
Feat: initialise collection stac TDE-453 (#132)
Browse files Browse the repository at this point in the history
* feat: initialise collection object and stac

* test: collection test

* fix: appease mypy

* fix: move stac version to its own file for reuse
  • Loading branch information
MDavidson17 authored Sep 22, 2022
1 parent 396dc16 commit 8c542d5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
38 changes: 38 additions & 0 deletions scripts/initialise_stac_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import argparse
import json
import os

from linz_logger import get_log

from scripts.files.fs import write
from scripts.logging.time_helper import time_in_ms
from scripts.stac.imagery.collection import ImageryCollection


def initialise_imagery_collection(title: str, description: str) -> None:
start_time = time_in_ms()
get_log().info("finalise_stac_collection_imagery_start", title=title, description=description)

collection = ImageryCollection(title=title, description=description)

tmp_file_path = os.path.join("/tmp/", "collection.json")
write(tmp_file_path, json.dumps(collection.stac).encode("utf-8"))

get_log().info("create_stac_collection_imagery_complete", title=title, duration=time_in_ms() - start_time)


def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--title", dest="title", required=True)
parser.add_argument("--description", dest="description", required=True)

arguments = parser.parse_args()

title = arguments.title
description = arguments.description

initialise_imagery_collection(title, description)


if __name__ == "__main__":
main()
38 changes: 38 additions & 0 deletions scripts/stac/imagery/collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from typing import Any, Dict, List, Optional

import ulid

from scripts.stac.util.STAC_VERSION import STAC_VERSION

PYSTAC_VERSION = "1.0.0"


class ImageryCollection:
stac: Dict[str, Any]

def __init__(self, title: Optional[str] = None, description: Optional[str] = None) -> None:
self.stac = {
"type": "Collection",
"stac_version": STAC_VERSION,
"id": str(ulid.ULID()),
"title": title,
"description": description,
"license": "CC-BY-4.0",
"links": [{"rel": "self", "href": "./collection.json", "type": "application/json"}],
}

def add_link(self, href: str, rel: str = "item", file_type: str = "application/json") -> None:
# Will be implemented in Future PR
pass

def update_spatial_extent(self, item_bbox: List[float]) -> None:
# Will be implemented in Future PR
pass

def update_temporal_extent(self, item_start_datetime: str, item_end_datetime: str) -> None:
# Will be implemented in Future PR
pass

def update_extent(self, bbox: Optional[List[float]] = None, interval: Optional[List[str]] = None) -> None:
# Will be implemented in Future PR
pass
10 changes: 10 additions & 0 deletions scripts/stac/tests/collection_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from scripts.stac.imagery.collection import ImageryCollection


def test_imagery_stac_collection_initialise() -> None:
title = "Test Urban Imagery"
description = "Test Urban Imagery Description"
collection = ImageryCollection(title, description)

assert collection.stac["title"] == title
assert collection.stac["description"] == description
1 change: 1 addition & 0 deletions scripts/stac/util/STAC_VERSION.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
STAC_VERSION = "1.0.0"

0 comments on commit 8c542d5

Please sign in to comment.