Skip to content

Commit

Permalink
untested ❗️ - kamangir/bolt#746
Browse files Browse the repository at this point in the history
  • Loading branch information
kamangir committed Jul 27, 2024
1 parent 561c1e4 commit 57e5853
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 95 deletions.
11 changes: 9 additions & 2 deletions blue_geo/.abcli/catalog/firms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ the `firms` catalog covers [FIRMS](https://firms.modaps.eosdis.nasa.gov): Fire I

## example use

🔥

```bash
@catalog query firms ingest,select - area \
--date 2024-07-18
@catalog query firms \
ingest,select \
- \
area,dryrun \
--date 2024-07-24

@open QGIS .
@publish tar .
```

🔥

```yaml
datacube:
area: WORLD
Expand Down
6 changes: 3 additions & 3 deletions blue_geo/.abcli/catalog/firms/browse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ function blue_geo_catalog_firms_browse() {
fi

local do_map_key=$(abcli_option_int "$options" map_key 0)
local api=$(abcli_option_choice "$options" area area)
local collection=$(abcli_option_choice "$options" area area)

local url="https://firms.modaps.eosdis.nasa.gov/"
[[ "$do_map_key" == 1 ]] &&
url="https://firms.modaps.eosdis.nasa.gov/api/map_key/"
[[ -z "$api" ]] &&
url="https://firms.modaps.eosdis.nasa.gov/api/$api/"
[[ ! -z "$collection" ]] &&
url="https://firms.modaps.eosdis.nasa.gov/api/$collection/"

abcli_browse $url
}
2 changes: 1 addition & 1 deletion blue_geo/.abcli/catalog/firms/ingest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function blue_geo_catalog_ingest_firms() {
local object_name=$(abcli_clarify_object $2 .)

abcli_eval dryrun=$do_dryrun \
python3 -m blue_geo.datacube.firms \
python3 -m blue_geo.catalog.firms \
ingest \
--object_name $object_name \
"${@:3}"
Expand Down
49 changes: 21 additions & 28 deletions blue_geo/.abcli/catalog/firms/query.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,33 @@
function blue_geo_catalog_query_firms() {
local options=$1

local catalog="firms"

local list_of_collectios=$(blue_geo_catalog get list_of_collections $catalog --delim ,)

if [ $(abcli_option_int "$options" help 0) == 1 ]; then
options="area,dryrun"

local date=$(abcli_string_timestamp_short \
--include_time 0 \
--unique 0)
local area=$(python3 -m blue_geo.datacube.firms.area \
get \
--what area \
--delim \|)
local source=$(python3 -m blue_geo.datacube.firms.area \
get \
--what source \
--values 1 \
--delim \|)

local args="[--date $date]$ABCUL[--depth 1]$ABCUL[--area $area]$ABCUL[--source $source]$ABCUL[--log 1]"

abcli_show_usage "@catalog query firms$ABCUL[$blue_geo_catalog_query_options]$ABCUL[-|<object-name>]$ABCUL[$options]$ABCUL$args" \
"firms -query-> <object-name>."
options="$list_of_collectios,dryrun"
abcli_show_usage "@catalog query $catalog$ABCUL[$blue_geo_catalog_query_options]$ABCUL[-|<object-name>]$ABCUL[$options]$ABCUL[<args>]" \
"$catalog -query-> <object-name>."
return
fi

local do_dryrun=$(abcli_option_int "$options" dryrun 0)
local api=$(abcli_option_choice "$options" area area)
local collection=$(abcli_option_choice "$options" $list_of_collectios area)

local object_name=$(abcli_clarify_object $2 -)
if [[ ",$list_of_collectios," != *",$collection,"* ]]; then
abcli_log_error "-@catalog: query: $catalog: $collection: collection not found."
return 1
fi

abcli_eval dryrun=$do_dryrun \
python3 -m blue_geo.datacube.firms \
query \
--object_name $object_name \
--api $api \
"${@:3}"
if [[ "$2" == "help" ]]; then
blue_geo_catalog_query_firms_${collection} help
return
fi

return 0
blue_geo_catalog_query_firms_${collection} \
,$options \
"${@:2}"
}

abcli_source_path - caller,suffix=/query
28 changes: 28 additions & 0 deletions blue_geo/.abcli/catalog/firms/query/area.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! /usr/bin/env bash

function blue_geo_catalog_query_firms_area() {
local options=$1

local catalog="firms"
local collection="area"

if [ $(abcli_option_int "$options" help 0) == 1 ]; then
options="$collection,dryrun"
local args=$(python3 -m blue_geo.catalog.$catalog.$collection get --what list_of_args)
abcli_show_usage "@catalog query $catalog$ABCUL[$blue_geo_catalog_query_options]$ABCUL[-|<object-name>]$ABCUL[$options]$ABCUL$args" \
"$catalog -query-> <object-name>."
return
fi

local do_dryrun=$(abcli_option_int "$options" dryrun 0)

local object_name=$(abcli_clarify_object $2 -)

abcli_eval dryrun=$do_dryrun \
python3 -m blue_geo.catalog.$catalog.$collection \
query \
--object_name $object_name \
"${@:3}"

return 0
}
3 changes: 2 additions & 1 deletion blue_geo/README.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
from blueness import module
import abcli
from abcli import file
from abcli.file.functions import build_from_template
from abcli.plugins import markdown
from blue_geo import NAME, VERSION, ICON
from blue_geo.logger import logger

NAME = f"{NAME}.README"
NAME = module.name(__file__, NAME)

features = {
"QGIS": {
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.162.1"
VERSION = "4.163.1"

REPO_NAME = "blue-geo"

Expand Down
29 changes: 29 additions & 0 deletions blue_geo/catalog/default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from argparse import ArgumentParser
from typing import Dict


def add_default_arguments(
default_args: Dict[str, Dict],
parser: ArgumentParser,
):
for arg, values in default_args.items():
parser.add_argument(
f"--{arg}",
type=values.get("type", str),
default=values["default"],
help=values["help"],
)


def as_list_of_args(default_args: Dict[str, Dict]) -> str:
return "$ABCUL".join(
sorted(
[
"--{} {}".format(
arg,
values["help"],
)
for arg, values in default_args.items()
]
)
)
30 changes: 30 additions & 0 deletions blue_geo/catalog/firms/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import argparse
from blueness import module
from blue_geo import NAME, VERSION
from blue_geo.catalog import get_datacube
from blue_geo.logger import logger
from blueness.argparse.generic import sys_exit

NAME = module.name(__file__, NAME)

parser = argparse.ArgumentParser(NAME, description=f"{NAME}-{VERSION}")
parser.add_argument(
"task",
type=str,
help="ingest",
)
parser.add_argument(
"--object_name",
type=str,
)
args = parser.parse_args()


success = False
if args.task == "ingest":
datacube = get_datacube(datacube_id=args.object_name)
success, _ = datacube.ingest(object_name=args.object_name)
else:
success = None

sys_exit(logger, NAME, args.task, success)
72 changes: 13 additions & 59 deletions blue_geo/catalog/firms/area/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import argparse
from blueness import module
from datetime import datetime, timedelta
from blue_geo import NAME, VERSION
from abcli.plugins.metadata import post_to_object
from blue_geo.catalog.default import add_default_arguments, as_list_of_args
from blue_geo.catalog.firms.area.enums import Area, Source
from blue_geo.catalog.firms.area.classes import FirmsAreaDatacube
from blue_geo.catalog.firms.area.default import args as default_args
from blue_geo.logger import logger
from blueness.argparse.generic import sys_exit

Expand All @@ -14,81 +14,35 @@
parser.add_argument(
"task",
type=str,
help="get|ingest|query",
)
parser.add_argument(
"--object_name",
type=str,
)
parser.add_argument(
"--source",
type=str,
default=Source.default().name,
help="|".join(Source.values()),
)
parser.add_argument(
"--area",
type=str,
default=Area.default().name,
help="|".join(Area.values()),
)
parser.add_argument(
"--date",
type=str,
default=(datetime.now() - timedelta(days=5)).strftime("%Y-%m-%d"),
help="yyyy-mm-dd",
)
parser.add_argument(
"--depth",
type=int,
default=1,
help="1..10",
help="get|query",
)
add_default_arguments(default_args, parser)
parser.add_argument(
"--what",
type=str,
default="area",
help="area|source",
)
parser.add_argument(
"--values",
type=int,
default=1,
help="0|1",
)
parser.add_argument(
"--delim",
type=str,
default="|",
help="list_of_args",
)
args = parser.parse_args()

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

success = False
if args.task == "get":
what = Area if args.what == "area" else Source if args.what == "source" else None
what = what.default() if what else None
print((delim.join(what.values()) if args.values else what.name) if what else None)
output = f"unknown-{args.what}"

if args.what == "list_of_args":
output = as_list_of_args(default_args)

print(output)
success = True
elif args.task == "ingest":
datacube = FirmsAreaDatacube(datacube_id=args.object_name)
success, _ = datacube.ingest(object_name=args.object_name)
elif args.task == "query":
datacube = FirmsAreaDatacube(
success = FirmsAreaDatacube.query(
object_name=args.object_name,
area=Area[args.area],
source=Source[args.source],
depth=args.depth,
date=args.date,
)

logger.info(f"🧊 {datacube.datacube_id}")

success = post_to_object(
args.object_name,
"datacube_id",
[datacube.datacube_id],
)
else:
success = None

Expand Down
13 changes: 13 additions & 0 deletions blue_geo/catalog/firms/area/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from abcli import file
from abcli.modules import objects
from abcli.plugins import metadata
from abcli.plugins.metadata import post_to_object
from blue_geo.catalog.firms import FirmsCatalog
from blue_geo.catalog.generic import GenericDatacube
from blue_geo.catalog.firms.area.enums import Area, Source
Expand Down Expand Up @@ -173,3 +174,15 @@ def ingest_url(self, html: bool = False) -> str:
self.depth, # day_range
self.date,
)

@staticmethod
def query(object_name: str, **kwargs) -> bool:
datacube = FirmsAreaDatacube(**kwargs)

logger.info(f"🧊 {datacube.description}")

return post_to_object(
object_name,
"datacube_id",
[datacube.datacube_id],
)
23 changes: 23 additions & 0 deletions blue_geo/catalog/firms/area/default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import Dict
from blue_geo.catalog.firms.area.enums import Area, Source
from datetime import datetime, timedelta

args: Dict[str, Dict] = {
"area": {
"default": Area.default().name,
"help": "|".join(Area.values()),
},
"date": {
"default": (datetime.now() - timedelta(days=5)).strftime("%Y-%m-%d"),
"help": "yyyy-mm-dd",
},
"depth": {
"type": int,
"default": 1,
"help": "1..10",
},
"source": {
"default": Source.default().name,
"help": "|".join(Source.values()),
},
}
6 changes: 6 additions & 0 deletions blue_geo/catalog/firms/classes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from blueness import module
from blue_geo import NAME
from blue_geo.catalog.generic import GenericCatalog
from blue_geo.logger import logger

NAME = module.name(__file__, NAME)


class FirmsCatalog(GenericCatalog):
name = "firms"
collections = ["area"]
Loading

0 comments on commit 57e5853

Please sign in to comment.