public float[][] getFloats(boolean copy) throws VisADException {
    FlatField fld = getAdaptedFlatField();
    if (fld == null) {
      throw new VisADException("Cannot get cached FlatField");
    }

    return fld.getFloats(copy);
  }
 private FlatField changeRangeType(FlatField image, RealType newRangeType)
     throws VisADException, RemoteException {
   FunctionType ftype = (FunctionType) image.getType();
   FlatField new_image =
       new FlatField(new FunctionType(ftype.getDomain(), newRangeType), image.getDomainSet());
   new_image.setSamples(image.getFloats(false), false);
   return new_image;
 }
Beispiel #3
0
  /** create parallel coordinates display for data */
  public static void parallel(DisplayImpl display, FlatField data)
      throws VisADException, RemoteException {

    FunctionType ftype = (FunctionType) data.getType();
    RealType index = (RealType) ftype.getDomain().getComponent(0);
    RealTupleType range = (RealTupleType) ftype.getRange();
    int ncoords = range.getDimension();
    int nrows = data.getLength();
    Set index_set = data.getDomainSet();
    float[][] samples = data.getFloats(false);

    RealType x = RealType.getRealType("coordinate");
    RealType y = RealType.getRealType("value");
    SetType xy = new SetType(new RealTupleType(x, y));
    FunctionType ptype = new FunctionType(index, xy);
    FieldImpl pfield = new FieldImpl(ptype, index_set);
    for (int j = 0; j < nrows; j++) {
      float[][] locs = new float[2][ncoords];
      for (int i = 0; i < ncoords; i++) {
        locs[0][i] = i;
        locs[1][i] = samples[i][j];
      }
      Gridded2DSet set = new Gridded2DSet(xy, locs, ncoords);
      pfield.setSample(j, set, false);
    }

    // create a DataReference for river system
    DataReference parallel_ref = new DataReferenceImpl("parallel");
    parallel_ref.setData(pfield);

    display.addMap(new ScalarMap(x, Display.XAxis));
    display.addMap(new ScalarMap(y, Display.YAxis));

    // enable axis scales
    display.getGraphicsModeControl().setScaleEnable(true);

    // link display to parallel display
    display.addReference(parallel_ref);
  }
  /**
   * Converts grid-relative wind to true (or absolute) wind. The U and V components of true wind are
   * {@link WesterlyWind} and {@link SoutherlyWind}, respectively. The domain of the input {@link
   * visad.FlatField} must have a manifold dimension of two or greater and it must have a reference
   * system which contains {@link visad.RealType#Latitude} and {@link visad.RealType#Longitude}. The
   * number of components in the range of the input {@link visad.FlatField} must be two. Both
   * components must have units convertible with {@link #DEFAULT_SPEED_UNIT}. The first and second
   * components are assumed to be the wind components in the direction of increasing first and
   * second manifold dimension indexes, respectively. The {@link visad.MathType} of the range of the
   * returned {@link visad.FlatField} will be <code>CartesianHorizontalWind.getEarthVectorType()
   * </code> and the domain will be the same as the input domain.
   *
   * @param rel The field of grid-relative wind.
   * @return The field of true wind corresponding to the input field.
   * @throws NullPointerException if <code>rel</code> is <code>null</code>.
   * @throws IllegalArgumentException if the input field doesn't have two and only two components in
   *     its range, or if the default units of the input range aren't equal, or if the domain of the
   *     input field doesn't have a transformation to latitude and longitude, or the grid is
   *     irregular or has too few points.
   * @throws VisADException if a VisAD failure occurs.
   * @throws RemoteException if a Java RMI failure occurs.
   * @see CartesianHorizontalWind
   */
  public static FlatField cartesianHorizontalWind(FlatField rel)
      throws VisADException, RemoteException {

    FunctionType funcType = (FunctionType) rel.getType();
    MathType rangeType = funcType.getRange();

    if (rel.getRangeDimension() != 2) {
      throw new IllegalArgumentException(rangeType.toString());
    }

    Unit[] units = rel.getDefaultRangeUnits();

    if (!units[0].equals(units[1])) {
      throw new IllegalArgumentException(units.toString());
    }

    SampledSet grid = (SampledSet) rel.getDomainSet();
    // check for single point grid
    if (grid instanceof SingletonSet) {
      return rel;
    } else if (grid instanceof GriddedSet) {
      int[] lengths = ((GriddedSet) grid).getLengths();
      if ((lengths[0] == 1) && (lengths[1] == 1)) {
        return rel;
      }
    }
    FlatField abs =
        new FlatField(
            new FunctionType(funcType.getDomain(), CartesianHorizontalWind.getEarthVectorType()),
            grid,
            (CoordinateSystem[]) null,
            rel.getRangeSets(),
            units);

    abs.setSamples(trueWind(rel.getFloats(), grid), false);

    return abs;
  }