Hi Edward and Mathias,
There have been some similar questions to your in the past.
See the question and answer at:
http://www.unidata.ucar.edu/staff/russ/visad/msg00487.html
http://www.unidata.ucar.edu/staff/russ/visad/msg00488.html
Note in msg00488.html:
FlatField fplane = f.resample(...);
Already gives you data appropriate to display as a z-plane
slice in the original 3-D display - the rest of the code is
only to transfer its values to another FlatField appropriate
for a purely 2-D display.
Here are a few specific comments about Edward's message:
> I have a problem which I have half-solved, but it appears to me that I am
> abusing the framework to get there, rather than working with it. Hints as
> to a better/more elegant way to do what I want would be greatly appreciated.
>
> I have a 3D domain data set (altitude - lat - lon) of 1-D data
> (temperature). I need to make and display 2-D horizontal slices out of
> this data.
>
> To date, I:
>
> 1) Convert my data from it's native format (ASCII vectors) to a VisAD data
> structure more or less as follows
>
> // declare the data types to be used
> RealTupleType domainType = new RealTupleType(altitude, latitude,
> longitude);
> RealTupleType rangeType = new RealTupleType(domainType,temp);
>
> // parse the input file to create appropriately ordered temperature
> and
> coordinate ranges
> float geoSamples[][] = getCoords);
> float tempSamples[][] = getTemps();
>
> // make the domain set
> Gridded3DSet domain3DSet = new Gridded3DSet(domainType, geoSamples,
> numAlts, numLats, numLons);
>
> // create the flatfield, and populate it with the observations
> FlatField dataItem = new FlatField(rangeType, domain3DSet);
> dataItem.setSamples(tempSamples);
>
>
> 2) To get, say, the surface level temperatures, I need to get this data
> structure into a 2D field, because I can't make a 2D ScalarMap to a 3D
> field. So I make a new 2D domain set and 2D Flatfield of the k-th level by
> \
> // create data structures to hold new samples
> float newGeoSamples[][] = new float[2][numLats*numLons];
> float newTemperatures[][] = new float[1][numLats*numLons];
>
> // extract the lats and lons we need to make a 2D set
> for (i=0; i<numLon; i++) {
> for (j=0; j < numLon; j++) {
> index3D = level + numLevel*j + numLevel*numLat*i;
> index2D = j + numLat*i;
> newGeoSamples[0][index2D] = geoSamples[1][index3D];
> newGeoSamples[1][index2D] = geoSamples[2][index3D];
> newTemperatures[0][index2D]
> }
> }
>
> // create the appropriate 2D data type descriptors
> domainTuple2D = new RealTuple Type(latitude, longitude);
> functionType2D = new FunctionType(domainTuple2D, temperature);
>
> // create the 2D flat field
> Gridded2DSet domain2DSet = new Gridded2DSet(domainTuple2D,
> newGeoSamples,
> numLats, numLons);
> FlatField field2D = new FlatField(functionType2D, domain2DSet);
Here you are creating a new 2-D FlatField. If you want to display
your slice in the 3-D box, then you should resample the 3-D FlatField
to a Gridded3DSet with manifold dimension = 2.
> 3) Now I can create ScalarMaps, DataReferences, and plot my data in the
> normal satisfactory manner.
>
> So why do I think I'm missing something? Well,
>
> A) I'm creating two entirely duplicative arrays in step two, at a
> considerable memory loss.
There are some cases where multiple data objects can share the
same float arrays. I'm not sure if that is possible here, given
the Java restriction that arrays can overlap only if they are
identical.
> B) I'm entirely avoiding using any of resample's built-in interpolation
> features, which seems highly counterintuitive.
See my comments above.
> C) GriddedSets can't handle missing data, if any. Which can happen in my
> problem domain.
VisAD supports missing values in Field ranges but not in
Field domains (or Sets in general). Field domains need
topologies and there are no good ways to define topologies
for sets that may include missing locations.
You may need to construct an IrregularSet that includes only
your non-missing "domain" values. Note that IrregularSet
constructors can be very slow because of the need to use a
Delaunay algorithm to construct an irregular topology.
If your missing data are sparse, you might be able to
explicitly construct an irregular topology that is almost
gridded, and pass it to the IrregularSet constructor in a
DelaunayCustom object. This would avoid the slow Delaunay
algorithm.
> I can't be the first person to want to do this, so I'm sure there's a more
> straightforward, efficient way. What am I missing? Correct use of
> Coordinate Systems? Correct use of IrregularSets? Can anyone point me to
> some example code I should have been looking at?
The only tricky part here is the missing data in the domain.
Several TestNN.java programs in visad/examples construct
IrregularSets.
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