diff --git a/edav/FOS-data-access-example.ipynb b/edav/FOS-data-access-example.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..9104cdcf1fdc683d266748967b72be416c2e47ba --- /dev/null +++ b/edav/FOS-data-access-example.ipynb @@ -0,0 +1,156 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "import json\n", + "import configparser\n", + "import os\n", + "\n", + "config = configparser.ConfigParser()\n", + "config.read('/projects/.maap/edav.ini')\n", + "\n", + "edav_das_url = config['edav']['edav_das_url']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# GET Dataset Information\n", + "\n", + "The following command shows how to retrieve from the ESA MAAP das service the metadata of FOS dataset, such as description, temporal extent, spatial coverage and so on." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "url = edav_das_url+\"/opensearch/datasets?datasetId=FOS\"\n", + "r = requests.get(url)\n", + "r.json()[\"features\"][0]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Get Records\n", + "\n", + "The following command shows how to retrieve from the ESA MAAP das service the list of FOS subDatasets including metadata. Being a paginated result, the command shows how to handle the retrival of a number of pages equal to **pages**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "url = edav_das_url+\"/opensearch/search?datasetId=FOS\"\n", + "r = requests.get(url)\n", + "\n", + "results=[]\n", + "if len(r.json()[\"features\"]) > 0:\n", + " results.extend(r.json()[\"features\"])\n", + "else:\n", + " print(\"No records found\")\n", + "\n", + "pages=0\n", + "while len(r.json()[\"features\"]) > 0 and pages==2:\n", + " r = requests.get(r.json()[\"properties\"][\"links\"][1][\"next\"])\n", + " results.extend(r.json()[\"features\"])\n", + " pages+=1\n", + "\n", + "for res in results:\n", + " print(res)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Filter records with a specific subDatasetId\n", + "\n", + "The following command shows how to retrieve from the ESA MAAP das service the dataset/subDataset of interest, i.e. **number of records= 1014**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "url = edav_das_url+\"/opensearch/search?datasetId=FOS&subDatasetId=AGB_Local_HD_97_5_Percent_Quantil\"\n", + "r = requests.get(url)\n", + "print(\"Number of records: %d\"%(r.json()[\"properties\"][\"totalResults\"]))\n", + "r.json()[\"features\"]\n", + "for res in r.json()[\"features\"]:\n", + " print(res)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Filter records with a geometry\n", + "\n", + "The following command shows how to retrieve from the ESA MAAP das service the dataset/subDataset of interest over an area of interest, i.e. **number of records= 24**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "min_lon=12.659379394795842\n", + "max_lon=12.763663681294867\n", + "min_lat=3.317562241422408\n", + "max_lat=3.3688016409270745\n", + "geom={\"type\":\"Polygon\",\"coordinates\":[[[min_lon,max_lat],[min_lon,min_lat],[max_lon,min_lat],[max_lon,max_lat],[min_lon,max_lat]]]}\n", + "url = edav_das_url+'/opensearch/search?datasetId=FOS&subDatasetId=AGB_Local_HD_97_5_Percent_Quantil&geometry='+json.dumps(geom)\n", + "r = requests.get(url)\n", + "print(\"Number of records: %d\"%(r.json()[\"properties\"][\"totalResults\"]))\n", + "if len(r.json()[\"features\"])>0:\n", + " for fea in r.json()[\"features\"]:\n", + " print(fea)\n", + "else:\n", + " print(\"No records in this area\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/init.sh b/init.sh index c75d415c86312994632fc6992f682c228e02749f..f41e11bb128f137144e8103fc5261607713bdc23 100755 --- a/init.sh +++ b/init.sh @@ -23,4 +23,5 @@ echo "[edav]" > $HOME/.maap/edav.ini echo "user_data_ingestion_url = https://edav-das-vap.${MAAP_ENV_TYPE,,}.esa-maap.org/loader/upload.json" >> $HOME/.maap/edav.ini echo "user_data_remote_s3_path = maap-scientific-data/shared" >> $HOME/.maap/edav.ini echo "user_data_local_s3_mount = /projects/s3-drive/user-data" >> $HOME/.maap/edav.ini -echo "user_data_upload_location = edav" >> $HOME/.maap/edav.ini \ No newline at end of file +echo "user_data_upload_location = edav" >> $HOME/.maap/edav.ini +echo "edav_das_url = https://edav-das.${MAAP_ENV_TYPE,,}.esa-maap.org" >> $HOME/.maap/edav.ini \ No newline at end of file