To run the examples, you first have to use the unix
source command to load the CDAT environment.
conda activate [YOUR_CDAT_CONDA_ENV]
On older anaconda version it might be
source activate [YOUR_CDAT_CONDA_ENV]
Once you’ve loaded the environment, you should be able to run the examples. They should output a .png file that has the same image as the example.
We strongly recommend using Jupyter notebooks for the tutorials. When you type the command below into your command-line window (e.g. Command Prompt for Windows or Terminal Window for Mac) it is best to have navigated via the command line to the folder that contains your Jupyter Notebooks either as single files (file extention .ipynb) or contained in subfolders. For additional help on Jupyter Notebooks see this Jupyter Documentation page.
We also recommend using the interactive python console for figuring out how to use CDAT’s scripting capabilities.
To run the interactive console, use the
ipython command, which should give you something like this:
Python 2.7.14 | packaged by conda-forge | (default, Dec 25 2017, 01:18:54) Type "copyright", "credits" or "license" for more information. IPython 5.5.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In :
To learn more about
ipython, you can read this tutorial.
Here’s a very simple example that walks you through the most basic steps:
import vcs, cdms2 import os import cdat_info # Download sample data files vcs.download_sample_data_files() # The vcs_canvas is the root object of VCS vcs_canvas = vcs.init() cdms_file = cdms2.open(os.path.join(cdat_info.get_sampledata_path(), "clt.nc")) # We'll pull a variable out of the netCDF file clt_variable = cdms_file("clt") # And then we'll plot it using the default graphics method (a boxfill) and the default template. vcs_canvas.plot(clt_variable) # To output to a .png file, you can just do this: vcs_canvas.png("clt.png") # And that's it!
Hopefully that helps some! If you have any other questions, let us know!