CFD Online Discussion Forums

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

owayz January 9, 2012 21: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 14: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 20: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 02:00

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

gschaider January 11, 2012 05: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 18: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 04: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 05: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 06: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 16:23

1.3.0

Thats the output of the command you sent me.

Regards,
Awais

owayz January 15, 2012 18: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 05: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 14: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 11:52

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

Thanks.

gschaider January 17, 2012 12: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 13:06

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

tiam March 17, 2014 12: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 18: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 07: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 14: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

tiam March 20, 2014 15:59

Hi!

Have no idea why I didn't get that debugging idea, I guess the script fails on me totally or it works for everything. So it works on all fields but UPrime2Mean!

It looks like this:
# x 1.5 1.5 1.5 1.5 1.5 1.5
# y 0 0.1 0.2 0.3 0.4 0.5
# z 1.5 1.5 1.5 1.5 1.5 1.5
# Time
0.2 (0 0 0 0 0 0) (0 0 0 0 0 0) (0 0 0 0 0 0)
0.4 (2.7993e-08 -7.77667e-10 1.05859e-08 2.16042e-11 -2.94084e-10 4.00318e-09)
0.6 (3.17292e-08 -1.45928e-09 1.17226e-08 8.21429e-11 -5.31962e-10 4.33446e-09)
0.8 (2.85533e-08 -1.82099e-09 1.0425e-08 1.72582e-10 -6.48406e-10 3.81149e-09)
1 (2.40662e-08 -1.85896e-09 8.91598e-09 2.70264e-10 -7.08062e-10 3.32037e-09)
1.2 (2.01257e-08 -1.64986e-09 7.54823e-09 3.69006e-10 -7.58858e-10 2.96515e-09)

gschaider March 20, 2014 17:33

Quote:

Originally Posted by tiam (Post 481176)
Hi!

Have no idea why I didn't get that debugging idea, I guess the script fails on me totally or it works for everything. So it works on all fields but UPrime2Mean!

It looks like this:
# x 1.5 1.5 1.5 1.5 1.5 1.5
# y 0 0.1 0.2 0.3 0.4 0.5
# z 1.5 1.5 1.5 1.5 1.5 1.5
# Time
0.2 (0 0 0 0 0 0) (0 0 0 0 0 0) (0 0 0 0 0 0)
0.4 (2.7993e-08 -7.77667e-10 1.05859e-08 2.16042e-11 -2.94084e-10 4.00318e-09)
0.6 (3.17292e-08 -1.45928e-09 1.17226e-08 8.21429e-11 -5.31962e-10 4.33446e-09)
0.8 (2.85533e-08 -1.82099e-09 1.0425e-08 1.72582e-10 -6.48406e-10 3.81149e-09)
1 (2.40662e-08 -1.85896e-09 8.91598e-09 2.70264e-10 -7.08062e-10 3.32037e-09)
1.2 (2.01257e-08 -1.64986e-09 7.54823e-09 3.69006e-10 -7.58858e-10 2.96515e-09)

OK. That explains it. That is a tensor field and that class only supports scalars and vectors

gschaider March 22, 2014 05:12

1 Attachment(s)
Quote:

Originally Posted by gschaider (Post 481188)
OK. That explains it. That is a tensor field and that class only supports scalars and vectors

The attached patch tries to make PyFoam more tolerant about this (it ignores, warns, but doesn't fail)

Attachment 29552

arieljeds February 4, 2016 07:18

Hi, I couldn't find a more relevant thread so I am reviving this one.

I am trying to use pyFoamTimelinePlot.py to plot values from probes but I can find NOTHING except for this thread to help me understand how to use it.

First of all, here is my probeDict file:

Code:

      fields
        (
            p_rgh
            p
            U
            Ux
            Uy
            Uz
            magU
            vorticity
            Co
        );

// Locations to be probed. runTime modifiable!
        probeLocations
        (
            ( -4    0    0 )        // 1 - inlet, in relaxation zone
            ( -2    0    0 )        // 2 - upstream
            ( -0.52  0    0 )        // 3 - upstream
            (  0.52  0    0 )        // 4 - at the larger radius
            (  2    0    0 )        // 5 -
            ( -4    0    0 )        // 6
            (  0    0.52  0 )        // 7
            (  0    -0.52  0 )        // 8
            (  0    3.9  0 )        // 9
            (  0    3.9  0 )        // 10
            (  0.37  0.37  0 )        // 11
            ( -0.37  0.37  0 )        // 12
            ( -0.37 -0.37  0 )  // 13
            (  0.37 -0.37  0 )  // 14
         
        );

I am then trying the following things:

1) This command DOES work:
Code:

pyFoamTimelinePlot.py --fields=p_rgh --basic-mode=lines postProcessing/ | gnuplot
This produces a plot of, for example, the p_rgh field. However, this is not that useful because it is plotting ALL of the probes.

2) This command DID work but is now giving the error listed below:

Code:

pyFoamTimelinePlot.py --fields=p_rgh --basic-mode=lines --csv-file=p_rgh.csv postProcessing/
This has worked for me previously but is now giving:

Code:

Traceback (most recent call last):
  File "/usr/local/bin/pyFoamTimelinePlot.py", line 5, in <module>
    pkg_resources.run_script('PyFoam==0.6.5', 'pyFoamTimelinePlot.py')
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 499, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1235, in run_script
    execfile(script_filename, namespace, namespace)
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/EGG-INFO/scripts/pyFoamTimelinePlot.py", line 5, in <module>
    TimelinePlot()
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/Applications/TimelinePlot.py", line 34, in __init__
    **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/Applications/PyFoamApplication.py", line 424, in __init__
    result=self.run()
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/Applications/TimelinePlot.py", line 463, in run
    spread=plots[0][-1]()
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/RunDictionary/TimelineDirectory.py", line 353, in __call__
    title="%s_t=%s" % (self.val,self.time))
  File "/usr/local/lib/python2.7/dist-packages/PyFoam-0.6.5-py2.7.egg/PyFoam/Basics/SpreadsheetData.py", line 138, in __init__
    dtype=list(zip(names,['f8']*len(names))))
ValueError: two fields with the same name

This error and producing no output.

Therefore, I have two specific questions for plotting values at probes:

1) Is it possible to use pyFoamTimelinePlot to specify which probe to plot at? And how would I do this?

2) Has anyone had experience with the error above? I don't understand it at all because this was working for a different case and I can't see where I've gone differently.

Any help or advice is much appreciated... I've been spending a loooooong time on this now and getting frustrated with the lack of documentation (aside from the code itself)


All times are GMT -4. The time now is 10:24.