Skip to content

Commit

Permalink
Merge pull request #336 from pypsa-meets-earth/Params_build_industria…
Browse files Browse the repository at this point in the history
…l_distribution_key

Add Params to build_industrial_distribution_key
  • Loading branch information
energyLS authored Jun 12, 2024
2 parents 44716a8 + b188350 commit 14a8088
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
5 changes: 5 additions & 0 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,11 @@ rule clean:


rule build_industrial_distribution_key: #default data
params:
countries=config["countries"],
gadm_level=config["sector"]["gadm_level"],
alternative_clustering=config["clustering_options"]["alternative_clustering"],
industry_database=config["custom_data"]["industry_database"],
input:
regions_onshore=pypsaearth(
"resources/bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
Expand Down
31 changes: 17 additions & 14 deletions scripts/build_industrial_distribution_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
gpd_version = StrictVersion(gpd.__version__)


def map_industry_to_buses(df):
def map_industry_to_buses(df, countries, gadm_level, shapes_path, gadm_clustering):
"""
Load hotmaps database of industrial sites and map onto bus regions.
Build industrial demand... Change name and add other functions.
Function similar to aviation/shipping. Use functions to disaggregate.
Only cement not steel - proof of concept.
Change hotmaps to more descriptive name, etc.
"""
df = df[df.country.isin(snakemake.config["countries"])]
df = df[df.country.isin(countries)]
df["gadm_{}".format(gadm_level)] = df[["x", "y", "country"]].apply(
lambda site: locate_bus(
site[["x", "y"]].astype("float"),
Expand All @@ -36,11 +36,11 @@ def map_industry_to_buses(df):
axis=1,
)

return df.set_index("gadm_" + str(snakemake.config["sector"]["gadm_level"]))
return df.set_index("gadm_" + str(gadm_level))


def build_nodal_distribution_key(
industrial_database, regions
industrial_database, regions, industry, countries
): # returns percentage of co2 emissions
"""Build nodal distribution keys for each sector."""

Expand Down Expand Up @@ -123,12 +123,12 @@ def match_technology(df):
)
sets_path_to_root("pypsa-earth-sec")

options = snakemake.config["sector"]
gadm_level = options["gadm_level"]

regions = gpd.read_file(snakemake.input.regions_onshore)
shapes_path = snakemake.input.shapes_path

countries = snakemake.config["countries"]
gadm_level = snakemake.params.gadm_level
countries = snakemake.params.countries
gadm_clustering = snakemake.params.alternative_clustering

# countries = ["EG", "BH"]

Expand All @@ -139,7 +139,7 @@ def match_technology(df):
lambda name: three_2_two_digits_country(name[:3]) + name[3:]
)

if snakemake.config["custom_data"]["industry_database"]:
if snakemake.params.industry_database:
logger.info(
"Using custom industry database from 'data_custom/industrial_database.csv' instead of default"
)
Expand All @@ -166,17 +166,20 @@ def match_technology(df):

geo_locs.capacity = pd.to_numeric(geo_locs.capacity)

gadm_clustering = snakemake.config["clustering_options"]["alternative_clustering"]

geo_locs = geo_locs[geo_locs.quality != "nonexistent"]

industry = geo_locs.industry.unique()

shapes_path = snakemake.input.shapes_path
industrial_database = map_industry_to_buses(
geo_locs[geo_locs.quality != "unavailable"]
geo_locs[geo_locs.quality != "unavailable"],
countries,
gadm_level,
shapes_path,
gadm_clustering,
)

keys = build_nodal_distribution_key(industrial_database, regions)
keys = build_nodal_distribution_key(
industrial_database, regions, industry, countries
)

keys.to_csv(snakemake.output.industrial_distribution_key)

0 comments on commit 14a8088

Please sign in to comment.