diff --git a/01-WCS-basics.ipynb b/01-WCS-basics.ipynb index ad8cecbb53e75753e1afe67e19242f1e0447c445..b6e9839ebee6378e8c4e66817b5b61b96275880d 100644 --- a/01-WCS-basics.ipynb +++ b/01-WCS-basics.ipynb @@ -140,7 +140,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "[Index](index.ipynb) | [Next](02-WCS-getExtent-ipynb)" + "[Index](index.ipynb) | [Next](02-WCS-getExtent.ipynb)" ] } ], @@ -164,7 +164,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.8.2" } }, "nbformat": 4, diff --git a/02-WCS-getExtent.ipynb b/02-WCS-getExtent.ipynb index 90783f45549fee950c7775494bfdb43e66b81718..1af2800a9d0ff303468b8e2b2c0ab1dee22554e5 100644 --- a/02-WCS-getExtent.ipynb +++ b/02-WCS-getExtent.ipynb @@ -115,7 +115,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "[Index](index.ipynb) | [Previous](01-WCS-basics-ipynb)" + "[Index](index.ipynb) | [Previous](01-WCS-basics.ipynb) | [Next](03-WCS-2.0.ipynb)" ] } ], @@ -139,7 +139,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.8.2" } }, "nbformat": 4, diff --git a/03-WCS-2.0.ipynb b/03-WCS-2.0.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..8d305bd6b00de8cfb8b7820fbf52d57073dce84a --- /dev/null +++ b/03-WCS-2.0.ipynb @@ -0,0 +1,158 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Working with WCS 2.0\n", + "====================\n", + "\n", + "The WCS standard underwent a major update in 2017 that introduced important improvements. Among these is a more abstract treatment of data axes, thinking especially of space-time datasets and data cubes. The friendly [OWSLib](https://geopython.github.io/OWSLib/) package has been updated accordingly and can be easily be used with the version 2.0 of the standard.\n", + "\n", + "Connection set up and service inspection functions as before:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from owslib.wcs import WebCoverageService\n", + "\n", + "wcs = WebCoverageService('http://maps.isric.org/mapserv?map=/map/phh2o.map',\n", + " version='2.0.1')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "With the 2.0 version, supported are announced in slightly different way, let us thus inspect these in first place:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "cov_id = 'phh2o_0-5cm_mean'\n", + "ph_0_5 = wcs.contents[cov_id]\n", + "ph_0_5.supportedFormats" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Perhaps the most noteciable change is the way segmentation is expressed. The infamous bounding boxes have been dropped at last and replaced by axis specific segmentation. The new argument `subsets` takes in a list of tuples, one tuple per axis. Each tuple is a triplet: (*axis identifier*, *minimum*, *maximum*). Here is an example with the same extent for Senegal used in the previous notebook:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "subsets = [('X', -1784000, -1140000), ('Y', 1356000, 1863000)]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "CRSs are also expressed in a different way in version 2.0, now referring to the [opengis.net](http://www.opengis.net) registry. Again the surrogate EPSG code 152160 is used, as the Petroleum folk remain unimpressed by the Homolosine projection:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "crs = \"http://www.opengis.net/def/crs/EPSG/0/152160\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "All information is now in place to issue a `GetCoverage` request and save the result to disk: " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "response = wcs.getCoverage(\n", + " identifier=[cov_id], \n", + " crs=crs,\n", + " subsets=subsets, \n", + " resx=250, resy=250, \n", + " format=ph_0_5.supportedFormats[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "with open('./data/Senegal_pH_0-5_mean.tif', 'wb') as file:\n", + " file.write(response.read())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The `rasterio` package can be used exactly as before to plot the segment obtained from the service:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import rasterio\n", + "from rasterio import plot\n", + "\n", + "ph = rasterio.open(\"./data/Senegal_pH_0-5_mean.tif\", driver=\"GTiff\")\n", + "%matplotlib inline\n", + "plot.show(ph, title='Mean pH between 0 and 5 cm deep in Senegal', cmap='gist_ncar')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[Index](index.ipynb) | [Previous](02-WCS-getExtent.ipynb)" + ] + } + ], + "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.2" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/index.ipynb b/index.ipynb index 98c6c696c7821dd5bc18364a643f7bacdfb0cb38..1b67e985220522c4b7e42c2b7f4a34bf09507d40 100644 --- a/index.ipynb +++ b/index.ipynb @@ -17,7 +17,8 @@ "--------------------\n", "\n", "1. [WCS: basic operations](01-WCS-basics.ipynb)\n", - "2. [WCS: fetching and plotting a map segment](02-WCS-getExtent.ipynb)" + "2. [WCS: fetching and plotting a map segment](02-WCS-getExtent.ipynb)\n", + "3. [WCS: working with WCS 2.0](03-WCS-2.0.ipynb)" ] } ], @@ -41,7 +42,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.8.2" } }, "nbformat": 4,