From 174ff6eae1db7f81bf3fe6de3fe1cb8b5c508576 Mon Sep 17 00:00:00 2001 From: trevorb1 Date: Wed, 20 Nov 2024 15:00:37 -0800 Subject: [PATCH 1/2] comment out docformatter --- .pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b33c3a50..10cd6a52 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 From c4e3055bdc5ae304dbd0b6188f65990795f1bf23 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 23:04:22 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- workflow/run_slurm.sh | 2 +- workflow/scripts/add_electricity.py | 15 +++++++++------ workflow/scripts/build_fuel_prices.py | 6 +++--- workflow/scripts/cluster_network.py | 16 ++++++++++------ workflow/scripts/plot_validation_production.py | 9 ++++++--- workflow/scripts/solve_network.py | 2 +- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/workflow/run_slurm.sh b/workflow/run_slurm.sh index 80f93b83..c6426953 100644 --- a/workflow/run_slurm.sh +++ b/workflow/run_slurm.sh @@ -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 \ No newline at end of file +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 diff --git a/workflow/scripts/add_electricity.py b/workflow/scripts/add_electricity.py index 00be2457..0ce70619 100755 --- a/workflow/scripts/add_electricity.py +++ b/workflow/scripts/add_electricity.py @@ -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 @@ -292,7 +293,7 @@ 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"]) @@ -300,8 +301,10 @@ def match_plant_to_bus(n, plants): # 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)) diff --git a/workflow/scripts/build_fuel_prices.py b/workflow/scripts/build_fuel_prices.py index 8d00b837..fceb22c8 100644 --- a/workflow/scripts/build_fuel_prices.py +++ b/workflow/scripts/build_fuel_prices.py @@ -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) + "_" diff --git a/workflow/scripts/cluster_network.py b/workflow/scripts/cluster_network.py index f5a2b051..7b69f4a0 100644 --- a/workflow/scripts/cluster_network.py +++ b/workflow/scripts/cluster_network.py @@ -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() @@ -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", ) @@ -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", ) @@ -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", ) @@ -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( diff --git a/workflow/scripts/plot_validation_production.py b/workflow/scripts/plot_validation_production.py index 02441669..b4e0950a 100644 --- a/workflow/scripts/plot_validation_production.py +++ b/workflow/scripts/plot_validation_production.py @@ -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, @@ -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", @@ -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, diff --git a/workflow/scripts/solve_network.py b/workflow/scripts/solve_network.py index f405c2d6..fa52ee86 100644 --- a/workflow/scripts/solve_network.py +++ b/workflow/scripts/solve_network.py @@ -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)