Merge pull request #748 from PyPSA/follow-up-637

follow-up to #637: remove duplicate code and update tsam version
This commit is contained in:
Fabian Neumann 2023-10-18 10:27:29 +02:00 committed by GitHub
commit 7884392326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 1 additions and 29 deletions

View File

@ -55,5 +55,5 @@ dependencies:
- pip: - pip:
- git+https://github.com/fneum/tsam.git@performance - tsam>=2.3.1
- pypsa>=0.25.2 - pypsa>=0.25.2

View File

@ -120,7 +120,6 @@ def add_brownfield(n, n_p, year):
n.links.loc[new_pipes, "p_nom_min"] = 0.0 n.links.loc[new_pipes, "p_nom_min"] = 0.0
# %%
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake

View File

@ -630,7 +630,6 @@ def add_heating_capacities_installed_before_baseyear(
n.mremove("Link", links_i) n.mremove("Link", links_i)
# %%
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake

View File

@ -96,23 +96,6 @@ def prepare_hotmaps_database(regions):
gdf.rename(columns={"index_right": "bus"}, inplace=True) gdf.rename(columns={"index_right": "bus"}, inplace=True)
gdf["country"] = gdf.bus.str[:2] gdf["country"] = gdf.bus.str[:2]
# the .sjoin can lead to duplicates if a geom is in two regions
if gdf.index.duplicated().any():
import pycountry
# get all duplicated entries
duplicated_i = gdf.index[gdf.index.duplicated()]
# convert from raw data country name to iso-2-code
s = df.loc[duplicated_i, "Country"].apply(
lambda x: pycountry.countries.lookup(x).alpha_2
)
# Get a boolean mask where gdf's country column matches s's values for the same index
mask = gdf["country"] == gdf.index.map(s)
# Filter gdf using the mask
gdf_filtered = gdf[mask]
# concat not duplicated and filtered gdf
gdf = pd.concat([gdf.drop(duplicated_i), gdf_filtered]).sort_index()
# the .sjoin can lead to duplicates if a geom is in two overlapping regions # the .sjoin can lead to duplicates if a geom is in two overlapping regions
if gdf.index.duplicated().any(): if gdf.index.duplicated().any():
# get all duplicated entries # get all duplicated entries
@ -164,7 +147,6 @@ def build_nodal_distribution_key(hotmaps, regions, countries):
return keys return keys
# %%
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake

View File

@ -706,7 +706,6 @@ def to_csv(df):
df[key].to_csv(snakemake.output[key]) df[key].to_csv(snakemake.output[key])
# %%
if __name__ == "__main__": if __name__ == "__main__":
# Detect running outside of snakemake and mock snakemake for testing # Detect running outside of snakemake and mock snakemake for testing
if "snakemake" not in globals(): if "snakemake" not in globals():

View File

@ -1060,7 +1060,6 @@ def plot_map_perfect(
) )
# %%
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake

View File

@ -33,8 +33,6 @@ if __name__ == "__main__":
lambda s: s != "", "lightgrey" lambda s: s != "", "lightgrey"
) )
# %%
def rename_index(ds): def rename_index(ds):
specific = ds.index.map(lambda x: f"{x[1]}\n({x[0]})") specific = ds.index.map(lambda x: f"{x[1]}\n({x[0]})")
generic = ds.index.get_level_values("carrier") generic = ds.index.get_level_values("carrier")

View File

@ -564,7 +564,6 @@ def plot_carbon_budget_distribution(input_eurostat):
plt.savefig(path, bbox_inches="tight") plt.savefig(path, bbox_inches="tight")
# %%
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake

View File

@ -274,7 +274,6 @@ def set_line_nom_max(
n.links.p_nom_max.clip(upper=p_nom_max_set, inplace=True) n.links.p_nom_max.clip(upper=p_nom_max_set, inplace=True)
# %%
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake

View File

@ -493,7 +493,6 @@ def set_temporal_aggregation_SEG(n, opts, solver_name):
return n return n
# %%
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake

View File

@ -844,7 +844,6 @@ def solve_network(n, config, solving, opts="", **kwargs):
return n return n
# %%
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake