Example #1
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);
    }
  }
Example #2
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);
  }
Example #3
0
  /** Go to the end of the animation sequence. */
  public void gotoEnd() {
    if (anime != null) {
      visad.Set aset = anime.getSet();
      if (aset != null) {
        try {
          anime.setCurrent(aset.getLength() - 1);
        } catch (VisADException ve) {;
        }
      }
    }

    setRunning(false);
    // shareIndex ();
    shareValue();
  }
Example #4
0
  /**
   * Load the volume data to the display
   *
   * @throws RemoteException problem loading remote data
   * @throws VisADException problem loading the data
   */
  private void loadVolumeData() throws VisADException, RemoteException {
    Trace.call1("VRC.loadVolumeData");
    FieldImpl grid = getGridDataInstance().getGrid();
    FieldImpl newGrid = grid;

    if (getSkipValue() > 0) {
      grid = GridUtil.subset(grid, getSkipValue() + 1);
      newGrid = grid;
    }

    if (!usePoints) {
      // make sure the projection is correct before we start
      // transforming the data
      setProjectionInView(true, true);

      CoordinateSystem cs = getNavigatedDisplay().getDisplayCoordinateSystem();
      if ((cs != null) && (getNavigatedDisplay() instanceof MapProjectionDisplay)) {
        try {
          if (GridUtil.isConstantSpatialDomain(grid)) {
            newGrid = makeLinearGrid(grid, cs);
          } else {
            Set timeSet = GridUtil.getTimeSet(grid);
            for (int i = 0; i < timeSet.getLength(); i++) {
              FieldImpl timeField = makeLinearGrid((FieldImpl) grid.getSample(i, false), cs);
              if (i == 0) {
                FunctionType ft =
                    new FunctionType(
                        ((SetType) timeSet.getType()).getDomain(), timeField.getType());
                newGrid = new FieldImpl(ft, timeSet);
              }
              newGrid.setSample(i, timeField, false);
            }
          }
        } catch (VisADException ve) {
          ve.printStackTrace();
          userErrorMessage(
              "Can't render volume for "
                  + paramName
                  + " in this projection. Try using the data projection");
          newGrid = grid;
        }
      }
    }
    Trace.call1("VRC.loadVolumeData.loadData");
    myDisplay.loadData(newGrid);
    Trace.call2("VRC.loadVolumeData.loadData");
    Trace.call2("loadVolumeData");
  }
Example #5
0
  /**
   * _more_
   *
   * @param visible _more_
   * @throws Exception _more_
   */
  public void setPairProfilesVisibility(boolean visible) throws Exception {
    profilesVisibility = visible;
    Set s = getDataTimeSet();
    int len = s.getLength();
    if (len < 2) { // no pair do nothing
      return;
    }
    AnimationWidget aniWidget = this.getAnimationWidget();
    // aniWidget.setBoxPanelVisible( !visible);
    // if (visible) {
    aniWidget.gotoIndex(0);
    aniWidget.setRunning(false);
    // }

    if (visible) {

      Set timeset = subSetProfilesTimeSet(s);
      dataNode.setOutputTimes((SampledSet) timeset);
    } else {
      Set timeset = getDataTimeSet();
      dataNode.setOutputTimes((SampledSet) timeset);
    }
    // GuiUtils.enableTree(aniWidget.getContents(), !visible);
    // now update the display list label
    aeroDisplay.setProfilesVisibility(visible, 0);

    if (visible) {
      if (s != null) {
        double[][] samples = s.getDoubles();
        DateTime dt = new DateTime(samples[0][1], s.getSetUnits()[0]);
        DateTime dt1 = new DateTime(samples[0][0], s.getSetUnits()[0]);
        listlabel =
            dt1.dateString()
                + ":"
                + dt1.timeString()
                + " and "
                + dt.dateString()
                + ":"
                + dt.timeString();
      }

    } else {
      listlabel = null;
    }

    updateDisplayList();
    updateHeaderLabel();
  }
Example #6
0
  /**
   * Constructs from another instance. The following attributes are set from the other instance:
   * color palette, the color RealType.
   *
   * @param that The other instance.
   * @throws VisADException VisAD failure.
   * @throws RemoteException Java RMI failure.
   */
  protected ImageRGBDisplayable(ImageRGBDisplayable that) throws VisADException, RemoteException {

    super(that);
    this.doAlpha = that.doAlpha;
    colorTupleType = that.colorTupleType;
    colorPalette = Set.copyFloats(that.colorPalette);
    if (colorTupleType != null) {
      setColorMaps();
    }
  }
Example #7
0
  /**
   * Respond to a timeChange event
   *
   * @param time new time
   */
  protected void timeChanged(Real time) {
    try {
      super.timeChanged(time);
      dataNode.setTime(new DateTime(time));
      if (getProfilesVisibility()) {
        AnimationWidget aniWidget = this.getAnimationWidget();
        int idx = 0;
        if (aniWidget.getTimes() != null) {
          int n = aniWidget.getTimes().length;
          for (int i = 0; i < n; i++) {
            if ((new DateTime(time)).equals(aniWidget.getTimeAtIndex(i))) {
              idx = i;
              continue;
            }
          }
        }
        aeroDisplay.setProfilesVisibility(true, idx);
        // display list update
        Set s = getDataTimeSet();
        if (s != null) {
          double[][] samples = s.getDoubles();
          DateTime dt = new DateTime(samples[0][idx + 1], s.getSetUnits()[0]);
          DateTime dt1 = new DateTime(samples[0][idx], s.getSetUnits()[0]);
          listlabel =
              dt1.dateString()
                  + ":"
                  + dt1.timeString()
                  + " and "
                  + dt.dateString()
                  + ":"
                  + dt.timeString();
        }

        updateDisplayList();
        updateHeaderLabel();
      }
    } catch (Exception ex) {
      logException("timeValueChanged", ex);
    }
  }
  /**
   * @param grid The grid.
   * @param gridWinds The grid-relative winds.
   * @param cs The coordinate system transformation of the grid.
   * @param index The index of the grid-relative wind component.
   * @param latI The index of latitude in the reference coordinate system.
   * @param lonI The index of longitude in the reference coordinate system.
   * @param us The array in which to add the computed U-component of the wind.
   * @param us The array in which to add the computed V-component of the wind.
   * @param vs
   * @throws IndexOutOfBoundsException if <code>gridWinds</code>, <code>us
   *                                   </code>, or <code>vs</code> is too small.
   * @throws VisADException if a VisAD failure occurs.
   */
  private static void addComponent(
      SampledSet grid,
      float[][] gridWinds,
      CoordinateSystem cs,
      int index,
      int latI,
      int lonI,
      float[] us,
      float[] vs)
      throws VisADException {

    int[][] neighbors = grid.getNeighbors(index);
    LatLonPointImpl refPt = new LatLonPointImpl();
    LatLonPointImpl neiPt = new LatLonPointImpl();
    Bearing bearing = new Bearing();
    float[] uv1 = new float[2];
    float[] uv2 = new float[2];
    boolean hasCS = cs != null;
    float[][] domainSamples = grid.getSamples(false);
    float[][] crefCoords = (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
        || (crefCoords == domainSamples)
        || (Arrays.equals(crefCoords[latI], domainSamples[latI])
            && Arrays.equals(crefCoords[lonI], domainSamples[lonI]))) {
      // us = gridWinds[0];
      // vs = gridWinds[1];
      System.arraycopy(gridWinds[0], 0, us, 0, us.length);
      System.arraycopy(gridWinds[1], 0, vs, 0, vs.length);
    } else {

      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,
            gridWinds[index][i],
            bearing,
            uv1);

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

        compute(
            refPt,
            neiPt,
            neiCoords[latI][1],
            neiCoords[lonI][1],
            0,
            gridWinds[index][i],
            bearing,
            uv2);

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

        if (bad1 && bad2) {
          us[i] = Float.NaN;
          vs[i] = Float.NaN;
        } else {
          if (bad1) {
            us[i] += uv2[0];
            vs[i] += uv2[1];
          } else if (bad2) {
            us[i] += uv1[0];
            vs[i] += uv1[1];
          } else {
            float tot = d1 + d2;
            float c1 = d2 / tot;
            float c2 = d1 / tot;

            us[i] += c1 * uv1[0] + c2 * uv2[0];
            vs[i] += c1 * uv1[1] + c2 * uv2[1];
          }
        }
      }
    }
  }
  /**
   * 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;
  }
  /**
   * Converts a time-series of grid-relative winds to a time-series of true (or absolute) winds. The
   * U and V components of true wind are {@link WesterlyWind} and {@link SoutherlyWind},
   * respectively. The domain of the input {@link visad.Field} must be a temporal {@link
   * visad.Gridded1DSet} or a {@link visad.SingletonSet}. The range values of the input {@link
   * visad.Field} must be {@link visad.FlatField}s. The domains of the range {@link
   * visad.FlatField}s must have a manifold dimension of two or greater and they 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 {@link
   * visad.FlatField}s 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
   * domains of the {@link visad.FlatField}s must be equal. The {@link visad.Field} returned by this
   * method has the same domain as the input {@link visad.Field}. The range values of the returned
   * {@link visad.Field} are {@link visad.FlatField}s that have the same domain as the input {@link
   * visad.FlatField}s. The {@link visad.MathType} of the range of the returned {@link
   * visad.FlatField}s will be <code>CartesianHorizontalWind.getEarthVectorType()</code>.
   *
   * @param rel The time-series of grid-relative wind.
   * @return The time-series of true wind corresponding to the input.
   * @throws NullPointerException if <code>rel</code> is <code>null</code>.
   * @throws IllegalArgumentException if the input field doesn't have a time-series domain, or if
   *     the range values aren't {@link visad.FlatField} with the same domain, or if the domain of
   *     the {@link visad.FlatField}s doesn't have a transformation to latitude and longitude, or if
   *     the domain is irregular or has too few points, or if the {@link visad.FlatField}s don't
   *     have two and only two components in their range, or if the default units of the {@link
   *     visad.FlatField}s range aren't equal.
   * @throws VisADException if a VisAD failure occurs.
   * @throws RemoteException if a Java RMI failure occurs.
   * @see CartesianHorizontalWind
   */
  public static Field timeSeriesCartesianHorizontalWind(Field rel)
      throws VisADException, RemoteException {

    FunctionType outerFuncType = (FunctionType) rel.getType();
    RealTupleType outerDomType = outerFuncType.getDomain();

    if (!(RealType.Time.equalsExceptNameButUnits(outerDomType)
        || !RealType.TimeInterval.equalsExceptNameButUnits(outerDomType))) {
      throw new IllegalArgumentException(outerDomType.toString());
    }

    MathType innerFuncType = outerFuncType.getRange();

    if (!(innerFuncType instanceof FunctionType)) {
      throw new IllegalArgumentException(innerFuncType.toString());
    }

    Field innerField = (Field) rel.getSample(0);
    Set innerDom = innerField.getDomainSet();
    if (innerDom instanceof SingletonSet) {
      return rel;
    } else if (innerDom instanceof GriddedSet) {
      int[] lengths = ((GriddedSet) innerDom).getLengths();
      if ((lengths[0] == 1) && (lengths[1] == 1)) {
        return rel;
      }
    }

    // account for null units, assume m/sec
    Unit[] rangeUnits = innerField.getDefaultRangeUnits();
    if ((rangeUnits == null) || (rangeUnits[0] == null) || rangeUnits[0].isDimensionless()) {
      rangeUnits = CartesianHorizontalWind.getEarthVectorType().getDefaultUnits();
    }
    FunctionType innerType =
        new FunctionType(
            ((SetType) innerDom.getType()).getDomain(),
            CartesianHorizontalWind.getEarthVectorType());

    FlatField uvField =
        new FlatField(innerType, innerDom, (CoordinateSystem) null, (Set[]) null, rangeUnits);

    Field result =
        new FieldImpl(new FunctionType(outerDomType, uvField.getType()), rel.getDomainSet());

    // System.out.println("making rHatField");
    Field rHatField = (doNewCode ? hatFieldNew(innerDom, 0) : hatFieldOld(innerDom, 0));
    // System.out.println("making sHatField");
    Field sHatField = (doNewCode ? hatFieldNew(innerDom, 1) : hatFieldOld(innerDom, 1));

    float[][] rHats = rHatField.getFloats(false);
    // ucar.unidata.util.Misc.printArray("rHats[0]", rHats[0]);
    // ucar.unidata.util.Misc.printArray("rHats[1]", rHats[1]);
    // System.out.println("\n");
    float[][] sHats = sHatField.getFloats(false);
    // ucar.unidata.util.Misc.printArray("sHats[0]", sHats[0]);
    // ucar.unidata.util.Misc.printArray("sHats[1]", sHats[1]);
    // System.out.println("\n");
    float[] us = new float[innerDom.getLength()];
    float[] vs = new float[us.length];

    for (int i = 0, n = rel.getLength(); i < n; i++) {
      if (i > 0) {
        innerField = (Field) rel.getSample(i);
        Set dom = innerField.getDomainSet();
        if (!innerDom.equals(dom)) {
          // System.out.println("new domain");
          innerDom = dom;
          rHatField = (doNewCode ? hatFieldNew(innerDom, 0) : hatFieldOld(innerDom, 0));
          sHatField = (doNewCode ? hatFieldNew(innerDom, 1) : hatFieldOld(innerDom, 1));

          rHats = rHatField.getFloats(false);
          sHats = sHatField.getFloats(false);
          /*
          throw new IllegalArgumentException("template="
                  + innerDom.toString() + "; domain="
                  + dom.toString());
          */
        }
        uvField =
            new FlatField(innerType, innerDom, (CoordinateSystem) null, (Set[]) null, rangeUnits);
        us = new float[innerDom.getLength()];
        vs = new float[us.length];
      }

      float[][] rsWinds = innerField.getFloats(false);
      float[] rWinds = rsWinds[0];
      float[] sWinds = rsWinds[1];
      // ucar.unidata.util.Misc.printArray("rWinds", rWinds);
      // System.out.println("\n");
      // ucar.unidata.util.Misc.printArray("sWinds", sWinds);
      // System.out.println("\n");

      for (int j = 0; j < us.length; j++) {
        us[j] = rWinds[j] * rHats[0][j] + sWinds[j] * sHats[0][j];
        vs[j] = rWinds[j] * rHats[1][j] + sWinds[j] * sHats[1][j];
      }
      // ucar.unidata.util.Misc.printArray("us", us);
      // System.out.println("\n");
      // ucar.unidata.util.Misc.printArray("vs", vs);
      // System.out.println("\n");

      uvField.setSamples(new float[][] {us, vs}, false);
      result.setSample(i, uvField, false);
    }

    return result;
  }
Example #12
0
  /**
   * Computes the output Level of Free Convection (LFC) from an (AirPressure -> MassicVolume)
   * buoyancy profile.
   *
   * @param datums The input data in the same order as during construction: <code>datums[0]
   *                                  </code> is the input buoyancy profile.
   * @return The pressure at the LFC of the buoyancy profile.
   * @throws ClassCastException if an input data reference has the wrong type of data object.
   * @throws TypeException if a VisAD data object has the wrong type.
   * @throws VisADException if a VisAD failure occurs.
   * @throws RemoteException if a Java RMI failure occurs.
   * @throws IllegalArgumentException if the profile is not ascending.
   */
  protected Data compute(Data[] datums) throws TypeException, VisADException, RemoteException {

    Field buoyProfile = (Field) datums[0];
    Real lfc = noData; // default return value

    if (buoyProfile != null) {
      FunctionType funcType = (FunctionType) buoyProfile.getType();
      RealTupleType domainType = funcType.getDomain();

      if (!Pressure.getRealType().equalsExceptNameButUnits(domainType)) {
        throw new TypeException(domainType.toString());
      }

      MathType rangeType = funcType.getRange();

      Util.vetType(MassicVolume.getRealType(), buoyProfile);

      Set domainSet = buoyProfile.getDomainSet();
      double[] pressures = domainSet.getDoubles()[0];
      float[] buoys = buoyProfile.getFloats()[0];

      if (pressures.length > 1) {
        int lastI = pressures.length - 1;
        boolean ascending = pressures[0] >= pressures[lastI];

        Unit presUnit = domainSet.getSetUnits()[0];
        int i;

        if (ascending) {
          /*
           * For a level of free convection to exist, the lower
           * buoyancy must be negative.
           */
          for (i = 0; (i < buoys.length) && (buoys[i] >= 0); i++) ;

          /*
           * To find the level of free convection, ascend to
           * positive buoyancy.
           */
          while ((++i < buoys.length) && (buoys[i] <= 0)) ;

          if (i < buoys.length) {
            lfc = interpolatePres(pressures[i], buoys[i], pressures[i - 1], buoys[i - 1], presUnit);
          }
        } else {
          /*
           * For a level of free convection to exist, the lower
           * buoyancy must be negative.
           */
          for (i = lastI; (i >= 0) && (buoys[i] >= 0); i--) ;

          /*
           * To find the level of free convection, ascend to
           * positive buoyancy.
           */
          while ((--i >= 0) && (buoys[i] <= 0)) ;

          if (i >= 0) {
            lfc = interpolatePres(pressures[i], buoys[i], pressures[i + 1], buoys[i + 1], presUnit);
          }
        }
      }
    }

    return lfc;
  }
Example #13
0
  /**
   * Computes the output property. A {@link java.beans.PropertyChangeEvent} is fired for the output
   * property if it differs from the previous value.
   *
   * @throws VisADException if a VisAD failure occurs.
   * @throws RemoteException if a Java RMI exception occurs.
   */
  void clock() throws VisADException, RemoteException {

    Set domainSet = buoyProfile.getDomainSet();
    Real oldLfc;
    Real newLfc;
    double[] pressures = domainSet.getDoubles()[0];
    float[] buoys = buoyProfile.getFloats()[0];

    /* Eliminate non-finite pressures and buoyancies. */
    int n = 0;

    for (int i = 0; i < pressures.length; i++) {
      if ((pressures[i] != pressures[i]) || (buoys[i] != buoys[i])) {
        n++;
      }
    }

    if (n > 0) {
      double[] tmpPres = new double[pressures.length - n];
      float[] tmpBuoy = new float[tmpPres.length];

      n = 0;

      for (int i = 0; i < pressures.length; i++) {
        if ((pressures[i] != pressures[i]) || (buoys[i] != buoys[i])) {
          continue;
        }

        tmpPres[n] = pressures[i];
        tmpBuoy[n] = buoys[i];

        n++;
      }

      pressures = tmpPres;
      buoys = tmpBuoy;
    }

    if (pressures.length <= 1) {
      newLfc = missingLfc;
    } else {
      Unit presUnit = domainSet.getSetUnits()[0];
      boolean ascending = pressures[0] > pressures[1];

      if (!ascending) {

        /*
         * The profile is descending.  Make the temporary value arrays
         * ascending.
         */
        for (int i = 0, j = pressures.length; i < pressures.length / 2; i++) {
          --j;

          double pres = pressures[i];

          pressures[i] = pressures[j];
          pressures[j] = pres;

          float buoy = buoys[i];

          buoys[i] = buoys[j];
          buoys[j] = buoy;
        }
      }

      /*
       * Descend from the top to positive buoyancy.
       */
      int i = buoys.length;

      while ((--i >= 0) && (buoys[i] <= 0)) ;

      if (i < 0) {

        /*
         * There is no positively buoyant region.
         */
        newLfc = missingLfc;
      } else {

        /*
         * Descend to first non-positive buoyant region.
         */
        while ((--i >= 0) && (buoys[i] > 0)) ;

        if (i < 0) {

          /*
           * There is no non-positive buoyant region.
           */
          newLfc = missingLfc;
        } else {

          /*
           * Interpolate the LFC.
           */
          double pressure =
              pressures[i + 1]
                  / Math.exp(
                      buoys[i + 1]
                          * (Math.log(pressures[i] / pressures[i + 1])
                              / (buoys[i] - buoys[i + 1])));

          newLfc = new Real((RealType) missingLfc.getType(), pressure, presUnit);
        }
      }
    }

    synchronized (this) {
      oldLfc = lfc;
      lfc = newLfc;
    }

    firePropertyChange(OUTPUT_PROPERTY_NAME, oldLfc, newLfc);
  }
  /**
   * run 'java visad.bom.ImageRendererJ3D len step' to test animation behavior of ImageRendererJ3D
   * renders a loop of len at step ms per frame then updates loop by deleting first time and adding
   * a new last time
   */
  public static void main(String args[]) throws VisADException, RemoteException, IOException {

    int step = 1000;
    int len = 3;
    if (args.length > 0) {
      try {
        len = Integer.parseInt(args[0]);
      } catch (NumberFormatException e) {
        len = 3;
      }
    }
    if (len < 1) len = 1;
    if (args.length > 1) {
      try {
        step = Integer.parseInt(args[1]);
      } catch (NumberFormatException e) {
        step = 1000;
      }
    }
    if (step < 1) step = 1;

    // create a netCDF reader
    Plain plain = new Plain();

    // open a netCDF file containing an image sequence and adapt
    // it to a Field Data object
    Field raw_image_sequence = null;
    try {
      // raw_image_sequence = (Field) plain.open("images256x256.nc");
      raw_image_sequence = (Field) plain.open("images.nc");
    } catch (IOException exc) {
      String s =
          "To run this example, the images.nc file must be "
              + "present in\nthe current directory."
              + "You can obtain this file from:\n"
              + "  ftp://www.ssec.wisc.edu/pub/visad-2.0/images.nc.Z";
      System.out.println(s);
      System.exit(0);
    }

    // just take first half of raw_image_sequence
    FunctionType image_sequence_type = (FunctionType) raw_image_sequence.getType();
    Set raw_set = raw_image_sequence.getDomainSet();
    float[][] raw_times = raw_set.getSamples();
    int raw_len = raw_times[0].length;
    if (raw_len != 4) {
      throw new VisADException("wrong number of images in sequence");
    }
    float raw_span = (4.0f / 3.0f) * (raw_times[0][3] - raw_times[0][0]);

    double[][] times = new double[1][len];
    for (int i = 0; i < len; i++) {
      times[0][i] = raw_times[0][i % raw_len] + raw_span * (i / raw_len);
    }
    Gridded1DDoubleSet set = new Gridded1DDoubleSet(raw_set.getType(), times, len);
    Field image_sequence = new FieldImpl(image_sequence_type, set);
    for (int i = 0; i < len; i++) {
      image_sequence.setSample(i, raw_image_sequence.getSample(i % raw_len));
    }

    // create a DataReference for image sequence
    final DataReference image_ref = new DataReferenceImpl("image");
    image_ref.setData(image_sequence);

    // create a Display using Java3D
    DisplayImpl display = new DisplayImplJ3D("image display");

    // extract the type of image and use
    // it to determine how images are displayed
    FunctionType image_type = (FunctionType) image_sequence_type.getRange();
    RealTupleType domain_type = image_type.getDomain();
    // map image coordinates to display coordinates
    display.addMap(new ScalarMap((RealType) domain_type.getComponent(0), Display.XAxis));
    display.addMap(new ScalarMap((RealType) domain_type.getComponent(1), Display.YAxis));
    // map image brightness values to RGB (default is grey scale)
    display.addMap(new ScalarMap((RealType) image_type.getRange(), Display.RGB));
    RealType hour_type = (RealType) image_sequence_type.getDomain().getComponent(0);
    ScalarMap animation_map = new ScalarMap(hour_type, Display.Animation);
    display.addMap(animation_map);
    AnimationControl animation_control = (AnimationControl) animation_map.getControl();
    animation_control.setStep(step);
    animation_control.setOn(true);

    /*
        // link the Display to image_ref
        ImageRendererJ3D renderer = new ImageRendererJ3D();
        display.addReferences(renderer, image_ref);
        // display.addReference(image_ref);
    */

    // create JFrame (i.e., a window) for display and slider
    JFrame frame = new JFrame("ImageRendererJ3D test");
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    // create JPanel in JFrame
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setAlignmentY(JPanel.TOP_ALIGNMENT);
    panel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
    frame.getContentPane().add(panel);

    // add display to JPanel
    panel.add(display.getComponent());

    // set size of JFrame and make it visible
    frame.setSize(500, 500);
    frame.setVisible(true);

    System.out.println("first animation sequence");
    // link the Display to image_ref
    ImageRendererJ3D renderer = new ImageRendererJ3D();
    display.addReferences(renderer, image_ref);
    // display.addReference(image_ref);

    // wait 4 * len seconds
    new Delay(len * 4000);

    // substitute a new image sequence for the old one
    for (int i = 0; i < len; i++) {
      times[0][i] = raw_times[0][(i + 1) % raw_len] + raw_span * ((i + 1) / raw_len);
    }
    set = new Gridded1DDoubleSet(raw_set.getType(), times, len);
    FieldImpl new_image_sequence = new FieldImpl(image_sequence_type, set);
    for (int i = 0; i < len; i++) {
      new_image_sequence.setSample(i, raw_image_sequence.getSample((i + 1) % raw_len));
    }

    System.out.println("second animation sequence");

    // tell renderer to resue frames in its scene graph
    renderer.setReUseFrames(true);
    image_ref.setData(new_image_sequence);
  }