Skip to content

Commit

Permalink
Added test for teca_gradient.cxx
Browse files Browse the repository at this point in the history
  • Loading branch information
taobrienlbl committed May 18, 2022
1 parent ccf2f42 commit 3b32a89
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ env:
- BUILD_TYPE=Debug
- TECA_DIR=/travis_teca_dir
- TECA_PYTHON_VERSION=3
- TECA_DATA_REVISION=127
- TECA_DATA_REVISION=139
jobs:
- DOCKER_IMAGE=ubuntu IMAGE_VERSION=20.04 IMAGE_NAME=ubuntu_20_04 REQUIRE_NETCDF_MPI=TRUE
- DOCKER_IMAGE=ubuntu IMAGE_VERSION=20.04 IMAGE_NAME=ubuntu_20_04 REQUIRE_NETCDF_MPI=FALSE
Expand Down
9 changes: 9 additions & 0 deletions python/teca_py_alg.i
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "teca_descriptive_statistics.h"
#include "teca_evaluate_expression.h"
#include "teca_elevation_mask.h"
#include "teca_gradient.h"
#include "teca_integrated_vapor_transport.h"
#include "teca_indexed_dataset_cache.h"
#include "teca_l2_norm.h"
Expand Down Expand Up @@ -143,6 +144,14 @@
%ignore teca_vorticity::operator=;
%include "teca_vorticity.h"

/***************************************************************************
gradient
***************************************************************************/
%ignore teca_gradient::shared_from_this;
%shared_ptr(teca_gradient)
%ignore teca_gradient::operator=;
%include "teca_gradient.h"

/***************************************************************************
derived_quantity
***************************************************************************/
Expand Down
6 changes: 6 additions & 0 deletions test/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,9 @@ teca_add_test(py_test_cartesian_mesh_multi_dim
${CMAKE_CURRENT_SOURCE_DIR}/test_cartesian_mesh_multi_dim.py 32 32 10
test_cartesian_mesh_multi_dim.nc 1
FEATURES ${TECA_HAS_CUDA})

teca_add_test(py_test_gradient
COMMAND ${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/test_gradient.py
"${TECA_DATA_ROOT}/teca_gradient_test_input.nc"
"${TECA_DATA_ROOT}/teca_gradient_baseline.nc")
61 changes: 61 additions & 0 deletions test/python/test_gradient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from mpi4py import MPI
from teca import *
import os
import sys


if not len(sys.argv) == 3:
sys.stderr.write('test_apply_binary_mask.py [input_file] [baseline_file] \n')
sys.exit(-1)
input_file = sys.argv[1]
baseline_file = sys.argv[2]


# create the reader
mesh_data_reader = teca_cf_reader.New()
mesh_data_reader.set_files_regex(input_file)

# create the gradient calculation
grad = teca_gradient.New()
grad.set_scalar_field('p')
grad.set_gradient_field_x('grad_p_x')
grad.set_gradient_field_y('grad_p_y')
grad.set_input_connection(mesh_data_reader.get_output_port())

# create the executive
exec = teca_index_executive.New()
point_arrays = ["grad_p_x","grad_p_y"]
exec.set_arrays(point_arrays)

# check whether we should be generating the test
do_test = 1
try:
do_test = int(os.environ["TECA_DO_TEST"])
except:
pass

# do the test if flagged
if do_test and os.path.exists(baseline_file):
baseline_reader = teca_cf_reader.New()
baseline_reader.set_files_regex(baseline_file)

# check the difference with the baseline dataset
diff = teca_dataset_diff.New()
diff.set_input_connection(0, baseline_reader.get_output_port())
diff.set_input_connection(1, grad.get_output_port())
diff.set_executive(exec)
diff.set_verbose(1)

diff.update()
# otherwise generate the baseline file
else:
writer = teca_cf_writer.New()
writer.set_input_connection(grad.get_output_port())
writer.set_thread_pool_size(1)
#writer.set_executive(exec)
writer.set_point_arrays(point_arrays)
writer.set_file_name(baseline_file)
writer.update()
sys.exit(-1)

sys.exit(0)

0 comments on commit 3b32a89

Please sign in to comment.