Changes between Version 6 and Version 7 of Examples/Ear5Animating
- Timestamp:
- 07/10/18 11:24:59 (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Examples/Ear5Animating
v6 v7 3 3 === NetCDF and HDF5 on JURECA === 4 4 The typical data format in climate science is NetCDF. Though NetCDF files can be loaded in !ParaView, this approach is very unflexible, as !ParaViews NetCDF reader makes some fixed assumptions regarding some naming conventions of the variables. 5 Fortunately, NetCDF files ge enrated with the newer NetCDF version 4 are based on HDF5 and can be loaded with !ParaViews [http://xdmf.org XDMF] reader.6 I n case one has older NetCDF files ofversion 3, a conversion from NetCDF-3 to NetCDF-4 is necessary. So one has to deal with som NetCDF and HDF5 related tools.5 Fortunately, NetCDF files generated with the newer NetCDF version 4 are based on HDF5 and can be loaded with !ParaViews [http://xdmf.org XDMF] reader. 6 If the NetCDF files are from the older version 3, a conversion from NetCDF-3 to NetCDF-4 is necessary. So one has to deal with som NetCDF and HDF5 related tools. 7 7 8 8 How to find out what modules to load for NetCDF/HDF5 on JURECA: … … 13 13 }}} 14 14 15 Load modules e.g.by:15 For JURECA software stage 2018a, the modules can be loaded by: 16 16 {{{ 17 17 #!bash … … 34 34 ncdump -k foo.nc 35 35 }}} 36 If ncdump returns netCDF-4, or netCDF-4 classic model, then congratulations, you already have an HDF file, as netCDF-4 is the netCDF data model implemented using HDF5 as the storage layer. These files can be read y by the HDF library version 1.8 or later, and from what I can tell, pytables. If ncdump returns classic or 64-bit offset, then you are using netCDF-3 and will need to convert to netCDF-4 (and thus HDF5). The good news is that if you have netCDF installed, you can do the conversion pretty easily:36 If ncdump returns netCDF-4, or netCDF-4 classic model, then congratulations, you already have an HDF file, as netCDF-4 is the netCDF data model implemented using HDF5 as the storage layer. These files can be read by the HDF library version 1.8 or later, and from what we can tell, pytables. If ncdump returns classic or 64-bit offset, then you are using netCDF-3 and will need to convert to netCDF-4 (and thus HDF5). The good news is that if you have NetCDF installed, you can do the conversion pretty easily: 37 37 {{{ 38 38 #!bash … … 40 40 }}} 41 41 42 Graphical HDF5 viewer: 43 HDFView is a very handy tool to investigate hdf5 files. To open HDFView on JURECA, either click on the HDFView icon on the desktop. Or launch HDFView by42 Graphical HDF5 viewer:\\ 43 HDFView is a handy tool to explore hdf5 files. To open HDFView on JURECA, either click on the HDFView icon on the desktop, or launch HDFView by 44 44 {{{ 45 45 #!bash … … 64 64 The files are stored at /data/slmet/slmet111/met_data/ecmwf/era5/netcdf4/2017/ 65 65 66 The files cover the months June and August 2017 in 1 h steps.67 For every file, its date is recorded in its filename . e.g. 2017061516_ml.nc (YYYYMMDDHH)66 The files cover the months June and August 2017 in steps of one hour. 67 For every file, its date is recorded in its filename, e.g. 2017061516_ml.nc (YYYYMMDDHH). 68 68 69 69 Some interesting variables stored in the 3D *ml-files: … … 71 71 - ciwc (1 x 137 x 601 x 1200): Specific cloud ice water content 72 72 - clwc (1 x 137 x 601 x 1200): Specific cloud liquid water content 73 - d (1 x 137 x 601 x 1200): divergence_of_wind73 - d (1 x 137 x 601 x 1200): Divergence of wind 74 74 - o3 (1 x 137 x 601 x 1200): Ozone mass mixing ratio 75 75 - q (1 x 137 x 601 x 1200): Specific humidity … … 83 83 - lat (601): latitude (degrees north), ranging from 90 to -90 84 84 - lon (1200): longitude (degrees east), ranging from 0 to 359.7 85 - lev, lev_2 (137): hybrid_sigma_pressure, ranging from 1 to 137 (137 is ground level !)85 - lev, lev_2 (137): hybrid_sigma_pressure, ranging from 1 to 137 (137 is ground level) 86 86 87 87 Calculation of coordinates:\\ 88 !ParaView natively does not understand the original coordinates (lat, lon, lev_2). Therefore, these must be converted into a "structured grid" data structure, whereevery node of the 3D grid has its own 3D coordinate. This calculation is done in the "generate_coordinates.py" script.89 In this script also the conversion to Cartesian coordinates takes place essentially via:88 !ParaView does not understand the original coordinates (lat, lon, lev_2) natively. Therefore, these must be converted into a "structured grid" data structure, in which every node of the 3D grid has its own 3D coordinate. This calculation is done in the "generate_coordinates.py" script. 89 In this script also the conversion from Spherical coordinates to Cartesian coordinates is done essentially via: 90 90 {{{ 91 91 #!python … … 95 95 z = height * np.sin(lat*3.14/180) 96 96 }}} 97 As you can see, the calculation of "height" is just some virtual height and does not correspond to the real extend of the earth, but this approach is sufficient for visualization. 97 98 The generated coordinates are stored in the new created file "coordinates.h5". 98 ATTENTION: !ParaView can read this "structured grid", but cannot volume-render it, as volume rendering with [https://www.ospray.org/ OspRay] or GPU-based only works for data of type "image data", wich is a 3D rectiliniear grid. Therefore, the filter "Resample to Image" must be applied to the reader in !ParaView !99 ATTENTION: !ParaView can read this "structured grid", but cannot volume-render it, as volume rendering with [https://www.ospray.org/ OspRay] or GPU-based only works for data of type "image data", wich is a 3D rectiliniear grid. Therefore, the filter "Resample to Image" must be applied to the reader in !ParaView later! 99 100 100 101 Create XDMF file:\\ 101 The hdf5 files are loaded via an xdmf reader. To enable this, an xdmf file must be created first, containing information about alle time steps and all variables. The script "make_xdmf.py" does this. The script essentially scans the directory where the data files are located and gets the names of all files for one month (the definition of the month is fixed in the script).102 The hdf5 files are loaded via an xdmf reader. To enable this, an xdmf file must be created first, containing information about alle time steps and all variables. The script "make_xdmf.py" does this. The script essentially scans the directory where the data files are located and collects the names of all files for one month (the definition of the month is fixed in the script). 102 103 Variables that can be later loaded into !ParaView are noted in the script in form of a python list: 103 104 {{{ … … 109 110 == !ParaView == 110 111 === Loading the necessary modules === 111 The needed modules can be found out with "module spider !ParaView/5.5.0".112 For !ParaView v5.5.0 the needed modules can be found out with "module spider !ParaView/5.5.0". 112 113 Load modules e.g. with: 113 114 {{{ … … 118 119 119 120 === ParaView GUI === 120 First load the modules as described above, then start !ParaView GUI 121 First load the modules as described above, then start !ParaView GUI on JURECA via vglrun: 121 122 {{{ 122 123 #!bash … … 125 126 The GUI is well suited to prototype the scene. In the GUI one can define the visualization pipeline with its parameters, i.e. the readers and filters, the color tables and the camera positions. However, for various reasons it makes sense to script the visualization with paraview-python: 126 127 - In the script all parameters are recorded in text form, so one can look up these parameters later 127 - Loading !ParaView GUIstate files sometimes does not work128 - !ParaView has a memory leak, so after a number of render steps you have to quit !ParaView and restart it at the aborted location (otherwise !ParaView would crash ). Thiscan be automated using a script.128 - You can save the state of your !ParaView session in so called state files. But unfortunately loading the saved state files sometimes does not work 129 - !ParaView has a memory leak, so after a number of render steps you have to quit !ParaView and restart it at the aborted location (otherwise !ParaView would crash because it eats up all memory). This restart procedure can be automated using a script. 129 130 130 131 … … 132 133 How To transfer pipeline parameters from GUI to script:\\ 133 134 In the !ParaView-GUI, start a Python trace by Tools->Start Trace. 134 Then create the pipeline you want. (Most of) the corresponding Python commands are displayed in the trace. These c an be transferred into a script with copy & paste and, if needed, modified there.135 Then create the pipeline you want. (Most of) the corresponding Python commands are displayed in the trace. These commands can be transferred into a script with copy & paste and, if needed, modified there. 135 136 136 137 How To transfer colormaps from GUI to script:\\ 137 138 Once you have designed a good colormap in the GUI, you can save it there as a preset. This preset can then be renamed and saved to disk as a *.json file. 138 Since a different colormap makes sense for each variable, one will end up with more then one colormap file. In this example the naming scheme for colormap files is "stein_''variable''.json", e.g. "stein_vo.json" for the vorticity. This naming scheme is expected in the Python scripts, which among other things load the color tables. 139 Since a different colormap makes sense for each variable, one will end up with more then one colormap file. In this example the naming scheme for colormap files is "stein_''variable''.json", e.g. "stein_vo.json" for the vorticity. This naming scheme is expected in the Python scripts, which among other things load the color tables: 140 {{{ 141 #!python 142 attribute = 'vo' 143 ImportPresets(filename='./stein_' + attribute + '.json') 144 }}} 139 145 140 146 How To transfer camera parameters from GUI to script:\\ 141 You can save four (and more) camera positions in the !ParaView GUI. Click on the camera icon ("Adjust Camera"), then "configure", then "Assign current view". The camera positions can be saved in an XML file via "export" and can later be loaded and used in the Python script e.g. with:147 You can save four (and more) camera positions in the !ParaView GUI. Click on the camera icon ("Adjust Camera"), then "configure", then "Assign current view". The camera positions can be permanently saved in an XML file via "export" and can later be loaded and used in the Python script e.g. with: 142 148 {{{ 143 149 #!python … … 150 156 camera.SetParallelScale(float(root[camIdx-1][1][0][0][6][0].attrib['value'])) 151 157 158 attribute = 'vo' 152 159 tree = ET.parse('camera_' + attribute + '.pvcvbc') 153 160 root = tree.getroot() … … 162 169 {{{ 163 170 #!bash 164 bash -c 'export DISPLAY=:0.0 && pvserver --disable-xdisplay-test' & sleep 2; see pvpython ./script.py 165 }}} 166 167 == Sample session for using the scripts: == 168 All files needed to run this sample session can be found in the attachment at the end of this page! Just download from there! 169 In this sample session, the typical usage of the scripts is demonstrated. All necessary files (scripts, colormaps, camera positions, texture) should be copied into one directory. At the end, 10 images for the two variables "ciwc" and "clwc" should be generated. 171 bash -c 'export DISPLAY=:0.0 && pvserver --disable-xdisplay-test' & sleep 2; pvpython ./script.py 172 }}} 173 174 == Sample session for using the attached scripts == 175 All files needed to run this sample session can be found in the attachment at the end of this page! Just download from there.\\ 176 177 In this sample session, the typical usage of the scripts is demonstrated. All necessary files (scripts, colormaps, camera positions, texture) should be placed into one directory. At the end, 10 images for the two variables "ciwc" and "clwc" should be generated. 170 178 171 179 === Prerequisites ===