From 31330f3590f64964804ceb972d1d2c3294c03e09 Mon Sep 17 00:00:00 2001
From: nehajo88 <nehajo88@gmail.com>
Date: Thu, 10 Nov 2022 16:19:19 +0000
Subject: [PATCH] update alg

---
 .../run_country_summaries-checkpoint.ipynb    | 149 +++++++++++-------
 .../dps/run_country_summaries.ipynb           | 137 ++++++++++------
 2 files changed, 174 insertions(+), 112 deletions(-)

diff --git a/country_summaries/dps/.ipynb_checkpoints/run_country_summaries-checkpoint.ipynb b/country_summaries/dps/.ipynb_checkpoints/run_country_summaries-checkpoint.ipynb
index 3b814d1..e3a4711 100644
--- a/country_summaries/dps/.ipynb_checkpoints/run_country_summaries-checkpoint.ipynb
+++ b/country_summaries/dps/.ipynb_checkpoints/run_country_summaries-checkpoint.ipynb
@@ -3,7 +3,7 @@
   {
    "cell_type": "code",
    "execution_count": 1,
-   "id": "turkish-strand",
+   "id": "worst-collapse",
    "metadata": {},
    "outputs": [
     {
@@ -26,7 +26,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "accepted-therapy",
+   "id": "introductory-stuart",
    "metadata": {},
    "source": [
     "# Launch DPS for Country_summaries_DPS.R"
@@ -35,7 +35,7 @@
   {
    "cell_type": "code",
    "execution_count": 2,
-   "id": "incoming-boulder",
+   "id": "floral-commodity",
    "metadata": {},
    "outputs": [
     {
@@ -43,18 +43,18 @@
      "output_type": "stream",
      "text": [
       "Requirement already satisfied: geopandas in /opt/conda/lib/python3.7/site-packages (0.10.2)\n",
-      "Requirement already satisfied: pandas>=0.25.0 in /opt/conda/lib/python3.7/site-packages (from geopandas) (1.1.4)\n",
       "Requirement already satisfied: pyproj>=2.2.0 in /opt/conda/lib/python3.7/site-packages (from geopandas) (3.2.1)\n",
-      "Requirement already satisfied: fiona>=1.8 in /opt/conda/lib/python3.7/site-packages (from geopandas) (1.8.22)\n",
       "Requirement already satisfied: shapely>=1.6 in /opt/conda/lib/python3.7/site-packages (from geopandas) (1.8.5.post1)\n",
-      "Requirement already satisfied: attrs>=17 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (20.3.0)\n",
-      "Requirement already satisfied: cligj>=0.5 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (0.7.2)\n",
+      "Requirement already satisfied: pandas>=0.25.0 in /opt/conda/lib/python3.7/site-packages (from geopandas) (1.1.4)\n",
+      "Requirement already satisfied: fiona>=1.8 in /opt/conda/lib/python3.7/site-packages (from geopandas) (1.8.22)\n",
+      "Requirement already satisfied: certifi in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (2021.5.30)\n",
       "Requirement already satisfied: click>=4.0 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (8.0.1)\n",
-      "Requirement already satisfied: setuptools in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (41.4.0)\n",
+      "Requirement already satisfied: cligj>=0.5 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (0.7.2)\n",
       "Requirement already satisfied: six>=1.7 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (1.12.0)\n",
-      "Requirement already satisfied: certifi in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (2021.5.30)\n",
-      "Requirement already satisfied: click-plugins>=1.0 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (1.1.1)\n",
+      "Requirement already satisfied: attrs>=17 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (20.3.0)\n",
       "Requirement already satisfied: munch in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (2.5.0)\n",
+      "Requirement already satisfied: click-plugins>=1.0 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (1.1.1)\n",
+      "Requirement already satisfied: setuptools in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (41.4.0)\n",
       "Requirement already satisfied: python-dateutil>=2.7.3 in /opt/conda/lib/python3.7/site-packages (from pandas>=0.25.0->geopandas) (2.8.1)\n",
       "Requirement already satisfied: pytz>=2017.2 in /opt/conda/lib/python3.7/site-packages (from pandas>=0.25.0->geopandas) (2021.1)\n",
       "Requirement already satisfied: numpy>=1.15.4 in /opt/conda/lib/python3.7/site-packages (from pandas>=0.25.0->geopandas) (1.19.4)\n",
@@ -62,11 +62,11 @@
       "Requirement already satisfied: typing-extensions>=3.6.4 in /opt/conda/lib/python3.7/site-packages (from importlib-metadata->click>=4.0->fiona>=1.8->geopandas) (3.7.4.3)\n",
       "Requirement already satisfied: zipp>=0.5 in /opt/conda/lib/python3.7/site-packages (from importlib-metadata->click>=4.0->fiona>=1.8->geopandas) (3.4.1)\n",
       "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
-      "\u001b[0m\u001b[33mWARNING: You are using pip version 22.0.3; however, version 22.3 is available.\n",
+      "\u001b[0m\u001b[33mWARNING: You are using pip version 22.0.3; however, version 22.3.1 is available.\n",
       "You should consider upgrading via the '/opt/conda/bin/python -m pip install --upgrade pip' command.\u001b[0m\u001b[33m\n",
       "\u001b[0mRequirement already satisfied: xmltodict in /opt/conda/lib/python3.7/site-packages (0.13.0)\n",
       "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
-      "\u001b[0m\u001b[33mWARNING: You are using pip version 22.0.3; however, version 22.3 is available.\n",
+      "\u001b[0m\u001b[33mWARNING: You are using pip version 22.0.3; however, version 22.3.1 is available.\n",
       "You should consider upgrading via the '/opt/conda/bin/python -m pip install --upgrade pip' command.\u001b[0m\u001b[33m\n",
       "\u001b[0m"
      ]
@@ -92,12 +92,39 @@
     "    return url.replace('/projects/my-private-bucket', f'https://s3.console.aws.amazon.com/s3/buckets/maap-ops-workspace/{user}')\n",
     "def local_to_https_uswest2(url, user='nehajo88'):\n",
     "    ''' A Function to convert local paths to https us-west-s urls'''\n",
-    "    return url.replace('/projects/my-private-bucket', f'https://maap-ops-workspace.s3.us-west-2.amazonaws.com/{user}')"
+    "    return url.replace('/projects/my-private-bucket', f'https://maap-ops-workspace.s3.us-west-2.amazonaws.com/{user}')\n",
+    "\n",
+    "import xml.etree.ElementTree as ET\n",
+    "from urllib.parse import urlparse\n",
+    "\n",
+    "def job_status_for(job_id: str) -> str:\n",
+    "    response = maap.getJobStatus(job_id)\n",
+    "    response.raise_for_status()\n",
+    "    \n",
+    "    root = ET.fromstring(response.text)\n",
+    "    status_element = root.find('.//{http://www.opengis.net/wps/2.0}Status')\n",
+    "    \n",
+    "    return status_element.text\n",
+    "\n",
+    "def job_result_for(job_id: str) -> str:\n",
+    "    response = maap.getJobResult(job_id)\n",
+    "    response.raise_for_status()\n",
+    "    \n",
+    "    root = ET.fromstring(response.text)\n",
+    "\n",
+    "    return root.find('.//{http://www.opengis.net/wps/2.0}Data').text\n",
+    "\n",
+    "def to_job_output_dir(job_result_url: str) -> str:\n",
+    "    url_path = urlparse(job_result_url).path\n",
+    "    # The S3 Key is the URL path excluding the `/{username}` prefix\n",
+    "    s3_key = \"/\".join(url_path.split(\"/\")[2:])\n",
+    "\n",
+    "    return f\"/projects/my-private-bucket/{s3_key}\""
    ]
   },
   {
    "cell_type": "markdown",
-   "id": "french-background",
+   "id": "sexual-floating",
    "metadata": {},
    "source": [
     "## COMMIT ALL CHANGES and REGISTER ALGORITHM FROM TERMINAL"
@@ -105,7 +132,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "intellectual-marketplace",
+   "id": "nearby-radio",
    "metadata": {},
    "source": [
     "conda activate r-with-gdal\n",
@@ -125,7 +152,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "stylish-easter",
+   "id": "processed-thursday",
    "metadata": {},
    "source": [
     "## BUILD Rscript ARGUMENTS\n",
@@ -134,7 +161,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "matched-heath",
+   "id": "adapted-bridge",
    "metadata": {},
    "source": [
     "## Run a DPS job\n"
@@ -142,8 +169,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
-   "id": "cleared-hopkins",
+   "execution_count": 5,
+   "id": "academic-estonia",
    "metadata": {},
    "outputs": [
     {
@@ -155,9 +182,9 @@
       "https://maap-ops-workspace.s3.us-west-2.amazonaws.com/shared/nehajo88/Data/Country_boundaries/GEDI_countries_Dubayah_individual/ne_10m_a_1_MEX.gpkg\n",
       "https://maap-ops-workspace.s3.us-west-2.amazonaws.com/shared/nehajo88/Data/Country_boundaries/GEDI_countries_Dubayah_individual/ne_10m_a_1_GHA.gpkg\n",
       "https://maap-ops-workspace.s3.us-west-2.amazonaws.com/shared/nehajo88/Data/Country_boundaries/GEDI_countries_Dubayah_individual/ne_10m_a_1_ECU.gpkg\n",
-      "Current time:\t202211101459\n",
-      "CPU times: user 51.8 ms, sys: 8.21 ms, total: 60 ms\n",
-      "Wall time: 1.18 s\n"
+      "Current time:\t202211101618\n",
+      "CPU times: user 50.4 ms, sys: 9.55 ms, total: 60 ms\n",
+      "Wall time: 671 ms\n"
      ]
     },
     {
@@ -198,11 +225,11 @@
        "      <th>0</th>\n",
        "      <td>success</td>\n",
        "      <td>200</td>\n",
-       "      <td>4d97afc0-afda-47fb-a5c9-77f868be9402</td>\n",
+       "      <td>e225ab1b-08ae-4a9c-8ed0-d13adae42c6b</td>\n",
        "      <td>1</td>\n",
        "      <td>SEN</td>\n",
-       "      <td>2022-11-10 14:59:43.650145</td>\n",
-       "      <td>14</td>\n",
+       "      <td>2022-11-10 16:18:44.924537</td>\n",
+       "      <td>16</td>\n",
        "      <td>run_country_summaries_ubuntu</td>\n",
        "      <td>nehajo88</td>\n",
        "      <td>maap-dps-worker-32gb</td>\n",
@@ -211,11 +238,11 @@
        "      <th>0</th>\n",
        "      <td>success</td>\n",
        "      <td>200</td>\n",
-       "      <td>0e12f6cb-ebd1-43c9-9ab4-fe0d90b28d97</td>\n",
+       "      <td>af838f7c-87a6-4084-8796-62f601041a56</td>\n",
        "      <td>2</td>\n",
        "      <td>MEX</td>\n",
-       "      <td>2022-11-10 14:59:43.713511</td>\n",
-       "      <td>14</td>\n",
+       "      <td>2022-11-10 16:18:45.007192</td>\n",
+       "      <td>16</td>\n",
        "      <td>run_country_summaries_ubuntu</td>\n",
        "      <td>nehajo88</td>\n",
        "      <td>maap-dps-worker-32gb</td>\n",
@@ -224,11 +251,11 @@
        "      <th>0</th>\n",
        "      <td>success</td>\n",
        "      <td>200</td>\n",
-       "      <td>e2de68c0-7c5a-4d5a-b45a-ba8e39df49d0</td>\n",
+       "      <td>0b6a8e75-264a-4b00-a947-01f3771566ee</td>\n",
        "      <td>3</td>\n",
        "      <td>GHA</td>\n",
-       "      <td>2022-11-10 14:59:44.420047</td>\n",
-       "      <td>14</td>\n",
+       "      <td>2022-11-10 16:18:45.167302</td>\n",
+       "      <td>16</td>\n",
        "      <td>run_country_summaries_ubuntu</td>\n",
        "      <td>nehajo88</td>\n",
        "      <td>maap-dps-worker-32gb</td>\n",
@@ -237,11 +264,11 @@
        "      <th>0</th>\n",
        "      <td>success</td>\n",
        "      <td>200</td>\n",
-       "      <td>b0e49837-4a29-44fd-bfa9-bc0d6f50b64a</td>\n",
+       "      <td>d921f34f-f80a-467f-a2ac-26b7f3e77600</td>\n",
        "      <td>4</td>\n",
        "      <td>ECU</td>\n",
-       "      <td>2022-11-10 14:59:44.539928</td>\n",
-       "      <td>14</td>\n",
+       "      <td>2022-11-10 16:18:45.307778</td>\n",
+       "      <td>16</td>\n",
        "      <td>run_country_summaries_ubuntu</td>\n",
        "      <td>nehajo88</td>\n",
        "      <td>maap-dps-worker-32gb</td>\n",
@@ -252,16 +279,16 @@
       ],
       "text/plain": [
        "    status  http_status_code                                job_id  dps_num  \\\n",
-       "0  success               200  4d97afc0-afda-47fb-a5c9-77f868be9402        1   \n",
-       "0  success               200  0e12f6cb-ebd1-43c9-9ab4-fe0d90b28d97        2   \n",
-       "0  success               200  e2de68c0-7c5a-4d5a-b45a-ba8e39df49d0        3   \n",
-       "0  success               200  b0e49837-4a29-44fd-bfa9-bc0d6f50b64a        4   \n",
+       "0  success               200  e225ab1b-08ae-4a9c-8ed0-d13adae42c6b        1   \n",
+       "0  success               200  af838f7c-87a6-4084-8796-62f601041a56        2   \n",
+       "0  success               200  0b6a8e75-264a-4b00-a947-01f3771566ee        3   \n",
+       "0  success               200  d921f34f-f80a-467f-a2ac-26b7f3e77600        4   \n",
        "\n",
        "  tile_num                submit_time  dbs_job_hour  \\\n",
-       "0      SEN 2022-11-10 14:59:43.650145            14   \n",
-       "0      MEX 2022-11-10 14:59:43.713511            14   \n",
-       "0      GHA 2022-11-10 14:59:44.420047            14   \n",
-       "0      ECU 2022-11-10 14:59:44.539928            14   \n",
+       "0      SEN 2022-11-10 16:18:44.924537            16   \n",
+       "0      MEX 2022-11-10 16:18:45.007192            16   \n",
+       "0      GHA 2022-11-10 16:18:45.167302            16   \n",
+       "0      ECU 2022-11-10 16:18:45.307778            16   \n",
        "\n",
        "                        algo_id      user           worker_type  \n",
        "0  run_country_summaries_ubuntu  nehajo88  maap-dps-worker-32gb  \n",
@@ -270,7 +297,7 @@
        "0  run_country_summaries_ubuntu  nehajo88  maap-dps-worker-32gb  "
       ]
      },
-     "execution_count": 3,
+     "execution_count": 5,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -333,7 +360,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "ordinary-bandwidth",
+   "id": "warming-disco",
    "metadata": {},
    "source": [
     "## Assess DPS Results"
@@ -341,8 +368,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
-   "id": "nuclear-matter",
+   "execution_count": 6,
+   "id": "billion-remove",
    "metadata": {},
    "outputs": [
     {
@@ -350,13 +377,21 @@
      "output_type": "stream",
      "text": [
       "Count total jobs:\t4\n",
-      "Count pending jobs:\t0\n",
-      "Count running jobs:\t1\n",
+      "Count pending jobs:\t4\n",
+      "Count running jobs:\t0\n",
       "Count succeeded jobs:\t0\n",
-      "Count failed jobs:\t3\n",
-      "% of failed jobs:\t100.0\n",
-      "CPU times: user 53.9 ms, sys: 6.2 ms, total: 60.1 ms\n",
-      "Wall time: 114 ms\n"
+      "Count failed jobs:\t0\n"
+     ]
+    },
+    {
+     "ename": "ZeroDivisionError",
+     "evalue": "division by zero",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+      "\u001b[0;31mZeroDivisionError\u001b[0m                         Traceback (most recent call last)",
+      "\u001b[0;32m<timed exec>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n",
+      "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero"
      ]
     }
    ],
@@ -387,15 +422,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "balanced-silence",
-   "metadata": {},
-   "outputs": [],
-   "source": []
-  },
-  {
-   "cell_type": "code",
-   "execution_count": null,
-   "id": "cutting-karen",
+   "id": "chinese-juice",
    "metadata": {},
    "outputs": [],
    "source": []
diff --git a/country_summaries/dps/run_country_summaries.ipynb b/country_summaries/dps/run_country_summaries.ipynb
index d4b6447..e3a4711 100644
--- a/country_summaries/dps/run_country_summaries.ipynb
+++ b/country_summaries/dps/run_country_summaries.ipynb
@@ -3,7 +3,7 @@
   {
    "cell_type": "code",
    "execution_count": 1,
-   "id": "invalid-holder",
+   "id": "worst-collapse",
    "metadata": {},
    "outputs": [
     {
@@ -26,7 +26,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "polar-equality",
+   "id": "introductory-stuart",
    "metadata": {},
    "source": [
     "# Launch DPS for Country_summaries_DPS.R"
@@ -35,7 +35,7 @@
   {
    "cell_type": "code",
    "execution_count": 2,
-   "id": "pending-ethernet",
+   "id": "floral-commodity",
    "metadata": {},
    "outputs": [
     {
@@ -43,18 +43,18 @@
      "output_type": "stream",
      "text": [
       "Requirement already satisfied: geopandas in /opt/conda/lib/python3.7/site-packages (0.10.2)\n",
+      "Requirement already satisfied: pyproj>=2.2.0 in /opt/conda/lib/python3.7/site-packages (from geopandas) (3.2.1)\n",
       "Requirement already satisfied: shapely>=1.6 in /opt/conda/lib/python3.7/site-packages (from geopandas) (1.8.5.post1)\n",
-      "Requirement already satisfied: fiona>=1.8 in /opt/conda/lib/python3.7/site-packages (from geopandas) (1.8.22)\n",
       "Requirement already satisfied: pandas>=0.25.0 in /opt/conda/lib/python3.7/site-packages (from geopandas) (1.1.4)\n",
-      "Requirement already satisfied: pyproj>=2.2.0 in /opt/conda/lib/python3.7/site-packages (from geopandas) (3.2.1)\n",
-      "Requirement already satisfied: setuptools in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (41.4.0)\n",
-      "Requirement already satisfied: munch in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (2.5.0)\n",
-      "Requirement already satisfied: attrs>=17 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (20.3.0)\n",
-      "Requirement already satisfied: cligj>=0.5 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (0.7.2)\n",
-      "Requirement already satisfied: six>=1.7 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (1.12.0)\n",
+      "Requirement already satisfied: fiona>=1.8 in /opt/conda/lib/python3.7/site-packages (from geopandas) (1.8.22)\n",
       "Requirement already satisfied: certifi in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (2021.5.30)\n",
       "Requirement already satisfied: click>=4.0 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (8.0.1)\n",
+      "Requirement already satisfied: cligj>=0.5 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (0.7.2)\n",
+      "Requirement already satisfied: six>=1.7 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (1.12.0)\n",
+      "Requirement already satisfied: attrs>=17 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (20.3.0)\n",
+      "Requirement already satisfied: munch in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (2.5.0)\n",
       "Requirement already satisfied: click-plugins>=1.0 in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (1.1.1)\n",
+      "Requirement already satisfied: setuptools in /opt/conda/lib/python3.7/site-packages (from fiona>=1.8->geopandas) (41.4.0)\n",
       "Requirement already satisfied: python-dateutil>=2.7.3 in /opt/conda/lib/python3.7/site-packages (from pandas>=0.25.0->geopandas) (2.8.1)\n",
       "Requirement already satisfied: pytz>=2017.2 in /opt/conda/lib/python3.7/site-packages (from pandas>=0.25.0->geopandas) (2021.1)\n",
       "Requirement already satisfied: numpy>=1.15.4 in /opt/conda/lib/python3.7/site-packages (from pandas>=0.25.0->geopandas) (1.19.4)\n",
@@ -92,12 +92,39 @@
     "    return url.replace('/projects/my-private-bucket', f'https://s3.console.aws.amazon.com/s3/buckets/maap-ops-workspace/{user}')\n",
     "def local_to_https_uswest2(url, user='nehajo88'):\n",
     "    ''' A Function to convert local paths to https us-west-s urls'''\n",
-    "    return url.replace('/projects/my-private-bucket', f'https://maap-ops-workspace.s3.us-west-2.amazonaws.com/{user}')"
+    "    return url.replace('/projects/my-private-bucket', f'https://maap-ops-workspace.s3.us-west-2.amazonaws.com/{user}')\n",
+    "\n",
+    "import xml.etree.ElementTree as ET\n",
+    "from urllib.parse import urlparse\n",
+    "\n",
+    "def job_status_for(job_id: str) -> str:\n",
+    "    response = maap.getJobStatus(job_id)\n",
+    "    response.raise_for_status()\n",
+    "    \n",
+    "    root = ET.fromstring(response.text)\n",
+    "    status_element = root.find('.//{http://www.opengis.net/wps/2.0}Status')\n",
+    "    \n",
+    "    return status_element.text\n",
+    "\n",
+    "def job_result_for(job_id: str) -> str:\n",
+    "    response = maap.getJobResult(job_id)\n",
+    "    response.raise_for_status()\n",
+    "    \n",
+    "    root = ET.fromstring(response.text)\n",
+    "\n",
+    "    return root.find('.//{http://www.opengis.net/wps/2.0}Data').text\n",
+    "\n",
+    "def to_job_output_dir(job_result_url: str) -> str:\n",
+    "    url_path = urlparse(job_result_url).path\n",
+    "    # The S3 Key is the URL path excluding the `/{username}` prefix\n",
+    "    s3_key = \"/\".join(url_path.split(\"/\")[2:])\n",
+    "\n",
+    "    return f\"/projects/my-private-bucket/{s3_key}\""
    ]
   },
   {
    "cell_type": "markdown",
-   "id": "conservative-connectivity",
+   "id": "sexual-floating",
    "metadata": {},
    "source": [
     "## COMMIT ALL CHANGES and REGISTER ALGORITHM FROM TERMINAL"
@@ -105,7 +132,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "unlikely-hartford",
+   "id": "nearby-radio",
    "metadata": {},
    "source": [
     "conda activate r-with-gdal\n",
@@ -125,7 +152,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "legislative-chile",
+   "id": "processed-thursday",
    "metadata": {},
    "source": [
     "## BUILD Rscript ARGUMENTS\n",
@@ -134,7 +161,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "sufficient-massage",
+   "id": "adapted-bridge",
    "metadata": {},
    "source": [
     "## Run a DPS job\n"
@@ -142,8 +169,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
-   "id": "chubby-variance",
+   "execution_count": 5,
+   "id": "academic-estonia",
    "metadata": {},
    "outputs": [
     {
@@ -155,9 +182,9 @@
       "https://maap-ops-workspace.s3.us-west-2.amazonaws.com/shared/nehajo88/Data/Country_boundaries/GEDI_countries_Dubayah_individual/ne_10m_a_1_MEX.gpkg\n",
       "https://maap-ops-workspace.s3.us-west-2.amazonaws.com/shared/nehajo88/Data/Country_boundaries/GEDI_countries_Dubayah_individual/ne_10m_a_1_GHA.gpkg\n",
       "https://maap-ops-workspace.s3.us-west-2.amazonaws.com/shared/nehajo88/Data/Country_boundaries/GEDI_countries_Dubayah_individual/ne_10m_a_1_ECU.gpkg\n",
-      "Current time:\t202211101539\n",
-      "CPU times: user 47.9 ms, sys: 13.2 ms, total: 61.1 ms\n",
-      "Wall time: 622 ms\n"
+      "Current time:\t202211101618\n",
+      "CPU times: user 50.4 ms, sys: 9.55 ms, total: 60 ms\n",
+      "Wall time: 671 ms\n"
      ]
     },
     {
@@ -198,11 +225,11 @@
        "      <th>0</th>\n",
        "      <td>success</td>\n",
        "      <td>200</td>\n",
-       "      <td>6f272e12-9602-4a18-ab14-bb70298ea011</td>\n",
+       "      <td>e225ab1b-08ae-4a9c-8ed0-d13adae42c6b</td>\n",
        "      <td>1</td>\n",
        "      <td>SEN</td>\n",
-       "      <td>2022-11-10 15:39:01.752047</td>\n",
-       "      <td>15</td>\n",
+       "      <td>2022-11-10 16:18:44.924537</td>\n",
+       "      <td>16</td>\n",
        "      <td>run_country_summaries_ubuntu</td>\n",
        "      <td>nehajo88</td>\n",
        "      <td>maap-dps-worker-32gb</td>\n",
@@ -211,11 +238,11 @@
        "      <th>0</th>\n",
        "      <td>success</td>\n",
        "      <td>200</td>\n",
-       "      <td>2064ce88-5aef-42d1-bd0c-dbbebf086d78</td>\n",
+       "      <td>af838f7c-87a6-4084-8796-62f601041a56</td>\n",
        "      <td>2</td>\n",
        "      <td>MEX</td>\n",
-       "      <td>2022-11-10 15:39:01.815854</td>\n",
-       "      <td>15</td>\n",
+       "      <td>2022-11-10 16:18:45.007192</td>\n",
+       "      <td>16</td>\n",
        "      <td>run_country_summaries_ubuntu</td>\n",
        "      <td>nehajo88</td>\n",
        "      <td>maap-dps-worker-32gb</td>\n",
@@ -224,11 +251,11 @@
        "      <th>0</th>\n",
        "      <td>success</td>\n",
        "      <td>200</td>\n",
-       "      <td>cf444ab8-a1f7-4ddc-b431-2dd8fa0f4568</td>\n",
+       "      <td>0b6a8e75-264a-4b00-a947-01f3771566ee</td>\n",
        "      <td>3</td>\n",
        "      <td>GHA</td>\n",
-       "      <td>2022-11-10 15:39:01.875601</td>\n",
-       "      <td>15</td>\n",
+       "      <td>2022-11-10 16:18:45.167302</td>\n",
+       "      <td>16</td>\n",
        "      <td>run_country_summaries_ubuntu</td>\n",
        "      <td>nehajo88</td>\n",
        "      <td>maap-dps-worker-32gb</td>\n",
@@ -237,11 +264,11 @@
        "      <th>0</th>\n",
        "      <td>success</td>\n",
        "      <td>200</td>\n",
-       "      <td>cc135899-600d-4299-ba0e-1ca9d2500e05</td>\n",
+       "      <td>d921f34f-f80a-467f-a2ac-26b7f3e77600</td>\n",
        "      <td>4</td>\n",
        "      <td>ECU</td>\n",
-       "      <td>2022-11-10 15:39:02.056273</td>\n",
-       "      <td>15</td>\n",
+       "      <td>2022-11-10 16:18:45.307778</td>\n",
+       "      <td>16</td>\n",
        "      <td>run_country_summaries_ubuntu</td>\n",
        "      <td>nehajo88</td>\n",
        "      <td>maap-dps-worker-32gb</td>\n",
@@ -252,16 +279,16 @@
       ],
       "text/plain": [
        "    status  http_status_code                                job_id  dps_num  \\\n",
-       "0  success               200  6f272e12-9602-4a18-ab14-bb70298ea011        1   \n",
-       "0  success               200  2064ce88-5aef-42d1-bd0c-dbbebf086d78        2   \n",
-       "0  success               200  cf444ab8-a1f7-4ddc-b431-2dd8fa0f4568        3   \n",
-       "0  success               200  cc135899-600d-4299-ba0e-1ca9d2500e05        4   \n",
+       "0  success               200  e225ab1b-08ae-4a9c-8ed0-d13adae42c6b        1   \n",
+       "0  success               200  af838f7c-87a6-4084-8796-62f601041a56        2   \n",
+       "0  success               200  0b6a8e75-264a-4b00-a947-01f3771566ee        3   \n",
+       "0  success               200  d921f34f-f80a-467f-a2ac-26b7f3e77600        4   \n",
        "\n",
        "  tile_num                submit_time  dbs_job_hour  \\\n",
-       "0      SEN 2022-11-10 15:39:01.752047            15   \n",
-       "0      MEX 2022-11-10 15:39:01.815854            15   \n",
-       "0      GHA 2022-11-10 15:39:01.875601            15   \n",
-       "0      ECU 2022-11-10 15:39:02.056273            15   \n",
+       "0      SEN 2022-11-10 16:18:44.924537            16   \n",
+       "0      MEX 2022-11-10 16:18:45.007192            16   \n",
+       "0      GHA 2022-11-10 16:18:45.167302            16   \n",
+       "0      ECU 2022-11-10 16:18:45.307778            16   \n",
        "\n",
        "                        algo_id      user           worker_type  \n",
        "0  run_country_summaries_ubuntu  nehajo88  maap-dps-worker-32gb  \n",
@@ -270,7 +297,7 @@
        "0  run_country_summaries_ubuntu  nehajo88  maap-dps-worker-32gb  "
       ]
      },
-     "execution_count": 3,
+     "execution_count": 5,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -333,7 +360,7 @@
   },
   {
    "cell_type": "markdown",
-   "id": "electric-hobby",
+   "id": "warming-disco",
    "metadata": {},
    "source": [
     "## Assess DPS Results"
@@ -341,8 +368,8 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 19,
-   "id": "cosmetic-matthew",
+   "execution_count": 6,
+   "id": "billion-remove",
    "metadata": {},
    "outputs": [
     {
@@ -350,13 +377,21 @@
      "output_type": "stream",
      "text": [
       "Count total jobs:\t4\n",
-      "Count pending jobs:\t0\n",
+      "Count pending jobs:\t4\n",
       "Count running jobs:\t0\n",
-      "Count succeeded jobs:\t4\n",
-      "Count failed jobs:\t0\n",
-      "% of failed jobs:\t0.0\n",
-      "CPU times: user 53.8 ms, sys: 4.77 ms, total: 58.6 ms\n",
-      "Wall time: 112 ms\n"
+      "Count succeeded jobs:\t0\n",
+      "Count failed jobs:\t0\n"
+     ]
+    },
+    {
+     "ename": "ZeroDivisionError",
+     "evalue": "division by zero",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+      "\u001b[0;31mZeroDivisionError\u001b[0m                         Traceback (most recent call last)",
+      "\u001b[0;32m<timed exec>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n",
+      "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero"
      ]
     }
    ],
@@ -387,7 +422,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "exposed-modem",
+   "id": "chinese-juice",
    "metadata": {},
    "outputs": [],
    "source": []
-- 
GitLab