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 ad4ecc6 commit 7644780
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 29 deletions.
3 changes: 1 addition & 2 deletions blue_geo/.abcli/datacube/query.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env bash

export blue_geo_datacube_query_read_args="[--index <index>]$ABCUL[--prefix <prefix>]$ABCUL[--suffix <suffix>]$ABCUL[--contains <contains>]$ABCUL[--notcontains <not-contains>]"
export blue_geo_datacube_query_read_args="[--count <count>]$ABCUL[--delim <delim>]$ABCUL[--index <index>]$ABCUL[--prefix <prefix>]$ABCUL[--suffix <suffix>]$ABCUL[--contains <contains>]$ABCUL[--notcontains <not-contains>]"
export blue_geo_datacube_query_options="download,ingest,select,upload"

function blue_geo_datacube_query() {
Expand All @@ -13,7 +13,6 @@ function blue_geo_datacube_query() {
abcli_show_usage "@datacube query$ABCUL<catalog>$ABCUL$options$ABCUL-|<object-name>$ABCUL<query-options>$ABCUL<args>" \
"<catalog> -query-> <object-name>."

blue_geo_datacube_query_len "$@"
blue_geo_datacube_query_read "$@"
return
fi
Expand Down
25 changes: 0 additions & 25 deletions blue_geo/.abcli/datacube/query/len.sh

This file was deleted.

4 changes: 3 additions & 1 deletion blue_geo/.abcli/datacube/query/read.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ function blue_geo_datacube_query_read() {
local options=$1

if [ $(abcli_option_int "$options" help 0) == 1 ]; then
options="download"
options="download,len"
local args="$blue_geo_datacube_query_read_args"
abcli_show_usage "@datacube query read$ABCUL[$options]$ABCUL[.|<object-name>]$ABCUL$args" \
"read query results in <object-name>."
return
fi

local do_download=$(abcli_option_int "$options" download 0)
local show_len=$(abcli_option_int "$options" len 0)

local object_name=$(abcli_clarify_object $2 .)

Expand All @@ -21,5 +22,6 @@ function blue_geo_datacube_query_read() {
python3 -m blue_geo.datacube.query \
read \
--object_name $object_name \
--show_len $show_len \
"${@:3}"
}
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.92.1"
VERSION = "4.93.1"

REPO_NAME = "blue-geo"

Expand Down
105 changes: 105 additions & 0 deletions blue_geo/datacube/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import argparse
from blue_geo import VERSION
from abcli.plugins.metadata import get_from_object
from blue_geo.datacube.catalogs import list_of
from blue_geo.ukraine_timemap 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="read",
)
parser.add_argument(
"--count",
type=int,
default=1,
)
parser.add_argument(
"--delim",
type=str,
default=",",
)
parser.add_argument(
"--offset",
type=int,
default=0,
)
parser.add_argument(
"--prefix",
type=str,
default="",
)
parser.add_argument(
"--suffix",
type=str,
default="",
)
parser.add_argument(
"--contains",
type=str,
default="",
)
parser.add_argument(
"--notcontains",
type=str,
default="",
)
parser.add_argument(
"--object_name",
type=str,
)
parser.add_argument(
"--log",
default=0,
type=int,
help="0|1",
)
parser.add_argument(
"--show_len",
default=0,
type=int,
help="0|1",
)
args = parser.parse_args()

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

success = False
if args.task == "read":
success = True
output = get_from_object(
args.object_name,
"datacube_id",
[],
)

output = [
datacube_id
for datacube_id in output
if (not args.prefix or datacube_id.startswith(args.prefix))
and (not args.suffix or datacube_id.endswith(args.suffix))
and (not args.contains or args.contains in datacube_id)
and (not args.notcontains or args.notcontains not in datacube_id)
]

output = output[args.offset :]

if args.count != -1:
output = output[args.count]

if args.log:
logger.info(
"{:,} datacube-id(s){}".format(
len(output),
"" if args.show_len else f": {delim.join(output)}",
)
)
else:
print(len(output) if args.show_len else delim.join(output))
else:
success = None

sys_exit(logger, NAME, args.task, success)

0 comments on commit 7644780

Please sign in to comment.