mainpyFormex - Support: sr #109010, Error getting curvature in...

 
 

sr #109010: Error getting curvature in TriSurface class object

Submitter:  Jordi <jordiguasp>
Submitted:  Thu 07 Apr 2016 03:03:23 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Privacy:  Public
Assigned to:  None Open/Closed:  Open
Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 22 Apr 2016 02:54:51 PM UTC, comment #5: 

Hi, thanks for your help. Finally I solve my problem and TriSurface class is working now.

I think that the problem is related with the C libraries compilation. When I installed pyformex I got a warning saying that C libraries weren't compiled and pyformex will work with python libraries. I coulden't compile C libraries because I didn't have gl.h which is related with drawgl_ compilation.

The library I was trying to work with was misc so I looked inside misc.py and I found the nodalSum() function.
The documentation says that it expects 4 arguments while the nodalSum() function in misc_.c expects 5 arguments.

The function which calls nodalSum when we use trisurface.curvature uses 5 arguments. We can find it inside arraytools.py (l. 2400). So nodalSum() will work if we use the C libraries but it breaks if we use python libraries.

To solve it (but not fix it) I changed setup.py and makefile to only compile misc_ library and I run make lib from the terminal. Finally I change arraytools.py line 2391 to be sure that I import C library:
from pyformex.lib import misc_ as misc

I apologize to work so shoddily with pyformex.

Jordi Guasp

Jordi <jordiguasp>
Fri 08 Apr 2016 02:31:10 PM UTC, comment #4: 

I did some tests with ipython. It seems to run well when using it to start pyformex, and give same results as python.
E.g., with the attached curvature.py I did
ipython pyformex/pyformex curvature.py
python  pyformex/pyformex curvature.py
both from the pyformex source tree.

There is a difference however when running the curvature script directly from the python interpreter.
'python curvature.py' directly raises an error


from pyformex import trisurface
ImportError: cannot import name trisurface


while 'ipython curvature.py' starts running but fails on the import in nodalsum, exactly like you have posted. I guess this is because the python import paths are set differently.
The startup code in pyformex/pyformex is resposible for setting correct paths and doing some basic imports.

With a command like 'ipython pyforme/pyformex curvature.py', only pyformex/pyformex is run through the starting ipython interpreter, while the curvature.py script is then run from the pyformex script engine, which is a special interpreter environment.


(file #36862)

Benedict Verhegghe <bverheg>
Group administrator
Fri 08 Apr 2016 01:47:29 PM UTC, comment #3: 

It looks like something went wrong with the import
    from pyformex.lib import misc
in line 2402.

This is probably because you are not starting pyformex in the standard way? You seem to be using ipython. How did you start pyformex then? Did you just import pyformex package in ipython?
Or did you set ipython as the interpreter to be used for pyformex?

The pyformex.lib contains special accelerated C-implementations of some algorithms and special startup code is required to select either the accelerated versions if available or the Python versions if not.
The pyformex command has an option --nouselib to always select the Python versions.

I also noticed that some pyformex modules are loaded from different places:
/home/jguasp/Documents/code/git/pyformex/pyformex
/home/jguasp/.local/anaconda/lib/python2.7/site-packages/pyformex/
which also hints at an incorrect startup. This mixed installation could also cause errors.

A temporary workaround for you might be to copy the source code of the nodalSum function from pyformex/lib/misc.py into arraytools (give the function another name, e.g. nodalSum2, because nodalSum also exists in arraytools), and then in arraytools.nodalSum, replace the call to misc.nodalSum with nodalsum2.


Benedict Verhegghe <bverheg>
Group administrator
Fri 08 Apr 2016 09:20:29 AM UTC, comment #2: 

Hi Benedict,

I cloned latest git version '1.0.2-a5' and got a different, but related, problem also with nodalSum()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-26-8f251b8b33c6> in <module>()
----> 1 pyformex_surface.curvature(neighbours=2)

/home/jguasp/Documents/code/git/pyformex/pyformex/trisurface.pyc in curvature(self, neighbours)
    714         principal directions.
    715         """
--> 716         curv = curvature(self.coords, self.elems, self.getEdges(), neighbours=neighbours)
    717         return curv
    718

/home/jguasp/Documents/code/git/pyformex/pyformex/trisurface.pyc in curvature(coords, elems, edges, neighbours)
    153     # a weight 1/|gi-p| could be used (gi=center of the face fi)
    154     p = coords
--> 155     n = geomtools.averageNormals(coords, elems, atNodes=True)
    156     # double-precision: this will allow us to check the sign of the angles
    157     p = p.astype(float64)

/home/jguasp/.local/anaconda/lib/python2.7/site-packages/pyformex/geomtools.pyc in averageNormals(coords, elems, atNodes, treshold)
   1313     """
   1314     n = polygonNormals(coords[elems])
-> 1315     n = nodalSum(n, elems, return_all=not atNodes, direction_treshold=treshold)
   1316     return normalize(n)
   1317

/home/jguasp/.local/anaconda/lib/python2.7/site-packages/pyformex/arraytools.pyc in nodalSum(val, elems, avg, return_all, direction_treshold)
   2400         val = misc.nodalSum(val, elems, elems.max(), avg, return_all)
   2401     else:
-> 2402         val = misc.nodalSum(val, elems, elems.max(), avg, return_all)
   2403     return val
   2404

AttributeError: 'NoneType' object has no attribute 'nodalSum'


Any clues?

Thank you,
Jordi.

Jordi <jordiguasp>
Thu 07 Apr 2016 03:18:10 PM UTC, comment #1: 

Hi Jordi,

Can you specify which version of pyFormex you are using.
I suspect this is a bug in that version. I tried your example in mine (latest development) and it works fine.

Benedict Verhegghe <bverheg>
Group administrator
Thu 07 Apr 2016 03:03:23 PM UTC, original submission:  

Hello,

I'm trying to calculate surcature using trisurface.TriSurface.curvature() method and I'm getting and error.

I'm make my verteices and triangles arrays:
vertices = numpy.array([[1,0,0],[0,1,0],[-1,0,0],[0,-1,0],[0,0,1],[0,0,-1]])
triangles = numpy.array([[1,4,0],[2,4,1],[3,4,2],[0,4,3],[5,1,0],[5,2,1],[5,3,2],[5,0,3]])

I initialize the class object:
surface = trisurface.TriSurface(vertices,triangles)

And when I try to get the curvature in de vertices I get the following error:
surface.curvature()
TypeError: nodalSum() takes exactly 4 arguments (5 given)

I think that triangulation is ok because when I try to get full statistics with surface.stats() I have no problems.

Have someone had the same problem?
Have anyone how to fix it?

Thank you,

Jordi

Jordi <jordiguasp>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #36862:  curvature.py added by bverheg (309B - text/x-python)
file #36856:  curvature_error.txt added by jordiguasp (2KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bverheg (Posted a comment)
  • -email is unavailable- added by jordiguasp (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-04-08 bverheg Attached File- Added curvature.py, #36862
    2016-04-07 jordiguasp Attached File- Added curvature_error.txt, #36856

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code