]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
Extending data file input capacity for vectors series
authorJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Sat, 15 Jun 2019 21:16:45 +0000 (23:16 +0200)
committerJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Sat, 15 Jun 2019 22:36:05 +0000 (00:36 +0200)
resources/ADAOSchemaCatalog.xml
src/daComposant/daCore/Interfaces.py
src/daSalome/daYacsSchemaCreator/infos_daComposant.py
src/daSalome/daYacsSchemaCreator/methods.py

index 6506dfa9a44688ecef7e004f37e22166f645f21a..5d0c3782367e938a8d8f55a48f2cade4127cea34 100644 (file)
@@ -409,13 +409,13 @@ if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index
 
   <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"/>
@@ -428,8 +428,16 @@ vector = aif(script).getvalue(columns)[1]
     <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>
@@ -463,6 +471,24 @@ if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index
     <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
index 3dd3138b74392e2b0a5c2726f7549075e0515331..2846d7bb01b6b2da7d32f9fbb5119afd2bb4415c 100644 (file)
@@ -122,7 +122,7 @@ class _TUIViewer(GenericCaseViewer):
                 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()
@@ -260,7 +260,7 @@ class _COMViewer(GenericCaseViewer):
                     __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':
@@ -361,9 +361,20 @@ class _SCDViewer(GenericCaseViewer):
                 __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'
@@ -707,6 +718,8 @@ class ImportFromFile(object):
 
     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
@@ -717,7 +730,7 @@ class ImportFromFile(object):
                     __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)
@@ -779,6 +792,9 @@ class ImportFromFile(object):
             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:
@@ -794,6 +810,8 @@ class ImportFromFile(object):
             __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
@@ -817,12 +835,16 @@ class ImportFromFile(object):
             __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 = ()
index 76aaed0b3460dc9573e5ac27449e54852b4983d8..7fd8e72dae66593c6c4db3ba9e849cb68e095cbc 100644 (file)
@@ -52,7 +52,7 @@ AssimType["ControlInput"]        = ["Vector", "VectorSerie"]
 
 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"]
@@ -236,7 +236,7 @@ BasicDataInputs = ["String", "Script", "ScriptWithOneFunction", "ScriptWithFunct
 # 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"]
index e19962a3559e77d51b0d2d5a4f25408b860c04a5..accc553739da6295d711b18199c978aa56361067 100644 (file)
@@ -266,7 +266,7 @@ def create_yacs_proc(study_config):
         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()
@@ -343,6 +343,33 @@ def create_yacs_proc(study_config):
         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"],))