This tutorial focuses on using DV3D, a CDAT tool, to create a 3D plot of temperature data on E3SM's ne30 native grid. When the code in this notebook is run as a separate Python script (with minor modifications), DV3D allows users to interact with the 3D plot that opens in a stand-alone window on their computer.
The CDAT software was developed by LLNL and this notebook was created and the example code was updated on December 17, 2019. This work was performed under the auspices of the U.S. Department of Energy by Lawrence Livermore National Laboratory under Contract DE-AC52-07NA27344.
You will ultimately need to run the Python code in this notebook in a command line window, not within this notebook. One possible work flow is:
python -i E3SM_ne30_Native_Grid_Test.py
The generic interactive Python command is:
python -i Name_of_Your_Notebook.py
A separate window should open where you can adjust the sliders and click on the "Configure" button to access more features of the plot. Click and drag on the center of the plot to change the angle at which you are viewing the data.
To exit the interactive mode, close the window and type control-D within your command line window to fully exit the interactive mode and to get your command prompt back. (If for some reason control-D does not work, try control-Z.)
An alternate work flow is to accomplish all the steps above in a command line window without using JupyterLab or the Jupyter Notebook.
import vcs, cdms2, sys
This tutorial uses the E3SM model version 1, 1 degree (standard resolution (ne30)) CMIP6 data which is available on NERSC's HPSS storage system. See the V1 1 Deg CMIP6 Data on HPSS post on the E3SM.org website to download the data.
The data file for this tutorial is "20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0500-01.nc" from the CMIP6 standard resolution (ne30) piControl run.
The grid file used is "ne30np4_latlon.091226.nc". To download this grid file, go to https://portal.nersc.gov/project/acme/hdavis/ and click on the "ne30np4_latlon.091226.nc" file which should automatically download via your browser. To facilitate running this notebook, the CMIP6 data file can also be downloaded from this same location.
Make sure both the data file and the grid file are in the same directory as this notebook before continuing to run this notebook.
The variable f
(for file) references the data file.
f=cdms2.open("20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0500-01.nc")
In this example the variable x
is the VCS canvas.
x = vcs.init()
Choose various DV3D settings for the type of plot you want to make.
dv3d = vcs.get3d_scalar()
dv3d.ToggleVolumePlot = vcs.on
dv3d.ToggleSphericalProj = vcs.on
dv3d.Camera={'Position': (-161, -171, 279), 'ViewUp': (.29, 0.67, 0.68), 'FocalPoint': (146.7, 8.5, -28.6)}
The next line of code shows us all the data variables within the CMIP6 netCDF file.
print(sorted(f.variables.keys()))
The variable we'll plot in this tutorial is temperature, T which is in degrees Kelvin. The next line assigns the temperature data (T) to the v
variable.
v = f["T"]
To ensure the color scale of our plot covers the minimum and maximum values of the data, we'll first determine min and max values, then modify the colormap scale.
Both VCS and Genutil have minmax functions. Here we'll use VCS's minmax function, but if you'd like to use Genutil's function instead, comment out the first line of code and un-comment the second and third lines.
vcs.minmax(v)
#import genutil
#genutil.minmax(v)
Modify the ScaleColormap to cover the min and max values of the data.
dv3d.VerticalScaling = 1.5
dv3d.ScaleColormap = [184.0, 308.0, 1]
dv3d.ScaleTransferFunction = [184.0, 308.0, 1]
x.plot( v, dv3d, grid_file="ne30np4_latlon.091226.nc")
If you want to interact with the 3D plot, save a python script from this notebook to run outside the notebook, then edit the python script to un-comment out the following line. Use a non-mesalib conda environment when running the Python script so you can interact with the 3D image in the window that opens after running the x.plot( v, dv3d ) command.
# x.interact()
When working inside a notebook, saving the above image to a separate .png file could be useful if you want to look at the image outside of the notebook. The line of code below will save the plot to a .png file in the same directory as this notebook.
If running the code in this notebook from the corresponding Python script, comment out or delete the following line of code since in the direct Python interface, saving to a .png file results in an all black .png file. If you want a 2D image of a particular view you've created while interacting with the 3D image, we recommend taking a screenshot.
x.png("native_T_sphere.png")
The CDAT software was developed by LLNL. This tutorial was written by Charles Doutriaux and Holly Davis. This work was performed under the auspices of the U.S. Department of Energy by Lawrence Livermore National Laboratory under Contract DE-AC52-07NA27344.
If you have questions about this notebook, please email our CDAT Support address, cdat-support@llnl.gov.