{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Use HTTP requests for WPS rook\n", "\n", "* rook wps: https://github.com/roocs/rook\n", "* wps documentation: http://geoprocessing.info/wpsdoc/\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import requests" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "url = os.environ.get('ROOK_URL', 'http://localhost:5000/wps')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## GetCapabilities" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'http://cp4cds-cn1.dkrz.de/wps?service=WPS&request=GetCapabilities'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "req_url = f\"{url}?service=WPS&request=GetCapabilities\"\n", "req_url" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "resp = requests.get(req_url)\n", "resp.ok" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n", " \n", " rook\n", " A WPS service for roocs.\n", " \n", " PyWPS\n", " WPS\n", " OGC\n", " processing\n", " birdhouse\n", " roocs\n", " demo\n", " cp4cds\n", " copernicus\n", " ecmwf\n", " theme\n", " \n", " WPS\n", " 1.0.0\n", " 2.0.0\n", " NONE\n", " \n", " NONE\n", " \n", " \n", " \n", " rook\n", " \n", " \n", " Lastname, Firstname\n", " Position Title\n", " \n", " \n", " +xx-xxx-xxx-xxxx\n", " \n", " \n", " \n", " \n", " City\n", " \n", " Zip or Postal Code\n", " Country\n", " Email Address\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " subset\n", " Subset\n", " Run subsetting on climate data.\n", " \n", " \n", " average\n", " Average\n", " Run averaging on climate data.\n", " \n", " \n", " orchestrate\n", " Orchestrate\n", " Run a workflow\n", " \n", " \n", " \n", " \n", " en-US\n", " \n", " \n", " en-US\n", " \n", " \n", "\n" ] } ], "source": [ "print(resp.text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## DescribeProcess subset" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'http://cp4cds-cn1.dkrz.de/wps?service=WPS&version=1.0.0&request=DescribeProcess&identifier=subset'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "req_url = f\"{url}?service=WPS&version=1.0.0&request=DescribeProcess&identifier=subset\"\n", "req_url" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "resp = requests.get(req_url)\n", "resp.ok" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n", " \n", " subset\n", " Subset\n", " Run subsetting on climate data.\n", " \n", " \n", " collection\n", " Collection\n", " c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest\n", " \n", " string\n", " \n", " \n", " \n", " time\n", " Time Period\n", " Example: 1860-01-01/1900-12-30\n", " \n", " string\n", " \n", " \n", " \n", " area\n", " Area\n", " Example: 0.,49.,10.,65\n", " \n", " string\n", " \n", " \n", " \n", " level\n", " Level\n", " Example: 0/1000\n", " \n", " string\n", " \n", " \n", " \n", " pre_checked\n", " Pre-Checked\n", " Use checked data only.\n", " \n", " boolean\n", " False\n", " \n", " \n", " \n", " \n", " \n", " output\n", " METALINK v4 output\n", " Metalink v4 document with references to NetCDF files.\n", " \n", " \n", " \n", " application/metalink+xml; version=4.0\n", " metalink/4.0/metalink4.xsd\n", " \n", " \n", " \n", " \n", " application/metalink+xml; version=4.0\n", " metalink/4.0/metalink4.xsd\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n" ] } ], "source": [ "print(resp.text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Execute subset (sync mode)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Edit data inputs**" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "collection = \"c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest\"\n", "time = \"1860-01-01/1900-12-30\"\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'http://cp4cds-cn1.dkrz.de/wps?service=WPS&version=1.0.0&request=Execute&identifier=subset&DataInputs=collection=c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest;time=1860-01-01/1900-12-30'" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "datainputs = f\"DataInputs=collection={collection};time={time}\"\n", "req_url = f\"{url}?service=WPS&version=1.0.0&request=Execute&identifier=subset&{datainputs}\"\n", "req_url" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "resp = requests.get(req_url)\n", "resp.ok" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", " \n", " subset\n", " Subset\n", " Run subsetting on climate data.\n", "\t\n", " \n", " PyWPS Process Subset finished\n", "\t\n", "\t\n", "\t\t\n", " output\n", " METALINK v4 output\n", " Metalink v4 document with references to NetCDF files.\n", " \n", "\t\t\n", "\t\n", "\n" ] } ], "source": [ "print(resp.text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Load metalink result document**\n", "\n", "Replace the metalink output URL.\n", "```python\n", "metalink_url = ''\n", "```" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "metalink_url = 'http://cp4cds-cn1.dkrz.de:80/outputs/rook/2ac0d5d2-f8b4-11ea-96c8-f2e4655a10b7/input.meta4'\n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", " 2020-09-17T09:05:34Z\n", " PyWPS/4.2.8\n", "\n", " \n", " NetCDF file\n", " 391277\n", " http://cp4cds-cn1.dkrz.de:80/outputs/rook/2e522a8e-f8b4-11ea-96c8-f2e4655a10b7/lon_bounds_day_EC-EARTH_historical_r1i1p1_18600101-19001229.nc\n", " \n", " \n", "\n", "\n" ] } ], "source": [ "print(requests.get(metalink_url).text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Execute subset (async mode)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'http://cp4cds-cn1.dkrz.de/wps?service=WPS&version=1.0.0&request=Execute&identifier=subset&DataInputs=collection=c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest;time=1860-01-01/1900-12-30&status=true&storeExecuteResponse=true'" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "req_url = f\"{url}?service=WPS&version=1.0.0&request=Execute&identifier=subset&{datainputs}\"\n", "req_url += \"&status=true&storeExecuteResponse=true\"\n", "req_url" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "resp = requests.get(req_url)\n", "resp.ok" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", " \n", " subset\n", " Subset\n", " Run subsetting on climate data.\n", "\t\n", " \n", " PyWPS Process subset accepted\n", "\t\n", "\n" ] } ], "source": [ "print(resp.text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Poll status location**\n", "\n", "Replace the `statusLocation` URL.\n", "```python\n", "statusLocation = ''\n", "```" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "# statusLocation = ''\n", "statusLocation = 'http://cp4cds-cn1.dkrz.de/outputs/rook/f005b850-f8b2-11ea-96c8-f2e4655a10b7.xml'\n" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", " \n", " subset\n", " Subset\n", " Run subsetting on climate data.\n", "\t\n", " \n", " PyWPS Process Subset finished\n", "\t\n", "\t\n", "\t\t\n", " output\n", " METALINK v4 output\n", " Metalink v4 document with references to NetCDF files.\n", " \n", "\t\t\n", "\t\n", "\n" ] } ], "source": [ "resp = requests.get(statusLocation)\n", "print(resp.text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Load metalink document**\n", "\n", "Replace the metalink output URL.\n", "```python\n", "metalink_url = ''\n", "```" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "metalink_url = 'http://cp4cds-cn1.dkrz.de:80/outputs/rook/f005b850-f8b2-11ea-96c8-f2e4655a10b7/input.meta4'\n" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", " 2020-09-17T08:56:46Z\n", " PyWPS/4.2.8\n", "\n", " \n", " NetCDF file\n", " 391277\n", " http://cp4cds-cn1.dkrz.de:80/outputs/rook/f388dff2-f8b2-11ea-96c8-f2e4655a10b7/lon_bounds_day_EC-EARTH_historical_r1i1p1_18600101-19001229.nc\n", " \n", " \n", "\n", "\n" ] } ], "source": [ "print(requests.get(metalink_url).text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Download netCDF output**\n", "\n", "Replace the download URL.\n", "\n", "```python\n", "download_url = ''\n", "```" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "download_url = 'http://cp4cds-cn1.dkrz.de/outputs/rook/f388dff2-f8b2-11ea-96c8-f2e4655a10b7/lon_bounds_day_EC-EARTH_historical_r1i1p1_18600101-19001229.nc'\n" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "http://cp4cds-cn1.dkrz.de/outputs/rook/f388dff2-f8b2-11ea-96c8-f2e4655a10b7/lon_bounds_day_EC-EARTH_historical_r1i1p1_18600101-19001229.nc\n" ] } ], "source": [ "print(download_url)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }