简体   繁体   中英

how to output an array from python to be shown by paraview

I have a 2d array of my coordinates, and at each coordinate I have values for pressure at that point. I want to export my data and set of coordinates in a way that I can later on open them in techplot or paraview.

I have read a lot on vtk but could not find a solution to my problem. I know it should be very easy but I am new here and in the beginning.

Thank you

A simple solution is to write your data in a CSV file.

The CSV file contains the coordinates of the points and the values of the variables at those points. For instance, this is the beginning of my file :

"X"          , "Y"          , "Z"          , "R"         
-5.00e+00    , -2.00e+00    , 0.00e+00     , 5.39e+00    
-3.89e+00    , -2.00e+00    , 0.00e+00     , 4.37e+00    
-2.78e+00    , -2.00e+00    , 0.00e+00     , 3.42e+00    
-1.67e+00    , -2.00e+00    , 0.00e+00     , 2.60e+00      

To visualize your data in ParaView :

  1. Open the file in ParaView.

    Import options will be displayed in the "Property" pannel (see below). Check that the field delimiter is correct, then press "Apply".

    CSV 阅读器的属性面板

  2. Use the Table To Points filter

    Select the CSV reader in the pipeline browser (element with same name as your file). Go to the Filters menu, in the main menu, go down to "Alphabetical", and look for "Table To Points".

    The property pannel of this filters is displayed below. In this pannel you will have to indicate which column define the X, Y and Z coordinates of the points. Since you have 2D data, you can check the "2D points" options to ignore the Z column. Then check "Apply".

    表到点属性面板

    If nothing appears in the view window, click on the eye symbol next to the TableToPoints element in the pipeline browser.

  3. Create a polygonal dataset

    With these operations you can visualize your data as dots colored by the quantities. For instance :

    数据点的可视化

    For a better visualization, I suggest creating a poloygonal dataset with the Delaunay 2D filter. Select the TableToPoints element in the pipeline browser, then go to the Filters menu and look for "Delaunay 2D" in the list of filters. With this filter you will have a smooth interpolated visualization. Here is the result for my example file :

    使用 delaunay 2D 过滤器进行可视化

You will find additional informations about the CSV files in the ParaView wiki

Please see the VTK File Format guide: http://www.vtk.org/wp-content/uploads/2015/04/file-formats.pdf

You will want to save your file as a structured points where the n_x and n_y size (dimension in VTK parlance) are greater than 1 and the n_z dimension is 1.

Your data file should look like

# vtk DataFile Version 2.0
This is a sample data set describing a 2D array of floats with dimensions 128 x 256.
ASCII
DATASET STRUCTURED_POINTS
DIMENSIONS 128 256 1
ORIGIN 0.0 0.0 0.0
SPACING 1.0 1.0 1.0
SCALARS pressure float 1
LOOKUP_TABLE default
1.0
1.0
...
<128*256 total entries>

Name save the file with extension .vtk and you will be able to load it in ParaView.

I would like to expand on the answer by Cory Quammen. When trying to apply his method I get the following error upon importing the .vtk file o Paraview (ver 5.8.1):

vtkstructuredpointsreader (0x5513c30): unrecognized keyword: scalars

I am not sure what is causing that, but I solved by explicitly defining CELL_DATA and POINT_DATA ; in my case, the resulting .vtk looks like this:

# vtk DataFile Version 3.0
Vtk output for binned flow configurations (metric in Ångström)
ASCII
DATASET STRUCTURED_POINTS
DIMENSIONS 65 1 30
ORIGIN 870.6375 0.0 0.0
SPACING 1.996875 25.0 1.9977631578947368
CELL_DATA 1856
POINT_DATA 1950
SCALARS density float 1
LOOKUP_TABLE default
25.206808815618885
36.654412373503654
36.242826782279884
36.50975262319155
35.96262518604988
34.16361654279422
31.625047088384182
30.86263741338999
30.848340565843436
...

I hope this may help people experiencing the same problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM