Skip to content

Commit

Permalink
Move times to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaehn committed Sep 21, 2023
1 parent 4087165 commit 2d8e66a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 47 deletions.
3 changes: 3 additions & 0 deletions cases/cosmo-ghg-11km-test/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions jobs/int2lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -103,29 +102,29 @@ 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
if starttime < datetime.strptime('2007-08-02', '%Y-%m-%d'):
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))

# Prepare runscript
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,
Expand All @@ -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))

45 changes: 17 additions & 28 deletions run_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,6 @@ def parse_arguments():
"to be in cases/<casename>/. 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 "
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -686,37 +675,37 @@ 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'):
print("This is a spinup simulation.")
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:
print("Built-in model restart is used.")
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! <<<')

0 comments on commit 2d8e66a

Please sign in to comment.