diff --git a/CHANGELOG.md b/CHANGELOG.md index c87f3f8e..a1dfa17d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- series of regrid*.py are added to GEOS_Util/post +- Introduce series of remap_restarts Python scripts to GEOS_Util/post +- Add a series of tests for remap_restarts ### Changed diff --git a/GEOS_Util/post/CMakeLists.txt b/GEOS_Util/post/CMakeLists.txt index ce71bc27..7de3ed32 100644 --- a/GEOS_Util/post/CMakeLists.txt +++ b/GEOS_Util/post/CMakeLists.txt @@ -168,3 +168,5 @@ install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/3CH.j DESTINATION post ) + +add_subdirectory(tests) diff --git a/GEOS_Util/post/tests/CMakeLists.txt b/GEOS_Util/post/tests/CMakeLists.txt new file mode 100644 index 00000000..80ddc86d --- /dev/null +++ b/GEOS_Util/post/tests/CMakeLists.txt @@ -0,0 +1,5 @@ + +file(GLOB test_scripts CONFIGURE_DEPENDS ./*.py ./*.yaml) +install( + PROGRAMS ${test_scripts} + DESTINATION bin) diff --git a/GEOS_Util/post/tests/c24Toc12.yaml b/GEOS_Util/post/tests/c24Toc12.yaml new file mode 100644 index 00000000..3bd204a4 --- /dev/null +++ b/GEOS_Util/post/tests/c24Toc12.yaml @@ -0,0 +1,48 @@ +# +# This template file can be filled with questionary or manually +# +# + +input: + air: + drymass: 1 + hydrostatic: 0 + shared: + MERRA-2: false + agrid: C24 + bcs_dir: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus-NLv3/Icarus-NLv3_Reynolds//CF0024x6C_DE0360xPE0180/ + expid: '' + ogrid: 360X180 + rst_dir: /discover/nobackup/projects/gmao/SIteam/Remapping_Test_Cases/c24Toc12/inputs + yyyymmddhh: '2000041421' + surface: + zoom: '1' + wemin: '13' + # it supports three models: catch, catchcnclm40, catchcnclm45 + catch_model: catch + +output: + shared: + agrid: C12 + bcs_dir: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus-NLv3/Icarus-NLv3_Reynolds//CF0012x6C_DE0360xPE0180/ + expid: hello + ogrid: 360X180 + out_dir: $NOBACKUP/REMAP_TESTS/c24Toc12/ + air: + remap: true + nlevel: '72' + surface: + split_saltwater: true + surflay: 50.0 + wemin: '13' + remap_water: true + remap_catch: true + analysis: + bkg: false + aqua: true + lcv: false + +slurm: + account: g0610 + qos: debug + constraint: hasw diff --git a/GEOS_Util/post/tests/f522Toc360.yaml b/GEOS_Util/post/tests/f522Toc360.yaml new file mode 100644 index 00000000..f4450582 --- /dev/null +++ b/GEOS_Util/post/tests/f522Toc360.yaml @@ -0,0 +1,47 @@ +# +# This template file can be filled with questionary or manually +# +# + +input: + air: + drymass: 1 + hydrostatic: 0 + shared: + MERRA-2: false + agrid: C720 + bcs_dir: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus_Updated/Icarus_Ostia//CF0720x6C_CF0720x6C/ + expid: f522_fp + ogrid: C720 + rst_dir: /discover/nobackup/projects/gmao/SIteam/Remapping_Test_Cases/f522Toc360/inputs/ + yyyymmddhh: '2019061421' + surface: + zoom: '8' + wemin: '26' + catch_model: catch + +output: + shared: + agrid: C360 + bcs_dir: /discover/nobackup/projects/gmao/share/gmao_ops/fvInput/g5gcm/bcs/Icarus-NLv3/Icarus-NLv3_Reynolds//CF0360x6C_DE0360xPE0180/ + expid: remap + ogrid: 360X180 + out_dir: $NOBACKUP/REMAP_TESTS/f522Toc360/ + air: + nlevel: '72' + remap: true + surface: + split_saltwater: true + surflay: 50.0 + wemin: '13' + remap_catch: true + remap_water: true + analysis: + bkg: true + aqua: true + lcv: true + +slurm: + account: g0610 + qos: debug + constraint: hasw diff --git a/GEOS_Util/post/tests/test_remap_cases.yaml b/GEOS_Util/post/tests/test_remap_cases.yaml new file mode 100644 index 00000000..30640090 --- /dev/null +++ b/GEOS_Util/post/tests/test_remap_cases.yaml @@ -0,0 +1,7 @@ +c24Toc12: + base_line: '/discover/nobackup/projects/gmao/SIteam/Remapping_Test_Cases/c24Toc12/baseline/' + config: 'c24Toc12.yaml' +f522Toc360: + base_line: '/discover/nobackup/projects/gmao/SIteam/Remapping_Test_Cases/f522Toc360/baseline/' + config: 'f522Toc360.yaml' + diff --git a/GEOS_Util/post/tests/test_remap_restarts.py b/GEOS_Util/post/tests/test_remap_restarts.py new file mode 100755 index 00000000..f699ba7c --- /dev/null +++ b/GEOS_Util/post/tests/test_remap_restarts.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +# +# source install/bin/g5_modules +# +# Newer GEOS code should load a module with GEOSpyD Python3 if not run: +# module load python/GEOSpyD/Min4.10.3_py3.9 +# + +import sys, getopt +import ruamel.yaml +import questionary +import glob +import subprocess as sp +import remap_restarts +from remap_questions import get_config_from_questionary +from remap_params import * +from remap_upper import * +from remap_lake_landice_saltwater import * +from remap_analysis import * +from remap_catchANDcn import * + +def compare(base, result): + #1) comparing nc4 + bases = glob.glob(base + '/*_rst*.nc4*') + results = glob.glob( result + '/*_rst*.nc4*') + if (len(bases) != len(results)) : + print(len(bases), len(results)) + print (" number of restart out should be the same") + return False + bases.sort() + results.sort() + for b, r in zip(bases, results): + cmd = 'nccmp -dmgfs '+ b + ' ' + r + print(cmd) + p = sp.Popen(shlex.split(cmd), stdout=subprocess.PIPE) + (out, err) = p.communicate() + rc = p.wait() + out = out.decode().split() + if "identical." in out : + print('identical') + else: + print ( f + ' is different from ' + r) + return False + return True + +def test_remap(config): + + upper = upperair(config_obj=config) + upper.remap() + lls = lake_landice_saltwater(config_obj=config) + lls.remap() + catch = catchANDcn(config_obj=config) + catch.remap() + ana = analysis(config_obj=config) + ana.remap() + + +if __name__ == '__main__' : + + yaml = ruamel.yaml.YAML() + stream ='' + cases_yaml = 'test_remap_cases.yaml' + with open(cases_yaml, 'r') as f: + stream = f.read() + cases = yaml.load(stream) + + cmd = 'whoami' + p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) + (user, err) = p.communicate() + p_status = p.wait() + user = user.decode().split()[0] + + for case, values in cases.items(): + base_line = values['base_line'] + config_yaml_file = values['config'] + + stream ='' + with open(config_yaml_file, 'r') as f: + stream = f.read() + config = yaml.load(stream) + + out_dir = '/discover/nobackup/'+user+'/REMAP_TESTS/'+case+'/' + config['output']['shared']['out_dir'] = out_dir + + test_remap(config) + + rc = compare(base_line, out_dir) + if (not rc) : + print ("failed in " + case) + else : + print (case +" test is successful") +