Skip to content

Commit

Permalink
Adding tests with netcdf (#130)
Browse files Browse the repository at this point in the history
* added netcdf4 flag to Linux_options.yml

* Update CMakeLists.txt

* Update Config.c

* Added tests for netcdf

* fixed potential source of error in developer workflow

* removed tarball

* restored netcdf tarball

* updated some file names

* temporarily adding flags to developer workflow to view test coverage

* forgot to install libaec in last commit

* more tests

* Update run_wgrib2_netcdf4_tests.sh

* adding more tests

* removed recent test - wasn't working

* fixed comments

* more tests

---------

Co-authored-by: Edward Hartnett <[email protected]>
  • Loading branch information
AlysonStahl-NOAA and edwardhartnett authored May 30, 2024
1 parent ef98afb commit 7264649
Show file tree
Hide file tree
Showing 8 changed files with 272,938 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/developer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install libnetcdf-dev libnetcdff-dev netcdf-bin pkg-config
sudo apt-get install libpng-dev autotools-dev autoconf gcovr
sudo apt-get install libpng-dev autotools-dev libaec-dev autoconf gcovr
- name: cache-jasper
id: cache-jasper
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
export CFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
export FCFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
export FFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
cmake .. -DFTP_TEST_FILES=ON -DTEST_FILE_DIR=/home/runner/data
cmake .. -DFTP_TEST_FILES=ON -DTEST_FILE_DIR=/home/runner/data -DUSE_NETCDF4=ON -DUSE_AEC=ON
make VERBOSE=1
ctest --verbose --output-on-failure --rerun-failed
gcovr --root .. -v --html-details --exclude ../tests --exclude CMakeFiles --print-summary -o test-coverage.html &> /dev/null
Expand Down
5 changes: 3 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ copy_test_data(gdaswave.t00z.wcoast.0p16.f000.grib2)
copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.grib2.inv)
copy_test_data(ref_npts_gdaswave.t00z.wcoast.0p16.f000.grib2.txt)
copy_test_data(ref_simple_packing.grib2)
copy_test_data(ref_WW3_Regional_US_West_Coast_20220718_0000.grib2.inv)
copy_test_data(tmp_int.grb)
copy_test_data(gdas.t12z.pgrb2.1p00.anl.75r.grib2)
copy_test_data(ref_wind.gdas.t12z.pgrb2.1p00.anl.75r.grib2.inv)
copy_test_data(ref_uv.gdas.t12z.pgrb2.1p00.anl.75r.grib2.inv)
Expand All @@ -114,6 +112,9 @@ shell_test(run_wgrib2_rpn_tests)

if (USE_NETCDF4)
shell_test(run_wgrib2_netcdf4_tests)
copy_test_data(ref_ncdump4.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt)
copy_test_data(ref_tablenc.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt)
copy_test_data(nctab.table)
endif()
if (USE_NETCDF3)
shell_test(run_wgrib2_netcdf3_tests)
Expand Down
8 changes: 8 additions & 0 deletions tests/data/nctab.table
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$nlev 5
$levs 0.1 0.07 0.04 0.02 0.01
$grads 1
UGRD:*:u
VGRD:*:v
TMP:*:temp
HGT:*:hgtprs
RH:*:rh
272,829 changes: 272,829 additions & 0 deletions tests/data/ref_ncdump4.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions tests/data/ref_tablenc.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
netcdf tablenc {
dimensions:
latitude = 181 ;
longitude = 360 ;
time = UNLIMITED ; // (1 currently)
plevel = 5 ;
variables:
double latitude(latitude) ;
latitude:units = "degrees_north" ;
latitude:long_name = "latitude" ;
double longitude(longitude) ;
longitude:units = "degrees_east" ;
longitude:long_name = "longitude" ;
double time(time) ;
time:units = "seconds since 1970-01-01 00:00:00.0 0:00" ;
time:long_name = "verification time generated by wgrib2 function verftime()" ;
time:reference_time = 1714132800. ;
time:reference_time_type = 1 ;
time:reference_date = "2024.04.26 12:00:00 UTC" ;
time:reference_time_description = "analyses, reference date is fixed" ;
time:time_step_setting = "auto" ;
time:time_step = 0. ;
float plevel(plevel) ;
plevel:lev_type = 100 ;
plevel:units = "mb" ;
plevel:long_name = "pressure level" ;
plevel:_FillValue = 9.999e+20f ;
float hgtprs(time, plevel, latitude, longitude) ;
hgtprs:_FillValue = 9.999e+20f ;
hgtprs:short_name = "hgtprs" ;
hgtprs:long_name = "Geopotential Height" ;
hgtprs:level = "pressure level" ;
hgtprs:units = "m" ;
float temp(time, plevel, latitude, longitude) ;
temp:_FillValue = 9.999e+20f ;
temp:short_name = "temp" ;
temp:long_name = "Temperature" ;
temp:level = "pressure level" ;
temp:units = "K" ;
float rh(time, plevel, latitude, longitude) ;
rh:_FillValue = 9.999e+20f ;
rh:short_name = "rh" ;
rh:long_name = "Relative Humidity" ;
rh:level = "pressure level" ;
rh:units = "percent" ;
float u(time, plevel, latitude, longitude) ;
u:_FillValue = 9.999e+20f ;
u:short_name = "u" ;
u:long_name = "U-Component of Wind" ;
u:level = "pressure level" ;
u:units = "m/s" ;
float v(time, plevel, latitude, longitude) ;
v:_FillValue = 9.999e+20f ;
v:short_name = "v" ;
v:long_name = "V-Component of Wind" ;
v:level = "pressure level" ;
v:units = "m/s" ;

// global attributes:
:Conventions = "COARDS" ;
:History = "created by wgrib2" ;
:GRIB2_grid_template = 0 ;
}
Binary file removed tests/data/tmp_int.grb
Binary file not shown.
20 changes: 10 additions & 10 deletions tests/run_wgrib2_netcdf3_tests.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#!/bin/sh
# This checks the use of AEC compression, only available if USE_NETCDF4 is turned on in CMake.
# This checks the use of netcdf, only available if USE_NETCDF4 is turned on in CMake.
#
# Alyson Stahl, 4/22/24

set -e
set -x

echo "*** Testing converting from grib to netcdf to grib"
# make template
../wgrib2/wgrib2 data/tmp_int.grb -rpn 0 -grib_out junk.template
../wgrib2/wgrib2 data/ref_simple_packing.grib2 -rpn 0 -grib_out junk_netcdf.template

# make netcdf file
../wgrib2/wgrib2 data/tmp_int.grb -nc3 -netcdf junk.nc
../wgrib2/wgrib2 data/ref_simple_packing.grib2 -nc3 -netcdf junk_netcdf.nc

# convert netcdf to grb
../wgrib2/wgrib2 junk.template -import_netcdf junk.nc TMP_500mb "0:1:0:181:0:360" -grib_out junk.grb
../wgrib2/wgrib2 junk_netcdf.template -import_netcdf junk_netcdf.nc TMP_500mb "0:1:0:181:0:360" -grib_out junk_netcdf.grb

n=`../wgrib2/wgrib2 data/tmp_int.grb -var -lev -rpn "sto_1" -import_grib junk.grb -rpn "rcl_1:print_rms" | \
n=`../wgrib2/wgrib2 data/ref_simple_packing.grib2 -var -lev -rpn "sto_1" -import_grib junk_netcdf.grb -rpn "rcl_1:print_rms" | \
grep -v ":rpn=0:" | wc -l`

rm junk.grb junk.nc junk.template
if [ "$n" -eq 1 ] ; then
echo "success"
exit 0
else
rm junk_netcdf.grb junk_netcdf.nc junk_netcdf.template
if [ "$n" -ne 1 ] ; then
exit 1
fi

echo "*** SUCCESS!"
exit 0
34 changes: 23 additions & 11 deletions tests/run_wgrib2_netcdf4_tests.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
#!/bin/sh
# This checks the use of AEC compression, only available if USE_NETCDF4 is turned on in CMake.
# This checks the use of netcdf, only available if USE_NETCDF4 is turned on in CMake.
#
# Alyson Stahl, 4/22/24

set -e
set -x

echo "*** Testing converting from grib to netcdf to grib"
# make template
../wgrib2/wgrib2 data/tmp_int.grb -rpn 0 -grib_out junk.template
../wgrib2/wgrib2 data/ref_simple_packing.grib2 -rpn 0 -grib_out junk_netcdf.template

# make netcdf file
../wgrib2/wgrib2 data/tmp_int.grb -nc4 -netcdf junk.nc
../wgrib2/wgrib2 data/ref_simple_packing.grib2 -nc4 -netcdf junk_netcdf.nc

# convert netcdf to grb
../wgrib2/wgrib2 junk.template -import_netcdf junk.nc TMP_500mb "0:1:0:181:0:360" -grib_out junk.grb
../wgrib2/wgrib2 junk_netcdf.template -import_netcdf junk_netcdf.nc TMP_500mb "0:1:0:181:0:360" -grib_out junk_netcdf.grb

n=`../wgrib2/wgrib2 data/tmp_int.grb -var -lev -rpn "sto_1" -import_grib junk.grb -rpn "rcl_1:print_rms" | \
n=`../wgrib2/wgrib2 data/ref_simple_packing.grib2 -var -lev -rpn "sto_1" -import_grib junk_netcdf.grb -rpn "rcl_1:print_rms" | \
grep -v ":rpn=0:" | wc -l`

rm junk.grb junk.nc junk.template
if [ "$n" -eq 1 ] ; then
echo "success"
exit 0
else
rm junk_netcdf.grb junk_netcdf.nc junk_netcdf.template
if [ "$n" -ne 1 ] ; then
exit 1
fi

echo "*** Testing converting from grib to netcdf with variables stored in 3D structure"
../wgrib2/wgrib2 data/gdas.t12z.pgrb2.1p00.anl.75r.grib2 -nc_nlev 7 -netcdf junk_netcdf.nc -match ":(UGRD|VGRD|HGT|TMP):"
ncdump -v HGT,TMP,UGRD,VGRD junk_netcdf.nc > netcdf.txt
touch netcdf.txt
diff -w data/ref_ncdump4.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt netcdf.txt


echo "*** Testing converting from grib to netcdf using table"
../wgrib2/wgrib2 data/gdas.t12z.pgrb2.1p00.anl.75r.grib2 -match ":(UGRD|VGRD|TMP|HGT|RH):" -nc_table data/nctab.table -netcdf tablenc.nc
ncdump -h tablenc.nc > tablenc.txt
touch tablenc.txt
diff -w tablenc.txt data/ref_tablenc.gdas.t12z.pgrb2.1p00.anl.75r.grib2.txt

echo "*** SUCCESS!"
exit 0

0 comments on commit 7264649

Please sign in to comment.