CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Visualization & Post-Processing Software > ParaView

[General] import local functions in pvpython

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 17, 2015, 17:42
Default import local functions in pvpython
  #1
Member
 
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 11
seanread is on a distinguished road
So I have a script in my working directory which has functions I want to call in to pv python, but for some reason when I call them,

for example

Code:
import os
os.chdir('pathtomyscript')
from script import function
python says it can't find the module.

Does anyone know why this might be happening and how I can fix the issue?
seanread is offline   Reply With Quote

Old   October 18, 2015, 17:59
Default
  #2
Senior Member
 
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12
Flowkersma is on a distinguished road
If you're in a folder with myscript.py which has a function named myFunction then
Code:
from myscript import myFunction
should work.

Regards,
Mikko
Flowkersma is offline   Reply With Quote

Old   October 18, 2015, 21:19
Default
  #3
Member
 
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 11
seanread is on a distinguished road
seems to be working today, I must have been doing something careless yesterday, but now, although I can import the function fine, it isn't recognising the things that I call from paraview.simple. For example currently I am using the following function:

Code:
def clip():

    import paraview

    FluentCaseReader1 = GetActiveSource()


    Clip1 = Clip( ClipType="Plane" )

    Clip1.Scalars = ['POINTS', 'DENSITY']

    Clip1.ClipType = "Plane"

    Clip1.ClipType.Origin = [-0.0454, -0.02, -0.002]

    Clip1.ClipType.Normal = [0.03, 0.1, 1]

    return(Clip1)
to define a clip, which works fine if I feed the body into pvpython, however when I import the function in pv python and then call the function, two strange things happen. Firstly, it saying

TypeError: clip() takes exactly 1 argument (0 given)

which is strange because clip() doesn't take any arguments.

Secondly, if I give it an arbitrary argument, say 1 for example, I get


FluentCaseReader1 = GetActiveSource()

NameError: global name 'GetActiveSource' is not defined

also, if I run the script in containing the functions in pv python and then call them they work fine...

Any suggestions?

Last edited by seanread; October 18, 2015 at 21:33. Reason: update
seanread is offline   Reply With Quote

Old   October 19, 2015, 04:54
Default
  #4
Senior Member
 
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12
Flowkersma is on a distinguished road
The namespaces are somehow confused. Why are you importing paraview in the beginning of your function? Can you try this?

Code:
import myscript
import paraview.simple as pv

myscript.clip()

so = pv.GetActiveSource()
pv.Clip(so)
Flowkersma is offline   Reply With Quote

Old   October 19, 2015, 06:17
Default
  #5
Member
 
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 11
seanread is on a distinguished road
Code:
>>> PA.clip()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/media/sean/data/MASTERSNASAL/Sean Read/Elderly flow paper/images/slicedata/PA.py", line 24, in clip
    DataRepresentation1 = GetDisplayProperties( FluentCaseReader1 )
NameError: global name 'GetDisplayProperties' is not defined

Code:
>>> pv.Clip(so)
<paraview.servermanager.Clip object at 0x7f8fd451dd50>
I added import paraview because it wasn't recognising the modules imported from paraview, but it didn't help. Is it something wrong with how I compiled paraview?
seanread is offline   Reply With Quote

Old   October 19, 2015, 09:51
Default
  #6
Senior Member
 
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12
Flowkersma is on a distinguished road
In the beginning of your script files you should import the ParaView Simple module. Simple module contains all the filters (Clip, Slice...). Either by
Code:
from paraview.simple import *
Clip(..)
or
Code:
import paraview.simple as pv
pv.Clip(...)
Flowkersma is offline   Reply With Quote

Old   October 19, 2015, 22:04
Default
  #7
Member
 
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 11
seanread is on a distinguished road
seems to have done the trick, thanks again!
seanread is offline   Reply With Quote

Old   December 9, 2015, 19:11
Default
  #8
Member
 
sean read
Join Date: Sep 2014
Location: Melbourne, Australia
Posts: 41
Rep Power: 11
seanread is on a distinguished road
hey you know this is weird, but I just did a clean install of paraview4.4 with openfoam from the debian package on ubuntu 15.10 and the same original problem with importing functions from the local folder has manifested. Do you have any thoughts as to why this might be?

Last edited by seanread; December 9, 2015 at 21:15.
seanread is offline   Reply With Quote

Reply

Tags
pvpython

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write k and epsilon before the abnormal end xiuying OpenFOAM Running, Solving & CFD 8 August 27, 2013 15:33
pisoFoam with k-epsilon turb blows up - Some questions Heroic OpenFOAM Running, Solving & CFD 26 December 17, 2012 03:34
Upgraded from Karmic Koala 9.10 to Lucid Lynx10.04.3 bookie56 OpenFOAM Installation 8 August 13, 2011 04:03
IcoFoam parallel woes msrinath80 OpenFOAM Running, Solving & CFD 9 July 22, 2007 02:58
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 18:07


All times are GMT -4. The time now is 01:00.