Skip to content

Commit

Permalink
Fix export to Simapro.
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Aug 18, 2023
1 parent 02d151f commit b344c4e
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 10 deletions.
Binary file modified premise/data/additional_inventories/lci-buses.xlsx
Binary file not shown.
Binary file modified premise/data/additional_inventories/lci-carbon-fiber.xlsx
Binary file not shown.
Binary file modified premise/data/additional_inventories/lci-hydrogen-distribution.xlsx
Binary file not shown.
Binary file modified premise/data/additional_inventories/lci-pass_cars.xlsx
Binary file not shown.
Binary file modified premise/data/additional_inventories/lci-trucks.xlsx
Binary file not shown.
19 changes: 12 additions & 7 deletions premise/ecoinvent_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ def _update_all(
def _export_to_matrices(obj):
obj.export_db_to_matrices()

def _export_to_simapro(obj):
obj.export_db_to_simapro()


class NewDatabase:
"""
Expand Down Expand Up @@ -616,8 +619,8 @@ def __find_cached_db(self, db_name: str, keep_uncertainty_data: bool) -> List[di
# check that directory exists, otherwise create it
Path(DIR_CACHED_DB).mkdir(parents=True, exist_ok=True)
# build file path
if db_name is None:
db_name = "unnamed"
if db_name is None and self.source_type == "ecospold":
db_name = f"ecospold_{self.system_model}_{self.version}"

file_name = Path(
DIR_CACHED_DB
Expand Down Expand Up @@ -646,8 +649,8 @@ def __find_cached_inventories(self, db_name: str) -> Union[None, List[dict]]:
# check that directory exists, otherwise create it
Path(DIR_CACHED_DB).mkdir(parents=True, exist_ok=True)
# build file path
if db_name is None:
db_name = "unnamed"
if db_name is None and self.source_type == "ecospold":
db_name = f"ecospold_{self.system_model}_{self.version}"

file_name = Path(
DIR_CACHED_DB
Expand Down Expand Up @@ -1398,11 +1401,12 @@ def write_db_to_simapro(self, filepath: str = None):
self.scenarios[s] = results[s][0]
cache.update(results[s][1])

with ProcessPool(processes=multiprocessing.cpu_count()) as pool:
args = [
(scenario, filepath[scen], self.version)
Export(scenario, filepath, self.version)
for scen, scenario in enumerate(self.scenarios)
]
pool.starmap(Export().export_db_to_simapro, args)
pool.map(_export_to_simapro, args)

# generate scenario report
self.generate_scenario_report()
Expand Down Expand Up @@ -1444,7 +1448,8 @@ def write_datapackage(self, name: str = f"datapackage_{date.today()}"):

cached_inventories.extend(extra_inventories)
list_scenarios = ["original"] + [
f"{s['model']} - {s['pathway']} - {s['year']}" for s in self.scenarios
f"{s['model']} - {s['pathway']} - {s['year']}"
for s in self.scenarios
]

build_datapackage(
Expand Down
2 changes: 1 addition & 1 deletion premise/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ class Export:
def __init__(
self,
scenario: dict = None,
filepath: Union[list[Path], list[Union[Path, Any]]] = None,
filepath: Path = None,
version: str = None,
):
self.db = scenario["database"]
Expand Down
3 changes: 1 addition & 2 deletions premise/fuels.py
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,7 @@ def fetch_fuel_share(
)

if np.isnan(fuel_share):
print(f"Incorrect fuel share for {fuel} in {region}.")
print(f"Warning: incorrect fuel share for {fuel} in {region} (-> set to 0%).")
fuel_share = 0

return float(fuel_share)
Expand Down Expand Up @@ -2202,7 +2202,6 @@ def generate_regional_fuel_market(
.sum(dim=["variables"])
== 0
):
print("No fuel market for", dataset["name"], "in", region)

if "hydrogen" in dataset["name"].lower():
prod_vars = [
Expand Down

0 comments on commit b344c4e

Please sign in to comment.