Re: Simple surface plot

Hi John,

> Ok so I am trying to show a 2D slice out of a 3D model grid;
> (currVar is a netcdf Variable)
> 
>     DimensionIterator dimIter = currVar.getDimensionIterator();
>     ucar.netcdf.Dimension dim0 = ( ucar.netcdf.Dimension )
> dimIter.next();
>     ucar.netcdf.Dimension dim1 = ( ucar.netcdf.Dimension )
> dimIter.next();
>     ucar.netcdf.Dimension dim2 = ( ucar.netcdf.Dimension )
> dimIter.next();
>     ucar.netcdf.Dimension dim3 = ( ucar.netcdf.Dimension )
> dimIter.next();
>         int[] index = {0, 0, 0, 0}; // first two indices fixed at 0, 0
>       int sizeX = shape[2];
>       int sizeY = shape[3];
>       int sizeXY = sizeX*sizeY;
> 
>       float[][] xy = new float[2][];
>       float[][] z = new float[1][];
>       xy[0] = new float[sizeXY];
>       xy[1] = new float[sizeXY];
>       z[0] = new float[sizeXY];
> 
>       for (int j=0; j<sizeY; j++) {
>         for (int i=0; i<sizeX; i++) {
>           index[2] = i;
>           index[3] = j;
>           z[0][i+j*sizeX] = currVar.getFloat(index);
> 
>           xy[0][i+j*sizeX] = (float) i;
>           xy[1][i+j*sizeX] = (float) j;
>         }
>       }
> 
>     RealType xtype = RealTypeFactory(dim2.getName());
>     RealType ytype = RealTypeFactory(dim2.getName());
>     RealType ztype = RealTypeFactory(currVar.getName());
> 
>     RealTupleType xyType = new RealTupleType(xtype, ytype);
>     FunctionType ft = new FunctionType(xyType, ztype);
> 
>     // look this is the one i changed!!!
>     //*** Gridded2DSet xySet = new Gridded2DSet(xyType, xy,
> xy[0].length);
>     Gridded2DSet xySet = new Gridded2DSet(xyType, xy, sizeX , sizeY);
>     FlatField ffld = new FlatField(ft, xySet);
>     ffld.setSamples(z);
> 
>     // create a DataReference
>     DataReference setRef = new DataReferenceImpl("Visad2D data
> reference");
>     setRef.setData(ffld);
> 
>     // create a Display using Java2D
>     DisplayImpl display = new DisplayImplJ3D("Visad2D display");
> 
>     // map plot to display coordinates
>     display.addMap(new ScalarMap(xtype, Display.XAxis));
>     display.addMap(new ScalarMap(ytype, Display.YAxis));
>     display.addMap(new ScalarMap(ztype, Display.ZAxis));
> 
>     // link the Display to the data
>     display.addReference(setRef);
> 
> so the first pass (line designated with //***) gave me this error:
> System Error:   java.lang.ArrayIndexOutOfBoundsException: 1
> System Error:           at
> visad.ShadowFunctionOrSetType.doTransform(ShadowFunctionOrSetType.java:2
> 053)
> System Error:           at
> visad.java3d.ShadowFunctionOrSetTypeJ3D.doTransform(ShadowFunctionOrSetT
> ypeJ3D.java:101)
> System Error:           at
> visad.java3d.DefaultRendererJ3D.doTransform(DefaultRendererJ3D.java:84)
> System Error:           at
> visad.java3d.RendererJ3D.doAction(RendererJ3D.java:163)
> System Error:           at visad.DisplayImpl.doAction(DisplayImpl.java:808)
> System Error:           at visad.ActionImpl.run(ActionImpl.java:186)
> System Error:           at
> visad.util.ThreadPool$ThreadMinnow.run(ThreadPool.java:76)
> 
> the second pass (as you see it above) got me past the Exception, but the
> data looks like it's
> displayed wrong: perhaps only took one longitude value and replicated
> it.
> 
> So I have a couple of questions:
>         what is the meaning of the 2 Gridded2DSet constructors? how does it
> change how the data should be passed in?

The first Gridded2DSet(MathType, float[][], int) constructor
you tried is the signature for manifold dimension = 1 (i.e.,
the grid points lie along a 1-D curve).

The second Gridded2DSet(MathType, float[][], int, int) is
the signature for manifold dimension = 2 (i.e., a true 2-D
grid, although "curvey").

>         Sindre Mehus "Simple surface plot" example uses a Gridded3DSet; how
> does that differ?

Your data have 2 independent variables (x and y) and one
dependent variable (z).  A "3-D grid" generally means 3
independent variables.  A Gridded3DSet defines a set of sample
locations in 3 independent variables with a gridded topology.

Once your data are in a FlatField whose domain Set is a
Gridded3DSet, you can pull out a 2-D slice by constructing
a Gridded2DSet that defines a 2-D grid of points on the slice,
then passing that Gridded2DSet as the argument to the
FlatField's resample() method.

You can find some relevant code examples on the VisAD mailing
list archive.  See the question at:

  http://www.unidata.ucar.edu/staff/russ/visad/msg00487.html

and the response at:

  http://www.unidata.ucar.edu/staff/russ/visad/msg00488.html

Cheers,
Bill
----------------------------------------------------------
Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738
http://www.ssec.wisc.edu/~billh/vis.html

  • 1999 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: