VCS 3D Temperature Anomaly

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.)

Download the Python 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.

To Interact with the 3D image...

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:

  1. Step through this notebook line by line to make sure everything works (you are running an environment with the needed packages, the code is working for you with the sample data, etc.).
  2. Once everything is working, either use the Python file we've provided above or save this notebook as a Python file by clicking on File (within the JupyterLab interface) > Export Notebook As... > Export Notebook to Executable Script.
  3. Open a new command line window and activate your favorite CDAT environment (for testing this notebook, we used the jupyter-vcdat environment after installing VCDAT. (Note: make sure you are using a "regular" version of the packages - NOT the mesalib version - since you will need to view the 3D image in a window that pops up once the Python script has been run.)
  4. Navigate to where the Python script is stored and type:
    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.

In [1]:
import vcs, cdms2, cdutil, genutil, sys

Get Tutorial Data

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.

In [2]:
vcs.download_sample_data_files()
Downloading: 'BlueMarble.ppm' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/BlueMarble.ppm
Downloading: 'clt.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/clt.nc
Downloading: 'geo.1deg.ctl' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/geo.1deg.ctl
Downloading: 'geo.1deg.gmp' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/geo.1deg.gmp
Downloading: 'geo.1deg.grb' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/geo.1deg.grb
Downloading: 'meshfill.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/meshfill.nc
Downloading: 'navy_land.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/navy_land.nc
Downloading: 'rlut_CERES_000001-000012_ac.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/rlut_CERES_000001-000012_ac.nc
Downloading: 'sampleCurveGrid4.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/sampleCurveGrid4.nc
Downloading: 'sampleGenGrid3.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/sampleGenGrid3.nc
Downloading: 'sftbyrgn.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/sftbyrgn.nc
Downloading: 'sftlf_10x10.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/sftlf_10x10.nc
Downloading: 'sftlf_visus.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/sftlf_visus.nc
Downloading: 'so_Omon_ACCESS1-0_historical_r1i1p1_185001-185412_2timesteps.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/so_Omon_ACCESS1-0_historical_r1i1p1_185001-185412_2timesteps.nc
Downloading: 'so_Omon_GISS-E2-R_historicalNat_r5i1p1_185001-187512_2timesteps.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/so_Omon_GISS-E2-R_historicalNat_r5i1p1_185001-187512_2timesteps.nc
Downloading: 'so_Omon_HadGEM2-CC_historical_r1i1p1_185912-186911_2timesteps.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/so_Omon_HadGEM2-CC_historical_r1i1p1_185912-186911_2timesteps.nc
Downloading: 'so_Omon_MPI-ESM-LR_1pctCO2_r1i1p1_185001-185912_2timesteps.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/so_Omon_MPI-ESM-LR_1pctCO2_r1i1p1_185001-185912_2timesteps.nc
Downloading: 'swan.four.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/swan.four.nc
Downloading: 'ta_ncep_87-6-88-4.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/ta_ncep_87-6-88-4.nc
Downloading: 'tas_ccsr-95a.xml' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_ccsr-95a.xml
Downloading: 'tas_ccsr-95a_1979.01-1979.12.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_ccsr-95a_1979.01-1979.12.nc
Downloading: 'tas_ccsr-95a_1980.01-1980.12.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_ccsr-95a_1980.01-1980.12.nc
Downloading: 'tas_ccsr-95a_1981.01-1981.12.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_ccsr-95a_1981.01-1981.12.nc
Downloading: 'tas_ccsr-95a_1982.01-1982.12.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_ccsr-95a_1982.01-1982.12.nc
Downloading: 'tas_ccsr-95a_1983.01-1983.12.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_ccsr-95a_1983.01-1983.12.nc
Downloading: 'tas_ccsr-95a_1984.01-1984.12.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_ccsr-95a_1984.01-1984.12.nc
Downloading: 'sftlf_ccsr.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/sftlf_ccsr.nc
Downloading: 'tas_dnm-95a.xml' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_dnm-95a.xml
Downloading: 'tas_dnm-95a_1979.01-1979.12.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_dnm-95a_1979.01-1979.12.nc
Downloading: 'tas_dnm-95a_1980.01-1980.12.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_dnm-95a_1980.01-1980.12.nc
Downloading: 'tas_dnm-95a_1981.01-1981.12.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_dnm-95a_1981.01-1981.12.nc
Downloading: 'tas_dnm-95a_1982.01-1982.12.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_dnm-95a_1982.01-1982.12.nc
Downloading: 'tas_dnm-95a_1983.01-1983.12.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_dnm-95a_1983.01-1983.12.nc
Downloading: 'tas_dnm-95a_1984.01-1984.12.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_dnm-95a_1984.01-1984.12.nc
Downloading: 'sftlf_dnm.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/sftlf_dnm.nc
Downloading: 'taylor.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/taylor.nc
Downloading: 'test_anim.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/test_anim.nc
Downloading: 'test_col.asc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/test_col.asc
Downloading: 'testgrib2.ctl' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/testgrib2.ctl
Downloading: 'testgrib2.grib2' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/testgrib2.grib2
Downloading: 'testgrib2.idx' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/testgrib2.idx
Downloading: 'testpp.pp' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/testpp.pp
Downloading: 'thermo.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/thermo.nc
Downloading: 'vertical.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/vertical.nc
Downloading: 'tas_ukmo_con.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_ukmo_con.nc
Downloading: 'tas_gavg_rnl_ecm.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_gavg_rnl_ecm.nc
Downloading: 'tas_ecm_1979.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_ecm_1979.nc
Downloading: 'tas_cru_1979.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_cru_1979.nc
Downloading: 'psl_6h.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/psl_6h.nc
Downloading: 'ts_da.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/ts_da.nc
Downloading: 'tas_mo.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_mo.nc
Downloading: 'tas_mo_clim.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_mo_clim.nc
Downloading: 'tas_6h.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/tas_6h.nc
Downloading: 'th_yr.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/th_yr.nc
Downloading: 'th_yr.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/th_yr.nc
Downloading: 'th_yr.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/th_yr.nc
Downloading: 'geos5-sample.nc' from 'https://cdat.llnl.gov/cdat/sample_data/' in: /Users/davis278/miniconda3/envs/cdat81-mesa/share/cdat/sample_data/geos5-sample.nc

Open the geos5-sample.nc data file

In [3]:
f=cdms2.open(vcs.sample_data+"/geos5-sample.nc")

Initialize the VCS canvas

In [4]:
x = vcs.init()

Set dv3d settings

Choose various dv3d settings for the type of plot you want to make.

In [5]:
dv3d = vcs.get3d_scalar()

Create a volume plot

In [6]:
dv3d.ToggleVolumePlot = vcs.on

Set the color map

In [7]:
dv3d.ScaleColormap = [-15.0, 15.0, 1] 
In [8]:
dv3d.ScaleTransferFunction =  [ 3.64, 24, 1]
In [9]:
dv3d.VerticalScaling = 6.0 

Set the initial camera position

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.

In [10]:
dv3d.Camera={'Position': (-161, -171, 279), 'ViewUp': (.29, 0.67, 0.68), 'FocalPoint': (146.7, 8.5, -28.6)}
In [11]:
dv3d_v = vcs.get3d_scalar()   

Choose variable to plot

Select the temperature (tmpu) variable from the open goes5-sample.nc file (f) and assign to the v0 variable.

In [12]:
v0 = f["tmpu"] 

Calculate Volume Average

Average the temperature of the 3D volume over the x axis (the longitude) and assign to the variable, va.

In [13]:
va = cdutil.averager( v0, axis='x' )

Create Volume bounds

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.

In [14]:
v01,va1=genutil.grower(v0,va)

Calculate Final 3D Temperature Volume

Subtract the volume bounds from each other to create the volume, v.

In [15]:
v = v01 - va1

Create the 3D plot

Note: when you run the following line, you can safely ignore the warning. You should see the 3D plot after the line runs.

In [16]:
x.plot( v, dv3d )
AREGSL: xyz
Warning, can't open data file 'None'
TYPEEEEEEEEP coastline
 build Volume Pipeline: range =  [-34.8010860443118, 24.015470886230446, -34.8010860443118, 0]
setVolRenderCfg
initCamera: Camera => ((-161.0, -171.0, 279.0), (146.7, 8.5, -28.6), (0.2906693100067274, 0.6715463369120944, 0.6815694165674988)) 
Out[16]:

Save a 2D image of the 3D plot

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.

In [17]:
x.png('temp_anomaly.png')