4 import ca.uqac.lif.cep.Connector;
5 import static ca.uqac.lif.cep.Connector.BOTTOM;
6 import static ca.uqac.lif.cep.Connector.INPUT;
7 import static ca.uqac.lif.cep.Connector.OUTPUT;
8 import static ca.uqac.lif.cep.Connector.TOP;
9 import ca.uqac.lif.cep.functions.ApplyFunction;
10 import ca.uqac.lif.cep.functions.Constant;
11 import ca.uqac.lif.cep.functions.FunctionTree;
12 import ca.uqac.lif.cep.functions.StreamVariable;
13 import ca.uqac.lif.cep.io.ReadLines;
14 import ca.uqac.lif.cep.mtnp.DrawPlot;
15 import ca.uqac.lif.cep.mtnp.UpdateTableStream;
16 import ca.uqac.lif.cep.signal.Limit;
17 import ca.uqac.lif.cep.signal.PeakFinderLocalMaximum;
18 import ca.uqac.lif.cep.signal.Smooth;
19 import ca.uqac.lif.cep.signal.Threshold;
20 import ca.uqac.lif.cep.tmf.CountDecimate;
21 import ca.uqac.lif.cep.tmf.Fork;
22 import ca.uqac.lif.cep.tmf.KeepLast;
23 import ca.uqac.lif.cep.tmf.Pump;
24 import ca.uqac.lif.cep.tmf.Splice;
25 import ca.uqac.lif.cep.tmf.Trim;
26 import ca.uqac.lif.cep.util.NthElement;
27 import ca.uqac.lif.cep.util.Numbers;
28 import ca.uqac.lif.cep.util.Strings;
29 import ca.uqac.lif.mtnp.plot.TwoDimensionalPlot.Axis;
30 import ca.uqac.lif.mtnp.plot.gral.Scatterplot;
69 public static void main(String[] args) {
71 int start_year = 1977, end_year = 1992;
75 ReadLines[] readers =
new ReadLines[end_year - start_year + 1];
76 for (
int y = start_year; y <= end_year; y++) {
77 readers[y - start_year] =
new ReadLines(
79 "data/vy2_" + y +
".asc"));
84 Splice spl =
new Splice(readers);
87 CountDecimate cd =
new CountDecimate(24 * 7);
88 Connector.connect(spl, cd);
92 Trim ignore_beginning =
new Trim(31);
93 Connector.connect(cd, ignore_beginning);
96 ApplyFunction to_array =
new ApplyFunction(
97 new Strings.SplitString(
"\\s+"));
98 Connector.connect(ignore_beginning, to_array);
103 Fork fork =
new Fork(3);
104 Connector.connect(to_array, fork);
107 ApplyFunction format_date =
new ApplyFunction(
new FunctionTree(
109 new NthElement(0), StreamVariable.X),
110 new FunctionTree(
new NthElement(1), StreamVariable.X)));
111 Connector.connect(fork, 0, format_date, INPUT);
114 ApplyFunction get_au1 =
new ApplyFunction(
new FunctionTree(
115 Numbers.numberCast,
new FunctionTree(
116 new NthElement(3), StreamVariable.X)));
117 Connector.connect(fork, 1, get_au1, INPUT);
120 Trim cd_delay =
new Trim(1);
121 Connector.connect(fork, 2, cd_delay, INPUT);
122 ApplyFunction get_au2 =
new ApplyFunction(
new FunctionTree(
123 Numbers.numberCast,
new FunctionTree(
124 new NthElement(3), StreamVariable.X)));
125 Connector.connect(cd_delay, get_au2);
129 ApplyFunction distance =
new ApplyFunction(
new FunctionTree(
130 Numbers.maximum, Constant.ZERO,
new FunctionTree(
132 StreamVariable.X, StreamVariable.Y)));
133 Connector.connect(get_au2, OUTPUT, distance, TOP);
134 Connector.connect(get_au1, OUTPUT, distance, BOTTOM);
139 Smooth smooth =
new Smooth(2);
140 Connector.connect(distance, smooth);
142 Fork f2 =
new Fork(2);
143 Connector.connect(smooth, f2);
144 PeakFinderLocalMaximum peak =
new PeakFinderLocalMaximum(5);
146 Connector.connect(f2, BOTTOM, peak, INPUT);
147 Threshold th =
new Threshold(0.0125f);
148 Connector.connect(peak, th);
149 Limit li =
new Limit(5);
150 Connector.connect(th, li);
152 UpdateTableStream table =
new UpdateTableStream(
"Date",
153 "Speed (AU/week)",
"Peak");
155 Connector.connect(format_date, OUTPUT, table, 0);
156 Connector.connect(f2, OUTPUT, table, 1);
157 Connector.connect(li, OUTPUT, table, 2);
161 Pump pump =
new Pump();
162 Connector.connect(table, pump);
164 KeepLast last =
new KeepLast(1);
165 Connector.connect(pump, last);
166 Scatterplot plot =
new Scatterplot();
167 plot.setCaption(Axis.X,
"Days after 1/1/77")
168 .setCaption(Axis.Y,
"AU");
170 DrawPlot draw =
new DrawPlot(plot);
171 Connector.connect(last, draw);
174 Connector.connect(draw, window);
Detect planetary encounters of Voyager 2 by analyzing its distance from the Earth.
Generate tables, charts and plots from event streams.
Receives a byte array as an input, and shows it in a Swing window as a picture.