Skip to content

Commit

Permalink
Fix post_int2lm
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaehn committed Sep 22, 2023
1 parent 62b4477 commit 9fc5863
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
9 changes: 6 additions & 3 deletions jobs/int2lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,20 @@ def main(starttime, hstart, hstop, cfg, model_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)
hstart_int2lm = 0
hstop_int2lm = cfg.forecasttime

# Total number of processes
np_tot = cfg.int2lm['np_x'] * cfg.int2lm['np_y']

# Set folder names
int2lm_run = os.path.join(cfg.int2lm_work, 'run')
int2lm_output = os.path.join(cfg.int2lm_work, 'output')
setattr(cfg, 'int2lm_run', os.path.join(cfg.chain_root, 'int2lm', 'run'))
setattr(cfg, 'int2lm_output', os.path.join(cfg.chain_root, 'int2lm', 'output'))
int2lm_run = os.path.join(cfg.int2lm_run)
int2lm_output = os.path.join(cfg.int2lm_output)

# Create int2lm directory
# Create int2lm directories
tools.create_dir(int2lm_run, "int2lm_run")
tools.create_dir(int2lm_output, "int2lm_output")

Expand Down
13 changes: 6 additions & 7 deletions jobs/post_int2lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ def main(start_time, hstart, hstop, cfg, model_cfg):
"""
tools.check_model(cfg, 'cosmo-ghg')

int2lm_output = cfg.int2lm_output
inidate_int2lm_yyyymmddhh = cfg.inidate_int2lm_yyyymmddhh

chem_list = cfg.post_int2lm_species
chem_list = cfg.post_int2lm['species']

date = dt.datetime.today()

Expand All @@ -64,13 +63,13 @@ def main(start_time, hstart, hstop, cfg, model_cfg):
# Add background tracers in all 'lbfd**t.nc' files to
# normal lbfd files, because CAMS tracers are only every 3 hours.
# We add it 4 times to hour-1, hour+0, hour+1 and hour+2
for f in sorted(glob.glob(os.path.join(int2lm_output, 'lbfd*t.nc'))):
for f in sorted(glob.glob(os.path.join(cfg.int2lm_output, 'lbfd*t.nc'))):
logging.info(f)
yyyymmddhh_str = os.path.basename(f)[4:-4]
yyyymmddhh = dt.datetime.strptime(yyyymmddhh_str, '%Y%m%d%H')

for hour in tools.iter_hours(yyyymmddhh, -1, 2):
outfile1 = os.path.join(int2lm_output,
outfile1 = os.path.join(cfg.int2lm_output,
hour.strftime('lbfd%Y%m%d%H' + '.nc'))
if os.path.exists(outfile1):
with nc.Dataset(outfile1, 'a') as outf, nc.Dataset(f) as inf:
Expand All @@ -91,7 +90,7 @@ def main(start_time, hstart, hstop, cfg, model_cfg):

# Meteo spinup simulation with tracer recycling
if hasattr(cfg, 'spinup') and \
hasattr(cfg, 'post_int2lm_species_spinup') and not cfg.first_one:
cfg.post_int2lm.get('species_spinup') is not None and not cfg.first_one:
var_list = cfg.post_int2lm_species_spinup
logging.info(
'INITIAL CONDITIONS (RECYCLING): Adding tracers %s from last COSMO run (%s) to regular int2lm files.'
Expand All @@ -101,7 +100,7 @@ def main(start_time, hstart, hstop, cfg, model_cfg):
infile_paths = sorted(
glob.glob(os.path.join(cfg.last_cosmo_output, infile_name)))
outfile_name = 'laf' + inidate_int2lm_yyyymmddhh + '.nc'
outfile_path = os.path.join(int2lm_output, outfile_name)
outfile_path = os.path.join(cfg.int2lm_output, outfile_name)

for infile_path in infile_paths:
with nc.Dataset(infile_path) as inf, nc.Dataset(outfile_path,
Expand All @@ -127,7 +126,7 @@ def main(start_time, hstart, hstop, cfg, model_cfg):
logging.info(
'INITIAL CONDITIONS: Adding tracers from laf*t.nc files to regular int2lm files.'
)
infile = os.path.join(int2lm_output,
infile = os.path.join(cfg.int2lm_output,
"laf" + inidate_int2lm_yyyymmddhh + "t.nc")
if os.path.exists(infile):
outfile = infile[:-4] + ".nc"
Expand Down
4 changes: 2 additions & 2 deletions jobs/prepare_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ def main(starttime, hstart, hstop, cfg, model_cfg):
else:
logging.info('COSMO analysis data for IC/BC')

setattr(cfg, 'int2lm_work', os.path.join(cfg.chain_root, 'int2lm'))
setattr(cfg, 'int2lm_input', os.path.join(cfg.int2lm_work, 'input'))
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

0 comments on commit 9fc5863

Please sign in to comment.