Пример #1
0
  /**
   * add to properties
   *
   * @param comps comps
   */
  public void getPropertiesComponents(List comps) {
    super.getPropertiesComponents(comps);
    binWidthField = new TimeLengthField("Bin Width", true);
    binRoundToField = new TimeLengthField("Bin Round To", true);
    binWidthField.setTime(binWidth);
    binRoundToField.setTime(binRoundTo);
    List roundToItems =
        Misc.toList(
            new Object[] {
              new TwoFacedObject("Change", new Double(0)),
              new TwoFacedObject("On the hour", new Double(60)),
              new TwoFacedObject("5 after", new Double(5)),
              new TwoFacedObject("10 after", new Double(10)),
              new TwoFacedObject("15 after", new Double(15)),
              new TwoFacedObject("20 after", new Double(20)),
              new TwoFacedObject("30 after", new Double(30)),
              new TwoFacedObject("45 after", new Double(45)),
              new TwoFacedObject("10 to", new Double(50)),
              new TwoFacedObject("5 to", new Double(55))
            });

    roundToCbx =
        GuiUtils.makeComboBox(
            roundToItems, roundToItems.get(0), false, this, "setRoundToFromComboBox");

    List widthItems =
        Misc.toList(
            new Object[] {
              new TwoFacedObject("Change", new Double(0)),
              new TwoFacedObject("5 minutes", new Double(5)),
              new TwoFacedObject("10 minutes", new Double(10)),
              new TwoFacedObject("15 minutes", new Double(15)),
              new TwoFacedObject("20 minutes", new Double(20)),
              new TwoFacedObject("30 minutes", new Double(30)),
              new TwoFacedObject("45 minutes", new Double(45)),
              new TwoFacedObject("1 hour", new Double(60)),
              new TwoFacedObject("6 hours", new Double(60 * 6)),
              new TwoFacedObject("12 hours", new Double(60 * 12)),
              new TwoFacedObject("1 day", new Double(60 * 24))
            });

    widthCbx =
        GuiUtils.makeComboBox(widthItems, widthItems.get(0), false, this, "setWidthFromComboBox");

    comps.add(GuiUtils.filler());
    comps.add(getPropertiesHeader("Time Binning"));

    comps.add(GuiUtils.rLabel("Bin Size:"));
    comps.add(GuiUtils.left(GuiUtils.hbox(binWidthField.getContents(), widthCbx, 5)));
    comps.add(GuiUtils.rLabel("Round To:"));
    comps.add(GuiUtils.left(GuiUtils.hbox(binRoundToField.getContents(), roundToCbx, 5)));
  }
Пример #2
0
  /** _more_ */
  private void getSelectedTimes() {
    if (isHourly()) {
      Object[] selects = chartTimeBox.getSelectedValues();
      if (forecastHours == null) {
        forecastHours = new ArrayList();
      }
      for (int i = 0; i < selects.length; i++) {
        Object select = selects[i];
        TwoFacedObject tfo = (TwoFacedObject) select;
        Integer hour = (Integer) tfo.getId();
        forecastHours.add(hour);
      }

    } else {
      forecastTimes = (List<DateTime>) Misc.toList(chartTimeBox.getSelectedValues());
    }
  }
Пример #3
0
  /**
   * Make a dataset with the file
   *
   * @return dataset
   */
  private RaobDataSet doMakeRaobDataSet() {
    SoundingAdapter adapter = null;
    try {
      adapter = new NetcdfSoundingAdapter(file);
    } catch (Exception ill) {
    }

    if (adapter == null) {
      try {
        adapter = new CMASoundingAdapter(file);
      } catch (Exception exc) {
        LogUtil.logException("Reading sounding:" + file, exc);
        return null;
      }
    }

    if (adapter == null) {
      throw new IllegalArgumentException("Could not open sounding file:" + file);
    }

    SoundingOb[] obs = adapter.getSoundingObs();
    return new RaobDataSet(adapter, Misc.toList(obs));
  }
Пример #4
0
  /** _more_ */
  protected void updateChart() {

    try {
      if (!madeChart) {
        createChart();
      }
      ignoreChartTimeChanges = true;

      if (isHourly()) {
        List<Integer> fHours = findForecastHours();
        List<TwoFacedObject> tfos = new ArrayList<TwoFacedObject>();
        for (Integer i : fHours) {
          tfos.add(new TwoFacedObject(i + "H", i));
        }

        Object[] selected = chartTimeBox.getSelectedValues();
        chartTimeBox.setListData(new Vector(tfos));
        GuiUtils.setSelectedItems(chartTimeBox, Misc.toList(selected));

        if ((selected == null) && (tfos.size() > 0)) {
          TwoFacedObject selected0 = tfos.get(0);
          forecastHours.add((Integer) selected0.getId());
        }

        // chartTimeBox.setSelectedItem(selected);
      } else {
        List<DateTime> fTimes = findForecastTimes();

        Object[] selected = chartTimeBox.getSelectedValues();

        chartTimeBox.setListData(new Vector(fTimes));
        GuiUtils.setSelectedItems(chartTimeBox, Misc.toList(selected));

        if ((selected == null) && (fTimes.size() > 0)) {
          DateTime dt0 = fTimes.get(0);
          forecastTimes.add(dt0);
        }

        // chartTimeBox.setSelectedItem(forecastTime);
      }
      ignoreChartTimeChanges = false;
      getSelectedTimes();
      chartTimeBox.repaint();
      Hashtable<Way, List> wayToTracks = new Hashtable<Way, List>();
      for (Way way : chartWays) {
        wayToTracks.put(way, new ArrayList<Way>());
      }

      List<StormTrack> tracksToUse = new ArrayList<StormTrack>();
      for (StormTrack track : stormDisplayState.getTrackCollection().getTracks()) {
        List trackList = wayToTracks.get(track.getWay());
        if (trackList == null) {
          continue;
        }
        if (track.getWay().isObservation()) {
          tracksToUse.add(track);
        } else {
          trackList.add(track);
        }
      }

      StormTrack obsTrack = stormDisplayState.getTrackCollection().getObsTrack();

      if (isHourly()) {
        for (Way way : chartWays) {
          List<StormTrack> tracksFromWay = wayToTracks.get(way);

          for (Integer fHour : forecastHours) {
            List<StormTrackPoint> points = new ArrayList<StormTrackPoint>();
            for (StormTrack track : tracksFromWay) {
              StormTrackPoint stp = track.findPointWithForecastHour(fHour.intValue());
              if (stp != null) {
                // TODO: What time do we use???
                points.add(stp);
              }
            }
            if (points.size() > 0) {
              points = (List<StormTrackPoint>) Misc.sort(points);
              tracksToUse.add(new StormTrack(stormDisplayState.getStormInfo(), way, points, null));
            }
          }
        }

      } else {
        for (Way way : chartWays) {
          List<StormTrack> tracksFromWay = wayToTracks.get(way);
          for (StormTrack track : tracksFromWay) {
            for (DateTime fTime : forecastTimes) {
              if (Misc.equals(fTime, track.getStartTime())) {
                tracksToUse.add(track);
              }
            }
          }
        }
      }

      List<LineState> lines = new ArrayList<LineState>();

      for (StormParam param : chartParams) {
        Hashtable seenWays = new Hashtable();
        List<LineState> linesForParam = new ArrayList<LineState>();
        for (StormTrack track : tracksToUse) {
          LineState lineState = null;
          if (chartDifference && param.getCanDoDifference()) {
            if (track.getWay().isObservation()) {
              continue;
            }
            track = StormDataSource.difference(obsTrack, track, param);
            if (track != null) {
              lineState = makeLine(track, param);
            }
          } else {
            lineState = makeLine(track, param);
          }
          if (lineState == null) {
            continue;
          }
          // Only add it if there are values
          if (lineState.getRange().getMin() == lineState.getRange().getMin()) {
            if (seenWays.get(track.getWay()) != null) {
              lineState.setVisibleInLegend(false);
            } else {
              seenWays.put(track.getWay(), "");
            }

            linesForParam.add(lineState);
          }
        }
        double max = Double.NEGATIVE_INFINITY;
        double min = Double.POSITIVE_INFINITY;
        ;
        for (LineState lineState : linesForParam) {
          Range r = lineState.getRange();
          min = Math.min(min, r.getMin());
          max = Math.max(max, r.getMax());
        }
        //                System.err.println(param + " min/max:" + min + "/" + max);
        boolean first = true;
        for (LineState lineState : linesForParam) {
          lineState.setAxisVisible(first);
          first = false;
          lineState.setRange(new Range(min, max));
        }
        lines.addAll(linesForParam);
      }
      getChart().setTracks(lines);
    } catch (Exception exc) {
      stormDisplayState.getStormTrackControl().logException("Updating chart", exc);
    }
  }
Пример #5
0
 /**
  * Return the list of color names. This is used in comboboxes to choose a color.
  *
  * @return List of color names
  */
 public Vector getColorNameList() {
   return new Vector(Misc.toList(GuiUtils.COLORNAMES));
 }
Пример #6
0
 /**
  * Create a PointDataSource
  *
  * @param descriptor descriptor for the DataSource
  * @param source file location or URL
  * @param description description of data
  * @param properties extra properties
  * @throws VisADException
  */
 public PointDataSource(
     DataSourceDescriptor descriptor, String source, String description, Hashtable properties)
     throws VisADException {
   this(descriptor, Misc.toList(new String[] {source}), description, properties);
 }
Пример #7
0
 /**
  * Set the source property (filename or URL). Used by persistence
  *
  * @param value data source
  */
 public void setSource(String value) {
   setSources(Misc.toList(new String[] {value}));
 }
Пример #8
0
  /**
   * Get the data represented by this class. Calls makeObs, real work needs to be implemented there.
   *
   * @param dataChoice choice for data
   * @param category category of data
   * @param dataSelection subselection properties
   * @param requestProperties additional selection properties (not used here)
   * @return Data object representative of the choice
   * @throws RemoteException Java RMI error
   * @throws VisADException VisAD Error
   */
  protected Data getDataInner(
      DataChoice dataChoice,
      DataCategory category,
      DataSelection dataSelection,
      Hashtable requestProperties)
      throws VisADException, RemoteException {

    Object id = dataChoice.getId();
    // CompositeDataChoice

    // If it is a list then we are doing a grid field
    boolean doGriddedData = false;
    if (id instanceof List) {
      if (((List) id).get(0) instanceof Integer) {
        doGriddedData = true;
      }
    }
    if (doGriddedData) {
      List idList = (List) id;
      //            Integer   i          = (Integer) idList.get(0);
      RealType type = (RealType) idList.get(1);
      Hashtable properties = dataChoice.getProperties();
      if (properties == null) {
        properties = new Hashtable();
      }

      Data firstGuessData = null;
      boolean doFirstGuessField = false;
      if (idList.size() > 2) {
        doFirstGuessField = ((Boolean) idList.get(2)).booleanValue();
      }

      if (doFirstGuessField) {
        DataChoice firstGuessDataChoice = (DataChoice) dataChoice.getProperty(PROP_FIRSTGUESS);
        if (firstGuessDataChoice == null) {
          List operands = new ArrayList();
          List categories = DataCategory.parseCategories("GRID-2D-TIME;GRID-3D-TIME", false);
          operands.add(
              new DataOperand("First Guess Field", "First Guess Field", categories, false));
          List userValues = getDataContext().selectDataChoices(operands);
          if (userValues == null) {
            return null;
          }

          firstGuessDataChoice = (DataChoice) userValues.get(0);
          dataChoice.setObjectProperty(PROP_FIRSTGUESS, firstGuessDataChoice);
        }

        if (firstGuessDataChoice != null) {
          firstGuessData = firstGuessDataChoice.getData(null);
          if (firstGuessData == null) {
            return null;
          }
        }
      }

      // Merge the point obs
      properties.put(PROP_GRID_PARAM, type);
      FieldImpl pointObs = null;
      List datas = new ArrayList();
      for (int i = 0; i < sources.size(); i++) {
        DataChoice choice =
            new DirectDataChoice(
                this, new Integer(i), "", "", dataChoice.getCategories(), properties);
        pointObs = (FieldImpl) getDataInner(choice, category, dataSelection, requestProperties);
        if (pointObs != null) {
          datas.add(pointObs);
        }
      }
      if (datas.size() == 0) {
        return null;
      }
      pointObs = PointObFactory.mergeData(datas);
      if (pointObs == null) {
        return null;
      }

      // { minY, minX, maxY, maxX };
      float spacingX = this.gridX;
      float spacingY = this.gridY;
      int passes = this.numGridPasses;
      float gain = this.gridGain;
      float searchRadius = this.gridSearchRadius;
      Number tmp;
      tmp = (Float) dataSelection.getProperty(PROP_GRID_X);
      if (tmp != null) {
        spacingX = tmp.floatValue();
      }
      tmp = (Float) dataSelection.getProperty(PROP_GRID_Y);
      if (tmp != null) {
        spacingY = tmp.floatValue();
      }
      tmp = (Integer) dataSelection.getProperty(PROP_GRID_NUMPASSES);
      if (tmp != null) {
        passes = tmp.intValue();
      }
      String theUnit = (String) dataSelection.getProperty(PROP_GRID_UNIT);
      if (theUnit == null) {
        theUnit = this.gridUnit;
      }
      tmp = (Float) dataSelection.getProperty(PROP_GRID_GAIN);
      if (tmp != null) {
        gain = tmp.floatValue();
      }
      tmp = (Float) dataSelection.getProperty(PROP_GRID_SEARCH_RADIUS);
      if (tmp != null) {
        searchRadius = tmp.floatValue();
      }

      float degreesX = 0, degreesY = 0;
      pointObs = PointObFactory.makeTimeSequenceOfPointObs(pointObs);
      if (theUnit.equals(SPACING_COMPUTE) || (spacingX <= 0) || (spacingY <= 0)) {
        degreesX = PointObFactory.OA_GRID_DEFAULT;
        degreesY = PointObFactory.OA_GRID_DEFAULT;
        if ((searchRadius == DEFAULT_RADIUS) && (firstGuessData == null)) {
          searchRadius = PointObFactory.OA_GRID_DEFAULT;
        }
      } else if (theUnit.equals(SPACING_POINTS)) {
        double[] bbox = PointObFactory.getBoundingBox(pointObs);
        float spanX = (float) Math.abs(bbox[1] - bbox[3]);
        float spanY = (float) Math.abs(bbox[0] - bbox[2]);
        degreesX = spanX / (int) spacingX;
        degreesY = spanY / (int) spacingY;
      } else if (theUnit.equals(SPACING_DEGREES)) {
        degreesX = spacingX;
        degreesY = spacingY;
      }
      Barnes.AnalysisParameters ap =
          new Barnes.AnalysisParameters(degreesX, degreesY, searchRadius, 0.0d);
      log_.debug(
          "X = "
              + degreesX
              + " Y = "
              + degreesY
              + " unit = "
              + theUnit
              + " gain = "
              + gain
              + " search = "
              + searchRadius);

      LogUtil.message("Doing Barnes Analysis");
      FieldImpl fi =
          PointObFactory.barnes(
              pointObs,
              type,
              degreesX,
              degreesY,
              passes,
              gain,
              searchRadius,
              ap,
              (FieldImpl) firstGuessData);
      if (ap.getGridXArray() != null) {
        log_.debug(
            "Analysis params: X = "
                + ap.getGridXArray().length
                + " Y = "
                + ap.getGridYArray().length
                + " search = "
                + ap.getScaleLengthGU()
                + " random = "
                + ap.getRandomDataSpacing());
      }
      return fi;
    }

    GeoSelection geoSelection = ((dataSelection != null) ? dataSelection.getGeoSelection() : null);
    GeoLocationInfo bbox = ((geoSelection == null) ? null : geoSelection.getBoundingBox());

    LatLonRect llr = ((bbox != null) ? bbox.getLatLonRect() : null);

    FieldImpl retField = null;
    try {
      // List choices = (List) dataChoice.getId();
      List choices =
          (dataChoice instanceof CompositeDataChoice)
              ? ((CompositeDataChoice) dataChoice).getDataChoices()
              : Misc.toList(new DataChoice[] {dataChoice});
      List datas = new ArrayList(choices.size());
      for (int i = 0; i < choices.size(); i++) {
        DataChoice subDataChoice = (DataChoice) choices.get(i);
        FieldImpl obs = makeObs(subDataChoice, dataSelection, llr);
        if (obs == null) {
          continue;
        }

        //                if (true) {
        //                    return obs;
        //                }
        datas.add(obs);
        if (fieldsDescription == null) {
          makeFieldDescription(obs);
        }
      }
      if (datas.isEmpty()) {
        return null;
      }
      retField = PointObFactory.mergeData(datas);
    } catch (Exception exc) {
      logException("Creating obs", exc);
    }
    return retField;
  }