Merge pull request #845 from PyPSA/performance-ship-raster
`build_ship_raster` performance improvements
This commit is contained in:
commit
ac9f0bf797
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import os, sys, glob
|
import os, sys, glob
|
||||||
|
|
||||||
helper_source_path = [match for match in glob.glob('**/_helpers.py', recursive=True)]
|
helper_source_path = [match for match in glob.glob("**/_helpers.py", recursive=True)]
|
||||||
|
|
||||||
for path in helper_source_path:
|
for path in helper_source_path:
|
||||||
path = os.path.dirname(os.path.abspath(path))
|
path = os.path.dirname(os.path.abspath(path))
|
||||||
|
@ -133,9 +133,7 @@ def disable_grid_expansion_if_LV_limit_hit(n):
|
|||||||
|
|
||||||
# allow small numerical differences
|
# allow small numerical differences
|
||||||
if lv_limit - total_expansion < 1:
|
if lv_limit - total_expansion < 1:
|
||||||
logger.info(
|
logger.info(f"LV is already reached, disabling expansion and LV limit")
|
||||||
f"LV is already reached, disabling expansion and LV limit"
|
|
||||||
)
|
|
||||||
extendable_acs = n.lines.query("s_nom_extendable").index
|
extendable_acs = n.lines.query("s_nom_extendable").index
|
||||||
n.lines.loc[extendable_acs, "s_nom_extendable"] = False
|
n.lines.loc[extendable_acs, "s_nom_extendable"] = False
|
||||||
n.lines.loc[extendable_acs, "s_nom"] = n.lines.loc[extendable_acs, "s_nom_min"]
|
n.lines.loc[extendable_acs, "s_nom"] = n.lines.loc[extendable_acs, "s_nom_min"]
|
||||||
|
@ -42,8 +42,8 @@ Description
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import zipfile
|
import zipfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import rioxarray
|
import rioxarray
|
||||||
from _helpers import configure_logging
|
from _helpers import configure_logging
|
||||||
@ -62,11 +62,13 @@ if __name__ == "__main__":
|
|||||||
xs, Xs, ys, Ys = zip(*(determine_cutout_xXyY(cutout) for cutout in cutouts))
|
xs, Xs, ys, Ys = zip(*(determine_cutout_xXyY(cutout) for cutout in cutouts))
|
||||||
|
|
||||||
with zipfile.ZipFile(snakemake.input.ship_density) as zip_f:
|
with zipfile.ZipFile(snakemake.input.ship_density) as zip_f:
|
||||||
zip_f.extract("shipdensity_global.tif")
|
resources = Path(snakemake.output[0]).parent
|
||||||
with rioxarray.open_rasterio("shipdensity_global.tif") as ship_density:
|
fn = "shipdensity_global.tif"
|
||||||
|
zip_f.extract(fn, resources)
|
||||||
|
with rioxarray.open_rasterio(resources / fn) as ship_density:
|
||||||
ship_density = ship_density.drop_vars(["band"]).sel(
|
ship_density = ship_density.drop_vars(["band"]).sel(
|
||||||
x=slice(min(xs), max(Xs)), y=slice(max(Ys), min(ys))
|
x=slice(min(xs), max(Xs)), y=slice(max(Ys), min(ys))
|
||||||
)
|
)
|
||||||
ship_density.rio.to_raster(snakemake.output[0])
|
ship_density.rio.to_raster(snakemake.output[0])
|
||||||
|
|
||||||
os.remove("shipdensity_global.tif")
|
(resources / fn).unlink()
|
||||||
|
@ -3000,8 +3000,9 @@ def add_industry(n, costs):
|
|||||||
|
|
||||||
if options["co2_spatial"] or options["co2network"]:
|
if options["co2_spatial"] or options["co2network"]:
|
||||||
p_set = (
|
p_set = (
|
||||||
-industrial_demand.loc[nodes, "process emission"]
|
-industrial_demand.loc[nodes, "process emission"].rename(
|
||||||
.rename(index=lambda x: x + " process emissions")
|
index=lambda x: x + " process emissions"
|
||||||
|
)
|
||||||
/ nhours
|
/ nhours
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@ -3414,6 +3415,7 @@ def cluster_heat_buses(n):
|
|||||||
pnl = c.pnl
|
pnl = c.pnl
|
||||||
agg = define_clustering(pd.Index(pnl.keys()), aggregate_dict)
|
agg = define_clustering(pd.Index(pnl.keys()), aggregate_dict)
|
||||||
for k in pnl.keys():
|
for k in pnl.keys():
|
||||||
|
|
||||||
def renamer(s):
|
def renamer(s):
|
||||||
return s.replace("residential ", "").replace("services ", "")
|
return s.replace("residential ", "").replace("services ", "")
|
||||||
|
|
||||||
|
@ -856,7 +856,7 @@ def solve_network(n, config, solving, opts="", **kwargs):
|
|||||||
kwargs["assign_all_duals"] = cf_solving.get("assign_all_duals", False)
|
kwargs["assign_all_duals"] = cf_solving.get("assign_all_duals", False)
|
||||||
|
|
||||||
if kwargs["solver_name"] == "gurobi":
|
if kwargs["solver_name"] == "gurobi":
|
||||||
logging.getLogger('gurobipy').setLevel(logging.CRITICAL)
|
logging.getLogger("gurobipy").setLevel(logging.CRITICAL)
|
||||||
|
|
||||||
rolling_horizon = cf_solving.pop("rolling_horizon", False)
|
rolling_horizon = cf_solving.pop("rolling_horizon", False)
|
||||||
skip_iterations = cf_solving.pop("skip_iterations", False)
|
skip_iterations = cf_solving.pop("skip_iterations", False)
|
||||||
|
Loading…
Reference in New Issue
Block a user