Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove broken pre-commit rule (docformatter) #476

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ repos:
hooks:
- id: snakefmt

- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
- id: docformatter
args: ["--in-place", "--make-summary-multi-line", "--pre-summary-newline"]
# - repo: https://github.com/PyCQA/docformatter
# rev: v1.7.5
# hooks:
# - id: docformatter
# args: ["--in-place", "--make-summary-multi-line", "--pre-summary-newline"]


- repo: https://github.com/keewis/blackdoc
Expand Down
2 changes: 1 addition & 1 deletion workflow/run_slurm.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# SLURM specifications made in default.cluster.yaml & the individual rules
# GRB_LICENSE_FILE=/share/software/user/restricted/gurobi/11.0.2/licenses/gurobi.lic⁠
snakemake --cluster "sbatch -A {cluster.account} --mail-type ALL --mail-user {cluster.email} -p {cluster.partition} -t {cluster.walltime} -o {cluster.output} -e {cluster.error} -c {threads} --mem {resources.mem_mb}" --cluster-config config/config.cluster.yaml --jobs 10 --latency-wait 60 --configfile config/base_paper/config.validation.yaml --rerun-incomplete -R build_powerplants
snakemake --cluster "sbatch -A {cluster.account} --mail-type ALL --mail-user {cluster.email} -p {cluster.partition} -t {cluster.walltime} -o {cluster.output} -e {cluster.error} -c {threads} --mem {resources.mem_mb}" --cluster-config config/config.cluster.yaml --jobs 10 --latency-wait 60 --configfile config/base_paper/config.validation.yaml --rerun-incomplete -R build_powerplants
15 changes: 9 additions & 6 deletions workflow/scripts/add_electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,17 @@ def match_nearest_bus(plants_subset, buses_subset):

# Create a BallTree for the given subset of buses
tree = BallTree(buses_subset[["x", "y"]].values, leaf_size=2)

# Find nearest bus for each plant in the subset
distances, indices = tree.query(plants_subset[["longitude", "latitude"]].values, k=1)

# Map the nearest bus information back to the plants subset
plants_subset["bus_assignment"] = buses_subset.reset_index().iloc[indices.flatten()]["Bus"].values
plants_subset["distance_nearest"] = distances.flatten()

return plants_subset


def match_plant_to_bus(n, plants):
"""
Matches each plant to it's corresponding bus in the network enfocing a
Expand All @@ -292,16 +293,18 @@ def match_plant_to_bus(n, plants):
plants_matched = plants.copy()
plants_matched["bus_assignment"] = None
plants_matched["distance_nearest"] = None

# Get a copy of buses and create a geometry column with GPS coordinates
buses = n.buses.copy()
buses["geometry"] = gpd.points_from_xy(buses["x"], buses["y"])

# First pass: Assign each plant to the nearest bus in the same state
for state in buses["state"].unique():
buses_in_state = buses[buses["state"] == state]
plants_in_state = plants_matched[(plants_matched["state"] == state) & (plants_matched["bus_assignment"].isnull())]

plants_in_state = plants_matched[
(plants_matched["state"] == state) & (plants_matched["bus_assignment"].isnull())
]

# Update plants_matched with the nearest bus within the same state
plants_matched.update(match_nearest_bus(plants_in_state, buses_in_state))

Expand Down
6 changes: 3 additions & 3 deletions workflow/scripts/build_fuel_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ def build_pudl_fuel_costs(snapshots: pd.DatetimeIndex, start_date: str, end_date
fuel_cost_temporal["interconnect"] = fuel_cost_temporal["nerc_region"].map(
const.NERC_REGION_MAPPER,
)
if snakemake.wildcards.interconnect != 'usa':

if snakemake.wildcards.interconnect != "usa":
fuel_cost_temporal = fuel_cost_temporal[fuel_cost_temporal["interconnect"] == snakemake.wildcards.interconnect]

fuel_cost_temporal["generator_name"] = (
fuel_cost_temporal["plant_name_eia"].astype(str)
+ "_"
Expand Down
16 changes: 10 additions & 6 deletions workflow/scripts/cluster_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def add_itls(buses, itls, itl_cost, expansion=True):
itls["USD2023perMWyr"] = 0

itls["p_min_pu_Rev"] = (-1 * (itls.mw_r0 / itls.mw_f0)).fillna(0)
itls['efficiency'] = 1- ((itls.length_miles/100) * 0.01)
itls["efficiency"] = 1 - ((itls.length_miles / 100) * 0.01)

# lines to add in reverse if forward direction is zero
itls_rev = itls[itls.mw_f0 == 0].copy()
Expand All @@ -363,7 +363,7 @@ def add_itls(buses, itls, itl_cost, expansion=True):
length=0 if itl_cost is None else itls_fwd.length_miles.values,
capital_cost=0 if itl_cost is None else itls_fwd.USD2023perMWyr.values,
p_nom_extendable=False,
efficiency= 1 if itl_cost is None else itls_fwd.efficiency.values,
efficiency=1 if itl_cost is None else itls_fwd.efficiency.values,
carrier="AC",
)

Expand All @@ -380,7 +380,7 @@ def add_itls(buses, itls, itl_cost, expansion=True):
length=0 if itl_cost is None else itls_rev.length_miles.values,
capital_cost=0 if itl_cost is None else itls_rev.USD2023perMWyr.values,
p_nom_extendable=False,
efficiency= 1 if itl_cost is None else itls_rev.efficiency.values,
efficiency=1 if itl_cost is None else itls_rev.efficiency.values,
carrier="AC",
)

Expand All @@ -401,7 +401,7 @@ def add_itls(buses, itls, itl_cost, expansion=True):
length=0 if itl_cost is None else itls.length_miles.values,
capital_cost=0 if itl_cost is None else itls.USD2023perMWyr.values,
p_nom_extendable=False,
efficiency= 1 if itl_cost is None else itls.efficiency.values,
efficiency=1 if itl_cost is None else itls.efficiency.values,
carrier="AC_exp",
)

Expand Down Expand Up @@ -511,8 +511,12 @@ def convert_to_transport(
)

# Dissolve TX for particular zones according to default reeds configurations
clustering.network.links.loc[clustering.network.links.bus0.isin(['p119']) & clustering.network.links.bus1.isin(['p122']), 'p_nom'] = 1e9
clustering.network.links.loc[clustering.network.links.bus1.isin(['p119']) & clustering.network.links.bus0.isin(['p122']), 'p_nom'] = 1e9
clustering.network.links.loc[
clustering.network.links.bus0.isin(["p119"]) & clustering.network.links.bus1.isin(["p122"]), "p_nom"
] = 1e9
clustering.network.links.loc[
clustering.network.links.bus1.isin(["p119"]) & clustering.network.links.bus0.isin(["p122"]), "p_nom"
] = 1e9
# Dissolve p124 and p99
if "p124" in clustering.network.buses.index and "p99" in clustering.network.buses.index:
clustering.network.add(
Expand Down
9 changes: 6 additions & 3 deletions workflow/scripts/plot_validation_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def plot_line_loading_map(
link_loading = n.links_t.p0.abs().mean() / n.links.p_nom / n.links.p_max_pu * 100
norm = plt.Normalize(vmin=0, vmax=100)

n.carriers.loc['AC_exp', 'color'] = '#dd2e23'
n.carriers.loc["AC_exp", "color"] = "#dd2e23"
fig, _ = plot_capacity_map(
n=n,
bus_values=gen / 5e3,
Expand Down Expand Up @@ -552,7 +552,10 @@ def plot_generator_cost_stack(

# Add a legend to the first subplot
fig.legend(
handles=[plt.Rectangle((0, 0), 1, 1, color=colors[carrier], label=carrier) for carrier in df_sorted["carrier"].unique()],
handles=[
plt.Rectangle((0, 0), 1, 1, color=colors[carrier], label=carrier)
for carrier in df_sorted["carrier"].unique()
],
loc="upper left",
bbox_to_anchor=(0.12, 0.875),
title="Carrier",
Expand Down Expand Up @@ -625,7 +628,7 @@ def plot_state_emissions_historical_bar(

# final = final[~final["state"].str.contains("Texas")]
final.to_csv(save.replace(".pdf", ".csv"))

fig, ax = plt.subplots(figsize=(8, 8))
sns.barplot(
data=final,
Expand Down
2 changes: 1 addition & 1 deletion workflow/scripts/solve_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def add_land_use_constraints(n):

if generators.empty:
return

p_nom = n.model["Generator-p_nom"].loc[generators.index]

grouper = pd.concat([generators.carrier, generators.land_region], axis=1)
Expand Down