Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 1700 python #1765

Merged
merged 16 commits into from
Apr 26, 2021
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
050f24b
Per #1700, no real change, removing extra newline.
JohnHalleyGotway Apr 22, 2021
b4d297a
Merge branch 'develop' into feature_1700_python
JohnHalleyGotway Apr 22, 2021
94279ac
Per #1700, move global_python.h from vx_data2d_python over to the vx_…
JohnHalleyGotway Apr 22, 2021
bf6e760
Per #1700, no code changes. Just removing commented out code.
JohnHalleyGotway Apr 23, 2021
6125e8b
Per #1700, lots of little changes to make the python scripts consiste…
JohnHalleyGotway Apr 23, 2021
88226b7
Per #1700, rename generic_python.py to set_python_env.py. Still actua…
JohnHalleyGotway Apr 23, 2021
8a82ad6
Per #1700 remove the pickle import.
JohnHalleyGotway Apr 23, 2021
acf9bd0
Per #1700, work in progress. Replaced pickle file with tmp file.
JohnHalleyGotway Apr 23, 2021
9c31d61
Per #1700, work in progress. Replaced pickle file with tmp file.
JohnHalleyGotway Apr 23, 2021
f969442
Per #1700, update read_tmp_ascii.py to work for both ascii2nc and sta…
JohnHalleyGotway Apr 23, 2021
f765966
Per #1700, getting closer. Work in progress. Just need to get user-py…
JohnHalleyGotway Apr 23, 2021
8237705
Per #1700, removing extraneous cout.
JohnHalleyGotway Apr 23, 2021
c6f61fb
Per #1700, fix logic in PyLineDataFile::do_tmp_ascii() to get stat_an…
JohnHalleyGotway Apr 25, 2021
124a44b
Per #1700, just comments.
JohnHalleyGotway Apr 25, 2021
e28d653
Per #1700, replace references to pickle with user_python
JohnHalleyGotway Apr 25, 2021
624d1bb
Per #1700, update documentation to replace pickle with temp files.
JohnHalleyGotway Apr 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Per #1700, work in progress. Replaced pickle file with tmp file.
JohnHalleyGotway committed Apr 23, 2021
commit 9c31d61e3652cd48c4077eb57fa291f26e80ef51
49 changes: 7 additions & 42 deletions met/src/libcode/vx_python3_utils/python3_script.cc
Original file line number Diff line number Diff line change
@@ -165,8 +165,10 @@ return ( var );

}


////////////////////////////////////////////////////////////////////////


PyObject * Python3_Script::lookup_ascii(const char * name) const

{
@@ -179,6 +181,7 @@ return ( var );

}


////////////////////////////////////////////////////////////////////////


@@ -219,46 +222,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 +273,10 @@ fflush(stderr);

}


////////////////////////////////////////////////////////////////////////


PyObject* Python3_Script::read_tmp_ascii(const char * tmp_filename) const

{
@@ -345,11 +310,11 @@ PyTypeObject* type = pobj->ob_type;

const char* p = type->tp_name;

mlog << Debug(2) << "read_tmp_ascii return type: " << p << "\n";

return pobj;

}


////////////////////////////////////////////////////////////////////////


2 changes: 0 additions & 2 deletions met/src/libcode/vx_python3_utils/python3_script.h
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 8 additions & 6 deletions met/src/tools/other/ascii2nc/python_handler.cc
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ 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";

@@ -230,8 +230,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 +247,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 +319,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 +380,7 @@ if ( status ) {

ConcatString wrapper;

wrapper = generic_python_wrapper;
wrapper = set_python_env_wrapper;

Python3_Script script(wrapper.text());

5 changes: 2 additions & 3 deletions met/src/tools/other/ascii2nc/python_handler.h
Original file line number Diff line number Diff line change
@@ -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);

};