From c7dcf6e1b2c5e9b292fe69d9cf426ddf2232ee86 Mon Sep 17 00:00:00 2001 From: kamangir Date: Mon, 15 Jul 2024 20:29:28 -0700 Subject: [PATCH] =?UTF-8?q?fascinating=20feature=20=F0=9F=AA=84=20-=20kama?= =?UTF-8?q?ngir/bolt#746?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blue_geo/__init__.py | 2 +- blue_geo/firms/__init__.py | 3 + blue_geo/firms/api/__init__.py | 3 + blue_geo/firms/api/area/__init__.py | 5 + blue_geo/firms/api/area/__main__.py | 26 ++++ blue_geo/firms/api/area/classes.py | 25 ++++ blue_geo/firms/api/area/enums.py | 43 ++++++ blue_geo/tests/test_firms_api_area.py | 21 +++ notebooks/firms-area-api.ipynb | 190 ++++++++++++++++++++++++++ 9 files changed, 317 insertions(+), 1 deletion(-) create mode 100644 blue_geo/firms/__init__.py create mode 100644 blue_geo/firms/api/__init__.py create mode 100644 blue_geo/firms/api/area/__init__.py create mode 100644 blue_geo/firms/api/area/__main__.py create mode 100644 blue_geo/firms/api/area/classes.py create mode 100644 blue_geo/firms/api/area/enums.py create mode 100644 blue_geo/tests/test_firms_api_area.py create mode 100644 notebooks/firms-area-api.ipynb diff --git a/blue_geo/__init__.py b/blue_geo/__init__.py index 56685b49..4e9208ec 100644 --- a/blue_geo/__init__.py +++ b/blue_geo/__init__.py @@ -4,7 +4,7 @@ DESCRIPTION = f"{ICON} AI for precise geospatial data analysis and visualization." -VERSION = "4.43.1" +VERSION = "4.44.1" REPO_NAME = "blue-geo" diff --git a/blue_geo/firms/__init__.py b/blue_geo/firms/__init__.py new file mode 100644 index 00000000..26a61ef1 --- /dev/null +++ b/blue_geo/firms/__init__.py @@ -0,0 +1,3 @@ +from blue_geo import NAME + +NAME = f"{NAME}.firms" diff --git a/blue_geo/firms/api/__init__.py b/blue_geo/firms/api/__init__.py new file mode 100644 index 00000000..f096e766 --- /dev/null +++ b/blue_geo/firms/api/__init__.py @@ -0,0 +1,3 @@ +from blue_geo.firms import NAME + +NAME = f"{NAME}.api" diff --git a/blue_geo/firms/api/area/__init__.py b/blue_geo/firms/api/area/__init__.py new file mode 100644 index 00000000..eaab5db5 --- /dev/null +++ b/blue_geo/firms/api/area/__init__.py @@ -0,0 +1,5 @@ +from blue_geo.firms.api import NAME + +NAME = f"{NAME}.area" + +REFERENCE = "https://firms.modaps.eosdis.nasa.gov/api/area/" diff --git a/blue_geo/firms/api/area/__main__.py b/blue_geo/firms/api/area/__main__.py new file mode 100644 index 00000000..98edbe90 --- /dev/null +++ b/blue_geo/firms/api/area/__main__.py @@ -0,0 +1,26 @@ +import argparse +from blue_geo import VERSION +from blue_geo.firms.api.area import NAME +from blue_geo.ukraine_timemap.functions import ingest +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="get_url", +) +parser.add_argument( + "--object_name", + type=str, +) +args = parser.parse_args() + +success = False +if args.task == "ingest": + success, _ = ingest(object_name=args.object_name) +else: + success = None + +sys_exit(logger, NAME, args.task, success) diff --git a/blue_geo/firms/api/area/classes.py b/blue_geo/firms/api/area/classes.py new file mode 100644 index 00000000..d21b1516 --- /dev/null +++ b/blue_geo/firms/api/area/classes.py @@ -0,0 +1,25 @@ +from . import NAME +from .enums import Area, Source +from blue_geo.logger import logger + + +class APIRequest: + def __init__( + self, + source: Source = Source.MODIS_NRT, + area: Area = Area.WORLD, + ): + self.area: Area = area + self.source: Source = source + + def as_str(self) -> str: + return "{}.{}, area:{}, source: {} ({})".format( + NAME, + self.__class__.__name__, + self.area.name.lower(), + self.source.name, + self.source.description, + ) + + def get_url(self) -> str: + return "" diff --git a/blue_geo/firms/api/area/enums.py b/blue_geo/firms/api/area/enums.py new file mode 100644 index 00000000..ceb317fe --- /dev/null +++ b/blue_geo/firms/api/area/enums.py @@ -0,0 +1,43 @@ +from enum import Enum, auto + + +class Area(Enum): + EAST = auto() + NORTH = auto() + SOUTH = auto() + WEST = auto() + WORLD = auto() + + +class Source(Enum): + LANDSAT_NRT = ( + auto(), + "LANDSAT Near Real-Time, Real-Time and Ultra Real-Time [US/Canada only]", + ) + MODIS_NRT = ( + auto(), + "MODIS Near Real-Time, Real-Time and Ultra Real-Time", + ) + MODIS_SP = ( + auto(), + "(MODIS Standard Processing)", + ) + VIIRS_NOAA20_NRT = ( + auto(), + "VIIRS NOAA-20 Near Real-Time, Real-Time and Ultra Real-Time", + ) + VIIRS_NOAA21_NRT = ( + auto(), + "VIIRS NOAA-21 Near Real-Time, Real-Time and Ultra Real-Time", + ) + VIIRS_SNPP_NRT = ( + auto(), + "VIIRS Suomi-NPP Near Real-Time, Real-Time and Ultra Real-Time", + ) + VIIRS_SNPP_SP = ( + auto(), + "VIIRS Suomi-NPP Standard Processing", + ) + + def __init__(self, _, description): + self.description = description diff --git a/blue_geo/tests/test_firms_api_area.py b/blue_geo/tests/test_firms_api_area.py new file mode 100644 index 00000000..248010ff --- /dev/null +++ b/blue_geo/tests/test_firms_api_area.py @@ -0,0 +1,21 @@ +import pytest +from blue_geo.firms.api.area import enums +from blue_geo.firms.api.area.classes import APIRequest + + +@pytest.mark.parametrize( + ["area", "source"], + [ + [ + enums.Area.WORLD, + enums.Source.MODIS_NRT, + ], + ], +) +def test_blue_geo_firms_api_area( + area: enums.Area, + source: enums.Source, +): + api_request = APIRequest(area=area, source=source) + + assert api_request.as_str() diff --git a/notebooks/firms-area-api.ipynb b/notebooks/firms-area-api.ipynb new file mode 100644 index 00000000..2d7ef116 --- /dev/null +++ b/notebooks/firms-area-api.ipynb @@ -0,0 +1,190 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# FIRMS Area API\n", + "\n", + "https://firms.modaps.eosdis.nasa.gov/api/area/\n", + "\n", + "map-key: https://firms.modaps.eosdis.nasa.gov/api/map_key/" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.environ[\"abcli_path_bash\"] = \"{}/git/awesome-bash-cli/bash\".format(os.getenv(\"HOME\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "🌐 abcli-9.163.1, built on 15 July 2024, 20:24:50\n" + ] + } + ], + "source": [ + "from abcli import fullname\n", + "from abcli import string\n", + "from abcli.modules import objects\n", + "from abcli.plugins import seed\n", + "from blue_geo.firms.api.area.classes import APIRequest\n", + "from blue_geo.logger import logger\n", + "\n", + "logger.info(f\"{fullname()}, built on {string.pretty_date()}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "🌐 blue_geo.firms.api.area.APIRequest, area:world, source: MODIS_NRT (MODIS Near Real-Time, Real-Time and Ultra Real-Time)\n" + ] + } + ], + "source": [ + "api_request = APIRequest()\n", + "logger.info(api_request.as_str())" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "object_name = f\"firms-{string.timestamp()}\"\n", + "object_path = objects.object_path(object_name)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "🌐 Hello World! 🪄\n" + ] + } + ], + "source": [ + "logger.info(\"Hello World! 🪄\")" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "🌀 blueness-3.64.1\n", + "🌀 blue_options-4.35.1\n", + "\u001b[0;36m📜 awesome-bash-cli: .env: 24 env var(s)\u001b[0m\n", + "\u001b[0;36m📜 awesome-bash-cli: abcli/config.env: 13 env var(s)\u001b[0m\n", + "\u001b[0;36m🔋 gpu: not found.\u001b[0m\n", + "\u001b[0;36m🚀 abcli-9.163.1.current\u001b[0m\n", + "\u001b[0;36mconfirmed: firms-2024-07-15-20-24-50-40562 does not exist.\u001b[0m\n", + "\u001b[0;36mfirms-2024-07-15-20-24-50-40562 open upload started.\u001b[0m\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + ":: firms-2024-07-15-20-24-50-40562 += #open.\n" + ] + } + ], + "source": [ + "%%bash -s $object_name\n", + "source ~/git/awesome-bash-cli/abcli/.abcli/abcli.sh in_notebook\n", + "\n", + "object_name=$1\n", + " \n", + "abcli upload - $object_name" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "# END" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.19" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}