예제 #1
0
 private XYDataset filterData(List<double[]> ds) {
   this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
   double[] correlation = null;
   double[] dblData1 = applyWindow(ds.get(0), (String) getTaperCB().getSelectedItem());
   try {
     if (ds.size() == 1) {
       correlation = IstiUtilsMath.correlate(dblData1, dblData1);
     } else {
       double[] dblData2 = applyWindow(ds.get(1), (String) taperCB.getSelectedItem());
       correlation = IstiUtilsMath.correlate(dblData1, dblData2);
     }
   } catch (IllegalArgumentException e) {
     logger.error("IllegalArgumentException:", e);
   }
   logger.debug("correlation computed, size = " + correlation.length);
   XYSeriesCollection dataset = new XYSeriesCollection();
   XYSeries series = new XYSeries(seriesName);
   double ampMax = 0;
   int ampMaxPoint = -1;
   for (int i = 0; i < correlation.length; i++) {
     series.add(sampleRate * (i - correlation.length / 2) / 1000, correlation[i]);
     if (Math.abs(correlation[i]) > ampMax) {
       ampMax = Math.abs(correlation[i]);
       ampMaxPoint = i;
     }
   }
   dataset.addSeries(series);
   getAmpMaxL().setText("Max Amplitude: " + dFormat.format(ampMax));
   getLagTimeL()
       .setText("Lag time: " + sampleRate * (ampMaxPoint - correlation.length / 2) / 1000 + " s");
   this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
   return dataset;
 }
예제 #2
0
 private XYDataset filterData(XYSeriesCollection series) {
   XYSeriesCollection ret = new XYSeriesCollection();
   if (getSmoothRB().isSelected()) {
     ret = series;
     ret = IstiUtilsMath.varismooth(ret);
   } else if (getRawAndSmoothRB().isSelected()) {
     XYSeries smoothedSeries = IstiUtilsMath.varismooth(series).getSeries(0);
     smoothedSeries.setKey("smoothed series");
     ret.addSeries(smoothedSeries);
     ret.addSeries(series.getSeries(0));
   } else if (getRawRB().isSelected()) {
     ret = series;
   }
   return ret;
 }
예제 #3
0
 private double[] applyWindow(double[] dataToProcess, String windowName) {
   if (windowName.equals("Hanning")) {
     return IstiUtilsMath.windowHanning(dataToProcess);
   } else if (windowName.equals("Hamming")) {
     return IstiUtilsMath.windowHamming(dataToProcess);
   } else if (windowName.equals("Cosine")) {
     return IstiUtilsMath.windowCosine(dataToProcess);
   } else if (windowName.equals("Triangular")) {
     return IstiUtilsMath.windowTriangular(dataToProcess);
   } else if (windowName.equals("Bartlett")) {
     return IstiUtilsMath.windowBartlett(dataToProcess);
   } else if (windowName.equals("Gauss")) {
     return IstiUtilsMath.windowGauss(dataToProcess);
   } else if (windowName.equals("Blackman")) {
     return IstiUtilsMath.windowBlackman(dataToProcess);
   } else {
     return dataToProcess;
   }
 }
예제 #4
0
  /**
   * @param input List of traces to process
   * @param filter Filter applied to traces before correlation
   * @param ti Time interval to define processed range
   * @return list of arrays - double raw data for selected traces and time ranges
   * @throws XMAXException if sample rates differ, gaps in the data, no data, or the data is too
   *     long.
   */
  private List<double[]> createData(List<PlotDataProvider> input, IFilter filter, TimeInterval ti)
      throws XMAXException {
    List<double[]> ret = new ArrayList<double[]>();
    PlotDataProvider channel1 = input.get(0);
    List<Segment> segments1;
    if (channel1.getRotation() != null) segments1 = channel1.getRawData(ti);
    else {
      segments1 = channel1.getRawData(channel1.getRotation(), ti);
    }
    int[] intData1 = new int[0];
    if (segments1.size() > 0) {
      long segment_end_time = 0;
      sampleRate = segments1.get(0).getSampleRate();
      for (Segment segment : segments1) {
        if (segment.getSampleRate() != sampleRate) {
          throw new XMAXException(
              "You have data with different sample rate for channel " + channel1.getName());
        }
        if (segment_end_time != 0
            && Segment.isDataBreak(
                segment_end_time, segment.getStartTime().getTime(), sampleRate)) {
          throw new XMAXException("You have gap in the data for channel " + channel1.getName());
        }
        segment_end_time = segment.getEndTime().getTime();
        intData1 = IstiUtilsMath.padArray(intData1, segment.getData(ti).data);
      }

    } else {
      throw new XMAXException("You have no data for channel " + channel1.getName());
    }

    logger.debug("size = " + intData1.length);
    if (filter != null) {
      intData1 = new FilterFacade(filter, channel1).filter(intData1);
    }
    double[] dblData1 = IstiUtilsMath.normData(intData1);
    if (dblData1.length > maxDataLength) {
      throw new XMAXException("Too many datapoints are selected.");
    }
    /*
     * if(dblData1.length%2 == 1){ dblData1 = Arrays.copyOf(dblData1,
     * dblData1.length-1); }
     */
    ret.add(dblData1);
    if (input.size() == 2) {
      PlotDataProvider channel2 = input.get(1);
      List<Segment> segments2;
      if (channel1.getRotation() != null) segments2 = channel2.getRawData(ti);
      else {
        segments2 = channel2.getRawData(channel2.getRotation(), ti);
      }
      int[] intData2 = new int[0];
      if (segments2.size() > 0) {
        long segment_end_time = 0;
        for (Segment segment : segments2) {
          if (segment.getSampleRate() != sampleRate) {
            throw new XMAXException(
                "Channels "
                    + channel1.getName()
                    + " and "
                    + channel2.getName()
                    + " have different sample rates: "
                    + sampleRate
                    + " and "
                    + segment.getSampleRate());
          }
          if (segment_end_time != 0
              && Segment.isDataBreak(
                  segment_end_time, segment.getStartTime().getTime(), sampleRate)) {
            throw new XMAXException("You have gap in the data for channel " + channel2.getName());
          }
          segment_end_time = segment.getEndTime().getTime();
          intData2 = IstiUtilsMath.padArray(intData2, segment.getData(ti).data);
        }

      } else {
        throw new XMAXException("You have no data for channel " + channel1.getName());
      }

      if (filter != null) {
        intData2 = new FilterFacade(filter, channel2).filter(intData2);
      }
      double[] dblData2 = IstiUtilsMath.normData(intData2);
      if (dblData2.length > maxDataLength) {
        throw new XMAXException(" Too many datapoints are selected");
      }
      /*
       * if(dblData2.length%2 == 1){ dblData2 = Arrays.copyOf(dblData2,
       * dblData2.length-1); }
       */
      ret.add(dblData2);
    }
    return ret;
  }
예제 #5
0
파일: TransPPM.java 프로젝트: usgs/xmax
  /**
   * @param input List of traces to process
   * @param filter Filter applied to traces before correlation
   * @param ti Time interval to define processed range
   * @return jFreeChart dataset of trace data in polar coordinates
   * @throws XMAXException if sample rates differ, gaps in the data, or no data for a channel
   */
  private XYDataset createDataset(List<PlotDataProvider> input, IFilter filter, TimeInterval ti)
      throws XMAXException {
    XYSeriesCollection dataset = new XYSeriesCollection();
    PlotDataProvider channel1 = input.get(0); // N/S
    PlotDataProvider channel2 = input.get(1); // E/W
    if (channel1.getSampleRate() != channel2.getSampleRate())
      throw new XMAXException("Channels have different sample rate");
    XYSeries series = new XYSeries(channel1.getName() + " " + channel2.getName(), false);
    double sampleRate;
    List<Segment> segments1;
    if (channel1.getRotation() != null && channel1.isRotated()) {
      segments1 = channel1.getRawData(channel1.getRotation(), ti);
    } else segments1 = channel1.getRawData(ti);

    int[] intData1 = new int[0];
    if (segments1.size() > 0) {
      long segment_end_time = 0;
      sampleRate = segments1.get(0).getSampleRate();
      for (Segment segment : segments1) {
        if (segment.getSampleRate() != sampleRate) {
          throw new XMAXException(
              "You have data with different sample rate for channel " + channel1.getName());
        }
        if (segment_end_time != 0
            && Segment.isDataBreak(
                segment_end_time, segment.getStartTime().getTime(), sampleRate)) {
          throw new XMAXException("You have gap in the data for channel " + channel1.getName());
        }
        segment_end_time = segment.getEndTime().getTime();
        intData1 = IstiUtilsMath.padArray(intData1, segment.getData(ti).data);
      }

    } else {
      throw new XMAXException("You have no data for channel " + channel1.getName());
    }
    List<Segment> segments2;
    if (channel2.getRotation() != null && channel2.isRotated())
      segments2 = channel2.getRawData(channel2.getRotation(), ti);
    else segments2 = channel2.getRawData(ti);
    int[] intData2 = new int[0];
    if (segments2.size() > 0) {
      long segment_end_time = 0;
      for (Segment segment : segments2) {
        if (segment.getSampleRate() != sampleRate) {
          throw new XMAXException(
              "Channels "
                  + channel1.getName()
                  + " and "
                  + channel2.getName()
                  + " have different sample rates: "
                  + sampleRate
                  + " and "
                  + segment.getSampleRate());
        }
        if (segment_end_time != 0
            && Segment.isDataBreak(
                segment_end_time, segment.getStartTime().getTime(), sampleRate)) {
          throw new XMAXException("You have gap in the data for channel " + channel2.getName());
        }
        segment_end_time = segment.getEndTime().getTime();
        intData2 = IstiUtilsMath.padArray(intData2, segment.getData(ti).data);
      }

    } else {
      throw new XMAXException("You have no data for channel " + channel1.getName());
    }
    if (filter != null) {
      intData1 = new FilterFacade(filter, channel1).filter(intData1);
      intData2 = new FilterFacade(filter, channel2).filter(intData2);
    }
    int dataSize = Math.min(intData1.length, intData2.length);
    if (dataSize > maxDataLength) {
      throw new XMAXException("Too many datapoints are selected.");
    }
    ArrayValues values1 = new ArrayValues(intData1, dataSize);
    ArrayValues values2 = new ArrayValues(intData2, dataSize);
    for (int i = 0; i < dataSize; i++) {
      double x = intData1[i] - values1.getAverage();
      double y = intData2[i] - values2.getAverage();
      double radius = Math.sqrt(x * x + y * y);
      double theta = 180 * Math.atan2(y, x) / Math.PI;
      series.add(theta, radius);
    }
    dataset.addSeries(series);
    return dataset;
  }