예제 #1
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;
  }
예제 #2
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;
  }