@@ -42,17 +42,21 @@ class Ecoinvent7zImporter:
4242
4343 def __init__ (self , archive_path : str ) -> None :
4444 self .archive_path = archive_path
45+ self .is_compressed = archive_path .endswith ('.7z' )
4546
4647 def install_biosphere (self , biosphere_name : str = "biosphere3" ) -> None :
4748 """
4849 Installs the biosphere that is bundled in the ecoinvent .7z. Simple extraction and installing through the
4950 standard bw2io importer is quick enough because we're talking about a single file.
5051 """
51- # extract the elementary exchanges to a temporary location
52- with py7zr .SevenZipFile (self .archive_path , mode = 'r' ) as archive :
53- temp = tempfile .gettempdir ()
54- archive .extract (temp , ["MasterData/ElementaryExchanges.xml" ])
55- bio_file = os .path .join (temp , "MasterData/ElementaryExchanges.xml" )
52+ if self .is_compressed :
53+ # extract the elementary exchanges to a temporary location
54+ with py7zr .SevenZipFile (self .archive_path , mode = 'r' ) as archive :
55+ temp = tempfile .gettempdir ()
56+ archive .extract (temp , ["MasterData/ElementaryExchanges.xml" ])
57+ bio_file = os .path .join (temp , "MasterData" , "ElementaryExchanges.xml" )
58+ else :
59+ bio_file = os .path .join (self .archive_path , "MasterData" , "ElementaryExchanges.xml" )
5660
5761 # initiate the importer with the elementary exchanges file
5862 importer = Ecospold2BiosphereImporter (biosphere_name , None , bio_file )
@@ -71,11 +75,16 @@ def install_ecoinvent(self, db_name, biosphere_name: str = "biosphere3"):
7175 log .warning (f"Database already exists, overwriting { db_name } " )
7276 bd .Database (db_name ).delete (warn = False )
7377
74- # load the spold files into memory
75- spold_bytes = self .read_archive_to_bytes ()
78+ if self .is_compressed :
79+ # load the spold files into memory
80+ spold_bytes = self .read_archive_to_bytes ()
81+
82+ # process the in-memory data to a dict format and applying strategies
83+ db_data = self .process_bytes (spold_bytes , db_name )
84+ else :
85+ # if the archive is not compressed, we can use the standard importer
86+ db_data = Ecospold2DataExtractor .extract (os .path .join (self .archive_path , "datasets" ), db_name )
7687
77- # process the in-memory data to a dict format and applying strategies
78- db_data = self .process_bytes (spold_bytes , db_name )
7988 db_data = self .apply_strategies (db_data , biosphere_name )
8089
8190 # rewrite into an ingestible format
0 commit comments