From f0edfafe5fb999130514e6a196ee7c6007e5a750 Mon Sep 17 00:00:00 2001
From: Genevieve Metson <genevieve.metson@liu.se>
Date: Fri, 9 Jul 2021 08:51:47 +0000
Subject: [PATCH] Update future_land_use/export/excel.py

---
 future_land_use/export/excel.py | 55 +++++++++++++++++----------------
 1 file changed, 28 insertions(+), 27 deletions(-)

diff --git a/future_land_use/export/excel.py b/future_land_use/export/excel.py
index e5e9c3f..7cc4036 100644
--- a/future_land_use/export/excel.py
+++ b/future_land_use/export/excel.py
@@ -780,7 +780,7 @@ def _fill_nutrient_demand(
                 col_name = f"{col}_{elem}_need"
                 summed_need = gridded_crops[col_name].sum()
                 if col == "ley_pasture_pasture":
-                    nutrient_demand.loc[col, dest_col] += summed_need
+                    continue #nutrient_demand.loc[col, dest_col] += summed_need #commented out as it should not be in the total need as we assume don't use any nutrients
                 mapped_name = merge_categories.get(col, col)
                 if mapped_name not in nutrient_demand.index:
                     print(f"Couldn't find: {mapped_name}, skipping")
@@ -833,33 +833,34 @@ def _fill_nutrient_demand(
             nutrient_demand.loc["total", dest_col] = nutrient_demand.loc[
                 mapped_cols, dest_col
             ].sum()
-    current_per_crop_need = datasets.load(TotalPerRoosCropNPKNeeds, bounds=border)
-    for elem, needs in current_per_crop_need.items():
-        summed_needs = 0
-        mapped_names = set()
-        for crop_category, need in needs.items():
-            if crop_category not in ["ley_pasture_pasture", "semi_nat_pasture_no_cat"]:
-                print(f"category {crop_category} has a need of {need} kg {elem}")
+            # commenting out the section below because current NPK demand was actually not calculated this way in the paper so should not be used for comparison
+   # current_per_crop_need = datasets.load(TotalPerRoosCropNPKNeeds, bounds=border)
+   # for elem, needs in current_per_crop_need.items():
+   #     summed_needs = 0
+   #     mapped_names = set()
+   #     for crop_category, need in needs.items():
+   #         if crop_category not in ["ley_pasture_pasture", "semi_nat_pasture_no_cat"]:
+    #            print(f"category {crop_category} has a need of {need} kg {elem}")
             # We want this column on it's own besides the total contained in ley_pasture
-            if crop_category == "ley_pasture_pasture":
-                nutrient_demand.loc[crop_category, (elem, "current")] += need
-            mapped_name = merge_categories.get(crop_category, crop_category)
-            if mapped_name not in nutrient_demand.index:
-                print(
-                    f"Couldn't find: {mapped_name}, has a need of {need} kg of {elem}"
+   #         if crop_category == "ley_pasture_pasture":
+   #             nutrient_demand.loc[crop_category, (elem, "current")] += need
+   #         mapped_name = merge_categories.get(crop_category, crop_category)
+   #         if mapped_name not in nutrient_demand.index:
+   #             print(
+   #                 f"Couldn't find: {mapped_name}, has a need of {need} kg of {elem}"
                 )
-                continue
-            summed_needs += need
-            nutrient_demand.loc[mapped_name, (elem, "current")] += need
-            mapped_names.add(mapped_name)
-        print(f"For {elem} we used a need of {summed_needs} kg")
-        mapped_names = mapped_names - set(
-            ["ley_pasture_pasture", "semi_nat_pasture_no_cat"]
-        )
-        nutrient_demand.loc["total", (elem, "current")] = nutrient_demand.loc[
-            mapped_names, (elem, "current")
-        ].sum()
-        remove = current_exporter.gridded_crops[f"{elem.lower()}_overflow"].sum()
-        nutrient_demand.loc["total", (elem, "current")] -= remove
+   #             continue
+   #         summed_needs += need
+   #         nutrient_demand.loc[mapped_name, (elem, "current")] += need
+   #         mapped_names.add(mapped_name)
+   #     print(f"For {elem} we used a need of {summed_needs} kg")
+   #     mapped_names = mapped_names - set(
+   #         ["ley_pasture_pasture", "semi_nat_pasture_no_cat"]
+   #     )
+  #      nutrient_demand.loc["total", (elem, "current")] = nutrient_demand.loc[
+  #          mapped_names, (elem, "current")
+  #      ].sum()
+  #      remove = current_exporter.gridded_crops[f"{elem.lower()}_overflow"].sum()
+  #      nutrient_demand.loc["total", (elem, "current")] -= remove
 
     return nutrient_demand
-- 
GitLab