Skip to content

Commit

Permalink
Align with master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Sep 26, 2023
1 parent 03ad9a5 commit b579729
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 419 deletions.
6 changes: 3 additions & 3 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ requirements:
- setuptools
run:
- numpy
- pandas==1.5.3
- pandas
- bw2io==0.8.7
- bw2data==3.6.6
- wurst==0.3.3
- bw2data
- wurst
- xarray
- prettytable
- pycountry
Expand Down
2 changes: 1 addition & 1 deletion premise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__all__ = ("NewDatabase", "clear_cache", "get_regions_definition")
__version__ = (1, 6, 6)
__version__ = (1, 7, 0)

from pathlib import Path

Expand Down
Binary file not shown.
Binary file modified premise/data/additional_inventories/lci-hydrogen-electrolysis.xlsx
Binary file not shown.
3 changes: 2 additions & 1 deletion premise/data/additional_inventories/migration_map.csv
Original file line number Diff line number Diff line change
Expand Up @@ -615,4 +615,5 @@ from;to;name_from;ref_prod_from;location_from;name_to;ref_prod_to;location_to
35;39;transmission network construction, electricity, high voltage;transmission network, long-distance;CH;transmission network construction, electricity, high voltage;transmission network, electricity, high voltage;CH
36;39;transmission network construction, electricity, high voltage;transmission network, long-distance;CH;transmission network construction, electricity, high voltage;transmission network, electricity, high voltage;CH
37;39;transmission network construction, electricity, high voltage;transmission network, long-distance;CH;transmission network construction, electricity, high voltage;transmission network, electricity, high voltage;CH
38;39;transmission network construction, electricity, high voltage;transmission network, long-distance;CH;transmission network construction, electricity, high voltage;transmission network, electricity, high voltage;CH
38;39;transmission network construction, electricity, high voltage;transmission network, long-distance;CH;transmission network construction, electricity, high voltage;transmission network, electricity, high voltage;CH
39;38;market for battery cell, Li-ion, LFP;battery cell, Li-ion, LFP;GLO;market for battery cell, Li-ion;battery cell, Li-ion;GLO
66 changes: 18 additions & 48 deletions premise/data_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ def get_gains_EU_data() -> xr.DataArray:
)
gains_emi_EU["sector"] = gains_emi_EU["Sector"] + gains_emi_EU["Activity"]
gains_emi_EU.drop(
[
"Sector",
"Activity",
],
axis=1,
["Sector", "Activity",], axis=1,
)

gains_emi_EU = gains_emi_EU[~gains_emi_EU["value"].isna()]
Expand Down Expand Up @@ -229,19 +225,15 @@ def fix_efficiencies(data: xr.DataArray, min_year: int) -> xr.DataArray:
# we correct it to 1, as we do not accept
# that efficiency degrades over time
data.loc[dict(year=[y for y in data.year.values if y > 2020])] = np.clip(
data.loc[dict(year=[y for y in data.year.values if y > 2020])],
1,
None,
data.loc[dict(year=[y for y in data.year.values if y > 2020])], 1, None,
)

# Inversely, if we are looking at a year prior to 2020
# and the ratio in efficiency change is superior to 1
# we correct it to 1, as we do not accept
# that efficiency in the past was higher than now
data.loc[dict(year=[y for y in data.year.values if y < 2020])] = np.clip(
data.loc[dict(year=[y for y in data.year.values if y < 2020])],
None,
1,
data.loc[dict(year=[y for y in data.year.values if y < 2020])], None, 1,
)

# ensure that efficiency can not decrease over time
Expand Down Expand Up @@ -398,9 +390,7 @@ def __init__(
new_vars = flatten(new_vars)

data = self.__get_iam_data(
key=key,
filedir=filepath_iam_files,
variables=new_vars,
key=key, filedir=filepath_iam_files, variables=new_vars,
)

self.regions = data.region.values.tolist()
Expand All @@ -412,9 +402,7 @@ def __init__(
)

self.electricity_markets = self.__fetch_market_data(
data=data,
input_vars=electricity_prod_vars,
system_model=self.system_model,
data=data, input_vars=electricity_prod_vars, system_model=self.system_model,
)

self.petrol_markets = self.__fetch_market_data(
Expand All @@ -439,12 +427,7 @@ def __init__(
input_vars={
k: v
for k, v in fuel_prod_vars.items()
if any(
x in k
for x in [
"diesel",
]
)
if any(x in k for x in ["diesel",])
},
system_model=self.system_model,
)
Expand All @@ -471,12 +454,7 @@ def __init__(
input_vars={
k: v
for k, v in fuel_prod_vars.items()
if any(
x in k
for x in [
"hydrogen",
]
)
if any(x in k for x in ["hydrogen",])
},
system_model=self.system_model,
)
Expand Down Expand Up @@ -533,12 +511,7 @@ def __init__(
efficiency_labels={
k: v
for k, v in fuel_eff_vars.items()
if any(
x in k
for x in [
"diesel",
]
)
if any(x in k for x in ["diesel",])
},
)
self.gas_efficiencies = self.get_iam_efficiencies(
Expand All @@ -554,12 +527,7 @@ def __init__(
efficiency_labels={
k: v
for k, v in fuel_eff_vars.items()
if any(
x in k
for x in [
"hydrogen",
]
)
if any(x in k for x in ["hydrogen",])
},
)

Expand Down Expand Up @@ -1121,7 +1089,10 @@ def get_external_data(self, datapackages):
.to_xarray()
)

array.coords["year"] = [int(y) for y in array.coords["year"]]
# convert to float64
array = array.astype(np.float64)
# convert year dim to int64
array.coords["year"] = array.coords["year"].astype(np.int64)

data[i]["production volume"] = array
regions = subset["region"].unique().tolist()
Expand Down Expand Up @@ -1163,7 +1134,10 @@ def get_external_data(self, datapackages):
.mean()
.to_xarray()
)
array.coords["year"] = [int(y) for y in array.coords["year"]]
# convert to float64
array = array.astype(np.float64)
# convert year dim to int64
array.coords["year"] = array.coords["year"].astype(np.int64)

ref_years = {}

Expand Down Expand Up @@ -1256,11 +1230,7 @@ def fetch_external_data_coal_power_plants(self):
df = df.drop(columns=["fuel input"])
array = (
df.melt(
id_vars=[
"country",
"CHP",
"fuel",
],
id_vars=["country", "CHP", "fuel",],
var_name="variable",
value_name="value",
)
Expand Down
51 changes: 14 additions & 37 deletions premise/ecoinvent_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
FILEPATH_WAVE = INVENTORY_DIR / "lci-wave_energy.xlsx"
FILEPATH_FUEL_CELL = INVENTORY_DIR / "lci-fuel_cell.xlsx"
FILEPATH_CSP = INVENTORY_DIR / "lci-concentrating-solar-power.xlsx"
FILEPATH_HOME_STORAGE_BATTERIES = INVENTORY_DIR / "lci-home-batteries.xlsx"

config = load_constants()

Expand Down Expand Up @@ -340,6 +341,10 @@ def check_scenarios(scenario: dict, key: bytes) -> dict:
scenario["filepath"] = check_filepath(filepath)
else:
scenario["filepath"] = DATA_DIR / "iam_output_files"
if key is None:
raise ValueError(
"You need to provide the encryption key to decrypt the IAM output files provided by `premise`."
)

scenario["model"] = check_model_name(scenario["model"])
scenario["pathway"] = check_pathway_name(
Expand Down Expand Up @@ -709,6 +714,7 @@ def __import_inventories(self, keep_uncertainty_data: bool = False) -> List[dict
(FILEPATH_COBALT, "3.8"),
(FILEPATH_GRAPHITE, "3.8"),
(FILEPATH_BATTERIES, "3.8"),
(FILEPATH_HOME_STORAGE_BATTERIES, "3.9"),
(FILEPATH_PHOTOVOLTAICS, "3.7"),
(FILEPATH_HYDROGEN_INVENTORIES, "3.9"),
(FILEPATH_HYDROGEN_SOLAR_INVENTORIES, "3.9"),
Expand All @@ -726,18 +732,12 @@ def __import_inventories(self, keep_uncertainty_data: bool = False) -> List[dict
(FILEPATH_SYNGAS_FROM_COAL_INVENTORIES, "3.7"),
(FILEPATH_BIOFUEL_INVENTORIES, "3.7"),
(FILEPATH_SYNFUEL_INVENTORIES, "3.7"),
(
FILEPATH_SYNFUEL_FROM_FT_FROM_WOOD_GASIFICATION_INVENTORIES,
"3.7",
),
(FILEPATH_SYNFUEL_FROM_FT_FROM_WOOD_GASIFICATION_INVENTORIES, "3.7",),
(
FILEPATH_SYNFUEL_FROM_FT_FROM_WOOD_GASIFICATION_WITH_CCS_INVENTORIES,
"3.7",
),
(
FILEPATH_SYNFUEL_FROM_FT_FROM_COAL_GASIFICATION_INVENTORIES,
"3.7",
),
(FILEPATH_SYNFUEL_FROM_FT_FROM_COAL_GASIFICATION_INVENTORIES, "3.7",),
(
FILEPATH_SYNFUEL_FROM_FT_FROM_COAL_GASIFICATION_WITH_CCS_INVENTORIES,
"3.7",
Expand Down Expand Up @@ -856,12 +856,7 @@ def update_dac(self) -> None:
# use multiprocessing to speed up the process
with ProcessPool(processes=multiprocessing.cpu_count()) as pool:
args = [
(
scenario,
self.version,
self.system_model,
self.modified_datasets,
)
(scenario, self.version, self.system_model, self.modified_datasets,)
for scenario in self.scenarios
]
results = pool.starmap(_update_dac, args)
Expand All @@ -882,12 +877,7 @@ def update_fuels(self) -> None:
# use multiprocessing to speed up the process
with ProcessPool(processes=multiprocessing.cpu_count()) as pool:
args = [
(
scenario,
self.version,
self.system_model,
self.modified_datasets,
)
(scenario, self.version, self.system_model, self.modified_datasets,)
for scenario in self.scenarios
]
results = pool.starmap(_update_fuels, args)
Expand All @@ -908,12 +898,7 @@ def update_cement(self) -> None:
# use multiprocessing to speed up the process
with ProcessPool(processes=multiprocessing.cpu_count()) as pool:
args = [
(
scenario,
self.version,
self.system_model,
self.modified_datasets,
)
(scenario, self.version, self.system_model, self.modified_datasets,)
for scenario in self.scenarios
]
results = pool.starmap(_update_cement, args)
Expand All @@ -934,12 +919,7 @@ def update_steel(self) -> None:
# use multiprocessing to speed up the process
with ProcessPool(processes=multiprocessing.cpu_count()) as pool:
args = [
(
scenario,
self.version,
self.system_model,
self.modified_datasets,
)
(scenario, self.version, self.system_model, self.modified_datasets,)
for scenario in self.scenarios
]
results = pool.starmap(_update_steel, args)
Expand Down Expand Up @@ -1220,9 +1200,7 @@ def write_superstructure_db_to_brightway(
)

write_brightway2_database(
data=self.database,
name=name,
reset_codes=True,
data=self.database, name=name, reset_codes=True,
)

# generate scenario report
Expand Down Expand Up @@ -1290,8 +1268,7 @@ def write_db_to_brightway(self, name: [str, List[str]] = None):

for scen, scenario in enumerate(self.scenarios):
write_brightway2_database(
scenario["database"],
name[scen],
scenario["database"], name[scen],
)
# generate scenario report
self.generate_scenario_report()
Expand Down
Loading

0 comments on commit b579729

Please sign in to comment.