Re: subsetting

Hi John,

> Suppose I have some MathType that looks like:
> 
> ((x1, x2, ... xn) -> (y1, y2, ... yn))
> 
> How should I create a subset of this data where one of the x's or y's
> falls within some range?

Get the domain Set of your Field, then select the subset of
its samples which satisfy the criteria.

Note that in the general case this destroys the topology
of the Set, leaving you at the mercy of Delaunay algorithms
for constructing a new topology.  You can avoid this two ways:

If you know something about the selection, such as it
only applies to x's and in fairly regular ways, you might
use that knowledge to construct a topology.

You might also construct a new Field with the same domain Set
as your original, but just mark the de-selected samples as
missing (plug range values with NaNs).

If you just want to visualize the selection, you can do this
using ScalarMaps of the x's and y's to Display.SelectRange.
visad/examples/Test21.java is an example of using SelectRange.

> For instance, I might have a data set like:
> 
> ((lat, lon) -> (elevation, temperature, precipitation, NDVI))
> 
> and I might want to bin this data by elevation in order to demonstrate
> something about microclimates on a mountainside.

For this you probably need to explicitly select samples
according to their elevation values.  One other way to
avoid Dealunay algorithms is to chnage the MathType to

(index -> (lat, lon, elevation, temperature, precipitation, NDVI))

where the domain Set of "index" values is simple a

  IntegerSet(index, number_of_selected_samples);

If "field" is your original FlatField, then something like:

  Set ds = field.getDomainSet();
  float[][] samples = ds.getSamples();
  float[][] values = field.getFloats();

  int len = field.getLength();
  int number = 0;
  int[] indices = new int[len];
  for (int i=0; i<len; i++) {
    if (low_elev < values[0][i] && values[0][i] < hi_elev) {
      indices[i] = number;
      number++;
    }
  }
  float[][] new_values = new float[5][number];
  for (int i=0; i<number; i++) {
    new_values[0][i] = samples[0][indices[i]];
    new_values[1][i] = samples[1][indices[i]];
    new_values[2][i] = valus[0][indices[i]];
    new_values[3][i] = valus[1][indices[i]];
    new_values[4][i] = valus[2][indices[i]];
  }
  RealType[] reals = {RealType.Latitude, RealType.Longitude,
                      RealType.Altitude, precipitation, NDVI};
  RealTupleType range = new RealTupleType(reals);
  RealType index = nrew RealType("index", null, null);
  FunctionType ft = new FunctionType(index, range);
  Integer1DSet new_ds = new Integer1DSet(number);
  FlatField new_field = new FlatField(ft, new_ds);
  new_field.setSamples(new_values);
  
This was a bit rushed, since I just returned from Washington
and am leaving for Illinois today.  Also, next week, I'll be
at IEEE Vis 99 in San Francisco and would be happy to talk
to any of you who are there (and will teach about VisAD at a
course there on Monday).

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: