<inline name="CreateNumpyVectorFromDataFile">
<script><code><![CDATA[
-import logging, sys, os
+import logging, sys, numpy
logging.debug("CREATE YI Entering in CreateNumpyVectorFromDataFile")
type = "Vector"
if sys.version_info.major > 2: import adao
from daCore.Interfaces import ImportFromFile as aif
-vector = aif(script).getvalue(columns)[1]
+vector = numpy.ravel( aif(script).getvalue(columns)[1] )
]]></code></script>
<inport name="script" type="string"/>
<inport name="columns" type="stringvec"/>
<script><code><![CDATA[
import numpy, logging
logging.debug("CREATE YI Entering in CreateNumpyVectorSerieFromString")
-vector_in_list = eval(str(vector_in_string),{},{})
-vector = numpy.matrix(vector_in_list)
+# vector_in_list = eval(str(vector_in_string),{},{})
+# vector = numpy.matrix(vector_in_list)
+if (vector_in_string.find("array")>-1) or (vector_in_string.find("matrix")>-1):
+ vector_in_string=vector_in_string.replace("array","numpy.array")
+ vector_in_string=vector_in_string.replace("matrix","numpy.matrix")
+ exec("vector="+vector_in_string)
+ vector = numpy.matrix(vector)
+else:
+ vector_in_string=vector_in_string.replace("'","").replace('"','')
+ vector = numpy.matrix(vector_in_string)
type = "VectorSerie"
logging.debug("VectorSerie is %s"%vector)
]]></code></script>
<outport name="stored" type="bool"/>
</inline>
+ <inline name="CreateNumpyVectorSerieFromDataFile">
+ <script><code><![CDATA[
+import logging, sys, numpy
+logging.debug("CREATE YI Entering in CreateNumpyVectorSerieFromDataFile")
+type = "VectorSerie"
+
+if sys.version_info.major > 2: import adao
+from daCore.Interfaces import ImportFromFile as aif
+if len(columns) == 0: columns = None
+vector = numpy.transpose( aif(script).getvalue(columns)[1] )
+]]></code></script>
+ <inport name="script" type="string"/>
+ <inport name="columns" type="stringvec"/>
+ <outport name="vector" type="pyobj"/>
+ <outport name="type" type="string"/>
+ <outport name="stored" type="bool"/>
+ </inline>
+
<inline name="SimpleExecuteDirectAlgorithm">
<script><code><![CDATA[
import logging
if k == "Stored" and not __v: continue
if k == "ColMajor" and not __v: continue
if k == "InputFunctionAsMulti" and not __v: continue
- if k == "nextStep" and not __v: continue
+ if k == "nextStep" and not __v: continue
if k == "AvoidRC" and __v: continue
if k == "noDetails": continue
if isinstance(__v,Persistence.Persistence): __v = __v.values()
__itype = r['INPUT_TYPE']
__idata = r['data']
if 'FROM' in __idata:
- # String, Script, Template, ScriptWithOneFunction, ScriptWithFunctions
+ # String, Script, DataFile, Template, ScriptWithOneFunction, ScriptWithFunctions
__ifrom = __idata['FROM']
__idata.pop('FROM','')
if __ifrom == 'String' or __ifrom == 'Template':
__local.pop(__k)
for __k,__v in __local.items():
if __k == "Concept": continue
- if __k in ['ScalarSparseMatrix','DiagonalSparseMatrix','Matrix','OneFunction','ThreeFunctions'] and 'Script' in __local: continue
+ if __k in ['ScalarSparseMatrix','DiagonalSparseMatrix','Matrix','OneFunction','ThreeFunctions'] and 'Script' in __local and __local['Script'] is not None: continue
+ if __k in ['Vector','VectorSerie'] and 'DataFile' in __local and __local['DataFile'] is not None: continue
if __k == 'Algorithm':
__text += "study_config['Algorithm'] = %s\n"%(repr(__v))
+ elif __k == 'DataFile':
+ __k = 'Vector'
+ __f = 'DataFile'
+ __v = "'"+repr(__v)+"'"
+ for __lk in ['Vector','VectorSerie']:
+ if __lk in __local and __local[__lk]: __k = __lk
+ __text += "%s_config['Type'] = '%s'\n"%(__command,__k)
+ __text += "%s_config['From'] = '%s'\n"%(__command,__f)
+ __text += "%s_config['Data'] = %s\n"%(__command,__v)
+ __text = __text.replace("''","'")
elif __k == 'Script':
__k = 'Vector'
__f = 'Script'
def __getentete(self, __nblines = 3):
"Lit l'entête du fichier pour trouver la définition des variables"
+ # La première ligne non vide non commentée est toujours considérée
+ # porter les labels de colonne, donc pas des valeurs
__header, __varsline, __skiprows = [], "", 1
if self._format in self.__binaryformats:
pass
__header.append(__line)
__skiprows += 1
__line = fid.readline().strip()
- __varsline = __line # Première ligne non commentée non vide
+ __varsline = __line
for i in range(max(0,__nblines)):
__header.append(fid.readline())
return (__header, __varsline, __skiprows)
with numpy.load(self._filename) as __allcolumns:
if self._colnames is None:
self._colnames = __allcolumns.files
+ for nom in self._colnames: # Si une variable demandée n'existe pas
+ if nom not in __allcolumns.files:
+ self._colnames = tuple( __allcolumns.files )
for nom in self._colnames:
if nom in __allcolumns.files:
if __columns is not None:
__columns = numpy.loadtxt(self._filename, usecols = __usecols, skiprows=self._skiprows)
if __useindex is not None:
__index = numpy.loadtxt(self._filename, dtype = bytes, usecols = (__useindex,), skiprows=self._skiprows)
+ if __usecols is None: # Si une variable demandée n'existe pas
+ self._colnames = None
#
elif self._format == "application/dymola.sdf" and PlatformInfo.has_sdf:
import sdf
__columns = numpy.loadtxt(self._filename, usecols = __usecols, delimiter = self._delimiter, skiprows=self._skiprows)
if __useindex is not None:
__index = numpy.loadtxt(self._filename, dtype = bytes, usecols = (__useindex,), delimiter = self._delimiter, skiprows=self._skiprows)
+ if __usecols is None: # Si une variable demandée n'existe pas
+ self._colnames = None
#
elif self._format == "text/tab-separated-values":
__usecols, __useindex = self.__getindices(self._colnames, self._colindex, self._delimiter)
__columns = numpy.loadtxt(self._filename, usecols = __usecols, delimiter = self._delimiter, skiprows=self._skiprows)
if __useindex is not None:
__index = numpy.loadtxt(self._filename, dtype = bytes, usecols = (__useindex,), delimiter = self._delimiter, skiprows=self._skiprows)
+ if __usecols is None: # Si une variable demandée n'existe pas
+ self._colnames = None
else:
raise ValueError("Unkown file format \"%s\" or no reader available"%self._format)
if __columns is None: __columns = ()
FromNumpyList = {}
FromNumpyList["Vector"] = ["String", "Script", "DataFile"]
-FromNumpyList["VectorSerie"] = ["String", "Script"]
+FromNumpyList["VectorSerie"] = ["String", "Script", "DataFile"]
FromNumpyList["Matrix"] = ["String", "Script"]
FromNumpyList["ScalarSparseMatrix"] = ["String", "Script"]
FromNumpyList["DiagonalSparseMatrix"] = ["String", "Script"]
# Data input dict
DataTypeDict = {}
DataTypeDict["Vector"] = ["String", "Script", "DataFile"]
-DataTypeDict["VectorSerie"] = ["String", "Script"]
+DataTypeDict["VectorSerie"] = ["String", "Script", "DataFile"]
DataTypeDict["Matrix"] = ["String", "Script"]
DataTypeDict["ScalarSparseMatrix"] = ["String", "Script"]
DataTypeDict["DiagonalSparseMatrix"] = ["String", "Script"]
factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpyVectorFromDataFile")
back_node = factory_back_node.cloneNode("Get" + key)
back_node.getInputPort("script").edInitPy(data_config["Data"])
- back_node.getInputPort("columns").edInitPy((key,))
+ back_node.getInputPort("columns").edInitPy((key,)) # On impose le concept, et le schéma YACS est ammendable
ADAO_Case.edAddChild(back_node)
# Set content of the node
back_node_script = back_node.getScript()
ADAO_Case.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type))
ADAO_Case.edAddDFLink(back_node.getOutputPort("stored"), CAS_node.getInputPort(key_stored))
+ if data_config["Type"] == "VectorSerie" and data_config["From"] == "DataFile":
+ # Create node
+ factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpyVectorSerieFromDataFile")
+ back_node = factory_back_node.cloneNode("Get" + key)
+ back_node.getInputPort("script").edInitPy(data_config["Data"])
+ back_node.getInputPort("columns").edInitPy(()) # On impose aucun nom et le schéma YACS est ammendable
+ ADAO_Case.edAddChild(back_node)
+ # Set content of the node
+ back_node_script = back_node.getScript()
+ if "Stored" in data_config:
+ back_node_script += "stored = " + str(data_config["Stored"]) + "\n"
+ else:
+ back_node_script += "stored = 0\n"
+ if key in init_config["Target"]:
+ # Connect node with InitUserData
+ back_node_script += "__builtins__[\"init_data\"] = init_data\n"
+ back_node.edAddInputPort("init_data", t_pyobj)
+ ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data"))
+ back_node.setScript(back_node_script)
+ # Connect node with CreateAssimilationStudy
+ CAS_node.edAddInputPort(key, t_pyobj)
+ CAS_node.edAddInputPort(key_type, t_string)
+ CAS_node.edAddInputPort(key_stored, t_bool)
+ ADAO_Case.edAddDFLink(back_node.getOutputPort("vector"), CAS_node.getInputPort(key))
+ ADAO_Case.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type))
+ ADAO_Case.edAddDFLink(back_node.getOutputPort("stored"), CAS_node.getInputPort(key_stored))
+
if data_config["Type"] in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix") and data_config["From"] == "String":
# Create node
factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpy%sFromString"%(data_config["Type"],))