Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
python_coupling [2020/02/17 23:51]
argemiro created
python_coupling [2020/02/18 19:15]
hermann
Line 1: Line 1:
 +{{ :​logo_logo.png?​400 |}}
 +\\
 +\\
 ====== Dinamica EGO and Python Coupling ====== ====== Dinamica EGO and Python Coupling ======
  
-O suporte ao Python ​(atualmente na versão 3.7) está presente no ramo "​Python"​ nos repositórios (em cima do ramo "​Tasks"​). Para compilar o ramo, é necessário ter as dependências do Python no dff_dependencies_windows. A versão contendo as dependências pode ser baixada em [[http://​csr.ufmg.br/​~romulo/​dff_dependencies_windows_python.7z]]. Para execução, é necessário ter a pasta "​PyEnvironment"​ dentro da pasta do Dinamica, o PyEnvironment também pode ser obtido em [[http://​csr.ufmg.br/​~romulo/​PyEnvironment.7z]]. ​+=== Example: Calculate ​Python ​Expression ===
  
-=== Exemplo: Calculate Python Expression === +An expression that can be used:
- +
-Uma expressão que pode ser usada:+
 <​code>​ <​code>​
 dinamica.package("​numpy"​) dinamica.package("​numpy"​)
Line 27: Line 28:
 </​code>​ </​code>​
  
-onde:+where:
 <​code>​ <​code>​
 dinamica.package("​numpy"​) dinamica.package("​numpy"​)
 </​code>​ </​code>​
-Pede ao PIP que instale o pacote ​numpy e faça o import.+Ask the PIP to install the numpy package and import ​it:
 \\  \\ 
 <​code>​ <​code>​
 print(dinamica.inputs) print(dinamica.inputs)
 </​code>​ </​code>​
-Imprime o vetor com todas as entradas passadas pelo Dinamica.+Prints the vector with all the entries passed by Dinamica:
 \\  \\ 
 <​code>​ <​code>​
 dinamica.outputs["​teste2"​] = 2.5 dinamica.outputs["​teste2"​] = 2.5
 </​code>​ </​code>​
-Coloca uma saída na struct ​com nome "teste2", ​contendo uma double ​com valor 2.5+Place an output in the struct ​named "test2", ​containing a double ​with a value of 2.5:
 \\  \\ 
 <​code>​ <​code>​
 dinamica.outputs["​tabela"​] = dinamica.prepareTable(dinamica.inputs["​t1"​],​ 3) dinamica.outputs["​tabela"​] = dinamica.prepareTable(dinamica.inputs["​t1"​],​ 3)
 </​code>​ </​code>​
-Coloca uma saída na struct ​com nome "tabela", ​contendo uma tabela com colunas de chaveEssa função não é necessária se a tabela já estiver com os '​*' ​nos nomes da coluna ​(portanto o usuário poderia fazer apenas ​dinamica.outputs["​teste2"​] = dinamica.inputs["​t1"​]). ​Toda tabela no Python ​é tratada como uma lista de listasonde cada lista interna corresponde ​uma **linha** da tabela.+Place an output in the struct ​named "table", ​containing a table with key columnsThis function is not necessary if the table already has '​*' ​in the column names (so the user could only do dinamica.outputs ["​teste2"​] = dinamica.inputs ["​t1"​]). ​Every table in Python ​is treated as a list of listswhere each internal list corresponds to a ** row ** of the table:
 \\  \\ 
 <​code>​ <​code>​
 dinamica.outputs["​lut"​] = dinamica.prepareLookupTable(dinamica.inputs["​t2"​]) dinamica.outputs["​lut"​] = dinamica.prepareLookupTable(dinamica.inputs["​t2"​])
 </​code>​ </​code>​
-Coloca uma saída na struct ​com nome "​lut", ​contendo uma LookupTable (Não existe outra forma de passar uma LookupTable ​de volta).+Put an output in the struct ​named "​lut", ​containing a LookupTable (There is no other way to pass a LookupTable ​back):
  
 ---- ----
Line 62: Line 63:
 | prepareLookupTable | It returns the lookup table prepared to output. The lut has to be in the form [[[key,​value][line1]...[lineM]]] where the first list contains the headers of the table and all the other lists are lines containing the data. | list(list) lut | | prepareLookupTable | It returns the lookup table prepared to output. The lut has to be in the form [[[key,​value][line1]...[lineM]]] where the first list contains the headers of the table and all the other lists are lines containing the data. | list(list) lut |
 | toTable | It returns a valid representation of dinamica table to output. Input Table can be: [[[header1...headerN][line1]...[lineM]]] where the first list contains the headers of the table and all the other lists are lines containing the data; {header1: [valuesOfColumn1],​ header2: [valuesOfColumn2]...} where the valuesOfComlumn#​ are all values of that column in table; [[(header1...headerN)(line)...(lineM)]] where the first tuple contains the headers of the table and all the other tuples are lines containing the data; [value1, value2, ..., valueN], those are the values for a lookup table with sequential key; pandas.Dataframe is a commom structure table used to manipulate CSVs; numpy.array is a commom structure for matrix, that can be tables as well. The first line of matrix needs to be the table header. | list(list);​dict(list);​list(tuple);​list;​pandas.DataFrame;​numpy.array inputTable | | toTable | It returns a valid representation of dinamica table to output. Input Table can be: [[[header1...headerN][line1]...[lineM]]] where the first list contains the headers of the table and all the other lists are lines containing the data; {header1: [valuesOfColumn1],​ header2: [valuesOfColumn2]...} where the valuesOfComlumn#​ are all values of that column in table; [[(header1...headerN)(line)...(lineM)]] where the first tuple contains the headers of the table and all the other tuples are lines containing the data; [value1, value2, ..., valueN], those are the values for a lookup table with sequential key; pandas.Dataframe is a commom structure table used to manipulate CSVs; numpy.array is a commom structure for matrix, that can be tables as well. The first line of matrix needs to be the table header. | list(list);​dict(list);​list(tuple);​list;​pandas.DataFrame;​numpy.array inputTable |
 +
 +\\
 +\\
 +===Congratulations,​ you have successfully completed this lesson!===
 +\\
 +☞[[lesson_21|Next Lesson]]
 +\\
 +☞[[:​guidebook_start| Back to Guidebook Start]]
 +