Skip to content
Snippets Groups Projects
Commit d9f52d13 authored by lkugler's avatar lkugler
Browse files

prints

parent a13e8801
Branches
Tags
No related merge requests found
......@@ -12,9 +12,6 @@ import importlib
from dartwrf.utils import script_to_str
from config.cfg import exp
def dict_to_py(d, outfile):
with open(outfile, 'w') as f:
txt = '# this file is autogenerated \nobs_kind_nrs = {'
......@@ -23,6 +20,33 @@ def dict_to_py(d, outfile):
txt += '}'
f.write(txt)
def _obskind_read():
"""Read dictionary of observation types + ID numbers ("kind")
from DART f90 script
"""
definitionfile = self.cluster.dart_srcdir+'/../../../assimilation_code/modules/observations/obs_kind_mod.f90'
with open(definitionfile, 'r') as f:
kind_def_f = f.readlines()
obskind_nrs = {}
for i, line in enumerate(kind_def_f):
if 'Integer definitions for DART OBS TYPES' in line:
# data starts below this line
i_start = i
break
for line in kind_def_f[i_start+1:]:
if 'MAX_DEFINED_TYPES_OF_OBS' in line:
# end of data
break
if '::' in line:
# a line looks like this
# integer, parameter, public :: MSG_4_SEVIRI_TB = 261
data = line.split('::')[-1].split('=')
kind_str = data[0].strip()
kind_nr = int(data[1].strip())
obskind_nrs[kind_str] = kind_nr
return obskind_nrs
class WorkFlows(object):
def __init__(self, exp_config='cfg.py', server_config='server.py'):
"""Set up the experiment folder in `archivedir`.
......@@ -30,10 +54,14 @@ class WorkFlows(object):
Args:
exp (str): Path to exp config file
config (str): Path to the cluster config file
Note:
in WorkFlows, we load the config from the git cloned folder
in all other dartwrf scripts, load the config from cluster.scripts_rundir
"""
# in WorkFlows, we load the config from the git cloned folder
# in all other dartwrf scripts, load the config from cluster.scripts_rundir
print('------ start exp from ', exp_config, ' and ', server_config, ' ------')
# exp = __import__('config/'+exp_config)
# load python config file
self.cluster = importlib.import_module('config.'+server_config.strip('.py')).cluster
# Set paths and backup scripts
......@@ -42,38 +70,11 @@ class WorkFlows(object):
if self.cluster.use_slurm:
self.cluster.slurm_scripts_dir = self.cluster.archivedir+'/slurm-scripts/'
print('scripts, which are submitted to SLURM:', self.cluster.slurm_scripts_dir)
print('SLURM scripts will be in', self.cluster.slurm_scripts_dir)
# copy obs kind def to config, we will read a table from there
# file needs to exist within package so sphinx can read it
def obskind_read():
"""Read dictionary of observation types + ID numbers ("kind")
from DART f90 script
"""
definitionfile = self.cluster.dart_srcdir+'/../../../assimilation_code/modules/observations/obs_kind_mod.f90'
with open(definitionfile, 'r') as f:
kind_def_f = f.readlines()
obskind_nrs = {}
for i, line in enumerate(kind_def_f):
if 'Integer definitions for DART OBS TYPES' in line:
# data starts below this line
i_start = i
break
for line in kind_def_f[i_start+1:]:
if 'MAX_DEFINED_TYPES_OF_OBS' in line:
# end of data
break
if '::' in line:
# a line looks like this
# integer, parameter, public :: MSG_4_SEVIRI_TB = 261
data = line.split('::')[-1].split('=')
kind_str = data[0].strip()
kind_nr = int(data[1].strip())
obskind_nrs[kind_str] = kind_nr
return obskind_nrs
dict_to_py(obskind_read(), self.cluster.scriptsdir+'/../config/obskind.py')
dict_to_py(_obskind_read(), self.cluster.scriptsdir+'/../config/obskind.py')
# Copy scripts to self.cluster.archivedir folder
os.makedirs(self.cluster.archivedir, exist_ok=True)
......@@ -93,6 +94,8 @@ class WorkFlows(object):
# probably not needed
# shutil.copy('config/'+server_config, 'config/cluster.py') # whatever server, the config name is always the same!
print('------ dartwrf experiment initialized ------')
print('--------------------------------------------')
def prepare_WRFrundir(self, init_time):
"""Create WRF/run directories and wrfinput files
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment