diff --git a/.travis.yml b/.travis.yml index 7925846b8..2b54df587 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/python/teca_py_alg.i b/python/teca_py_alg.i index ffa7b3971..792516d87 100644 --- a/python/teca_py_alg.i +++ b/python/teca_py_alg.i @@ -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" @@ -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 ***************************************************************************/ diff --git a/test/python/CMakeLists.txt b/test/python/CMakeLists.txt index 0a696f808..9cf7f0d98 100644 --- a/test/python/CMakeLists.txt +++ b/test/python/CMakeLists.txt @@ -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") diff --git a/test/python/test_gradient.py b/test/python/test_gradient.py new file mode 100644 index 000000000..f83bb91f8 --- /dev/null +++ b/test/python/test_gradient.py @@ -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)