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 * feat: create items * fix: add dependencies * fix: minor code tidy and add test * feat: implement update collection * fix: appease pylint will be reverted in next PR * test: add more tests * fix: formatting * fix: all formatting * fix: remove additional file * fix: typo Co-authored-by: Alice Fage <[email protected]>
- Loading branch information
1 parent
47e966a
commit 9127002
Showing
5 changed files
with
162 additions
and
12 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
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
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
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
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,49 @@ | ||
import argparse | ||
import json | ||
from typing import List | ||
|
||
from linz_logger import get_log | ||
|
||
from scripts.cli.cli_helper import format_source | ||
from scripts.files.files_helper import is_json | ||
from scripts.files.fs import read, write | ||
from scripts.logging.time_helper import time_in_ms | ||
from scripts.stac.imagery.collection import ImageryCollection | ||
from scripts.stac.imagery.item import ImageryItem | ||
|
||
|
||
def update_imagery_collection(files: List[str], collection_path: str) -> None: | ||
start_time = time_in_ms() | ||
get_log().info("finalise_stac_collection_imagery_start", collection=collection_path) | ||
|
||
collection = ImageryCollection(stac=json.loads(read(collection_path))) | ||
|
||
for file in files: | ||
if not is_json(file): | ||
get_log().trace("create_stac_file_not_tiff_skipped", file=file) | ||
item = ImageryItem(stac=json.loads(read(file))) | ||
collection.add_link(href=file) | ||
collection.update_temporal_extent(item.stac["properties"]["start_datetime"], item.stac["properties"]["end_datetime"]) | ||
collection.update_spatial_extent(item.stac["bbox"]) | ||
|
||
write(collection_path, json.dumps(collection.stac).encode("utf-8")) | ||
|
||
get_log().info( | ||
"update_stac_collection_imagery_complete", collection=collection.stac, source=files, duration=time_in_ms() - start_time | ||
) | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--source", dest="source", nargs="+", required=True) | ||
parser.add_argument("--collection", dest="collection", help="path to collection.json", required=True) | ||
arguments = parser.parse_args() | ||
|
||
files = format_source(arguments.source) | ||
collection_path = arguments.collection | ||
|
||
update_imagery_collection(files, collection_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |