Skip to content

Commit

Permalink
Black reformating
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Jul 29, 2023
1 parent 5e3cec9 commit 6b2251f
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 101 deletions.
14 changes: 7 additions & 7 deletions premise/cement.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

import yaml

from .logger import create_logger
from .transformation import BaseTransformation, Dict, IAMDataCollection, List, np, ws
from .utils import DATA_DIR
from .logger import create_logger

logger = create_logger("cement")

Expand Down Expand Up @@ -464,9 +464,9 @@ def add_datasets_to_database(self) -> None:
:return: Does not return anything. Modifies in place.
"""

#print("Start integration of cement data...")
# print("Start integration of cement data...")

#print("Create new clinker production datasets and delete old datasets")
# print("Create new clinker production datasets and delete old datasets")

clinker_prod_datasets = list(self.build_clinker_production_datasets().values())
self.database.extend(clinker_prod_datasets)
Expand All @@ -486,7 +486,7 @@ def add_datasets_to_database(self) -> None:
)
)

#print("Create new clinker market datasets and delete old datasets")
# print("Create new clinker market datasets and delete old datasets")
clinker_market_datasets = list(
self.fetch_proxies(
name="market for clinker",
Expand All @@ -512,7 +512,7 @@ def add_datasets_to_database(self) -> None:
)
)

#print("Create new cement market datasets")
# print("Create new cement market datasets")

# cement markets
markets = ws.get_many(
Expand Down Expand Up @@ -553,10 +553,10 @@ def add_datasets_to_database(self) -> None:

self.database.extend(new_datasets)

#print(
# print(
# "Create new cement production datasets and "
# "adjust electricity consumption"
#)
# )
# cement production
production = ws.get_many(
self.database,
Expand Down
5 changes: 3 additions & 2 deletions premise/direct_air_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import wurst
import yaml

from .utils import DATA_DIR
from .logger import create_logger
from .utils import DATA_DIR

logger = create_logger("dac")

Expand Down Expand Up @@ -58,6 +58,7 @@ def _update_dac(scenario, version, system_model, modified_datasets):

return scenario, modified_datasets


class DirectAirCapture(BaseTransformation):
"""
Class that modifies DAC and DACCS inventories and markets
Expand Down Expand Up @@ -105,7 +106,7 @@ def generate_dac_activities(self) -> None:
modifies the original datasets to include the heat source, and adds the modified datasets to the database.
"""
#print("Generate region-specific direct air capture processes.")
# print("Generate region-specific direct air capture processes.")

# get original dataset
for ds_list in self.carbon_storage.values():
Expand Down
58 changes: 40 additions & 18 deletions premise/ecoinvent_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

import copy
import multiprocessing
from multiprocessing.pool import ThreadPool as Pool
from multiprocessing import Pool as ProcessPool
import os
import pickle
import sys
from datetime import date
from multiprocessing import Pool as ProcessPool
from multiprocessing.pool import ThreadPool as Pool
from pathlib import Path
from typing import List, Union

Expand All @@ -27,10 +27,10 @@
from .emissions import _update_emissions
from .export import (
Export,
_prepare_database,
build_datapackage,
generate_scenario_factor_file,
generate_superstructure_db,
_prepare_database,
)
from .external import ExternalScenario
from .external_data_validation import check_external_scenarios, check_inventories
Expand Down Expand Up @@ -400,17 +400,41 @@ def check_time_horizon(time_horizon: int) -> int:

return int(time_horizon)

def _update_all(scenario, version, system_model, modified_datasets, use_absolute_efficiency, vehicle_type, gains_scenario):
scenario, modified_datasets = _update_vehicles(scenario, vehicle_type, version, system_model, modified_datasets)
scenario, modified_datasets = _update_electricity(scenario, version, system_model, modified_datasets, use_absolute_efficiency)
scenario, modified_datasets = _update_dac(scenario, version, system_model, modified_datasets)
scenario, modified_datasets = _update_cement(scenario, version, system_model, modified_datasets)
scenario, modified_datasets = _update_steel(scenario, version, system_model, modified_datasets)
scenario, modified_datasets = _update_fuels(scenario, version, system_model, modified_datasets)
scenario, modified_datasets = _update_emissions(scenario, version, system_model, gains_scenario, modified_datasets)

def _update_all(
scenario,
version,
system_model,
modified_datasets,
use_absolute_efficiency,
vehicle_type,
gains_scenario,
):
scenario, modified_datasets = _update_vehicles(
scenario, vehicle_type, version, system_model, modified_datasets
)
scenario, modified_datasets = _update_electricity(
scenario, version, system_model, modified_datasets, use_absolute_efficiency
)
scenario, modified_datasets = _update_dac(
scenario, version, system_model, modified_datasets
)
scenario, modified_datasets = _update_cement(
scenario, version, system_model, modified_datasets
)
scenario, modified_datasets = _update_steel(
scenario, version, system_model, modified_datasets
)
scenario, modified_datasets = _update_fuels(
scenario, version, system_model, modified_datasets
)
scenario, modified_datasets = _update_emissions(
scenario, version, system_model, gains_scenario, modified_datasets
)

return scenario, modified_datasets


class NewDatabase:
"""
Class that represents a new wurst inventory database, modified according to IAM data.
Expand Down Expand Up @@ -504,7 +528,7 @@ def __init__(
self.database = self.__find_cached_db(
source_db, keep_uncertainty_data=keep_uncertainty_data
)
#print("Done!")
# print("Done!")
else:
self.database = self.__clean_database(
keep_uncertainty_data=keep_uncertainty_data
Expand All @@ -523,7 +547,7 @@ def __init__(
data = self.__import_additional_inventories(self.additional_inventories)
self.database.extend(data)

#print("Done!")
# print("Done!")

print("\n/////////////////////// EXTRACTING IAM DATA ////////////////////////")

Expand Down Expand Up @@ -551,7 +575,7 @@ def _fetch_iam_data(scenario):
with Pool(processes=multiprocessing.cpu_count()) as pool:
pool.map(_fetch_iam_data, self.scenarios)

#print("Done!")
# print("Done!")

def __find_cached_db(self, db_name: str, keep_uncertainty_data: bool) -> List[dict]:
"""
Expand Down Expand Up @@ -710,7 +734,7 @@ def __import_inventories(self, keep_uncertainty_data: bool = False) -> List[dict

self.database.extend(datasets)

#print("Done!\n")
# print("Done!\n")
return data

def __import_additional_inventories(
Expand Down Expand Up @@ -809,7 +833,6 @@ def update_dac(self) -> None:
self.scenarios[s] = results[s][0]
self.modified_datasets.update(results[s][1])


def update_fuels(self) -> None:
"""
This method will update the fuels inventories
Expand Down Expand Up @@ -1362,8 +1385,7 @@ 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
33 changes: 18 additions & 15 deletions premise/electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from . import VARIABLES_DIR
from .data_collection import get_delimiter
from .export import biosphere_flows_dictionary
from .logger import create_logger
from .transformation import (
BaseTransformation,
Dict,
Expand All @@ -34,7 +35,6 @@
ws,
)
from .utils import DATA_DIR, eidb_label, get_efficiency_solar_photovoltaics
from .logger import create_logger

LOSS_PER_COUNTRY = DATA_DIR / "electricity" / "losses_per_country.csv"
IAM_BIOMASS_VARS = VARIABLES_DIR / "biomass_variables.yaml"
Expand Down Expand Up @@ -162,7 +162,9 @@ def get_production_weighted_losses(
return {"high": high, "medium": medium, "low": low}


def _update_electricity(scenario, version, system_model, modified_datasets, use_absolute_efficiency):
def _update_electricity(
scenario, version, system_model, modified_datasets, use_absolute_efficiency
):
electricity = Electricity(
database=scenario["database"],
iam_data=scenario["iam data"],
Expand Down Expand Up @@ -204,6 +206,7 @@ def _update_electricity(scenario, version, system_model, modified_datasets, use_

return scenario, modified_datasets


class Electricity(BaseTransformation):
"""
Class that modifies electricity markets in the database based on IAM output data.
Expand Down Expand Up @@ -1224,7 +1227,7 @@ def update_efficiency_of_solar_pv(self) -> None:
:return:
"""

#print("Update efficiency of solar PV panels.")
# print("Update efficiency of solar PV panels.")

# TODO: check if IAM data provides efficiencies for PV panels and use them instead

Expand Down Expand Up @@ -1313,7 +1316,7 @@ def update_ng_production_ds(self) -> None:
to high pressure natural gas markets.
"""

#print("Update natural gas extraction datasets.")
# print("Update natural gas extraction datasets.")

countries = ["NL", "DE", "FR", "RER", "IT", "CH"]

Expand Down Expand Up @@ -1397,7 +1400,7 @@ def update_ng_production_ds(self) -> None:
)

def create_biomass_markets(self) -> None:
#print("Create biomass markets.")
# print("Create biomass markets.")

with open(IAM_BIOMASS_VARS, "r", encoding="utf-8") as stream:
biomass_map = yaml.safe_load(stream)
Expand Down Expand Up @@ -1585,7 +1588,7 @@ def create_biomass_markets(self) -> None:
)

# replace biomass inputs
#print("Replace biomass inputs.")
# print("Replace biomass inputs.")
for dataset in ws.get_many(
self.database,
ws.either(
Expand Down Expand Up @@ -1620,7 +1623,7 @@ def create_region_specific_power_plants(self):
"""

#print("Create region-specific power plants.")
# print("Create region-specific power plants.")
all_plants = []

techs = [
Expand Down Expand Up @@ -1742,7 +1745,7 @@ def update_electricity_efficiency(self) -> None:
:rtype: list
"""

#print("Adjust efficiency of power plants...")
# print("Adjust efficiency of power plants...")

mapping = InventorySet(self.database)
self.fuel_map = mapping.generate_fuel_map()
Expand All @@ -1764,7 +1767,7 @@ def update_electricity_efficiency(self) -> None:

for technology in technologies_map:
dict_technology = technologies_map[technology]
#print("Rescale inventories and emissions for", technology)
# print("Rescale inventories and emissions for", technology)

for dataset in ws.get_many(
self.database,
Expand Down Expand Up @@ -1868,7 +1871,7 @@ def adjust_coal_power_plant_emissions(self) -> None:
including coal-fired CHPs.
"""

#print("Adjust efficiency and emissions of coal power plants...")
# print("Adjust efficiency and emissions of coal power plants...")

coal_techs = [
"Coal PC",
Expand Down Expand Up @@ -2041,7 +2044,7 @@ def update_electricity_markets(self) -> None:
]

# We first need to empty 'market for electricity' and 'market group for electricity' datasets
#print("Empty old electricity datasets")
# print("Empty old electricity datasets")

datasets_to_empty = ws.get_many(
self.database,
Expand Down Expand Up @@ -2108,14 +2111,14 @@ def update_electricity_markets(self) -> None:
)

# We then need to create high voltage IAM electricity markets
#print("Create high voltage markets.")
# print("Create high voltage markets.")
self.create_new_markets_high_voltage()
#print("Create medium voltage markets.")
# print("Create medium voltage markets.")
self.create_new_markets_medium_voltage()
#print("Create low voltage markets.")
# print("Create low voltage markets.")
self.create_new_markets_low_voltage()

#print("Done!")
# print("Done!")

def write_log(self, dataset, status="created"):
"""
Expand Down
Loading

0 comments on commit 6b2251f

Please sign in to comment.