generated from linz/template-python-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
396dc16
commit 8c542d5
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
STAC_VERSION = "1.0.0" |