From cc96b383174a7be01e16522ec33448c862484e5e Mon Sep 17 00:00:00 2001
From: Danijel Schorlemmer <ds@gfz-potsdam.de>
Date: Fri, 16 Sep 2022 15:41:39 +0200
Subject: [PATCH] Switch to use taxonomy-lib

---
 exposureinitializer/exposureinitializer.py | 17 +++++++++--------
 setup.py                                   |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/exposureinitializer/exposureinitializer.py b/exposureinitializer/exposureinitializer.py
index 6b53190..a40f858 100644
--- a/exposureinitializer/exposureinitializer.py
+++ b/exposureinitializer/exposureinitializer.py
@@ -26,7 +26,7 @@ import glob
 import csv
 from databaselib.database import PostGISDatabase
 from exposurelib.database import SpatiaLiteExposure, PostGISExposure
-from exposurelib.utils import add_occupancy_to_taxonomy
+from taxonomylib import Taxonomy
 
 
 # Add a logger printing error, warning, info and debug messages to the screen
@@ -319,13 +319,14 @@ class ExposureInitializer:
                     last_boundary_id = row["BOUNDARY_ID"]
 
                 # Read in an asset
-                # Add the occupancy to the taxonomy string and store it in the database
-                taxonomy = add_occupancy_to_taxonomy(
-                    row["TAXONOMY"], str(row["OCCUPANCY"]).upper()
-                )
-                if not self.exposure_db.taxonomy_string_exists(taxonomy):
-                    self.exposure_db.insert_taxonomy(taxonomy)
-                taxonomy_id = self.exposure_db.get_taxonomy_id(taxonomy)
+                # Create the expanded taxonomy string and add the occupancy to it
+                taxonomy = Taxonomy(row["TAXONOMY"])
+                taxonomy.set_section("occupancy", row["OCCUPANCY"].upper())
+                taxonomy_string = taxonomy.get_expanded_string()
+                # Store the expanded taxonomy string in the database
+                if not self.exposure_db.taxonomy_string_exists(taxonomy_string):
+                    self.exposure_db.insert_taxonomy(taxonomy_string)
+                taxonomy_id = self.exposure_db.get_taxonomy_id(taxonomy_string)
                 asset = {
                     "number": float(row["BUILDINGS"]),
                     "structural": float(row["COST_STRUCTURAL_EUR"]),
diff --git a/setup.py b/setup.py
index 6680ef6..201f20c 100644
--- a/setup.py
+++ b/setup.py
@@ -31,6 +31,7 @@ setup(
     install_requires=[
         "numpy",
         "exposurelib@https://git.gfz-potsdam.de/dynamicexposure/globaldynamicexposure/exposure-lib/-/archive/master/exposure-lib-master.zip",  # noqa: E501
+        "taxonomylib@https://git.gfz-potsdam.de/dynamicexposure/globaldynamicexposure/taxonomy-lib/-/archive/main/taxonomy-lib-main.zip",  # noqa: E501
     ],
     extras_require={
         "tests": tests_require,
-- 
GitLab