Skip to content

Commit

Permalink
style: run black
Browse files Browse the repository at this point in the history
  • Loading branch information
BainanXia committed Dec 16, 2020
1 parent 7a27cff commit d254ab1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
12 changes: 4 additions & 8 deletions prereise/gather/demanddata/eia/map_ba.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def get_demand_in_loadzone(agg_demand, bus_map):
:return: (*pandas.DataFrame*) -- data frame with demand columns according
to load zone.
"""
ba_agg = bus_map[["BA", "Pd"]].groupby("BA")\
.sum().rename(columns={"Pd": "PdTotal"})
ba_agg = bus_map[["BA", "Pd"]].groupby("BA").sum().rename(columns={"Pd": "PdTotal"})

ba_scaling_factor = bus_map.merge(ba_agg, left_on="BA", right_on="BA")
ba_scaling_factor = ba_scaling_factor.assign(
Expand All @@ -55,13 +54,11 @@ def get_demand_in_loadzone(agg_demand, bus_map):
for zone_name in zone_scaling_df.index.get_level_values(0).to_list():
if zone_name in zone_demand.columns.to_list():
zone_demand[zone_name] += (
zone_scaling_df.loc[zone_name, "zone_scaling"]
* agg_demand[ba_name]
zone_scaling_df.loc[zone_name, "zone_scaling"] * agg_demand[ba_name]
)
else:
zone_demand[zone_name] = (
zone_scaling_df.loc[zone_name, "zone_scaling"]
* agg_demand[ba_name]
zone_scaling_df.loc[zone_name, "zone_scaling"] * agg_demand[ba_name]
)
return zone_demand

Expand All @@ -83,8 +80,7 @@ def map_buses_to_county(bus_county_map):
bus_county_map.loc[:, "County"] = None
bus_county_map.loc[:, "BA"] = None
bus_no_county_match = []
for index, row in tqdm(bus_county_map.iterrows(),
total=len(bus_county_map)):
for index, row in tqdm(bus_county_map.iterrows(), total=len(bus_county_map)):
params = {
"latitude": row["lat"],
"longitude": row["lon"],
Expand Down
2 changes: 1 addition & 1 deletion prereise/gather/demanddata/eia/tests/test_map_ba.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from pandas.testing import assert_series_equal

from prereise.gather.demanddata.eia.map_ba import (
get_demand_in_loadzone,
aggregate_ba_demand,
get_demand_in_loadzone,
)


Expand Down
3 changes: 1 addition & 2 deletions prereise/gather/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def get_monthly_net_generation(state, eia_form_923, resource, hps=True):
# Get monthly total net generation by summing up across plants
# with all positive values. Note that negative ones are included in
# actual demand.
eia_net_generation = list(net_generation.apply(lambda x: x[x > 0]
.sum()).values)
eia_net_generation = list(net_generation.apply(lambda x: x[x > 0].sum()).values)

# If there is no such generator in the state, the function will return
# a list of 0 instead of NaN.
Expand Down
11 changes: 5 additions & 6 deletions prereise/gather/hydrodata/eia/decompose_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,17 @@ def get_profile_by_plant(plant_df, total_profile):
raise TypeError("total_profile must be a pandas.Series object")
if not all([float(val) == val for val in total_profile]):
raise TypeError("total_profile must be all numbers")
if 'Pmax' not in plant_df.columns:
if "Pmax" not in plant_df.columns:
raise ValueError("Pmax must be one of the columns of plant_df")

total_hydro_capacity = plant_df['Pmax'].sum()
res_profile = pd.DataFrame(index=total_profile.index,
columns=plant_df.index)
total_hydro_capacity = plant_df["Pmax"].sum()
res_profile = pd.DataFrame(index=total_profile.index, columns=plant_df.index)

for plantid in res_profile.columns:
if total_hydro_capacity == 0:
factor = 0
else:
factor = plant_df.loc[plantid]['Pmax']/total_hydro_capacity
plant_profile = [val*factor for val in total_profile]
factor = plant_df.loc[plantid]["Pmax"] / total_hydro_capacity
plant_profile = [val * factor for val in total_profile]
res_profile[plantid] = plant_profile.copy()
return res_profile
5 changes: 3 additions & 2 deletions prereise/gather/hydrodata/eia/net_demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def get_net_demand_profile(state, scenario):
wind_in_state = wind[wind_plant_in_state].sum(axis=1)
solar_in_state = solar[solar_plant_in_state].sum(axis=1)

loadzone_in_state = [grid.zone2id[z] for z in abv2loadzone[state] if z
in grid.zone2id]
loadzone_in_state = [
grid.zone2id[z] for z in abv2loadzone[state] if z in grid.zone2id
]
demand_in_state = demand[loadzone_in_state].sum(axis=1)
net_demand_in_state = demand_in_state - wind_in_state - solar_in_state

Expand Down
5 changes: 3 additions & 2 deletions prereise/gather/hydrodata/eia/tests/test_decompose_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import pandas as pd
import pytest

from prereise.gather.hydrodata.eia.decompose_profile import \
get_profile_by_state
from prereise.gather.hydrodata.eia.decompose_profile import (
get_profile_by_state,
)


def test_get_profile_argument_type():
Expand Down

0 comments on commit d254ab1

Please sign in to comment.