root/misc/StationData/stationdata.pro

Revision 820, 22.6 kB (checked in by mankoff, 10 months ago)

update legend link too..

Line 
1
2
3function load_GHCN_station_list, restore=restore
4
5if keyword_set(restore) then begin
6    restore,file='v2.temperature.inv.txt.sav'
7    return, s
8endif
9
10file = 'v2.temperature.inv.txt'
11;               012  7   10      42   48   56
12fmt = '          A3, A5, A3,     A32, F7.2,F8.2,I5, I4,  A1,I5, A2,A2,A2,I2,A1,I2,A16,A1'
13readfmt,file,fmt,icc,wmo,wmo_mod,name,lat, lon, ele,tele,p, pop,tp,v, lo,co,a, ds,veg,bi,skipline=38
14name = STRCOMPRESS(name)
15s = { GHCN_station_list, $
16      icc: '', wmo: '', wmo_mod: '', name: '', $
17      lat: 0.0, lon: 0.0, $
18      ele: 0, tele:0, p:'', pop:0, tp:'', v:'', lo:'', co:0, $
19      a:'', ds:0, veg:'', bi:'' }
20s = REPLICATE( s, n_elements(icc) )
21s.icc = icc & s.wmo = wmo & s.wmo_mod = wmo_mod & s.name=name
22s.lat = lat & s.lon = lon
23s.ele = ele & s.tele = tele & s.p = p & s.pop=pop & s.tp=tp & s.v=v
24s.lo = lo & s.co=co & s.a=a & s.ds=ds & s.veg=veg & s.bi=bi
25save, s,file='v2.temperature.inv.txt.sav'
26return, s
27end
28
29
30function load_GISS_station_list, restore=restore
31
32if keyword_set(restore) then begin
33    restore, file='station_list.txt.sav'
34    return, s
35endif
36
37file='station_list.txt'
38fmt = '          A5, A3,     A1, A1,     A32, A35,  A3'
39readfmt,file,fmt,wmo,wmo_mod,n,  dummy,  name,dummy,cc, skipline=1
40name = STRCOMPRESS(name)
41wmo = STRING(wmo,FORMAT='(I5.5)')
42wmo_mod = STRING(wmo_mod,FORMAT='(I3.3)')
43cc = STRING(cc,FORMAT='(I3.3)')
44s = { GISS_station_list, wmo:'', wmo_mod: '', n:'', name:'', icc:'' }
45s = REPLICATE( s, n_elements(n) )
46s.wmo = wmo & s.wmo_mod=wmo_mod & s.n=n & s.name=name & s.icc=cc
47save, s, file='station_list.txt.sav'
48return, s
49end
50
51
52function load_station_data, giss, ghcn, restore=restore
53
54if keyword_set(restore) then begin
55    restore, 'station_data.sav'
56    return, s
57endif
58
59ns = n_elements(GISS)
60nyr = 2010-1880
61arr = fltarr( nyr )
62s0 = { months, data:fltarr( nyr, 12 ), $
63       names:['January','February','March','April','May','Jun',$
64              'July','August','September','October','November','December'] }
65s1 = { seasons, data:fltarr( nyr, 4 ), $
66       names:['DJF','MAM','JJA','SON'] }
67s = { station_data, $
68      icc: '', wmo: '', wmo_mod: '', name: '', $
69      years: arr, $
70      annual: arr, $
71      months: s0, $
72      seasons: s1 }
73s = replicate( s, ns )
74
75for i = 0, ns-1 do begin
76;for i = 5308, 5319 do begin ; testing
77;for i = 5308, ns-1 do begin ; testing
78    station = giss[i].icc + giss[i].wmo + giss[i].wmo_mod + giss[i].n
79    file = FINDFILE('./data/'+station+'*.txt')
80    if n_elements(file) ne 1 then stop else file = file[0]
81    if file eq '' then continue
82    readcol, file, year,jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec,djf,mam,jja,son,ann, skipline=1, /silent
83    s[i].icc = giss[i].icc
84    s[i].wmo = giss[i].wmo
85    s[i].wmo_mod = giss[i].wmo_mod
86    s[i].name = giss[i].name
87
88    s[i].years = year
89    s[i].months.data[0:n_elements(year)-1,0:11] = $
90      [[jan],[feb],[mar],[apr],[may],[jun], $
91       [jul],[aug],[sep],[oct],[nov],[dec]]
92    s[i].seasons.data[0:n_elements(year)-1,0:3] = [[djf],[mam],[jja],[son]]
93    s[i].annual = ann
94    ygd = where( s[i].years ne 0, count )
95    if count ne 0 then begin
96       y0 = min( s[i].years[ygd] )
97       s[i].years = SHIFT( s[i].years, y0-1880 )
98       s[i].months.data = SHIFT( s[i].months.data, y0-1880 )
99       s[i].seasons.data = SHIFT( s[i].seasons.data, y0-1880 )
100       s[i].annual = SHIFT( s[i].annual, y0-1880 )
101    endif
102
103    print, i
104endfor
105save, s, filename='station_data.sav'
106return, s
107end
108
109
110
111
112
113
114
115pro load_panoply,r,g,b
116openr, lun, 'panoply_diff.pa1', /get
117r = ( g = ( b = bytarr(256) ) )
118a = assoc(lun, r)
119
120; load to IDL
121r = a[0] & g = a[1] & b = a[2]
122r[0] = ( g[0] = ( b[0] = 0 ) )
123r[255] = ( g[255] = ( b[255] = 255 ) )
124r[254] = ( g[254] = ( b[254] = 192 ) )
125tvlct,r,g,b
126
127; return basic color vectors, 8 blue 8 red
128r = a[0]
129g = a[1]
130b = a[2]
131subset = makex(8,256,16)
132r = r[subset]
133g = g[subset]
134b = b[subset]
135free_lun, lun
136end
137
138
139
140
141
142function make_meta_data, giss, ghcn, data, restore=restore
143if keyword_set(restore) then begin
144    restore, 'meta.sav'
145    return, s
146end
147s = { wmo: '', wmo_mod: '', icc: '', $
148      baseline: 0.0, nbaselineyr: 0, $
149      mall: 0.0, ball: 0.0, nall: 0, $
150      m100: 0.0, b100: 0.0, n100: 0, $
151      m50: 0.0, b50: 0.0, n50: 0, $
152      m25: 0.0, b25: 0.0, n25: 0, $
153      m2000: 0.0, b2000: 0.0, n2000: 0, $
154      m1990: 0.0, b1990: 0.0, n1990: 0, $
155      m1980: 0.0, b1980: 0.0, n1980: 0, $
156      m1970: 0.0, b1970: 0.0, n1970: 0, $
157      m1960: 0.0, b1960: 0.0, n1960: 0, $
158      m1950: 0.0, b1950: 0.0, n1950: 0 }
159s = replicate(s,n_elements(giss))
160for i=0, n_elements( giss )-1 do begin
161
162    giss_idx = i & print, i
163    s[i].wmo = giss[giss_idx].wmo
164    s[i].wmo_mod = giss[giss_idx].wmo_mod
165    s[i].icc = giss[giss_idx].icc
166
167    ghcn_idx = where( giss[giss_idx].wmo eq ghcn.wmo AND $
168                      giss[giss_idx].wmo_mod eq ghcn.wmo_mod AND $
169                      giss[giss_idx].icc eq ghcn.icc, n )
170    if n ne 1 then stop else ghcn_idx = ghcn_idx[0]
171    data_idx = where( giss[giss_idx].wmo eq data.wmo AND $
172                      giss[giss_idx].wmo_mod eq data.wmo_mod AND $
173                      giss[giss_idx].icc eq data.icc, n )
174    ;if n ne 1 then stop else data_idx = data_idx[0]
175    if n eq 0 then continue
176    if n ne 1 then data_idx = data_idx[0]
177
178    ; 1951 to 1980 baseline
179    baseyears = where( data[data_idx].years ge 1951 and $
180                       data[data_idx].years le 1980 AND $
181                       data[data_idx].years ne 0 AND $
182                       data[data_idx].annual ne 999.9, n )
183    if n ge 2 then begin
184        s[i].baseline = total(data[data_idx].annual[baseyears]) / float(n)
185        s[i].nbaselineyr = n
186    endif
187
188    ; 1st order line fit for all available years
189    gd = where( data[data_idx].years ne 0 AND $
190                data[data_idx].annual ne 999.9, n )
191    if n ge 2 then begin
192        s[i].nall = n
193        line = indgen(n_elements(data[data_idx].years))
194        r1 = poly_fit( line[gd], data[data_idx].annual[gd], 1 )
195        s[i].ball = r1[0]
196        s[i].mall = r1[1]
197    endif
198
199    ; 1st order line fit for last 100 years
200    gd = where( data[data_idx].years ne 0 AND $
201                data[data_idx].annual ne 999.9 AND $
202                data[data_idx].years GE 1908, n )
203    if n ge 2 then begin
204        s[i].n100 = n
205        line = indgen(n_elements(data[data_idx].years))
206        r1 = poly_fit( line[gd], data[data_idx].annual[gd], 1 )
207        s[i].b100 = r1[0]
208        s[i].m100 = r1[1]
209    endif
210
211    ; 1st order line fit for last 50 years
212    gd = where( data[data_idx].years ne 0 AND $
213                data[data_idx].annual ne 999.9 AND $
214                data[data_idx].years GE 1958, n )
215    if n ge 2 then begin
216        s[i].n50 = n
217        line = indgen(n_elements(data[data_idx].years))
218        r1 = poly_fit( line[gd], data[data_idx].annual[gd], 1 )
219        s[i].b50 = r1[0]
220        s[i].m50 = r1[1]
221    endif
222
223    ; 1st order line fit for last 25 years
224    gd = where( data[data_idx].years ne 0 AND $
225                data[data_idx].annual ne 999.9 AND $
226                data[data_idx].years GE 1983, n )
227    if n ge 2 then begin
228        s[i].n25 = n
229        line = indgen(n_elements(data[data_idx].years))
230        r1 = poly_fit( line[gd], data[data_idx].annual[gd], 1 )
231        s[i].b25 = r1[0]
232        s[i].m25 = r1[1]
233    endif
234
235
236    ; every decade!
237    for yr=1950,2000,10 do begin
238       gd = where( data[data_idx].years ne 0 AND $
239                   data[data_idx].annual ne 999.9 AND $
240                   data[data_idx].years GE yr AND $
241                   data[data_idx].years LE yr+9, n )
242       if n ge 2 then begin
243          str = 's[i].n'+STRTRIM(yr,2)+'=n' & dummy=execute(str)
244          line = indgen(n_elements(data[data_idx].years))
245          r1 = poly_fit( line[gd], data[data_idx].annual[gd], 1 )
246          str = 's[i].b'+STRTRIM(yr,2)+'= r1[0]' & dummy=execute(str)
247          str = 's[i].m'+STRTRIM(yr,2)+' = r1[1]' & dummy=execute(str)
248       endif
249    endfor
250 endfor
251
252save, s, filename='meta.sav'
253end
254
255
256
257
258
259
260pro make_img, s
261; s stands for 'station'
262
263sname = s.icc + s.wmo + s.wmo_mod
264if sname eq '' then return
265
266set_plot,'ps'
267device, /color, bits=8, filename='images/'+sname+'.ps'
268load_panoply
269
270nyrs = n_elements(where( s.years ne 0 ) )
271if nyrs le 20 then MESSAGE, "Less than 20 data points at this station", /CONTINUE
272
273dd = s.months.data
274bad = where( dd eq 0 or dd eq 999.90, nbad, complement=gd, ncomplement=ngd )
275if n_elements(gd) le 2 then begin
276   MESSAGE, "Error... Not enough data to produce image", /CONTINUE
277   return
278end
279img = BYTSCL( dd, min=min(dd[gd]), max=max(dd[gd]), top=252 )+1 ; 1 to 253
280img[ bad ] = 254
281erase
282
283; rather than having a keyogram-ish type display with 12 (Jan -> Dec)
284; rather than -90 -> 90, I'm making it 18 high. This way you can easily
285; see an entire winter or summer season. Shift the addition by 1 year so that
286; Dec of Year X moves up 1 pixel to Jan of Year X+1. Then, because
287; we shifted, invalidate the shift wrap.
288; img = [[img[*,0:*]],[SHIFT(img[*,0:5],-1)]]
289; img[ n_elements(img[*,0])-1, 12:* ] = 254
290
291!p.thick=3
292!p.charthick=3
293!p.charsize=1.0
294!x.thick=3
295!y.thick=3
296
297
298position = [ 0.12, 0.55, 0.88, 0.925 ]
299
300gd = where( s.annual ne 0 and s.annual ne 999.90 and s.years ne 0, ngd, complement=bad, ncomplement=nbad )
301plotg, s.years[gd], s.annual[gd], $
302       /yno, gval=224, $
303       xrange=[1880,2010], /xst,psym=2, xminor=2, $
304;       xticklen=-0.01, yticklen=-0.01, $
305       ;xtitle='Time (Years)', $
306       ytitle='Temperature (Degrees C)', $
307       title=s.name, $
308       position=position, thick=1, /nodata
309
310;10 year smooth
311ann = s.annual
312if nbad ge 1 then ann[bad] = !values.f_nan
313anns = smooth( ann, 10, /nan, /EDGE )
314oplot, s.years[gd], anns[gd], thick=30, color=254
315
316; overplot the asterisks
317oplot, s.years[gd], s.annual[gd], psym=2, thick=1
318
319
320; 1st order line fit to ALL data
321gd = where( s.annual ne 999.90 AND s.years NE 0 )
322line = indgen(n_elements(s.years))
323r1 = poly_fit( line[gd], s.annual[gd], 1 )
324fit1 = r1[0] + r1[1]*line
325oplot, s.years[gd], fit1[gd],color=0
326
327; 1st order line fit to last 50 years
328gd = where( s.annual ne 999.90 and s.years ne 0 and s.years ge 2007-50, n )
329if n ge 30 then begin
330   line = indgen(n_elements(s.years))
331   r1 = poly_fit( line[gd], s.annual[gd], 1 )
332   fit1 = r1[0] + r1[1]*line
333   oplot, s.years[gd], fit1[gd],color=150,thick=10
334endif
335; 1st order line fit to last 25 years
336gd = where( s.annual ne 999.90 and s.years ne 0 and s.years ge 2007-25, n )
337if n ge 15 then begin
338   line = indgen(n_elements(s.years))
339   r1 = poly_fit( line[gd], s.annual[gd], 1 )
340   fit1 = r1[0] + r1[1]*line
341   oplot, s.years[gd], fit1[gd],color=200,thick=10
342endif
343; 1st order line fit to last decade
344gd = where( s.annual ne 999.90 and s.years ne 0 and s.years ge 2007-10, n )
345if n ge 4 then begin
346   line = indgen(n_elements(s.years))
347   r1 = poly_fit( line[gd], s.annual[gd], 1 )
348   fit1 = r1[0] + r1[1]*line
349   oplot, s.years[gd], fit1[gd],color=250,thick=10
350endif
351
352
353position = [ position[0], 0.3, position[2], 0.475 ]
354top = position[3]
355imdisp, img, /noscale, aspect=0.2, /axis, /ystyle, order=1, $
356        xrange=[1880,2010]-0.5, $
357        xtickn=congrid([' '],60), $
358        yticks=2, $
359        ytickv=[0,5.5,11]+0.5, $
360        ytickn=['Jan','Jun','Dec'], $
361        yticklen=-0.01, xticklen=-0.1, $
362;        ytitle='Time (Months)', $
363        position=position, /usepos
364;axis, /yaxis, yminor=1, yticklen=0.00001, yticks=1, ytickn=[' ',' ']
365
366position[[1,3]] = position[[1,3]]-0.19
367bot = position[1]
368img = shift( img, 0, 6 )
369img[ *, 0:5 ] = SHIFT( img[ *, 0:5 ], 1 )
370img[ n_elements(img[*,0])-1, 0:5] = 254
371imdisp, img, /noscale, aspect=0.2, /axis, /ystyle, order=1, $
372        xrange=[1880,2010]-0.5, $
373        xtickn=congrid([' '],60), $
374        yticks=2, $
375        ytickv=[0,5.5,11]+0.5, $
376        ytickn=['July','Dec','Jun'], $
377        yticklen=-0.01, xticklen=-0.1, $
378;        xtitle='Time (Years)', $
379;        ytitle='Time (Months)', $
380        position=position, /usepos
381
382bad = where( dd eq 0 or dd eq 999.90, nbad, complement=gd, ncomplement=ngd )
383colorbar, bottom=1, $
384          divisions=1, $
385          maxrange=max(dd[gd]), $
386          minrange=min(dd[gd]), $
387          minor=1, $
388          yticklen=1, $
389          ncolors=252, $
390          position=[ bot, 0.90, top, 0.92 ], $
391          title='Temp (Deg. C)', $
392          /right, /vertical
393       
394
395
396;gd = where( s.years ne 0 and s.annual ne 999.90 )
397;axis, /yaxis, /save, yrange=minmax(s.annual[gd])+[-2,2], yminor=1, yticklen=-0.01
398;oplot, s.years, s.annual, color=0, thick=2, psym=2
399
400device, /close
401;spawn, 'convert images/'+sname+'.ps ./images/'+sname+'.png'
402set_plot,'x'
403end
404
405
406
407
408
409
410pro makeKML, giss, ghcn, data, meta
411openw, lun, 'StationData_net.kml', /get_lun
412printf, lun, '<?xml version="1.0" encoding="UTF-8"?>'
413printf, lun, '<kml xmlns="http://earth.google.com/kml/2.1">'
414printf, lun, '<Document>'
415
416printf, lun, '<Folder>'
417printf, lun, '<name>Station Data (2000 Anomaly)</name>'
418for i=0,n_elements(giss)-1 do begin
419;for i=0,100 do begin
420    print, i
421
422    giss_idx = i
423    meta_idx =  where( giss[giss_idx].icc eq meta.icc AND $
424                       giss[giss_idx].wmo eq meta.wmo AND $
425                       giss[giss_idx].wmo_mod eq meta.wmo_mod, n )
426    if n eq 0 then continue
427    meta_idx = meta_idx[0]
428    ghcn_idx =  where( giss[giss_idx].icc eq ghcn.icc AND $
429                       giss[giss_idx].wmo eq ghcn.wmo AND $
430                       giss[giss_idx].wmo_mod eq ghcn.wmo_mod, n )
431    if n eq 0 then continue
432    ghcn_idx = ghcn_idx[0]
433    data_idx =  where( giss[giss_idx].icc eq data.icc AND $
434                       giss[giss_idx].wmo eq data.wmo AND $
435                       giss[giss_idx].wmo_mod eq data.wmo_mod, n )
436    if n eq 0 then continue
437    data_idx = data_idx[0]
438
439;    if meta[meta_idx].nbaselineyr le 10 then continue
440;    if meta[meta_idx].m25 eq 0 then continue
441
442    if STRPOS( giss[giss_idx].name, "&" ) NE -1 then $
443      giss[giss_idx].name = $
444      STRJOIN(STRSPLIT(giss[giss_idx].name,'&',/EXTRACT),'and')
445   
446   printf, lun, '<Placemark>'
447   printf, lun, '  <name>'+STRTRIM(giss[giss_idx].name,2)+'</name>'
448   printf, lun, '  <Snippet></Snippet>'
449
450   printf, lun, '  <description><![CDATA['
451   description, lun, $
452                giss[giss_idx].icc, $
453                giss[giss_idx].wmo, $
454                giss[giss_idx].wmo_mod, $
455                giss[giss_idx].name
456   printf, lun, '  ]]></description>'
457
458   printf, lun, '  <Point>'
459   printf, lun, '    <coordinates>'+ $
460           STRTRIM(ghcn[ghcn_idx].lon,2)+','+STRTRIM(ghcn[ghcn_idx].lat,2)+ $
461           '    </coordinates>'
462   printf, lun, '  </Point>'
463
464
465   icon, lun, giss[giss_idx], ghcn[ghcn_idx], meta[meta_idx], data[data_idx]
466
467   printf, lun, '</Placemark>'
468   printf, lun, ' '
469endfor
470
471printf, lun, '</Folder>'
472printf, lun, '</Document>'
473printf, lun, '</kml>'
474free_lun, lun
475end
476
477
478
479
480
481
482
483pro description, lun,icc,wmo,wmo_mod,name
484printf, lun, '    <center>'
485printf, lun, '      <img src="http://edgcm.columbia.edu/~mankoff/StationData/images/'+ $
486        icc+wmo+wmo_mod+'.ps.png">'
487printf, lun, '    </center>'
488
489spawn, 'grep '+icc+wmo+wmo_mod+' v2.temperature.inv.txt', out
490printf, lun, '    <font size=-1>'
491printf, lun, '      <pre>'
492printf, lun, 'iccWMO_#... Name                              Lat     Lon Elev TEleP Pop Tp VLoCoAds------Vege------bi'
493printf, lun, out
494printf, lun, '<a href="http://edgcm.columbia.edu/~mankoff/StationData/v2.temperature.inv.txt">legend</a>'
495printf, lun, '      </pre>'
496printf, lun, '    </font>'
497
498station = icc + wmo + wmo_mod
499file = FINDFILE('data/'+station+'*.txt')
500file = file[0]
501file = strmid(file,strpos(file,'/',/reverse_search)+1,100) ; just the name
502printf, lun, '    <font size=-1>' + $
503        '<a href="http://edgcm.columbia.edu/~mankoff/StationData/data/'+ $
504        file+'">station data file</a></font><br><br>'
505
506printf, lun, '    <font size=-1>Produced by ' + $
507        '<a href="mailto:mankoff@giss.nasa.gov">Ken Mankoff</a>'
508printf, lun, 'for <a href="http://EdGCM.columbia.edu"</a>EdGCM</a>'
509printf, lun, '    <br>'
510printf, lun, '    Source: <a ' + $
511        'href="http://data.giss.nasa.gov/gistemp/station_data/">NASA ' + $
512        'GISS Temperature Station Data</a></font>'
513end
514
515
516pro icon, lun, giss, ghcn, meta, data
517
518; load the colors. r,g,b are 16 long. 0 through 7 are 'cold' and
519; 8 through 15 are 'warm'. White is not in the colorbar.
520load_panoply,r,g,b
521
522printf, lun, '<Style>'
523printf, lun, '<IconStyle>'
524
525
526; size is number of years of data
527num_pts = n_elements(where( data.annual NE 999.90 AND data.years NE 0 ) )
528size = KDM_RANGE( num_pts, 0.5, 1.5, $
529                  datamin = 30, datamax = 2010-1880+30, $
530                  underflow = 0.5, overflow = 1.5 )
531
532
533; opacity is inverse proximity to city
534opaque = KDM_RANGE( ghcn.pop, 128,255, $
535                    datamin = 10, datamax = 20000, $
536                    underflow = 128, overflow = 255 )
537alpha = STRING( 255-opaque+128, FORMAT='(Z2.2)')
538
539
540
541gd0 = where( data.years ge 1951 and $
542             data.years le 1981 and $
543             data.years ne 0 and $
544             data.annual ne 999.9, n0 )
545gd1 = where( data.years ge 2000 and $
546             data.years ne 0 and $
547             data.annual ne 999.9, n1 )
548if n0 le 10 OR n1 lt 4 then begin
549   bb = 'ff' & gg = 'ff' & rr = 'ff'
550endif else begin
551   base = mean( data.annual[gd0] )
552   diff = mean( data.annual[gd1] )
553   ctidx = KDM_RANGE( diff-base, 0,15, $
554                      datamin=-3, datamax=3, $
555                      underflow=0, overflow=15 )
556   bb = b[ctidx] & gg = g[ctidx] & rr = r[ctidx]
557   bb = string(bb,format='(Z2.2)')
558   gg = string(gg,format='(Z2.2)')
559   rr = string(rr,format='(Z2.2)')
560;   if abs(diff-base) lt 0.1 then begin
561;      bb = 'ff' & gg = 'ff' & rr = 'ff'
562;   endif
563endelse
564
565printf, lun, '<scale>', + STRTRIM(size,2) + '</scale>'
566printf, lun, '<color>'+alpha+bb+gg+rr+'</color>'
567
568; Airport or not (use airplane icon)
569printf, lun, '<Icon>'
570;; Airplane icon shows up blue (Google Earth bug?), so only do pins...
571;; printf, lun, ghcn.a eq 'A'?  $
572;;         '<href>http://maps.google.com/mapfiles/kml/pal2/icon56.png</href>' : $
573;;         '<href>http://maps.google.com/mapfiles/kml/paddle/wht-blank.png</href>'
574printf, lun, '<href>http://maps.google.com/mapfiles/kml/paddle/wht-blank.png</href>'
575printf, lun, '</Icon>'
576
577printf, lun, '</IconStyle>'
578printf, lun, '</Style>'
579end
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613pro write_vp
614giss = load_giss_station_list(/restore)
615ghcn = LOAD_GHCN_STATION_LIST(/restore)
616data = load_station_data(/restore)
617;meta = make_meta_data(/restore)
618
619p_lut = ['R','S','U']
620tp_lut = ['FL', 'HI', 'MT', 'MV']
621v_lut = ['DE', 'FO', 'IC', 'MA', 'xx']
622bi_lut = ['A','B','C']
623
624openw, lun, 'vp.txt', /get_lun, width=512
625printf, lun, '#lon lat ele tele pop co ds p tp v bi ' + $
626        'nbaseyrs baseT recentT ' + $
627        'trend_all, trend25'
628for i=0, n_elements(giss)-1 do begin
629   giss_idx = i
630   ghcn_idx = where( giss[giss_idx].wmo eq ghcn.wmo AND $
631                     giss[giss_idx].wmo_mod eq ghcn.wmo_mod AND $
632                     giss[giss_idx].icc eq ghcn.icc, nghcn )
633   if nghcn eq 0 then continue
634   if nghcn ge 1 then ghcn_idx = ghcn_idx[0]
635   data_idx = where( giss[giss_idx].wmo eq data.wmo AND $
636                     giss[giss_idx].wmo_mod eq data.wmo_mod AND $
637                     giss[giss_idx].icc eq data.icc, ndata )
638   if ndata eq 0 then continue
639   if ndata ge 1 then data_idx = data_idx[0]
640;;     meta_idx = where( giss[giss_idx].wmo eq meta.wmo AND $
641;;                       giss[giss_idx].wmo_mod eq meta.wmo_mod AND $
642;;                       giss[giss_idx].icc eq meta.icc, nmeta )
643;;     if nmeta eq 0 then continue
644;;     if nmeta ge 1 then meta_idx = meta_idx[0]
645   
646; save GHCN everything and the data NumYears, baseline, and last decade
647; ghcn.lat,lon,ele,tele,pop,co,ds
648
649   p = where( ghcn[ghcn_idx].p eq p_lut )
650   tp = where( ghcn[ghcn_idx].tp eq tp_lut )
651   v = where( ghcn[ghcn_idx].v eq v_lut )
652   bi = where( ghcn[ghcn_idx].bi eq bi_lut )
653   
654   ; record the number of baseline years
655   nbaseyears = -999 & baselinetemp = -999
656   baseyears = where( data[data_idx].years ge 1951 and $
657                      data[data_idx].years le 1980 AND $
658                      data[data_idx].years ne 0 AND $
659                      data[data_idx].annual ne 999.9, nbaseyears )
660   ; record the baseline temperature
661   if nbaseyears gt 10 then $
662      baselinetemp = mean( data[data_idx].annual[baseyears] )
663
664   ; record the last 2k->present mean to compare with baseline
665   recent_t = -999
666   recent = where( data[data_idx].years ge 2000 and $
667                   data[data_idx].years ne 0 and $
668                   data[data_idx].annual ne 999.9, nrecent )
669   if nrecent ge 4 then $
670      recent_t = mean( data[data_idx].annual[recent] )
671   
672   ;; slope of 1st order line fit for all available years
673   trend_all = -999
674   gd = where( data[data_idx].years ne 0 AND $
675               data[data_idx].annual ne 999.9, n )
676   if n ge 2 then begin
677      line = indgen(n_elements(data[data_idx].years))
678      r1 = poly_fit( line[gd], data[data_idx].annual[gd], 1 )
679      trend_all = r1[1]
680   endif
681   
682   ;; trend for last 25 years
683   trend25 = -999
684   gd = where( data[data_idx].years ne 0 AND $
685               data[data_idx].annual ne 999.9 AND $
686               data[data_idx].years GE 1983, n )
687   if n ge 2 then begin
688      line = indgen(n_elements(data[data_idx].years))
689      r1 = poly_fit( line[gd], data[data_idx].annual[gd], 1 )
690      trend25 = r1[1]
691   endif
692   
693   printf, lun, $
694           ghcn[ghcn_idx].lon, $
695           ghcn[ghcn_idx].lat, $
696           ghcn[ghcn_idx].ele, $
697           ghcn[ghcn_idx].tele, $
698           ghcn[ghcn_idx].pop, $
699           ghcn[ghcn_idx].co, $
700           ghcn[ghcn_idx].ds, $
701           p[0],tp[0],v[0],bi[0], $
702           nbaseyears, baselinetemp, recent_t, $
703           trend_all, trend25
704   
705endfor
706free_lun, lun
707end
708
709
710pro stationdata
711
712; get all the data
713;
714; clean:
715;; giss = LOAD_GISS_STATION_LIST()
716;; ghcn = LOAD_GHCN_STATION_LIST()
717;; data = load_station_data(giss,ghcn)
718;; meta = make_meta_data(giss,ghcn,data)
719
720; quick:
721giss = LOAD_GISS_STATION_LIST(/restore)
722ghcn = LOAD_GHCN_STATION_LIST(/restore)
723data = load_station_data(/restore)
724meta = make_meta_data(/restore)
725
726;for i=0,100 do make_img, data[i]
727for i=0,n_elements(data)-1 do make_img, data[i]
728makeKML, giss, ghcn, data, meta
729
730; $ for v in *.ps; do convert $v $v.png; done
731; gzip the KML file
732; upload KML_net, images, and if changed, KML and CGI
733
734end
735
736
737
738
739
740
741
742; color is temperature trend, and
743; size is proximity to city (inverse)
744; opacity is number of years of data
745
746;; size is proximity to city (inverse)
747;; size = KDM_RANGE( ghcn.pop, 0,1, $
748;;                   datamin=10, datamax=20000, $
749;;                   underflow=0, overflow=1) ; scale 0 to 1
750;; size = 1.5-size ; invert. Cities are 0.5, rural is 1.5
751;; printf, lun, '<scale>', + STRTRIM(size,2) + '</scale>'
752
753;; ; opacity is number of years of data
754;; num_pts = n_elements(where( data.annual NE 999.90 AND data.years NE 0 ) )
755;; opaque = KDM_RANGE( num_pts, 128,255, datamin=25, datamax=2010-1880+30, $
756;;                     underflow=128, overflow=255)
757;; alpha = string(opaque,format='(Z2.2)')
Note: See TracBrowser for help on using the browser.