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 Nov 29, 2024
2 parents 9eca1a9 + 9a74be1 commit b63e393
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 66 deletions.
2 changes: 1 addition & 1 deletion premise/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def adjust_battery_market_shares(self) -> None:
"NMC811": "market for battery capacity, Li-ion, NMC811, stationary",
"VRFB": "market for battery capacity, redox-flow, Vanadium, stationary",
"LEAD-ACID": "market for battery capacity, lead acid, rechargeable, stationary",
"NAS": "market for battery capacity, Sodium-Nickel-Chloride, Na-NiCl, stationary"
"NAS": "market for battery capacity, Sodium-Nickel-Chloride, Na-NiCl, stationary",
}.items()
}

Expand Down
15 changes: 6 additions & 9 deletions premise/fuels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2589,7 +2589,9 @@ def generate_fuel_markets(self):

# we also need to add old fuel markets which now take an
# input for new fuel markets
for location in self.iam_to_ecoinvent_loc[dataset["location"]]:
for location in self.iam_to_ecoinvent_loc[
dataset["location"]
]:
self.new_fuel_markets.update(
{
(dataset["name"], location): {
Expand All @@ -2606,8 +2608,6 @@ def generate_fuel_markets(self):
}
)



# add to log
self.write_log(dataset)
# add it to list of created datasets
Expand Down Expand Up @@ -2649,10 +2649,9 @@ def generate_fuel_markets(self):

for dataset in ws.get_many(
self.database,
ws.either(*[
ws.equals("name", x[0])
for x in list(self.new_fuel_markets.keys())
])
ws.either(
*[ws.equals("name", x[0]) for x in list(self.new_fuel_markets.keys())]
),
):
if "log parameters" not in dataset:
dataset["log parameters"] = {}
Expand All @@ -2670,8 +2669,6 @@ def generate_fuel_markets(self):
}
)



# add to database
self.database.extend(new_datasets)

Expand Down
45 changes: 30 additions & 15 deletions premise/heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,19 @@ def regionalize_heat_production(self):
exc["name"],
exc["location"],
) in self.carbon_intensity_markets:
fossil_co2 += exc[
"amount"
] * self.carbon_intensity_markets[(exc["name"], exc["location"])]["fossil"]
fossil_co2 += (
exc["amount"]
* self.carbon_intensity_markets[
(exc["name"], exc["location"])
]["fossil"]
)

non_fossil_co2 += exc[
"amount"
] * self.carbon_intensity_markets[(exc["name"], exc["location"])]["non-fossil"]
non_fossil_co2 += (
exc["amount"]
* self.carbon_intensity_markets[
(exc["name"], exc["location"])
]["non-fossil"]
)

if fossil_co2 + non_fossil_co2 > 0:

Expand All @@ -210,8 +216,10 @@ def regionalize_heat_production(self):
)

ds["exchanges"] = [
e for e in ds["exchanges"]
if e["name"] not in (
e
for e in ds["exchanges"]
if e["name"]
not in (
"Carbon dioxide, fossil",
"Carbon dioxide, non-fossil",
)
Expand All @@ -234,7 +242,7 @@ def regionalize_heat_production(self):
"Carbon dioxide, fossil",
"air",
"unspecified",
"kilogram"
"kilogram",
)
],
),
Expand All @@ -259,7 +267,7 @@ def regionalize_heat_production(self):
"Carbon dioxide, non-fossil",
"air",
"unspecified",
"kilogram"
"kilogram",
)
],
),
Expand All @@ -269,11 +277,18 @@ def regionalize_heat_production(self):
if "log parameters" not in ds:
ds["log parameters"] = {}

ds["log parameters"]["initial amount of fossil CO2"] = initial_fossil_co2
ds["log parameters"]["new amount of fossil CO2"] = float(fossil_co2)
ds["log parameters"]["initial amount of biogenic CO2"] = initial_non_fossil_co2
ds["log parameters"]["new amount of biogenic CO2"] = float(non_fossil_co2)

ds["log parameters"][
"initial amount of fossil CO2"
] = initial_fossil_co2
ds["log parameters"]["new amount of fossil CO2"] = float(
fossil_co2
)
ds["log parameters"][
"initial amount of biogenic CO2"
] = initial_non_fossil_co2
ds["log parameters"]["new amount of biogenic CO2"] = float(
non_fossil_co2
)

for new_dataset in list(new_ds.values()):
self.write_log(new_dataset)
Expand Down
93 changes: 53 additions & 40 deletions premise/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,26 +628,24 @@ def check_battery_capacity(self):
ws.either(
*[
ws.contains("name", s)
for s in [
"(MIX)",
"(LFP)",
"(NCx)",
"(PLiB)",
"(CONT",
"(TC"
]
for s in ["(MIX)", "(LFP)", "(NCx)", "(PLiB)", "(CONT", "(TC"]
]
)
),
):
# check that sum of technosphere exchanges sum to 1
total = sum([exc["amount"] for exc in ds["exchanges"] if exc["type"] == "technosphere"])
total = sum(
[
exc["amount"]
for exc in ds["exchanges"]
if exc["type"] == "technosphere"
]
)
if not np.isclose(total, 1.0, rtol=1e-3):
message = f"Total exchange amount is {total}, not 1.0"
self.log_issue(
ds, "Incorrect market shares", message, issue_type="major"
)


for ds in ws.get_many(
self.database,
ws.contains("name", "market for battery capacity, "),
Expand All @@ -657,29 +655,37 @@ def check_battery_capacity(self):
ws.either(
*[
ws.contains("name", s)
for s in [
"MIX",
"LFP",
"NCx",
"PLiB",
"TC",
"CONT"
]
for s in ["MIX", "LFP", "NCx", "PLiB", "TC", "CONT"]
]
)
)
),
):
# check that um of technosphere exchanges equal zero
total = sum([exc["amount"] for exc in ds["exchanges"] if exc["type"] == "technosphere"])
total = sum(
[
exc["amount"]
for exc in ds["exchanges"]
if exc["type"] == "technosphere"
]
)
if not np.isclose(total, 0.0, rtol=1e-3):
message = f"Total exchange amount is {total}, not 0.0"
self.log_issue(
ds, "EoL not balanced with battery input", message, issue_type="major"
ds,
"EoL not balanced with battery input",
message,
issue_type="major",
)

# also check that sum of positive technosphere exchanges
# have a correct value
total = sum([exc["amount"] for exc in ds["exchanges"] if exc["type"] == "technosphere" and exc["amount"] > 0])
total = sum(
[
exc["amount"]
for exc in ds["exchanges"]
if exc["type"] == "technosphere" and exc["amount"] > 0
]
)
# this sum needs to be at least 2
if total < 2:
message = f"Total exchange amount is {total}, not at least 2"
Expand All @@ -692,8 +698,9 @@ def run_battery_checks(self):
self.save_log()

if len(self.major_issues_log) > 0:
print("---> MAJOR anomalies found during battery update: check the change report.")

print(
"---> MAJOR anomalies found during battery update: check the change report."
)


class HeatValidation(BaseDatasetValidator):
Expand Down Expand Up @@ -906,8 +913,9 @@ def run_heat_checks(self):
self.save_log()

if len(self.major_issues_log) > 0:
print("---> MAJOR anomalies found during heat update: check the change report.")

print(
"---> MAJOR anomalies found during heat update: check the change report."
)


class TransportValidation(BaseDatasetValidator):
Expand Down Expand Up @@ -1148,9 +1156,9 @@ def run_vehicle_checks(self):
self.save_log()

if len(self.major_issues_log) > 0:
print("---> MAJOR anomalies found during transport update: check the change report.")


print(
"---> MAJOR anomalies found during transport update: check the change report."
)


class TruckValidation(TransportValidation):
Expand Down Expand Up @@ -1495,8 +1503,9 @@ def run_electricity_checks(self):
self.save_log()

if len(self.major_issues_log) > 0:
print("---> MAJOR anomalies found during electricity update: check the change report.")

print(
"---> MAJOR anomalies found during electricity update: check the change report."
)


class FuelsValidation(BaseDatasetValidator):
Expand Down Expand Up @@ -1590,8 +1599,9 @@ def run_fuel_checks(self):
self.save_log()

if len(self.major_issues_log) > 0:
print("---> MAJOR anomalies found during fuels update: check the change report.")

print(
"---> MAJOR anomalies found during fuels update: check the change report."
)


class SteelValidation(BaseDatasetValidator):
Expand Down Expand Up @@ -1797,8 +1807,9 @@ def run_steel_checks(self):
self.save_log()

if len(self.major_issues_log) > 0:
print("---> MAJOR anomalies found during steel update: check the change report.")

print(
"---> MAJOR anomalies found during steel update: check the change report."
)


class CementValidation(BaseDatasetValidator):
Expand Down Expand Up @@ -1963,8 +1974,9 @@ def run_cement_checks(self):
self.save_log()

if len(self.major_issues_log) > 0:
print("---> MAJOR anomalies found during cement update: check the change report.")

print(
"---> MAJOR anomalies found during cement update: check the change report."
)


class BiomassValidation(BaseDatasetValidator):
Expand Down Expand Up @@ -2059,5 +2071,6 @@ def run_biomass_checks(self):
self.save_log()

if len(self.major_issues_log) > 0:
print("---> MAJOR anomalies found during biomass update: check the change report.")

print(
"---> MAJOR anomalies found during biomass update: check the change report."
)
1 change: 0 additions & 1 deletion tests/test_process_ei310_cutoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def test_brightway():
assert all(isinstance(result, float) for result in results)
print(results)


# destroy all objects
del ndb
del lca
Expand Down

0 comments on commit b63e393

Please sign in to comment.