Skip to content

Commit

Permalink
Fix lead time when consequential
Browse files Browse the repository at this point in the history
Fix inter year in fuels.py
Version bump
  • Loading branch information
romainsacchi committed Aug 17, 2023
1 parent 882bfbc commit c4c3e3c
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 53 deletions.
4 changes: 3 additions & 1 deletion docs/consequential.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ Range time

Integer. Years. To measure the trend around the point where the additional
capital will be installed, a range of n years before and after the point
is taken as the time interval.
is taken as the time interval. Note that if set to a value other than 0,
the duration argument must be set to 0.

Duration
^^^^^^^^

Integer. Years. Duration over which the change in demand should be measured.
Note that if set to a value other than 0, the range time argument must be set to 0.

Foresight
^^^^^^^^^
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, 1)
__version__ = (1, 6, 2)

from pathlib import Path

Expand Down
56 changes: 25 additions & 31 deletions premise/data/consequential/blacklist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,19 @@
# if it is present, the activity is replaced by the activity
# specified in the `replacement` field.
---
- name: electricity production, at co-generation power plant/hard coal, oxy, pipeline 200km, storage 1000m
- name: electricity production, at co-generation hard coal-fired power plant, post, pipeline 200km, storage 1000m
reference product: electricity, high voltage
unit: kilowatt hour
- name: electricity production, at co-generation power plant/hard coal, oxy, pipeline 400km, storage 3000m
reference product: electricity, high voltage
unit: kilowatt hour
- name: electricity production, at co-generation power plant/hard coal, post, pipeline 200km, storage 1000m
reference product: electricity, high voltage
unit: kilowatt hour
- name: electricity production, at co-generation power plant/hard coal, post, pipeline 400km, storage 1000m
reference product: electricity, high voltage
unit: kilowatt hour
- name: electricity production, at co-generation power plant/hard coal, post, pipeline 400km, storage 3000m
reference product: electricity, high voltage
unit: kilowatt hour
- name: electricity production, at co-generation power plant/hard coal, pre, pipeline 200km, storage 1000m
reference product: electricity, high voltage
unit: kilowatt hour
- name: electricity production, at co-generation power plant/hard coal, pre, pipeline 400km, storage 3000m
reference product: electricity, high voltage
unit: kilowatt hour
- name: electricity production, at co-generation power plant/wood, post, pipeline 200km, storage 1000m
reference product: electricity, high voltage
unit: kilowatt hour
- name: electricity production, at co-generation power plant/wood, post, pipeline 400km, storage 3000m
reference product: electricity, high voltage
unit: kilowatt hour
- name: electricity production, at co-generation power plant/natural gas, post, pipeline 200km, storage 1000m
reference product: electricity, high voltage
unit: kilowatt hour
- name: electricity production, at co-generation power plant/natural gas, pre, pipeline 200km, storage 1000m

- name: electricity production, at co-generation wood-fired power plant, post, pipeline 200km, storage 1000m
reference product: electricity, high voltage
unit: kilowatt hour
- name: electricity production, at co-generation power plant/oil, post, pipeline 200km, storage 1000m

- name: electricity production, at co-generation natural gas-fired power plant, post, pipeline 200km, storage 1000m
reference product: electricity, high voltage
unit: kilowatt hour
- name: electricity production, at co-generation power plant/oil, pre, pipeline 200km, storage 1000m

- name: electricity production, at co-generation oil-fired power plant, post, pipeline 200km, storage 1000m
reference product: electricity, high voltage
unit: kilowatt hour

Expand Down Expand Up @@ -117,6 +93,24 @@
reference product: heat, central or small-scale, other than natural gas
location: CH

- name: heat and power co-generation, hard coal
reference product: electricity, high voltage
unit: kilowatt hour
location: DE
replacement:
name: electricity production, hard coal
reference product: electricity, high voltage
location: DE

- name: heat and power co-generation, oil
reference product: electricity, high voltage
unit: kilowatt hour
location: DE
replacement:
name: electricity production, oil
reference product: electricity, high voltage
location: DE

- name: air separation, cryogenic
reference product: nitrogen, liquid
unit: kilogram
Expand Down
14 changes: 14 additions & 0 deletions premise/data/consequential/leadtimes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@ Gas CC: 3
Gas CC CCS: 3
Gas CHP: 3
Gas CHP CCS: 3
Gas ST: 3
Oil ST: 3
Oil CC CCS: 3
Oil CC: 3
Oil CHP CCS: 3
Oil CHP: 3
Foil ST: 3
Geothermal: 3
Hydro: 4
Hydrogen: 3
Nuclear: 7
Nuclear_EPR: 7
Nuclear_SMR: 7
Solar CSP: 3
Solar CSP autonomous: 3
Solar PV Centralized: 2
Solar PV Residential: 2
Wind Onshore: 2
Wind Offshore: 3
Wave: 3
diesel: 3
gasoline: 3
diesel, synthetic, from wood: 3
Expand Down Expand Up @@ -65,3 +71,11 @@ hydrogen, biomass, with CCS: 3
hydrogen, coal: 3
hydrogen, nat. gas: 3
hydrogen, nat. gas, with CCS: 3
hydrogen, coal, with CCS: 3
hydrogen, solar: 3
cement, dry feed rotary kiln: 10
steel - primary: 10
steel - secondary: 10
daccs_sorbent: 3
biomass - residual: 3
biomass crops - purpose grown: 3
16 changes: 15 additions & 1 deletion premise/data/consequential/lifetimes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Gas CC: 35
Gas CC CCS: 35
Gas CHP: 35
Gas CHP CCS: 35
Gas ST: 35
Oil ST: 25
Oil CC CCS: 25
Oil CC: 25
Expand All @@ -26,11 +27,16 @@ Geothermal: 30
Hydro: 130
Hydrogen: 35
Nuclear: 40
Nuclear_EPR: 40
Nuclear_SMR: 40
Foil ST: 25
Solar CSP: 30
Solar CSP autonomous: 30
Solar PV Centralized: 30
Solar PV Residential: 30
Wind Onshore: 25
Wind Offshore: 25
Wave: 25
diesel: 35
gasoline: 35
diesel, synthetic, from wood: 35
Expand Down Expand Up @@ -64,4 +70,12 @@ hydrogen, biomass: 35
hydrogen, biomass, with CCS: 35
hydrogen, coal: 35
hydrogen, nat. gas: 35
hydrogen, nat. gas, with CCS: 35
hydrogen, nat. gas, with CCS: 35
hydrogen, coal, with CCS: 35
hydrogen, solar: 35
cement, dry feed rotary kiln: 40
steel - primary: 40
steel - secondary: 40
daccs_sorbent: 20
biomass - residual: 35
biomass crops - purpose grown: 35
21 changes: 14 additions & 7 deletions premise/data_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ def __init__(
)

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

self.petrol_markets = self.__fetch_market_data(
Expand All @@ -421,6 +423,7 @@ def __init__(
for k, v in fuel_prod_vars.items()
if any(x in k for x in ["gasoline", "ethanol", "methanol"])
},
system_model=self.system_model,
)
if self.petrol_markets is not None:
# divide the volume of "gasoline" by 2
Expand All @@ -442,6 +445,7 @@ def __init__(
]
)
},
system_model=self.system_model,
)
if self.diesel_markets is not None:
# divide the volume of "gasoline" by 2
Expand All @@ -458,6 +462,7 @@ def __init__(
for k, v in fuel_prod_vars.items()
if any(x in k for x in ["biogas", "methane", "natural gas"])
},
system_model=self.system_model,
)

self.hydrogen_markets = self.__fetch_market_data(
Expand All @@ -472,17 +477,18 @@ def __init__(
]
)
},
system_model=self.system_model,
)

self.cement_markets = self.__fetch_market_data(
data=data, input_vars=cement_prod_vars
data=data, input_vars=cement_prod_vars, system_model="cutoff"
)
self.steel_markets = self.__fetch_market_data(
data=data, input_vars=steel_prod_vars
data=data, input_vars=steel_prod_vars, system_model="cutoff"
)
self.dac_markets = self.__fetch_market_data(data=data, input_vars=dac_prod_vars)
self.dac_markets = self.__fetch_market_data(data=data, input_vars=dac_prod_vars, system_model="cutoff")
self.biomass_markets = self.__fetch_market_data(
data=data, input_vars=biomass_prod_vars
data=data, input_vars=biomass_prod_vars, system_model="cutoff"
)

self.carbon_capture_rate = self.__get_carbon_capture_rate(
Expand All @@ -496,6 +502,7 @@ def __init__(
data=data,
input_vars=other_vars,
normalize=False,
system_model = "cutoff"
)

self.electricity_efficiencies = self.get_iam_efficiencies(
Expand Down Expand Up @@ -707,7 +714,7 @@ def __get_iam_data(
return array

def __fetch_market_data(
self, data: xr.DataArray, input_vars: dict, normalize: bool = True
self, data: xr.DataArray, input_vars: dict, system_model: str, normalize: bool = True,
) -> [xr.DataArray, None]:
"""
This method retrieves the market share for each technology,
Expand Down Expand Up @@ -742,7 +749,7 @@ def __fetch_market_data(
rev_input_vars[v] for v in market_data.variables.values
]

if self.system_model == "consequential":
if system_model == "consequential":
market_data = consequential_method(
market_data, self.year, self.system_model_args
)
Expand Down
2 changes: 2 additions & 0 deletions premise/electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,8 @@ def create_biomass_markets(self) -> None:
0,
1,
)
elif self.system_model == "consequential" and biomass_type == "biomass - residual":
share = 0
else:
share = 0

Expand Down
4 changes: 2 additions & 2 deletions premise/fuels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2195,8 +2195,8 @@ def generate_regional_fuel_market(

if (
self.iam_fuel_markets.sel(
region=region, variables=prod_vars, year=self.year
).sum(dim=["variables"])
region=region, variables=prod_vars
).interp(year=self.year).sum(dim=["variables"])
== 0
):
print("No fuel market for", dataset["name"], "in", region)
Expand Down
27 changes: 18 additions & 9 deletions premise/marginal_mixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ def get_leadtime(list_tech: Tuple) -> np.ndarray:
with open(IAM_LEADTIMES, "r", encoding="utf-8") as stream:
dict_ = yaml.safe_load(stream)

dict_ = {k: v for k, v in dict_.items() if k in list(list_tech)}
# check that all technologies have a lead-time
if not all([k in dict_.keys() for k in list_tech]):
raise ValueError(
f"Not all technologies have a lead-time. "
f"Missing technologies: {set(list_tech) - set(dict_.keys())}"
)
dict_ = {k: dict_[k] for k in list(list_tech)}


return np.array(list(dict_.values()), dtype=float)


Expand Down Expand Up @@ -203,12 +211,12 @@ def consequential_method(data: xr.DataArray, year: int, args: dict) -> xr.DataAr
},
(False, False, False, True): {
"start": year,
"end": year + leadtime,
"end": year + fetch_avg_leadtime(leadtime, shares),
"start_avg": year,
"end_avg": year + fetch_avg_lifetime(lifetime=leadtime, shares=shares),
},
(False, False, True, True): {
"start": year - leadtime,
"start": year - fetch_avg_leadtime(leadtime, shares),
"end": year,
"start_avg": year
- fetch_avg_lifetime(lifetime=leadtime, shares=shares),
Expand All @@ -227,8 +235,8 @@ def consequential_method(data: xr.DataArray, year: int, args: dict) -> xr.DataAr
"end_avg": year + range_time,
},
(True, False, False, True): {
"start": year + leadtime - range_time,
"end": year + leadtime + range_time,
"start": year + fetch_avg_leadtime(leadtime, shares) - range_time,
"end": year + fetch_avg_leadtime(leadtime, shares) + range_time,
"start_avg": year + fetch_avg_leadtime(leadtime, shares) - range_time,
"end_avg": year + fetch_avg_leadtime(leadtime, shares) + range_time,
},
Expand All @@ -251,8 +259,8 @@ def consequential_method(data: xr.DataArray, year: int, args: dict) -> xr.DataAr
"end_avg": year + duration,
},
(False, True, False, True): {
"start": year + leadtime,
"end": year + leadtime + duration,
"start": year + fetch_avg_leadtime(leadtime, shares),
"end": year + fetch_avg_leadtime(leadtime, shares) + duration,
"start_avg": year + fetch_avg_leadtime(leadtime, shares),
"end_avg": year + fetch_avg_leadtime(leadtime, shares) + duration,
},
Expand Down Expand Up @@ -281,8 +289,9 @@ def consequential_method(data: xr.DataArray, year: int, args: dict) -> xr.DataAr

except KeyError:
print(
"The combination of range_time, duration, foresight, and lead_time "
"is not possible. Please check your input."
f"The combination of range_time, duration, foresight, and lead_time {range_time, duration, foresight, lead_time} "
"is not possible. Please check your input. Specifically, if `range_time` is non-null, `duration` must be null, "
"and vice versa."
)
continue

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def package_files(directory):

setup(
name="premise",
version="1.6.1",
version="1.6.2",
python_requires=">=3.9,<3.11",
packages=packages,
author="Romain Sacchi <[email protected]>, Alois Dirnaichner <[email protected]>, Chris Mutel "
Expand Down

0 comments on commit c4c3e3c

Please sign in to comment.