VAPOR3 3.9.4
Classes | Public Member Functions | Static Public Member Functions | List of all members
VAPoR::PyEngine Class Reference

A class for managing derived variables computed with Python. More...

#include <PyEngine.h>

Inheritance diagram for VAPoR::PyEngine:
Wasp::MyBase

Public Member Functions

 PyEngine (DataMgr *dataMgr)
 
 ~PyEngine ()
 
int AddFunction (string name, string script, const vector< string > &inputs, const vector< string > &outputs, const vector< string > &outMeshes, bool coordFlag=false)
 
void RemoveFunction (string name)
 
std::vector< string > GetFunctionNames () const
 
string GetFunctionScript (string name) const
 
bool GetFunctionScript (string name, string &script, std::vector< string > &inputVarNames, std::vector< string > &outputVarNames, std::vector< string > &outputMeshNames, bool &coordFlag) const
 
string GetFunctionStdout (string name) const
 
- Public Member Functions inherited from Wasp::MyBase
 MyBase ()
 
const string & getClassName () const
 

Static Public Member Functions

static int Initialize ()
 
static int Calculate (const string &script, vector< string > inputVarNames, vector< DimsType > inputVarDims, vector< float * > inputVarArrays, vector< string > outputVarNames, vector< DimsType > outputVarDims, vector< float * > outputVarArrays)
 
- Static Public Member Functions inherited from Wasp::MyBase
static void SetErrMsg (const char *format,...)
 Record a formatted error message.
 
static void SetErrMsg (int errcode, const char *format,...)
 Record a formatted error message and an error code.
 
static const char * GetErrMsg ()
 
static void SetErrCode (int err_code)
 Record an error code.
 
static int GetErrCode ()
 Retrieve the current error code.
 
static void SetErrMsgCB (ErrMsgCB_T cb)
 
static ErrMsgCB_T GetErrMsgCB ()
 
static void SetErrMsgFilePtr (FILE *fp)
 
static const FILE * SetErrMsgFilePtr ()
 
static void SetDiagMsg (const char *format,...)
 Record a formatted diagnostic message.
 
static const char * GetDiagMsg ()
 
static void SetDiagMsgCB (DiagMsgCB_T cb)
 
static DiagMsgCB_T GetDiagMsgCB ()
 
static void SetDiagMsgFilePtr (FILE *fp)
 
static bool EnableErrMsg (bool enable)
 
static bool GetEnableErrMsg ()
 

Additional Inherited Members

- Public Types inherited from Wasp::MyBase
typedef void(* ErrMsgCB_T) (const char *msg, int err_code)
 
typedef void(* DiagMsgCB_T) (const char *msg)
 
- Static Public Attributes inherited from Wasp::MyBase
static char * ErrMsg
 
static int ErrCode
 
static int ErrMsgSize
 
static FILE * ErrMsgFilePtr
 
static ErrMsgCB_T ErrMsgCB
 
static char * DiagMsg
 
static int DiagMsgSize
 
static FILE * DiagMsgFilePtr
 
static DiagMsgCB_T DiagMsgCB
 
static bool Enabled
 
- Protected Member Functions inherited from Wasp::MyBase
void SetClassName (const string &name)
 

Detailed Description

A class for managing derived variables computed with Python.

Author
John Clyne

This class provides a means to manage derived variables on the DataMgr calculated using Python. It allows the user of this class to define derived variables that execute Python scripts and installs the derived variable on the DataMgr class. The Python script may operate on input variables managed by the DataMgr

Definition at line 20 of file PyEngine.h.

Constructor & Destructor Documentation

◆ PyEngine()

VAPoR::PyEngine::PyEngine ( DataMgr dataMgr)
inline

Constructor for PyEngine class

Parameters
[in]dataMgrA pointer to a DataMgr instance upon which derived variables created by this class will be managed.

Definition at line 27 of file PyEngine.h.

References VAssert.

◆ ~PyEngine()

VAPoR::PyEngine::~PyEngine ( )

Member Function Documentation

◆ AddFunction()

int VAPoR::PyEngine::AddFunction ( string  name,
string  script,
const vector< string > &  inputs,
const vector< string > &  outputs,
const vector< string > &  outMeshes,
bool  coordFlag = false 
)

Add new derived variable(s) to the DataMgr

This method adds one or more derived variables to the DataMgr specified by the constructor. Each derived variable is calculated by executing the same Python script specified by script. I.e. a single Python script may compute multiple variables.

Parameters
[in]nameA string identifier for the collection of derived variables computed by script. If a script named name already exists it is removed with RemoveFunction() and replaced with the new definition.
[in]scriptA Python (NumPy) script that will be invoked each time one of the variables listed in outputs is accessed. The scope of the script will contain NumPy Array (numpy.array) variables named in inputs.
[in]inputsA list of input DataMgr variable names. The named DataMgr variables will be made available in the scope of the Python script as NumPy Arrays.
[in]outputsA list of derived DataMgr variable names. The named variables are expected to be computed by script as NumPy Arrays and will appear as DataMgr derived variables.
[in]outMeshesA list of output mesh names, one for each output variable listed in outputs. The output mesh names must be known to the DataMgr. Each output variable created by script is expected to be sampled by the named mesh. See DataMgr::GetMesh()
Return values
statusA negative integer is returned on failure and an error message is reported with MyBase::SetErrMsg(). AddFunction() will fail if any of the output variables named in outputs already exist in the DataMgr as returned by DataMgr::GetDataVarNames(), or if any of the output mesh names in outMeshes are not known to the DataMgr (see DataMgr::GetMeshNames())
Note
The Python script script is executed when one of the output variables is read. Depending on the region requested only a subset of the DataMgr variable may be provided to script as a NumPy array. Currently this occurs if all of the input variables named by inputs and the requested output variable are sampled on the same mesh.

◆ Calculate()

static int VAPoR::PyEngine::Calculate ( const string &  script,
vector< string >  inputVarNames,
vector< DimsType inputVarDims,
vector< float * >  inputVarArrays,
vector< string >  outputVarNames,
vector< DimsType outputVarDims,
vector< float * >  outputVarArrays 
)
static

Execute a NumPy script

This static method executes the NumPy script script and copies the outputs of the Python NumPy Arrays named by outputVarNames into the regions of memory provided by outputVarArrays. The contents of the memory referenced by inputVarArrays are made available to script as inputs in the form of NumPy Arrays.

Parameters
[in]scriptA Python (NumPy) script that is expected to operate on the NumPy Arrays listed in inputVarNames and store outputs in the NumPy arrays listed in outputVarNames
[in]inputVarNamesA list of NumPy Array names that will be made available in the scope of the executed Python script, script.
[in]inputVarDimsA list of dimensions for each of the possibly multi-dimensional NumPy arrays named by inputVarNames
[in]inputVarArraysA list of regions of memory for each input NumPy Array that will be copied in the Python environment prior to executing script. The size of the region copy is given by the dimensions in inputVarDims
[in]outputVarNamesA list of NumPy Array names that are expected to be created within the scope of the Python script script The required dimesions of each array is given by outputVarDims
[in]outputVarDimsA list of dimensions for each of the possibly multi-dimensional NumPy arrays named by outputVarNames.
[in]outputVarArraysA list of regions of memory for each output NumPy Array that will be copied out of the Python environment after executing script. The size of the region copied is given by the dimensions in outputVarDims

◆ GetFunctionNames()

std::vector< string > VAPoR::PyEngine::GetFunctionNames ( ) const

Return a list of all active function names

This method returns a vector of names for all active (not previously removed) functions created with AddFunction()

See also
AddFunction();

◆ GetFunctionScript() [1/2]

string VAPoR::PyEngine::GetFunctionScript ( string  name) const

Return the script for a named function

This method returns as a string the NumPy script associated with the function named by name.

Return values
scriptReturns the Python script bound to name. Any empty string is returned if name is not defined.
See also
AddFunction(), RemoveFunction()

◆ GetFunctionScript() [2/2]

bool VAPoR::PyEngine::GetFunctionScript ( string  name,
string &  script,
std::vector< string > &  inputVarNames,
std::vector< string > &  outputVarNames,
std::vector< string > &  outputMeshNames,
bool &  coordFlag 
) const

◆ GetFunctionStdout()

string VAPoR::PyEngine::GetFunctionStdout ( string  name) const

Return stdout as a string

This method returns as a string any content written to stdout by the most recent invocation of the named script name

◆ Initialize()

static int VAPoR::PyEngine::Initialize ( )
static

Initialize the class

This static initializer must be called to initialize the Python C API at least once prior to using other PyEngine class methods.

Return values
statusA negative int is returned on failure and an error message will be logged with MyBase::SetErrMsg()

◆ RemoveFunction()

void VAPoR::PyEngine::RemoveFunction ( string  name)

Remove a previously defined function

This method removes the function previously created by AddFunction() and named by name. All of the associated derived variables are removed from the DataMgr. The method is a no-op if name is not an active function.


The documentation for this class was generated from the following file: