From 2d8e66a21346a764576f6b2a1998f2bc8eb6230c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20J=C3=A4hn?= Date: Thu, 21 Sep 2023 14:28:38 +0200 Subject: [PATCH] Move times to config file --- cases/cosmo-ghg-11km-test/config.yaml | 3 ++ jobs/int2lm.py | 38 +++++++++++----------- run_chain.py | 45 ++++++++++----------------- 3 files changed, 39 insertions(+), 47 deletions(-) diff --git a/cases/cosmo-ghg-11km-test/config.yaml b/cases/cosmo-ghg-11km-test/config.yaml index 58165cdf..a82dd4a2 100644 --- a/cases/cosmo-ghg-11km-test/config.yaml +++ b/cases/cosmo-ghg-11km-test/config.yaml @@ -5,6 +5,9 @@ constraint: gpu restart_step: 12 variant: spinup spinup: 6 +startdate: 2015-01-01T00:00:00Z +hstart: 0 +hstop: 24 meteo: dir: ./input/cosmo-ghg/meteo diff --git a/jobs/int2lm.py b/jobs/int2lm.py index b57da79a..b61c50f3 100644 --- a/jobs/int2lm.py +++ b/jobs/int2lm.py @@ -26,16 +26,16 @@ def main(starttime, hstart, hstop, cfg, model_cfg): ``startdate`` of the simulation. Create necessary directory structure to run **int2lm** (run and output - directories, defined in ``cfg.int2lm`` and ``cfg.int2lm_output``). + directories, defined in ``cfg.int2lm`` and ``cfg.int2lm['output']``). - Copy the **int2lm**-executable from ``cfg.int2lm_bin`` to - ``cfg.int2lm_work/int2lm``. + Copy the **int2lm**-executable from ``cfg.int2lm['bin']`` to + ``cfg.int2lm['work']/int2lm``. Copy the extpar-file ``cfg.int2lm['extpar_file']`` to ``cfg.int2lm_run/work``. **COSMOART**: Copy the ``libgrib_api`` files to - ``cfg.int2lm_work/libgrib_api``. + ``cfg.int2lm['work']/libgrib_api``. **COSMO**: Convert the tracer-csv-files into a **int2lm**-namelist file. @@ -58,36 +58,35 @@ def main(starttime, hstart, hstop, cfg, model_cfg): logfile_finish = os.path.join(cfg.log_finished_dir, "int2lm") # Create int2lm directory - tools.create_dir(cfg.int2lm_work, "int2lm_work") - tools.create_dir(cfg.int2lm_output, "int2lm_output") + tools.create_dir(cfg.int2lm['work'], "int2lm_work") + tools.create_dir(cfg.int2lm['output'], "int2lm_output") - tools.copy_file(cfg.int2lm_bin, os.path.join(cfg.int2lm_work, "int2lm")) + tools.copy_file(cfg.int2lm['bin'], os.path.join(cfg.int2lm['work'], "int2lm")) # Copy extpar file to input/extpar directory - extpar_dir = os.path.join(cfg.int2lm_input, "extpar") - extpar_file = os.path.join(cfg.int2lm_extpar_dir, cfg.int2lm_extpar_file) + extpar_dir = os.path.join(cfg.int2lm['input'], "extpar") tools.create_dir(extpar_dir, "int2lm extpar") - tools.copy_file(extpar_file, extpar_dir) + tools.copy_file(cfg.int2lm['extpar_file'], extpar_dir) # Copy landuse and plant-functional-type files if cfg.model == 'cosmo-art': - lu_file_src = os.path.join(cfg.int2lm_lu_dir, cfg.int2lm_lu_file) + lu_file_src = os.path.join(cfg.int2lm['lu_dir'], cfg.int2lm_lu_file) lu_file_dst = os.path.join(extpar_dir, 'landuse.nc') tools.copy_file(lu_file_src, lu_file_dst) - pft_file_src = os.path.join(cfg.int2lm_pft_dir, cfg.int2lm_pft_file) + pft_file_src = os.path.join(cfg.int2lm['pft_dir'], cfg.int2lm_pft_file) pft_file_dst = os.path.join(extpar_dir, 'pft.nc') tools.copy_file(pft_file_src, pft_file_dst) # Copy libgrib_api - dest = os.path.join(cfg.int2lm_work, 'libgrib_api') + dest = os.path.join(cfg.int2lm['work'], 'libgrib_api') try: # delete so no error when forcing this job shutil.rmtree(dest) except FileNotFoundError: pass try: - shutil.copytree(src=cfg.int2lm_libgrib_dir, + shutil.copytree(src=cfg.int2lm['libgrib_dir'], dst=dest, symlinks=True) except FileNotFoundError: @@ -103,13 +102,13 @@ def main(starttime, hstart, hstop, cfg, model_cfg): if os.path.isfile(tracer_csvfile): datasets_csvfile = os.path.join(cfg.chain_src_dir, 'cases', cfg.casename, 'int2lm_datasets.csv') - input_art_filename = os.path.join(cfg.int2lm_work, 'INPUT_ART') + input_art_filename = os.path.join(cfg.int2lm['work'], 'INPUT_ART') tools.write_int2lm_input_art.main(tracer_csvfile, datasets_csvfile, input_art_filename) # Prepare namelist - with open(cfg.int2lm_namelist) as input_file: + with open(cfg.int2lm['namelist']) as input_file: to_write = input_file.read() # Change of soil model from TERRA to TERRA multi-layer on 2 Aug 2007 @@ -117,7 +116,7 @@ def main(starttime, hstart, hstop, cfg, model_cfg): multi_layer = ".FALSE." else: multi_layer = ".TRUE." - output_file = os.path.join(cfg.int2lm_work, "INPUT") + output_file = os.path.join(cfg.int2lm['work'], "INPUT") with open(output_file, "w") as outf: outf.write(to_write.format(cfg=cfg, multi_layer=multi_layer)) @@ -125,7 +124,7 @@ def main(starttime, hstart, hstop, cfg, model_cfg): with open(cfg.int2lm_runjob) as input_file: to_write = input_file.read() - output_file = os.path.join(cfg.int2lm_work, "run.job") + output_file = os.path.join(cfg.int2lm['work'], "run.job") with open(output_file, "w") as outf: outf.write( to_write.format(cfg=cfg, @@ -137,7 +136,8 @@ def main(starttime, hstart, hstop, cfg, model_cfg): # Submit job result = subprocess.run( ["sbatch", "--wait", - os.path.join(cfg.int2lm_work, "run.job")]) + os.path.join(cfg.int2lm['work'], "run.job")]) exitcode = result.returncode if exitcode != 0: raise RuntimeError("sbatch returned exitcode {}".format(exitcode)) + diff --git a/run_chain.py b/run_chain.py index 3b9c1654..2a975d8c 100755 --- a/run_chain.py +++ b/run_chain.py @@ -33,20 +33,6 @@ def parse_arguments(): "to be in cases//. The runs are executed " "sequentially in the order they're given here.") - times_help = ("Triplet of {date hstart hstop} | " - "date: Startdate of the run in the format " - "yyyy-mm-dd | " - "hstart: Time on the startdate when the " - "simulation starts. If this is zero, the " - "simulation starts at midnight of the +startdate. | " - "hstop: Length of the simulation in hours. The " - "simulation runs until startdate + hstart + " - "hstop. Depending on your config.py settings, " - "processing-chain will split up the simulation " - "and perform several restarts before reaching the " - "stopping-time.") - parser.add_argument("times", nargs=3, help=times_help) - jobs_help = ("List of job-names to be executed. A job is a .py-" "file in jobs/ with a main()-function which " "handles one aspect of the processing chain, for " @@ -80,9 +66,6 @@ def parse_arguments(): default=1) args = parser.parse_args() - args.startdate = args.times[0] - args.hstart = int(args.times[1]) - args.hstop = int(args.times[2]) return args @@ -196,6 +179,12 @@ def set_job_variables(self): if hasattr(self, 'cosmo'): self.cosmo['execname'] = self.model.lower() + return self + + def set_attributes_time(self): + + + return self def print_config(self): @@ -266,7 +255,7 @@ def run_chain(work_root, model_cfg, cfg, start_time, hstart, hstop, job_names, """ # ini date and forecast time (ignore meteo times) - inidate = int((start_time - datetime(1970, 1, 1)).total_seconds()) + inidate = start_time inidate_yyyymmddhh = start_time.strftime('%Y%m%d%H') inidate_yyyymmdd_hh = start_time.strftime('%Y%m%d_%H') inidate_yyyymmddhhmmss = start_time.strftime('%Y%m%d%H%M%S') @@ -686,7 +675,6 @@ def load_model_config_yaml(yamlfile): print(f"Starting chain for case {casename} and model {cfg.model}") - start_time = datetime.strptime(args.startdate, '%Y-%m-%d') # check for restart compatibility and spinup if 'restart' in model_cfg['models'][cfg.model]['features']: if hasattr(cfg, 'spinup'): @@ -694,9 +682,9 @@ def load_model_config_yaml(yamlfile): restart_runs_spinup(work_root=cfg.work_root, model_cfg=model_cfg, cfg=cfg, - start=start_time, - hstart=args.hstart, - hstop=args.hstop, + start=cfg.startdate, + hstart=cfg.hstart, + hstop=cfg.hstop, job_names=args.job_list, force=args.force) else: @@ -704,19 +692,20 @@ def load_model_config_yaml(yamlfile): restart_runs(work_root=cfg.work_root, model_cfg=model_cfg, cfg=cfg, - start=start_time, - hstart=args.hstart, - hstop=args.hstop, + start=cfg.startdate, + hstart=cfg.hstart, + hstop=cfg.hstop, job_names=args.job_list, force=args.force) else: print("No restart is used.") run_chain(work_root=cfg.work_root, cfg=cfg, - start_time=start_time, - hstart=args.hstart, - hstop=args.hstop, + start_time=cfg.startdate, + hstart=cfg.hstart, + hstop=cfg.hstop, job_names=args.job_list, force=args.force) print('>>> finished chain for good or bad! <<<') +