From 1757cb1a139932a3e8157148e5b292c69e6247a8 Mon Sep 17 00:00:00 2001 From: johnhg Date: Mon, 5 Apr 2021 21:33:34 -0600 Subject: [PATCH] Feature 1747 pylonglong (#1748) * Per #1747, update MET to interpret longlong values as integers. NetCDF file attributes that have an LL suffix are read into python as numpy.int64 objects. Right now MET fails when trying to read those as integers. Update the parsing logic to interpret those as ints. * Per #1747, since MET can now interpret both long and longlong's as ints, there's no need to cast nx and ny to ints in the read_tmp_dataplane.py script anymore. * Per #1747, this is slightly unrelated. But after installing the netCDF4 module on kiowa for /usr/local/met-python3/bin/python3, we should no longer need a custom PATH setting to get unit_python.xml to work. Reverting the change I made to it a couple of days ago to get it working. --- met/data/wrappers/read_tmp_dataplane.py | 1 - met/src/libcode/vx_python3_utils/python3_dict.cc | 8 ++++++++ test/xml/unit_python.xml | 4 +--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/met/data/wrappers/read_tmp_dataplane.py b/met/data/wrappers/read_tmp_dataplane.py index e21c17ba3f..c6f8f57a9c 100644 --- a/met/data/wrappers/read_tmp_dataplane.py +++ b/met/data/wrappers/read_tmp_dataplane.py @@ -27,7 +27,6 @@ grid[grid_attr] = attr_val else: met_attrs[attr] = attr_val -grid['nx'], grid['ny'] = int(grid['nx']), int(grid['ny']) met_attrs['grid'] = grid met_attrs['name'] = met_attrs['name_str'] del met_attrs['name_str'] diff --git a/met/src/libcode/vx_python3_utils/python3_dict.cc b/met/src/libcode/vx_python3_utils/python3_dict.cc index 6d38599aa4..99a0d5fc93 100644 --- a/met/src/libcode/vx_python3_utils/python3_dict.cc +++ b/met/src/libcode/vx_python3_utils/python3_dict.cc @@ -164,6 +164,14 @@ if ( ! a ) { } +// If not a Long, try interpreting as LongLong for numpy.int64 values + +if ( ! PyLong_Check(a) ) { + + a = PyLong_FromLongLong(PyLong_AsLongLong(a)); + +} + if ( ! PyLong_Check(a) ) { mlog << Error << "\nPython3_Dict::lookup_int(const char *) -> " diff --git a/test/xml/unit_python.xml b/test/xml/unit_python.xml index 6ed8dfa9d8..1c89950159 100644 --- a/test/xml/unit_python.xml +++ b/test/xml/unit_python.xml @@ -7,7 +7,6 @@ - @@ -392,8 +391,7 @@ - export PATH='&ANACONDA_BIN;:${PATH}'; \ - &MET_BIN;/plot_data_plane + &MET_BIN;/plot_data_plane MET_PYTHON_EXE &MET_PYTHON_EXE;