Skip to content

Commit

Permalink
Black reformating
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Jul 31, 2024
1 parent bf42923 commit 4f487b0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 41 deletions.
45 changes: 24 additions & 21 deletions premise/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def _update_battery(scenario, version, system_model):

battery.adjust_battery_mass()

if battery.iam_data.battery_mobile_scenarios is not None or battery.iam_data.battery_stationary_scenarios is not None:
if (
battery.iam_data.battery_mobile_scenarios is not None
or battery.iam_data.battery_stationary_scenarios is not None
):
battery.adjust_battery_market_shares()

scenario["database"] = battery.database
Expand Down Expand Up @@ -134,11 +137,13 @@ def adjust_battery_market_shares(self) -> None:
"NMC622": "market for battery capacity, Li-ion, NMC622, stationary",
"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"
"LEAD-ACID": "market for battery capacity, lead acid, rechargeable, stationary",
}.items()
}

self._adjust_shares(market_datasets_stationary, datasets_mapping_stationary, "stationary")
self._adjust_shares(
market_datasets_stationary, datasets_mapping_stationary, "stationary"
)
self._adjust_shares(market_datasets_mobile, datasets_mapping_mobile, "mobile")

def _adjust_shares(self, market_datasets, datasets_mapping, market_type):
Expand All @@ -150,8 +155,6 @@ def _adjust_shares(self, market_datasets, datasets_mapping, market_type):
else:
battery_scenarios = self.iam_data.battery_stationary_scenarios



for ds in ws.get_many(
self.database,
ws.either(*[ws.equals("name", name) for name in market_datasets]),
Expand Down Expand Up @@ -294,24 +297,24 @@ def write_log(self, dataset, status):
Write log file.
"""

log_params = dataset.get('log parameters', {})
battery_input = log_params.get('battery input', '')
old_battery_mass = log_params.get('old battery mass', '')
new_battery_mass = log_params.get('new battery mass', '')
log_params = dataset.get("log parameters", {})
battery_input = log_params.get("battery input", "")
old_battery_mass = log_params.get("old battery mass", "")
new_battery_mass = log_params.get("new battery mass", "")

shares = [
log_params.get('NMC111 market share', ''),
log_params.get('NMC532 market share', ''),
log_params.get('NMC622 market share', ''),
log_params.get('NMC811 market share', ''),
log_params.get('NMC900-Si market share', ''),
log_params.get('LFP market share', ''),
log_params.get('NCA market share', ''),
log_params.get('LAB market share', ''),
log_params.get('LSB market share', ''),
log_params.get('SIB market share', ''),
log_params.get('VRFB market share', ''),
log_params.get('LEAD-ACID market share', '')
log_params.get("NMC111 market share", ""),
log_params.get("NMC532 market share", ""),
log_params.get("NMC622 market share", ""),
log_params.get("NMC811 market share", ""),
log_params.get("NMC900-Si market share", ""),
log_params.get("LFP market share", ""),
log_params.get("NCA market share", ""),
log_params.get("LAB market share", ""),
log_params.get("LSB market share", ""),
log_params.get("SIB market share", ""),
log_params.get("VRFB market share", ""),
log_params.get("LEAD-ACID market share", ""),
]

logger.info(
Expand Down
49 changes: 30 additions & 19 deletions premise/data_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
BATTERY_MOBILE_SCENARIO_DATA = DATA_DIR / "battery" / "mobile_scenarios.csv"
BATTERY_STATIONARY_SCENARIO_DATA = DATA_DIR / "battery" / "stationary_scenarios.csv"


def print_missing_variables(missing_vars):
if missing_vars:
print("The following variables are missing from the IAM file:")
Expand Down Expand Up @@ -854,8 +855,12 @@ def __init__(

self.coal_power_plants = self.fetch_external_data_coal_power_plants()

self.battery_mobile_scenarios = self.fetch_external_data_battery_mobile_scenarios()
self.battery_stationary_scenarios = self.fetch_external_data_battery_stationary_scenarios()
self.battery_mobile_scenarios = (
self.fetch_external_data_battery_mobile_scenarios()
)
self.battery_stationary_scenarios = (
self.fetch_external_data_battery_stationary_scenarios()
)

def fetch_external_data_battery_mobile_scenarios(self):
"""
Expand Down Expand Up @@ -898,7 +903,9 @@ def fetch_external_data_battery_mobile_scenarios(self):
.to_xarray()
)

def fetch_external_data_battery_stationary_scenarios(self, exclude_chemistries = ["NAS"]):
def fetch_external_data_battery_stationary_scenarios(
self, exclude_chemistries=["NAS"]
):
"""
Fetch external data on stationary battery scenarios.
"""
Expand All @@ -916,30 +923,34 @@ def fetch_external_data_battery_stationary_scenarios(self, exclude_chemistries =
if exclude_chemistries is not None:
data = data[~data["chemistry"].isin(exclude_chemistries)]

grouped_data = data.groupby(
[
"scenario",
"chemistry",
"year",
]
)['value'].sum().reset_index()
grouped_data = (
data.groupby(
[
"scenario",
"chemistry",
"year",
]
)["value"]
.sum()
.reset_index()
)

total_shares = grouped_data.groupby(['scenario', 'year'])['value'].sum().reset_index()
total_shares = total_shares.rename(columns={'value': 'total_share'})
total_shares = (
grouped_data.groupby(["scenario", "year"])["value"].sum().reset_index()
)
total_shares = total_shares.rename(columns={"value": "total_share"})

merged_data = pd.merge(grouped_data, total_shares, on=['scenario', 'year'])
merged_data = pd.merge(grouped_data, total_shares, on=["scenario", "year"])

# Scale the remaining shares so that they sum up to one
merged_data['scaled_value'] = merged_data['value'] / merged_data['total_share']
merged_data["scaled_value"] = merged_data["value"] / merged_data["total_share"]

xarray_data = (
merged_data.set_index(['scenario', 'chemistry', 'year'])['scaled_value']
.to_xarray()
)
xarray_data = merged_data.set_index(["scenario", "chemistry", "year"])[
"scaled_value"
].to_xarray()

return xarray_data


def __get_iam_variable_labels(
self, filepath: Path, variable: str
) -> Dict[str, Union[str, List[str]]]:
Expand Down
4 changes: 3 additions & 1 deletion premise/new_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@
FILEPATH_CSP = INVENTORY_DIR / "lci-concentrating-solar-power.xlsx"
FILEPATH_HOME_STORAGE_BATTERIES = INVENTORY_DIR / "lci-home-batteries.xlsx"
FILEPATH_VANADIUM = INVENTORY_DIR / "lci-batteries-vanadium.xlsx"
FILEPATH_VANADIUM_REDOX_BATTERY = INVENTORY_DIR / "lci-batteries-vanadium-redox-flow.xlsx"
FILEPATH_VANADIUM_REDOX_BATTERY = (
INVENTORY_DIR / "lci-batteries-vanadium-redox-flow.xlsx"
)
FILEPATH_SIB_BATTERY = INVENTORY_DIR / "lci-batteries-SIB.xlsx"
FILEPATH_HYDROGEN_TURBINE = INVENTORY_DIR / "lci-hydrogen-turbine.xlsx"
FILEPATH_HYDROGEN_HEATING = INVENTORY_DIR / "lci-hydrogen-heating.xlsx"
Expand Down

0 comments on commit 4f487b0

Please sign in to comment.