Skip to content

Commit

Permalink
Black reformating
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Sep 7, 2023
1 parent 1654ac0 commit 6017d34
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
14 changes: 5 additions & 9 deletions premise/data_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,17 +593,16 @@ def __init__(
self.fertilizer_use = (
fertilizer
/ crops_production.sel(
variables=fertilizer.coords["variables"].values,
region=fertilizer.coords["region"].values,
year=fertilizer.coords["year"].values,
)
variables=fertilizer.coords["variables"].values,
region=fertilizer.coords["region"].values,
year=fertilizer.coords["year"].values,
)
) * np.where(crops_production > 0, 1, np.nan)
self.fertilizer_use /= self.fertilizer_use.sel(year=2020)
self.fertilizer_use = self.fertilizer_use.interpolate_na(
dim="year", method="linear", fill_value="extrapolate"
)


self.trsp_cars = get_vehicle_fleet_composition(self.model, vehicle_type="car")
self.trsp_trucks = get_vehicle_fleet_composition(
self.model, vehicle_type="truck"
Expand Down Expand Up @@ -807,8 +806,6 @@ def __fetch_market_data(
.sum(dim="variables")
)



# back-fill nans
market_data = market_data.bfill(dim="year")
# fill NaNs with zeros
Expand Down Expand Up @@ -1081,8 +1078,7 @@ def __get_iam_production_volumes(

if available_vars:
data_to_return = data.loc[
:, [v for v in flatten(input_vars.values())
if v in available_vars], :
:, [v for v in flatten(input_vars.values()) if v in available_vars], :
]

else:
Expand Down
14 changes: 10 additions & 4 deletions premise/fuels.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,10 +1788,16 @@ def should_adjust_land_use_change_emissions(
)

def adjust_fertilizer_use(self, dataset: dict, crop_type: str) -> dict:

scaling_factor = self.iam_data.fertilizer_use.sel(
region=dataset["location"] if dataset["location"] in self.regions else self.ecoinvent_to_iam_loc[dataset["location"]], variables=crop_type
).interp(year=self.year).values.item(0)
scaling_factor = (
self.iam_data.fertilizer_use.sel(
region=dataset["location"]
if dataset["location"] in self.regions
else self.ecoinvent_to_iam_loc[dataset["location"]],
variables=crop_type,
)
.interp(year=self.year)
.values.item(0)
)

if np.isnan(scaling_factor):
scaling_factor = 1.0
Expand Down

0 comments on commit 6017d34

Please sign in to comment.