Skip to content

Commit

Permalink
Some fixes for cosmo case
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaehn committed Jan 16, 2024
1 parent add761e commit 780c66d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 45 deletions.
44 changes: 2 additions & 42 deletions jobs/cosmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,13 @@
import logging
import os
import subprocess
import csv
from .tools import write_cosmo_input_ghg
from . import tools
from . import tools, prepare_cosmo
from datetime import datetime, timedelta

BASIC_PYTHON_JOB = True


def set_cfg_variables(cfg):
cfg.cosmo_base = cfg.chain_root / 'cosmo'
cfg.cosmo_input = cfg.chain_root / 'cosmo' / 'input'
cfg.cosmo_run = cfg.chain_root / 'cosmo' / 'run'
cfg.cosmo_output = cfg.chain_root / 'cosmo' / 'output'
cfg.cosmo_output_reduced = cfg.chain_root / 'cosmo' / 'output_reduced'

# Number of tracers
if 'tracers' in cfg.workflow['features']:
tracer_csvfile = cfg.chain_src_dir / 'cases' / cfg.casename / 'cosmo_tracers.csv'
if tracer_csvfile.is_file():
with open(tracer_csvfile, 'r') as csv_file:
reader = csv.DictReader(csv_file, delimiter=',')
reader = [r for r in reader if r[''] != '#']
cfg.in_tracers = len(reader)
else:
raise FileNotFoundError(f"File not found: {tracer_csvfile}")

# tracer_start namelist parameter for spinup simulation
if hasattr(cfg, 'spinup'):
if cfg.first_one:
cfg.tracer_start = 0
else:
cfg.tracer_start = cfg.spinup
else:
cfg.tracer_start = 0

# asynchronous I/O
if hasattr(cfg, 'cfg.cosmo_np_io'):
if cfg.cosmo_np_io == 0:
cfg.lasync_io = '.FALSE.'
cfg.num_iope_percomm = 0
else:
cfg.lasync_io = '.TRUE.'
cfg.num_iope_percomm = 1


def main(cfg):
"""Setup the namelists for a COSMO tracer run and submit the job to the queue.
Expand Down Expand Up @@ -78,7 +40,7 @@ def main(cfg):
cfg : Config
Object holding all user-configuration parameters as attributes.
"""
set_cfg_variables(cfg)
prepare_cosmo.set_cfg_variables(cfg)
tools.change_logfile(cfg.logfile)
launch_time = cfg.init_time_logging("cosmo")

Expand All @@ -101,8 +63,6 @@ def main(cfg):
tools.create_dir(ini_dir, "cosmo_input_initial")
startfiletime = datetime.strptime(cfg.laf_startfile[-10:], "%Y%m%d%H")
if cfg.startdate_sim >= startfiletime:
starttime_last = cfg.startdate_sim - timedelta(
hours=cfg.restart_step)
work_root = os.path.dirname(os.path.dirname(cfg.chain_root))
last_output_path = os.path.join(work_root, cfg.casename,
cfg.chunk_id_prev, 'cosmo',
Expand Down
4 changes: 2 additions & 2 deletions jobs/oem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import logging

from . import tools, cosmo
from . import tools, prepare_cosmo

BASIC_PYTHON_JOB = True

Expand All @@ -24,7 +24,7 @@ def main(cfg):
If an error occurs during the process.
"""
tools.change_logfile(cfg.logfile)
cosmo.set_cfg_variables(cfg)
prepare_cosmo.set_cfg_variables(cfg)
launch_time = cfg.init_time_logging("oem")

oem_dir = cfg.oem['dir']
Expand Down
3 changes: 2 additions & 1 deletion jobs/online_vprm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import logging

from . import tools
from . import tools, prepare_cosmo

BASIC_PYTHON_JOB = True

Expand All @@ -18,6 +18,7 @@ def main(cfg):
cfg : Config
Object holding all user-configuration parameters as attributes.
"""
prepare_cosmo.set_cfg_variables()
tools.change_logfile(cfg.logfile)
launch_time = cfg.init_time_logging("online_vprm")
dest_modis = 'modis.nc'
Expand Down
35 changes: 35 additions & 0 deletions jobs/prepare_cosmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from pathlib import Path
import logging
import csv
from datetime import timedelta
from . import tools

Expand All @@ -12,6 +13,40 @@
def set_cfg_variables(cfg):
cfg.int2lm_root = cfg.chain_root / 'int2lm'
cfg.int2lm_input = cfg.int2lm_root / 'input'
cfg.cosmo_base = cfg.chain_root / 'cosmo'
cfg.cosmo_input = cfg.chain_root / 'cosmo' / 'input'
cfg.cosmo_run = cfg.chain_root / 'cosmo' / 'run'
cfg.cosmo_output = cfg.chain_root / 'cosmo' / 'output'
cfg.cosmo_output_reduced = cfg.chain_root / 'cosmo' / 'output_reduced'

# Number of tracers
if 'tracers' in cfg.workflow['features']:
tracer_csvfile = cfg.chain_src_dir / 'cases' / cfg.casename / 'cosmo_tracers.csv'
if tracer_csvfile.is_file():
with open(tracer_csvfile, 'r') as csv_file:
reader = csv.DictReader(csv_file, delimiter=',')
reader = [r for r in reader if r[''] != '#']
cfg.in_tracers = len(reader)
else:
raise FileNotFoundError(f"File not found: {tracer_csvfile}")

# tracer_start namelist parameter for spinup simulation
if hasattr(cfg, 'spinup'):
if cfg.first_one:
cfg.tracer_start = 0
else:
cfg.tracer_start = cfg.spinup
else:
cfg.tracer_start = 0

# asynchronous I/O
if hasattr(cfg, 'cfg.cosmo_np_io'):
if cfg.cosmo_np_io == 0:
cfg.lasync_io = '.FALSE.'
cfg.num_iope_percomm = 0
else:
cfg.lasync_io = '.TRUE.'
cfg.num_iope_percomm = 1


def main(cfg):
Expand Down

0 comments on commit 780c66d

Please sign in to comment.