Skip to content

Commit

Permalink
refactor: resetting defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
jankovicgd committed Nov 21, 2024
1 parent 19e5e3a commit ba36b01
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/eodm/cli/_globals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from datetime import datetime

from pystac import Extent, SpatialExtent, TemporalExtent

DEFAULT_EXTENT = Extent(
spatial=SpatialExtent.from_coordinates([[-180, -90], [180, 90]]),
temporal=TemporalExtent.from_now(),
)

DEFAULT_DATETIME_INTERVAL = f"{datetime(1900, 1, 1)}/.."
DEFAULT_BBOX = "-180.0,-90.0,180.0, 90.0"
15 changes: 9 additions & 6 deletions src/eodm/cli/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def __init__(self, ll_x: float, ll_y: float, ur_x: float, ur_y: float) -> None:
self.ur_y = ur_y

def __str__(self) -> str:
return f"BBox({self.ll_x}, {self.ll_y}, {self.ur_x}, {self.ur_y})"
return f"{self.ll_x},{self.ll_y},{self.ur_x},{self.ur_y}"

def __iter__(self) -> Iterator[float]:
yield from (self.ll_x, self.ll_y, self.ur_x, self.ur_y)


def parse_bbox(value: str) -> BBox:
def bbox(value: str) -> BBox:
coords = value.split(",")
if len(coords) != 4:
raise ValueError(
Expand All @@ -40,7 +40,7 @@ def __str__(self) -> str:
return f"{self.lower.isoformat()}/{self.upper.isoformat()}"


def parse_datetime_interval(value: str) -> DatetimeInterval:
def datetime_interval(value: str) -> DatetimeInterval:
dts = value.split("/")
if not (0 < len(dts) < 3):
raise ValueError("Invalid datetime interval")
Expand All @@ -67,12 +67,15 @@ class Output(str, Enum):


BBoxType = Annotated[
BBox | None, Option(parser=parse_bbox, help="format: ll_x,ll_y,ur_x,ur_y")
BBox | str,
Option("--bbox", "-b", parser=bbox, help="WGS 84 format:minx,miny,maxx,maxy"),
]
DateTimeIntervalType = Annotated[
DatetimeInterval | None,
DatetimeInterval | str,
Option(
parser=parse_datetime_interval,
"--datetime-interval",
"-d",
parser=datetime_interval,
help="ISO format: single, start/end, start/.., ../end for open bounds",
),
]
Expand Down
29 changes: 22 additions & 7 deletions src/eodm/cli/extract/apps/stac_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from typing import cast
from typing import Annotated, cast

import typer

from eodm.cli._globals import DEFAULT_BBOX, DEFAULT_DATETIME_INTERVAL
from eodm.cli._serialization import serialize
from eodm.cli._types import BBoxType, DateTimeIntervalType, Output, OutputType
from eodm.cli._types import (
BBoxType,
DateTimeIntervalType,
Output,
OutputType,
)
from eodm.extract import extract_stac_api_collections, extract_stac_api_items

app = typer.Typer(no_args_is_help=True)
Expand All @@ -20,13 +26,22 @@ def main():
def items(
url: str,
collection: str,
bbox: BBoxType = None,
datetime_interval: DateTimeIntervalType = None,
limit: int | None = None,
bbox: BBoxType = DEFAULT_BBOX,
datetime_interval: DateTimeIntervalType = DEFAULT_DATETIME_INTERVAL,
limit: Annotated[
int,
typer.Option(
"--limit",
"-l",
parser=lambda x: x if x else None,
metavar="INT",
help="Limit query.",
),
] = 0,
output: OutputType = Output.default,
):
"""
Extract items from a STAC API collection
Extract items from a collection found in a STAC API
"""

_bbox = None
Expand All @@ -50,7 +65,7 @@ def items(
@app.command(no_args_is_help=True)
def collections(url: str, output: OutputType = Output.default):
"""
Extract collections from STAC API
Extract all collections from STAC API
"""

collections = extract_stac_api_collections(url)
Expand Down

0 comments on commit ba36b01

Please sign in to comment.