[Paraview] Saving as csv data

Moreland, Kenneth kmorel at sandia.gov
Tue Oct 10 17:57:44 EDT 2017


Teng,

Once you have called servermanager.Fetch(), you are given a raw VTK object. There are literally books written about using the VTK library. You could consult the VTK Textbook (https://www.vtk.org/vtk-textbook/), and the VTK User's Guide (https://www.vtk.org/vtk-textbook/), both of which you can get for free as a pdf file. You can also consult the Doxygen documentation generated for all VTK classes (http://www.vtk.org/doc/nightly/html).

Unfortunately, almost all of the documentation for VTK is geared to using it in C++ since that is its native language. However, the Python bindings that you are using are very similar and it is easy to convert from one to the other.

-Ken

From: Li, Teng [mailto:tengli2 at illinois.edu]
Sent: Tuesday, October 10, 2017 2:11 PM
To: Moreland, Kenneth <kmorel at sandia.gov>; paraview at paraview.org
Subject: [EXTERNAL] RE: [Paraview] Saving as csv data

Hi Kenneth,

Thanks for your detailed explanation! I think I have to learn Paraview python carefully. And could you give me some resources to learn the paraview python function details, such as GetComponent(a,b) and other numerical operations?

Best,
Teng


Teng Li

Master Candidate in Structures

Department of Civil and Environmental Engineering

University of Illinois at Urbana-Champaign

205 North Mathews Ave, Urbana, IL. 61801

Phone:(217)8196210, Email: tengli2 at illinois.edu<mailto:tengli2 at illinois.edu>





________________________________
From: Moreland, Kenneth [kmorel at sandia.gov]
Sent: Tuesday, October 10, 2017 9:16 AM
To: Li, Teng; paraview at paraview.org<mailto:paraview at paraview.org>
Subject: Re: [Paraview] Saving as csv data
The first parameter of GetComponent is the tuple you pull and the second parameter is the component of the tuple. Calling GetComponent(5,1) gets the 2nd component (stress_y, index 1) of the 6th stress value (index 5). Although GetComponent(1,5) technically works, you are actually asking for the 6th component (index 5) of the 2nd value (index 1). Since there are only 3 components and VTK does not check array bounds, you actually get the 3rd component of the following tuple.

Alternatively, I suggest you call GetTuple(). It takes one argument, the index to the stress value. It returns a Python triple with the 3 stress values.

-Ken


From: "Li, Teng" <tengli2 at illinois.edu<mailto:tengli2 at illinois.edu>>
Date: Monday, October 9, 2017 at 8:34 PM
To: "Moreland, Kenneth" <kmorel at sandia.gov<mailto:kmorel at sandia.gov>>, "paraview at paraview.org<mailto:paraview at paraview.org>" <paraview at paraview.org<mailto:paraview at paraview.org>>
Subject: RE: [EXTERNAL] RE: [Paraview] Saving as csv data

Hi Moreland,

Thanks! I am now able to go further. And now I know there is only one array, array 0 in my data. And I have three components in it. I guess they are: stress_x, stress_y, stress_xy. However, after searching some information, I still can not figure out the data structure of .stress.GetComponent(a,b). I do not know the meaning of a and b.

Please find the codes:

>>> a = GetActiveSource()

>>> a.UpdatePipeline()

>>> rawData = servermanager.Fetch(a)

>>> rawData

(vtkCommonDataModelPython.vtkUnstructuredGrid)00000077A55E0588

>>> data_cell = rawData.GetCellData()

>>> data_cell

(vtkCommonDataModelPython.vtkCellData)00000077A5564FA8

>>> stress = data_cell.GetArray(0)

>>> stress

(vtkCommonCorePython.vtkDoubleArray)00000077A55E0048

>>> stress.GetComponent(1,5)

-4059988.0

>>> stress.GetComponent(5,1)

-5031060.0



As we can see, I use 1 and 5 for both a and b. However, both cases are right. It is strange because there should be only three components. Could you help me to figure out the meanings of a and b in GetComponent(a,b)? And whether I can use the : to extract all the data in a certain dimension, say row or column.



Best,

Teng


Teng Li

Master Candidate in Structures

Department of Civil and Environmental Engineering

University of Illinois at Urbana-Champaign

205 North Mathews Ave, Urbana, IL. 61801

Phone:(217)8196210, Email: tengli2 at illinois.edu<mailto:tengli2 at illinois.edu>





________________________________
From: Moreland, Kenneth [kmorel at sandia.gov]
Sent: Monday, October 09, 2017 4:15 PM
To: Li, Teng; paraview at paraview.org<mailto:paraview at paraview.org>
Subject: RE: [EXTERNAL] RE: [Paraview] Saving as csv data
Teng,

GetCellData is a function. You have to call the function by adding parentheses to the call. Specifically, change

data_cell = rawData.GetCellData

to

data_cell = rawData.GetCellData()

That will return a class from which you can pull the data array for the stress field. (For example, data_cell.GetArray(0).)

-Ken

From: Li, Teng [mailto:tengli2 at illinois.edu]
Sent: Monday, October 9, 2017 2:23 PM
To: Moreland, Kenneth <kmorel at sandia.gov<mailto:kmorel at sandia.gov>>; paraview at paraview.org<mailto:paraview at paraview.org>
Subject: [EXTERNAL] RE: [Paraview] Saving as csv data

Hi Moreland,

Thank you for your detailed explanation and two specific solutions.

In order not to lose the accuracy, I will first try to save the stress data as the point data and then process it.

Also, I am searching ways to process the vtk data directly by using python shell. I have been searching the codes to get access to the real data, here are some codes I have:

>>> a =GetActiveSource()                            # First highlight the stress vtk file in pipeline.
>>> a
<paraview.servermanager.LegacyVTKReader object at 0x0000006D080174E0>
>>> a.UpdatePipeline()
>>> rawData = servermanager.Fetch(a)
>>> data_cell = rawData.CELL_DATA_FIELD
>>> data_cell
>>> data_cell = rawData.GetCellData
>>> data_cell
<built-in method GetCellData of vtkCommonDataModelPython.vtkUnstructuredGrid object at 0x0000006D08060648>
>>> print data_cell
<built-in method GetCellData of vtkCommonDataModelPython.vtkUnstructuredGrid object at 0x0000006D08060648>

However, I just have the data information, not the real stress data I need to process. And there are 118 time steps, thus 118 vtk files of my problem. I hope there is a way to process the data in python shell once and the results in all the files will change accordingly. That means I can process the stress component as the data array and do some calculations. And then save them in the old vtk file and visualize them again. That is the idea in my mind now.

And actually, since the csv file records all the stress data (cell data). If I can just print all the data arrays in the csv file and store them as variables in the python shell, I can process them and save as new csv files.

So actually, my question is how I can print out the data, no matter in the vtk files or the csv files by using python shell.

Best,
Teng


Teng Li

Master Candidate in Structures

Department of Civil and Environmental Engineering

University of Illinois at Urbana-Champaign

205 North Mathews Ave, Urbana, IL. 61801

Phone:(217)8196210, Email: tengli2 at illinois.edu<mailto:tengli2 at illinois.edu>





________________________________
From: Moreland, Kenneth [kmorel at sandia.gov]
Sent: Monday, October 09, 2017 1:47 PM
To: Li, Teng; paraview at paraview.org<mailto:paraview at paraview.org>
Subject: RE: [Paraview] Saving as csv data
Teng,

The issue is that your stress field data is associated with the cells and you are writing out the point data in your csv file. Thus, the stress data is not being written. There are two solutions, both with flaws:

Solution 1: When you get the dialog box labeled "Configure Writer (DataSetCSVWriter)" (after you choose a filename), change the option "Field Association" from "Points" to "Cells". If you do this option, you will only get the x, y, and z for the stress (labeled "stress:0", "stress:1", and "stress:2"). You will not get the x, y, z information for the placement of the points.

Solution 2: Before writing out the csv file, run the "Cell Data to Point Data" filter. Then write out the csv file with point data as you have been doing. You will get the x, y, and z for the stress (labeled "stress:0", "stress:1", and "stress:2") and you will also get the positional x, y, and z (labeled "Points:0", "Points:1", and "Points:2"). The problem with this solution is that it will alter the stress data slightly by averaging values of adjacent cells to points.

Also note that neither of these options will automatically write out the magnitude of the stress. To write out the stress magnitude, first run the "Calculator" filter to compute the magnitude of the stress vectors.

-Ken

From: ParaView [mailto:paraview-bounces at paraview.org] On Behalf Of Li, Teng
Sent: Monday, October 9, 2017 11:17 AM
To: paraview at paraview.org<mailto:paraview at paraview.org>
Subject: [EXTERNAL] [Paraview] Saving as csv data

Hi all,

I have a question about saving vtk data in a csv file. Please find the following link for the vtk file:

https://drive.google.com/file/d/0B-Dmy2O1v21NbGlfTm9odlZpa2M/view?usp=sharinghttps://drive.google.com/file/d/0B-Dmy2O1v21NbGlfTm9odlZpa2M/view?usp=sharing

I expected to see 7 components in the csv file I saved: x, y, z, stress_x, stress_y, stress_z, stress_magnitude. However, in the csv file I saved, there are only three columns of data. Please find the csv file I saved:

https://drive.google.com/file/d/0B-Dmy2O1v21NeWZnejVqbHEzME0/view?usp=sharinghttps://drive.google.com/file/d/0B-Dmy2O1v21NeWZnejVqbHEzME0/view?usp=sharing

I saved the vtk file by first highlighting the vtk file in the pipeline, and then click save data. Then I used the default settings. Is there anything wrong in my saving process?

Thanks!

Best,
Teng


Teng Li

Master Candidate in Structures

Department of Civil and Environmental Engineering

University of Illinois at Urbana-Champaign

205 North Mathews Ave, Urbana, IL. 61801

Phone:(217)8196210, Email: tengli2 at illinois.edu<mailto:tengli2 at illinois.edu>




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20171010/cbc3b85a/attachment-0001.html>


More information about the ParaView mailing list