Skip to content

Commit

Permalink
test oro namelist for icon
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasjucker committed Feb 11, 2025
1 parent 541ca63 commit 23dd8d9
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 18 deletions.
31 changes: 15 additions & 16 deletions python/WrapExtpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ def main():
lradtopo = config.get('lradtopo', False)
radtopo_radius = config.get('radtopo_radius', 40000.0)

generate_external_parameters(
igrid_type, args.input_grid, iaot_type, ilu_type, ialb_type,
isoil_type, itopo_type, it_cl_type, iera_type, iemiss_type,
radtopo_radius, args.raw_data_path, args.run_dir, args.account,
args.host, args.no_batch_job, lurban, lsgsl, lfilter_oro, lradtopo)
generate_external_parameters(igrid_type, args.input_grid, iaot_type,
ilu_type, ialb_type, isoil_type, itopo_type,
it_cl_type, iera_type, iemiss_type, radtopo_radius,
args.raw_data_path, args.run_dir,
args.account, args.host, args.no_batch_job,
lurban, lsgsl, lfilter_oro, lradtopo)


def generate_external_parameters(igrid_type,
Expand Down Expand Up @@ -125,6 +126,7 @@ def generate_external_parameters(igrid_type,
'it_cl_type': it_cl_type,
'iera_type': iera_type,
'iemiss_type': iemiss_type,
'lradtopo': lradtopo,
'radtopo_radius': radtopo_radius,
'lsgsl': lsgsl,
'lfilter_oro': lfilter_oro,
Expand All @@ -133,8 +135,7 @@ def generate_external_parameters(igrid_type,
'run_dir': run_dir,
'account': account,
'host': host,
'no_batch_job': no_batch_job,
'lradtopo': lradtopo
'no_batch_job': no_batch_job
}

namelist = setup_namelist(args_dict)
Expand Down Expand Up @@ -238,7 +239,12 @@ def setup_oro_namelist(args):
if igrid_type == 2:
return setup_oro_namelist_cosmo(args)
else:
return setup_oro_namelist_icon(args)
tg = IconGrid(args['input_grid'])
lonmax = np.amax(tg.lons)
lonmin = np.amin(tg.lons)
latmin = np.amin(tg.lats)
latmax = np.amax(tg.lats)
return setup_oro_namelist_icon(args,lonmax,lonmin,latmax,latmin)


def setup_oro_namelist_cosmo(args):
Expand Down Expand Up @@ -366,13 +372,7 @@ def orography_smoothing_params():
return namelist


def setup_oro_namelist_icon(args):

tg = IconGrid(args['input_grid'])
lonmax = np.amax(tg.lons)
lonmin = np.amin(tg.lons)
latmin = np.amin(tg.lats)
latmax = np.amax(tg.lats)
def setup_oro_namelist_icon(args,lonmax,lonmin,latmax,latmin):

namelist = {}

Expand Down Expand Up @@ -616,7 +616,6 @@ def setup_era_namelist(args):

return namelist


def setup_emiss_namelist(args):
namelist = {}
iemiss_type = args['iemiss_type']
Expand Down
109 changes: 107 additions & 2 deletions test/pytest/test_wrap_extpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def test_setup_era_namelist_invalid():
setup_era_namelist(args)


def test_setup_emiss_namelist_type1():
def test_setup_emiss_namelist_type_1():
args = {'iemiss_type': 1, 'raw_data_path': '/path/to/raw/data'}
expected_namelist = {
'iemiss_type': 1,
Expand All @@ -527,7 +527,7 @@ def test_setup_emiss_namelist_type1():
assert setup_emiss_namelist(args) == expected_namelist


def test_setup_emiss_namelist_type2():
def test_setup_emiss_namelist_type_2():
args = {'iemiss_type': 2, 'raw_data_path': '/path/to/raw/data'}
expected_namelist = {
'iemiss_type': 2,
Expand All @@ -542,3 +542,108 @@ def test_setup_emiss_namelist_invalid():
args = {'iemiss_type': 99, 'raw_data_path': '/path/to/raw/data'}
with pytest.raises(ValueError, match='Unknown iemiss_type 99'):
setup_emiss_namelist(args)


def test_setup_oro_namelist_icon_type_1():
args = {
'itopo_type': 1,
'raw_data_path': '/path/to/raw/data',
'lradtopo': False,
'radtopo_radius': 40000.0
}
lonmax, lonmin, latmax, latmin = 180.0, -180.0, 90.0, -90.0
expected_namelist = {
'orography_buffer_file': 'oro_buffer.nc',
'orography_output_file': 'oro_grid.nc',
'lcompute_sgsl': ".FALSE.",
'sgsl_buffer_file': 'placeholder_file',
'itopo_type': 1,
'raw_data_orography_path': '/path/to/raw/data',
'topo_files': [
"'GLOBE_A10.nc' ", "'GLOBE_B10.nc' ", "'GLOBE_C10.nc' ",
"'GLOBE_D10.nc' ", "'GLOBE_E10.nc' ", "'GLOBE_F10.nc' ",
"'GLOBE_G10.nc' ", "'GLOBE_H10.nc' ", "'GLOBE_I10.nc' ",
"'GLOBE_J10.nc' ", "'GLOBE_K10.nc' ", "'GLOBE_L10.nc' ",
"'GLOBE_M10.nc' ", "'GLOBE_N10.nc' ", "'GLOBE_O10.nc' ",
"'GLOBE_P10.nc' "
],
'ntiles_column': 4,
'ntiles_row': 4,
'lscale_separation': ".FALSE.",
'lsso_param': ".TRUE.",
'scale_sep_files': "'placeholder_file'",
'raw_data_scale_sep_path': '/path/to/raw/data',
'lfilter_oro': ".FALSE.",
'ilow_pass_oro': 4,
'numfilt_oro': 1,
'ilow_pass_xso': 5,
'lxso_first': ".FALSE.",
'numfilt_xso': 1,
'rxso_mask': 750.0,
'eps_filter': 0.1,
'rfill_valley': 0.0,
'ifill_valley': 1,
'lradtopo': ".FALSE.",
'idem_type': 1
}
assert setup_oro_namelist_icon(args, lonmax, lonmin, latmax, latmin) == expected_namelist


def test_setup_oro_namelist_icon_type_3_lradtopo():
args = {
'itopo_type': 3,
'raw_data_path': '/path/to/raw/data',
'lradtopo': True,
'radtopo_radius': 60000.0
}
lonmax = 30.0
lonmin = -10.0
latmax = 60.0
latmin = 31.0
expected_namelist = {
'orography_buffer_file': 'oro_buffer.nc',
'orography_output_file': 'oro_grid.nc',
'lcompute_sgsl': ".FALSE.",
'sgsl_buffer_file': 'placeholder_file',
'itopo_type': 1,
'raw_data_orography_path': '/path/to/raw/data',
'topo_files': [
"'MERIT_N90-N60_W030-E000.nc' ", "'MERIT_N90-N60_E000-E030.nc' ",
"'MERIT_N60-N30_W030-E000.nc' ", "'MERIT_N60-N30_E000-E030.nc' "
],
'ntiles_column': 2,
'ntiles_row': 2,
'lscale_separation': ".FALSE.",
'lsso_param': ".TRUE.",
'scale_sep_files': "'placeholder_file'",
'raw_data_scale_sep_path': '/path/to/raw/data',
'lfilter_oro': ".FALSE.",
'ilow_pass_oro': 4,
'numfilt_oro': 1,
'ilow_pass_xso': 5,
'lxso_first': ".FALSE.",
'numfilt_xso': 1,
'rxso_mask': 750.0,
'eps_filter': 0.1,
'rfill_valley': 0.0,
'ifill_valley': 1,
'lradtopo': ".TRUE.",
'radius': 60000.0,
'nhori': 24,
'max_missing' : 0.95,
'min_circ_cov' : 1,
'itype_scaling' : 0,
'idem_type': 3
}
assert setup_oro_namelist_icon(args, lonmax, lonmin, latmax, latmin) == expected_namelist

def test_setup_oro_namelist_icon_invalid():
args = {
'itopo_type': 4,
'raw_data_path': '/path/to/raw/data',
'lradtopo': False,
'radtopo_radius': 40000.0
}
lonmax, lonmin, latmax, latmin = 180.0, -180.0, 90.0, -90.0
with pytest.raises(ValueError, match='Unknown itopo_type 4'):
setup_oro_namelist_icon(args, lonmax, lonmin, latmax, latmin)

0 comments on commit 23dd8d9

Please sign in to comment.