allow to disable progressbar

This commit is contained in:
Fabian 2023-03-07 20:37:47 +01:00
parent d45bee628e
commit 104fc68fb0
13 changed files with 35 additions and 13 deletions

View File

@ -25,7 +25,7 @@ CDIR = RDIR if not run.get("shared_cutouts") else ""
LOGS = "logs/" + RDIR LOGS = "logs/" + RDIR
BENCHMARKS = "benchmarks/" + RDIR BENCHMARKS = "benchmarks/" + RDIR
RESOURCES = "resources/" + RDIR if run.get("shared_resources") else "resources/" RESOURCES = "resources/" + RDIR if not run.get("shared_resources") else "resources/"
RESULTS = "results/" + RDIR RESULTS = "results/" + RDIR

View File

@ -11,6 +11,7 @@ logging:
run: run:
name: "" # use this to keep track of runs with different settings name: "" # use this to keep track of runs with different settings
disable_progressbar: false # set to true to disable the progressbar
shared_resources: false # set to true to share the default resources across runs shared_resources: false # set to true to share the default resources across runs
shared_cutouts: false # set to true to share the default cutout(s) across runs shared_cutouts: false # set to true to share the default cutout(s) across runs

View File

@ -264,7 +264,10 @@ def aggregate_costs(n, flatten=False, opts=None, existing_only=False):
return costs return costs
def progress_retrieve(url, file): def progress_retrieve(url, file, disable=False):
if disable:
urllib.request.urlretrieve(url, file)
else:
with tqdm(unit="B", unit_scale=True, unit_divisor=1024, miniters=1) as t: with tqdm(unit="B", unit_scale=True, unit_divisor=1024, miniters=1) as t:
def update_to(b=1, bsize=1, tsize=None): def update_to(b=1, bsize=1, tsize=None):

View File

@ -398,6 +398,7 @@ def idees_per_country(ct, year, base_dir):
def build_idees(countries, year): def build_idees(countries, year):
nprocesses = snakemake.threads nprocesses = snakemake.threads
disable_progress = snakemake.config["run"].get("disable_progressbar", False)
func = partial(idees_per_country, year=year, base_dir=snakemake.input.idees) func = partial(idees_per_country, year=year, base_dir=snakemake.input.idees)
tqdm_kwargs = dict( tqdm_kwargs = dict(
@ -405,6 +406,7 @@ def build_idees(countries, year):
unit=" country", unit=" country",
total=len(countries), total=len(countries),
desc="Build from IDEES database", desc="Build from IDEES database",
disable=disable_progress,
) )
with mute_print(): with mute_print():
with mp.Pool(processes=nprocesses) as pool: with mp.Pool(processes=nprocesses) as pool:

View File

@ -179,6 +179,7 @@ def add_non_eu28_industrial_energy_demand(demand):
def industrial_energy_demand(countries, year): def industrial_energy_demand(countries, year):
nprocesses = snakemake.threads nprocesses = snakemake.threads
disable_progress = snakemake.config["run"].get("disable_progressbar", False)
func = partial( func = partial(
industrial_energy_demand_per_country, year=year, jrc_dir=snakemake.input.jrc industrial_energy_demand_per_country, year=year, jrc_dir=snakemake.input.jrc
) )
@ -187,6 +188,7 @@ def industrial_energy_demand(countries, year):
unit=" country", unit=" country",
total=len(countries), total=len(countries),
desc="Build industrial energy demand", desc="Build industrial energy demand",
disable=disable_progress,
) )
with mp.Pool(processes=nprocesses) as pool: with mp.Pool(processes=nprocesses) as pool:
demand_l = list(tqdm(pool.imap(func, countries), **tqdm_kwargs)) demand_l = list(tqdm(pool.imap(func, countries), **tqdm_kwargs))

View File

@ -245,7 +245,9 @@ def industry_production_per_country(country, year, eurostat_dir, jrc_dir):
def industry_production(countries, year, eurostat_dir, jrc_dir): def industry_production(countries, year, eurostat_dir, jrc_dir):
nprocesses = 1 # snakemake.threads nprocesses = snakemake.threads
disable_progress = snakemake.config["run"].get("disable_progressbar", False)
func = partial( func = partial(
industry_production_per_country, industry_production_per_country,
year=year, year=year,
@ -257,6 +259,7 @@ def industry_production(countries, year, eurostat_dir, jrc_dir):
unit=" country", unit=" country",
total=len(countries), total=len(countries),
desc="Build industry production", desc="Build industry production",
disable=disable_progress,
) )
with mp.Pool(processes=nprocesses) as pool: with mp.Pool(processes=nprocesses) as pool:
demand_l = list(tqdm(pool.imap(func, countries), **tqdm_kwargs)) demand_l = list(tqdm(pool.imap(func, countries), **tqdm_kwargs))

View File

@ -204,7 +204,7 @@ if __name__ == "__main__":
configure_logging(snakemake) configure_logging(snakemake)
nprocesses = int(snakemake.threads) nprocesses = int(snakemake.threads)
noprogress = not snakemake.config["atlite"].get("show_progress", False) noprogress = snakemake.config["run"].get("disable_progressbar", True)
config = snakemake.config["renewable"][snakemake.wildcards.technology] config = snakemake.config["renewable"][snakemake.wildcards.technology]
resource = config["resource"] # pv panel config / wind turbine config resource = config["resource"] # pv panel config / wind turbine config
correction_factor = config.get("correction_factor", 1.0) correction_factor = config.get("correction_factor", 1.0)
@ -369,3 +369,4 @@ if __name__ == "__main__":
ds["profile"] = ds["profile"].where(ds["profile"] >= min_p_max_pu, 0) ds["profile"] = ds["profile"].where(ds["profile"] >= min_p_max_pu, 0)
ds.to_netcdf(snakemake.output.profile) ds.to_netcdf(snakemake.output.profile)
client.shutdown()

View File

@ -64,7 +64,8 @@ if __name__ == "__main__":
to_fn = Path(f"{rootpath}/data") to_fn = Path(f"{rootpath}/data")
logger.info(f"Downloading databundle from '{url}'.") logger.info(f"Downloading databundle from '{url}'.")
progress_retrieve(url, tarball_fn) disable_progress = snakemake.config["run"].get("disable_progressbar", False)
progress_retrieve(url, tarball_fn, disable=disable_progress)
logger.info("Extracting databundle.") logger.info("Extracting databundle.")
tarfile.open(tarball_fn).extractall(to_fn) tarfile.open(tarball_fn).extractall(to_fn)

View File

@ -32,7 +32,8 @@ if __name__ == "__main__":
to_fn = Path(f"{rootpath}/data/gas_network/scigrid-gas") to_fn = Path(f"{rootpath}/data/gas_network/scigrid-gas")
logger.info(f"Downloading databundle from '{url}'.") logger.info(f"Downloading databundle from '{url}'.")
progress_retrieve(url, zip_fn) disable_progress = snakemake.config["run"].get("disable_progressbar", False)
progress_retrieve(url, zip_fn, disable=disable_progress)
logger.info("Extracting databundle.") logger.info("Extracting databundle.")
zipfile.ZipFile(zip_fn).extractall(to_fn) zipfile.ZipFile(zip_fn).extractall(to_fn)

View File

@ -29,7 +29,8 @@ if __name__ == "__main__":
to_fn = Path("data") to_fn = Path("data")
logger.info(f"Downloading databundle from '{url}'.") logger.info(f"Downloading databundle from '{url}'.")
progress_retrieve(url, tarball_fn) disable_progress = snakemake.config["run"].get("disable_progressbar", False)
progress_retrieve(url, tarball_fn, disable=disable_progress)
logger.info("Extracting databundle.") logger.info("Extracting databundle.")
tarfile.open(tarball_fn).extractall(to_fn) tarfile.open(tarball_fn).extractall(to_fn)

View File

@ -2,8 +2,10 @@
# #
# SPDX-License-Identifier: CC0-1.0 # SPDX-License-Identifier: CC0-1.0
run: run:
name: "test-sector-myopic" name: "test-sector-myopic"
disable_progressbar: true
shared_resources: true shared_resources: true
shared_cutouts: true shared_cutouts: true

View File

@ -2,11 +2,14 @@
# #
# SPDX-License-Identifier: CC0-1.0 # SPDX-License-Identifier: CC0-1.0
run: run:
name: "test-sector-overnight" name: "test-sector-overnight"
disable_progressbar: true
shared_resources: true shared_resources: true
shared_cutouts: true shared_cutouts: true
scenario: scenario:
ll: ll:
- v1.5 - v1.5

View File

@ -4,8 +4,10 @@
tutorial: true tutorial: true
run: run:
name: "test-elec" # use this to keep track of runs with different settings name: "test-elec" # use this to keep track of runs with different settings
disable_progressbar: true
shared_resources: true shared_resources: true
shared_cutouts: true shared_cutouts: true