示例#1
0
 private void computeChartDataIfPossible() {
   // need to do this later: all GUI events must be processed first in order to get the correct
   // state
   SwingUtilities.invokeLater(
       () -> {
         if (scatterPlotModel.pointDataSource != null
             && scatterPlotModel.dataField != null
             && scatterPlotModel.pointDataSource.getFeatureCollection() != null
             && scatterPlotModel.pointDataSource.getFeatureCollection().features() != null
             && scatterPlotModel.pointDataSource.getFeatureCollection().features().hasNext()
             && scatterPlotModel.pointDataSource.getFeatureCollection().features().next() != null
             && scatterPlotModel
                     .pointDataSource
                     .getFeatureCollection()
                     .features()
                     .next()
                     .getAttribute(scatterPlotModel.dataField.getLocalName())
                 != null
             && getRaster() != null) {
           compute(scatterPlotModel.useRoiMask ? scatterPlotModel.roiMask : null);
         } else {
           scatterpointsDataset.removeAllSeries();
           acceptableDeviationDataset.removeAllSeries();
           regressionDataset.removeAllSeries();
           getPlot().removeAnnotation(r2Annotation);
           computedDatas = null;
         }
       });
 }
示例#2
0
  @Override
  public void populate(XYPlot plot, AROTraceData analysis) {
    if (analysis != null) {
      gpsData.removeAllSeries();
      // create the GPS dataset...
      Map<GpsState, XYIntervalSeries> seriesMap =
          new EnumMap<GpsState, XYIntervalSeries>(GpsState.class);
      for (GpsState eventType : GpsState.values()) {
        XYIntervalSeries series = new XYIntervalSeries(eventType);
        seriesMap.put(eventType, series);
        gpsData.addSeries(series);
      }

      Iterator<GpsInfo> iter =
          analysis.getAnalyzerResult().getTraceresult().getGpsInfos().iterator();
      if (iter.hasNext()) {
        while (iter.hasNext()) {
          GpsInfo gpsEvent = iter.next();
          if (gpsEvent.getGpsState() != GpsState.GPS_DISABLED) {
            seriesMap
                .get(gpsEvent.getGpsState())
                .add(
                    gpsEvent.getBeginTimeStamp(),
                    gpsEvent.getBeginTimeStamp(),
                    gpsEvent.getEndTimeStamp(),
                    0.5,
                    0,
                    1);
          }
        }
      }

      XYItemRenderer renderer = plot.getRenderer();
      renderer.setSeriesPaint(gpsData.indexOf(GpsState.GPS_STANDBY), Color.YELLOW);
      renderer.setSeriesPaint(gpsData.indexOf(GpsState.GPS_ACTIVE), new Color(34, 177, 76));

      // Assign ToolTip to renderer
      renderer.setBaseToolTipGenerator(
          new XYToolTipGenerator() {
            @Override
            public String generateToolTip(XYDataset dataset, int series, int item) {
              GpsState eventType = (GpsState) gpsData.getSeries(series).getKey();
              return MessageFormat.format(
                  ResourceBundleHelper.getMessageString("gps.tooltip"),
                  dataset.getX(series, item),
                  ResourceBundleHelper.getEnumString(eventType));
            }
          });
    }
    plot.setDataset(gpsData);
  }
示例#3
0
 private void finishScalingUpdate(
     AxisRangeControl axisRangeControl, ValueAxis newAxis, ValueAxis oldAxis) {
   if (axisRangeControl.isAutoMinMax()) {
     newAxis.setAutoRange(false);
     acceptableDeviationDataset.removeAllSeries();
     regressionDataset.removeAllSeries();
     getPlot().removeAnnotation(r2Annotation);
     newAxis.setAutoRange(true);
     axisRangeControl.adjustComponents(newAxis, 3);
     newAxis.setAutoRange(false);
     computeRegressionAndAcceptableDeviationData();
   } else {
     newAxis.setAutoRange(false);
     newAxis.setRange(oldAxis.getRange());
   }
 }
示例#4
0
 private void computeRegressionAndAcceptableDeviationData() {
   acceptableDeviationDataset.removeAllSeries();
   regressionDataset.removeAllSeries();
   getPlot().removeAnnotation(r2Annotation);
   if (computedDatas != null) {
     final ValueAxis domainAxis = getPlot().getDomainAxis();
     final double min = domainAxis.getLowerBound();
     final double max = domainAxis.getUpperBound();
     acceptableDeviationDataset.addSeries(computeAcceptableDeviationData(min, max));
     if (scatterPlotModel.showRegressionLine) {
       final XYIntervalSeries series = computeRegressionData(min, max);
       if (series != null) {
         regressionDataset.addSeries(series);
         computeCoefficientOfDetermination();
       }
     }
   }
 }
示例#5
0
 @Override
 protected String getDataAsText() {
   if (scatterpointsDataset.getItemCount(0) > 0) {
     final ScatterPlotTableModel scatterPlotTableModel;
     scatterPlotTableModel =
         new ScatterPlotTableModel(getRasterName(), getCorrelativeDataName(), computedDatas);
     return scatterPlotTableModel.toCVS();
   }
   return "";
 }
示例#6
0
  private void computeCoefficientOfDetermination() {
    int numberOfItems = scatterpointsDataset.getSeries(0).getItemCount();
    double arithmeticMeanOfX = 0; // arithmetic mean of X
    double arithmeticMeanOfY = 0; // arithmetic mean of Y
    double varX = 0; // variance of X
    double varY = 0; // variance of Y
    double coVarXY = 0; // covariance of X and Y;
    // compute arithmetic means
    for (int i = 0; i < numberOfItems; i++) {
      arithmeticMeanOfX += scatterpointsDataset.getXValue(0, i);
      arithmeticMeanOfY += scatterpointsDataset.getYValue(0, i);
    }
    arithmeticMeanOfX /= numberOfItems;
    arithmeticMeanOfY /= numberOfItems;
    // compute variances and covariance
    for (int i = 0; i < numberOfItems; i++) {
      varX += Math.pow(scatterpointsDataset.getXValue(0, i) - arithmeticMeanOfX, 2);
      varY += Math.pow(scatterpointsDataset.getYValue(0, i) - arithmeticMeanOfY, 2);
      coVarXY +=
          (scatterpointsDataset.getXValue(0, i) - arithmeticMeanOfX)
              * (scatterpointsDataset.getYValue(0, i) - arithmeticMeanOfY);
    }
    // computation of coefficient of determination
    double r2 = Math.pow(coVarXY, 2) / (varX * varY);
    r2 = MathUtils.round(r2, Math.pow(10.0, 5));

    final double[] coefficients = Regression.getOLSRegression(scatterpointsDataset, 0);
    final double intercept = coefficients[0];
    final double slope = coefficients[1];
    final String linearEquation;
    if (intercept >= 0) {
      linearEquation = "y = " + (float) slope + "x + " + (float) intercept;
    } else {
      linearEquation = "y = " + (float) slope + "x - " + Math.abs((float) intercept);
    }

    TextTitle tt = new TextTitle(linearEquation + "\nR² = " + r2);
    tt.setTextAlignment(HorizontalAlignment.RIGHT);
    tt.setFont(chart.getLegend().getItemFont());
    tt.setBackgroundPaint(new Color(200, 200, 255, 100));
    tt.setFrame(new BlockBorder(Color.white));
    tt.setPosition(RectangleEdge.BOTTOM);

    r2Annotation = new XYTitleAnnotation(0.98, 0.02, tt, RectangleAnchor.BOTTOM_RIGHT);
    r2Annotation.setMaxWidth(0.48);
    getPlot().addAnnotation(r2Annotation);
  }
示例#7
0
 private XYIntervalSeries computeRegressionData(double xStart, double xEnd) {
   if (scatterpointsDataset.getItemCount(0) > 1) {
     final double[] coefficients = Regression.getOLSRegression(scatterpointsDataset, 0);
     final Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]);
     final XYSeries regressionData =
         DatasetUtilities.sampleFunction2DToSeries(curve, xStart, xEnd, 100, "regression line");
     final XYIntervalSeries xyIntervalRegression = new XYIntervalSeries(regressionData.getKey());
     for (int i = 0; i < regressionData.getItemCount(); i++) {
       XYDataItem item = regressionData.getDataItem(i);
       final double x = item.getXValue();
       final double y = item.getYValue();
       xyIntervalRegression.add(x, x, x, y, y, y);
     }
     return xyIntervalRegression;
   } else {
     JOptionPane.showMessageDialog(
         this,
         "Unable to compute regression line.\n"
             + "At least 2 values are needed to compute regression coefficients.");
     return null;
   }
 }
示例#8
0
  private void createUI() {

    final XYPlot plot = getPlot();
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setNoDataMessage(NO_DATA_MESSAGE);
    int confidenceDSIndex = 0;
    int regressionDSIndex = 1;
    int scatterpointsDSIndex = 2;
    plot.setDataset(confidenceDSIndex, acceptableDeviationDataset);
    plot.setDataset(regressionDSIndex, regressionDataset);
    plot.setDataset(scatterpointsDSIndex, scatterpointsDataset);

    plot.addAnnotation(r2Annotation);

    final DeviationRenderer identityRenderer = new DeviationRenderer(true, false);
    identityRenderer.setSeriesPaint(0, StatisticChartStyling.SAMPLE_DATA_PAINT);
    identityRenderer.setSeriesFillPaint(0, StatisticChartStyling.SAMPLE_DATA_FILL_PAINT);
    plot.setRenderer(confidenceDSIndex, identityRenderer);

    final DeviationRenderer regressionRenderer = new DeviationRenderer(true, false);
    regressionRenderer.setSeriesPaint(0, StatisticChartStyling.REGRESSION_DATA_PAINT);
    regressionRenderer.setSeriesFillPaint(0, StatisticChartStyling.REGRESSION_DATA_FILL_PAINT);
    plot.setRenderer(regressionDSIndex, regressionRenderer);

    final XYErrorRenderer scatterPointsRenderer = new XYErrorRenderer();
    scatterPointsRenderer.setDrawXError(true);
    scatterPointsRenderer.setErrorStroke(new BasicStroke(1));
    scatterPointsRenderer.setErrorPaint(StatisticChartStyling.CORRELATIVE_POINT_OUTLINE_PAINT);
    scatterPointsRenderer.setSeriesShape(0, StatisticChartStyling.CORRELATIVE_POINT_SHAPE);
    scatterPointsRenderer.setSeriesOutlinePaint(
        0, StatisticChartStyling.CORRELATIVE_POINT_OUTLINE_PAINT);
    scatterPointsRenderer.setSeriesFillPaint(0, StatisticChartStyling.CORRELATIVE_POINT_FILL_PAINT);
    scatterPointsRenderer.setSeriesLinesVisible(0, false);
    scatterPointsRenderer.setSeriesShapesVisible(0, true);
    scatterPointsRenderer.setSeriesOutlineStroke(0, new BasicStroke(1.0f));
    scatterPointsRenderer.setSeriesToolTipGenerator(
        0,
        (dataset, series, item) -> {
          final XYIntervalSeriesCollection collection = (XYIntervalSeriesCollection) dataset;
          final Comparable key = collection.getSeriesKey(series);
          final double xValue = collection.getXValue(series, item);
          final double endYValue = collection.getEndYValue(series, item);
          final double yValue = collection.getYValue(series, item);
          return String.format(
              "%s: mean = %6.2f, sigma = %6.2f | %s: value = %6.2f",
              getRasterName(), yValue, endYValue - yValue, key, xValue);
        });
    plot.setRenderer(scatterpointsDSIndex, scatterPointsRenderer);

    final boolean autoRangeIncludesZero = false;
    final boolean xLog = scatterPlotModel.xAxisLogScaled;
    final boolean yLog = scatterPlotModel.yAxisLogScaled;
    plot.setDomainAxis(
        StatisticChartStyling.updateScalingOfAxis(
            xLog, plot.getDomainAxis(), autoRangeIncludesZero));
    plot.setRangeAxis(
        StatisticChartStyling.updateScalingOfAxis(
            yLog, plot.getRangeAxis(), autoRangeIncludesZero));

    createUI(createChartPanel(chart), createInputParameterPanel(), bindingContext);

    plot.getDomainAxis().addChangeListener(domainAxisChangeListener);
    scatterPlotDisplay.setMouseWheelEnabled(true);
    scatterPlotDisplay.setMouseZoomable(true);
  }
示例#9
0
  private void updateDataSet() {
    if (!isInitialized) {
      return;
    }

    dataset.removeAllSeries();

    double dx = 0.5 * dataSourceConfig.boxSize;

    if (profileData != null) {
      final float[] sampleValues = profileData.getSampleValues();
      final float[] sampleSigmas = profileData.getSampleSigmas();
      XYIntervalSeries series =
          new XYIntervalSeries(
              getRaster() != null ? getRaster().getName() : DEFAULT_SAMPLE_DATASET_NAME);
      for (int x = 0; x < sampleValues.length; x++) {
        final float y = sampleValues[x];
        final float dy = sampleSigmas[x];
        series.add(x, x - dx, x + dx, y, y - dy, y + dy);
      }
      dataset.addSeries(series);

      if (dataSourceConfig.useCorrelativeData
          && dataSourceConfig.pointDataSource != null
          && dataSourceConfig.dataField != null) {

        XYIntervalSeries corrSeries =
            new XYIntervalSeries(
                getCorrelativeDataLabel(
                    dataSourceConfig.pointDataSource, dataSourceConfig.dataField));
        int[] shapeVertexIndexes = profileData.getShapeVertexIndexes();
        SimpleFeature[] simpleFeatures =
            dataSourceConfig.pointDataSource.getFeatureCollection().toArray(new SimpleFeature[0]);

        if (shapeVertexIndexes.length == simpleFeatures.length) {
          int fieldIndex =
              getAttributeIndex(dataSourceConfig.pointDataSource, dataSourceConfig.dataField);
          if (fieldIndex != -1) {
            for (int i = 0; i < simpleFeatures.length; i++) {
              Number attribute = (Number) simpleFeatures[i].getAttribute(fieldIndex);
              if (attribute != null) {
                final double x = shapeVertexIndexes[i];
                final double y = attribute.doubleValue();
                corrSeries.add(x, x, x, y, y, y);
              }
            }
            dataset.addSeries(corrSeries);
          }
        } else {
          System.out.println("Weird things happened:");
          System.out.println("  shapeVertexIndexes.length = " + shapeVertexIndexes.length);
          System.out.println("  simpleFeatures.length     = " + simpleFeatures.length);
        }
      }

      profilePlotDisplay.restoreAutoBounds();
      xAxisRangeControl
          .getBindingContext()
          .setComponentsEnabled(
              PROPERTY_NAME_MARK_SEGMENTS, profileData.getShapeVertices().length > 2);
    }
  }