Enhancements in Time Series Visualization
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngine@96091 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c638a73622
commit
f3c6400347
|
@ -137,10 +137,14 @@ public class TimeSeriesGraph extends GenericStandaloneGraph {
|
|||
}
|
||||
|
||||
public static JFreeChart createStaticChart(Dataset dataset, String timeSeriesStringFormat) {
|
||||
return createStaticChart(dataset, timeSeriesStringFormat, "Time Series");
|
||||
}
|
||||
|
||||
public static JFreeChart createStaticChart(Dataset dataset, String timeSeriesStringFormat, String chartName) {
|
||||
|
||||
|
||||
JFreeChart chart = ChartFactory.createTimeSeriesChart(
|
||||
"Time Series", // title
|
||||
chartName, // title
|
||||
"", // x-axis label
|
||||
"", // y-axis label
|
||||
(XYDataset)dataset, // data
|
||||
|
|
|
@ -119,8 +119,8 @@ public class SignalProcessing {
|
|||
}
|
||||
|
||||
public static Image renderSignalWithGenericTime(double[] signal, float t0, float timeshift, String name) {
|
||||
if (signal.length>20000) {
|
||||
AnalysisLogger.getLogger().debug("Too many points to display: "+signal.length);
|
||||
if (signal.length > 20000) {
|
||||
AnalysisLogger.getLogger().debug("Too many points to display: " + signal.length);
|
||||
return null;
|
||||
}
|
||||
org.jfree.data.xy.XYSeries xyseries = new org.jfree.data.xy.XYSeries(name);
|
||||
|
@ -134,87 +134,113 @@ public class SignalProcessing {
|
|||
Image image = ImageTools.toImage(chart.createBufferedImage(680, 420));
|
||||
return image;
|
||||
}
|
||||
|
||||
public static Image renderSignalWithGenericTime(double[] signal, double [] timeline, String name) {
|
||||
if (signal.length>20000) {
|
||||
AnalysisLogger.getLogger().debug("Too many points to display: "+signal.length);
|
||||
|
||||
public static Image renderSignalWithGenericTime(double[] signal, double[] timeline, String name) {
|
||||
if (signal.length > 20000) {
|
||||
AnalysisLogger.getLogger().debug("Too many points to display: " + signal.length);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
org.jfree.data.xy.XYSeries xyseries = new org.jfree.data.xy.XYSeries(name);
|
||||
|
||||
|
||||
for (int i = 0; i < signal.length; i++) {
|
||||
xyseries.add(timeline[i], signal[i]);
|
||||
}
|
||||
|
||||
|
||||
XYSeriesCollection collection = new XYSeriesCollection(xyseries);
|
||||
JFreeChart chart = NumericSeriesGraph.createStaticChart(collection);
|
||||
Image image = ImageTools.toImage(chart.createBufferedImage(680, 420));
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Image renderSignalWithTime(double[] signal, Date[] dates, String name, String format) {
|
||||
org.jfree.data.time.TimeSeries series = new org.jfree.data.time.TimeSeries(name);
|
||||
if (signal.length>20000) {
|
||||
AnalysisLogger.getLogger().debug("Too many points to display: "+signal.length);
|
||||
if (signal.length > 20000) {
|
||||
AnalysisLogger.getLogger().debug("Too many points to display: " + signal.length);
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < signal.length; i++){
|
||||
try{
|
||||
for (int i = 0; i < signal.length; i++) {
|
||||
try {
|
||||
FixedMillisecond ms = new FixedMillisecond(dates[i]);
|
||||
series.add(ms, signal[i]);
|
||||
}catch(Exception e){
|
||||
AnalysisLogger.getLogger().debug("Skipping value yet present: "+dates[i]);
|
||||
} catch (Exception e) {
|
||||
AnalysisLogger.getLogger().debug("Skipping value yet present: " + dates[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TimeSeriesCollection dataset = new TimeSeriesCollection();
|
||||
dataset.addSeries(series);
|
||||
JFreeChart chart = TimeSeriesGraph.createStaticChart(dataset, format,name);
|
||||
Image image = ImageTools.toImage(chart.createBufferedImage(680, 420));
|
||||
return image;
|
||||
}
|
||||
|
||||
public static Image renderSignalsWithTime(List<double[]> signals, Date[] dates, List<String> names, String format) {
|
||||
TimeSeriesCollection dataset = new TimeSeriesCollection();
|
||||
int nsignals = signals.size();
|
||||
for (int j = 0; j < nsignals; j++) {
|
||||
double[] signal = signals.get(j);
|
||||
String name = names.get(j);
|
||||
|
||||
org.jfree.data.time.TimeSeries series = new org.jfree.data.time.TimeSeries(name);
|
||||
if (signal.length > 20000) {
|
||||
AnalysisLogger.getLogger().debug("Too many points to display: " + signal.length);
|
||||
return null;
|
||||
}
|
||||
int offset = 0;
|
||||
if (j>0)
|
||||
offset = signals.get(j-1).length;
|
||||
|
||||
for (int i = offset; i < offset+signal.length; i++) {
|
||||
try {
|
||||
FixedMillisecond ms = new FixedMillisecond(dates[i]);
|
||||
series.add(ms, signal[i-offset]);
|
||||
} catch (Exception e) {
|
||||
AnalysisLogger.getLogger().debug("Skipping value yet present: " + dates[i]);
|
||||
}
|
||||
}
|
||||
dataset.addSeries(series);
|
||||
}
|
||||
|
||||
JFreeChart chart = TimeSeriesGraph.createStaticChart(dataset, format);
|
||||
Image image = ImageTools.toImage(chart.createBufferedImage(680, 420));
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
public static Image renderSignalSpectrogram(double[] signal, double [] timeline, int samplingRate, int frameslength, int windowshift) {
|
||||
SpectrogramCustom spec = new SpectrogramCustom(signal, samplingRate, Window.get(Window.HAMMING, frameslength), windowshift, frameslength, 640, 480);
|
||||
double[][] spectrum = spec.spectra.toArray(new double[spec.spectra.size()][]);
|
||||
spec.setZoomX(640d/(double)spectrum.length);
|
||||
BufferedImage image = SignalConverter.createImage(spec,640,480);
|
||||
return ImageTools.toImage(image);
|
||||
|
||||
public static Image renderSignalSpectrogram(double[] signal, double[] timeline, int samplingRate, int frameslength, int windowshift) {
|
||||
SpectrogramCustom spec = new SpectrogramCustom(signal, samplingRate, Window.get(Window.HAMMING, frameslength), windowshift, frameslength, 640, 480);
|
||||
double[][] spectrum = spec.spectra.toArray(new double[spec.spectra.size()][]);
|
||||
spec.setZoomX(640d / (double) spectrum.length);
|
||||
BufferedImage image = SignalConverter.createImage(spec, 640, 480);
|
||||
return ImageTools.toImage(image);
|
||||
}
|
||||
|
||||
|
||||
public static Image renderSignalSpectrogram2(double[][] spectrogram) {
|
||||
SpectrumPlot2 spectrumPlot = new SpectrumPlot2(spectrogram);
|
||||
AnalysisLogger.getLogger().debug("Spectrum W:"+spectrumPlot.width);
|
||||
AnalysisLogger.getLogger().debug("Spectrum H:"+spectrumPlot.height);
|
||||
// spectrumPlot.hzoomSet(2f);
|
||||
spectrumPlot.hzoomSet(640f/(float)spectrumPlot.width);
|
||||
spectrumPlot.vzoomSet(480f/(float)spectrumPlot.height);
|
||||
AnalysisLogger.getLogger().debug("Spectrum W:" + spectrumPlot.width);
|
||||
AnalysisLogger.getLogger().debug("Spectrum H:" + spectrumPlot.height);
|
||||
// spectrumPlot.hzoomSet(2f);
|
||||
spectrumPlot.hzoomSet(640f / (float) spectrumPlot.width);
|
||||
spectrumPlot.vzoomSet(480f / (float) spectrumPlot.height);
|
||||
/*
|
||||
ApplicationFrame app = new ApplicationFrame("Spectrogram ");
|
||||
app.setContentPane(spectrumPlot);
|
||||
app.pack();
|
||||
app.setVisible(true);
|
||||
*/
|
||||
BufferedImage image = SignalConverter.createImage(spectrumPlot,640,480);
|
||||
* ApplicationFrame app = new ApplicationFrame("Spectrogram "); app.setContentPane(spectrumPlot); app.pack(); app.setVisible(true);
|
||||
*/
|
||||
BufferedImage image = SignalConverter.createImage(spectrumPlot, 640, 480);
|
||||
return ImageTools.toImage(image);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void displaySignalWithTime(double[] signal, Date[] dates, String name, String format) {
|
||||
org.jfree.data.time.TimeSeries series = new org.jfree.data.time.TimeSeries(name);
|
||||
if (signal.length>20000) {
|
||||
AnalysisLogger.getLogger().debug("Too many points to display: "+signal.length);
|
||||
if (signal.length > 20000) {
|
||||
AnalysisLogger.getLogger().debug("Too many points to display: " + signal.length);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < signal.length; i++){
|
||||
try{
|
||||
for (int i = 0; i < signal.length; i++) {
|
||||
try {
|
||||
FixedMillisecond ms = new FixedMillisecond(dates[i]);
|
||||
series.add(ms, signal[i]);
|
||||
}catch(Exception e){
|
||||
AnalysisLogger.getLogger().debug("Skipping value yet present: "+dates[i]);
|
||||
} catch (Exception e) {
|
||||
AnalysisLogger.getLogger().debug("Skipping value yet present: " + dates[i]);
|
||||
}
|
||||
}
|
||||
TimeSeriesCollection dataset = new TimeSeriesCollection();
|
||||
|
@ -225,6 +251,39 @@ public class SignalProcessing {
|
|||
tsg.render(dataset);
|
||||
}
|
||||
|
||||
public static void displaySignalsWithTime(List<double[]> signals, Date[] dates, List<String> names, String format) {
|
||||
TimeSeriesCollection dataset = new TimeSeriesCollection();
|
||||
int nsignals = signals.size();
|
||||
for (int j = 0; j < nsignals; j++) {
|
||||
double[] signal = signals.get(j);
|
||||
String name = names.get(j);
|
||||
|
||||
org.jfree.data.time.TimeSeries series = new org.jfree.data.time.TimeSeries(name);
|
||||
if (signal.length > 20000) {
|
||||
AnalysisLogger.getLogger().debug("Too many points to display: " + signal.length);
|
||||
return ;
|
||||
}
|
||||
int offset = 0;
|
||||
if (j>0)
|
||||
offset = signals.get(j-1).length;
|
||||
|
||||
for (int i = offset; i < offset+signal.length; i++) {
|
||||
try {
|
||||
FixedMillisecond ms = new FixedMillisecond(dates[i]);
|
||||
series.add(ms, signal[i-offset]);
|
||||
} catch (Exception e) {
|
||||
AnalysisLogger.getLogger().debug("Skipping value yet present: " + dates[i]);
|
||||
}
|
||||
}
|
||||
dataset.addSeries(series);
|
||||
}
|
||||
|
||||
TimeSeriesGraph tsg = new TimeSeriesGraph("Multiple Time Series");
|
||||
tsg.timeseriesformat = format;
|
||||
tsg.render(dataset);
|
||||
|
||||
}
|
||||
|
||||
public static double[] downSample(double[] signal, int numElements, AlgorithmConfiguration config) throws Exception {
|
||||
config.initRapidMiner();
|
||||
double[] rebuiltSignal = new double[signal.length];
|
||||
|
@ -282,8 +341,8 @@ public class SignalProcessing {
|
|||
|
||||
return dates;
|
||||
}
|
||||
|
||||
public static double[] fillSignal(double[] signal) throws Exception{
|
||||
|
||||
public static double[] fillSignal(double[] signal) throws Exception {
|
||||
ExampleSet es = SignalConverter.signal2ExampleSet(signal);
|
||||
SeriesMissingValueReplenishment sampler = (SeriesMissingValueReplenishment) OperatorService.createOperator("SeriesMissingValueReplenishment");
|
||||
sampler.setParameter("attribute_name", "att0");
|
||||
|
@ -291,20 +350,20 @@ public class SignalProcessing {
|
|||
es = sampler.apply(es);
|
||||
AnalysisLogger.getLogger().debug("Finished");
|
||||
double[] rebuiltSignal = new double[signal.length];
|
||||
SignalConverter.exampleSet2Signal(rebuiltSignal, es,0d);
|
||||
|
||||
SignalConverter.exampleSet2Signal(rebuiltSignal, es, 0d);
|
||||
|
||||
return rebuiltSignal;
|
||||
}
|
||||
|
||||
|
||||
public static double[] fillTimeSeries(double[] values, double[] timeseconds, double samplingRate, AlgorithmConfiguration config) throws Exception {
|
||||
|
||||
|
||||
double t0 = timeseconds[0];
|
||||
double t1 = timeseconds[timeseconds.length - 1];
|
||||
int signalength = Math.abs((int) ((t1 - t0) * samplingRate) + 1);
|
||||
AnalysisLogger.getLogger().debug("SignalProcessing->Old Time Series had: "+values.length+" samples. New Time Series will have: "+signalength+" samples");
|
||||
if (values.length==signalength)
|
||||
AnalysisLogger.getLogger().debug("SignalProcessing->Old Time Series had: " + values.length + " samples. New Time Series will have: " + signalength + " samples");
|
||||
if (values.length == signalength)
|
||||
return values;
|
||||
|
||||
|
||||
config.initRapidMiner();
|
||||
double signal[] = new double[signalength];
|
||||
Arrays.fill(signal, Double.NaN);
|
||||
|
@ -335,7 +394,6 @@ public class SignalProcessing {
|
|||
return rebuiltSignal;
|
||||
}
|
||||
|
||||
|
||||
public static double[][] multiSignalAnalysis(List<double[]> signals, int samplingRate, int windowshift, int frameslength, boolean display) throws Exception {
|
||||
|
||||
List<double[][]> spectra = new ArrayList<double[][]>();
|
||||
|
@ -413,15 +471,14 @@ public class SignalProcessing {
|
|||
return cutSpectrum;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
public static void main(String[] args) throws Exception {
|
||||
AlgorithmConfiguration conf = new AlgorithmConfiguration();
|
||||
conf.setConfigPath("./cfg/");
|
||||
conf.initRapidMiner();
|
||||
// double[] signal = new double[] {1,2,Double.NaN,4,5};
|
||||
double[] signal = new double[] {Double.NaN,1,2,3,4,5,Double.NaN};
|
||||
// double[] signal = new double[] {Double.NaN,Double.NaN,Double.NaN};
|
||||
// double[] signal = new double[] {Double.NaN,Double.NaN,0};
|
||||
// double[] signal = new double[] {1,2,Double.NaN,4,5};
|
||||
double[] signal = new double[] { Double.NaN, 1, 2, 3, 4, 5, Double.NaN };
|
||||
// double[] signal = new double[] {Double.NaN,Double.NaN,Double.NaN};
|
||||
// double[] signal = new double[] {Double.NaN,Double.NaN,0};
|
||||
double[] resignal = fillSignal(signal);
|
||||
System.out.println(resignal);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.io.BufferedWriter;
|
|||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
|
@ -129,7 +130,7 @@ public class TimeSeriesAnalysis extends StandardLocalExternalAlgorithm {
|
|||
AnalysisLogger.getLogger().debug("TimeSeriesAnalysis->Building Time Series");
|
||||
TimeSeries ts = TimeSeries.buildFromSignal(signal, config);
|
||||
String timepattern = ts.getTimepattern();
|
||||
String chartpattern = "HH:mm:ss MM-dd-yy";
|
||||
String chartpattern = "MM-dd-yy";
|
||||
if (timepattern.equals("s") ||
|
||||
(DateGuesser.isJavaDateOrigin(ts.getTime()[0]) &&
|
||||
DateGuesser.isJavaDateOrigin(ts.getTime()[ts.getTime().length-1]))
|
||||
|
@ -198,7 +199,18 @@ public class TimeSeriesAnalysis extends StandardLocalExternalAlgorithm {
|
|||
|
||||
uniformSignalSamplesImg = SignalProcessing.renderSignalWithGenericTime(ts.getValues(), 0,1, "Uniformly Sampled Time Series in Samples");
|
||||
spectrogramImg = SignalProcessing.renderSignalSpectrogram2(pd.currentspectrum);
|
||||
forecastsignalImg = SignalProcessing.renderSignalWithTime(ssa.getForecastSignal(), newtimes, "Forecasted Time Series", chartpattern);
|
||||
int timeseriesV = ts.getValues().length;
|
||||
double[] forecastedpiece = Arrays.copyOfRange(ssa.getForecastSignal(), timeseriesV, timeseriesV+pointsToReconstruct);
|
||||
List<String> tsnames = new ArrayList<String>();
|
||||
tsnames.add("Original Time Series");
|
||||
tsnames.add("Forecasted Time Series");
|
||||
List<double[]> signals = new ArrayList<double[]>();
|
||||
signals.add(ts.getValues());
|
||||
signals.add(forecastedpiece);
|
||||
forecastsignalImg = SignalProcessing.renderSignalsWithTime(signals, newtimes, tsnames, chartpattern);
|
||||
if (display){
|
||||
SignalProcessing.displaySignalsWithTime(signals, newtimes, tsnames, chartpattern);
|
||||
}
|
||||
double[] eigenValues = new double[ssa.getPercentList().size()];
|
||||
for (int i=0;i<eigenValues.length;i++){
|
||||
eigenValues[i] = ssa.getPercentList().get(i);
|
||||
|
|
Loading…
Reference in New Issue