Skip to content

Commit

Permalink
Allows writing untransformed databases
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Jul 28, 2024
1 parent 81a3c7f commit 80009c7
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions premise/new_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,13 @@ def write_superstructure_db_to_brightway(
)

for scenario in self.scenarios:
scenario = load_database(scenario)
try:
scenario = load_database(scenario)
except KeyError:
scenario["database"] = pickle.loads(pickle.dumps(self.database, -1))
except FileNotFoundError:
scenario["database"] = pickle.loads(pickle.dumps(self.database, -1))

_prepare_database(
scenario=scenario,
db_name=name,
Expand Down Expand Up @@ -1066,7 +1072,13 @@ def write_db_to_brightway(self, name: [str, List[str]] = None):
print("Write new database(s) to Brightway.")

for s, scenario in enumerate(self.scenarios):
scenario = load_database(scenario)
try:
scenario = load_database(scenario)
except KeyError:
scenario["database"] = pickle.loads(pickle.dumps(self.database, -1))
except FileNotFoundError:
scenario["database"] = pickle.loads(pickle.dumps(self.database, -1))

_prepare_database(
scenario=scenario,
db_name=name[s],
Expand Down Expand Up @@ -1135,7 +1147,13 @@ def scenario_name(scenario):
print("Write new database(s) to matrix.")

for s, scenario in enumerate(self.scenarios):
scenario = load_database(scenario)
try:
scenario = load_database(scenario)
except KeyError:
scenario["database"] = pickle.loads(pickle.dumps(self.database, -1))
except FileNotFoundError:
scenario["database"] = pickle.loads(pickle.dumps(self.database, -1))

_prepare_database(
scenario=scenario,
db_name="database",
Expand Down Expand Up @@ -1170,7 +1188,13 @@ def write_db_to_simapro(self, filepath: str = None):
print("Write Simapro import file(s).")

for scenario in self.scenarios:
scenario = load_database(scenario)
try:
scenario = load_database(scenario)
except KeyError:
scenario["database"] = pickle.loads(pickle.dumps(self.database, -1))
except FileNotFoundError:
scenario["database"] = pickle.loads(pickle.dumps(self.database, -1))

_prepare_database(
scenario=scenario,
db_name="database",
Expand Down Expand Up @@ -1211,7 +1235,13 @@ def write_db_to_olca(self, filepath: str = None):
print("Write Simapro import file(s) for OpenLCA.")

for scenario in self.scenarios:
scenario = load_database(scenario)
try:
scenario = load_database(scenario)
except KeyError:
scenario["database"] = pickle.loads(pickle.dumps(self.database, -1))
except FileNotFoundError:
scenario["database"] = pickle.loads(pickle.dumps(self.database, -1))

_prepare_database(
scenario=scenario,
db_name="database",
Expand Down Expand Up @@ -1246,7 +1276,13 @@ def write_datapackage(
raise ValueError(f"No cached inventories found at {cache_fp}.")

for scenario in self.scenarios:
scenario = load_database(scenario)
try:
scenario = load_database(scenario)
except KeyError:
scenario["database"] = pickle.loads(pickle.dumps(self.database, -1))
except FileNotFoundError:
scenario["database"] = pickle.loads(pickle.dumps(self.database, -1))

_prepare_database(
scenario=scenario,
db_name=name,
Expand Down

0 comments on commit 80009c7

Please sign in to comment.