CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Any way to extract data from contour plots using paraView?

Register Blogs Community New Posts Updated Threads Search

Like Tree8Likes
  • 2 Post By Angela Wang
  • 3 Post By nimasam
  • 1 Post By Kina
  • 1 Post By Kina
  • 1 Post By Kina

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 26, 2010, 19:28
Question Any way to extract data from contour plots using paraView?
  #1
New Member
 
Angela Wang
Join Date: Mar 2009
Location: Fairfax, VA, USA
Posts: 15
Rep Power: 17
Angela Wang is on a distinguished road
Send a message via MSN to Angela Wang
Hi all,

I have a newbie question about how to extract x, y coordinates of interpolation points on a contour and their interpolated field values by using paraView?

Thanks.

Angela
y_jiang and marho987 like this.
Angela Wang is offline   Reply With Quote

Old   October 27, 2010, 06:25
Default
  #2
Senior Member
 
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25
nimasam is on a distinguished road
after contour
choose : Filters -> Data analysis -> integrate Variables

then a new window will open, then in "showing" tab , choose "contour"

if you want to save data in ".csv" you can choose : file -> save data
nanavati, AnthonyP and Aabadani like this.
nimasam is offline   Reply With Quote

Old   October 27, 2010, 13:13
Default
  #3
New Member
 
Angela Wang
Join Date: Mar 2009
Location: Fairfax, VA, USA
Posts: 15
Rep Power: 17
Angela Wang is on a distinguished road
Send a message via MSN to Angela Wang
Quote:
Originally Posted by nimasam View Post
after contour
choose : Filters -> Data analysis -> integrate Variables

then a new window will open, then in "showing" tab , choose "contour"

if you want to save data in ".csv" you can choose : file -> save data
Thanks a lot~ I works cool~~~
Angela Wang is offline   Reply With Quote

Old   July 5, 2016, 12:13
Default
  #4
Senior Member
 
Alex
Join Date: Jan 2014
Posts: 126
Rep Power: 12
Kina is on a distinguished road
I have also exported my contour data and the export seems fine. However, I plan to plot the contour with tikz.
It seems that the contour data is highly unsorted. Thus, the tikz plots don't look like they should. Is there any way to pre-sort the contour lines before exporting or do I have to manually piece the points together?

Cheers
Alex
Kina is offline   Reply With Quote

Old   November 29, 2017, 02:55
Default
  #5
Member
 
Join Date: Apr 2012
Location: Trivandrum
Posts: 37
Rep Power: 14
toolpost is on a distinguished road
Quote:
Originally Posted by Kina View Post
I have also exported my contour data and the export seems fine. However, I plan to plot the contour with tikz.
It seems that the contour data is highly unsorted. Thus, the tikz plots don't look like they should. Is there any way to pre-sort the contour lines before exporting or do I have to manually piece the points together?

Cheers
Alex
I am in a similar situation with gnuplot. The data exported from paraview is unsorted and 'plot with line' option makes zig zag-lines. I tried to sort the data using the contour values but doesn't work as I expected. Did you find any solution Kina? or Somebody know any other way to sort out this?

Thanks
toolpost is online now   Reply With Quote

Old   November 29, 2017, 05:42
Default
  #6
Senior Member
 
Alex
Join Date: Jan 2014
Posts: 126
Rep Power: 12
Kina is on a distinguished road
Quote:
Originally Posted by toolpost View Post
I am in a similar situation with gnuplot. The data exported from paraview is unsorted and 'plot with line' option makes zig zag-lines. I tried to sort the data using the contour values but doesn't work as I expected. Did you find any solution Kina? or Somebody know any other way to sort out this?

Thanks

Hey, what's up?

yes, I have managed to sort the contours by coding an octave file that reads in all the unsorted contours and builds a matrix that compares the vector length difference of all points to the current and reconstructs the contours. You might have to do a little tweaking depending on your columns of the .csv output file. This code currently sorts velocity contours I think. You can possibly also run this in matlab although I am not sure if matlab recognizes all the octave syntax correctly.

Proof picture below so you know what it actually looks like afterwards in tikz (or gnuplot, whatever)

Code:
#!/usr/bin/octave -qf
format short

filename = 'yourfile.csv';
M = dlmread(filename,',',1,0); %read in original matrix
% [p U1 U2 U3 N0 N1 N2 x y z]
M = [M(:,6) M(:,7) M(:,8) M(:,5)];	%reduce Matrix to important info
% [x y z u]
M = sortrows(M,2); %sort Matrix Y axis
M = M([(end/2+1):end],:); %isolate positive Y-Values
M(:,2) = []; %delete Y-column
% [x z u]
%M(:,3) = M(:,3) * 1.205; %Calculate real pressure from incompressible
M = sortrows(M,3); %sortieren pressure fields

p = -10^10;
n = 1;
nContours = 1;

% Datei öffnen
ISOPlot = fopen('pressureIsoLines.txt', 'w');
fprintf(ISOPlot, ' x y p \n');

do
	if (M(n,3) != p)
		nContours++;
		n0 = n;
		p = M(n,3);

		do
			n++;

			if (n == rows(M))
				break;
			endif

		until (M(n+1,3) != p)
		n1 = n;

		MTemp = M([n0:n1],:);	%Temporäre Matrix Pressure-Isoline
		MTemp = sortrows(MTemp,1); %approx. average of matrix
		MTempInit = MTemp;
		MTIso = [];
		MdTemp = [];

		rRef = MTemp(ceil(end/2),:); %start ref point
		MTemp(ceil(end/2),:) = [];	%delete ref

		MdTemp = [sqrt((MTemp(:,1)-rRef(1)).^2 + (MTemp(:,2) - rRef(2)).^2) MTemp];
		MdTemp = sortrows(MdTemp,1); %Matrix: vector differences from ref point

		MTIso = [0 rRef];
		MTIso = [MdTemp(1,:) ; MTIso];

		rRef = MdTemp(1,(2:end));	%new ref point

		for i = 1:rows(MTemp)
			if (MTemp(i,:) == rRef)
				MTemp(i,:) = [];
				break;
			endif
		endfor

escape = 0;

	do

		rRef1 = MTIso(1,(2:end));	%new ref point
		rRef2 = MTIso(end,(2:end));

		MTempRef = MTemp;
		for i = 1:rows(MTempRef)
			if (MTempRef(i,:) == rRef1)
				MTempRef(i,:) = [];
				break;
			endif
		endfor
		for i = 1:rows(MTempRef)
			if (MTempRef(i,:) == rRef2)
				MTempRef(i,:) = [];
				break;
			endif
		endfor

		MdTemp1 = [sqrt((MTempRef(:,1)-rRef1(1)).^2 + (MTempRef(:,2) - rRef1(2)).^2) MTempRef];
		MdTemp1 = sortrows(MdTemp1,1); %new vector diff matrix
		if (rows(MdTemp1)>0)
			dCheck1 = MdTemp1(1,1);
		else
			dCheck1 = 10e3;
		endif

		MdTemp2 = [sqrt((MTempRef(:,1)-rRef2(1)).^2 + (MTempRef(:,2) - rRef2(2)).^2) MTempRef];
		MdTemp2 = sortrows(MdTemp2,1); %new vector diff matrix
		if (rows(MdTemp2)>0)
			dCheck2 = MdTemp2(1,1);
		else
			dCheck2 = 10e3;
		endif

		if (dCheck1 < dCheck2)
			if (rows(MdTemp1) > 0)
			MTIso = [MdTemp1(1,:) ; MTIso];
			rRef = rRef1;	%new ref point
			endif
		else
			if (rows(MdTemp1) > 0)
			MTIso = [MTIso ; MdTemp2(1,:)];
			rRef = rRef2;	%new ref point
			endif
		endif

	if (rows(MTemp) > 2)	%delete ref point
		for i = 1:rows(MTemp)
			if (MTemp(i,:) == rRef)
				MTemp(i,:) = [];
				break;
			endif
		endfor

	else
		MTemp = [];
		escape = 1;

	endif

	until (escape == 1)

	endif

	if (n < rows(M))
		n++;
	endif

	for i = (1:rows(MTIso))

		fprintf(ISOPlot, ' %f %f %f \n', MTIso(i,2:end)');

		if (MTIso(i,1) >= 0.15)
			fprintf(ISOPlot, '\n');
		endif

	endfor

fprintf(ISOPlot, '\n');

until (n == rows(M))

fclose(ISOPlot);
Attached Images
File Type: png Contours.png (65.0 KB, 177 views)
toolpost likes this.
Kina is offline   Reply With Quote

Old   November 29, 2017, 20:02
Default
  #7
Member
 
Join Date: Apr 2012
Location: Trivandrum
Posts: 37
Rep Power: 14
toolpost is on a distinguished road
Quote:
Originally Posted by Kina View Post
Hey, what's up?

yes, I have managed to sort the contours by coding an octave file that reads in all the unsorted contours and builds a matrix that compares the vector length difference of all points to the current and reconstructs the contours. You might have to do a little tweaking depending on your columns of the .csv output file. This code currently sorts velocity contours I think. You can possibly also run this in matlab although I am not sure if matlab recognizes all the octave syntax correctly.

Proof picture below so you know what it actually looks like afterwards in tikz (or gnuplot, whatever)
Hello Kina!

Thanks for the code! I have been searching yesterday and trying to tackle with a matlab code 'points2contour', which I found in mathworks website. I will try to modify your code as per my data and let you know the results. Also, I use octave, not comfortable with matlab.

Your reply and willingness to help is really appreciated.

Thanks
toolpost is online now   Reply With Quote

Old   November 30, 2017, 10:42
Default
  #8
Senior Member
 
Alex
Join Date: Jan 2014
Posts: 126
Rep Power: 12
Kina is on a distinguished road
Quote:
Originally Posted by toolpost View Post
Hello Kina!

Thanks for the code! I have been searching yesterday and trying to tackle with a matlab code 'points2contour', which I found in mathworks website. I will try to modify your code as per my data and let you know the results. Also, I use octave, not comfortable with matlab.

Your reply and willingness to help is really appreciated.

Thanks
Yeah alright! Just to tell you one or two lines for better understanding: the code takes the first point of each contour it reads from the file and tries to find the nearest point of the same contour by the minimal distance. Then, the point is removed from the original file matrix. If the distance exceeds a certain threshold, it switches over to the next contour. That's what I remember from it. If you use octave you should be able to follow the code. It worked for me.

Cheers
toolpost likes this.
Kina is offline   Reply With Quote

Old   December 2, 2017, 22:54
Default
  #9
Member
 
Join Date: Apr 2012
Location: Trivandrum
Posts: 37
Rep Power: 14
toolpost is on a distinguished road
Quote:
Originally Posted by Kina View Post
Yeah alright! Just to tell you one or two lines for better understanding: the code takes the first point of each contour it reads from the file and tries to find the nearest point of the same contour by the minimal distance. Then, the point is removed from the original file matrix. If the distance exceeds a certain threshold, it switches over to the next contour. That's what I remember from it. If you use octave you should be able to follow the code. It worked for me.

Cheers
Hi Kina!

Thanks for the detailed info. I have used the code without much modifications, though I faced some minor issues. I noticed that an iso-contour from paraview bears not exactly same contour values, minor deviations in the order of 0.001 were present. So, I had to re-export the data from paraview with precision set to 4, and thus able to sort most of the contours. Still,some repetitions and random jumps were there. But, I managed to edit the output file manually without much headache. Please see the figure attached.

Thanks again for the help!

Jabir
Attached Images
File Type: jpg sonicB.jpg (63.6 KB, 104 views)
toolpost is online now   Reply With Quote

Old   December 3, 2017, 05:27
Default
  #10
Senior Member
 
Alex
Join Date: Jan 2014
Posts: 126
Rep Power: 12
Kina is on a distinguished road
Quote:
Originally Posted by toolpost View Post
Hi Kina!

Thanks for the detailed info. I have used the code without much modifications, though I faced some minor issues. I noticed that an iso-contour from paraview bears not exactly same contour values, minor deviations in the order of 0.001 were present. So, I had to re-export the data from paraview with precision set to 4, and thus able to sort most of the contours. Still,some repetitions and random jumps were there. But, I managed to edit the output file manually without much headache. Please see the figure attached.

Thanks again for the help!

Jabir
Hey Jabir,

looks good so far some minor manipulation of the output was also necessary for me. Instead of lowering the output resolution you could have also put in another threshold for the p value in form of changing:

Code:
do
	if (M(n,3) != p)
		nContours++;
		n0 = n;
		p = M(n,3);
at the beginning to

Code:
do
	if (M(n,3) < 0.99 * p || M(n,3) > 1.01 * p)
		nContours++;
		n0 = n;
		p = M(n,3);
which would give you roughly 1% of tolerance of the referenced p value before switching over to a new contour. Apart from that: glad I could help you!

Best wishes for the rest of your project
Alex
toolpost likes this.
Kina is offline   Reply With Quote

Old   December 3, 2017, 21:37
Default
  #11
Member
 
Join Date: Apr 2012
Location: Trivandrum
Posts: 37
Rep Power: 14
toolpost is on a distinguished road
Quote:
Originally Posted by Kina View Post
Code:
do
    if (M(n,3) != p)
        nContours++;
        n0 = n;
        p = M(n,3);
at the beginning to

Code:
do
    if (M(n,3) < 0.99 * p || M(n,3) > 1.01 * p)
        nContours++;
        n0 = n;
        p = M(n,3);
which would give you roughly 1% of tolerance of the referenced p value before switching over to a new contour.
Hello Alex!

That's a cool idea to give some tolerance to the contour magnitude. I will definitely try this next time.

Thanks for your help. I really appreciate it.

Jabir
toolpost is online now   Reply With Quote

Reply


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 extract data for contour plot? Farid CFX 9 April 3, 2017 20:07
[OpenFOAM] extracting data from paraview tharem ParaView 1 January 18, 2011 00:45
Extract data we want from Techplot to a data file vetnav Main CFD Forum 0 July 28, 2010 21:17
How to update polyPatchbs localPoints liu OpenFOAM Running, Solving & CFD 6 December 30, 2005 18:27
drawing of contour plots chinthakindi Main CFD Forum 1 April 27, 2004 05:33


All times are GMT -4. The time now is 02:57.