Пример #1
0
  /**
   * Create e field description from the field
   *
   * @param fi field to use
   */
  protected void makeFieldDescription(FieldImpl fi) {
    if (fi == null) {
      fieldsDescription = "Bad data: null";
      return;
    }
    try {
      if (ucar.unidata.data.grid.GridUtil.isTimeSequence(fi)) {
        fi = (FieldImpl) fi.getSample(0);
      }
      PointOb ob = (PointOb) fi.getSample(0);
      Tuple tuple = (Tuple) ob.getData();
      MathType[] comps = ((TupleType) tuple.getType()).getComponents();
      Trace.msg("PointDataSource #vars=" + comps.length);
      StringBuffer params = new StringBuffer(comps.length + " Fields:<ul>");
      String dataSourceName = getName();
      DataChoice.addCurrentName(new TwoFacedObject("Point Data>Time", "Time"));
      DataChoice.addCurrentName(new TwoFacedObject("Point Data>Latitude", "Latitude"));
      DataChoice.addCurrentName(new TwoFacedObject("Point Data>Altitude", "Altitude"));

      for (int i = 0; i < comps.length; i++) {
        params.append("<li>");
        String paramName = ucar.visad.Util.cleanTypeName(comps[i].toString());
        DataAlias alias = DataAlias.findAlias(paramName);
        params.append(paramName);
        if (alias != null) {
          params.append(" --  " + alias.getLabel());
          DataChoice.addCurrentName(
              new TwoFacedObject(
                  dataSourceName + ">" + alias.getLabel() + " -- " + paramName, paramName));
        } else {
          DataChoice.addCurrentName(
              new TwoFacedObject(dataSourceName + ">" + paramName, paramName));
        }
        Data data = tuple.getComponent(i);
        if (data instanceof Real) {
          Unit unit = ((Real) data).getUnit();
          if (unit != null) {
            params.append("  [" + unit.toString() + "]");
          }
        }
      }
      fieldsDescription = params.toString();
    } catch (Exception exc) {
      logException("getting description", exc);
    }
  }
Пример #2
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");
  }
Пример #3
0
  /** Make the <code>DataChoices</code> for this <code>DataSource</code>. */
  public void doMakeDataChoices() {

    if (sources == null) {
      return;
    }
    String stationModelName = (String) getProperty(PROP_STATIONMODELNAME);
    Hashtable properties =
        Misc.newHashtable(DataChoice.PROP_ICON, "/auxdata/ui/icons/Placemark16.gif");
    if (stationModelName != null) {
      properties.put(PROP_STATIONMODELNAME, stationModelName);
    }
    if (!getDefaultLevels().isEmpty()) {
      properties.put(DataSelection.PROP_DEFAULT_LEVELS, getDefaultLevels());
    }
    DataChoice uberChoice = null;
    /*  Might want to do this someday
    uberChoice = new DirectDataChoice(this,
                                        sources, getName(),
                                        getDataName(),
                                        getPointCategories(),
                                        properties);
    */

    if (sources.size() > 1) {
      uberChoice =
          new CompositeDataChoice(
              this, sources, getName(), getDataName(), getPointCategories(), properties);
      addDataChoice(uberChoice);
    }

    for (int i = 0; i < sources.size(); i++) {
      String dataChoiceDesc = getDescription();
      String dataChoiceName = getDataName();
      if (uberChoice != null) {
        dataChoiceDesc = IOUtil.getFileTail(sources.get(i).toString());
        dataChoiceName = IOUtil.getFileTail(sources.get(i).toString());
      }

      DataChoice choice =
          new DirectDataChoice(
              this,
              new Integer(i),
              dataChoiceDesc,
              dataChoiceName,
              getPointCategories(),
              properties);

      /*
      We'd like to create sub choices for each parameter but we don't really
      know the parameters until we read the data and that can be expensive
                  DirectDataChoice subChoice = new DirectDataChoice(this,
                            (String) sources.get(i),
                            getDescription(), getDataName(),
                            getPointCategories(), properties);
                            choice.addDataChoice(subChoice);*/

      if (uberChoice != null) {
        ((CompositeDataChoice) uberChoice).addDataChoice(choice);
      } else {
        addDataChoice(choice);
      }
      // Only add the grid data choices for the first source
      if (i > 0) {
        continue;
      }
      try {
        FieldImpl sample = (makeGridFields ? getSample(choice) : null);
        if (sample != null) {
          for (int dataChoiceType = 0; dataChoiceType < 2; dataChoiceType++) {
            Hashtable seenFields = new Hashtable();
            if (ucar.unidata.data.grid.GridUtil.isTimeSequence(sample)) {
              sample = (FieldImpl) sample.getSample(0);
            }
            PointOb ob = (PointOb) sample.getSample(0);
            Tuple tuple = (Tuple) ob.getData();
            TupleType tupleType = (TupleType) tuple.getType();
            MathType[] types = tupleType.getComponents();
            CompositeDataChoice compositeDataChoice = null;
            for (int typeIdx = 0; typeIdx < types.length; typeIdx++) {
              if (!(types[typeIdx] instanceof RealType)) {
                continue;
              }
              RealType type = (RealType) types[typeIdx];
              if (!canCreateGrid(type)) {
                continue;
              }
              //                        List gridCategories =
              //                            DataCategory.parseCategories("OA Fields;GRID-2D-TIME;");
              List gridCategories = DataCategory.parseCategories("GRID-2D-TIME;", false);
              if (compositeDataChoice == null) {
                compositeDataChoice =
                    new CompositeDataChoice(
                        this,
                        "",
                        "Grid Fields from Objective Analysis",
                        "Gridded Fields " + ((dataChoiceType == 0) ? "" : "(with first guess)"),
                        Misc.newList(DataCategory.NONE_CATEGORY),
                        null);
                addDataChoice(compositeDataChoice);
              }
              String name = ucar.visad.Util.cleanTypeName(type.toString());
              if (seenFields.get(name) != null) {
                continue;
              }
              seenFields.put(name, name);
              List idList = Misc.newList(new Integer(i), type);
              if (dataChoiceType == 1) {
                idList.add(new Boolean(true));
              }
              DataChoice gridChoice =
                  new DirectDataChoice(this, idList, name, name, gridCategories, (Hashtable) null);
              compositeDataChoice.addDataChoice(gridChoice);
            }
          }
        }
      } catch (Exception exc) {
        throw new WrapperException("Making grid parameters", exc);
      }
      //            if(true) break;
    }
  }
Пример #4
0
  public static boolean isByRefUsable(DataDisplayLink link, ShadowType shadow)
      throws VisADException, RemoteException {
    ShadowFunctionOrSetType shadowType = (ShadowFunctionOrSetType) shadow.getAdaptedShadowType();
    CoordinateSystem dataCoordinateSystem = null;
    FlatField fltField = null;
    int num_images = 1;
    FieldImpl field = (FieldImpl) link.getData();
    if (!(field instanceof FlatField)) {
      num_images = field.getDomainSet().getLength();
      if (1
          == num_images) { // If there is a single image in the animation dont do anything, simply
                           // return true
        return true;
      }
      shadowType = (ShadowFunctionOrSetType) shadowType.getRange();
      fltField = (FlatField) field.getSample(0);
      dataCoordinateSystem = fltField.getDomainCoordinateSystem();
    } else {
      dataCoordinateSystem = ((FlatField) field).getDomainCoordinateSystem();
      return true;
    }

    // cs might be cached
    if (dataCoordinateSystem instanceof CachingCoordinateSystem) {
      dataCoordinateSystem =
          ((CachingCoordinateSystem) dataCoordinateSystem).getCachedCoordinateSystem();
    }

    ShadowRealType[] DomainComponents = shadowType.getDomainComponents();
    ShadowRealTupleType Domain = shadowType.getDomain();
    ShadowRealTupleType domain_reference = Domain.getReference();
    ShadowRealType[] DC = DomainComponents;

    if (domain_reference != null && domain_reference.getMappedDisplayScalar()) {
      DC = shadowType.getDomainReferenceComponents();
    }

    DisplayTupleType spatial_tuple = null;
    for (int i = 0; i < DC.length; i++) {
      java.util.Enumeration maps = DC[i].getSelectedMapVector().elements();
      ScalarMap map = (ScalarMap) maps.nextElement();
      DisplayRealType real = map.getDisplayScalar();
      spatial_tuple = real.getTuple();
    }

    CoordinateSystem coord = spatial_tuple.getCoordinateSystem();

    if (coord instanceof CachingCoordinateSystem) {
      coord = ((CachingCoordinateSystem) coord).getCachedCoordinateSystem();
    }

    boolean useLinearTexture = false;
    if (coord instanceof InverseLinearScaledCS) {
      InverseLinearScaledCS invCS = (InverseLinearScaledCS) coord;
      useLinearTexture = (invCS.getInvertedCoordinateSystem()).equals(dataCoordinateSystem);
    }

    /**
     * if useLinearTexture is true at this point, it's true for the first image of a sequence with
     * numimages > 1. We'll have to assume that byRef will apply until below is resolved.
     */

    /**
     * more consideration/work needed here. CoordinateSystems might be equal even if they aren't the
     * same transform (i,j) -> (lon,lat) if (!useLinearTexture) { //If DisplayCoordinateSystem !=
     * DataCoordinateSystem if (num_images > 1) { //Its an animation int lengths[] =
     * ((visad.GriddedSet) fltField.getDomainSet()).getLengths(); int data_width = lengths[0]; int
     * data_height = lengths[1]; for (int i = 1; i < num_images; i++) {//Playing safe: go down the
     * full sequence to find if the full set is Geostaionary or NOT FlatField ff = (FlatField)
     * field.getSample(i); //Quicker Approach would be to just compare only the first two images in
     * the sequence. But that may not be safe. CoordinateSystem dcs =
     * ff.getDomainCoordinateSystem(); // dcs might be cached if (dcs instanceof
     * CachingCoordinateSystem) { dcs = ((CachingCoordinateSystem) dcs).getCachedCoordinateSystem();
     * } int[] lens = ((visad.GriddedSet) ff.getDomainSet()).getLengths(); if (lens[0] != data_width
     * || lens[1] != data_height || ( (dcs != null) && (dataCoordinateSystem != null) &&
     * !dcs.equals(dataCoordinateSystem))) { useLinearTexture = false; break; } } } }
     */
    return useLinearTexture;
  }