Skip to content

Commit

Permalink
Correct biofuels LCIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Jun 25, 2023
1 parent ed9937f commit 3a6f816
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 38 deletions.
Binary file modified premise/data/additional_inventories/lci-biofuels.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion premise/data/iam_output_files/image_SSP1-Base.csv

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion premise/data/iam_output_files/image_SSP2-Base.csv

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion premise/data/iam_output_files/image_SSP2-RCP19.csv

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion premise/data/iam_output_files/image_SSP2-RCP26.csv

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions premise/data_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,10 @@ def __init__(
)

self.land_use = self.__get_iam_production_volumes(
data=data, input_vars=land_use_vars
data=data, input_vars=land_use_vars, fill=True
)
self.land_use_change = self.__get_iam_production_volumes(
data=data, input_vars=land_use_change_vars
data=data, input_vars=land_use_change_vars, fill=True
)

self.trsp_cars = get_vehicle_fleet_composition(self.model, vehicle_type="car")
Expand Down Expand Up @@ -935,7 +935,7 @@ def __get_carbon_capture_rate(

return rate

def __get_iam_production_volumes(self, input_vars, data) -> [xr.DataArray, None]:
def __get_iam_production_volumes(self, input_vars, data, fill: bool = False) -> [xr.DataArray, None]:
"""
Returns n xarray with production volumes for different sectors:
electricity, steel, cement, fuels.
Expand Down Expand Up @@ -976,6 +976,16 @@ def __get_iam_production_volumes(self, input_vars, data) -> [xr.DataArray, None]
k for k, v in input_vars.items() if v in available_vars
]

if fill:
# if fill, we fill zero values
# with the nearest year's value
# first, convert zero values to NaNs
data_to_return = data_to_return.where(data_to_return != 0)
# then, backfill
data_to_return = data_to_return.bfill(dim="year")
# then, forward fill
data_to_return = data_to_return.ffill(dim="year")

return data_to_return

def get_external_data(self, datapackages):
Expand Down
60 changes: 39 additions & 21 deletions premise/fuels.py
Original file line number Diff line number Diff line change
Expand Up @@ -1481,11 +1481,16 @@ def adjust_land_use(self, dataset: dict, region: str, crop_type: str) -> dict:
:return: adjusted dataset
"""
string = ""
land_use = 0

for exc in dataset["exchanges"]:
# we adjust the land use
if exc["type"] == "biosphere" and exc["name"].startswith("Occupation"):
# lower heating value, dry basis
lhv_ar = dataset["LHV [MJ/kg dry]"]
if "LHV [MJ/kg as received]" in dataset:
lower_heating_value = dataset["LHV [MJ/kg as received]"]
else:
lower_heating_value = dataset.get("LHV [MJ/kg dry]", 0)

# Ha/GJ
land_use = (
Expand All @@ -1494,33 +1499,39 @@ def adjust_land_use(self, dataset: dict, region: str, crop_type: str) -> dict:
.values
)

# replace NA values with 0
if np.isnan(land_use):
land_use = 0

if land_use > 0:
# HA to m2
land_use *= 10000
# m2/GJ to m2/MJ
land_use /= 1000
# m2/kg, as received
land_use *= lhv_ar
land_use *= lower_heating_value
# update exchange value
exc["amount"] = float(land_use)

string = (
f"The land area occupied has been modified to {land_use}, "
f"to be in line with the scenario {self.scenario} of {self.model.upper()} "
f"in {self.year} in the region {region}. "
)
if "comment" in dataset:
dataset["comment"] += string
else:
dataset["comment"] = string
string = (
f"The land area occupied has been modified to {land_use}, "
f"to be in line with the scenario {self.scenario} of {self.model.upper()} "
f"in {self.year} in the region {region}. "
)

if "log parameters" not in dataset:
dataset["log parameters"] = {}
dataset["log parameters"].update(
{
"land footprint": land_use,
}
)
if string and land_use:
if "comment" in dataset:
dataset["comment"] += string
else:
dataset["comment"] = string

if "log parameters" not in dataset:
dataset["log parameters"] = {}
dataset["log parameters"].update(
{
"land footprint": land_use,
}
)

return dataset

Expand Down Expand Up @@ -1551,13 +1562,20 @@ def adjust_land_use_change_emissions(
.values
)

# replace NA values with 0
if np.isnan(land_use_co2):
land_use_co2 = 0

if land_use_co2 > 0:
# lower heating value, as received
lower_heating_value_as_received = dataset["LHV [MJ/kg dry]"]
if "LHV [MJ/kg as received]" in dataset:
lower_heating_value = dataset["LHV [MJ/kg as received]"]
else:
lower_heating_value = dataset.get("LHV [MJ/kg dry]", 0)

# kg CO2/MJ
land_use_co2 /= 1000
land_use_co2 *= lower_heating_value_as_received
land_use_co2 *= lower_heating_value

land_use_co2_exc = {
"uncertainty type": 0,
Expand Down
20 changes: 10 additions & 10 deletions premise/iam_variables_mapping/crops_variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ sugar:
temperate: sugarbeet
tropical: sugarcane
land_use:
image: Land Use|Average|Biomass|Sugar
image: Land Use|Marginal|Biomass|Sugar
land_use_change:
image: Emission Factor|CO2|Energy|Supply|Biomass|Average|Sugar
image: Emission Factor|CO2|Energy|Supply|Biomass|Marginal|Sugar
oil:
crop_type:
image:
Expand All @@ -23,9 +23,9 @@ oil:
temperate: rapeseed
tropical: palm oil
land_use:
image: Land Use|Average|Biomass|OilCrop
image: Land Use|Marginal|Biomass|OilCrop
land_use_change:
image: Emission Factor|CO2|Energy|Supply|Biomass|Average|Oilcrops
image: Emission Factor|CO2|Energy|Supply|Biomass|Marginal|Oilcrops
wood:
crop_type:
image:
Expand All @@ -35,9 +35,9 @@ wood:
temperate: poplar
tropical: eucalyptus
land_use:
image: Land Use|Average|Biomass|Woody
image: Land Use|Marginal|Biomass|Woody
land_use_change:
image: Emission Factor|CO2|Energy|Supply|Biomass|Average|Woody
image: Emission Factor|CO2|Energy|Supply|Biomass|Marginal|Woody
grass:
crop_type:
image:
Expand All @@ -47,9 +47,9 @@ grass:
temperate: switchgrass
tropical: miscanthus
land_use:
image: Land Use|Average|Biomass|Grassy
image: Land Use|Marginal|Biomass|Grassy
land_use_change:
image: Emission Factor|CO2|Energy|Supply|Biomass|Average|Grassy
image: Emission Factor|CO2|Energy|Supply|Biomass|Marginal|Grassy
grain:
crop_type:
image:
Expand All @@ -59,6 +59,6 @@ grain:
temperate: corn
tropical: corn
land_use:
image: Land Use|Average|Biomass|Maize
image: Land Use|Marginal|Biomass|Maize
land_use_change:
image: Emission Factor|CO2|Energy|Supply|Biomass|Average|Maize
image: Emission Factor|CO2|Energy|Supply|Biomass|Marginal|Maize

0 comments on commit 3a6f816

Please sign in to comment.