This tutorial illustrates using VCS (a CDAT tool) to plot a three-dimensional temperature anomaly.
To download this Jupyter Notebook, right click on the link and choose "Download Linked File As..." or "Save Link as...". Remember where you saved the downloaded file, which should have an .ipynb extension. (You'll need to launch the Jupyter notebook or JupyterLab instance from the location where you store the notebook file.)
The CDAT software was developed by LLNL and this notebook was created and the example code was updated on June 19, 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 3D_Temp_Anomaly.py
at the prompt. 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.
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, cdutil, genutil, sys
Download many sample data files for all of our notebooks. For this exercise you need the goes5-sample.nc sample data file, the last one that is downloaded.
vcs.download_sample_data_files()
f=cdms2.open(vcs.sample_data+"/geos5-sample.nc")
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.ScaleColormap = [-15.0, 15.0, 1]
dv3d.ScaleTransferFunction = [ 3.64, 24, 1]
dv3d.VerticalScaling = 6.0
If you run the Python code version of this notebook, you can change the camera angle manually in the interactive plot by clicking and dragging the cursor.
dv3d.Camera={'Position': (-161, -171, 279), 'ViewUp': (.29, 0.67, 0.68), 'FocalPoint': (146.7, 8.5, -28.6)}
dv3d_v = vcs.get3d_scalar()
Select the temperature (tmpu) variable from the open goes5-sample.nc file (f) and assign to the v0 variable.
v0 = f["tmpu"]
Average the temperature of the 3D volume over the x axis (the longitude) and assign to the variable, va.
va = cdutil.averager( v0, axis='x' )
Grow the volume from initial temperature values (v0) to the average temperature along the x axis (va) and assign the beginning and ending values as v01 and va1 respectively.
v01,va1=genutil.grower(v0,va)
Subtract the volume bounds from each other to create the volume, v.
v = v01 - va1
Note: when you run the following line, you can safely ignore the warning. You should see the 3D plot after the line runs.
x.plot( v, dv3d )
The .png file will be in the same directory as this notebook, or the directory of the Python file if you ran the script direcly in a command line window.
x.png('temp_anomaly.png')