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