diff --git a/met/data/wrappers/Makefile.am b/met/data/wrappers/Makefile.am index f3518fa27b..d2f83ff125 100644 --- a/met/data/wrappers/Makefile.am +++ b/met/data/wrappers/Makefile.am @@ -21,13 +21,12 @@ SUBDIRS = wrappersdir = $(pkgdatadir)/wrappers wrappers_DATA = \ - generic_python.py \ - generic_pickle.py \ + set_python_env.py \ read_tmp_dataplane.py \ - write_tmp_dataplane.py \ - write_pickle_mpr.py \ read_tmp_ascii.py \ - write_tmp_point.py + write_tmp_dataplane.py \ + write_tmp_point.py \ + write_tmp_mpr.py EXTRA_DIST = ${wrappers_DATA} diff --git a/met/data/wrappers/generic_pickle.py b/met/data/wrappers/generic_pickle.py deleted file mode 100644 index 2ea1528f56..0000000000 --- a/met/data/wrappers/generic_pickle.py +++ /dev/null @@ -1,10 +0,0 @@ -######################################################################## -# -# When MET_PYTHON_EXE is defined, this script initializes the Python -# environment for reading the temporary pickle file back into MET. -# -######################################################################## - -import sys -import numpy as np -import pickle diff --git a/met/data/wrappers/read_tmp_ascii.py b/met/data/wrappers/read_tmp_ascii.py index b4f4303044..66c008e3cd 100644 --- a/met/data/wrappers/read_tmp_ascii.py +++ b/met/data/wrappers/read_tmp_ascii.py @@ -8,6 +8,8 @@ Message_Type, Station_ID, Valid_Time, Lat, Lon, Elevation, GRIB_Code or Variable_Name, Level, Height, QC_String, Observation_Value +MPR format: See documentation of the MPR line type + Version Date 1.0.0 2021/02/18 David Fillmore Initial version """ @@ -18,25 +20,22 @@ import argparse -point_data = None - def read_tmp_ascii(filename): """ Arguments: - filename (string): temporary file created by write_tmp_point.py + filename (string): temporary file created by write_tmp_point.py or write_tmp_mpr.py Returns: - (list of lists): point data + (list of lists): point or mpr data """ - print('read_tmp_ascii:' + filename) f = open(filename, 'r') lines = f.readlines() f.close() - global point_data - point_data = [eval(line.strip('\n')) for line in lines] - - return point_data + global ascii_data + ascii_data = [eval(line.strip('\n')) for line in lines] + + return ascii_data if __name__ == '__main__': """ diff --git a/met/data/wrappers/generic_python.py b/met/data/wrappers/set_python_env.py similarity index 63% rename from met/data/wrappers/generic_python.py rename to met/data/wrappers/set_python_env.py index b436b6325a..5b6c2743c2 100644 --- a/met/data/wrappers/generic_python.py +++ b/met/data/wrappers/set_python_env.py @@ -1,11 +1,9 @@ ######################################################################## # -# When MET_PYTHON_EXE is not defined, this script initializes -# MET's python runtime environment. +# This script initializes MET's python runtime environment. # ######################################################################## import os import sys import numpy as np -import pickle diff --git a/met/data/wrappers/write_pickle_mpr.py b/met/data/wrappers/write_pickle_mpr.py deleted file mode 100644 index 2e3f2d0d04..0000000000 --- a/met/data/wrappers/write_pickle_mpr.py +++ /dev/null @@ -1,33 +0,0 @@ -######################################################################## -# -# Adapted from a script provided by George McCabe -# Adapted by Randy Bullock -# -# usage: /path/to/python write_pickle_mpr.py \ -# pickle_output_filename .py -# -######################################################################## - -import os -import sys -import pickle -import importlib.util - -print('Python Script:\t', sys.argv[0]) -print('User Command:\t', sys.argv[2:]) -print('Write Pickle:\t', sys.argv[1]) - -pickle_filename = sys.argv[1] - -pyembed_module_name = sys.argv[2] -sys.argv = sys.argv[2:] - -user_base = os.path.basename(pyembed_module_name).replace('.py','') - -spec = importlib.util.spec_from_file_location(user_base, pyembed_module_name) -met_in = importlib.util.module_from_spec(spec) -spec.loader.exec_module(met_in) - -print(met_in) - -pickle.dump( met_in.mpr_data, open( pickle_filename, "wb" ) ) diff --git a/met/data/wrappers/write_tmp_dataplane.py b/met/data/wrappers/write_tmp_dataplane.py index b9194b2920..ff254bf978 100644 --- a/met/data/wrappers/write_tmp_dataplane.py +++ b/met/data/wrappers/write_tmp_dataplane.py @@ -13,6 +13,10 @@ import importlib.util import netCDF4 as nc +print("Python Script:\t" + repr(sys.argv[0])) +print("User Command:\t" + repr(' '.join(sys.argv[2:]))) +print("Temporary File:\t" + repr(sys.argv[1])) + netcdf_filename = sys.argv[1] pyembed_module_name = sys.argv[2] sys.argv = sys.argv[2:] diff --git a/met/data/wrappers/write_tmp_mpr.py b/met/data/wrappers/write_tmp_mpr.py new file mode 100644 index 0000000000..ed0f4f0675 --- /dev/null +++ b/met/data/wrappers/write_tmp_mpr.py @@ -0,0 +1,39 @@ +######################################################################## +# +# Adapted from a script provided by George McCabe +# Adapted by Randy Bullock +# +# usage: /path/to/python write_tmp_mpr.py \ +# tmp_output_filename .py +# +######################################################################## + +import os +import sys +import importlib.util + +print("Python Script:\t" + repr(sys.argv[0])) +print("User Command:\t" + repr(' '.join(sys.argv[2:]))) +print("Temporary File:\t" + repr(sys.argv[1])) + +tmp_filename = sys.argv[1] +pyembed_module_name = sys.argv[2] +sys.argv = sys.argv[2:] + +# append user script dir to system path +pyembed_dir, pyembed_file = os.path.split(pyembed_module_name) +if pyembed_dir: + sys.path.insert(0, pyembed_dir) + +if not pyembed_module_name.endswith('.py'): + pyembed_module_name += '.py' + +user_base = os.path.basename(pyembed_module_name).replace('.py','') + +spec = importlib.util.spec_from_file_location(user_base, pyembed_module_name) +met_in = importlib.util.module_from_spec(spec) +spec.loader.exec_module(met_in) + +f = open(tmp_filename, 'w') +for line in met_in.mpr_data: + f.write(str(line) + '\n') diff --git a/met/data/wrappers/write_tmp_point.py b/met/data/wrappers/write_tmp_point.py index 94f56cd3dd..b6cecddfbb 100644 --- a/met/data/wrappers/write_tmp_point.py +++ b/met/data/wrappers/write_tmp_point.py @@ -4,7 +4,7 @@ # Adapted by Randy Bullock # # usage: /path/to/python write_tmp_point.py \ -# tmp_ascii_output_filename .py +# tmp_output_filename .py # ######################################################################## @@ -12,15 +12,22 @@ import sys import importlib.util -print('Python Script:\t', sys.argv[0]) -print('User Command:\t', sys.argv[2:]) -print('Write Temporary Ascii:\t', sys.argv[1]) +print("Python Script:\t" + repr(sys.argv[0])) +print("User Command:\t" + repr(' '.join(sys.argv[2:]))) +print("Temporary File:\t" + repr(sys.argv[1])) tmp_filename = sys.argv[1] - pyembed_module_name = sys.argv[2] sys.argv = sys.argv[2:] +# append user script dir to system path +pyembed_dir, pyembed_file = os.path.split(pyembed_module_name) +if pyembed_dir: + sys.path.insert(0, pyembed_dir) + +if not pyembed_module_name.endswith('.py'): + pyembed_module_name += '.py' + user_base = os.path.basename(pyembed_module_name).replace('.py','') spec = importlib.util.spec_from_file_location(user_base, pyembed_module_name) diff --git a/met/docs/Users_Guide/appendixF.rst b/met/docs/Users_Guide/appendixF.rst index a5e34df338..ee895a8166 100644 --- a/met/docs/Users_Guide/appendixF.rst +++ b/met/docs/Users_Guide/appendixF.rst @@ -35,11 +35,11 @@ The types of Python embedding supported in MET are described below. In all cases Setting this environment variable triggers slightly different processing logic in MET. Rather than executing the user-specified script with compiled Python instance directly, MET does the following: -1. Wrap the user's Python script and arguments with a wrapper script (write_pickle_mpr.py, write_pickle_point.py, or write_pickle_dataplane.py) and specify the name of a temporary file to be written. +1. Wrap the user's Python script and arguments with a wrapper script (write_tmp_mpr.py, write_tmp_point.py, or write_tmp_dataplane.py) and specify the name of a temporary file to be written. -2. Use a system call to the **MET_PYTHON_EXE** Python instance to execute these commands and write the resulting data objects to a temporary Python pickle file. +2. Use a system call to the **MET_PYTHON_EXE** Python instance to execute these commands and write the resulting data objects to a temporary ASCII or NetCDF file. -3. Use the compiled Python instance to read data from that temporary pickle file. +3. Use the compiled Python instance to run a wrapper script (read_tmp_ascii.py or read_tmp_dataplane.py) to read data from that temporary file. With this approach, users should be able to execute Python scripts in their own custom environments. diff --git a/met/scripts/python/read_ascii_mpr.py b/met/scripts/python/read_ascii_mpr.py index 781485c58c..4a8c988405 100755 --- a/met/scripts/python/read_ascii_mpr.py +++ b/met/scripts/python/read_ascii_mpr.py @@ -6,7 +6,7 @@ ######################################################################## -print('Python Script:\t', sys.argv[0]) +print("Python Script:\t" + repr(sys.argv[0])) ## ## input file specified on the command line diff --git a/met/scripts/python/read_ascii_numpy.py b/met/scripts/python/read_ascii_numpy.py index 70393db6d8..b7a1e081b4 100755 --- a/met/scripts/python/read_ascii_numpy.py +++ b/met/scripts/python/read_ascii_numpy.py @@ -6,7 +6,7 @@ ########################################### -print('Python Script:\t', sys.argv[0]) +print("Python Script:\t" + repr(sys.argv[0])) ## ## input file specified on the command line diff --git a/met/scripts/python/read_ascii_numpy_grid.py b/met/scripts/python/read_ascii_numpy_grid.py index 88d868a2ad..fa72cbff6b 100755 --- a/met/scripts/python/read_ascii_numpy_grid.py +++ b/met/scripts/python/read_ascii_numpy_grid.py @@ -6,7 +6,7 @@ ########################################### -print('Python Script:\t', sys.argv[0]) +print("Python Script:\t" + repr(sys.argv[0])) ## ## input file specified on the command line diff --git a/met/scripts/python/read_ascii_point.py b/met/scripts/python/read_ascii_point.py index d5521eb0ca..cfd37d272a 100755 --- a/met/scripts/python/read_ascii_point.py +++ b/met/scripts/python/read_ascii_point.py @@ -6,7 +6,7 @@ ######################################################################## -print('Python Script:\t', sys.argv[0]) +print("Python Script:\t" + repr(sys.argv[0])) ## ## input file specified on the command line diff --git a/met/scripts/python/read_ascii_xarray.py b/met/scripts/python/read_ascii_xarray.py index 0d15030f88..53f8574d48 100755 --- a/met/scripts/python/read_ascii_xarray.py +++ b/met/scripts/python/read_ascii_xarray.py @@ -7,7 +7,7 @@ ########################################### -print('Python Script:\t', sys.argv[0]) +print("Python Script:\t" + repr(sys.argv[0])) ## ## input file specified on the command line diff --git a/met/src/basic/vx_util/data_line.cc b/met/src/basic/vx_util/data_line.cc index da012b9a0a..16f275327e 100644 --- a/met/src/basic/vx_util/data_line.cc +++ b/met/src/basic/vx_util/data_line.cc @@ -193,18 +193,12 @@ out << prefix << "\n"; if ( N_items == 0 ) { out.flush(); return; } -// std::ostringstream sstream; -// sstream.width(2); - for (j=0; j(ldf); +PyLineDataFile * pldf = dynamic_cast(ldf); - if ( pldf ) { +if ( pldf ) { - const bool status = read_py_single_text_line(pldf); + const bool status = read_py_single_text_line(pldf); - return ( status ); + return ( status ); - } +} #endif /* WITH_PYTHON */ -//////////////////////////////////////////////////// ifstream & f = *(ldf->in); @@ -606,6 +587,7 @@ return ( true ); #endif /* WITH_PYTHON */ + //////////////////////////////////////////////////////////////////////// @@ -848,6 +830,7 @@ for (j=0; j " - << "pickle object is not a list!\n\n"; + << "tmp ascii object is not a list!\n\n"; exit ( 1 ); @@ -301,7 +303,7 @@ void PyLineDataFile::do_straight() ConcatString command, path, user_base; -path = generic_python_wrapper; +path = set_python_env_wrapper; mlog << Debug(3) << "PyLineDataFile::do_straight() -> " @@ -372,7 +374,13 @@ return; //////////////////////////////////////////////////////////////////////// -void PyLineDataFile::do_pickle() + // + // wrapper usage: /path/to/python wrapper.py + // tmp_output_filename user_script_name + // [ user_script args ... ] + // + +void PyLineDataFile::do_tmp_ascii() { @@ -380,7 +388,7 @@ int j; const int N = UserScriptArgs.n(); ConcatString command; ConcatString path; -ConcatString pickle_path; +ConcatString tmp_ascii_path; const char * tmp_dir = 0; int status; @@ -394,15 +402,16 @@ if ( ! tmp_dir ) tmp_dir = default_tmp_dir; path << cs_erase << tmp_dir << '/' - << pickle_base_name; + << tmp_base_name; -pickle_path = make_temp_file_name(path.text(), 0); +tmp_ascii_path = make_temp_file_name(path.text(), 0); +tmp_ascii_path << ".txt"; command << cs_erase - << UserPathToPython << ' ' // user's path to python - << replace_path(write_pickle_wrapper) << ' ' // write_pickle.py - << pickle_path << ' ' // pickle output filename - << UserScriptPath; // user's script name + << UserPathToPython << ' ' // user's path to python + << replace_path(write_tmp_mpr_wrapper) << ' ' // write_tmp_mpr.py + << tmp_ascii_path << ' ' // temporary ascii output filename + << UserScriptPath; // user's script name for (j=0; j " + mlog << Error << "\nPyLineDataFile::do_tmp_ascii() -> " << "command \"" << command.text() << "\" failed ... status = " << status << "\n\n"; @@ -427,31 +436,24 @@ if ( status ) { ConcatString wrapper; -wrapper = generic_pickle_wrapper; +wrapper = set_python_env_wrapper; script = new Python3_Script (wrapper.text()); mlog << Debug(4) << "Reading temporary Python line data file: " - << pickle_path << "\n"; - -script->read_pickle(list_name, pickle_path.text()); + << tmp_ascii_path << "\n"; -main_list = script->lookup(list_name); +script->import_read_tmp_ascii_py(); -if ( ! main_list ) { +PyObject * dobj = script->read_tmp_ascii(tmp_ascii_path.text()); - mlog << Error << "\nPyLineDataFile::do_pickle() ->" - << "nul main list pointer!\n\n"; - - exit ( 1 ); - -} +main_list = script->lookup_ascii(tmp_list_name); // // cleanup // -remove_temp_file(pickle_path); +remove_temp_file(tmp_ascii_path); // // done diff --git a/met/src/basic/vx_util/python_line.h b/met/src/basic/vx_util/python_line.h index b5a51bd230..5f994a144d 100644 --- a/met/src/basic/vx_util/python_line.h +++ b/met/src/basic/vx_util/python_line.h @@ -52,8 +52,8 @@ class PyLineDataFile : public LineDataFile { ConcatString UserPathToPython; - void do_straight (); // straight-up python, no pickle - void do_pickle (); // pickle + void do_straight (); // run compiled python interpreter + void do_tmp_ascii(); // run user-defined MET_PYTHON_EXE ConcatString make_header_line () const; ConcatString make_data_line (); diff --git a/met/src/libcode/vx_data2d_python/Makefile.am b/met/src/libcode/vx_data2d_python/Makefile.am index ae3d3c21d3..185dd5d548 100644 --- a/met/src/libcode/vx_data2d_python/Makefile.am +++ b/met/src/libcode/vx_data2d_python/Makefile.am @@ -17,7 +17,6 @@ libvx_data2d_python_a_SOURCES = \ grid_from_python_dict.h grid_from_python_dict.cc \ python_dataplane.h python_dataplane.cc \ data2d_python.h data2d_python.cc \ - var_info_python.h var_info_python.cc \ - global_python.h + var_info_python.h var_info_python.cc libvx_data2d_python_a_CPPFLAGS = ${MET_CPPFLAGS} -I../vx_python2_utils ${MET_PYTHON_CC} $(MET_PYTHON_LD) diff --git a/met/src/libcode/vx_python3_utils/Makefile.am b/met/src/libcode/vx_python3_utils/Makefile.am index 0f45bb5214..3d0941ec47 100644 --- a/met/src/libcode/vx_python3_utils/Makefile.am +++ b/met/src/libcode/vx_python3_utils/Makefile.am @@ -22,5 +22,6 @@ libvx_python3_utils_a_SOURCES = \ python3_script.h python3_script.cc \ python3_numpy.h python3_numpy.cc \ python3_util.h python3_util.cc \ - vx_python3_utils.h + vx_python3_utils.h \ + global_python.h libvx_python3_utils_a_CPPFLAGS = ${MET_CPPFLAGS} ${CPPFLAGS} ${MET_PYTHON_CC} $(MET_PYTHON_LD) diff --git a/met/src/libcode/vx_data2d_python/global_python.h b/met/src/libcode/vx_python3_utils/global_python.h similarity index 100% rename from met/src/libcode/vx_data2d_python/global_python.h rename to met/src/libcode/vx_python3_utils/global_python.h diff --git a/met/src/libcode/vx_python3_utils/python3_script.cc b/met/src/libcode/vx_python3_utils/python3_script.cc index 7bd567ae2c..d9ac7f41e5 100644 --- a/met/src/libcode/vx_python3_utils/python3_script.cc +++ b/met/src/libcode/vx_python3_utils/python3_script.cc @@ -165,8 +165,10 @@ return ( var ); } + //////////////////////////////////////////////////////////////////////// + PyObject * Python3_Script::lookup_ascii(const char * name) const { @@ -175,10 +177,30 @@ PyObject * var = 0; var = PyDict_GetItemString (DictAscii, name); +if ( ! var ) { + + mlog << Error << "\nPython3_Script::lookup_ascii(const char * name) -> " + << "value for name \"" << name << "\" not found\n\n"; + + + exit ( 1 ); + +} + +if ( ! PyList_Check(var) ) { + + mlog << Error << "\nPython3_Script::lookup_ascii(const char * name) -> " + << "value for name \"" << name << "\" not a python list\n\n"; + + exit ( 1 ); + +} + return ( var ); } + //////////////////////////////////////////////////////////////////////// @@ -219,46 +241,6 @@ return pobj; //////////////////////////////////////////////////////////////////////// - // - // example: - // - // data = pickle.load( open( "save.p", "rb" ) ) - // - - -void Python3_Script::read_pickle(const char * variable, const char * pickle_filename) const - -{ - -mlog << Debug(3) << "Reading temporary pickle file: " - << pickle_filename << "\n"; - -ConcatString command; - -command << variable - << " = pickle.load(open(\"" - << pickle_filename - << "\", \"rb\"))"; - -PyErr_Clear(); - -run(command.text()); - -if ( PyErr_Occurred() ) { - - mlog << Error << "\nPython3_Script::read_pickle() -> " - << "command \"" << command << "\" failed!\n\n"; - - exit ( 1 ); - -} - -return; - -} - -//////////////////////////////////////////////////////////////////////// - void Python3_Script::import_read_tmp_ascii_py(void) { @@ -310,8 +292,10 @@ fflush(stderr); } + //////////////////////////////////////////////////////////////////////// + PyObject* Python3_Script::read_tmp_ascii(const char * tmp_filename) const { @@ -325,8 +309,6 @@ command << "read_tmp_ascii(\"" << tmp_filename << "\")"; -mlog << Debug(3) << command << "\n"; - PyErr_Clear(); PyObject * pobj; @@ -341,15 +323,11 @@ if ( PyErr_Occurred() ) { exit ( 1 ); } -PyTypeObject* type = pobj->ob_type; - -const char* p = type->tp_name; - -mlog << Debug(2) << "read_tmp_ascii return type: " << p << "\n"; - return pobj; + } + //////////////////////////////////////////////////////////////////////// diff --git a/met/src/libcode/vx_python3_utils/python3_script.h b/met/src/libcode/vx_python3_utils/python3_script.h index 6930d226a5..1174385c15 100644 --- a/met/src/libcode/vx_python3_utils/python3_script.h +++ b/met/src/libcode/vx_python3_utils/python3_script.h @@ -83,8 +83,6 @@ class Python3_Script { PyObject * run(const char * command) const; // runs a command in the namespace of the script - void read_pickle (const char * variable_name, const char * pickle_filename) const; - void import_read_tmp_ascii_py (void); PyObject * read_tmp_ascii (const char * tmp_filename) const; diff --git a/met/src/libcode/vx_python3_utils/python3_util.cc b/met/src/libcode/vx_python3_utils/python3_util.cc index 82990d8999..fe56b6f6b2 100644 --- a/met/src/libcode/vx_python3_utils/python3_util.cc +++ b/met/src/libcode/vx_python3_utils/python3_util.cc @@ -117,7 +117,6 @@ if ( PyLong_Check(obj) ) { // long? } - return ( k ); } @@ -154,7 +153,6 @@ if ( PyLong_Check(obj) ) { // long? } - return ( x ); } @@ -205,8 +203,6 @@ if ( PyUnicode_Check(obj) ) { // string? mlog << Error << "\npyobject_as_concat_string(PyObject *) -> " << "bad object type\n\n"; - cout << "\n\n pyobject_as_concat_string: obj = " << obj << "\n\n" << flush; - exit ( 1 ); } diff --git a/met/src/libcode/vx_statistics/pair_base.cc b/met/src/libcode/vx_statistics/pair_base.cc index 0fe6a1b006..1061423e25 100644 --- a/met/src/libcode/vx_statistics/pair_base.cc +++ b/met/src/libcode/vx_statistics/pair_base.cc @@ -496,8 +496,7 @@ void PairBase::set_point_obs(int i_obs, const char *sid, if(i_obs < 0 || i_obs >= n_obs) { mlog << Error << "\nPairBase::set_point_obs() -> " << "range check error: " << i_obs << " not in (0, " - << n_obs << ").\n\n" - ; + << n_obs << ").\n\n"; exit(1); } diff --git a/met/src/tools/core/stat_analysis/stat_analysis.cc b/met/src/tools/core/stat_analysis/stat_analysis.cc index c3d6788b71..02365d1525 100644 --- a/met/src/tools/core/stat_analysis/stat_analysis.cc +++ b/met/src/tools/core/stat_analysis/stat_analysis.cc @@ -39,6 +39,8 @@ // 010 07/26/18 Halley Gotway Support masks from gen_vx_mask. // 011 10/14/19 Halley Gotway Add support for climo distribution // percentile thresholds. +// 012 04/25/21 Halley Gotway Replace pickle files for temporary +// ascii. // //////////////////////////////////////////////////////////////////////// diff --git a/met/src/tools/other/ascii2nc/ascii2nc.cc b/met/src/tools/other/ascii2nc/ascii2nc.cc index 360329659c..6df5e2ba97 100644 --- a/met/src/tools/other/ascii2nc/ascii2nc.cc +++ b/met/src/tools/other/ascii2nc/ascii2nc.cc @@ -43,7 +43,8 @@ // 015 03-20-19 Fillmore Add aeronetv2 and aeronetv3 options. // 016 01-30-20 Bullock Add python option. // 017 01-25-21 Halley Gotway MET #1630 Handle zero obs. -// 018 03-01-21 Fillmore Replace pickle files for temporary ascii. +// 018 03-01-21 Fillmore Replace pickle files for temporary +// ascii. // //////////////////////////////////////////////////////////////////////// diff --git a/met/src/tools/other/ascii2nc/python_handler.cc b/met/src/tools/other/ascii2nc/python_handler.cc index 09c7b90d2c..2f3a0927c9 100644 --- a/met/src/tools/other/ascii2nc/python_handler.cc +++ b/met/src/tools/other/ascii2nc/python_handler.cc @@ -26,12 +26,14 @@ using namespace std; //////////////////////////////////////////////////////////////////////// -static const char generic_python_wrapper [] = "generic_python"; +static const char set_python_env_wrapper [] = "set_python_env"; static const char write_tmp_ascii_wrapper[] = "MET_BASE/wrappers/write_tmp_point.py"; static const char list_name [] = "point_data"; +static const char tmp_list_name [] = "ascii_data"; + static const char tmp_base_name [] = "tmp_ascii2nc"; @@ -230,8 +232,8 @@ bool PythonHandler::readAsciiFiles(const vector< ConcatString > &ascii_filename_ bool status = false; -if ( use_tmp_ascii ) status = do_tmp_ascii (); -else status = do_straight (); +if ( use_tmp_ascii ) status = do_tmp_ascii (); +else status = do_straight (); return ( status ); @@ -247,7 +249,7 @@ bool PythonHandler::do_straight() ConcatString command, path, user_base; -path = generic_python_wrapper; +path = set_python_env_wrapper; mlog << Debug(3) << "Running user's python script (" @@ -319,7 +321,9 @@ return ( true ); // - // wrapper usage: /path/to/python wrapper.py tmp_output_filename user_script_name [ user_script args ... ] + // wrapper usage: /path/to/python wrapper.py + // tmp_output_filename user_script_name + // [ user_script args ... ] // bool PythonHandler::do_tmp_ascii() @@ -378,7 +382,7 @@ if ( status ) { ConcatString wrapper; -wrapper = generic_python_wrapper; +wrapper = set_python_env_wrapper; Python3_Script script(wrapper.text()); @@ -389,7 +393,7 @@ script.import_read_tmp_ascii_py(); PyObject * dobj = script.read_tmp_ascii(tmp_ascii_path.text()); -PyObject * obj = script.lookup_ascii(list_name); +PyObject * obj = script.lookup_ascii(tmp_list_name); if ( ! PyList_Check(obj) ) { diff --git a/met/src/tools/other/ascii2nc/python_handler.h b/met/src/tools/other/ascii2nc/python_handler.h index b0fb2ef492..695b8fcb96 100644 --- a/met/src/tools/other/ascii2nc/python_handler.h +++ b/met/src/tools/other/ascii2nc/python_handler.h @@ -68,12 +68,11 @@ class PythonHandler : public FileHandler virtual bool readAsciiFiles(const vector< ConcatString > &ascii_filename_list); - bool do_tmp_ascii(); - bool do_straight (); // straight-up python, no temporary ascii + bool do_straight (); // run compiled python interpreter + bool do_tmp_ascii(); // run user-defined MET_PYTHON_EXE void load_python_obs(PyObject *); // python object is list of lists - bool read_obs_from_script (const char * script_name, const char * variable_name); }; diff --git a/test/xml/unit_python.xml b/test/xml/unit_python.xml index 6ed8dfa9d8..572e2f925d 100644 --- a/test/xml/unit_python.xml +++ b/test/xml/unit_python.xml @@ -374,24 +374,24 @@ - - + + &MET_BIN;/ascii2nc MET_PYTHON_EXE &MET_PYTHON_EXE; \ "&MET_BASE;/python/read_ascii_point.py &MET_DATA;/sample_obs/ascii/sample_ascii_obs.txt" \ - &OUTPUT_DIR;/python/ascii2nc_pickle.nc \ + &OUTPUT_DIR;/python/ascii2nc_user_python.nc \ -format python - &OUTPUT_DIR;/python/ascii2nc_pickle.nc + &OUTPUT_DIR;/python/ascii2nc_user_python.nc - - + + export PATH='&ANACONDA_BIN;:${PATH}'; \ &MET_BIN;/plot_data_plane @@ -399,19 +399,19 @@ \ PYTHON_NUMPY \ - &OUTPUT_DIR;/python/letter_pickle.ps \ + &OUTPUT_DIR;/python/letter_user_python.ps \ 'name = "&MET_BASE;/python/read_ascii_numpy.py &DATA_DIR_PYTHON;/letter.txt LETTER";' \ -plot_range 0.0 255.0 \ -title "Python enabled plot_data_plane" \ -v 1 - &OUTPUT_DIR;/python/letter_pickle.ps + &OUTPUT_DIR;/python/letter_user_python.ps - - + + &MET_BIN;/stat_analysis MET_PYTHON_EXE &MET_PYTHON_EXE; @@ -419,10 +419,10 @@ \ -lookin python &MET_BASE;/python/read_ascii_mpr.py &OUTPUT_DIR;/python/point_stat_120000L_20050807_120000V.stat \ -job aggregate_stat -line_type MPR -out_line_type sl1l2 -by FCST_VAR \ - -out_stat &OUTPUT_DIR;/python/stat_analysis_pickle_AGGR_MPR_to_SL1L2.stat + -out_stat &OUTPUT_DIR;/python/stat_analysis_user_python_AGGR_MPR_to_SL1L2.stat - &OUTPUT_DIR;/python/stat_analysis_pickle_AGGR_MPR_to_SL1L2.stat + &OUTPUT_DIR;/python/stat_analysis_user_python_AGGR_MPR_to_SL1L2.stat