Beispiel #1
0
 /** Gets string representation of ChannelView in the debug purposes */
 public String toString() {
   String ret = "";
   for (PlotDataProvider channel : plotDataProviders) {
     ret = ret + channel.getStation().getName() + "/" + channel.getChannelName() + " ";
   }
   return "ChannelView: " + ret;
 }
Beispiel #2
0
 @Override
 public void transform(
     List<PlotDataProvider> input,
     TimeInterval ti,
     IFilter filter,
     Object configuration,
     JFrame parentFrame) {
   if ((input == null) || (input.size() == 0) || (input.size() > 2)) {
     JOptionPane.showMessageDialog(
         parentFrame,
         "You should select two channels to view correlation\nor one channel to view autocorrelation",
         "Error",
         JOptionPane.ERROR_MESSAGE);
   } else {
     try {
       List<String> channelNames = new ArrayList<String>();
       for (PlotDataProvider channel : input) {
         channelNames.add(channel.getName());
       }
       @SuppressWarnings("unused")
       ViewCorrelation vc =
           new ViewCorrelation(
               parentFrame, createData(input, filter, ti), channelNames, sampleRate, ti);
     } catch (XMAXException e) {
       JOptionPane.showMessageDialog(
           parentFrame, e.getMessage(), "Warning", JOptionPane.WARNING_MESSAGE);
     }
   }
   ((XMAXframe) parentFrame).getGraphPanel().forceRepaint();
 }
Beispiel #3
0
 /** Return time interval of loaded data */
 public TimeInterval getLoadedTimeRange() {
   TimeInterval ret = null;
   for (PlotDataProvider channel : plotDataProviders) {
     if (ret == null) {
       ret = channel.getTimeRange();
     } else {
       ret = TimeInterval.getAggregate(ret, channel.getTimeRange());
     }
   }
   return ret;
 }
Beispiel #4
0
 public ChannelView(
     List<PlotDataProvider> channels,
     int infoPanelWidth,
     boolean isDrawSelectionCheckBox,
     Color graphAreaBgColor,
     Color infoAreaBgColor) {
   super();
   String names = "";
   for (PlotDataProvider channel : channels) {
     names = names + channel.toString() + ";";
     channelNames.add(channel.toString());
   }
   logger.debug("ChannelView created for list: " + names);
   initialize(infoPanelWidth, isDrawSelectionCheckBox, graphAreaBgColor, infoAreaBgColor);
   setPlotDataProviders(channels);
 }
Beispiel #5
0
 protected String getBlockHeaderText(PlotDataProvider channel, int x) {
   long time = getTime(x);
   List<Segment> segments = channel.getRawData(new TimeInterval(time, time));
   if (segments.size() > 0) {
     return segments.get(0).getBlockHeaderText(time);
   } else {
     return "<html>There is no data in this place</html>";
   }
 }
Beispiel #6
0
 public ChannelView(
     PlotDataProvider channel,
     int infoPanelWidth,
     boolean isDrawSelectionCheckBox,
     Color graphAreaBgColor,
     Color infoAreaBgColor) {
   super();
   logger.debug("ChannelView created for " + channel.toString());
   initialize(infoPanelWidth, isDrawSelectionCheckBox, graphAreaBgColor, infoAreaBgColor);
   List<PlotDataProvider> lst = new ArrayList<PlotDataProvider>();
   lst.add(channel);
   setPlotDataProviders(lst);
 }
Beispiel #7
0
 /**
  * Setter of the property <tt>plotDataProviders</tt>
  *
  * @param channels List of plotDataProviders to draw inside this ChannelView.
  */
 public void setPlotDataProviders(List<PlotDataProvider> channels) {
   if (plotDataProviders != null) {
     for (PlotDataProvider channel : plotDataProviders) {
       channel.deleteObserver(this);
     }
   }
   plotDataProviders = channels;
   for (PlotDataProvider channel : plotDataProviders) {
     channel.addObserver(this);
     logger.debug("Observer for " + channel.toString() + " added");
     if (channel.getMaxValue() > maxValueAllChannels) {
       maxValueAllChannels = channel.getMaxValue();
     }
     if (channel.getMinValue() < minValueAllChannels) {
       minValueAllChannels = channel.getMinValue();
     }
   }
   lastClickedY = Integer.MIN_VALUE;
 }
Beispiel #8
0
 protected String getChannelLabelText(PlotDataProvider channel) {
   String respname = "No response";
   try {
     if (channel.getResponse() != null) {
       respname = channel.getResponse().getFileName();
     }
   } catch (TraceViewException e) {
     // do nothing
   }
   return "<html>"
       + channel.getName()
       + "<br><i>Start time: </i> "
       + TimeInterval.formatDate(
           channel.getTimeRange().getStartTime(), TimeInterval.DateFormatType.DATE_FORMAT_MIDDLE)
       + "<br><i>Duration: </i> "
       + channel.getTimeRange().convert()
       + "<br><i>Sample rate: </i>"
       + channel.getSampleRate()
       + " ms <br>"
       + respname
       + "</html>";
 }
Beispiel #9
0
  /** Prepares pixelized data for PlotDataProviders to draw. Should be called before paint. */
  public synchronized String updateData() {

    int width = graphAreaPanel.getWidth(); // - graphAreaPanel.getInsets().left -

    // graphAreaPanel.getInsets().right;
    logger.debug("Updating data " + this + "Width = " + width);
    graphs = new ArrayList<PlotData>();
    List<String> errorChannels = new ArrayList<String>();
    for (PlotDataProvider channel : plotDataProviders) {
      // lg.debug("processing channel: " + channel);
      PlotData data = null;
      try {
        data =
            channel.getPlotData(
                graphPanel.getTimeRange(),
                width,
                graphPanel.getFilter(),
                graphPanel.getRemoveGain(),
                graphPanel.getColorMode());
      } catch (TraceViewException e) {
        channel.setRotation(null);
        try {
          errorChannels.add(
              channel.getNetworkName()
                  + "/"
                  + channel.getStation()
                  + "/"
                  + channel.getLocationName()
                  + "/"
                  + channel.getChannelName()
                  + " - "
                  + e.getMessage());
          data =
              channel.getPlotData(
                  graphPanel.getTimeRange(),
                  width,
                  graphPanel.getFilter(),
                  graphPanel.getRemoveGain(),
                  graphPanel.getColorMode());
        } catch (TraceViewException | RemoveGainException e1) {
          // do nothing
          logger.error("TraceViewException:", e1);
        }
      } catch (RemoveGainException e) {
        try {
          errorChannels.add(
              channel.getNetworkName()
                  + "/"
                  + channel.getStation()
                  + "/"
                  + channel.getLocationName()
                  + "/"
                  + channel.getChannelName()
                  + " - "
                  + e.getMessage());
          data =
              channel.getPlotData(
                  graphPanel.getTimeRange(),
                  width,
                  graphPanel.getFilter(),
                  null,
                  graphPanel.getColorMode());
        } catch (TraceViewException | RemoveGainException e1) {
          // do nothing
          logger.error("TraceViewException:", e1);
        }
      }

      graphs.add(data);
      meanValue = data.getMeanValue();
    }

    Collections.sort(graphs);

    if (errorChannels.size() > 0) return errorChannels.get(0);
    else return "";
  }
Beispiel #10
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;
  }
Beispiel #11
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 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;
  }