4789
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
4781
|
3 |
"{ Package: 'stx:libbasic2' }"
|
|
4 |
|
|
5 |
"{ NameSpace: Smalltalk }"
|
|
6 |
|
|
7 |
Object subclass:#TableData
|
|
8 |
instanceVariableNames:'rowData columnNames columnTypes tableName'
|
|
9 |
classVariableNames:''
|
|
10 |
poolDictionaries:''
|
4973
|
11 |
category:'Collections-Sequenceable-Table'
|
4781
|
12 |
!
|
|
13 |
|
|
14 |
!TableData class methodsFor:'documentation'!
|
|
15 |
|
|
16 |
documentation
|
4971
|
17 |
" Unfinished
|
4781
|
18 |
Ongoing work to support some algorithms on table data (such as CSV files).
|
|
19 |
|
|
20 |
Snippets to read and process tabular (CSV) data
|
4971
|
21 |
Snippets to generate a plot.
|
4781
|
22 |
|
4971
|
23 |
The category DWD (Deutscher Wetter Dienst / German weather service)
|
|
24 |
contains specific code to deal with historic weather data.
|
|
25 |
|
4781
|
26 |
[author:]
|
|
27 |
Claus Gittinger
|
|
28 |
|
|
29 |
[instance variables:]
|
|
30 |
rowData the actual data
|
|
31 |
columnNames name per column
|
|
32 |
columnTypes type per column (default is String)
|
|
33 |
tableName name - only used for labeling graphs
|
|
34 |
|
|
35 |
[class variables:]
|
|
36 |
|
|
37 |
[see also:]
|
|
38 |
|
|
39 |
"
|
|
40 |
! !
|
|
41 |
|
|
42 |
!TableData class methodsFor:'instance creation'!
|
|
43 |
|
|
44 |
fromFile:filename
|
|
45 |
^ self new readCSV:filename
|
|
46 |
|
|
47 |
"
|
|
48 |
self fromFile:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'
|
|
49 |
"
|
|
50 |
|
|
51 |
"Created: / 06-01-2019 / 13:28:53 / Claus Gittinger"
|
|
52 |
"Modified: / 09-01-2019 / 12:08:02 / Claus Gittinger"
|
|
53 |
!
|
|
54 |
|
|
55 |
rows:rowData columnNames:names
|
|
56 |
^ self new rows:rowData columnNames:names
|
|
57 |
|
|
58 |
"Created: / 06-01-2019 / 13:25:37 / Claus Gittinger"
|
|
59 |
!
|
|
60 |
|
|
61 |
rows:rowData columnNames:names tableName:tableName
|
|
62 |
^ self new rows:rowData columnNames:names tableName:tableName
|
|
63 |
|
|
64 |
"Created: / 06-01-2019 / 19:24:47 / Claus Gittinger"
|
|
65 |
! !
|
|
66 |
|
|
67 |
!TableData methodsFor:'accessing'!
|
|
68 |
|
|
69 |
getColumn:index
|
4971
|
70 |
"return a column (by index) as a vector"
|
4781
|
71 |
|
|
72 |
^ rowData collect:[:row | row at:index].
|
|
73 |
|
|
74 |
"
|
|
75 |
self new
|
|
76 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
|
|
77 |
getColumn:1.
|
|
78 |
"
|
|
79 |
|
|
80 |
"Created: / 06-01-2019 / 19:04:08 / Claus Gittinger"
|
4971
|
81 |
"Modified (comment): / 30-05-2019 / 11:29:54 / Claus Gittinger"
|
4781
|
82 |
!
|
|
83 |
|
|
84 |
getColumnNamed:name
|
4971
|
85 |
"return a column (by name) as a vector"
|
|
86 |
|
4781
|
87 |
^ self getColumn:(self indexOfColumnNamed:name)
|
|
88 |
|
|
89 |
"
|
|
90 |
self new
|
|
91 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
|
|
92 |
getColumnNamed:'TXK'.
|
|
93 |
"
|
|
94 |
|
|
95 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
96 |
|
|
97 |
"Created: / 06-01-2019 / 19:04:24 / Claus Gittinger"
|
4971
|
98 |
"Modified (comment): / 30-05-2019 / 11:30:00 / Claus Gittinger"
|
4781
|
99 |
!
|
|
100 |
|
|
101 |
getColumns:indexCollection
|
4971
|
102 |
"return multiple columns (by index vector) as a vector of columns"
|
|
103 |
|
4781
|
104 |
^ rowData collect:[:row |
|
|
105 |
indexCollection collect:[:eachColIdx | row at:eachColIdx] as:Array.
|
|
106 |
].
|
|
107 |
|
|
108 |
"
|
|
109 |
self new
|
|
110 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
|
|
111 |
getColumns:#(1 2 3).
|
|
112 |
"
|
|
113 |
|
|
114 |
"Created: / 06-01-2019 / 19:04:47 / Claus Gittinger"
|
4971
|
115 |
"Modified (comment): / 30-05-2019 / 11:30:30 / Claus Gittinger"
|
4781
|
116 |
!
|
|
117 |
|
|
118 |
getColumnsNamed:names
|
4971
|
119 |
"return multiple columns (by name vector) as a vector of columns"
|
|
120 |
|
4781
|
121 |
|colsIndices|
|
|
122 |
|
|
123 |
colsIndices := names collect:[:eachName | self indexOfColumnNamed:eachName].
|
|
124 |
^ self getColumns:colsIndices
|
|
125 |
|
|
126 |
"
|
|
127 |
self new
|
|
128 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
|
|
129 |
getColumnsNamed:#('MESS_DATUM' 'TXK' 'TNK').
|
|
130 |
"
|
|
131 |
|
|
132 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
133 |
|
|
134 |
"Created: / 06-01-2019 / 19:04:56 / Claus Gittinger"
|
4971
|
135 |
"Modified (comment): / 30-05-2019 / 11:30:41 / Claus Gittinger"
|
4781
|
136 |
!
|
|
137 |
|
|
138 |
tableName:aString
|
4971
|
139 |
"set the table's name"
|
|
140 |
|
4781
|
141 |
tableName := aString.
|
|
142 |
|
4971
|
143 |
"Modified (comment): / 30-05-2019 / 11:30:52 / Claus Gittinger"
|
4781
|
144 |
!
|
|
145 |
|
|
146 |
tableNamePrefix:aString
|
4971
|
147 |
"prepend a prefix to the table's name"
|
|
148 |
|
4781
|
149 |
tableName := aString,tableName.
|
|
150 |
|
|
151 |
"Created: / 06-01-2019 / 21:13:12 / Claus Gittinger"
|
4971
|
152 |
"Modified (comment): / 30-05-2019 / 11:31:08 / Claus Gittinger"
|
4781
|
153 |
!
|
|
154 |
|
|
155 |
tableNameSuffix:aString
|
4971
|
156 |
"append a suffix to the table's name"
|
|
157 |
|
4781
|
158 |
tableName := tableName,aString.
|
|
159 |
|
|
160 |
"Created: / 06-01-2019 / 21:13:01 / Claus Gittinger"
|
4971
|
161 |
"Modified (comment): / 30-05-2019 / 11:31:17 / Claus Gittinger"
|
4781
|
162 |
! !
|
|
163 |
|
|
164 |
!TableData methodsFor:'analysis'!
|
|
165 |
|
|
166 |
addBincoSlidingMean3ForColumnNamed:colName
|
|
167 |
"add a column with the sliding binco mean (1/4 + 1/2 + 1/4).
|
|
168 |
As binco:3 is quite common,
|
|
169 |
that is a tuned version of addBincoSlidingMean:3 forColumnNamed:colName"
|
|
170 |
|
|
171 |
| outRows valColIdx prevRow firstIndex lastIndex meanColIdx|
|
|
172 |
|
|
173 |
valColIdx := self indexOfColumnNamed:colName.
|
|
174 |
|
|
175 |
outRows := OrderedCollection new.
|
|
176 |
prevRow := nil.
|
|
177 |
firstIndex := 1. lastIndex := rowData size.
|
|
178 |
rowData := rowData collectWithIndex:[:row :idx|
|
|
179 |
|slidingSum|
|
|
180 |
|
|
181 |
((idx > firstIndex) and:[idx < lastIndex]) ifTrue:[
|
|
182 |
slidingSum := (
|
|
183 |
((rowData at:idx-1) at:valColIdx)
|
|
184 |
+ (((rowData at:idx) at:valColIdx)*2)
|
|
185 |
+ ((rowData at:idx+1) at:valColIdx)
|
|
186 |
) / 4.
|
|
187 |
].
|
|
188 |
row copyWith:slidingSum.
|
|
189 |
].
|
|
190 |
meanColIdx := columnNames size+1.
|
|
191 |
(rowData at:firstIndex) at:meanColIdx put:((rowData at:firstIndex+1) at:meanColIdx).
|
|
192 |
(rowData at:lastIndex) at:meanColIdx put:((rowData at:lastIndex-1) at:meanColIdx).
|
|
193 |
columnNames := columnNames copyWith:('Sliding_Binco_Mean_of_',colName).
|
|
194 |
^ self
|
|
195 |
|
|
196 |
"
|
|
197 |
(((self new
|
|
198 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
199 |
meanPerYearOfColumnNamed:'TXK')
|
|
200 |
addBincoSlidingMean3ForColumnNamed:'Mean_Per_Year_TXK')
|
|
201 |
tableName:'Feldberg/Schwarzwald';
|
|
202 |
plot:{ #x -> 'MESS_DATUM' . #y -> { 'Mean_Per_Year_TXK' . 'Sliding_Binco_Mean_of_Mean_Per_Year_TXK' . }}.
|
|
203 |
|
|
204 |
"
|
|
205 |
|
|
206 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
207 |
|
|
208 |
"Created: / 08-01-2019 / 00:10:16 / Claus Gittinger"
|
|
209 |
"Modified (comment): / 09-01-2019 / 12:32:34 / Claus Gittinger"
|
|
210 |
!
|
|
211 |
|
|
212 |
addBincoSlidingMean:n forColumnNamed:colName
|
|
213 |
"add a column with the sliding binco mean (1/2^n + ... + 1/4 + 1/2 + 1/4 + ... + 1/2^n)"
|
|
214 |
|
|
215 |
|nH outRows valColIdx prevRow firstIndex lastIndex meanColIdx wAll|
|
|
216 |
|
|
217 |
self assert:(n odd).
|
|
218 |
nH := n // 2.
|
|
219 |
|
|
220 |
valColIdx := self indexOfColumnNamed:colName.
|
|
221 |
|
|
222 |
outRows := OrderedCollection new.
|
|
223 |
prevRow := nil.
|
|
224 |
firstIndex := 1+nH. lastIndex := rowData size-nH.
|
|
225 |
wAll := 0.
|
|
226 |
1 to:nH do:[:delta |
|
|
227 |
wAll := wAll + (1 / (2 raisedTo:delta)).
|
|
228 |
wAll := wAll + (1 / (2 raisedTo:delta)).
|
|
229 |
].
|
|
230 |
wAll := wAll + 1.
|
|
231 |
|
|
232 |
rowData := rowData collectWithIndex:[:row :idx|
|
|
233 |
|slidingSum|
|
|
234 |
|
|
235 |
((idx >= firstIndex) and:[idx <= lastIndex]) ifTrue:[
|
|
236 |
slidingSum := 0.
|
|
237 |
"/ ... /8 /4 /2 /1 /2 /4 /8 ...
|
|
238 |
1 to:nH do:[:delta |
|
|
239 |
slidingSum := slidingSum + (((rowData at:idx-delta) at:valColIdx) / (2 raisedTo:delta)).
|
|
240 |
slidingSum := slidingSum + (((rowData at:idx+delta) at:valColIdx) / (2 raisedTo:delta)).
|
|
241 |
].
|
|
242 |
slidingSum := slidingSum + ((rowData at:idx) at:valColIdx).
|
|
243 |
slidingSum := slidingSum / wAll.
|
|
244 |
].
|
|
245 |
row copyWith:slidingSum.
|
|
246 |
].
|
|
247 |
meanColIdx := columnNames size+1.
|
|
248 |
1 to:nH do:[:delta |
|
|
249 |
(rowData at:0+delta) at:meanColIdx put:((rowData at:nH+1) at:meanColIdx)
|
|
250 |
].
|
|
251 |
1 to:nH do:[:delta |
|
|
252 |
(rowData at:rowData size+1-delta) at:meanColIdx put:((rowData at:rowData size-nH-1) at:meanColIdx)
|
|
253 |
].
|
|
254 |
columnNames := columnNames copyWith:('Sliding_Binco_Mean_of_',colName).
|
|
255 |
^ self
|
|
256 |
|
|
257 |
"
|
|
258 |
(((self new
|
|
259 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
260 |
meanPerYearOfColumnNamed:'TXK')
|
|
261 |
addBincoSlidingMean:5 forColumnNamed:'Mean_Per_Year_TXK')
|
|
262 |
tableName:'Feldberg/Schwarzwald';
|
|
263 |
plot:{ #x -> 'MESS_DATUM' .
|
|
264 |
#y -> { 'Mean_Per_Year_TXK' . 'Sliding_Binco_Mean_of_Mean_Per_Year_TXK' . }}.
|
|
265 |
|
|
266 |
"
|
|
267 |
|
|
268 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
269 |
|
|
270 |
"Created: / 07-01-2019 / 15:37:16 / Claus Gittinger"
|
|
271 |
"Modified (comment): / 09-01-2019 / 12:22:31 / Claus Gittinger"
|
|
272 |
!
|
|
273 |
|
|
274 |
addSlidingMean:n forColumnNamed:colName
|
|
275 |
"add a column with the sliding mean.
|
|
276 |
The sliding mean looks meaner, but may introduce lag (phase shift),
|
|
277 |
which binco avoids."
|
|
278 |
|
|
279 |
|slidingValues slidingSum outRows valColIdx prevYear sum countDaysPerYear|
|
|
280 |
|
|
281 |
valColIdx := self indexOfColumnNamed:colName.
|
|
282 |
|
|
283 |
"/ take the the first n values as initial sliding mean
|
|
284 |
slidingValues := (1 to:n) collect:[:rowIdx | (rowData at:rowIdx) at:valColIdx] as:OrderedCollection.
|
|
285 |
slidingSum := slidingValues sum.
|
|
286 |
|
|
287 |
outRows := OrderedCollection new.
|
|
288 |
prevYear := nil.
|
|
289 |
sum := countDaysPerYear := 0.
|
|
290 |
rowData := rowData collect:[:row |
|
|
291 |
| rowsDate rowsYear val|
|
|
292 |
|
|
293 |
slidingSum := slidingSum - slidingValues first.
|
|
294 |
slidingValues removeFirst.
|
|
295 |
slidingValues add:(row at:valColIdx).
|
|
296 |
slidingSum := slidingSum + slidingValues last.
|
|
297 |
row copyWith:(slidingSum / n).
|
|
298 |
].
|
|
299 |
columnNames := columnNames copyWith:('Sliding_Mean_of_',colName).
|
|
300 |
^ self
|
|
301 |
|
|
302 |
"
|
|
303 |
(((self new
|
|
304 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
305 |
meanPerYearOfColumnNamed:'TXK')
|
|
306 |
addSlidingMean:11 forColumnNamed:'Mean_Per_Year_TXK')
|
|
307 |
tableName:'Feldberg/Schwarzwald';
|
|
308 |
plot:{ #x -> 'MESS_DATUM' . #y -> { 'Mean_Per_Year_TXK' . 'Sliding_Mean_of_Mean_Per_Year_TXK' . }}.
|
|
309 |
|
|
310 |
"
|
|
311 |
|
|
312 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
313 |
|
|
314 |
"Created: / 06-01-2019 / 20:05:42 / Claus Gittinger"
|
|
315 |
"Modified (comment): / 09-01-2019 / 12:33:16 / Claus Gittinger"
|
|
316 |
!
|
|
317 |
|
|
318 |
extractRowsWhere:filterBlock
|
|
319 |
"return a new table containing only rows for which filterBlock evaluates to true"
|
|
320 |
|
|
321 |
|outRows|
|
|
322 |
|
|
323 |
outRows := rowData select:filterBlock.
|
|
324 |
^ self class
|
|
325 |
rows:outRows columnNames:columnNames
|
|
326 |
|
|
327 |
"
|
|
328 |
(((self new
|
|
329 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
330 |
meanPerMonthOfColumnNamed:'TXK')
|
|
331 |
extractRowsWhere:[:row | (row at:1) startsWith:'1945'])
|
|
332 |
plot
|
|
333 |
|
|
334 |
(((self new
|
|
335 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
336 |
meanPerMonthOfColumnNamed:'TXK')
|
|
337 |
extractRowsWhere:[:row | ((row at:1) from:5 to:6) = '01'])
|
|
338 |
plot
|
|
339 |
|
|
340 |
(((self new
|
|
341 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
342 |
meanPerMonthOfColumnNamed:'TXK')
|
|
343 |
extractMonth:8)
|
|
344 |
plot
|
|
345 |
|
|
346 |
(((self new
|
|
347 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
348 |
meanPerMonthOfColumnNamed:'TXK')
|
|
349 |
extractMonth:9)
|
|
350 |
plot
|
|
351 |
|
|
352 |
(((self new
|
|
353 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
354 |
meanPerMonthOfColumnNamed:'TXK')
|
|
355 |
extractMonth:10)
|
|
356 |
plot
|
|
357 |
|
|
358 |
(((self new
|
|
359 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19530101_20171231_04931.txt')
|
|
360 |
meanPerMonthOfColumnNamed:'TXK')
|
|
361 |
extractMonth:10)
|
|
362 |
tableNameSuffix:'-Echterdingen';
|
|
363 |
plot
|
|
364 |
|
|
365 |
"
|
|
366 |
|
|
367 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
368 |
|
|
369 |
"Created: / 09-01-2019 / 12:35:44 / Claus Gittinger"
|
|
370 |
! !
|
|
371 |
|
|
372 |
!TableData methodsFor:'analysis - DWD'!
|
|
373 |
|
|
374 |
extractMonth:monthIndex
|
|
375 |
"return a new table containing only rows for that month.
|
|
376 |
This is specific to DWD data"
|
|
377 |
|
|
378 |
^ self extractMonth:monthIndex columnName:'MESS_DATUM' format:'%4y%2m%2d'
|
|
379 |
|
|
380 |
"
|
|
381 |
(((self new
|
|
382 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
383 |
meanPerMonthOfColumnNamed:'TXK')
|
|
384 |
extractMonth:1 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
385 |
plot
|
|
386 |
|
|
387 |
(((self new
|
|
388 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
389 |
meanPerMonthOfColumnNamed:'TXK')
|
|
390 |
extractMonth:2 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
391 |
plot
|
|
392 |
|
|
393 |
(((self new
|
|
394 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
395 |
meanPerMonthOfColumnNamed:'TXK')
|
|
396 |
extractMonth:8 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
397 |
plot
|
|
398 |
|
|
399 |
(((self new
|
|
400 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
401 |
meanPerMonthOfColumnNamed:'TXK')
|
|
402 |
extractMonth:9 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
403 |
plot
|
|
404 |
|
|
405 |
(((self new
|
|
406 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
407 |
meanPerMonthOfColumnNamed:'TXK')
|
|
408 |
extractMonth:10 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
409 |
plot
|
|
410 |
|
|
411 |
(((self new
|
|
412 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19530101_20171231_04931.txt')
|
|
413 |
meanPerMonthOfColumnNamed:'TXK')
|
|
414 |
extractMonth:10 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
415 |
tableNameSuffix:'-Echterdingen';
|
|
416 |
plot
|
|
417 |
|
|
418 |
"
|
|
419 |
|
|
420 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
421 |
|
|
422 |
"Created: / 06-01-2019 / 19:00:52 / Claus Gittinger"
|
|
423 |
"Modified (comment): / 09-01-2019 / 18:30:09 / Claus Gittinger"
|
|
424 |
!
|
|
425 |
|
|
426 |
extractMonth:monthIndex columnName:monthColumnName
|
|
427 |
"return a new table containing only rows for that month.
|
|
428 |
This is specific to DWD data"
|
|
429 |
|
|
430 |
^ self extractMonth:monthIndex columnName:monthColumnName format:'%4y%2m%2d'
|
|
431 |
|
|
432 |
"
|
|
433 |
(((self new
|
|
434 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
435 |
meanPerMonthOfColumnNamed:'TXK')
|
|
436 |
extractMonth:1 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
437 |
plot
|
|
438 |
|
|
439 |
(((self new
|
|
440 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
441 |
meanPerMonthOfColumnNamed:'TXK')
|
|
442 |
extractMonth:2 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
443 |
plot
|
|
444 |
|
|
445 |
(((self new
|
|
446 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
447 |
meanPerMonthOfColumnNamed:'TXK')
|
|
448 |
extractMonth:8 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
449 |
plot
|
|
450 |
|
|
451 |
(((self new
|
|
452 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
453 |
meanPerMonthOfColumnNamed:'TXK')
|
|
454 |
extractMonth:9 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
455 |
plot
|
|
456 |
|
|
457 |
(((self new
|
|
458 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
459 |
meanPerMonthOfColumnNamed:'TXK')
|
|
460 |
extractMonth:10 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
461 |
plot
|
|
462 |
|
|
463 |
(((self new
|
|
464 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19530101_20171231_04931.txt')
|
|
465 |
meanPerMonthOfColumnNamed:'TXK')
|
|
466 |
extractMonth:10 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
467 |
tableNameSuffix:'-Echterdingen';
|
|
468 |
plot
|
|
469 |
|
|
470 |
"
|
|
471 |
|
|
472 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
473 |
|
|
474 |
"Created: / 09-01-2019 / 14:42:05 / Claus Gittinger"
|
|
475 |
"Modified (comment): / 09-01-2019 / 18:31:31 / Claus Gittinger"
|
|
476 |
!
|
|
477 |
|
4971
|
478 |
extractMonth:monthIndex columnName:monthColumnName format:dateFormat
|
|
479 |
"return a new table containing only rows for that month.
|
|
480 |
This is specific to DWD data"
|
|
481 |
|
|
482 |
|dateColIdx|
|
|
483 |
|
|
484 |
dateColIdx := self indexOfColumnNamed:monthColumnName.
|
|
485 |
^ (self
|
|
486 |
extractRowsWhere:[:row |
|
|
487 |
| rowsDate rowsYearAndMonth val|
|
|
488 |
|
|
489 |
rowsDate := Date readFrom:(row at:dateColIdx) format:dateFormat.
|
|
490 |
rowsDate month = monthIndex
|
|
491 |
])
|
|
492 |
tableName:(Date nameOfMonth:monthIndex),' Mean'
|
|
493 |
|
|
494 |
"
|
|
495 |
(((self new
|
|
496 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
497 |
meanPerMonthOfColumnNamed:'TXK')
|
|
498 |
extractMonth:1 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
499 |
plot
|
|
500 |
|
|
501 |
(((self new
|
|
502 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
503 |
meanPerMonthOfColumnNamed:'TXK')
|
|
504 |
extractMonth:2 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
505 |
plot
|
|
506 |
|
|
507 |
(((self new
|
|
508 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
509 |
meanPerMonthOfColumnNamed:'TXK')
|
|
510 |
extractMonth:8 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
511 |
plot
|
|
512 |
|
|
513 |
(((self new
|
|
514 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
515 |
meanPerMonthOfColumnNamed:'TXK')
|
|
516 |
extractMonth:9 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
517 |
plot
|
|
518 |
|
|
519 |
(((self new
|
|
520 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
521 |
meanPerMonthOfColumnNamed:'TXK')
|
|
522 |
extractMonth:10 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
523 |
plot
|
|
524 |
|
|
525 |
(((self new
|
|
526 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19530101_20171231_04931.txt')
|
|
527 |
meanPerMonthOfColumnNamed:'TXK')
|
|
528 |
extractMonth:10 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
529 |
tableNameSuffix:'-Echterdingen';
|
|
530 |
plot
|
|
531 |
|
|
532 |
(((self new
|
|
533 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19530101_20171231_04931.txt')
|
|
534 |
meanPerMonthOfColumnNamed:'TXK')
|
|
535 |
extractMonth:3 columnName:'MESS_DATUM' format:'%4y%2m')
|
|
536 |
tableNameSuffix:'-Echterdingen';
|
|
537 |
plot
|
|
538 |
|
|
539 |
|table|
|
|
540 |
table := (self new
|
|
541 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19530101_20171231_04931.txt').
|
|
542 |
1 to:12 do:[:month |
|
|
543 |
((table
|
|
544 |
meanPerMonthOfColumnNamed:'TXK')
|
|
545 |
extractMonth:month columnName:'MESS_DATUM' format:'%4y%2m')
|
|
546 |
tableNameSuffix:'-Echterdingen';
|
|
547 |
plot
|
|
548 |
]
|
|
549 |
"
|
|
550 |
|
|
551 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
552 |
|
|
553 |
"Created: / 09-01-2019 / 18:27:28 / Claus Gittinger"
|
|
554 |
!
|
|
555 |
|
4781
|
556 |
extractMonth:month day:day
|
|
557 |
"return a new table containing only rows for that day in month"
|
|
558 |
|
|
559 |
^ self extractMonth:month day:day columnName:'MESS_DATUM' format:'%4y%2m%2d'
|
|
560 |
|
|
561 |
"
|
|
562 |
((self fromFile:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
563 |
extractMonth:1 day:1)
|
|
564 |
tableName:'1st Januar, Feldberg';
|
|
565 |
plot:{ #x -> 'MESS_DATUM' . #y -> { 'TXK' . 'TNK' }}
|
|
566 |
"
|
|
567 |
|
|
568 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
569 |
|
|
570 |
"Created: / 06-01-2019 / 13:15:46 / Claus Gittinger"
|
|
571 |
"Modified (comment): / 10-01-2019 / 16:20:48 / Claus Gittinger"
|
4971
|
572 |
!
|
|
573 |
|
|
574 |
extractMonth:month day:day columnName:monthColumnName format:dateFormat
|
|
575 |
"return a new table containing only rows for that day in month"
|
|
576 |
|
|
577 |
|outRows dateColIdx|
|
|
578 |
|
|
579 |
dateColIdx := self indexOfColumnNamed:monthColumnName.
|
|
580 |
outRows := rowData select:[:row |
|
|
581 |
|rowsDate|
|
|
582 |
|
|
583 |
rowsDate := Date readFrom:(row at:dateColIdx) format:dateFormat.
|
|
584 |
(rowsDate month = month) and:[rowsDate day = day].
|
|
585 |
].
|
|
586 |
^ self class rows:outRows columnNames:columnNames
|
|
587 |
|
|
588 |
"
|
|
589 |
((self fromFile:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
590 |
extractMonth:1 day:1 columnName:'MESS_DATUM' format:'%4y%2m%2d')
|
|
591 |
plot:{ #x -> 'MESS_DATUM' . #y -> { 'TXK' . 'TNK' }}
|
|
592 |
"
|
|
593 |
|
|
594 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
595 |
|
|
596 |
"Created: / 10-01-2019 / 16:14:29 / Claus Gittinger"
|
|
597 |
!
|
|
598 |
|
|
599 |
meanPerMonthOfColumnNamed:colName
|
|
600 |
"return a new table containing the arithmetic mean per month of a column"
|
|
601 |
|
|
602 |
|outRows valColIdx dateColIdx prevYearAndMonth sum countDaysPerMonth|
|
|
603 |
|
|
604 |
dateColIdx := self indexOfColumnNamed:'MESS_DATUM'.
|
|
605 |
valColIdx := self indexOfColumnNamed:colName.
|
|
606 |
|
|
607 |
outRows := OrderedCollection new.
|
|
608 |
prevYearAndMonth := nil.
|
|
609 |
sum := countDaysPerMonth := 0.
|
|
610 |
rowData do:[:row |
|
|
611 |
| rowsDate rowsYearAndMonth val|
|
|
612 |
|
|
613 |
rowsDate := row at:dateColIdx.
|
|
614 |
"/ yyyymmdd
|
|
615 |
rowsYearAndMonth := rowsDate copyTo:6.
|
|
616 |
prevYearAndMonth isNil ifTrue:[
|
|
617 |
prevYearAndMonth := rowsYearAndMonth.
|
|
618 |
sum := countDaysPerMonth := 0.
|
|
619 |
].
|
|
620 |
(rowsYearAndMonth = prevYearAndMonth) ifTrue:[
|
|
621 |
val := Number readFrom:(row at:valColIdx).
|
|
622 |
sum := sum + val.
|
|
623 |
countDaysPerMonth := countDaysPerMonth + 1.
|
|
624 |
] ifFalse:[
|
|
625 |
outRows add:{ prevYearAndMonth . (sum / countDaysPerMonth) }.
|
|
626 |
sum := countDaysPerMonth := 0.
|
|
627 |
prevYearAndMonth := rowsYearAndMonth.
|
|
628 |
].
|
|
629 |
].
|
|
630 |
^ self class
|
|
631 |
rows:outRows columnNames:{ 'MESS_DATUM' . 'Mean per month of ',colName }
|
|
632 |
tableName:('Mean Per Month of ',colName)
|
|
633 |
|
|
634 |
"
|
|
635 |
((self new
|
|
636 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
637 |
meanPerMonthOfColumnNamed:'TXK')
|
|
638 |
plot
|
|
639 |
|
|
640 |
"
|
|
641 |
|
|
642 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
643 |
|
|
644 |
"Created: / 06-01-2019 / 19:06:36 / Claus Gittinger"
|
|
645 |
"Modified (comment): / 09-01-2019 / 12:24:34 / Claus Gittinger"
|
|
646 |
!
|
|
647 |
|
|
648 |
meanPerYearOfColumnNamed:colName
|
|
649 |
"return a new table containing the arithmetic mean per year of a column"
|
|
650 |
|
|
651 |
|outRows valColIdx dateColIdx prevYear sum countDaysPerYear|
|
|
652 |
|
|
653 |
dateColIdx := self indexOfColumnNamed:'MESS_DATUM'.
|
|
654 |
valColIdx := self indexOfColumnNamed:colName.
|
|
655 |
|
|
656 |
outRows := OrderedCollection new.
|
|
657 |
prevYear := nil.
|
|
658 |
sum := countDaysPerYear := 0.
|
|
659 |
rowData do:[:row |
|
|
660 |
| rowsDate rowsYear val|
|
|
661 |
|
|
662 |
rowsDate := row at:dateColIdx.
|
|
663 |
"/ yyyymmdd
|
|
664 |
rowsYear := rowsDate copyTo:4.
|
|
665 |
prevYear isNil ifTrue:[
|
|
666 |
prevYear := rowsYear.
|
|
667 |
sum := countDaysPerYear := 0.
|
|
668 |
].
|
|
669 |
(rowsYear = prevYear) ifTrue:[
|
|
670 |
val := Number readFrom:(row at:valColIdx).
|
|
671 |
sum := sum + val.
|
|
672 |
countDaysPerYear := countDaysPerYear + 1.
|
|
673 |
] ifFalse:[
|
|
674 |
outRows add:{ prevYear . (sum / countDaysPerYear) }.
|
|
675 |
sum := countDaysPerYear := 0.
|
|
676 |
prevYear := rowsYear.
|
|
677 |
].
|
|
678 |
].
|
|
679 |
^ self class
|
|
680 |
rows:outRows columnNames:{ 'MESS_DATUM' . 'Mean_Per_Year_',colName }
|
|
681 |
tableName:('Mean Per Year of ',colName)
|
|
682 |
|
|
683 |
"
|
|
684 |
((self new
|
|
685 |
read:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
686 |
meanPerYearOfColumnNamed:'TXK')
|
|
687 |
plot
|
|
688 |
|
|
689 |
"
|
|
690 |
|
|
691 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
692 |
|
|
693 |
"Created: / 06-01-2019 / 19:40:34 / Claus Gittinger"
|
|
694 |
"Modified: / 06-01-2019 / 22:34:06 / Claus Gittinger"
|
4781
|
695 |
! !
|
|
696 |
|
|
697 |
!TableData methodsFor:'helpers'!
|
|
698 |
|
|
699 |
indexOfColumnNamed:name
|
4971
|
700 |
"find a column index by name"
|
|
701 |
|
4781
|
702 |
^ columnNames indexOf:name ifAbsent:[self error:'no such column'].
|
|
703 |
|
|
704 |
"
|
|
705 |
self new
|
|
706 |
read:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
|
|
707 |
indexOfColumnNamed:'MESS_DATUM'.
|
|
708 |
"
|
|
709 |
|
|
710 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
711 |
|
|
712 |
"Created: / 06-01-2019 / 13:20:47 / Claus Gittinger"
|
4971
|
713 |
"Modified (comment): / 30-05-2019 / 11:33:23 / Claus Gittinger"
|
4781
|
714 |
! !
|
|
715 |
|
|
716 |
!TableData methodsFor:'instance creation'!
|
|
717 |
|
|
718 |
rows:rowDataArg columnNames:columnNamesArg
|
|
719 |
rowData := rowDataArg.
|
|
720 |
columnNames := columnNamesArg.
|
|
721 |
|
|
722 |
"Created: / 06-01-2019 / 13:26:01 / Claus Gittinger"
|
|
723 |
!
|
|
724 |
|
|
725 |
rows:rowDataArg columnNames:columnNamesArg tableName:tableNameArg
|
|
726 |
rowData := rowDataArg.
|
|
727 |
columnNames := columnNamesArg.
|
|
728 |
tableName := tableNameArg.
|
|
729 |
|
|
730 |
"Created: / 06-01-2019 / 19:25:10 / Claus Gittinger"
|
|
731 |
! !
|
|
732 |
|
|
733 |
!TableData methodsFor:'plotting'!
|
|
734 |
|
|
735 |
plot
|
|
736 |
self plot:nil
|
|
737 |
|
|
738 |
"
|
|
739 |
|data tmax|
|
|
740 |
|
|
741 |
data := self fromFile:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'.
|
|
742 |
tmax := data withColumnsNamed:#('MESS_DATUM' 'TXK' 'TNK').
|
|
743 |
tmax plot:{ #x -> 'MESS_DATUM' . #y -> { 'TXK' 'TNK' }} .
|
|
744 |
"
|
|
745 |
|
|
746 |
"Created: / 06-01-2019 / 18:47:27 / Claus Gittinger"
|
|
747 |
"Modified: / 06-01-2019 / 21:32:22 / Claus Gittinger"
|
|
748 |
!
|
|
749 |
|
|
750 |
plot:optionalSpec
|
|
751 |
|tmpFile|
|
|
752 |
|
|
753 |
[
|
|
754 |
tmpFile := Filename newTemporary.
|
|
755 |
tmpFile writingFileDo:[:s |
|
|
756 |
self writeCSVToStream:s.
|
|
757 |
].
|
|
758 |
"/ FileBrowserV2 openOn:tmpFile.
|
|
759 |
self plot:optionalSpec file:tmpFile.
|
|
760 |
] ensure:[
|
|
761 |
tmpFile delete
|
|
762 |
].
|
|
763 |
|
|
764 |
"
|
|
765 |
|data tmax|
|
|
766 |
|
|
767 |
data := self fromFile:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'.
|
|
768 |
tmax := data withColumnsNamed:#('MESS_DATUM' 'TXK' 'TNK').
|
|
769 |
tmax plot:{ #x -> 'MESS_DATUM' . #y -> { 'TXK' 'TNK' }} .
|
|
770 |
"
|
|
771 |
|
|
772 |
"Created: / 06-01-2019 / 21:32:09 / Claus Gittinger"
|
|
773 |
"Modified: / 09-01-2019 / 18:40:16 / Claus Gittinger"
|
|
774 |
!
|
|
775 |
|
|
776 |
plot:optionalSpec file:fileName
|
|
777 |
|script scriptFile outFile width height spec xCol yCols|
|
|
778 |
|
|
779 |
scriptFile := Filename newTemporary .
|
|
780 |
outFile := '/tmp/plot3.png'.
|
|
781 |
outFile asFilename contents:''.
|
|
782 |
|
|
783 |
width := 1200.
|
|
784 |
height := 400.
|
|
785 |
|
|
786 |
optionalSpec notNil ifTrue:[
|
|
787 |
spec := optionalSpec isDictionary
|
|
788 |
ifTrue:[optionalSpec]
|
|
789 |
ifFalse:[Dictionary withAssociations:optionalSpec].
|
|
790 |
|
|
791 |
yCols := spec at:#y.
|
|
792 |
xCol := spec at:#x.
|
|
793 |
script := '
|
|
794 |
png(filename="%1", height=%3, width=%2)
|
|
795 |
Data <- read.csv(file="%4", header=TRUE, sep=";")
|
|
796 |
',xCol,' <- Data$',xCol,'
|
|
797 |
',((yCols collect:[:col | col,' <- Data$',col]) asStringWith:Character cr),
|
|
798 |
"/'plot(',xCol,', '
|
|
799 |
"/ ,((yCols collect:[:col | col,', ']) asStringWith:''),
|
|
800 |
"/' type="l", main = "%5")'
|
|
801 |
'
|
|
802 |
',('plot(%1, %2, type="b", col=2, main = "%%5")' bindWith:xCol with:yCols first),'
|
|
803 |
',((yCols from:2 collect:[:ycol | 'lines(%1, %2, type="l", col=3)' bindWith:xCol with:ycol]) asStringWith:Character cr)
|
|
804 |
,'
|
|
805 |
# dev.off()
|
|
806 |
'
|
|
807 |
bindWith:outFile
|
|
808 |
with:width
|
|
809 |
with:height
|
|
810 |
with:fileName asFilename pathName
|
|
811 |
with:(tableName ? '').
|
|
812 |
"/ self halt.
|
|
813 |
] ifFalse:[
|
|
814 |
script := '
|
|
815 |
# library(ggplot2)
|
|
816 |
# library(ggfortify)
|
|
817 |
|
|
818 |
png(filename="%1", height=%3, width=%2)
|
|
819 |
Data <- read.csv(file="%4", header=TRUE, sep=";")
|
|
820 |
|
|
821 |
# theme_set(theme_classic())
|
|
822 |
|
|
823 |
# Plot
|
|
824 |
# autoplot(Data) +
|
|
825 |
# labs(title="Data") +
|
|
826 |
# theme(plot.title = element_text(hjust=0.1))
|
|
827 |
plot(Data, type="l", main = "%5")
|
|
828 |
# plot(Data, cex = .4)
|
|
829 |
dev.off()
|
|
830 |
'
|
|
831 |
bindWith:outFile
|
|
832 |
with:width
|
|
833 |
with:height
|
|
834 |
with:fileName asFilename pathName
|
|
835 |
with:(tableName ? '').
|
|
836 |
].
|
|
837 |
|
|
838 |
scriptFile contents:script.
|
|
839 |
|
|
840 |
OSProcess new
|
|
841 |
command:('r --silent --vanilla --slave -f %1' bindWith:scriptFile);
|
|
842 |
execute.
|
|
843 |
"/ self halt.
|
|
844 |
"/ outFile asFilename exists.
|
4971
|
845 |
((Smalltalk classNamed:#Image) fromFile:outFile asFilename) inspect.
|
4781
|
846 |
|
|
847 |
"
|
|
848 |
|data tmax|
|
|
849 |
|
|
850 |
data := self fromFile:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'.
|
|
851 |
tmax := data withColumnsNamed:#('MESS_DATUM' 'TXK').
|
|
852 |
tmax tableName:'Feldberg'.
|
|
853 |
tmax plot:{ #x -> 'MESS_DATUM' . #y -> { 'TXK' . 'TNK' }}.
|
|
854 |
"
|
|
855 |
|
|
856 |
"Created: / 06-01-2019 / 21:32:43 / Claus Gittinger"
|
4971
|
857 |
"Modified: / 30-05-2019 / 11:28:42 / Claus Gittinger"
|
4781
|
858 |
!
|
|
859 |
|
|
860 |
plotFile:fileName
|
|
861 |
self plot:nil file:fileName
|
|
862 |
|
|
863 |
"
|
|
864 |
|data tmax|
|
|
865 |
|
|
866 |
data := self fromFile:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'.
|
|
867 |
tmax := data withColumnsNamed:#('MESS_DATUM' 'TXK').
|
|
868 |
tmax tableName:'Test'.
|
|
869 |
tmax plot.
|
|
870 |
"
|
|
871 |
|
|
872 |
"Created: / 06-01-2019 / 15:59:47 / Claus Gittinger"
|
|
873 |
"Modified: / 06-01-2019 / 21:32:59 / Claus Gittinger"
|
|
874 |
!
|
|
875 |
|
|
876 |
writeCSVToStream:aStream
|
|
877 |
"save myself as CSV onto a stream"
|
|
878 |
|
|
879 |
columnNames
|
|
880 |
do:[:nm |
|
|
881 |
(nm includes:$;) ifTrue:[
|
|
882 |
aStream nextPut:$"; nextPutAll:nm; nextPut:$".
|
|
883 |
] ifFalse:[
|
|
884 |
aStream nextPutAll:nm
|
|
885 |
]]
|
|
886 |
separatedBy:[aStream nextPut:$;].
|
|
887 |
aStream cr.
|
|
888 |
rowData do:[:row |
|
|
889 |
row
|
|
890 |
do:[:col |
|
|
891 |
|s|
|
|
892 |
s := col printString.
|
|
893 |
(s includes:$;) ifTrue:[
|
|
894 |
aStream nextPut:$"; nextPutAll:s; nextPut:$".
|
|
895 |
] ifFalse:[
|
|
896 |
aStream nextPutAll:s
|
|
897 |
]
|
|
898 |
]
|
|
899 |
separatedBy:[aStream nextPut:$;].
|
|
900 |
aStream cr.
|
|
901 |
].
|
|
902 |
|
|
903 |
"
|
|
904 |
|data tmax|
|
|
905 |
|
|
906 |
data := self fromFile:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'.
|
|
907 |
tmax := data withColumnsNamed:#('MESS_DATUM' 'TXK' 'TNK').
|
|
908 |
String streamContents:[:s | tmax writeCSVToStream:s]
|
|
909 |
"
|
|
910 |
|
|
911 |
"Created: / 09-01-2019 / 17:48:25 / Claus Gittinger"
|
|
912 |
! !
|
|
913 |
|
|
914 |
!TableData methodsFor:'processing'!
|
|
915 |
|
|
916 |
removeColumn:index
|
|
917 |
"destructively remove a column"
|
|
918 |
|
|
919 |
columnNames := columnNames copyWithoutIndex:index.
|
|
920 |
rowData := rowData collect:[:row | row copyWithoutIndex:index].
|
|
921 |
|
|
922 |
"
|
|
923 |
self new
|
|
924 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
|
|
925 |
removeColumn:1;
|
|
926 |
inspect.
|
|
927 |
"
|
|
928 |
|
|
929 |
"Created: / 06-01-2019 / 13:05:41 / Claus Gittinger"
|
|
930 |
"Modified (comment): / 09-01-2019 / 12:13:50 / Claus Gittinger"
|
|
931 |
!
|
|
932 |
|
|
933 |
removeColumnNamed:name
|
|
934 |
"destructively remove a column"
|
|
935 |
|
|
936 |
self removeColumn:(self indexOfColumnNamed:name)
|
|
937 |
|
|
938 |
"
|
|
939 |
self new
|
|
940 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
|
|
941 |
removeColumnNamed:'STATIONS_ID';
|
|
942 |
removeColumnNamed:'QN_3';
|
|
943 |
removeColumnNamed:'FX';
|
|
944 |
removeColumnNamed:'FM';
|
|
945 |
removeColumnNamed:'RSK';
|
|
946 |
removeColumnNamed:'RSKF';
|
|
947 |
removeColumnNamed:'SDK';
|
|
948 |
removeColumnNamed:'SHK_TAG';
|
|
949 |
removeColumnNamed:'NM';
|
|
950 |
removeColumnNamed:'VPM';
|
|
951 |
removeColumnNamed:'PM';
|
|
952 |
removeColumnNamed:'TMK';
|
|
953 |
removeColumnNamed:'UPM';
|
|
954 |
removeColumnNamed:'eor';
|
|
955 |
inspect.
|
|
956 |
"
|
|
957 |
|
|
958 |
"/ StringCollection('MESS_DATUM' 'QN_3' 'FX' 'FM' 'QN_4' 'RSK' 'RSKF' 'SDK' 'SHK_TAG' 'NM' 'VPM' 'PM' 'TMK' 'UPM' 'TXK' 'TNK' 'TGK' 'eor')
|
|
959 |
|
|
960 |
"Created: / 06-01-2019 / 13:06:50 / Claus Gittinger"
|
|
961 |
"Modified (comment): / 09-01-2019 / 12:13:53 / Claus Gittinger"
|
|
962 |
!
|
|
963 |
|
|
964 |
withColumns:indexCollection
|
|
965 |
"return a new TableData instance, containing only the given columns"
|
|
966 |
|
|
967 |
|remainingNames|
|
|
968 |
|
|
969 |
remainingNames := indexCollection collect:[:colIdx | columnNames at:colIdx] as:Array.
|
|
970 |
^ self class
|
|
971 |
rows:(rowData collect:[:row |
|
|
972 |
indexCollection collect:[:colIdx | row at:colIdx] as:Array
|
|
973 |
])
|
|
974 |
columnNames:remainingNames.
|
|
975 |
|
|
976 |
"
|
|
977 |
(self fromFile:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
978 |
withColumns:#(1 2 3).
|
|
979 |
"
|
|
980 |
|
|
981 |
"Created: / 06-01-2019 / 14:35:11 / Claus Gittinger"
|
|
982 |
"Modified (comment): / 09-01-2019 / 12:13:57 / Claus Gittinger"
|
|
983 |
!
|
|
984 |
|
|
985 |
withColumnsNamed:nameCollection
|
|
986 |
"return a new TableData instance, containing only the given columns"
|
|
987 |
|
|
988 |
^ self withColumns:(nameCollection collect:[:nm |self indexOfColumnNamed:nm])
|
|
989 |
|
|
990 |
"
|
|
991 |
(self fromFile:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
992 |
withColumnsNamed:#('MESS_DATUM' 'TXK').
|
|
993 |
"
|
|
994 |
|
|
995 |
"Created: / 06-01-2019 / 14:36:16 / Claus Gittinger"
|
|
996 |
"Modified (comment): / 09-01-2019 / 12:13:45 / Claus Gittinger"
|
|
997 |
!
|
|
998 |
|
|
999 |
withoutColumn:index
|
|
1000 |
"return a new TableData instance, without the given columns"
|
|
1001 |
|
|
1002 |
^ self class
|
|
1003 |
rows:(rowData collect:[:row | row copyWithoutIndex:index])
|
|
1004 |
columnNames:(columnNames copyWithoutIndex:index).
|
|
1005 |
|
|
1006 |
"
|
|
1007 |
self new
|
4789
|
1008 |
readCSV:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
|
4781
|
1009 |
withoutColumn:1.
|
|
1010 |
"
|
|
1011 |
|
|
1012 |
"Created: / 06-01-2019 / 13:27:11 / Claus Gittinger"
|
4789
|
1013 |
"Modified (comment): / 10-01-2019 / 16:25:56 / Claus Gittinger"
|
4781
|
1014 |
!
|
|
1015 |
|
|
1016 |
withoutColumns:indexCollection
|
|
1017 |
"return a new TableData instance, without the given columns"
|
|
1018 |
|
|
1019 |
|remainingColIndices remainingNames|
|
|
1020 |
|
|
1021 |
remainingColIndices := (1 to:columnNames size) asNewOrderedCollection removeAll:indexCollection; yourself.
|
|
1022 |
remainingNames := remainingColIndices collect:[:colIdx | columnNames at:colIdx] as:Array.
|
|
1023 |
^ self class
|
|
1024 |
rows:(rowData collect:[:row |
|
|
1025 |
remainingColIndices collect:[:colIdx | row at:colIdx] as:Array
|
|
1026 |
])
|
|
1027 |
columnNames:remainingNames.
|
|
1028 |
|
|
1029 |
"
|
|
1030 |
(self fromFile:'~/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt')
|
|
1031 |
withoutColumns:#(1 2 3).
|
|
1032 |
"
|
|
1033 |
|
|
1034 |
"Created: / 06-01-2019 / 14:32:08 / Claus Gittinger"
|
|
1035 |
"Modified (comment): / 09-01-2019 / 12:14:29 / Claus Gittinger"
|
|
1036 |
! !
|
|
1037 |
|
|
1038 |
!TableData methodsFor:'reading'!
|
|
1039 |
|
|
1040 |
readCSV:filename
|
|
1041 |
^ self readCSV:filename separator:$;
|
|
1042 |
|
|
1043 |
"
|
|
1044 |
self new
|
|
1045 |
readCSV:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
|
|
1046 |
inspect.
|
|
1047 |
"
|
|
1048 |
|
|
1049 |
"Created: / 09-01-2019 / 12:07:27 / Claus Gittinger"
|
|
1050 |
!
|
|
1051 |
|
|
1052 |
readCSV:filename separator:separatorCharacter
|
|
1053 |
|headLine numCols dataLine ls word row rows|
|
|
1054 |
|
|
1055 |
filename asFilename readingFileDo:[:s |
|
|
1056 |
rows := OrderedCollection new.
|
|
1057 |
headLine := s nextLine.
|
|
1058 |
numCols := (headLine occurrencesOf:separatorCharacter)+1.
|
|
1059 |
columnNames := (headLine splitBy:separatorCharacter) collect:#withoutSeparators.
|
|
1060 |
[s atEnd] whileFalse:[
|
|
1061 |
dataLine := s nextLine.
|
|
1062 |
ls := dataLine readStream.
|
|
1063 |
row := OrderedCollection new:numCols.
|
|
1064 |
[ls atEnd] whileFalse:[
|
|
1065 |
ls skipSeparators.
|
|
1066 |
word := (ls upTo:separatorCharacter) withoutSeparators.
|
|
1067 |
row add:word.
|
|
1068 |
].
|
|
1069 |
rows add:(row asArray).
|
|
1070 |
].
|
|
1071 |
].
|
|
1072 |
rowData := rows.
|
|
1073 |
|
|
1074 |
"
|
|
1075 |
self new
|
|
1076 |
readCSV:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt';
|
|
1077 |
inspect.
|
|
1078 |
"
|
|
1079 |
|
|
1080 |
"Created: / 09-01-2019 / 12:11:11 / Claus Gittinger"
|
|
1081 |
!
|
|
1082 |
|
|
1083 |
readDemoCSV
|
|
1084 |
self readCSV:'/Users/cg/Documents/klima/data/DWD/daily/kl/historical/produkt_klima_tag_19450101_20171231_01346.txt'.
|
|
1085 |
|
|
1086 |
"Created: / 09-01-2019 / 12:07:52 / Claus Gittinger"
|
|
1087 |
! !
|
|
1088 |
|
|
1089 |
!TableData class methodsFor:'documentation'!
|
|
1090 |
|
|
1091 |
version_CVS
|
|
1092 |
^ '$Header$'
|
|
1093 |
! !
|
|
1094 |
|