{ "cells": [ { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "import geopandas as gpd\n", "import pandas as pd\n", "import rasterio as rio" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "#set working directory\n", "import os\n", "os.chdir('C:\\\\Users\\\\jtrum\\\\world_bank\\\\data')\n", "\n", "#read in files\n", "luanda = gpd.read_file('luanda2clean.geojson')\n", "\n", "with rio.open('ESA_WorldCover_10m_2021_v200_S12E012_Map.tif') as src:\n", " landCover = src.read()\n", " profile = src.profile\n", "\n", "\n", "# convert to dataframe\n", "landCover = pd.DataFrame(landCover[0])" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0123456789...35990359913599235993359943599535996359973599835999
00000000000...20202020201010101010
10000000000...20202020201010101010
20000000000...20202020202020201010
30000000000...20202020202020201010
40000000000...20203030202020101010
..................................................................
359950000000000...30303030303030303030
359960000000000...30303030303030303030
359970000000000...30303030303030303030
359980000000000...30303030303030303030
359990000000000...30303030303030303030
\n", "

36000 rows × 36000 columns

\n", "
" ], "text/plain": [ " 0 1 2 3 4 5 6 7 8 9 \\\n", "0 0 0 0 0 0 0 0 0 0 0 \n", "1 0 0 0 0 0 0 0 0 0 0 \n", "2 0 0 0 0 0 0 0 0 0 0 \n", "3 0 0 0 0 0 0 0 0 0 0 \n", "4 0 0 0 0 0 0 0 0 0 0 \n", "... ... ... ... ... ... ... ... ... ... ... \n", "35995 0 0 0 0 0 0 0 0 0 0 \n", "35996 0 0 0 0 0 0 0 0 0 0 \n", "35997 0 0 0 0 0 0 0 0 0 0 \n", "35998 0 0 0 0 0 0 0 0 0 0 \n", "35999 0 0 0 0 0 0 0 0 0 0 \n", "\n", " ... 35990 35991 35992 35993 35994 35995 35996 35997 35998 \\\n", "0 ... 20 20 20 20 20 10 10 10 10 \n", "1 ... 20 20 20 20 20 10 10 10 10 \n", "2 ... 20 20 20 20 20 20 20 20 10 \n", "3 ... 20 20 20 20 20 20 20 20 10 \n", "4 ... 20 20 30 30 20 20 20 10 10 \n", "... ... ... ... ... ... ... ... ... ... ... \n", "35995 ... 30 30 30 30 30 30 30 30 30 \n", "35996 ... 30 30 30 30 30 30 30 30 30 \n", "35997 ... 30 30 30 30 30 30 30 30 30 \n", "35998 ... 30 30 30 30 30 30 30 30 30 \n", "35999 ... 30 30 30 30 30 30 30 30 30 \n", "\n", " 35999 \n", "0 10 \n", "1 10 \n", "2 10 \n", "3 10 \n", "4 10 \n", "... ... \n", "35995 30 \n", "35996 30 \n", "35997 30 \n", "35998 30 \n", "35999 30 \n", "\n", "[36000 rows x 36000 columns]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "landCover" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "from sentinelsat import SentinelAPI, read_geojson" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "username = 'jtrummler'\n", "password = 'Cf5lvg0503!'" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "api = SentinelAPI(username, password, 'https://scihub.copernicus.eu/dhus')" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "footprint = read_geojson('luanda2clean.geojson')" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "Unsupported date value 20/01/31", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", "File \u001b[1;32mc:\\Users\\jtrum\\miniconda3\\envs\\wash_scan\\lib\\site-packages\\sentinelsat\\sentinel.py:1299\u001b[0m, in \u001b[0;36mformat_query_date\u001b[1;34m(in_date)\u001b[0m\n\u001b[0;32m 1298\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m-> 1299\u001b[0m \u001b[39mreturn\u001b[39;00m datetime\u001b[39m.\u001b[39;49mstrptime(in_date, \u001b[39m\"\u001b[39;49m\u001b[39m%\u001b[39;49m\u001b[39mY\u001b[39;49m\u001b[39m%\u001b[39;49m\u001b[39mm\u001b[39;49m\u001b[39m%d\u001b[39;49;00m\u001b[39m\"\u001b[39;49m)\u001b[39m.\u001b[39mstrftime(\u001b[39m\"\u001b[39m\u001b[39m%\u001b[39m\u001b[39mY-\u001b[39m\u001b[39m%\u001b[39m\u001b[39mm-\u001b[39m\u001b[39m%d\u001b[39;00m\u001b[39mT\u001b[39m\u001b[39m%\u001b[39m\u001b[39mH:\u001b[39m\u001b[39m%\u001b[39m\u001b[39mM:\u001b[39m\u001b[39m%\u001b[39m\u001b[39mSZ\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m 1300\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mValueError\u001b[39;00m:\n", "File \u001b[1;32mc:\\Users\\jtrum\\miniconda3\\envs\\wash_scan\\lib\\_strptime.py:568\u001b[0m, in \u001b[0;36m_strptime_datetime\u001b[1;34m(cls, data_string, format)\u001b[0m\n\u001b[0;32m 566\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Return a class cls instance based on the input string and the\u001b[39;00m\n\u001b[0;32m 567\u001b[0m \u001b[39mformat string.\"\"\"\u001b[39;00m\n\u001b[1;32m--> 568\u001b[0m tt, fraction, gmtoff_fraction \u001b[39m=\u001b[39m _strptime(data_string, \u001b[39mformat\u001b[39;49m)\n\u001b[0;32m 569\u001b[0m tzname, gmtoff \u001b[39m=\u001b[39m tt[\u001b[39m-\u001b[39m\u001b[39m2\u001b[39m:]\n", "File \u001b[1;32mc:\\Users\\jtrum\\miniconda3\\envs\\wash_scan\\lib\\_strptime.py:349\u001b[0m, in \u001b[0;36m_strptime\u001b[1;34m(data_string, format)\u001b[0m\n\u001b[0;32m 348\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m found:\n\u001b[1;32m--> 349\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mtime data \u001b[39m\u001b[39m%r\u001b[39;00m\u001b[39m does not match format \u001b[39m\u001b[39m%r\u001b[39;00m\u001b[39m\"\u001b[39m \u001b[39m%\u001b[39m\n\u001b[0;32m 350\u001b[0m (data_string, \u001b[39mformat\u001b[39m))\n\u001b[0;32m 351\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mlen\u001b[39m(data_string) \u001b[39m!=\u001b[39m found\u001b[39m.\u001b[39mend():\n", "\u001b[1;31mValueError\u001b[0m: time data '20/01/31' does not match format '%Y%m%d'", "\nDuring handling of the above exception, another exception occurred:\n", "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[26], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m products \u001b[39m=\u001b[39m api\u001b[39m.\u001b[39;49mquery(footprint,\n\u001b[0;32m 2\u001b[0m date\u001b[39m=\u001b[39;49m(\u001b[39m'\u001b[39;49m\u001b[39m20/01/31\u001b[39;49m\u001b[39m'\u001b[39;49m, \u001b[39m'\u001b[39;49m\u001b[39m20/01/01\u001b[39;49m\u001b[39m'\u001b[39;49m),\n\u001b[0;32m 3\u001b[0m platformname\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39mSentinel-2\u001b[39;49m\u001b[39m'\u001b[39;49m,\n\u001b[0;32m 4\u001b[0m cloudcoverpercentage\u001b[39m=\u001b[39;49m(\u001b[39m0\u001b[39;49m, \u001b[39m10\u001b[39;49m))\n", "File \u001b[1;32mc:\\Users\\jtrum\\miniconda3\\envs\\wash_scan\\lib\\site-packages\\sentinelsat\\sentinel.py:261\u001b[0m, in \u001b[0;36mSentinelAPI.query\u001b[1;34m(self, area, date, raw, area_relation, order_by, limit, offset, **keywords)\u001b[0m\n\u001b[0;32m 184\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mquery\u001b[39m(\n\u001b[0;32m 185\u001b[0m \u001b[39mself\u001b[39m,\n\u001b[0;32m 186\u001b[0m area\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 193\u001b[0m \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkeywords\n\u001b[0;32m 194\u001b[0m ):\n\u001b[0;32m 195\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"Query the OpenSearch API with the coordinates of an area, a date interval\u001b[39;00m\n\u001b[0;32m 196\u001b[0m \u001b[39m and any other search keywords accepted by the API.\u001b[39;00m\n\u001b[0;32m 197\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 259\u001b[0m \u001b[39m the product's attributes (a dictionary) as the value.\u001b[39;00m\n\u001b[0;32m 260\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[1;32m--> 261\u001b[0m query \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mformat_query(area, date, raw, area_relation, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkeywords)\n\u001b[0;32m 263\u001b[0m \u001b[39mif\u001b[39;00m query\u001b[39m.\u001b[39mstrip() \u001b[39m==\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m\"\u001b[39m:\n\u001b[0;32m 264\u001b[0m \u001b[39m# An empty query should return the full set of products on the server, which is a bit unreasonable.\u001b[39;00m\n\u001b[0;32m 265\u001b[0m \u001b[39m# The server actually raises an error instead and it's better to fail early in the client.\u001b[39;00m\n\u001b[0;32m 266\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mEmpty query.\u001b[39m\u001b[39m\"\u001b[39m)\n", "File \u001b[1;32mc:\\Users\\jtrum\\miniconda3\\envs\\wash_scan\\lib\\site-packages\\sentinelsat\\sentinel.py:320\u001b[0m, in \u001b[0;36mSentinelAPI.format_query\u001b[1;34m(area, date, raw, area_relation, **keywords)\u001b[0m\n\u001b[0;32m 318\u001b[0m query_parts\u001b[39m.\u001b[39mappend(\u001b[39m\"\u001b[39m\u001b[39m(\u001b[39m\u001b[39m{}\u001b[39;00m\u001b[39m)\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m.\u001b[39mformat(\u001b[39m\"\u001b[39m\u001b[39m OR \u001b[39m\u001b[39m\"\u001b[39m\u001b[39m.\u001b[39mjoin(sub_parts)))\n\u001b[0;32m 319\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m--> 320\u001b[0m value \u001b[39m=\u001b[39m _format_query_value(attr, value)\n\u001b[0;32m 321\u001b[0m \u001b[39mif\u001b[39;00m value \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m 322\u001b[0m query_parts\u001b[39m.\u001b[39mappend(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m{\u001b[39;00mattr\u001b[39m}\u001b[39;00m\u001b[39m:\u001b[39m\u001b[39m{\u001b[39;00mvalue\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m)\n", "File \u001b[1;32mc:\\Users\\jtrum\\miniconda3\\envs\\wash_scan\\lib\\site-packages\\sentinelsat\\sentinel.py:1223\u001b[0m, in \u001b[0;36m_format_query_value\u001b[1;34m(attr, value)\u001b[0m\n\u001b[0;32m 1221\u001b[0m \u001b[39mpass\u001b[39;00m\n\u001b[0;32m 1222\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39misinstance\u001b[39m(value, (\u001b[39mlist\u001b[39m, \u001b[39mtuple\u001b[39m)) \u001b[39mand\u001b[39;00m \u001b[39mlen\u001b[39m(value) \u001b[39m==\u001b[39m \u001b[39m2\u001b[39m:\n\u001b[1;32m-> 1223\u001b[0m value \u001b[39m=\u001b[39m (format_query_date(value[\u001b[39m0\u001b[39;49m]), format_query_date(value[\u001b[39m1\u001b[39m]))\n\u001b[0;32m 1224\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m 1225\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[0;32m 1226\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mDate-type query parameter \u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00mattr\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m expects either a two-element tuple of \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 1227\u001b[0m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mstr or datetime objects or a \u001b[39m\u001b[39m'\u001b[39m\u001b[39m[ TO ]\u001b[39m\u001b[39m'\u001b[39m\u001b[39m-format string. Received \u001b[39m\u001b[39m{\u001b[39;00mvalue\u001b[39m}\u001b[39;00m\u001b[39m.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 1228\u001b[0m )\n", "File \u001b[1;32mc:\\Users\\jtrum\\miniconda3\\envs\\wash_scan\\lib\\site-packages\\sentinelsat\\sentinel.py:1301\u001b[0m, in \u001b[0;36mformat_query_date\u001b[1;34m(in_date)\u001b[0m\n\u001b[0;32m 1299\u001b[0m \u001b[39mreturn\u001b[39;00m datetime\u001b[39m.\u001b[39mstrptime(in_date, \u001b[39m\"\u001b[39m\u001b[39m%\u001b[39m\u001b[39mY\u001b[39m\u001b[39m%\u001b[39m\u001b[39mm\u001b[39m\u001b[39m%d\u001b[39;00m\u001b[39m\"\u001b[39m)\u001b[39m.\u001b[39mstrftime(\u001b[39m\"\u001b[39m\u001b[39m%\u001b[39m\u001b[39mY-\u001b[39m\u001b[39m%\u001b[39m\u001b[39mm-\u001b[39m\u001b[39m%d\u001b[39;00m\u001b[39mT\u001b[39m\u001b[39m%\u001b[39m\u001b[39mH:\u001b[39m\u001b[39m%\u001b[39m\u001b[39mM:\u001b[39m\u001b[39m%\u001b[39m\u001b[39mSZ\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m 1300\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mValueError\u001b[39;00m:\n\u001b[1;32m-> 1301\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mUnsupported date value \u001b[39m\u001b[39m{}\u001b[39;00m\u001b[39m\"\u001b[39m\u001b[39m.\u001b[39mformat(in_date))\n", "\u001b[1;31mValueError\u001b[0m: Unsupported date value 20/01/31" ] } ], "source": [ "products = api.query(footprint,\n", " date=('20/01/31', '20/01/01'),\n", " platformname='Sentinel-2',\n", " cloudcoverpercentage=(0, 10))" ] } ], "metadata": { "kernelspec": { "display_name": "wash_scan", "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.17" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }