Skip to content

Commit

Permalink
Datacube refactor - kamangir/bolt#746
Browse files Browse the repository at this point in the history
  • Loading branch information
kamangir committed Jul 21, 2024
1 parent 6a8e725 commit f1fba1f
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 29 deletions.
22 changes: 14 additions & 8 deletions blue_geo/.abcli/datacube/get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ function blue_geo_datacube_get() {

if [[ "$what" == "catalog" ]]; then
local object_name=$(abcli_clarify_object $2 .)
extra_args="--object_name $object_name ${@:3}"
python3 -m blue_geo.datacube \
get \
--what "$what" \
--object_name $object_name \
"${@:3}"
elif [[ "$what" == "template" ]]; then
extra_args="--catalog $2 ${@:3}"
python3 -m blue_geo.datacube \
get \
--what "$what" \
--catalog "$2" \
"${@:3}"
else
extra_args="${@:2}"
python3 -m blue_geo.datacube \
get \
--what "$what" \
"${@:2}"
fi

python3 -m blue_geo.datacube \
get \
--what "$what" \
"$extra_args"
}
2 changes: 1 addition & 1 deletion blue_geo/.abcli/datacube/ingest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function blue_geo_datacube_ingest() {

[[ "$do_copy_template" == 1 ]] &&
abcli_clone \
$BLUE_GEO_FIRMS_QGIS_TEMPLATE \
$template_object_name \
$object_name \
~meta

Expand Down
2 changes: 1 addition & 1 deletion blue_geo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

DESCRIPTION = f"{ICON} AI for precise geospatial data analysis and visualization."

VERSION = "4.99.1"
VERSION = "4.100.1"

REPO_NAME = "blue-geo"

Expand Down
2 changes: 1 addition & 1 deletion blue_geo/config.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
BLUE_GEO_UKRAINE_TIMEMAP_QGIS_TEMPLATE=ukraine-timemap-template-v11

BLUE_GEO_FIRMS_QGIS_TEMPLATE=firms-template-v1
BLUE_GEO_FIRMS_AREA_QGIS_TEMPLATE=firms-template-v1
33 changes: 30 additions & 3 deletions blue_geo/datacube/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import argparse
from blue_geo import VERSION
from blue_geo.datacube.catalogs import list_of
from blue_geo.ukraine_timemap import NAME
from blue_geo import env
from blue_geo.datacube.catalogs import catalog_of
from blue_geo.datacube import NAME
from blue_geo.logger import logger
from blueness.argparse.generic import sys_exit

parser = argparse.ArgumentParser(NAME, description=f"{NAME}-{VERSION}")
parser.add_argument(
"task",
type=str,
help="list_of_catalogs",
help="get|list_of_catalogs",
)
parser.add_argument(
"--delim",
Expand All @@ -22,12 +24,37 @@
type=int,
help="0|1",
)
parser.add_argument(
"--what",
default="",
type=str,
help="catalog|template",
)
parser.add_argument(
"--object_name",
type=str,
default="",
)
parser.add_argument(
"--catalog",
type=str,
default="",
)
args = parser.parse_args()

delim = " " if args.delim == "space" else args.delim

success = False
if args.task == "list_of_catalogs":
if args.task == "get":
success = True
output = f"unknown-{args.what}"
if args.what == "template":
output = env.QGIS_TEMPLATES.get(args.catalog, output)
elif args.what == "catalog":
_, output = catalog_of(datacube_id=args.object_name)

print(output)
elif args.task == "list_of_catalogs":
success = True
output = list_of

Expand Down
20 changes: 19 additions & 1 deletion blue_geo/datacube/catalogs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
from typing import Tuple, List
from blue_geo.datacube.generic import GenericDatacube
from blue_geo.datacube.firms.area import FirmsAreaDatacube

list_of = [FirmsAreaDatacube.catalog]

list_of_datacube_classes: List[GenericDatacube] = [
FirmsAreaDatacube,
]

list_of = list(
set([datacube_class.catalog for datacube_class in list_of_datacube_classes])
)


def catalog_of(datacube_id: str) -> Tuple[bool, str]:
for datacube_class in list_of_datacube_classes:
success, _ = datacube_class.parse_datacube_id(datacube_id)
if success:
return True, datacube_class.catalog

return False, "unknown-catalog"
14 changes: 7 additions & 7 deletions blue_geo/datacube/firms/area/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,27 @@ def parse_datacube_id(cls, datacube_id: str) -> Tuple[

# datacube-firm_area-<area>-<source>
pieces = datacube_id.split("-")
if len(pieces) < 6:
if len(pieces) < 8:
return False, {}

area_str = pieces[2].upper
if area_str not in Area.values:
area_str = pieces[2]
if area_str not in Area.values():
return False, {}

source_str = pieces[3]
if source_str not in Source.values:
if source_str not in Source.values():
return False, {}

date = pieces[4]
date = "{}-{}-{}".format(pieces[4], pieces[5], pieces[6])

depth_str = pieces[5]
depth_str = pieces[7]
if not depth_str.isdigit():
return False, {}

return (
True,
{
"area": Area[area_str],
"area": Area[area_str.upper()],
"source": Source[source_str],
"date": date,
"depth": int(depth_str),
Expand Down
5 changes: 1 addition & 4 deletions blue_geo/datacube/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ def parse_datacube_id(cls, datacube_id: str) -> Tuple[
pieces = datacube_id.split("-") + ["", ""]

return (
all(
pieces[0] == "datacube",
pieces[1] == cls.catalog,
),
pieces[0] == "datacube" and pieces[1] == cls.catalog,
{},
)
8 changes: 6 additions & 2 deletions blue_geo/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
"BLUE_GEO_UKRAINE_TIMEMAP_QGIS_TEMPLATE", ""
)

BLUE_GEO_FIRMS_QGIS_TEMPLATE = os.getenv(
"BLUE_GEO_FIRMS_QGIS_TEMPLATE",
BLUE_GEO_FIRMS_AREA_QGIS_TEMPLATE = os.getenv(
"BLUE_GEO_FIRMS_AREA_QGIS_TEMPLATE",
"",
)

FIRMS_MAP_KEY = os.getenv("FIRMS_MAP_KEY", "")

QGIS_TEMPLATES = {
"firms_area": BLUE_GEO_FIRMS_AREA_QGIS_TEMPLATE,
}
2 changes: 1 addition & 1 deletion blue_geo/tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ def test_abcli_env():

def test_blue_geo_env():
assert env.BLUE_GEO_UKRAINE_TIMEMAP_QGIS_TEMPLATE
assert env.BLUE_GEO_FIRMS_QGIS_TEMPLATE
assert env.BLUE_GEO_FIRMS_AREA_QGIS_TEMPLATE
assert env.FIRMS_MAP_KEY

0 comments on commit f1fba1f

Please sign in to comment.