[Paraview] generic NetCDFreader support for CellData

Engelen, J. van (Joeri) j.vanengelen1 at uu.nl
Thu May 3 11:37:47 EDT 2018


Thank you Cory,

That indeed worked on the toy example, but when I tried it on my full dataset (uploaded here as well) Paraview v5.4.1 had trouble rendering it (only rendered part of the outer sides, when activating coloring).
I think it is not the script now giving issues, but the renderer. As I experience similar issues previously with celldata loaded from a .VTR file (I assumed that that file was corrupted).
It seems to me that when you go beyond a certain amount of cells, Paraview does not render its output properly.

Could you test whether it works for you on v5.5?

I uploaded my full dataset here:
https://coeri.stackstorage.com/s/ztga1yLO8mjD1EO

To visualize data properly:
Put a threshold filter and filter out 0.0 (as that is NoData) by putting minimum on 0.5, furthermore stretch the z direction by a factor 3000.


From: Cory Quammen [mailto:cory.quammen at kitware.com]
Sent: Thursday, May 03, 2018 4:13 PM
To: Engelen, J. van (Joeri)
Cc: Moreland, Kenneth; paraview at public.kitware.com
Subject: Re: [Paraview] generic NetCDFreader support for CellData

Indeed, my original script is not quite right. Here is a more robust version that should copy all point data arrays to cell data arrays:


dims = inputs[0].GetDimensions()

ext = inputs[0].GetExtent()

output.SetDimensions(dims[0]+1, dims[1]+1, dims[2]+1)

output.SetExtent(ext[0], ext[1]+1, ext[2], ext[3]+1, ext[4], ext[5]+1)

inputPd = inputs[0].PointData

outputCd = output.CellData

for array in inputPd:

  print(type(array))

  outputCd.append(array, array.GetName())
I hope that does it. It works in my ParaView 5.5 with the sample data you provided (thank you for providing that!).

Best regards,
Cory

On Thu, May 3, 2018 at 7:48 AM Engelen, J. van (Joeri) <j.vanengelen1 at uu.nl<mailto:j.vanengelen1 at uu.nl>> wrote:
Thanks everybody for the support,

I followed Ken’s suggestion, which will simplify things, however when I put Cory’s original script in the programmable filter no Data Array can be found in the output. So I sense there is a (small) bug in the script?
I tried changing the last three lines to the oneliner output.GetCellData().SetScalars(inputs[0].GetPointData().GetScalars())
But that did not help.

I have uploaded a small subset of my data here for you to toy around with https://coeri.stackstorage.com/s/0vUfQkVyv2MD3Ml. (Note: It helps for visualization to stretch the z-axis by a factor 3000).
This perhaps helps you with helping me.


From: Moreland, Kenneth [mailto:kmorel at sandia.gov<mailto:kmorel at sandia.gov>]
Sent: Wednesday, May 02, 2018 7:27 PM
To: Quammen, Cory (External Contacts); Engelen, J. van (Joeri)
Cc: paraview at public.kitware.com<mailto:paraview at public.kitware.com>
Subject: Re: [Paraview] generic NetCDFreader support for CellData

The NetCDF Generic/CF reader has an option named “Output Type” that you can use to force the output to a vtkImageData. Then Cory’s original programmable filter will work, and you won’t have to deal with the coordinates.

-Ken

From: ParaView <paraview-bounces at public.kitware.com<mailto:paraview-bounces at public.kitware.com>> on behalf of Cory Quammen <cory.quammen at kitware.com<mailto:cory.quammen at kitware.com>>
Date: Wednesday, May 2, 2018 at 11:19 AM
To: "j.vanengelen1 at uu.nl<mailto:j.vanengelen1 at uu.nl>" <j.vanengelen1 at uu.nl<mailto:j.vanengelen1 at uu.nl>>
Cc: "paraview at public.kitware.com<mailto:paraview at public.kitware.com>" <paraview at public.kitware.com<mailto:paraview at public.kitware.com>>
Subject: [EXTERNAL] Re: [Paraview] generic NetCDFreader support for CellData

On Wed, May 2, 2018 at 11:37 AM Engelen, J. van (Joeri) <j.vanengelen1 at uu.nl<mailto:j.vanengelen1 at uu.nl>> wrote:
Thank you Cory,

I sense this solution might work. However, the type of my data is “Rectilinear Grid”, not sure if that increases the complexity (dx = 1000, dy = 1000, dz = 1).

Ah. From the documentation: "To define a vtkRectilinearGrid<https://www.vtk.org/doc/nightly/html/classvtkRectilinearGrid.html>, you must specify the dimensions of the data and provide three arrays of values specifying the coordinates along the x-y-z axes". It should be a similar script, but you'd have to add an additional X, Y, and Z position at the end of those coordinate arrays. So your script would look more like:

dims = inputs[0].GetDimensions()

ext = inputs[0].GetExtent()

output.SetDimensions(dims[0]+1, dims[1]+1, dims[2]+1)

output.SetExtent(ext[0], ext[1]+1, ext[2], ext[3]+1, ext[4], ext[5]+1)

inputPd = inputs[0].GetPointData()

outputCd = output.GetCellData()

outputCd.SetScalars(inputPd.GetScalars())



# Set coordinates

xCoords = inputs[0].GetXCoordinates().NewInstance()

xCoords.DeepCopy(inputs[0].GetXCoordinates())

xCoords.InsertNextValue(1.0) # Should a reasonable x value for your dataset larger than previous max x

output.SetXCoordinates(xCoords)



yCoords = inputs[0].GetYCoordinates().NewInstance()

yCoords.DeepCopy(inputs[0].GetYCoordinates())

yCoords.InsertNextValue(1.5) # Should be a reasonable like the x coordinate

output.SetYCoordinates(yCoords)



zCoords = inputs[0].GetZCoordinates().NewInstance()

zCoords.DeepCopy(inputs[0].GetZCoordinates())

zCoords.InsertNextValue(1.0) # Should be a reasonable like the z coordinate

output.SetZCoordinates(zCoords)


Some extent information also needs to be supplied, but I'm not entirely clear on how to do that correctly.

A better solution would be to add an option to the reader to take care of this for you if that is reasonable for your data.

Best,
Cory

Regardless, the script you provided does not give me output and it also does not throw an error, so I’m left a bit in the dark here.

From: Cory Quammen [mailto:cory.quammen at kitware.com<mailto:cory.quammen at kitware.com>]
Sent: Wednesday, May 02, 2018 5:01 PM
To: Engelen, J. van (Joeri)
Cc: paraview at public.kitware.com<mailto:paraview at public.kitware.com>
Subject: Re: [Paraview] generic NetCDFreader support for CellData

Joeri,

You can try the "Point Data to Cell Data" filter, but that averages the point data and places the results in the cell data. You may wind up with some incorrect values using that approach.

Better would be to use a "Progammable Filter" to resize the cartesian grid read by the NetCDF reader and treat the point data as cell data. That is a bit involved, but not terrible. Set the Script to


dims = inputs[0].GetDimensions()

ext = inputs[0].GetExtent()

output.SetDimensions(dims[0]+1, dims[1]+1, dims[2]+1)

output.SetExtent(ext[0], ext[1]+1, ext[2], ext[3]+1, ext[4], ext[5]+1)

inputPd = inputs[0].GetPointData()

outputCd = output.GetCellData()

outputCd.SetScalars(inputPd.GetScalars())


This assumes that the NetCDF reader is producing a vtkImageData (you can check under the Information panel) which would report the Type: of the data set as "Image (Uniform Rectilinear Grid).

HTH,
Cory

On Wed, May 2, 2018 at 10:17 AM Engelen, J. van (Joeri) <j.vanengelen1 at uu.nl<mailto:j.vanengelen1 at uu.nl>> wrote:
Hi,

I was wondering whether it is possible to read NetCDF files as CellData.

I have categorial data on Cartesian coordinates that I want to visualize. To be more specific, the data represents lithologies of the subsurface. So 1 = sand, 3 = clay, 5 = rock.
The problem is that my file is automatically interpreted as PointData. To render this PointData, Paraview than consequently interpolates to achieve cell values.
With most variables that is not such a problem, but here it is. If I have sand (1) overlying rock (5), Paraview shows me clay (3).

Also, the information available to me was ambiguous,
-this source says it is probably not possible:
https://public.kitware.com/pipermail/paraview/2017-September/040984.html
-this states it is possible return Cell Data information:
https://www.paraview.org/ParaView/Doc/Nightly/www/py-doc/paraview.simple.NetCDFReader.html

I tried converting my data from NetCDF to a .vtr file in Python, but this resulted in more problems than solutions. (Just gave me very glitched rendering).

So I have two questions:
-Is this possible?
-Are there any workarounds you can think of to get my data as CellData in Paraview?

I’m using Paraview v5.4.1 on Windows 7.

Kind regards,
Joeri
_______________________________________________
Powered by www.kitware.com<http://www.kitware.com>

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: http://paraview.org/Wiki/ParaView

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
https://public.kitware.com/mailman/listinfo/paraview


--
Cory Quammen
Staff R&D Engineer
Kitware, Inc.


--
Cory Quammen
Staff R&D Engineer
Kitware, Inc.


--
Cory Quammen
Staff R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/paraview/attachments/20180503/31952607/attachment-0001.html>


More information about the ParaView mailing list