{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Search for Landsat-8 products using the \"eop:track\" as a queryable" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import lxml.etree as etree\n", "import requests\n", "import cioppy\n", "ciop = cioppy.Cioppy()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def get_params(osd):\n", "\n", " oss_ns = {'a':'http://www.w3.org/2001/XMLSchema', \n", " 'b':'http://www.w3.org/2001/XMLSchema-instance',\n", " 'c':'http://a9.com/-/opensearch/extensions/time/1.0/',\n", " 'd':'http://www.opengis.net/eop/2.0',\n", " 'e':'http://purl.org/dc/terms/',\n", " 'f':'http://a9.com/-/spec/opensearch/extensions/parameters/1.0/',\n", " 'g':'http://purl.org/dc/elements/1.1/',\n", " 'h':'http://www.terradue.com/opensearch',\n", " 'i':'http://a9.com/-/opensearch/extensions/geo/1.0/',\n", " 'j':'http://a9.com/-/spec/opensearch/1.1/'}\n", " \n", " oss_content = etree.fromstring(requests.get(osd).content)\n", " \n", " url_template_element = oss_content.xpath('/j:OpenSearchDescription/j:Url[@type=\"application/atom+xml\"]',\n", " namespaces=oss_ns)[0]\n", " \n", " parameters = dict()\n", " \n", " for index, parameter in enumerate(url_template_element.xpath('.//f:Parameter', namespaces=oss_ns)):\n", " \n", " parameters[parameter.attrib['name']] = {'title' : parameter.attrib['title'], \n", " 'value' : parameter.attrib['value']}\n", " \n", " options = []\n", " for option in parameter.xpath('.//f:Option', namespaces=oss_ns):\n", " \n", " options.append(option.attrib['value'])\n", " \n", " parameters[parameter.attrib['name']] = {'title' : parameter.attrib['title'], \n", " 'value' : parameter.attrib['value'],\n", " 'options' : options}\n", " return parameters" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def get_param_value(osd, os_parameter):\n", "\n", " params = get_params(osd)\n", "\n", " res = None\n", " \n", " for index, param in enumerate(params):\n", " \n", " if params[param]['value'] == os_parameter:\n", " \n", " res = params[param]\n", " res['name'] = param\n", " \n", " return res" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the Landsat-8 endpoint" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "osd_url = 'https://catalog.terradue.com/landsat8/description'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get the Landsat-8 search parameters" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "ls8_parameters = get_params(osd_url)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print all the OpenSearch parameters" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " {geo:uid?} The identifier of the resource within the search engine context (local reference)\n", " {t2:downloadOrigin?} a string that identifies the download origin (keyword, hostname...) to adapt the enclosure. If the parameter is enclosed between [] (e.g. [terradue]), enclosure will be returned only if there is a enclosure found for this source.\n", " {eop:cloudCover?} A number, set or interval requesting the cloud coverage\n", " {eop:frame?} A number, set or interval requesting the range of orbit frames\n", " {startIndex} index of the first search result desired\n", " {t2:vendorSpecifics?} A number, set or interval filtering vendor specific name:value\n", " {startPage} page number of the set of search results desired\n", " {eop:sensorType?} A string identifying the sensor type\n", " {eop:accessedFrom?} A string identifying the location from which the resource will be accessed. The catalogue shall return the download location in the enclosure atom link according to the parameter value.\n", " {t2:landCover?} A number, set or interval requesting the land coverage\n", " {eop:productType?} A string identifying the product type\n", " {time:start?} start of the temporal interval (RFC-3339)\n", " {eop:sensorResolution?} A string identifying the sensor spectral range\n", " {sct:source?} The URI of a source link (rel=via in ATOM).\n", " {geo:geometry?} Geometry in WKT\n", " {geo:relation?} Spatial relation (possible values are “intersects”, “contains”, “disjoint”). The default is intersects.\n", " {eop:parentIdentifier?} A string identifying the collection of the entry in a hierarchy of dataset\n", " {eop:processingLevel?} A string identifying the processing level applied to the dataset\n", " {language} desired language of the results\n", " {eop:platform?} A string with the platform short name\n", " {eop:track?} A number, set or interval requesting the range of orbit tracks \n", "{t2:doubleCheckGeomtry?} Set to apply a finer geometry filtering\n", " {time:end?} stop of the temporal interval (RFC-3339)\n", " {dct:modified?} date after which dataset are updated (RFC-3339)\n", " {geo:box?} Rectangular bounding box\n", " {count} number of search results per page desired\n", " {time:relation?} Temporal relation (possible values are “intersects”, “contains”, “during”, “disjoint”, “equals”)\n", " {eop:orbitDirection?} A string identifying the orbit direction\n", " {dct:subject?} The identifier of a category. Recommended best practice is to use a controlled vocabulary.\n", " {searchTerms} EO Free Text Search\n", " {t2:extension?} The value:name of a extension.\n", " {eop:instrument?} A string identifying the instrument\n", " {eop:title?} A name given to the resource\n", " {eop:orbitType?} A string identifying the orbit type\n" ] } ], "source": [ "for key, value in ls8_parameters.iteritems():\n", "\n", " print '%24s' % ls8_parameters[key]['value'], ls8_parameters[key]['title'] " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Find the parameter associated to **'{eop:wrsLongitudeGrid?}'** and its options" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "product_type_parameter = get_param_value(osd_url, '{eop:track?}')\n", "download_origin_parameter = get_param_value(osd_url, '{t2:downloadOrigin?}')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'track'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "product_type_parameter['name']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now search for Landsat-8 products creating a dictionary with the search parameters" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "search_params = dict([(product_type_parameter['name'], \n", " '160'), (download_origin_parameter['name'], 'terradue')])" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'do': 'terradue', 'track': '160'}" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "search_params" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "search = ciop.search(end_point=osd_url,\n", " params=search_params,\n", " output_fields='self,productType,track,enclosure,identifier,wkt,startdate', \n", " model='EOP')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Show the first result returned" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'enclosure': 'https://store.terradue.com/download/landsat8/files/v1/LC08_L1TP_160248_20190430_20190430_01_RT',\n", " 'identifier': 'LC08_L1TP_160248_20190430_20190430_01_RT',\n", " 'productType': 'L1TP',\n", " 'self': 'https://catalog.terradue.com/landsat8/search?format=atom&uid=LC08_L1TP_160248_20190430_20190430_01_RT',\n", " 'startdate': '2019-04-30T08:07:29.6130000Z',\n", " 'track': '160',\n", " 'wkt': 'POLYGON((93.72898 81.78061,98.27937 80.20367,108.4065 80.72712,105.58942 82.40608,93.72898 81.78061))'}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "search[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can of course write the search parameters directly with:\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "search = ciop.search(end_point=osd_url,\n", " params={'track': '160'},\n", " output_fields='self,productType,track,enclosure,identifier,wkt,startdate', \n", " model='EOP')" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'enclosure': 'https://earthexplorer.usgs.gov/download/external/options/LANDSAT_8_C1/LC81602482019120LGN00/INVSVC/',\n", " 'identifier': 'LC08_L1TP_160248_20190430_20190430_01_RT',\n", " 'productType': 'L1TP',\n", " 'self': 'https://catalog.terradue.com/landsat8/search?format=atom&uid=LC08_L1TP_160248_20190430_20190430_01_RT',\n", " 'startdate': '2019-04-30T08:07:29.6130000Z',\n", " 'track': '160',\n", " 'wkt': 'POLYGON((93.72898 81.78061,98.27937 80.20367,108.4065 80.72712,105.58942 82.40608,93.72898 81.78061))'}" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "search[0]" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.12" } }, "nbformat": 4, "nbformat_minor": 2 }