Visualization of NetCDF file not resulting in 3D spherical view

(Qing Xia) #1


I was trying to visualize data on a sphere which is stored in a netcdf file. Somehow paraview didn’t convert latitude and longitude into spherical coordinates. Instead, it uses latitude as x-axis and longitude as y-axis, and it gave a 2D plot instead of 3D view. I have attached the plots and also the netcdf file. I tried different versions of paraview but still had the same issue. My suspicion was that the netcdf file was corrupted, but I could see any mistake when I used ncdump to output the content of netcdf file to text.

Thanks for taking a look!

Qing (378 KB)

(Kenneth Moreland) #2

The short answer is that your data file does not properly identify the dimensions as latitude and longitude, and therefore the ParaView reader defaults back to Cartesian coordinates. I’ll explain a bit more, but for the impatient you can skip to the bottom where I’ll describe a solution.

NetCDF is not a file format in the same sense that a .vtk file has a specific file format that necessarily dictates the semantic meaning of the data. Rather, netCDF is a “self describing” file, which simply means that the contained data is arranged in general (multidimensional) arrays with metadata like names and attributes. In order for a reader (like the one in ParaView) to understand how to interpret your data, there has to be some agreement on how to specify array meanings through this metadata (i.e. a convention), and of course the file has to follow this convention.

For the “general” netCDF reader, ParaView uses the CF convention. The CF convention is a good choice for a general reader because it is extremely well adopted and has good fallbacks when attribute data is missing.

And this gets us back to the data in question. The problem here is that the data in your attached file does not adhere to the CF convention for specifying latitude and longitude. The data simply names the dimensions “latitude” and “longitude”, but that is not sufficient. Here is an excerpt from the CF convention on how to specify latitude coordinates:

Variables representing latitude must always explicitly include the units attribute; there is no default value. The units attribute will be a string formatted as per the udunits.dat file. The recommended unit of latitude is degrees_north.

A similar specification is needed for longitude.

So now the promised fix. To get your data to load correctly into ParaView, you just need to add the appropriate units attributes to your latitude and longitude variables. It would be best to do this in whatever program is generating your data. But if that is not possible, it is straightforward to add these attributes using the ncatted program (part of the netCDF Operators (NCO) toolset. (You can get this from many package managers if it is not already on your system.) The command to add the appropriate attributes to your data is:

ncatted -a 'units,latitude,o,c,degrees_north' -a 'units,longitude,o,c,degrees_east'

Attached is a fixed version of your data I created with this command. (378.3 KB)

(Qing Xia) #3

Hi Kenneth,

Thank you for the explanation and the fix! It saves a ton of time for me. I have included the units in the original code and it’s working great now. I saw the units in the netCDF file but somehow ignored them and thought the format was similar to vtk format.