From 9fc5863a9eddd9bbdae164bed9e1abbbdb91b6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20J=C3=A4hn?= Date: Fri, 22 Sep 2023 21:33:08 +0200 Subject: [PATCH] Fix post_int2lm --- jobs/int2lm.py | 9 ++++++--- jobs/post_int2lm.py | 13 ++++++------- jobs/prepare_data.py | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/jobs/int2lm.py b/jobs/int2lm.py index 64a8b7b5..e37b1853 100644 --- a/jobs/int2lm.py +++ b/jobs/int2lm.py @@ -58,6 +58,7 @@ 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 @@ -65,10 +66,12 @@ def main(starttime, hstart, hstop, cfg, model_cfg): 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") diff --git a/jobs/post_int2lm.py b/jobs/post_int2lm.py index 61f30c15..13f30003 100644 --- a/jobs/post_int2lm.py +++ b/jobs/post_int2lm.py @@ -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() @@ -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: @@ -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.' @@ -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, @@ -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" diff --git a/jobs/prepare_data.py b/jobs/prepare_data.py index a72e66be..49056b94 100644 --- a/jobs/prepare_data.py +++ b/jobs/prepare_data.py @@ -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")