Skip to content

Commit

Permalink
Fix inidates for spinup runs
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaehn committed Oct 1, 2023
1 parent 94309a2 commit ee61770
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
4 changes: 2 additions & 2 deletions cases/cosmo-ghg-spinup-test/int2lm_INPUT.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
&CONTRL
yinput_model = 'COSMO', ! string to identify the input model
ydate_ini = '{cfg.inidate_int2lm_yyyymmddhh}', ! start of the forecast
ydate_ini = '{inidate_int2lm_yyyymmddhh}', ! start of the forecast

hstart = {hstart_int2lm}, ! first hour to be processed
hstop = {hstop_int2lm}, ! last hour to be processed
Expand Down Expand Up @@ -140,7 +140,7 @@
ylmext_lfn='{extpar_filename}',
ylmext_cat='../input/extpar/',
ylmext_form_read='ncdf', ! Input format of external data
yinext_lfn='{meteo_prefix}{cfg.inidate_int2lm_yyyymmddhh}', ! Name of the file with the external fields
yinext_lfn='{meteo_prefix}{inidate_int2lm_yyyymmddhh}', ! Name of the file with the external fields
yinext_cat='../input/meteo/',
yinext_form_read="grb1", ! Input format of external data from coarse grid
ie_ext=600,
Expand Down
2 changes: 1 addition & 1 deletion cases/cosmo-ghg-spinup-test/int2lm_runjob.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash -l
#SBATCH --job-name=int2lm_{cfg.inidate_yyyymmddhh}_{cfg.forecasttime}
#SBATCH --job-name=int2lm_{inidate_yyyymmddhh}_{cfg.forecasttime}
#SBATCH --account={cfg.compute_account}
#SBATCH --time={walltime}
#SBATCH --nodes={nodes}
Expand Down
23 changes: 13 additions & 10 deletions jobs/int2lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@
import os
import logging
import shutil
from . import tools
import subprocess
from datetime import datetime, timedelta
import pytz
from datetime import datetime, timedelta
from . import tools, prepare_data


def set_cfg_variables(cfg):

# Int2lm processing always starts at hstart=0, thus modifying inidate
inidate_int2lm_yyyymmddhh = (
cfg.startdate + timedelta(hours=cfg.hstart)).strftime('%Y%m%d%H')
setattr(cfg, 'inidate_int2lm_yyyymmddhh', inidate_int2lm_yyyymmddhh)
setattr(cfg, 'int2lm_run', os.path.join(cfg.chain_root, 'int2lm', 'run'))
setattr(cfg, 'int2lm_output',
os.path.join(cfg.chain_root, 'int2lm', 'output'))
Expand Down Expand Up @@ -68,9 +64,8 @@ def main(starttime, hstart, hstop, cfg, model_cfg):
cfg : config-object
Object holding all user-configuration parameters as attributes
"""
cfg = prepare_data.set_cfg_variables(cfg)
cfg = set_cfg_variables(cfg)
hstart_int2lm = 0
hstop_int2lm = cfg.forecasttime

# Total number of processes
np_tot = cfg.int2lm['np_x'] * cfg.int2lm['np_y']
Expand Down Expand Up @@ -143,12 +138,19 @@ def main(starttime, hstart, hstop, cfg, model_cfg):
cfg.int2lm['namelist_filename'])) as input_file:
int2lm_namelist = input_file.read()

# Int2lm processing always starts at hstart=0, thus modifying inidate
inidate_int2lm_yyyymmddhh = (
cfg.startdate + timedelta(hours=cfg.hstart)).strftime('%Y%m%d%H')
hstart_int2lm = 0
hstop_int2lm = cfg.forecasttime

output_file = os.path.join(int2lm_run, "INPUT")
with open(output_file, "w") as outf:
outf.write(
int2lm_namelist.format(
cfg=cfg,
**cfg.int2lm,
inidate_int2lm_yyyymmddhh=inidate_int2lm_yyyymmddhh,
hstart_int2lm=hstart_int2lm,
hstop_int2lm=hstop_int2lm,
multi_layer=multi_layer,
Expand All @@ -170,8 +172,9 @@ def main(starttime, hstart, hstop, cfg, model_cfg):
int2lm_runscript.format(cfg=cfg,
**cfg.int2lm,
int2lm_run=int2lm_run,
ini_day=cfg.inidate_int2lm_yyyymmddhh[0:8],
ini_hour=cfg.inidate_int2lm_yyyymmddhh[8:],
inidate_yyyymmddhh=inidate_int2lm_yyyymmddhh,
ini_day=inidate_int2lm_yyyymmddhh[0:8],
ini_hour=inidate_int2lm_yyyymmddhh[8:],
np_tot=np_tot,
hstop_int2lm=hstop_int2lm,
logfile=logfile,
Expand Down
13 changes: 10 additions & 3 deletions jobs/prepare_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
from calendar import monthrange


def set_cfg_variables(cfg):

if cfg.model.startswith('cosmo'):
setattr(cfg, 'int2lm_root', os.path.join(cfg.chain_root, 'int2lm'))
setattr(cfg, 'int2lm_input', os.path.join(cfg.int2lm_root, 'input'))

return cfg

def main(starttime, hstart, hstop, cfg, model_cfg):
"""
**ICON** (if ``cfg.model`` is ``tools.Target.ICON``)
Expand Down Expand Up @@ -80,6 +88,8 @@ def main(starttime, hstart, hstop, cfg, model_cfg):
Object holding all user-configuration parameters as attributes
"""

cfg = set_cfg_variables(cfg)

if cfg.model.startswith('icon'):
logging.info('ICON input data (IC/BC)')

Expand All @@ -101,7 +111,6 @@ def main(starttime, hstart, hstop, cfg, model_cfg):
input_dir = os.path.join(cfg.chain_root, 'icon', 'input',
file_info[1])
input_dir_name = 'icon_input_' + file_info[1]
setattr(cfg, input_dir_name, input_dir)
tools.create_dir(input_dir, input_dir_name)
varname_scratch = varname + '_scratch'
tools.copy_file(getattr(cfg, varname),
Expand Down Expand Up @@ -460,8 +469,6 @@ def main(starttime, hstart, hstop, cfg, model_cfg):
else:
logging.info('COSMO analysis data for IC/BC')

setattr(cfg, 'int2lm_root', os.path.join(cfg.chain_root, 'int2lm'))
setattr(cfg, 'int2lm_input', os.path.join(cfg.int2lm_root, 'input'))
dest_path = os.path.join(cfg.int2lm_input, 'meteo')
tools.create_dir(dest_path, "meteo input")

Expand Down
16 changes: 14 additions & 2 deletions run_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,19 @@ def run_chain(work_root, model_cfg, cfg, start_time, hstart, hstop, job_names,
If True will do job regardless of completion status
"""

# ini date and forecast time (ignore meteo times)
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')
setattr(cfg, 'inidate_yyyymmddhh', inidate_yyyymmddhh)
setattr(cfg, 'inidate_yyyymmdd_hh', inidate_yyyymmdd_hh)
setattr(cfg, 'inidate_yyyymmddhhmmss', inidate_yyyymmddhhmmss)
setattr(cfg, 'hstart', hstart)
setattr(cfg, 'hstop', hstop)
forecasttime = '%d' % (hstop - hstart)
inidate_int2lm_yyyymmddhh = (start_time +
timedelta(hours=hstart)).strftime('%Y%m%d%H')

if hasattr(cfg, 'spinup'):
if cfg.first_one: # first run in spinup
chain_root_last_run = ''
Expand All @@ -277,7 +289,7 @@ def run_chain(work_root, model_cfg, cfg, start_time, hstart, hstop, job_names,
setattr(cfg, 'forecasttime', forecasttime)

# Folder naming and structure
job_id = '%s_%d_%d' % (cfg.inidate_yyyymmddhh, hstart, hstop)
job_id = '%s_%d_%d' % (inidate_yyyymmddhh, hstart, hstop)
chain_root = os.path.join(work_root, cfg.casename, job_id)
setattr(cfg, 'job_id', job_id)
setattr(cfg, 'chain_root', chain_root)
Expand Down Expand Up @@ -558,7 +570,7 @@ def restart_runs_spinup(work_root, model_cfg, cfg, start, hstart, hstop,
if endtime_act_sim > start + timedelta(hours=hstop):
continue

print('Runtime of sub-simulation: ', run_time)
print(f'Runtime of sub-simulation: {run_time} h')

if cfg.first_one:
run_chain(work_root=work_root,
Expand Down

0 comments on commit ee61770

Please sign in to comment.