From 4735bd407e0af490e6d799a575b5f9127ec72f17 Mon Sep 17 00:00:00 2001 From: Camilo Ramirez Gomez Date: Mon, 4 Nov 2019 11:25:45 +0100 Subject: [PATCH] added code to be able to set cropland share in several areas at once --- nexus_tool/water_demand.py | 2 +- water_demand_runner.ipynb | 265 +++++++++++++++++-------------------- 2 files changed, 121 insertions(+), 146 deletions(-) diff --git a/nexus_tool/water_demand.py b/nexus_tool/water_demand.py index d87582c..72284b2 100644 --- a/nexus_tool/water_demand.py +++ b/nexus_tool/water_demand.py @@ -51,7 +51,7 @@ def set_cropland_share(df, crop_var, geo_boundary = 'global', if crop_share not in df.columns: df[crop_share] = [{}]*df.shape[0] - df.loc[df[geo_boundary]==boundary_name, crop_share] = [crop_var] + df.loc[df[geo_boundary].isin(boundary_name), crop_share] = [crop_var] else: print('Please provide a geo_boundary (e.g. "Province") and a boundary_name (e.g. "Name of province")') return df diff --git a/water_demand_runner.ipynb b/water_demand_runner.ipynb index a6437d6..e85f603 100644 --- a/water_demand_runner.ipynb +++ b/water_demand_runner.ipynb @@ -12,25 +12,16 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 17, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The autoreload extension is already loaded. To reload it, use:\n", - " %reload_ext autoreload\n" - ] - } - ], + "outputs": [], "source": [ "%load_ext autoreload" ] }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -47,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -73,7 +64,7 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -91,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ @@ -112,7 +103,7 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -168,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ @@ -177,10 +168,10 @@ "\n", "nwsas.set_cropland_share({'dates':0.7,'vegetable':0.3,'olives':0}, \n", " geo_boundary = 'province', \n", - " boundary_name = 'Jufrah', inplace = True)\n", + " boundary_name = ['Jufrah'], inplace = True)\n", "nwsas.set_cropland_share({'dates':0,'vegetable':0.3,'olives':0.7}, \n", " geo_boundary = 'province', \n", - " boundary_name = 'Gharyan', inplace = True)" + " boundary_name = ['Gharyan'], inplace = True)" ] }, { @@ -209,7 +200,7 @@ }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ @@ -229,7 +220,7 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ @@ -248,7 +239,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 42, "metadata": {}, "outputs": [], "source": [ @@ -265,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 43, "metadata": {}, "outputs": [], "source": [ @@ -283,7 +274,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 44, "metadata": {}, "outputs": [], "source": [ @@ -300,7 +291,7 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 48, "metadata": {}, "outputs": [ { @@ -324,210 +315,194 @@ " \n", " \n", " \n", + " \n", " Irrigated area (ha)\n", - " Water intensity (m3/ha)\n", " Water demand (Mm3)\n", - " Total demand (GWh)\n", + " Water intensity (m3/ha)\n", " \n", " \n", + " country\n", " province\n", " \n", " \n", " \n", - " \n", " \n", " \n", " \n", " \n", + " Algeria\n", " Adrar\n", " 24101.816848\n", - " 15793.791148\n", " 380.659062\n", - " 0.0\n", + " 15793.791148\n", " \n", " \n", " Biskra\n", " 5749.995666\n", - " 10033.720376\n", " 57.693849\n", - " 0.0\n", + " 10033.720376\n", " \n", " \n", " Djelfa\n", " 3449.972096\n", - " 10303.348469\n", " 35.546265\n", - " 0.0\n", + " 10303.348469\n", " \n", " \n", " El Oued\n", " 68999.985344\n", - " 11470.236142\n", " 791.446126\n", - " 0.0\n", - " \n", - " \n", - " Gabes\n", - " 2874.983928\n", - " 10074.150089\n", - " 28.963020\n", - " 0.0\n", - " \n", - " \n", - " Ghadamis\n", - " 5353.213079\n", - " 10515.471347\n", - " 56.291559\n", - " 0.0\n", + " 11470.236142\n", " \n", " \n", " Ghardaia\n", " 34499.998422\n", - " 12775.158413\n", " 440.742945\n", - " 0.0\n", - " \n", - " \n", - " Gharyan\n", - " 8557.616421\n", - " 10818.727280\n", - " 92.582518\n", - " 0.0\n", + " 12775.158413\n", " \n", " \n", " Illizi\n", " 1770.396215\n", - " 14169.601170\n", " 25.085808\n", - " 0.0\n", - " \n", - " \n", - " Jufrah\n", - " 7963.713904\n", - " 15113.240202\n", - " 120.357521\n", - " 0.0\n", - " \n", - " \n", - " Kebili\n", - " 27412.511949\n", - " 11207.277369\n", - " 307.219625\n", - " 0.0\n", + " 14169.601170\n", " \n", " \n", " Khenchela\n", " 1149.970213\n", - " 10830.580811\n", " 12.454845\n", - " 0.0\n", + " 10830.580811\n", " \n", " \n", " Laghouat\n", " 5749.994721\n", - " 10084.528374\n", " 57.985985\n", - " 0.0\n", - " \n", - " \n", - " Musrata\n", - " 21082.919486\n", - " 8890.634530\n", - " 187.440532\n", - " 0.0\n", + " 10084.528374\n", " \n", " \n", " Ouargla\n", " 32699.346634\n", - " 12379.121096\n", " 404.789172\n", - " 0.0\n", + " 12379.121096\n", " \n", " \n", " Tamanrasset\n", " 4868.857546\n", - " 15656.343103\n", " 76.228504\n", - " 0.0\n", - " \n", - " \n", - " Tataouine\n", - " 1833.775565\n", - " 10215.633880\n", - " 18.733180\n", - " 0.0\n", + " 15656.343103\n", " \n", " \n", " Tebessa\n", " 4599.970966\n", - " 10927.332730\n", " 50.265413\n", - " 0.0\n", + " 10927.332730\n", + " \n", + " \n", + " Libya\n", + " Ghadamis\n", + " 5353.213079\n", + " 56.291559\n", + " 10515.471347\n", + " \n", + " \n", + " Gharyan\n", + " 8557.616421\n", + " 92.582518\n", + " 10818.727280\n", + " \n", + " \n", + " Jufrah\n", + " 7963.713904\n", + " 120.357521\n", + " 15113.240202\n", + " \n", + " \n", + " Musrata\n", + " 21082.919486\n", + " 187.440532\n", + " 8890.634530\n", + " \n", + " \n", + " Tunisia\n", + " Gabes\n", + " 2874.983928\n", + " 28.963020\n", + " 10074.150089\n", + " \n", + " \n", + " Kebili\n", + " 27412.511949\n", + " 307.219625\n", + " 11207.277369\n", + " \n", + " \n", + " Tataouine\n", + " 1833.775565\n", + " 18.733180\n", + " 10215.633880\n", " \n", " \n", " Tozeur\n", " 9617.446033\n", - " 10794.142744\n", " 103.812085\n", - " 0.0\n", + " 10794.142744\n", " \n", " \n", "\n", "" ], "text/plain": [ - " Irrigated area (ha) Water intensity (m3/ha) Water demand (Mm3) \\\n", - "province \n", - "Adrar 24101.816848 15793.791148 380.659062 \n", - "Biskra 5749.995666 10033.720376 57.693849 \n", - "Djelfa 3449.972096 10303.348469 35.546265 \n", - "El Oued 68999.985344 11470.236142 791.446126 \n", - "Gabes 2874.983928 10074.150089 28.963020 \n", - "Ghadamis 5353.213079 10515.471347 56.291559 \n", - "Ghardaia 34499.998422 12775.158413 440.742945 \n", - "Gharyan 8557.616421 10818.727280 92.582518 \n", - "Illizi 1770.396215 14169.601170 25.085808 \n", - "Jufrah 7963.713904 15113.240202 120.357521 \n", - "Kebili 27412.511949 11207.277369 307.219625 \n", - "Khenchela 1149.970213 10830.580811 12.454845 \n", - "Laghouat 5749.994721 10084.528374 57.985985 \n", - "Musrata 21082.919486 8890.634530 187.440532 \n", - "Ouargla 32699.346634 12379.121096 404.789172 \n", - "Tamanrasset 4868.857546 15656.343103 76.228504 \n", - "Tataouine 1833.775565 10215.633880 18.733180 \n", - "Tebessa 4599.970966 10927.332730 50.265413 \n", - "Tozeur 9617.446033 10794.142744 103.812085 \n", + " Irrigated area (ha) Water demand (Mm3) \\\n", + "country province \n", + "Algeria Adrar 24101.816848 380.659062 \n", + " Biskra 5749.995666 57.693849 \n", + " Djelfa 3449.972096 35.546265 \n", + " El Oued 68999.985344 791.446126 \n", + " Ghardaia 34499.998422 440.742945 \n", + " Illizi 1770.396215 25.085808 \n", + " Khenchela 1149.970213 12.454845 \n", + " Laghouat 5749.994721 57.985985 \n", + " Ouargla 32699.346634 404.789172 \n", + " Tamanrasset 4868.857546 76.228504 \n", + " Tebessa 4599.970966 50.265413 \n", + "Libya Ghadamis 5353.213079 56.291559 \n", + " Gharyan 8557.616421 92.582518 \n", + " Jufrah 7963.713904 120.357521 \n", + " Musrata 21082.919486 187.440532 \n", + "Tunisia Gabes 2874.983928 28.963020 \n", + " Kebili 27412.511949 307.219625 \n", + " Tataouine 1833.775565 18.733180 \n", + " Tozeur 9617.446033 103.812085 \n", "\n", - " Total demand (GWh) \n", - "province \n", - "Adrar 0.0 \n", - "Biskra 0.0 \n", - "Djelfa 0.0 \n", - "El Oued 0.0 \n", - "Gabes 0.0 \n", - "Ghadamis 0.0 \n", - "Ghardaia 0.0 \n", - "Gharyan 0.0 \n", - "Illizi 0.0 \n", - "Jufrah 0.0 \n", - "Kebili 0.0 \n", - "Khenchela 0.0 \n", - "Laghouat 0.0 \n", - "Musrata 0.0 \n", - "Ouargla 0.0 \n", - "Tamanrasset 0.0 \n", - "Tataouine 0.0 \n", - "Tebessa 0.0 \n", - "Tozeur 0.0 " + " Water intensity (m3/ha) \n", + "country province \n", + "Algeria Adrar 15793.791148 \n", + " Biskra 10033.720376 \n", + " Djelfa 10303.348469 \n", + " El Oued 11470.236142 \n", + " Ghardaia 12775.158413 \n", + " Illizi 14169.601170 \n", + " Khenchela 10830.580811 \n", + " Laghouat 10084.528374 \n", + " Ouargla 12379.121096 \n", + " Tamanrasset 15656.343103 \n", + " Tebessa 10927.332730 \n", + "Libya Ghadamis 10515.471347 \n", + " Gharyan 10818.727280 \n", + " Jufrah 15113.240202 \n", + " Musrata 8890.634530 \n", + "Tunisia Gabes 10074.150089 \n", + " Kebili 11207.277369 \n", + " Tataouine 10215.633880 \n", + " Tozeur 10794.142744 " ] }, - "execution_count": 92, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "nwsas.print_summary(geo_boundary = 'province')" + "nwsas.print_summary(geo_boundary = ['country','province'])" ] }, {