89 int AddFunction(
string name,
string script,
const vector<string> &inputs,
const vector<string> &outputs,
const vector<string> &outMeshes,
bool coordFlag =
false);
121 bool GetFunctionScript(
string name,
string &script, std::vector<string> &inputVarNames, std::vector<string> &outputVarNames, std::vector<string> &outputMeshNames,
bool &coordFlag)
const;
165 static int Calculate(
const string &script, vector<string> inputVarNames, vector<DimsType> inputVarDims, vector<float *> inputVarArrays, vector<string> outputVarNames,
166 vector<DimsType> outputVarDims, vector<float *> outputVarArrays);
171 DerivedPythonVar(
string varName,
string units,
DC::XType type,
string mesh,
string time_coord_var,
bool hasMissing, std::vector<string> inNames,
string script,
DataMgr *dataMgr,
174 ~DerivedPythonVar() {}
180 std::vector<string> GetInputs()
const {
return (_inNames); }
182 int GetDimLensAtLevel(
int level, std::vector<size_t> &dims_at_level, std::vector<size_t> &bs_at_level)
const;
184 virtual size_t GetNumRefLevels()
const;
186 virtual std::vector<size_t> GetCRatios()
const {
return (_varInfo.GetCRatios()); }
188 int OpenVariableRead(
size_t ts,
int level = 0,
int lod = 0);
190 int CloseVariable(
int fd);
192 int ReadRegion(
int fd,
const std::vector<size_t> &min,
const std::vector<size_t> &max,
float *region);
194 bool VariableExists(
size_t ts,
int reflevel,
int lod)
const;
196 bool GetDataVarInfo(DC::DataVar &cvar)
const;
200 string GetScriptStdout()
const {
return (_stdoutString); }
203 DC::DataVar _varInfo;
204 std::vector<string> _inNames;
208 DC::FileTable _fileTable;
211 string _stdoutString;
213 int _readRegionAll(
int fd,
const DimsType &min,
const DimsType &max,
float *region);
215 int _readRegionSubset(
int fd,
const DimsType &min,
const DimsType &max,
float *region);
221 func_c(
const string &name,
const string &script,
const std::vector<string> &inputVarNames,
const std::vector<string> &outputVarNames,
const std::vector<string> &outputMeshNames,
222 const std::vector<DerivedPythonVar *> &derivedVars,
bool coordFlag)
223 : _name(name), _script(script), _inputVarNames(inputVarNames), _outputVarNames(outputVarNames), _outputMeshNames(outputMeshNames), _derivedVars(derivedVars), _coordFlag(coordFlag)
229 std::vector<string> _inputVarNames;
230 std::vector<string> _outputVarNames;
231 std::vector<string> _outputMeshNames;
232 std::vector<DerivedPythonVar *> _derivedVars;
236 std::map<string, func_c> _functions;
237 std::map<string, string> _functionsStdio;
239 static bool _isInitialized;
241 PyEngine() : _dataMgr(NULL) {}
243 static void _cleanupDict(PyObject *mainDict, vector<string> keynames);
245 static int _c2python(PyObject *dict, vector<string> inputVarNames, vector<DimsType> inputVarDims, vector<float *> inputVarArrays);
247 static int _python2c(PyObject *dict, vector<string> outputVarNames, vector<DimsType> outputVarDims, vector<float *> outputVarArrays);
249 bool _validOutputVar(
string name)
const;
250 int _checkOutVars(
const vector<string> &outputVarNames)
const;
251 bool _validOutputMesh(
string name)
const;
252 int _checkOutMeshes(
const vector<string> &outputMeshNames)
const;
254 string _getTimeCoordVarName(
const vector<string> &varNames)
const;
Base class for storing variable metadata.
XType
External storage types for primitive data.
A cache based data reader.
Derived data variable abstract class.
A class for managing derived variables computed with Python.
string GetFunctionScript(string name) const
int AddFunction(string name, string script, const vector< string > &inputs, const vector< string > &outputs, const vector< string > &outMeshes, bool coordFlag=false)
static int Calculate(const string &script, vector< string > inputVarNames, vector< DimsType > inputVarDims, vector< float * > inputVarArrays, vector< string > outputVarNames, vector< DimsType > outputVarDims, vector< float * > outputVarArrays)
void RemoveFunction(string name)
string GetFunctionStdout(string name) const
PyEngine(DataMgr *dataMgr)
std::vector< string > GetFunctionNames() const
bool GetFunctionScript(string name, string &script, std::vector< string > &inputVarNames, std::vector< string > &outputVarNames, std::vector< string > &outputMeshNames, bool &coordFlag) const
std::array< size_t, 3 > DimsType
Type for specifying integer indices.