×

Notice

The forum is in read only mode.

Python Script in Salome

  • Matthew Bondy
  • Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
14 years 9 months ago #3708 by Matthew Bondy
Python Script in Salome was created by Matthew Bondy
I have a text file containing x,y,&z coordinates obtained using a white light scan. I am attempting to create a script that I can run in Salome to create all of these points. I am trying to familiarize myself with Python but I could really use some assistance.

I started by going through this EDF tutorial: www.salome-platform.org/user-section/sal...ials/edf-exercise-10

My next step was to create a very simple code that would create a point. I started by defining a vector and using the vector to create the point. This worked. My next step was to try to create a matrix. This is where I run into some issues. Im not familiar with the variable types in Python and it seems this is critical. The code below will run but it just creates two points using the first set of coordinates.

[code:1]
import salome
import geompy
import smesh, SMESH
import math
XYZM=[-80.829, 126.277, -105.210,
-96.833, 190.280, -112.132];
pnt1 = geompy.MakeVertex (XYZM[0], XYZM[1], XYZM[2])
geompy.addToStudy(pnt1, "pnt1"«»)
# pnt2 = geompy.MakeVertex (XYZM[3], XYZM[4], XYZM[5])
# geompy.addToStudy(pnt1, "pnt2"«»)
[/code:1]

My next step would be to use a 'for' statement to create multiple points (the commented lines would be deleted). My plan was to paste the contents of the xyz text file into this script. I already pasted the first two lines into the XYZM matrix. At the moment XYZM is a list but Im thinking that might not be the best choice (it just came out that way using Octave notation).

I also had to add a comma at the end of the first line of point data. I have had some success adding this type of item using a 'Replace' type function but if I can avoid this that would be nice.

I guess what I am looking for right now is a suggestion on how to bring in the point data and any other suggestions you might have.

Thanks,
- Matt Bondy<br /><br />Post edited by: Matthew Bondy, at: 2010/01/05 00:37
More
14 years 9 months ago #3709 by kwou
Replied by kwou on topic Re:Python Script in Salome
Hi Matthew

you could import Numeric into your workspace or file and have the proper vector and matrix objects available. It takes some time on the learning curve -as usual- but it might come out handy.

import Numeric (or if you prefer ''from Numeric import *'' so you can omit the ''Numeric.''&lt;command&gt; in front of the command).

q1, q2, q3 = mesh.GetNodeXYZ(node_id)
q4, q5, q6 = mesh.GetNodeXYZ(node_id)
qa = Numeric.array([q1,q2,q3])
qb = Numeric.array([q4,q5,q6])
qab = Numeric.subtract(qa,qb)

I used Numeric in this example:
www.caelinux.org/wiki/images/f/ff/Kw_solid4.zip
file BSgeomesh_solide3.py has some more Numeric examples, mostly at the end.

This doesnot solve your problem at the moment, but using Numeric is a bit easier for handling larger sets of data.

Still waiting though for Salome to change to Numpy, and dropping Numeric.

kind regards - kees<br /><br />Post edited by: Kees Wouters, at: 2010/01/05 00:58

Interest: structural mechanics, solar energy (picture at 'my location' shows too little pv panels)

--
kind regards - kees
  • Matthew Bondy
  • Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
14 years 9 months ago #3710 by Matthew Bondy
Replied by Matthew Bondy on topic Re:Python Script in Salome
Thanks for the advice. I have yet to try anything yet but from what I have read numeric will make my task much easier.

I was under the impression that Python was fairly scientifically orientated. I think the source of this impression probably stated or implied the use of one of these numerical extensions. I wonder if Salome would mesh faster if one of the newer versions was used.<br /><br />Post edited by: Matthew Bondy, at: 2010/01/05 02:10
More
14 years 9 months ago #3714 by Jake
Replied by Jake on topic Re:Python Script in Salome
Matthew Bondy wrote:

Thanks for the advice. I have yet to try anything yet but from what I have read numeric will make my task much easier.

I was under the impression that Python was fairly scientifically orientated. I think the source of this impression probably stated or implied the use of one of these numerical extensions. I wonder if Salome would mesh faster if one of the newer versions was used.&lt;br /&gt;&lt;br /&gt;Post edited by: Matthew Bondy, at: 2010/01/05 02:10


NETGEN is written in C++, not Python, so I doubt it would have much of an effect.
  • Matthew Bondy
  • Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
14 years 8 months ago #3720 by Matthew Bondy
Replied by Matthew Bondy on topic Re:Python Script in Salome
I got it to work after much slamming of head against wall. I have a little over 100,000 points to plot so its taking a while (computationally). I ended up taking the data (in a text file with some troublesome hidden characters) and importing it to Octave. I then exported the data from Octave to a new file to clean it up and then added it to the script. I wasted a lot of time on trying to get nice point names by using the 'eval' function. I figured without changing the points variable name the points would just overwrite eachother but that was not the case oddly enough. I have read that eval adds a lot of cpu time so its probably good to avoid (creating these points has taken ~5 minutes and is not done yet).

I also used the Ubuntu standard text editor quite a bit to remove or replace spaces and such to get a format acceptable for the python script.

The abbreviated script (I removed most of the data set):
[code:1]
import salome
import geompy
import smesh, SMESH
import math
from Numeric import *
XYZM=array([-8.08290000*10,1.26277000*100,-1.05210000*100
,-9.68330000*10,1.90280000*100,-1.12132000*100
,5.75630000*10,1.22545000*100,-1.41885000*100
,4.59960000*10,1.01743000*100,-1.36741000*100]);
for i in range( 1, 102164, 1):
pnt = geompy.MakeVertex (XYZM[3*(i-1)],XYZM[3*(i-1)+1],XYZM[3*(i-1)+2])
geompy.addToStudy(pnt, &quot;pnt&quot;«»)
[/code:1]<br /><br />Post edited by: Matthew Bondy, at: 2010/01/08 08:26
Moderators: catux
Time to create page: 0.126 seconds
Powered by Kunena Forum