Skip to content

Commit

Permalink
Starting to work on cosmo case
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaehn committed Sep 19, 2023
1 parent d971089 commit ec75e91
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 41 deletions.
113 changes: 113 additions & 0 deletions cases/cosmo-ghg-11km-test/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Configuration file for the 'cosmo-ghg-11km-test' case with COSMO-GHG

# GENERAL SETTINGS
model: cosmo-ghg
restart_step: 12
variant: spinup
spinup: 6

# case name = pathname in cases/
casename: null # Set this value based on your use case

# Root directory settings
chain_src_dir: null # Set this value based on your use case
work_root: null # Set this value based on your use case

# PRE-PROCESSING
input_root: null # Set this value based on your use case

# METEO
meteo_dir: null # Set this value based on your use case
meteo_prefix: laf
meteo_nameformat: "laf%Y%m%d%H"
meteo_inc: 1

# ICBC
cams_dir_orig: null # Set this value based on your use case
cams_dir_proc: null # Set this value based on your use case
cams_parameters:
- suffix: cams_co2
inc: 3

# EMISSIONS
emissions_dir: null # Set this value based on your use case
emis_gridname: co2_

# OAE
oem_dir: null # Set this value based on your use case
oem_gridded_emissions_nc: emissions.nc
oem_vertical_profiles_nc: vertical_profiles.nc
oem_hourofday_nc: hourofday.nc
oem_hourofyear_nc: hourofyear.nc
oem_dayofweek_nc: dayofweek.nc
oem_monthofyear_nc: monthofyear.nc

# BIOFLUXES
vprm_dir: null # Set this value based on your use case
vprm_prefix:
- vprm2_

# ONLINE_VPRM
online_vprm_dir: null # Set this value based on your use case
modis_filename: MODIS_sur_refl_Example_20150101-20150201.nc
vegetation_filename: VPRM_VegClasses_example_vprm.nc

# INT2LM
int2lm_extpar_dir: null # Set this value based on your use case
int2lm_extpar_file: test_domain.nc
int2lm_bin: null # Set this value based on your use case
int2lm_namelist: null # Set this value based on your use case
int2lm_runjob: null # Set this value based on your use case
int2lm_walltime: "01:00:00"
int2lm_nodes: 2
int2lm_ntasks_per_node: 12
int2lm_np_x: 8
int2lm_np_y: 3

# POST_INT2LM
post_int2lm_species:
- CO2_BG
post_int2lm_species_spinup:
- CO2_BG
- CO2_GPP
- CO2_RA
- CO2_A
- CO2_GPP2
- CO2_RA2
- CO2_A2

# SIMULATION
# COSMO
cosmo_bin: null # Set this value based on your use case
cosmo_namelist: null # Set this value based on your use case
cosmo_runjob: null # Set this value based on your use case
cosmo_walltime: "00:30:00"
cosmo_np_x: 6
cosmo_np_y: 4
cosmo_np_io: 0

# POST-PROCESSING
# REDUCE_OUTPUT
convert_gas: true
output_levels: 20

# POST_COSMO
output_root: null # Set this value based on your use case
reference_dir: null # Set this value based on your use case
output_dir: null # Set this value based on your use case
values_to_check:
- - cosmo-ghg_pgi_gpu_e5e9e5a_lffd2015010200.nc
- lffd2015010200.nc
- T
- P
- U
- V
- W
- CO2_BG
- CO2_A
- CO2_GPP
- CO2_RA
- CO2_A2
- CO2_GPP2
- CO2_RA2

99 changes: 58 additions & 41 deletions run_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,61 +88,78 @@ def parse_arguments():


def load_config_file(casename, cfg):
"""Load the config file.
Looks for the config file in ``cases/casename/config.py`` and then imports
it as a module. This lets the config file contain python statements which
are evaluated on import.
If this is not the first config-file to be imported by run_chain.py, the
module has to be reloaded to overwrite the values of the old case.
Access variables declared in the config-file (``myval = 9``) with
``cfg.myval``.
Add new variables with::
"""
Load the configuration settings from a YAML file.
setattr(cfg, 'myval', 9)
This function reads the configuration settings from a YAML file located in
the 'cases/casename' directory and sets them as attributes of the provided
`cfg` object.
Parameters
----------
casename : str
Name of the folder in cases/ where the configuration files are stored
cfg : module or None
If cfg is None, the module is freshly imported. If it is a module
object, that module is reloaded.
Parameters:
- casename (str): Name of the folder in 'cases/' where the configuration
files are stored.
- cfg (object): An object to store the configuration settings as attributes.
Returns
-------
config-object
Object with all variables as attributes
Returns:
- cfg (object): The same `cfg` object with configuration settings as
attributes.
"""
cfg_path = os.path.join('cases', casename, 'config')

if not os.path.exists(os.path.dirname(cfg_path)):
all_cases = [path.name for path in os.scandir('cases') if path.is_dir]
cfg_path = os.path.join('cases', casename, 'config.yaml')

if not os.path.exists(cfg_path):
all_cases = [path.name for path in os.scandir('cases') if path.is_dir()]
closest_name = min([(tools.levenshtein(casename, name), name)
for name in all_cases],
key=lambda x: x[0])[1]
raise FileNotFoundError("Case-directory '{}' not found, did you "
"mean '{}'?".format(casename, closest_name))

sys.path.append(os.path.dirname(cfg_path))
raise FileNotFoundError(
f"Case-directory '{casename}' not found, did you mean '{closest_name}'?"
)

try:
if cfg is None:
cfg = importlib.import_module(os.path.basename(cfg_path))
else:
cfg = importlib.reload(cfg)
except ModuleNotFoundError:
raise FileNotFoundError("No file 'config.py' in " +
os.path.dirname(cfg_path))
with open(cfg_path, 'r') as yaml_file:
cfg_data = yaml.load(yaml_file, Loader=yaml.FullLoader)
except FileNotFoundError:
raise FileNotFoundError(f"No file 'config.yaml' in {os.path.dirname(cfg_path)}")

for key, value in cfg_data.items():
setattr(cfg, key, value)

# Set additional config variables
cfg = set_user_account(cfg)

return cfg


# so that a different cfg-file can be imported later
sys.path.pop()
def set_user_account(cfg):
setattr(cfg, user, os.environ['USER'])
if cfg.user == 'jenkins':
# g110 account for Jenkins testing
setattr(cfg, compute_account, 'g110')
elif os.path.exists(os.environ['HOME'] + '/.acct'):
# Use account specified in ~/.acct file
with open(os.environ['HOME'] + '/.acct', 'r') as file:
setattr(cfg, compute_account, file.read().rstrip())
else:
# Use standard account
setattr(cfg, compute_account, os.popen("id -gn").read().splitlines()[0])

return cfg

def set_node_info(cfg):
if cfg.constraint == 'gpu':
setattr(cfg, ntasks_per_node, 12)
setattr(cfg, mpich_cuda, ('export MPICH_RDMA_ENABLED_CUDA=1\n'
'export MPICH_G2G_PIPELINE=256\n'
'export CRAY_CUDA_MPS=1\n')
)
elif cfg.constraint == 'mc':
setattr(cfg, ntasks_per_node, 36)
setattr(cfg, mpich_cuda, '')
else:
raise ValueError("Invalid value for 'constraint' in the configuration."
"It should be either 'gpu' or 'mc'.")


def run_chain(work_root, model_cfg, cfg, start_time, hstart, hstop, job_names,
force):
Expand Down

0 comments on commit ec75e91

Please sign in to comment.