Personal tools
You are here: Home Modeling Committee Gulf of Maine Model Interoperability Pilot Project MATLAB Model Interoperability Demo
Document Actions

MATLAB Model Interoperability Demo

by Rich Signell last modified 2008-10-31 16:36

The Matlab Model Interoperability Demo shows how to efficiently access and visualize multidimensional data (e.g. elevation, salinity, water velocity, wave heights) from a number of different Gulf of Maine ocean models using tools from a new CF Toolbox. The CF toolbox uses high-level NetCDF-Java routines that return lon,lat,depth and time in a standard form regardless of the type of model, allowing data from FVCOM, POM, ECOM, ROMS, WAVEWATCH3 to be accessed using the exact same matlab function.

Sample bottom temperature snapshot from WHOI-ROMS Ecohab modelSetting up Matlab to work with NetCDF-Java and the CF Toolbox:

Step 1: Fix Matlab's java classpath:
  • In Matlab, type "edit classpath.txt" and comment the line that contains mwucarunits.jar so it looks like this: 
    #$matlabroot/java/jarext/mwucarunits.jar 
    and save your changes.  For Linux users: If you can't edit the system classpath.txt file, then copy it to your home directory and make the edit there.  Matlab looks first for classpath.txt in your home directory, so it will use your edited version.
  • Exit and restart MATLAB.  
  • (Worried that you just commented out some java methods used by the system?  Don't be.  The mwucarunits.jar file is only used by the Mathworks "Model-Based Calibration Toolbox" and contains an old implementation of the Unidata UDUNITS package that conflicts with the more recent version that NetCDF-Java uses.)
Step 2: Set up Matlab to work with NetCDF-Java:
  • Get our version of Unidata's NetCDF-Java library: toolsUI-2.2.22-skb0.6.jar (~15 MB) and save it on your computer.  If your browser saves it with a .zip extension, just rename it back to .jar after you have downloaded it.
  • Get our CSTM Java library: cstmTools-1.0.02.jar (~5 MB) and save it to your computer.
  • For Matlab 7+:   In Matlab, type "edit startup.m" and add the following lines (modified  for the actual location of your jar files):

    javaaddpath('c:\your_path_here\toolsUI-2.2.22-skb0.6.jar','-end');
    javaaddpath('c:\your_path_here\cstmTools-1.0.02.jar','-end');
  • For Matlab 6 or 6.5: Type "edit classpath.txt" in Matlab, add the jar files to the list
  • Restart Matlab.   If you type "javaclasspath" you should see the two jar files you added (along with all the Java stuff that comes with Matlab)
Step 3: Set up Matlab to work with our CF Toolbox:
  • Get our Matlab CF Toolbox:  matlab_cf_2.7.zip
  • This toolbox has six directories:  ./cf,  ./cf/demos, ./seawater, ./RPSstuff, /cstmTBX-1.0, and /cstmTBX-1.0/Utilities.  If you already have the seawater and RPSstuff directories you can use your existing ones.
  • Add "cf", "seawater", "RPSstuff", "cstmTBX-1.0", and "cstmTBX-1.0/Utilities"  directories to your Matlab path.
Step 4: Try demos!
  • Go to the CF Toolbox demos subdirectory ( ./cf/demos), and try the following:
  • do_interop.m Demonstrates reading several different structured (POM, ECOM, and ROMS) and unstructured grid (FVCOM) model results with the exact same routine.  Doesn't make any fancy plots, but delivers 3D data fields with corrresponding lon,lat, z and time.
  • do_interop_plot3d.m Makes a 3D plot of the bottom temperature for structured grid models.
  • test_plot3D_fvcom.m Makes a 3D plot of bottom layer temperature for unstructured grid FVCOM model.
  • do_interop_data.m Compares an observed vertical profile of temperature to two different models.
  • gomoos_latest.m Plots a daily-averaged section of alongshore velocity from the latest GoMOOS forecast. 
  • do_interop_bot_temp.m Plots observed bottom temperatures within the last day on top of the predicted bottom temperature from the GoMOOS forecast model.
  • bathy_comp.m Compare bathymetry from two different bathymetric grids (global or regional).
Step 5: Explore on your own!
  • Type "help cf" to see a brief description of the CF tools.   http://w3.ualg.pt/~jluis/mirone/
  • The tools with "cf" are meant to be used with CF compliant data, while the tool "nj_varget" works with non-CF compliant data as well.   All the data on the Gulf of Maine Interoperability Experiment THREDDS Catalog at http://coast-enviro.er.usgs.gov/thredds/gom_interop_catalog.html is CF-compliant.  Browse the catalog and then cut-n-paste the OpenDAP URL into your matlab workspace to access that dataset. 
  • Explore bathymetry!  A collection of regional and global bathymetry (including the NOAA Coastal Relief Model) is available through this THREDDS Catalog:
    http://coast-enviro.er.usgs.gov/thredds/bathy_catalog.html
    If you are on a PC, there is an extremely useful toolkit for bathymetry called Mirone, by Joachim Luis.  You can use the "cf_subsetGrid.m" routine to clip just the region you want from a bathymetry data set.  For example:   
    >> uri='http://coast-enviro.er.usgs.gov/thredds/dodsC/bathy/crm_vol1.nc';
    >> [data,geo]=cf_subsetGrid(uri,'topo',[-70.9 -70.1 41.15 41.65]);
    will clip the bathy data from the Martha's Vineyard region out of the Coastal Relief Model Vol. 1 (Northeast) into your Matlab work space.   To make a simple plot, you can use "pcolor" or
    >> imagesc(geo.lon,geo.lat,data); axis xy
    To get the data into Mirone, do:
    >> grid2mirone(data,geo)
    See the Mirone help for more information -- it's a very powerful tool with many capabilities, including profiles, color-shaded relief images, output to Google Earth, the free Fledermaus IVIEW3D viewer, and more.
  • The CF toolbox routines can access data from THREDDS catalogs and OpenDAP servers (as well as local and remote NetCDF files).  More sources of data can be found by searching for "thredds" or "opendap" at NASA's Global Change Master Directory (http://gcmd.nasa.gov)


« January 2009 »
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
 

Bedford Institute of Oceanography Center for Marine Biodiversity The Huntsman Marine Science Center Census of Marine LIfe Gulf of Maine
Gulf of Maine Ocean Observing System
Coastal Ocean Observing Center U.S. Fish & Wildlife Service Gulf of Maine Council on the Marine Environment St. Andrews Biological Station
New Hampshire Department of Environmental Services
NOAA Coastal Services Center National Undersea Research Center Maine Department of Marine Resources Massachusetts Office of Coastal Zone Management Environmental Protection Agency United States Geological Survey Seabird Ecological Assessment Network
Stellwagen Bank National Marine Sanctuary