[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Reading OpenDAP data into Matlab using NetCDF-JAVA
- Subject: Re: Reading OpenDAP data into Matlab using NetCDF-JAVA
- Date: Fri, 02 Dec 2005 17:57:01 -0700
Rich Signell wrote:
John,
I would like to begin promoting the use of the high level java
interfaces to NetCDF & OpenDAP data for the large community of Matlab
users who now rely on low-level machine dependent binary interfaces.
In addition to getting away from maintaining a collection of machine
dependent binary file Matlab/NetCDF/OpenDAP interfaces, it would be
wonderful simply use the logic that you have coded into NetCDF-Java to
return coordinates for a variable, for example, instead of having to
repeat that logic in Matlab code.
I'd like to distribute a simple example that shows access to OpenDAP
data from Matlab as part of my pitch.
Here's the simple Matlab script I came up with (with help from Tom
Whittaker):
% <DAP.M>
% Simple example script to grab OpenDAP data into Matlab via Java
% % Rich Signell address@hidden
%
server='dods://stellwagen.er.usgs.gov/cgi-bin/nph-dods/';
file='adria/data/bathy/adria_bathy_15sec.nc';
url=[server file] % opendap URL %
import ucar.nc2.dods.* % import opendap reader classes
%
% Grab some data from this URL
s=DODSNetcdfFile(url);
v=s.findVariable('depth');
h=v.read([1100 20],[150 200]); % hyperslab some data
u=copyToNDJavaArray(h);
close(s);
pcolor(double(u));shading flat;colorbar;
title('Po Delta Bathymetry, Adriatic Sea. Depth below MSL(m)');
% </DAP.M>
So finally, here are my questions:
1) Is this the best way to get OpenDAP data?
see below
2) To make this work, I seem to need idv.jar, nc2.2.jar and visad.jar in
the same directory, but only need to add the full path name to idv.jar
in my Matlab classpath.txt file. Does that make sense to you?
you shouldnt need idv, just netcdf-2.2.jar and dods.jar, get it from:
http://www.unidata.ucar.edu/software/netcdf-java/
other jars are supposedly optional, see the README.
You might want to just use the toolsUI.jar, which has everything in it.
3) Would there be a simple example of asking, say, for a hyperslab of
temperature from a CF compliant file and having netcdf-java returning
the coordinates (lon,lat,time) for that hyperslab as well?
GridDataset dataset =
GridDataset.open("dods://motherlode.ucar.edu:8080/thredds/dodsC/model/DGEX/CONUS_12km/DGEX_CONUS_12km_20051202_0600.grib2");
GeoGrid grid = dataset.findGridByName("Temperature");
Array temp_data = grid_section.readDataSlice(0, 0, -1, -1);
// this is the coord sys for the entire grid:
GridCoordSys gcs = grid.getCoordinateSystem();
CoordinateAxis latAxis = gcs.getYHorizAxis();
Array lat_data = latAxis.read();
CoordinateAxis lonAxis = gcs.getXHorizAxis();
Array lon_data = lonAxis .read();
CoordinateAxis timeAxis = gcs.getTimeAxis();
CoordinateAxis zAxis = gcs.getVerticalAxis();
I hope that wasn't too many questions. I tried to think of an
appropriate list to ask this to, but couldn't come up with one.
If you think it's appropriate to ask this somewhere else, please let me
know.
Thanks,
Rich