Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Jul 14, 2023
2 parents 8e77a43 + 0744bb9 commit fd277be
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 45 deletions.
29 changes: 18 additions & 11 deletions premise/electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,8 +1592,7 @@ def create_region_specific_power_plants(self):
dataset["name"]
for dataset in self.database
if dataset["name"]
in [y for k, v in self.powerplant_map.items()
for y in v if k in techs]
in [y for k, v in self.powerplant_map.items() for y in v if k in techs]
]

list_datasets_to_duplicate.extend(
Expand All @@ -1605,7 +1604,6 @@ def create_region_specific_power_plants(self):
"carbon dioxide, captured from natural gas",
"carbon dioxide, captured at wood burning",
"carbon dioxide, captured at hydrogen burning",

]
)

Expand All @@ -1632,8 +1630,7 @@ def create_region_specific_power_plants(self):
providers = [
e
for e in plant["exchanges"]
if e["type"] == "technosphere"
and e["unit"] == "kilowatt hour"
if e["type"] == "technosphere" and e["unit"] == "kilowatt hour"
]

for provider in providers:
Expand Down Expand Up @@ -1729,13 +1726,14 @@ def update_electricity_efficiency(self) -> None:
]
),
):

if (
dataset["name"],
dataset["reference product"],
dataset["location"],
dataset["unit"],
) in self.modified_datasets[(self.model, self.scenario, self.year)]["emptied"]:
) in self.modified_datasets[(self.model, self.scenario, self.year)][
"emptied"
]:
continue

# Find current efficiency
Expand All @@ -1744,8 +1742,15 @@ def update_electricity_efficiency(self) -> None:
)

if not self.use_absolute_efficiency:
iam_location = self.geo.ecoinvent_to_iam_location(dataset["location"])
if iam_location in self.iam_data.electricity_efficiencies.coords["region"].values:
iam_location = self.geo.ecoinvent_to_iam_location(
dataset["location"]
)
if (
iam_location
in self.iam_data.electricity_efficiencies.coords[
"region"
].values
):
# Find relative efficiency change indicated by the IAM
scaling_factor = 1 / self.find_iam_efficiency_change(
data=self.iam_data.electricity_efficiencies,
Expand All @@ -1760,7 +1765,9 @@ def update_electricity_efficiency(self) -> None:
new_efficiency = self.find_iam_efficiency_change(
data=self.iam_data.electricity_efficiencies,
variable=technology,
location=self.geo.ecoinvent_to_iam_location(dataset["location"]),
location=self.geo.ecoinvent_to_iam_location(
dataset["location"]
),
)

if ei_eff != 1 and not np.isnan(new_efficiency):
Expand Down Expand Up @@ -1917,7 +1924,7 @@ def adjust_coal_power_plant_emissions(self) -> None:
}
)

#self.write_log(dataset=dataset, status="updated")
# self.write_log(dataset=dataset, status="updated")

def update_electricity_markets(self) -> None:
"""
Expand Down
19 changes: 14 additions & 5 deletions premise/inventory_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ def add_biosphere_links(self, delete_missing: bool = False) -> None:
)

def lower_case_technosphere_exchanges(self) -> None:

blakclist = [
"NOx",
"SOx",
Expand All @@ -582,20 +581,30 @@ def lower_case_technosphere_exchanges(self) -> None:
if not any([x in ds["name"] for x in blakclist]):
ds["name"] = ds["name"][0].lower() + ds["name"][1:]
if not any([x in ds["reference product"] for x in blakclist]):
ds["reference product"] = ds["reference product"][0].lower() + ds["reference product"][1:]
ds["reference product"] = (
ds["reference product"][0].lower() + ds["reference product"][1:]
)

for exc in ds["exchanges"]:
if exc["type"] in ["technosphere", "production"]:
if not any([x in exc["name"] for x in blakclist]):
exc["name"] = exc["name"][0].lower() + exc["name"][1:]

if not any([x in exc.get("reference product", "") for x in blakclist]):
if not any(
[x in exc.get("reference product", "") for x in blakclist]
):
if exc.get("reference product") is not None:
exc["reference product"] = exc["reference product"][0].lower() + exc["reference product"][1:]
exc["reference product"] = (
exc["reference product"][0].lower()
+ exc["reference product"][1:]
)

if not any([x in exc.get("product", "") for x in blakclist]):
if exc.get("product") is not None:
exc["product"] = exc["product"][0].lower() + exc["product"][1:]
exc["product"] = (
exc["product"][0].lower() + exc["product"][1:]
)

def remove_ds_and_modifiy_exchanges(self, name: str, ex_data: dict) -> None:
"""
Remove an activity dataset from :attr:`import_db` and replace the corresponding
Expand Down
84 changes: 63 additions & 21 deletions premise/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,69 @@ def fetch_data(
"GDP": iam_data.other_vars if hasattr(iam_data, "other_vars") else None,
"CO2": iam_data.other_vars if hasattr(iam_data, "other_vars") else None,
"GMST": iam_data.other_vars if hasattr(iam_data, "other_vars") else None,
"Electricity - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None,
"Electricity (biom) - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None,
"Electricity - efficiency": iam_data.electricity_efficiencies if hasattr(iam_data, "electricity_efficiencies") else None,
"Fuel (gasoline) - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None,
"Fuel (gasoline) - efficiency": iam_data.petrol_efficiencies if hasattr(iam_data, "petrol_efficiencies") else None,
"Fuel (diesel) - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None,
"Fuel (diesel) - efficiency": iam_data.diesel_efficiencies if hasattr(iam_data, "diesel_efficiencies") else None,
"Fuel (gas) - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None,
"Fuel (gas) - efficiency": iam_data.gas_efficiencies if hasattr(iam_data, "gas_efficiencies") else None,
"Fuel (hydrogen) - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None,
"Fuel (hydrogen) - efficiency": iam_data.hydrogen_efficiencies if hasattr(iam_data, "hydrogen_efficiencies") else None,
"Cement - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None,
"Cement - efficiency": iam_data.cement_efficiencies if hasattr(iam_data, "cement_efficiencies") else None,
"Cement - CCS": iam_data.carbon_capture_rate if hasattr(iam_data, "carbon_capture_rate") else None,
"Steel - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None,
"Steel - efficiency": iam_data.steel_efficiencies if hasattr(iam_data, "steel_efficiencies") else None,
"Steel - CCS": iam_data.carbon_capture_rate if hasattr(iam_data, "carbon_capture_rate") else None,
"Direct Air Capture - generation": iam_data.production_volumes if hasattr(iam_data, "production_volumes") else None,
"Transport (cars)": iam_data.trsp_cars if hasattr(iam_data, "trsp_cars") else None,
"Transport (buses)": iam_data.trsp_buses if hasattr(iam_data, "trsp_buses") else None,
"Transport (trucks)": iam_data.trsp_trucks if hasattr(iam_data, "trsp_trucks") else None,
"Electricity - generation": iam_data.production_volumes
if hasattr(iam_data, "production_volumes")
else None,
"Electricity (biom) - generation": iam_data.production_volumes
if hasattr(iam_data, "production_volumes")
else None,
"Electricity - efficiency": iam_data.electricity_efficiencies
if hasattr(iam_data, "electricity_efficiencies")
else None,
"Fuel (gasoline) - generation": iam_data.production_volumes
if hasattr(iam_data, "production_volumes")
else None,
"Fuel (gasoline) - efficiency": iam_data.petrol_efficiencies
if hasattr(iam_data, "petrol_efficiencies")
else None,
"Fuel (diesel) - generation": iam_data.production_volumes
if hasattr(iam_data, "production_volumes")
else None,
"Fuel (diesel) - efficiency": iam_data.diesel_efficiencies
if hasattr(iam_data, "diesel_efficiencies")
else None,
"Fuel (gas) - generation": iam_data.production_volumes
if hasattr(iam_data, "production_volumes")
else None,
"Fuel (gas) - efficiency": iam_data.gas_efficiencies
if hasattr(iam_data, "gas_efficiencies")
else None,
"Fuel (hydrogen) - generation": iam_data.production_volumes
if hasattr(iam_data, "production_volumes")
else None,
"Fuel (hydrogen) - efficiency": iam_data.hydrogen_efficiencies
if hasattr(iam_data, "hydrogen_efficiencies")
else None,
"Cement - generation": iam_data.production_volumes
if hasattr(iam_data, "production_volumes")
else None,
"Cement - efficiency": iam_data.cement_efficiencies
if hasattr(iam_data, "cement_efficiencies")
else None,
"Cement - CCS": iam_data.carbon_capture_rate
if hasattr(iam_data, "carbon_capture_rate")
else None,
"Steel - generation": iam_data.production_volumes
if hasattr(iam_data, "production_volumes")
else None,
"Steel - efficiency": iam_data.steel_efficiencies
if hasattr(iam_data, "steel_efficiencies")
else None,
"Steel - CCS": iam_data.carbon_capture_rate
if hasattr(iam_data, "carbon_capture_rate")
else None,
"Direct Air Capture - generation": iam_data.production_volumes
if hasattr(iam_data, "production_volumes")
else None,
"Transport (cars)": iam_data.trsp_cars
if hasattr(iam_data, "trsp_cars")
else None,
"Transport (buses)": iam_data.trsp_buses
if hasattr(iam_data, "trsp_buses")
else None,
"Transport (trucks)": iam_data.trsp_trucks
if hasattr(iam_data, "trsp_trucks")
else None,
}

if data[sector] is not None:
Expand Down
20 changes: 12 additions & 8 deletions premise/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ def select_multiple_suppliers(
suppliers = list(
ws.get_many(
self.database,
ws.either(*[ws.contains("name", sup) for sup in possible_names]),
ws.either(
*[ws.contains("name", sup) for sup in possible_names]
),
ws.either(
*[
ws.equals("location", item)
Expand All @@ -339,9 +341,13 @@ def select_multiple_suppliers(
)
counter += 1
except IndexError:
raise IndexError("No supplier found for {} in {}, "
"looking for terms: {} "
"and with blacklist: {}".format(possible_names, possible_locations, look_for, blacklist))
raise IndexError(
"No supplier found for {} in {}, "
"looking for terms: {} "
"and with blacklist: {}".format(
possible_names, possible_locations, look_for, blacklist
)
)

suppliers = get_shares_from_production_volume(suppliers)

Expand Down Expand Up @@ -648,8 +654,7 @@ def fetch_proxies(
ds
for ds in self.database
if not (
ds["name"] == ds_name
and ds["reference product"] == ds_ref_prod
ds["name"] == ds_name and ds["reference product"] == ds_ref_prod
)
]

Expand Down Expand Up @@ -700,8 +705,7 @@ def empty_original_datasets(
# add tag
existing_ds["has_downstream_consumer"] = False
existing_ds["exchanges"] = [
e for e in existing_ds["exchanges"]
if e["type"] == "production"
e for e in existing_ds["exchanges"] if e["type"] == "production"
]

# for cases where external scenarios are used
Expand Down

0 comments on commit fd277be

Please sign in to comment.