Skip to content

Commit

Permalink
❗️ untested - towards datacube browse and ingest πŸš€ - kamangir/bolt#746
Browse files Browse the repository at this point in the history
  • Loading branch information
kamangir committed Jul 19, 2024
1 parent 08bdc1e commit 62137f0
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 19 deletions.
23 changes: 23 additions & 0 deletions blue_geo/.abcli/datacube.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /usr/bin/env bash

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

if [ "$task" == "help" ]; then
blue_geo_datacube_browse "$@"
blue_geo_datacube_ingest "$@"
blue_geo_datacube_list "$@"
return
fi

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

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

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

function firms_browse() {
local options=$1

if [ $(abcli_option_int "$options" help 0) == 1 ]; then
options="home$EOP|map_key|area-api$EOPE"
abcli_show_usage "firms browse$ABCUL$options" \
"browse firms."
return
fi

local do_map_key=$(abcli_option_int "$options" map_key 0)
local do_area_api=$(abcli_option_int "$options" area-api 0)

local url="https://firms.modaps.eosdis.nasa.gov/"
[[ "$do_map_key" == 1 ]] &&
url="https://firms.modaps.eosdis.nasa.gov/api/map_key/"
[[ "$do_area_api" == 1 ]] &&
url="https://firms.modaps.eosdis.nasa.gov/api/area/"

abcli_browse $url
}
12 changes: 11 additions & 1 deletion blue_geo/.abcli/ingest/firms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function blue_geo_ingest_firms() {
local options=$1

if [ $(abcli_option_int "$options" help 0) == 1 ]; then
options="dryrun,~upload"
options="$EOP~copy_template,dryrun,~upload$EOPE"
local date=$(abcli_string_timestamp_short \
--include_time 0 \
--unique 0)
Expand All @@ -24,10 +24,20 @@ function blue_geo_ingest_firms() {
fi

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

local object_name=$(abcli_clarify_object $2 .)

if [[ "$do_copy_template" == 1 ]]; then
abcli_clone \
$BLUE_GEO_FIRMS_QGIS_TEMPLATE \
$object_name \
~meta
rm -v \
$abcli_object_root/$object_name/firms.*
fi

abcli_eval dryrun=$do_dryrun \
python3 -m blue_geo.firms.api.area \
ingest \
Expand Down
5 changes: 2 additions & 3 deletions blue_geo/.abcli/ukraine-timemap/browse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ function ukraine_timemap_browse() {
local options=$1

if [ $(abcli_option_int "$options" help 0) == 1 ]; then
options="dataset|github"
abcli_show_usage "ukraine_timemap browse$ABCUL[$options]" \
options="home$EOP|dataset|github$EOPE"
abcli_show_usage "ukraine_timemap browse$ABCUL$options" \
"browse ukraine-timemap."
return
fi
Expand All @@ -20,5 +20,4 @@ function ukraine_timemap_browse() {
url="https://bellingcat-embeds.ams3.cdn.digitaloceanspaces.com/production/ukr/timemap/api.json"

abcli_browse $url

}
4 changes: 2 additions & 2 deletions blue_geo/.abcli/ukraine-timemap/ingest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function ukraine_timemap_ingest() {
local options=$1

if [ $(abcli_option_int "$options" help 0) == 1 ]; then
options="${EOP}~copy_template,dryrun,~upload$EOPE"
options="$EOP~copy_template,dryrun,~upload$EOPE"
local open_options="open$EOP,~QGIS$EOPE"
abcli_show_usage "ukraine_timemap ingest$ABCUL$options$ABCUL-$EOP|<object-name>$EOPE$ABCUL$open_options" \
"ingest the latest dataset from https://github.com/bellingcat/ukraine-timemap."
Expand All @@ -19,7 +19,7 @@ function ukraine_timemap_ingest() {

if [[ "$do_copy_template" == 1 ]]; then
abcli_clone \
$UKRAINE_TIMEMAP_TEMPLATE \
$BLUE_GEO_UKRAINE_TIMEMAP_QGIS_TEMPLATE \
$object_name \
~meta
rm -v \
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.58.1"
VERSION = "4.59.1"

REPO_NAME = "blue-geo"

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

BLUE_GEO_FIRMS_QGIS_TEMPLATE=firms-template-v1
9 changes: 8 additions & 1 deletion blue_geo/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
load_config(__name__)


UKRAINE_TIMEMAP_TEMPLATE = os.getenv("UKRAINE_TIMEMAP_TEMPLATE", "")
BLUE_GEO_UKRAINE_TIMEMAP_QGIS_TEMPLATE = os.getenv(
"BLUE_GEO_UKRAINE_TIMEMAP_QGIS_TEMPLATE", ""
)

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

FIRMS_MAP_KEY = os.getenv("FIRMS_MAP_KEY", "")
11 changes: 2 additions & 9 deletions blue_geo/firms/api/area/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ def ingest(self, object_name: str) -> Tuple[
)
)

csv_filename = objects.path_of(
f"{object_name}.csv",
object_name,
create=True,
)
csv_filename = objects.path_of(f"firms.csv", object_name, create=True)
if not file.download(
self.url(),
csv_filename,
Expand All @@ -91,10 +87,7 @@ def ingest(self, object_name: str) -> Tuple[
)

if not file.save_geojson(
objects.path_of(
f"{object_name}.geojson",
object_name,
),
objects.path_of("firms.geojson", object_name),
gdf,
):
return False, gdf
Expand Down
3 changes: 2 additions & 1 deletion blue_geo/tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ def test_abcli_env():


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

0 comments on commit 62137f0

Please sign in to comment.