Skip to content

Commit

Permalink
Merge pull request #267 from GEOS-ESM/feature/wjiang/add_tests
Browse files Browse the repository at this point in the history
Create test suite for remap_restarts.py
  • Loading branch information
mathomp4 authored Jul 22, 2022
2 parents 2cd4a5a + d545b6b commit 28fe9c1
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions GEOS_Util/post/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,5 @@ install(PROGRAMS
${CMAKE_CURRENT_BINARY_DIR}/3CH.j
DESTINATION post
)

add_subdirectory(tests)
5 changes: 5 additions & 0 deletions GEOS_Util/post/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

file(GLOB test_scripts CONFIGURE_DEPENDS ./*.py ./*.yaml)
install(
PROGRAMS ${test_scripts}
DESTINATION bin)
48 changes: 48 additions & 0 deletions GEOS_Util/post/tests/c24Toc12.yaml
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions GEOS_Util/post/tests/f522Toc360.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions GEOS_Util/post/tests/test_remap_cases.yaml
Original file line number Diff line number Diff line change
@@ -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'

92 changes: 92 additions & 0 deletions GEOS_Util/post/tests/test_remap_restarts.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 28fe9c1

Please sign in to comment.