Skip to content

Commit

Permalink
Merge pull request #34 from kamangir/watch-targets-refactors-2024-10-…
Browse files Browse the repository at this point in the history
…07-33560

watch targets refactors
  • Loading branch information
kamangir authored Oct 8, 2024
2 parents 25104a5 + 0663d2a commit c7a969d
Show file tree
Hide file tree
Showing 17 changed files with 292 additions and 126 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ to use on [AWS SageMaker](https://aws.amazon.com/sagemaker/) replace `<plugin-na

[![pylint](https://github.com/kamangir/blue-geo/actions/workflows/pylint.yml/badge.svg)](https://github.com/kamangir/blue-geo/actions/workflows/pylint.yml) [![pytest](https://github.com/kamangir/blue-geo/actions/workflows/pytest.yml/badge.svg)](https://github.com/kamangir/blue-geo/actions/workflows/pytest.yml) [![bashtest](https://github.com/kamangir/blue-geo/actions/workflows/bashtest.yml/badge.svg)](https://github.com/kamangir/blue-geo/actions/workflows/bashtest.yml) [![PyPI version](https://img.shields.io/pypi/v/blue-geo.svg)](https://pypi.org/project/blue-geo/)

built by 🌀 [`blue_options-4.90.1`](https://github.com/kamangir/awesome-bash-cli), based on 🌐 [`blue_geo-4.637.1`](https://github.com/kamangir/blue-geo).
built by 🌀 [`blue_options-4.90.1`](https://github.com/kamangir/awesome-bash-cli), based on 🌐 [`blue_geo-4.643.1`](https://github.com/kamangir/blue-geo).
6 changes: 6 additions & 0 deletions blue_geo/.abcli/actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
function blue_geo_action_git_before_push() {
blue_geo build_README

blue_geo_watch_targets save \
target=all \
$BLUE_GEO_WATCH_TARGET_LIST
cp -v $ABCLI_OBJECT_ROOT/$BLUE_GEO_WATCH_TARGET_LIST/target/shape.geojson \
$abcli_path_git/blue-geo/blue_geo/watch/targets.geojson

[[ "$(abcli_git get_branch)" == "main" ]] &&
blue_geo pypi build
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,3 @@ function test_blue_geo_watch_targets_get_query_args() {
--delim +)" \
- empty
}

function test_blue_geo_watch_targets_list() {
local options=$1

abcli_download - $BLUE_GEO_WATCH_TARGET_LIST

abcli_assert \
$(blue_geo_watch_targets list \
--delim + \
--log 0) \
- non-empty
[[ $? -ne 0 ]] && return 1

abcli_assert \
$(blue_geo_watch_targets list \
--catalog_name SkyFox \
--collection Venus \
--delim + \
--log 0) \
- non-empty
}
22 changes: 22 additions & 0 deletions blue_geo/.abcli/tests/watch_targets_list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /usr/bin/env bash

function test_blue_geo_watch_targets_list() {
local options=$1

abcli_download - $BLUE_GEO_WATCH_TARGET_LIST

abcli_assert \
$(blue_geo_watch_targets list \
--delim + \
--log 0) \
- non-empty
[[ $? -ne 0 ]] && return 1

abcli_assert \
$(blue_geo_watch_targets list \
--catalog_name SkyFox \
--collection Venus \
--delim + \
--log 0) \
- non-empty
}
24 changes: 24 additions & 0 deletions blue_geo/.abcli/tests/watch_targets_save.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /usr/bin/env bash

function test_blue_geo_watch_targets_save() {
local options=$1

abcli_download - $BLUE_GEO_WATCH_TARGET_LIST

local target_name
for target_name in Leonardo all; do
local object_name="test_blue_geo_watch_targets_save-$target_name-$(abcli_string_timestamp)"

blue_geo_watch_targets save \
target=$target_name \
$object_name

local object_path=$ABCLI_OBJECT_ROOT/$object_name
[[ ! -f "$object_path/target/shape.geojson" ]] &&
return 1

abcli_hr
done

return 0
}
4 changes: 2 additions & 2 deletions blue_geo/.abcli/watch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ function blue_geo_watch() {
[[ $? -ne 0 ]] && return 1

blue_geo_watch_targets save \
--target_name $target \
--object_name $query_object_name
target=$target \
$query_object_name
[[ $? -ne 0 ]] && return 1
fi

Expand Down
26 changes: 25 additions & 1 deletion blue_geo/.abcli/watch/targets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,29 @@ function blue_geo_watch_targets() {
return
fi

if [[ ",get,list,save," == *","$task","* ]]; then
if [[ ",get,list," == *","$task","* ]]; then
python3 -m blue_geo.watch.targets "$@"
return
fi

if [[ "$task" == "save" ]]; then
local options=$2
local target_name=$(abcli_option "$options" target all)

local object_name=$(abcli_clarify_object $3 .)

abcli_clone \
~relate \
$BLUE_GEO_QGIS_TEMPLATE_WATCH \
$object_name

python3 -m blue_geo.watch.targets save \
--target_name $target_name \
--object_name $object_name \
"${@:4}"
return
fi

if [[ "$task" == "publish" ]]; then
abcli_publish \
as=geo-watch-targets,suffix=.yaml \
Expand All @@ -65,6 +83,12 @@ function blue_geo_watch_targets() {
fi

if [[ "$task" == "upload" ]]; then
blue_geo_watch_targets \
save \
target=all \
$BLUE_GEO_WATCH_TARGET_LIST
[[ $? -ne 0 ]] && return 1

abcli_$task - $BLUE_GEO_WATCH_TARGET_LIST
return
fi
Expand Down
2 changes: 1 addition & 1 deletion blue_geo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

DESCRIPTION = f"{ICON} AI for a Blue Planet."

VERSION = "4.637.1"
VERSION = "4.643.1"

REPO_NAME = "blue-geo"

Expand Down
13 changes: 7 additions & 6 deletions blue_geo/help/watch/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,14 @@ def help_save(
tokens: List[str],
mono: bool,
) -> str:
args = [
"[--target_name <target>]",
"[--object_name <object-name>]",
]
options = "target=all|<target-name>"
return show_usage(
["@targets save"] + args,
"save <target> -> <object-name>.",
[
"@targets save",
f"[{options}]",
"[.|<object-name>]",
],
"save target(s) -> <object-name>.",
mono=mono,
)

Expand Down
81 changes: 20 additions & 61 deletions blue_geo/tests/test_target.py
Original file line number Diff line number Diff line change
@@ -1,77 +1,36 @@
import pytest
from shapely.geometry import Polygon

from blue_objects import file
from blue_objects import file, objects

from blue_geo.watch.targets.classes import Target, TargetList


@pytest.fixture
def target_list():
return TargetList(download=True)


def test_target(target_list: TargetList):
target = target_list.list_of_targets["elkhema"]

assert target.one_liner
from blue_geo.tests.test_target_list import target_list
from blue_geo.watch.targets import TargetList, Target


@pytest.mark.parametrize(
["catalog_name", "collection", "expected_target"],
[
["SkyFox", "Venus", "Leonardo"],
["EarthSearch", "sentinel_2_l1c", "burning-man-2024"],
],
["target_name"],
[["elkhema"]],
)
def test_target_list(
catalog_name: str,
collection: str,
expected_target: str,
def test_target(
target_list: TargetList,
target_name: str,
):
assert target_list.list_of_targets

assert target_list.test()

assert target_list.object_name
target = target_list.list_of_targets[target_name]

assert file.exists(target_list.filename())

list_of_targets = target_list.get_list(
catalog_name=catalog_name,
collection=collection,
)
assert isinstance(target, Target)

assert expected_target in list_of_targets


def test_targets_load(target_list: TargetList):
assert target_list.list_of_targets
assert target.one_liner

for target in target_list.list_of_targets.values():
assert isinstance(target, Target)
polygon = target.polygon
assert isinstance(polygon, Polygon)

for target in ["chilcotin-river-landslide", "elkhema"]:
assert target in target_list.list_of_targets
object_name = objects.unique_object()

assert target.save(object_name)

def test_targets_get(
target_list: TargetList,
):
target = target_list.get("bellingcat-2024-09-27-nagorno-karabakh")
assert target.query_args["datetime"] == "2024-05-01/2024-09-01"

target = target_list.get(
"bellingcat-2024-09-27-nagorno-karabakh-test",
including_versions=False,
assert file.exists(
objects.path_of(
filename="target/shape.geojson",
object_name=object_name,
)
)
assert not "count" in target.query_args

target = target_list.get("bellingcat-2024-09-27-nagorno-karabakh-void")
assert not "count" in target.query_args

target = target_list.get("bellingcat-2024-09-27-nagorno-karabakh")
assert target.query_args["count"] == 30

target = target_list.get("bellingcat-2024-09-27-nagorno-karabakh-test")
assert target.query_args["count"] == 2
85 changes: 85 additions & 0 deletions blue_geo/tests/test_target_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import pytest

from blue_objects import file, objects
from blue_geo.watch.targets.classes import Target, TargetList


@pytest.fixture
def target_list():
return TargetList(download=True)


@pytest.mark.parametrize(
["catalog_name", "collection", "expected_target"],
[
["SkyFox", "Venus", "Leonardo"],
["EarthSearch", "sentinel_2_l1c", "burning-man-2024"],
],
)
def test_target_list(
catalog_name: str,
collection: str,
expected_target: str,
target_list: TargetList,
):
assert target_list.list_of_targets

assert target_list.test()

assert target_list.object_name

assert file.exists(target_list.filename())

list_of_targets = target_list.get_list(
catalog_name=catalog_name,
collection=collection,
)

assert expected_target in list_of_targets


def test_target_list_load(target_list: TargetList):
assert target_list.list_of_targets

for target in target_list.list_of_targets.values():
assert isinstance(target, Target)

for target in ["chilcotin-river-landslide", "elkhema"]:
assert target in target_list.list_of_targets


def test_target_list_get(
target_list: TargetList,
):
target = target_list.get("bellingcat-2024-09-27-nagorno-karabakh")
assert target.query_args["datetime"] == "2024-05-01/2024-09-01"

target = target_list.get(
"bellingcat-2024-09-27-nagorno-karabakh-test",
including_versions=False,
)
assert not "count" in target.query_args

target = target_list.get("bellingcat-2024-09-27-nagorno-karabakh-void")
assert not "count" in target.query_args

target = target_list.get("bellingcat-2024-09-27-nagorno-karabakh")
assert target.query_args["count"] == 30

target = target_list.get("bellingcat-2024-09-27-nagorno-karabakh-test")
assert target.query_args["count"] == 2


def test_target_list_save(
target_list: TargetList,
):
object_name = objects.unique_object()

assert target_list.save(object_name)

assert file.exists(
objects.path_of(
filename="target/shape.geojson",
object_name=object_name,
)
)
Loading

0 comments on commit c7a969d

Please sign in to comment.