CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (http://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Plot Data from Probes (http://www.cfd-online.com/Forums/openfoam-post-processing/95994-plot-data-probes.html)

owayz January 9, 2012 22:01

Plot Data from Probes
 
Hallo,
My question might sound a little bit simple and old. But I am gonna ask it any for. :)
I have a transient simulation, with many probes in my flow domain. I want to plot the probes data. The format of the file for the probed fields doesn't seem plotable to me (atleast with the software I know).
I want to plot some points over time. Is there any simple, elegant, easy and time saving way to do it?
Or do I have to right my own utility to get individual points data out of that file.
Regards,
Awais

gschaider January 10, 2012 15:53

Quote:

Originally Posted by owayz (Post 338554)
Hallo,
My question might sound a little bit simple and old. But I am gonna ask it any for. :)
I have a transient simulation, with many probes in my flow domain. I want to plot the probes data. The format of the file for the probed fields doesn't seem plotable to me (atleast with the software I know).
I want to plot some points over time. Is there any simple, elegant, easy and time saving way to do it?
Or do I have to right my own utility to get individual points data out of that file.
Regards,
Awais

The file format is immediately plotable with Gnuplot (a program that should be on every engineering workstation). It is a bit strange in the beginning because it is driven by a command line, but the advantage of this is that you can easily prepare scripts that automatically generate the pictures you want.

Another option would be to write a small script in the scripting language of your choice that transforms the file into a CSV-file (basically replace groups of spaces with a comma) which you can open with a lot of programs (including Excel and OpenOffice)

I (but I'm biased) prefer pyFoamTimelinePlot from the PyFoam-utilities. For instance

pyFoamTimelinePlot.py . --value=T --dir=probes --basic-mode=line

prints the Gnuplot-commands to plot the temperature on all probe locations to the terminal, so

pyFoamTimelinePlot.py . --value=T --dir=probes --basic-mode=line | gnuplot

generates a PNG with that plot

pyFoamTimelinePlot.py . --value=T --dir=probes --basic-mode=line --csv=temperature.csv

writes a CSV-file with all the temperatures.

owayz January 10, 2012 21:47

Thanks for your help and I can understand why you are biased. :)
Indeed pyFoam sounds a combination of handy utilities.
But I have an error while using the utility you have just mentioned. When I use it, it says:

"Traceback (most recent call last):
File "/usr/local/bin/pyFoamTimelinePlot.py", line 3, in <module>
from PyFoam.Applications.TimelinePlot import TimelinePlot
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Applications/TimelinePlot.py", line 11, in <module>
from PyFoam.RunDictionary.TimelineDirectory import TimelineDirectory
File "/usr/local/lib/python2.6/dist-packages/PyFoam/RunDictionary/TimelineDirectory.py", line 11, in <module>
from PyFoam.Basics.SpreadsheetData import SpreadsheetData
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Basics/SpreadsheetData.py", line 6, in <module>
import numpy,copy
ImportError: No module named numpy
"


I hope that you will help me again and I really appreciate it.

Thanks and Regards,
Awais

Bernhard January 11, 2012 03:00

The last line provides a good clue. You are missing the NumPy package for python: http://numpy.scipy.org/

gschaider January 11, 2012 06:07

Quote:

Originally Posted by owayz (Post 338733)
Thanks for your help and I can understand why you are biased. :)
Indeed pyFoam sounds a combination of handy utilities.
But I have an error while using the utility you have just mentioned. When I use it, it says:

"Traceback (most recent call last):
File "/usr/local/bin/pyFoamTimelinePlot.py", line 3, in <module>
from PyFoam.Applications.TimelinePlot import TimelinePlot
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Applications/TimelinePlot.py", line 11, in <module>
from PyFoam.RunDictionary.TimelineDirectory import TimelineDirectory
File "/usr/local/lib/python2.6/dist-packages/PyFoam/RunDictionary/TimelineDirectory.py", line 11, in <module>
from PyFoam.Basics.SpreadsheetData import SpreadsheetData
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Basics/SpreadsheetData.py", line 6, in <module>
import numpy,copy
ImportError: No module named numpy
"


I hope that you will help me again and I really appreciate it.

Thanks and Regards,
Awais

Some of the utilities need the numpy-library (basically the "standard"-library for matrix-computations in Python). You'll have to install it (as pointed out in the other posting). Have a look what the package-manager of your distro provides and go with that. I've added a prerequisites-note to the Wiki-page

owayz January 11, 2012 19:26

Well I have seen the pre-requisites on the wiki page. And only Python is mentioned as a pre-requisite.
I have also installed numpy and now I have this error.
"Traceback (most recent call last):
File "/usr/local/bin/pyFoamTimelinePlot.py", line 5, in <module>
TimelinePlot()
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Applications/TimelinePlot.py", line 32, in __init__
interspersed=True)
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Applications/PyFoamApplication.py", line 155, in __init__
result=self.run()
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Applications/TimelinePlot.py", line 403, in run
spread=plots[0][-1]()
File "/usr/local/lib/python2.6/dist-packages/PyFoam/RunDictionary/TimelineDirectory.py", line 317, in __call__
title="%s_t=%s" % (self.val,self.time))
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Basics/SpreadsheetData.py", line 66, in __init__
self.data=numpy.array(map(tuple,data),dtype=zip(na mes,['f8']*len(names)))
TypeError: expected a readable buffer object
"


Thanks for your quick response again,
Awais

gschaider January 12, 2012 05:49

Quote:

Originally Posted by owayz (Post 338915)
Well I have seen the pre-requisites on the wiki page. And only Python is mentioned as a pre-requisite.

That's why I modified it yesterday.

Quote:

Originally Posted by owayz (Post 338915)
I have also installed numpy and now I have this error.
"Traceback (most recent call last):
File "/usr/local/bin/pyFoamTimelinePlot.py", line 5, in <module>
TimelinePlot()
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Applications/TimelinePlot.py", line 32, in __init__
interspersed=True)
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Applications/PyFoamApplication.py", line 155, in __init__
result=self.run()
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Applications/TimelinePlot.py", line 403, in run
spread=plots[0][-1]()
File "/usr/local/lib/python2.6/dist-packages/PyFoam/RunDictionary/TimelineDirectory.py", line 317, in __call__
title="%s_t=%s" % (self.val,self.time))
File "/usr/local/lib/python2.6/dist-packages/PyFoam/Basics/SpreadsheetData.py", line 66, in __init__
self.data=numpy.array(map(tuple,data),dtype=zip(na mes,['f8']*len(names)))
TypeError: expected a readable buffer object
"


Thanks for your quick response again,
Awais

That's a weird one (havn't seen this and I use the command all the time). Could you provide me with the numpy-version (pyFoamVersion.py should print it) you're using and the command line you use.

If I can't figure it out from that information I'll have to ask you to report it on the Mantis of openfoam-extend and provide me some sample data (only the timeline-directory the rest of the case is unneeded) there

owayz January 13, 2012 06:54

Output from pyFoamVersion.py
"
PYTHONPATH: not set
OpenFOAM (1, 7, 1) of the installed versions ['171']
pyFoam-Version: 0.5.6
Configuration search path: [('file', '/etc/pyFoam/pyfoamrc'), ('directory', '/etc/pyFoam/pyfoamrc.d'), ('file', '/home/awais/.pyFoam/pyfoamrc'), ('directory', '/home/awais/.pyFoam/pyfoamrc.d')]
Configuration files (used): []

Installed libraries:
Gnuplot : No Not a problem. Version from ThirdParty is used
ply : No Not a problem. Version from ThirdParty is used
Numeric : No Not a problem if numpy is present
numpy : Yes
matplotlib : No Only Gnuplot-plotting possible
psyco : No Not a problem. Acceleration not possible
hotshot : Yes
profile : No Not a problem. Can't profile using this library
cProfile : Yes
PyQt4 : Yes
PyQt4.Qwt5 : No Only an alternate plotting back-end
vtk : No Not a problem. Only used for some utilities
Tkinter : No Not a problem. Used for the old version of DisplayBlockmesh and some matplotlib-implementations
mercurial : No Not a problem. Used for experimental case handling

"

Plus I still can't see any change in prerequisites on Wiki page. May be I am looking at the wrong page. Could you provide me the link ?

Regards,
Awais

gschaider January 14, 2012 07:15

Quote:

Originally Posted by owayz (Post 339164)
Output from pyFoamVersion.py
"
PYTHONPATH: not set
OpenFOAM (1, 7, 1) of the installed versions ['171']
pyFoam-Version: 0.5.6
Configuration search path: [('file', '/etc/pyFoam/pyfoamrc'), ('directory', '/etc/pyFoam/pyfoamrc.d'), ('file', '/home/awais/.pyFoam/pyfoamrc'), ('directory', '/home/awais/.pyFoam/pyfoamrc.d')]
Configuration files (used): []

Installed libraries:
Gnuplot : No Not a problem. Version from ThirdParty is used
ply : No Not a problem. Version from ThirdParty is used
Numeric : No Not a problem if numpy is present
numpy : Yes
matplotlib : No Only Gnuplot-plotting possible
psyco : No Not a problem. Acceleration not possible
hotshot : Yes
profile : No Not a problem. Can't profile using this library
cProfile : Yes
PyQt4 : Yes
PyQt4.Qwt5 : No Only an alternate plotting back-end
vtk : No Not a problem. Only used for some utilities
Tkinter : No Not a problem. Used for the old version of DisplayBlockmesh and some matplotlib-implementations
mercurial : No Not a problem. Used for experimental case handling

I see. The released version doesn't yet have the feature "also print the version number" ... next release. Anyway. Could you provide me with the output of

python -c "import numpy; print numpy.__version__"


Quote:

Originally Posted by owayz (Post 339164)
Plus I still can't see any change in prerequisites on Wiki page. May be I am looking at the wrong page. Could you provide me the link ?

Here you are:
http://openfoamwiki.net/index.php/Co...#Prerequisites

owayz January 15, 2012 17:23

1.3.0

Thats the output of the command you sent me.

Regards,
Awais

owayz January 15, 2012 19:45

Thanks It worked.
 
Dear Gschaider,
I tried it again and this time I was able to extract the data csv format. May be I was doing something wrong earlier.:o
Thanks alot for your help.
I really appreciate that. :)

Regards,
Awais

gschaider January 16, 2012 06:31

Quote:

Originally Posted by owayz (Post 339453)
Dear Gschaider,
I tried it again and this time I was able to extract the data csv format. May be I was doing something wrong earlier.:o
Thanks alot for your help.
I really appreciate that. :)

Regards,
Awais

Should you be able to reproduce the behaviour it'd be nice if you let me know (Mantis-Bugreport preferred) so that I can at least catch the user-error in a way that gives a less obscure error message

owayz January 16, 2012 15:45

Sure I will do that.
But I would take this opportunity to tell you again, that its a perfect tool for me. I hope it will be useful for others as well.
Keep up the good work and thanks.
Awais

alquimista January 17, 2012 12:52

How can I display the probes updated every time the file (of the probes) change?

Thanks.

gschaider January 17, 2012 13:48

Quote:

Originally Posted by alquimista (Post 339773)
How can I display the probes updated every time the file (of the probes) change?

With pyFoam: you can't (I thought about it once but it wasn't that important to me and I never found the time)

I THINK (not sure): there is a way that involves gnuplot, the tail-command and a pipe. But I'm not totally sure

alquimista January 17, 2012 14:06

Thanks gschaider for the tip. I'll post the reply when I reach it.

tiam March 17, 2014 13:32

Hm, I keep getting some bug as well. My probes are in the postProcessing/probes1 directory
so I write

pyFoamTimelinePlot.py . --dir=postProcessing/probes1/ --info

and get

Traceback (most recent call last):
File "/usr/local/bin/pyFoamTimelinePlot.py", line 5, in <module>
TimelinePlot()
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Applications/TimelinePlot.py", line 31, in __init__
interspersed=True)
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Applications/PyFoamApplication.py", line 309, in __init__
result=self.run()
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Applications/TimelinePlot.py", line 236, in run
writeTime=self.opts.writeTime)
File "/usr/local/lib/python2.7/dist-packages/PyFoam/RunDictionary/TimelineDirectory.py", line 66, in __init__
if TimelineValue(self.dir,v,self.usedTime).isVector:
File "/usr/local/lib/python2.7/dist-packages/PyFoam/RunDictionary/TimelineDirectory.py", line 245, in __init__
self.positions.append(poses[i])

Any ideas anyone?

gschaider March 19, 2014 19:28

Quote:

Originally Posted by tiam (Post 480509)
Hm, I keep getting some bug as well. My probes are in the postProcessing/probes1 directory
so I write

pyFoamTimelinePlot.py . --dir=postProcessing/probes1/ --info

and get

Traceback (most recent call last):
File "/usr/local/bin/pyFoamTimelinePlot.py", line 5, in <module>
TimelinePlot()
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Applications/TimelinePlot.py", line 31, in __init__
interspersed=True)
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Applications/PyFoamApplication.py", line 309, in __init__
result=self.run()
File "/usr/local/lib/python2.7/dist-packages/PyFoam/Applications/TimelinePlot.py", line 236, in run
writeTime=self.opts.writeTime)
File "/usr/local/lib/python2.7/dist-packages/PyFoam/RunDictionary/TimelineDirectory.py", line 66, in __init__
if TimelineValue(self.dir,v,self.usedTime).isVector:
File "/usr/local/lib/python2.7/dist-packages/PyFoam/RunDictionary/TimelineDirectory.py", line 245, in __init__
self.positions.append(poses[i])

Any ideas anyone?

No.

The problem with that class is that it tries to find out what kind of data is inside by looking at the filename and the number of columns in the file. Sometimes it gets thrown of the train. Especially with field names that have a _

Could you give me the filenames in the probes-directory and the first few lines of a file?

tiam March 20, 2014 08:11

Hi and thank you for the reply!

Here are the files

postProcessing
│** ├── probes1
│** │** └── 0
│** │** ├── k
│** │** ├── nuSgs
│** │** ├── p
│** │** ├── pMean
│** │** ├── pPrime2Mean
│** │** ├── U
│** │** ├── UMean
│** │** └── UPrime2Mean

I do have a whole bunch of probes, about 200. Here are the first lines in k, with most of the columns cut of

# x 1.5 1.5 1.5 1.5
# y 0 0.1 0.2 0.3
# z 1.5 1.5 1.5 1.5
# Time
0.2 0.000119397 5.58722e-05 4.39089e-05 1.68841e-05
0.4 1.48173e-05 5.61585e-05 4.32905e-05 1.68423e-05
0.6 2.72097e-05 5.63581e-05 4.28651e-05 1.67996e-05
0.8 1.71347e-05 5.65558e-05 4.25659e-05 1.67494e-05
1 8.93701e-06 5.68052e-05 4.23349e-05 1.66891e-05
1.2 5.12171e-06 5.71486e-05 4.21242e-05 1.66199e-05
1.4 3.79153e-06 5.7625e-05 4.18843e-05 1.65415e-05
1.6 3.45644e-06 5.82698e-05 4.15752e-05 1.64632e-05

gschaider March 20, 2014 15:43

Quote:

Originally Posted by tiam (Post 481081)
Hi and thank you for the reply!

Here are the files

postProcessing
│** ├── probes1
│** │** └── 0
│** │** ├── k
│** │** ├── nuSgs
│** │** ├── p
│** │** ├── pMean
│** │** ├── pPrime2Mean
│** │** ├── U
│** │** ├── UMean
│** │** └── UPrime2Mean

I do have a whole bunch of probes, about 200. Here are the first lines in k, with most of the columns cut of

# x 1.5 1.5 1.5 1.5
# y 0 0.1 0.2 0.3
# z 1.5 1.5 1.5 1.5
# Time
0.2 0.000119397 5.58722e-05 4.39089e-05 1.68841e-05
0.4 1.48173e-05 5.61585e-05 4.32905e-05 1.68423e-05
0.6 2.72097e-05 5.63581e-05 4.28651e-05 1.67996e-05
0.8 1.71347e-05 5.65558e-05 4.25659e-05 1.67494e-05
1 8.93701e-06 5.68052e-05 4.23349e-05 1.66891e-05
1.2 5.12171e-06 5.71486e-05 4.21242e-05 1.66199e-05
1.4 3.79153e-06 5.7625e-05 4.18843e-05 1.65415e-05
1.6 3.45644e-06 5.82698e-05 4.15752e-05 1.64632e-05

Can't try it right now, but it seems that the "# Time" line catches the program by surprise. It is possible that it wasn't there in old OF-versions (and this code was written aaaages ago)

BTW: is it sure that this is the file it chokes on? Could you check by (for instance) creating "probes2/0" copying one file over using pyFoamTimelinePlot.py on probes2 until it fails? Thanks


All times are GMT -4. The time now is 19:42.