Skip to content

Commit

Permalink
firms ingest refactor - kamangir/bolt#746
Browse files Browse the repository at this point in the history
  • Loading branch information
kamangir committed Jul 17, 2024
1 parent de33870 commit 0fbe188
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 9 deletions.
2 changes: 2 additions & 0 deletions blue_geo/.abcli/blue_geo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ function blue_geo() {

if [ $task == "help" ]; then
ukraine_timemap "$@"
blue_geo_QGIS "$@"
blue_geo_ingest "$@"
return
fi

Expand Down
21 changes: 21 additions & 0 deletions blue_geo/.abcli/ingest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /usr/bin/env bash

function blue_geo_ingest() {
local task=$(abcli_unpack_keyword $1 help)

if [ "$task" == "help" ]; then
blue_geo_ingest_firms "$@"
return
fi

local function_name=blue_geo_ingest_$task
if [[ $(type -t $function_name) == "function" ]]; then
$function_name "${@:2}"
return
fi

abcli_log_error "-blue_geo: ingest: $task: command not found."
return 1
}

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

function blue_geo_ingest_firms() {
local options=$1

if [ $(abcli_option_int "$options" help 0) == 1 ]; then
options="dryrun,~upload"
local date=$(abcli_string_timestamp_short \
--include_time 0 \
--unique 0)
local area=$(python3 -m blue_geo.firms.api.area \
get \
--what area \
--delim \|)
local source=$(python3 -m blue_geo.firms.api.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 "blue_geo ingest firms$ABCUL[$options]$ABCUL[.|<object-name>]$ABCUL$args" \
"firms -ingest-> <object-name>."
return
fi

local do_dryrun=$(abcli_option_int "$options" dryrun 0)
local do_upload=$(abcli_option_int "$options" upload $(abcli_not $do_dryrun))

local object_name=$(abcli_clarify_object $2 .)

abcli_eval dryrun=$do_dryrun \
python3 -m blue_geo.firms.api.area \
ingest \
--object_name $object_name \
"${@:4}"

[[ "$do_dryrun" == 1 ]] &&
abcli_upload - $object_name

return 0
}
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.48.1"
VERSION = "4.49.1"

REPO_NAME = "blue-geo"

Expand Down
33 changes: 28 additions & 5 deletions blue_geo/firms/api/area/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
parser.add_argument(
"task",
type=str,
help="ingest",
help="get|ingest",
)
parser.add_argument(
"--object_name",
Expand All @@ -36,20 +36,43 @@
help="yyyy-mm-dd",
)
parser.add_argument(
"--day_range",
"--depth",
type=int,
default=1,
help="1..10",
)

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="|",
)
args = parser.parse_args()

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

success = False
if args.task == "ingest":
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)
success = True
elif args.task == "ingest":
api_request = APIRequest(
area=Area[args.area],
source=Source[args.source],
day_range=args.day_range,
depth=args.depth,
date=args.date,
)

Expand Down
6 changes: 3 additions & 3 deletions blue_geo/firms/api/area/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(
source: Source = Source.default(),
area: Area = Area.default(),
date: str = "",
day_range: int = 1,
depth: int = 1,
log: bool = True,
):
self.prefix = "https://firms.modaps.eosdis.nasa.gov"
Expand All @@ -20,7 +20,7 @@ def __init__(
self.area: Area = area
self.source: Source = source

self.day_range: int = day_range
self.depth: int = depth

self.date: str = (
date if date else (datetime.now() - timedelta(days=5)).strftime("%Y-%m-%d")
Expand Down Expand Up @@ -58,6 +58,6 @@ def url(self, html: bool = False) -> str:
self.map_key,
self.source.name,
self.area.name.lower(),
self.day_range,
self.depth, # day_range
self.date,
)

0 comments on commit 0fbe188

Please sign in to comment.