{ "cells": [ { "cell_type": "markdown", "id": "3dc7fa1d", "metadata": {}, "source": [ "# Albatross — Expert notebook (WPS + programmatic usage)\n", "\n", "This notebook provides a practical, developer-oriented walkthrough for running **Albatross** via WPS and (optionally) locally." ] }, { "cell_type": "code", "id": "79deadf3", "metadata": { "jupyter": { "is_executing": true } }, "source": [ "import urllib.parse\n", "import requests\n", "import re\n", "from pathlib import Path\n", "\n", "import pandas as pd\n", "import matplotlib.pyplot as plt" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "id": "a3a4fc42", "metadata": {}, "source": [ "## WPS call\n", "\n", "Set your endpoint URL and build an `Execute` request (KVP encoding)." ] }, { "cell_type": "code", "execution_count": null, "id": "ccbdaa91", "metadata": {}, "outputs": [], "source": [ "WPS_URL = \"https:///wps\" # <-- change me\n", "INPUT_FILE_URL = \"https://raw.githubusercontent.com/climateintelligence/albatross/main/albatross/data/APGD_Como_ppt.txt\"\n", "\n", "params = {\n", " \"service\": \"WPS\",\n", " \"version\": \"1.0.0\",\n", " \"request\": \"Execute\",\n", " \"identifier\": \"Drought\",\n", " \"datainputs\": \";\".join([\n", " f\"input_file={INPUT_FILE_URL}\",\n", " \"target_variable=ZRB\",\n", " \"index=ONI\",\n", " \"glo_var=SST\",\n", " \"phase_mode=2\",\n", " \"months=3\",\n", " \"training_start_year=1951\",\n", " \"training_end_year=2015\",\n", " \"target_season=1\",\n", " ]),\n", "}\n", "url = f\"{WPS_URL}?{urllib.parse.urlencode(params)}\"\n", "print(url)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "214ffffa", "metadata": {}, "outputs": [], "source": [ "resp = requests.get(url, timeout=300)\n", "print(\"HTTP status:\", resp.status_code)\n", "text = resp.text\n", "print(text[:800])\n", "\n", "if resp.status_code != 200 or \"ProcessSucceeded\" not in text:\n", " m = re.search(r\"<(?:\\w+:)?ExceptionText>(.*?)\", text, re.DOTALL)\n", " if m:\n", " raise RuntimeError(\"WPS error: \" + re.sub(r\"\\s+\", \" \", m.group(1)).strip())\n", " raise RuntimeError(\"WPS execution did not succeed (inspect response above).\")\n", "\n", "print(\"✅ WPS ProcessSucceeded\")\n" ] }, { "cell_type": "markdown", "id": "11acd18e", "metadata": {}, "source": [ "## Extract output references (if any)" ] }, { "cell_type": "code", "execution_count": null, "id": "32fa45da", "metadata": {}, "outputs": [], "source": [ "hrefs = re.findall(r'href=\"([^\"]+)\"', text)\n", "hrefs = [h for h in hrefs if h.startswith(\"http\")]\n", "print(\"Found hrefs:\", hrefs)\n" ] }, { "cell_type": "markdown", "id": "6ff79083", "metadata": {}, "source": [ "## Local (developer) use\n", "\n", "If you have installed the repo (`pip install -e .`), you can inspect the process class and its inputs/outputs." ] }, { "cell_type": "code", "execution_count": null, "id": "2d5aefae", "metadata": {}, "outputs": [], "source": [ "from albatross.processes.wps_drought import Drought\n", "\n", "proc = Drought()\n", "print(\"Process identifier:\", proc.identifier)\n", "print(\"Inputs:\", [i.identifier for i in proc.inputs])\n", "print(\"Outputs:\", [o.identifier for o in proc.outputs])\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 5 }