示例#1
0
  /**
   * Indicates if a VisAD MathType is compatible with this instance. A RealType is compatible if its
   * {@link RealType#equalsExceptNameButUnits} method returns true when given the return value of
   * {@link #getRealType()} and if this quantity has no coordinate system transformation. A
   * RealTupleType is compatible if its {@link RealTupleType#equalsExceptNameButUnits} method
   * returns true when given the return value of {@link #getRealTupleType()} and if the coordinate
   * system transformations are compatible. A SetType is compatible if its RealTupleType is
   * compatible. A FunctionType is compatible if the MathType of its range is compatible. All other
   * MathTypes are incompatible.
   *
   * @param type The VisAD MathType to examine for compatibility.
   * @return <code>true</code> if and only if the MathType is compatible with this instance.
   * @throws VisADException VisAD failure.
   */
  public boolean isCompatible(MathType type) throws VisADException {

    boolean isCompatible;

    if (type instanceof RealType) {
      isCompatible =
          ((RealType) type).equalsExceptNameButUnits(realType)
              && (getRealTupleType().getCoordinateSystem() == null);
    } else if (type instanceof RealTupleType) {
      RealTupleType thisTupleType = getRealTupleType();
      RealTupleType thatTupleType = (RealTupleType) type;

      if (!thatTupleType.equalsExceptNameButUnits(thisTupleType)) {
        isCompatible = false;
      } else {
        CoordinateSystem thisCS = thisTupleType.getCoordinateSystem();
        CoordinateSystem thatCS = thatTupleType.getCoordinateSystem();

        isCompatible =
            ((thisCS == null)
                ? thatCS == null
                : thisCS.getReference().equalsExceptNameButUnits(thatCS.getReference()));
      }
    } else if (type instanceof SetType) {
      isCompatible = isCompatible(((SetType) type).getDomain());
    } else if (type instanceof FunctionType) {
      isCompatible = isCompatible(((FunctionType) type).getRange());
    } else {
      isCompatible = false;
    }

    return isCompatible;
  }
示例#2
0
  /**
   * Set the sounding in the table
   *
   * @param sounding the sounding
   * @throws RemoteException Java RMI problem
   * @throws VisADException problem dissecting data
   */
  private void setupTable(Field sounding) throws VisADException, RemoteException {

    Set domain = sounding.getDomainSet();
    CoordinateSystem cs = domain.getCoordinateSystem();

    numDomainCols = domain.getDimension();
    if (cs != null) {
      numDomainCols++;
    }
    RealType[] rangeComps = ((FunctionType) sounding.getType()).getRealComponents();
    numRangeCols = rangeComps.length;
    columnNames = new String[numDomainCols + numRangeCols];

    SetType t = (SetType) domain.getType();
    Unit[] units = domain.getSetUnits();
    RealTupleType rtt = t.getDomain();
    RealType[] comps = rtt.getRealComponents();
    columnNames[0] = makeColumnName(comps[0], units[0]);
    if ((cs != null)) {
      RealTupleType refType = cs.getReference();
      RealType[] refComps = refType.getRealComponents();
      Unit[] refUnits = cs.getReferenceUnits();
      columnNames[1] = makeColumnName(refComps[0], refUnits[0]);
    }

    // set for default
    for (int i = 0; i < rangeComps.length; i++) {
      columnNames[numDomainCols + i] =
          makeColumnName(rangeComps[i], rangeComps[i].getDefaultUnit());
    }
    // wind
    if (rangeComps.length > 2) {
      csUnits = new Unit[] {rangeComps[2].getDefaultUnit(), rangeComps[3].getDefaultUnit()};
      haveUV =
          (Unit.canConvert(csUnits[0], CommonUnit.meterPerSecond)
              && Unit.canConvert(csUnits[1], CommonUnit.meterPerSecond));
      if (haveUV) {
        windTransform =
            new InverseCoordinateSystem(
                new RealTupleType(Speed.getRealType(), Direction.getRealType()),
                new PolarHorizontalWind.PolarCoordinateSystem(
                    new RealTupleType(rangeComps[2], rangeComps[3]),
                    CommonUnit.meterPerSecond,
                    CommonUnit.degree));
      } else {
        windTransform = new PolarHorizontalWind.PolarCoordinateSystem(csUnits[0], csUnits[1]);
      }
    }
    if (model == null) {
      model = new SoundingTableModel();
      sorter = new TableSorter(model);
      JTableHeader header = getTableHeader();
      header.setToolTipText("Click to sort");
      sorter.setTableHeader(getTableHeader());
      setModel(sorter);
      setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
      setPreferredScrollableViewportSize(new Dimension(400, 200));
      getTableHeader().setReorderingAllowed(false);
    }
  }
示例#3
0
  /**
   * Set the sounding in the table
   *
   * @param sounding the sounding
   * @throws RemoteException Java RMI problem
   * @throws VisADException problem dissecting data
   */
  private void setSounding(Field sounding) throws VisADException, RemoteException {
    domainData = null;

    // domain values
    Set domain = sounding.getDomainSet();
    CoordinateSystem cs = domain.getCoordinateSystem();

    float[][] domSamples = domain.getSamples(false);
    if ((cs != null)) {
      float[][] domFloats = Set.copyFloats(domSamples);
      // Must convert from the default coordinate domain system to
      // the domain coordinate system of the sounding.
      String fromUnit = sounding.getDomainUnits()[0].toString();
      String toUnit = cs.getCoordinateSystemUnits()[0].toString();
      if (!fromUnit.equals(toUnit) && SimpleUnit.isCompatible(fromUnit, toUnit)) {
        float conversionFactor = (float) SimpleUnit.getConversionFactor(fromUnit, toUnit);
        for (int i = 0; i < domFloats.length; i++) {
          for (int j = 0; j < domFloats[i].length; j++) {
            domFloats[i][j] = domFloats[i][j] * conversionFactor;
          }
        }
      }
      float[][] refData = cs.toReference(domFloats);
      domainData = new float[][] {domSamples[0], refData[0]};
    }
    // range values
    RealType[] rangeComps = ((FunctionType) sounding.getType()).getRealComponents();
    rangeData = sounding.getFloats(false);

    // wind
    if (rangeComps.length > 2) {
      transformWinds = (showUAndV && !haveUV) || (!showUAndV && haveUV);
      if (!transformWinds) {
        for (int i = 2; i < 4; i++) {
          columnNames[numDomainCols + i] =
              makeColumnName(rangeComps[i], rangeComps[i].getDefaultUnit());
        }
      } else {
        RealTupleType refType = windTransform.getReference();
        Unit[] refUnits = windTransform.getReferenceUnits();
        for (int i = 0; i < 2; i++) {
          columnNames[numDomainCols + i + 2] =
              makeColumnName((RealType) refType.getComponent(i), refUnits[i]);
        }
        float[][] newVals =
            windTransform.toReference(Set.copyFloats(new float[][] {rangeData[2], rangeData[3]}));
        rangeData[2] = newVals[0];
        rangeData[3] = newVals[1];
      }
    }
    sorter.setTableModel(model);
  }
  /**
   * @param gridWinds
   * @param grid
   * @return
   * @throws IllegalArgumentException if the grid is irregular or has too few points or has no
   *     {@link visad.CoordinateSystem}, or if the reference of the grid's {@link
   *     visad.CoordinateSystem} doesn't contain {@link visad.RealType.Latitude} and {@link
   *     visad.RealType.Longitude}.
   * @throws VisADException
   */
  private static float[][] trueWind(float[][] gridWinds, SampledSet grid) throws VisADException {

    if (grid instanceof IrregularSet) {
      throw new IllegalArgumentException(grid.toString());
    }

    CoordinateSystem cs = grid.getCoordinateSystem();
    boolean hasCS = (cs != null);

    RealTupleType rtt = (hasCS) ? cs.getReference() : ((SetType) grid.getType()).getDomain();

    int latI = rtt.getIndex(RealType.Latitude);

    if (latI == -1) {
      throw new IllegalArgumentException(rtt.toString());
    }

    int lonI = rtt.getIndex(RealType.Longitude);

    if (lonI == -1) {
      throw new IllegalArgumentException(rtt.toString());
    }

    if (grid.getManifoldDimension() < 2) {
      throw new IllegalArgumentException(grid.toString());
    }

    float[] us = new float[grid.getLength()];
    float[] vs = new float[grid.getLength()];

    Arrays.fill(us, 0);
    Arrays.fill(vs, 0);
    addComponent(grid, gridWinds, cs, 0, latI, lonI, us, vs);
    addComponent(grid, gridWinds, cs, 1, latI, lonI, us, vs);

    return new float[][] {us, vs};
  }
  /**
   * I have no idea what this does.
   *
   * @param grid sampling grid
   * @param index some sort of index
   * @return a new flat field with something different
   * @throws RemoteException Java RMI error
   * @throws VisADException VisAD error
   */
  private static FlatField hatFieldOld(Set grid, int index) throws VisADException, RemoteException {

    CoordinateSystem cs = grid.getCoordinateSystem();
    boolean hasCS = (cs != null);

    RealTupleType rtt = (hasCS) ? cs.getReference() : ((SetType) grid.getType()).getDomain();

    int latI = rtt.getIndex(RealType.Latitude);

    if (latI == -1) {
      throw new IllegalArgumentException(grid.toString());
    }

    int lonI = rtt.getIndex(RealType.Longitude);

    if (lonI == -1) {
      throw new IllegalArgumentException(grid.toString());
    }

    if (grid.getManifoldDimension() < 2) {
      throw new IllegalArgumentException(grid.toString());
    }

    int[][] neighbors = grid.getNeighbors(index);
    LatLonPointImpl refPt = new LatLonPointImpl();
    LatLonPointImpl neiPt = new LatLonPointImpl();
    Bearing bearing = new Bearing();
    float[] hat1 = new float[2];
    float[] hat2 = new float[2];
    float[][] hat = new float[2][grid.getLength()];

    for (int i = 0; i < neighbors.length; i++) {
      float[][] refCoords = grid.indexToValue(new int[] {i});
      if (hasCS) {
        refCoords = cs.toReference(refCoords);
      }

      float[][] neiCoords = grid.indexToValue(neighbors[i]);
      if (hasCS) {
        neiCoords = cs.toReference(neiCoords);
      }

      refPt.set(refCoords[latI][0], refCoords[lonI][0]);
      compute(refPt, neiPt, neiCoords[latI][0], neiCoords[lonI][0], -180, bearing, hat1);

      float d1 = (float) bearing.getDistance();

      compute(refPt, neiPt, neiCoords[latI][1], neiCoords[lonI][1], 0, bearing, hat2);

      float d2 = (float) bearing.getDistance();
      boolean bad1 = Double.isNaN(d1);
      boolean bad2 = Double.isNaN(d2);

      if (bad1 && bad2) {
        hat[0][i] = Float.NaN;
        hat[1][i] = Float.NaN;
      } else {
        if (bad1) {
          hat[0][i] = hat2[0];
          hat[1][i] = hat2[1];
        } else if (bad2) {
          hat[0][i] = hat1[0];
          hat[1][i] = hat1[1];
        } else {
          float tot = d1 + d2;
          float c1 = d2 / tot;
          float c2 = d1 / tot;
          float xhat = c1 * hat1[0] + c2 * hat2[0];
          float yhat = c1 * hat1[1] + c2 * hat2[1];
          float mag = (float) Math.sqrt(xhat * xhat + yhat * yhat);

          hat[0][i] = xhat / mag;
          hat[1][i] = yhat / mag;
        }
      }
    }

    FlatField hatField =
        new FlatField(
            new FunctionType(
                ((SetType) grid.getType()).getDomain(),
                new RealTupleType(
                    RealType.getRealType("xHat", CommonUnit.dimensionless),
                    RealType.getRealType("yHat", CommonUnit.dimensionless))),
            grid);

    hatField.setSamples(hat, false);

    return hatField;
  }
  /**
   * The returned {@link visad.FlatField} will have NaN-s for those unit vector components that
   * could not be computed.
   *
   * @param grid The spatial grid.
   * @param index The index of the manifold dimension along which to compute the unit vector.
   * @return A field of components of the unit vector for the given manifold dimension.
   * @throws NullPointerException if the grid is <code>null</code>.
   * @throws IllegalArgumentException if the manifold dimension of the grid is less than 2 or if the
   *     grid doesn't contain {@link visad.RealType#Latitude} and {@link visad.RealType#Longitude}.
   * @throws VisADException if a VisAD failure occurs.
   * @throws RemoteException if a Java RMI failure occurs.
   */
  private static FlatField hatFieldNew(Set grid, int index) throws VisADException, RemoteException {

    CoordinateSystem cs = grid.getCoordinateSystem();
    boolean hasCS = cs != null;

    RealTupleType rtt = (hasCS) ? cs.getReference() : ((SetType) grid.getType()).getDomain();

    int latI = rtt.getIndex(RealType.Latitude);

    if (latI == -1) {
      throw new IllegalArgumentException(rtt.toString());
    }

    int lonI = rtt.getIndex(RealType.Longitude);
    if (lonI == -1) {
      throw new IllegalArgumentException(rtt.toString());
    }

    if (grid.getManifoldDimension() < 2) {
      throw new IllegalArgumentException(grid.toString());
    }

    int[][] neighbors = grid.getNeighbors(index);
    LatLonPointImpl refPt = new LatLonPointImpl();
    LatLonPointImpl neiPt = new LatLonPointImpl();
    Bearing bearing = new Bearing();
    float[] hat1 = new float[2];
    float[] hat2 = new float[2];
    float[][] hat = new float[2][grid.getLength()];

    float[][] refCoords = null;
    float[][] neiCoords = null;
    float[][] domainSamples = grid.getSamples(false);

    refCoords = (hasCS) ? cs.toReference(Set.copyFloats(domainSamples)) : domainSamples;
    // If the grid is lat/lon or has an IdentityCoordinateSystem
    // don't do the rotation
    // TODO:  handle rotated lat/lon grids
    if (!hasCS
        || (refCoords == domainSamples)
        || (Arrays.equals(refCoords[latI], domainSamples[latI])
            && Arrays.equals(refCoords[lonI], domainSamples[lonI]))) {
      if (index == 0) {
        Arrays.fill(hat[0], 1);
        Arrays.fill(hat[1], 0);
      } else {
        Arrays.fill(hat[0], 0);
        Arrays.fill(hat[1], 1);
      }
    } else {

      float latBefore, lonBefore, latAfter, lonAfter;
      // int backOffset = (index==0) ? -180 : 0;
      // int foreOffset = (index==0) ? 0 : -180;
      int backOffset = -180;
      int foreOffset = 0;
      for (int i = 0; i < neighbors.length; i++) {
        refPt.set(refCoords[latI][i], refCoords[lonI][i]);
        if ((neighbors[i][0] < 0) || (neighbors[i][0] >= neighbors.length)) {
          latBefore = Float.NaN;
          lonBefore = Float.NaN;
        } else {
          latBefore = refCoords[latI][neighbors[i][0]];
          lonBefore = refCoords[lonI][neighbors[i][0]];
        }
        if ((neighbors[i][1] < 0) || (neighbors[i][1] >= neighbors.length)) {
          latAfter = Float.NaN;
          lonAfter = Float.NaN;
        } else {
          latAfter = refCoords[latI][neighbors[i][1]];
          lonAfter = refCoords[lonI][neighbors[i][1]];
        }

        compute(refPt, neiPt, latBefore, lonBefore, backOffset, bearing, hat1);

        float d1 = (float) bearing.getDistance();

        compute(refPt, neiPt, latAfter, lonAfter, foreOffset, bearing, hat2);

        float d2 = (float) bearing.getDistance();
        boolean bad1 = Double.isNaN(d1);
        boolean bad2 = Double.isNaN(d2);

        if (bad1 && bad2) {
          hat[0][i] = Float.NaN;
          hat[1][i] = Float.NaN;
        } else {
          if (bad1) {
            hat[0][i] = hat2[0];
            hat[1][i] = hat2[1];
          } else if (bad2) {
            hat[0][i] = hat1[0];
            hat[1][i] = hat1[1];
          } else {
            float tot = d1 + d2;
            float c1 = d2 / tot;
            float c2 = d1 / tot;
            float xhat = c1 * hat1[0] + c2 * hat2[0];
            float yhat = c1 * hat1[1] + c2 * hat2[1];
            float mag = (float) Math.sqrt(xhat * xhat + yhat * yhat);

            hat[0][i] = xhat / mag;
            hat[1][i] = yhat / mag;
          }
        }
      }
    }

    FlatField hatField =
        new FlatField(
            new FunctionType(
                ((SetType) grid.getType()).getDomain(),
                new RealTupleType(
                    RealType.getRealType("xHat", CommonUnit.dimensionless),
                    RealType.getRealType("yHat", CommonUnit.dimensionless))),
            grid);

    hatField.setSamples(hat, false);
    return hatField;
  }
  /**
   * determine whether the given MathType and collection of ScalarMaps meets the criteria to use
   * ImageRendererJ3D. Throw a VisADException if ImageRenderer cannot be used, otherwise return
   * true.
   */
  public static boolean isRendererUsable(MathType type, ScalarMap[] maps) throws VisADException {
    RealType time = null;
    RealTupleType domain = null;
    RealTupleType range = null;
    RealType x = null, y = null;
    RealType rx = null, ry = null; // WLH 19 July 2000
    RealType r = null, g = null, b = null;
    RealType rgb = null;

    // must be a function
    if (!(type instanceof FunctionType)) {
      throw new VisADException("Not a FunctionType");
    }
    FunctionType function = (FunctionType) type;
    RealTupleType functionD = function.getDomain();
    MathType functionR = function.getRange();

    // time function
    if (function.equalsExceptName(image_sequence_type)
        || function.equalsExceptName(image_sequence_type2)
        || function.equalsExceptName(image_sequence_type3)) {
      // strip off time RealType
      time = (RealType) functionD.getComponent(0);
      function = (FunctionType) functionR;
      functionD = function.getDomain();
      functionR = function.getRange();
    }

    // ((ImageLine, ImageElement) -> ImageValue)
    // ((ImageLine, ImageElement) -> (ImageValue))
    // ((ImageLine, ImageElement) -> (Red, Green, Blue))
    if (function.equalsExceptName(image_type)
        || function.equalsExceptName(image_type2)
        || function.equalsExceptName(image_type3)) {
      domain = function.getDomain();
      MathType rt = function.getRange();
      if (rt instanceof RealType) {
        range = new RealTupleType((RealType) rt);
      } else if (rt instanceof RealTupleType) {
        range = (RealTupleType) rt;
      } else {
        // illegal MathType
        throw new VisADException("Illegal RangeType");
      }
    } else {
      // illegal MathType
      throw new VisADException("Illegal MathType");
    }

    // extract x and y from domain
    x = (RealType) domain.getComponent(0);
    y = (RealType) domain.getComponent(1);

    // WLH 19 July 2000
    CoordinateSystem cs = domain.getCoordinateSystem();
    if (cs != null) {
      RealTupleType rxy = cs.getReference();
      rx = (RealType) rxy.getComponent(0);
      ry = (RealType) rxy.getComponent(1);
    }

    // extract colors from range
    int dim = range.getDimension();
    if (dim == 1) rgb = (RealType) range.getComponent(0);
    else { // dim == 3
      r = (RealType) range.getComponent(0);
      g = (RealType) range.getComponent(1);
      b = (RealType) range.getComponent(2);
    }

    // verify that collection of ScalarMaps is legal
    boolean btime = (time == null);
    boolean bx = false, by = false;
    boolean brx = false, bry = false; // WLH 19 July 2000
    boolean br = false, bg = false, bb = false;
    boolean dbr = false, dbg = false, dbb = false;
    Boolean latlon = null;
    DisplayRealType spatial = null;

    for (int i = 0; i < maps.length; i++) {
      ScalarMap m = maps[i];
      ScalarType md = m.getScalar();
      DisplayRealType mr = m.getDisplayScalar();
      boolean ddt = md.equals(time);
      boolean ddx = md.equals(x);
      boolean ddy = md.equals(y);
      boolean ddrx = md.equals(rx);
      boolean ddry = md.equals(ry);
      boolean ddr = md.equals(r);
      boolean ddg = md.equals(g);
      boolean ddb = md.equals(b);
      boolean ddrgb = md.equals(rgb);

      // animation mapping
      if (ddt) {
        if (btime) throw new VisADException("Multiple Time mappings");
        if (!mr.equals(Display.Animation)) {
          throw new VisADException("Time mapped to something other than Animation");
        }
        btime = true;
      }

      // spatial mapping
      else if (ddx || ddy || ddrx || ddry) {
        if (ddx && bx || ddy && by || ddrx && brx || ddry && bry) {
          throw new VisADException("Duplicate spatial mappings");
        }
        if (((ddx || ddy) && (brx || bry)) || ((ddrx || ddry) && (bx || by))) {
          throw new VisADException("reference and non-reference spatial mappings");
        }
        RealType q = (ddx ? x : null);
        if (ddy) q = y;
        if (ddrx) q = rx;
        if (ddry) q = ry;

        boolean ll;
        if (mr.equals(Display.XAxis) || mr.equals(Display.YAxis) || mr.equals(Display.ZAxis)) {
          ll = false;
        } else if (mr.equals(Display.Latitude)
            || mr.equals(Display.Longitude)
            || mr.equals(Display.Radius)) {
          ll = true;
        } else throw new VisADException("Illegal domain mapping");

        if (latlon == null) {
          latlon = new Boolean(ll);
          spatial = mr;
        } else if (latlon.booleanValue() != ll) {
          throw new VisADException("Multiple spatial coordinate systems");
        }
        // two mappings to the same spatial DisplayRealType are not allowed
        else if (spatial == mr) {
          throw new VisADException("Multiple mappings to the same spatial DisplayRealType");
        }

        if (ddx) bx = true;
        else if (ddy) by = true;
        else if (ddrx) brx = true;
        else if (ddry) bry = true;
      }

      // rgb mapping
      else if (ddrgb) {
        if (br || bg || bb) {
          throw new VisADException("Duplicate color mappings");
        }
        if (rgb == null || !(mr.equals(Display.RGB) || mr.equals(Display.RGBA))) {
          throw new VisADException("Illegal RGB/RGBA mapping");
        }
        dbr = dbg = dbb = true;
        br = bg = bb = true;
      }

      // color mapping
      else if (ddr || ddg || ddb) {
        if (rgb != null) throw new VisADException("Illegal RGB mapping");
        RealType q = (ddr ? r : (ddg ? g : b));
        if (mr.equals(Display.Red)) dbr = true;
        else if (mr.equals(Display.Green)) dbg = true;
        else if (mr.equals(Display.Blue)) dbb = true;
        else throw new VisADException("Illegal color mapping");

        if (ddr) br = true;
        else if (ddg) bg = true;
        else bb = true;
      }

      // illegal ScalarMap involving this MathType
      else if (ddt || ddx || ddy || ddrx || ddry || ddr || ddg || ddb || ddrgb) {
        throw new VisADException("Illegal mapping: " + m);
      }
    }

    // return true if all conditions for ImageRendererJ3D are met
    if (!(btime && ((bx && by) || (brx && bry)) && br && bg && bb && dbr && dbg && dbb)) {
      throw new VisADException("Insufficient mappings");
    }
    return true;
  }