Examples/WRF – vis
wiki:Examples/WRF

Visualization and animating of Pan European Climate Simulation with the WRF Model using ParaView Python-Scripting

Data

In this example, one data file containing 12 timesteps was given. The file is stored at /arch/software/grafprod/data/slts.fz-juelich.de/k.goergen/WRF_initial_example/wrf_rv025_r07_test.wrfout_3km.20100702130000-20100703000000.nc in netCDF format. As netCDF 3 is used, the file had to be converted to netCDF 4 (which is hdf5) via "nccopy -k 4 foo3.nc foo4c.h5".

Variables of Interest

3D Scalar Variables

The 3D variables are located on a grid of size 49x1552x1600. As for each variable all 12 timesteps are stored in one hdf5 array, the size of this array is 12x49x1552x1600, obviously.
Here is a list of interesting scalar variables:

  • CLDFRA: Cloud Fraction (values from 0 to 1)
  • QNICE: Ice Number concentration (values from -1.1e-8 to 1.3e6, good value for visualisation: 10000)
  • QNRAIN: Rain Number concentration (values from -3e-5 to 620000, good value for visualisation: 5000)
  • QVAPOR: Water vapor mixing ratio (values from -0.0043 bis 0.0207, good value for visualisation: 0.005)

3D Vector Variables

The wind components are stored on a staggered grid. Please note, that therefore the array size of those components vary along one axis each.
Vector Components:

  • U: x-wind component (12 x 49 x 1552 x 1601)
  • V: y-wind component (12 x 49 x 1553 x 1600)
  • w: z-wind component (12 x 50 x 1552 x 1600)

2D Scalar Variables

There are also a couple of surface related 2D variables includes in the data, located on a grid of size 12x1552x1600.
Some examples:

  • HGT: Terrain Height
  • LH: Latent Heat Flux at the Surface
  • LANDMASK
  • LU_INDEX
  • QFX
  • SNOWH
  • SST
  • T2
  • TMN
  • VEGFRA

Coordinates

The coordinates of the 3D grid are given by lon, lat and two pressure values:

  • XLON: 12 x 1552 x 1600
  • XLAT: 12 x 1552 x 1600
  • PH: 12 x 50 x 1552 x 1600
  • PHB: 12 x 50 x 1552 x 1600

As ParaView can not load the coordinates of the grid from the original data, a new data file coordinates.h5 is generated by the Python script generate_coordinates.py. In this script, the longitude values are corrected by the cosine of the latitude values:

xlat = np.cos(xlat/180.0*np.pi)
print "generating longitude"
dsetIn = fIn['/XLONG']
dsetOut = fOut.create_dataset("/XLONG", (num_x, num_y, num_z), dtype=np.float32)
xlon = dsetIn[0, : , :]
mi = np.min(xlon)
ma = np.max(xlon)
xlon = (xlon-(ma+mi)/2.0) * xlat

Also the height value is calculated as PH+PHB. As these pressure values are located on a staggered grid, two grid levels must be averaged:

dsetIn1 = fIn['/PH']
dsetIn2 = fIn['/PHB']
dsetOut = fOut.create_dataset("/Z", (num_x, num_y, num_z), dtype=np.float32)
ph1 = dsetIn1[0, 0, : , :]
phb1 = dsetIn2[0, 0, : , :]

for z in range(num_x):
  sys.stdout.write("%d " % (z))
  ph2 = dsetIn1[0, z+1, : , :]
  phb2 = dsetIn2[0, z+1, : , :]
  result = (ph1+phb1+ph2+phb2)*0.00025/(9.81*2)
  dsetOut[z, : , :] = result
  print "min=%f, max=%f" % (np.min(result), np.max(result))
  ph1 = ph2
  phb1 = phb2

Time Information

The time value of the 12 timesteps is store in the variable XTIME, which is just a one-dimensional array of size 12.

XDMF Files

There are 4 python scripts for generating the necessary xdfm-file:

  • make_xdmf_structuredgrid.py: generates one xdfm-file for all timesteps containing some 3D variables and the wind vectors.
  • make_xdmf_structuredgrid_singletimesteps.py: same as above, but generates a single xdmf file for each timestep.
  • make_xdmf_structuredgrid_2d.py: generates one xdfm-file for all timesteps containing some 2D variables. The coordinates of this surface layer is read from the lowest level (as a hyperslab) from the 3D coordinates stored in coordinates.h5.
  • make_xdmf_structuredgrid_2d_singletimesteps.py: same as above, but generates a single xdmf file for each timestep.

ParaView Script

The images are generated by the script "paraview_movie_script.py", or, more specifically, by an upgraded version called "paraview_movie_script_test.py", which was developed later and can better handle the progression from time animation to the camera flight. This script loads "structuredGrid.xdmf" for 3D volume rendering and "structuredGrid_2D.xdmf" for surface coloring. Also some colortable are loaded from file (e.g. "colortable_qvapor.json") and assigned to the variables. The 3D structured grid is resampled to image data of size 1600x1600x100, which is volume rendered for one variable (e.g. CLDFRA or QVAPOR). Predefined camera positions are loaded from "cam4.pvcvbc" and are used in 3 keyframes for the camera flight.

In a first try we had problems with ParaView, because during the camera flight, which only shows the last timestep, ParaView loaded this single timestep again and again for each camera move, slowing down the rendering process significantly. Therefore, as a workaround, the script "paraview_movie_script_singletimestep.py" was developed, which (in connection with "make_xdmf_structuredgrid_singletimesteps.py") only loaded the last timestep for the camera flight. Actually, this approach is no longer necessary, as a solution was found and implemented in "paraview_movie_script_test.py". The solution was just to disable the timeTrack from using the animation time by "timeTrack.UseAnimationTime = 0".

Last modified 17 months ago Last modified on 07/20/18 12:36:38