Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pathways' into pathways
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarojhahn committed Jul 25, 2024
2 parents fa295e1 + a48b37c commit 40cd418
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 0 deletions.
1 change: 1 addition & 0 deletions premise/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def adjust_battery_mass(self) -> None:

for exc in ws.technosphere(ds, ws.equals("unit", "kilogram")):
exc["amount"] *= scaling_factor
exc["loc"] *= scaling_factor
exc["minimum"] *= scaling_factor_min
exc["maximum"] *= scaling_factor_max

Expand Down
13 changes: 13 additions & 0 deletions premise/data/utils/logging/logconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ handlers:
formatter: simple
mode: a

file_wind_turbine:
class: logging.FileHandler
level: INFO
filename: "export/logs/premise_wind_turbine.log"
encoding: utf8
formatter: simple
mode: a

file_emissions:
class: logging.FileHandler
level: INFO
Expand Down Expand Up @@ -145,6 +153,11 @@ loggers:
handlers: [ file_battery ]
propagate: False

wind_turbine:
level: INFO
handlers: [ file_wind_turbine ]
propagate: False

heat:
level: INFO
handlers: [ file_heat ]
Expand Down
32 changes: 32 additions & 0 deletions premise/data/utils/logging/reporting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,38 @@ premise_battery:
unit: 0-1
tab: Battery

premise_wind_turbine:
columns:
timestamp:
name: timestamp
description: Timestamp of the log entry
module:
name: module
description: Module name
level:
name: level
description: Log level
status:
name: status
description: Status of the dataset
model:
name: model
description: IAM model name
pathway:
name: pathway
description: Pathway name
year:
name: year
description: Year
dataset:
name: dataset
description: Dataset name
region:
name: region
description: Region name
tab: Wind Turbine


premise_emissions:
columns:
timestamp:
Expand Down
5 changes: 5 additions & 0 deletions premise/new_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
print_version,
warning_about_biogenic_co2,
)
from .wind_turbines import _update_wind_turbines

logger = logging.getLogger("module")

Expand Down Expand Up @@ -870,6 +871,10 @@ def update(self, sectors: [str, list, None] = None) -> None:
},
"steel": {"func": _update_steel, "args": (self.version, self.system_model)},
"fuels": {"func": _update_fuels, "args": (self.version, self.system_model)},
"wind": {
"func": _update_wind_turbines,
"args": (self.version, self.system_model),
},
"metals": {
"func": _update_metals,
"args": (self.version, self.system_model),
Expand Down
1 change: 1 addition & 0 deletions premise/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def generate_change_report(source, version, source_type, system_model):
"premise_fuel",
"premise_heat",
"premise_battery",
"premise_wind_turbine",
"premise_transport",
"premise_steel",
"premise_metal",
Expand Down
117 changes: 117 additions & 0 deletions premise/wind_turbines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
"""
module to create a variant of the onshore and offshore wind
turbine datasets to represent the direct-drive technology.
"""

import copy
import uuid

from .activity_maps import InventorySet
from .logger import create_logger
from .transformation import BaseTransformation, IAMDataCollection, List, np, ws

logger = create_logger("wind_turbine")


def _update_wind_turbines(scenario, version, system_model):
wind_turbine = WindTurbine(
database=scenario["database"],
iam_data=scenario["iam data"],
model=scenario["model"],
pathway=scenario["pathway"],
year=scenario["year"],
version=version,
system_model=system_model,
cache=scenario.get("cache"),
index=scenario.get("index"),
)

wind_turbine.create_direct_drive_turbines()

scenario["database"] = wind_turbine.database
scenario["index"] = wind_turbine.index
scenario["cache"] = wind_turbine.cache

return scenario


class WindTurbine(BaseTransformation):
"""
Class that create additional wind turbine datasets
to represent the direct-drive technology.
"""

def __init__(
self,
database: List[dict],
iam_data: IAMDataCollection,
model: str,
pathway: str,
year: int,
version: str,
system_model: str,
cache: dict = None,
index: dict = None,
) -> None:
super().__init__(
database,
iam_data,
model,
pathway,
year,
version,
system_model,
cache,
index,
)
self.system_model = system_model
mapping = InventorySet(database=database, version=version, model=model)
self.powerplant_map = mapping.generate_powerplant_map()

def create_direct_drive_turbines(self):
"""
Create direct-drive wind turbine datasets.
"""

wind_turbine_technologies = ["Wind Onshore", "Wind Offshore"]

for technology in wind_turbine_technologies:
for dataset in ws.get_many(
self.database,
ws.either(
*[
ws.equals("name", tech)
for tech in self.powerplant_map[technology]
]
),
):
# create a true copy of the dataset
dataset_copy = copy.deepcopy(dataset)

dataset_copy["name"] += ", direct drive"
dataset_copy["code"] = str(uuid.uuid4().hex)
dataset_copy["comment"] = (
"This dataset represents the direct-drive technology "
"variant of the ecoinvent dataset."
)

for exc in ws.production(dataset_copy):
exc["name"] = dataset_copy["name"]
if "input" in exc:
del exc["input"]

self.database.append(dataset_copy)

self.write_log(dataset_copy)

def write_log(self, dataset, status="created"):
"""
Write log file.
"""

logger.info(
f"{status}|{self.model}|{self.scenario}|{self.year}|"
f"{dataset['name']}|{dataset['location']}"
)

0 comments on commit 40cd418

Please sign in to comment.