dataplot_txttimeseries.pro 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. pro plotts1, arrsv, title, typestr, minperc=minperc, $
  2. juldatemin=juldatemin, juldatemax=juldatemax, $
  3. emax=emax, emin=emin
  4. ;+--------------------------------------------------------
  5. ; plot mean and rms timeseries
  6. ;
  7. ; Author: D. J. Lea Feb 2008
  8. ;+--------------------------------------------------------
  9. ;date_label = LABEL_DATE(DATE_FORMAT = $
  10. ; ['%D %M, %Y'])
  11. ;date_label = LABEL_DATE(DATE_FORMAT = $
  12. ; ['%D', '%M, %Y'])
  13. ;date_label = LABEL_DATE(DATE_FORMAT = $
  14. ; ['%M %Y'])
  15. date_label = LABEL_DATE(DATE_FORMAT=['%D-%M','%Y'])
  16. ; sort times (in case of a repeated day)
  17. timsrt=sort(arrsv(0,*))
  18. taxis=arrsv(0,timsrt)
  19. num=arrsv(1,timsrt)
  20. yaxis=arrsv(2,timsrt)
  21. yaxis2=arrsv(3,timsrt)
  22. ; remove any zero times or non-finite values
  23. wh=where(taxis gt 0 and finite(yaxis) and finite(yaxis2))
  24. if (wh(0) gt -1) then begin
  25. taxis=taxis(wh)
  26. num=num(wh)
  27. yaxis=yaxis(wh)
  28. yaxis2=yaxis2(wh)
  29. endif
  30. ; remove any with num lt than a specific value
  31. if (n_elements(minperc) eq 1) then begin
  32. maxnum=max(num,min=minnum)
  33. wh=where(num gt maxnum*minperc)
  34. if (wh(0) gt -1) then begin
  35. taxis=taxis(wh)
  36. num=num(wh)
  37. yaxis=yaxis(wh)
  38. yaxis2=yaxis2(wh)
  39. endif
  40. endif
  41. mxt=max(taxis,min=mnt)
  42. print, 'mnt mxt ',mnt, mxt
  43. ymx=max([yaxis,yaxis2],min=ymn)
  44. print, 'ymn ymx ',ymn,ymx
  45. ;create a small amount of space around the max and min
  46. spc=(ymx-ymn)*0.05
  47. ymn=ymn-spc*3
  48. ymx=ymx+spc
  49. if (n_elements(emax) gt 0) then ymx=emax
  50. if (n_elements(emin) gt 0) then ymn=emin
  51. ; setup time axis range
  52. skip=0
  53. xmx=max(taxis,min=xmn)
  54. if (n_elements(juldatemin) gt 0) then begin
  55. if (xmn le juldatemin) then xmn=juldatemin
  56. if (xmx le juldatemin) then skip=1
  57. endif
  58. if (n_elements(juldatemax) gt 0) then begin
  59. if (xmx ge juldatemax) then xmx=juldatemax
  60. if (xmn ge juldatemin) then skip=1
  61. endif
  62. if (skip eq 0) then begin
  63. ;plot, arrsv(0,timsrt), arrsv(2,timsrt), xstyle=1, linestyle=1, $
  64. ; yrange=[ymn,ymx], $
  65. ; ytitle=typestr, title=title, $
  66. ; XTICKFORMAT = ['LABEL_DATE'], $
  67. ; XTICKUNITS = ['Day'], $
  68. ; XTICKINTERVAL = 4
  69. ;plot, arrsv(0,timsrt), arrsv(3,timsrt), xstyle=1, /noerase, $
  70. ; yrange=[ymn,ymx], $
  71. ; XTICKFORMAT = ['LABEL_DATE'], $
  72. ; XTICKUNITS = ['Day'], $
  73. ; XTICKINTERVAL = 4
  74. ;plot, arrsv(0,timsrt), arrsv(2,timsrt), xstyle=1, linestyle=1, $
  75. ; yrange=[ymn,ymx], $
  76. ; ytitle=typestr, title=title, $
  77. ; XTICKFORMAT = ['LABEL_DATE','LABEL_DATE'],$
  78. ; XTICKUNITS = ['Day','Month']
  79. ;plot, arrsv(0,timsrt), arrsv(3,timsrt), xstyle=1, /noerase, $
  80. ; yrange=[ymn,ymx], $
  81. ; XTICKFORMAT = ['LABEL_DATE','LABEL_DATE'],$
  82. ; XTICKUNITS = ['Day','Month']
  83. ;plot, taxis, yaxis, xstyle=1, linestyle=1, $
  84. ; yrange=[ymn,ymx], $
  85. ; ytitle=typestr, title=title, $
  86. ; XTICKFORMAT = ['LABEL_DATE']
  87. ;
  88. ;plot, taxis, yaxis2, xstyle=1, /noerase, $
  89. ; yrange=[ymn,ymx], $
  90. ; XTICKFORMAT = ['LABEL_DATE']
  91. plot, taxis, yaxis, xstyle=1, ystyle=1, linestyle=1, $
  92. yrange=[ymn,ymx], xrange=[xmn,xmx], $
  93. ytitle=typestr, title=title, $
  94. XTICKUNITS=['Time', 'Time'], XTICKFORMAT = ['LABEL_DATE'],YMARGIN=[6,4]
  95. plot, taxis, yaxis2, xstyle=4+1, ystyle=4+1, /noerase, $
  96. yrange=[ymn,ymx], xrange=[xmn,xmx], $
  97. XTICKUNITS=['Time', 'Time'], XTICKFORMAT = ['LABEL_DATE'],YMARGIN=[6,4]
  98. ; key
  99. xcoord=0.8
  100. ycoord=0.9
  101. ycoord=0.35
  102. ycoord=0.2
  103. ycoord2=ycoord-0.05
  104. xcoord2=xcoord+0.03
  105. xcoord3=xcoord+0.05
  106. plots, [xcoord,xcoord2],[ycoord,ycoord], linestyle=0, /normal
  107. xyouts, xcoord3, ycoord, 'RMS', /normal
  108. plots, [xcoord,xcoord2],[ycoord2,ycoord2], linestyle=1, /normal
  109. xyouts, xcoord3, ycoord2, 'mean',/normal
  110. endif
  111. end
  112. ; plot number
  113. pro plotts2, arrsv, title, typestr, minperc=minperc, $
  114. juldatemin=juldatemin, juldatemax=juldatemax
  115. ; number
  116. ;
  117. ;date_label = LABEL_DATE(DATE_FORMAT = $
  118. ; ['%D %M, %Y'])
  119. ;date_label = LABEL_DATE(DATE_FORMAT = $
  120. ; ['%M %Y'])
  121. date_label = LABEL_DATE(DATE_FORMAT=['%D-%M','%Y'])
  122. timsrt=sort(arrsv(0,*))
  123. taxis=arrsv(0,timsrt)
  124. yaxis=arrsv(1,timsrt)
  125. wh=where(taxis gt 0 and finite(yaxis)) ; remove any zero times and non-finite vals
  126. if (wh(0) gt -1) then begin
  127. taxis=taxis(wh)
  128. yaxis=yaxis(wh)
  129. endif
  130. mxt=max(taxis,min=mnt)
  131. print, 'mnt mxt ',mnt, mxt
  132. ;plot, arrsv(0,timsrt), arrsv(1,timsrt), xstyle=1, $
  133. ; ytitle='Number of obs assim', title=title, $
  134. ; XTICKFORMAT = ['LABEL_DATE'], $
  135. ; XTICKUNITS = ['Day'], $
  136. ; XTICKINTERVAL = 4
  137. ;info, taxis
  138. ;info, yaxis
  139. ;print,taxis, yaxis
  140. ;plot, taxis, yaxis, xstyle=1, $
  141. ; ytitle='Number of obs assim', title=title, $
  142. ; XTICKFORMAT = ['LABEL_DATE']
  143. ymx=max(yaxis)*1.05
  144. ; setup time axis range
  145. skip=0
  146. xmx=max(taxis,min=xmn)
  147. if (n_elements(juldatemin) gt 0) then begin
  148. if (xmn le juldatemin) then xmn=juldatemin
  149. if (xmx le juldatemin) then skip=1
  150. endif
  151. if (n_elements(juldatemax) gt 0) then begin
  152. if (xmx ge juldatemax) then xmx=juldatemax
  153. if (xmn ge juldatemin) then skip=1
  154. endif
  155. if (skip eq 0) then $
  156. plot, taxis, yaxis, xstyle=1, ystyle=1, $
  157. ytitle='Number of obs assim', title=title, yrange=[0,ymx], xrange=[xmn,xmx],$
  158. XTICKUNITS = ['Time', 'Time'], XTICKFORMAT = ['LABEL_DATE'],YMARGIN=[6,4]
  159. print,'min time ',min(arrsv(0,timsrt)),max(arrsv(0,timsrt))
  160. end
  161. PRO dataplot_txttimeseries, files, gif=gif, ps=ps, filtstr=filtstr, view=view, $
  162. bin=bin, minperc=minperc, datemin=datemin, datemax=datemax, notitle=notitle, $
  163. emax=emax, emin=emin
  164. ; DJL switch off wave compatibility mode
  165. res=execute("waveoff")
  166. if (n_elements(filtstr) eq 0) then filtstr=""
  167. if (n_elements(view) eq 0) then view=0
  168. print, 'dataplot_txttimeseries '
  169. if (n_elements(datemin) gt 0) then begin
  170. ; month, day, year
  171. juldatemin=julday(datemin(1),datemin(2), datemin(0))
  172. print, 'juldatemin set:', juldatemin, datemin
  173. endif
  174. if (n_elements(datemax) gt 0) then begin
  175. ; month, day, year
  176. juldatemax=julday(datemax(1),datemax(2), datemax(0))
  177. print, 'juldatemax set:', juldatemax, datemax
  178. endif
  179. numfiles=n_elements(files)
  180. print,'numfiles ',numfiles
  181. imax=500
  182. arrs=dblarr(4,imax)
  183. arr=dblarr(4)
  184. arrsv=dblarr(4,10000)
  185. j=0L ; position in full array
  186. for ii=0,numfiles-1 do begin
  187. print,files(ii)
  188. OPENR, unit, files(ii), /get_lun
  189. obstypestr=""
  190. readf,unit,obstypestr
  191. typestr=""
  192. readf,unit,typestr
  193. xrange=fltarr(2)
  194. readf,unit,xrange
  195. yrange=fltarr(2)
  196. readf,unit,yrange
  197. binspday=0.0
  198. readf,unit,binspday
  199. i=0
  200. while (~ eof(unit) and i lt imax) do begin
  201. readf,unit,arr
  202. print,i,arr
  203. if arr(1) eq 0 then arr(2:*)=0
  204. print,arr
  205. arrs(*,i)=arr
  206. i=i+1
  207. endwhile
  208. numtimes=i
  209. print, 'numtimes ',numtimes
  210. if (numtimes ge binspday) then begin
  211. print,arrs(*,numtimes-binspday:numtimes-1)
  212. ; store daily values from each file in full time series array
  213. arrsv(*,j:j+binspday-1)=arrs(*,numtimes-binspday:numtimes-1)
  214. j=j+binspday
  215. endif else begin
  216. if (numtimes gt 0) then begin
  217. print, '** numtimes ',numtimes
  218. print, arrs(*,0:numtimes-1)
  219. arrsv(*,j:j+numtimes-1)=arrs(*,0:numtimes-1)
  220. j=j+numtimes
  221. endif
  222. endelse
  223. FREE_LUN, unit
  224. print, obstypestr
  225. print, typestr
  226. print, xrange
  227. print, yrange
  228. print, binspday
  229. endfor
  230. print, 'j ',j
  231. arrsv=arrsv(*,0:j-1)
  232. ;stop
  233. ; bin up the data
  234. ;print,arrsv
  235. if (n_elements(bin) gt 0) then begin
  236. if (bin gt 1) then begin
  237. ; time 0 num 1 mean 2 rms 3
  238. arrsv2=dblarr(4,j/bin)
  239. for i=0,j/bin-1 do begin
  240. arrsvtemp=arrsv(*,i*bin:(i+1)*bin-1)
  241. print,arrsvtemp
  242. wh=where(arrsvtemp(1,*) gt 0) ; number of obs gt 0
  243. ; print,wh
  244. if (wh(0) gt -1) then begin
  245. ; number of obs
  246. arrsv2(1,i)=total(arrsvtemp(1,wh))
  247. ; mean
  248. arrsv2(2,i)=total(arrsvtemp(2,wh)*arrsvtemp(1,wh))/arrsv2(1,i)
  249. ; rms
  250. arrsv2(3,i)=sqrt(total(arrsvtemp(3,wh)^2*arrsvtemp(1,wh))/arrsv2(1,i))
  251. ; date (average)
  252. ; print,arrsv(0,i*bin)
  253. arrsv2(0,i)=total(arrsvtemp(0,*))/bin
  254. ; print,arrsv2(0,i)
  255. endif
  256. endfor
  257. info, arrsv2
  258. arrsv=arrsv2
  259. endif
  260. endif
  261. nel=n_elements(arrsv(0,*))
  262. ; produce 1 month/3 month/all average values
  263. finaltime=arrsv(0,nel-1)
  264. onemon=finaltime-30
  265. threemon=finaltime-90
  266. print,arrsv
  267. wh1=where(arrsv(0,*) gt onemon and arrsv(1,*) gt 0)
  268. wh3=where(arrsv(0,*) gt threemon and arrsv(1,*) gt 0)
  269. wh0=where(arrsv(1,*) gt 0)
  270. num1=total(arrsv(1,wh1))
  271. mean1=total(arrsv(2,wh1)*arrsv(1,wh1))/num1
  272. rms1=sqrt(total(arrsv(3,wh1)^2*arrsv(1,wh1))/num1)
  273. print,num1
  274. num3=total(arrsv(1,wh3))
  275. mean3=total(arrsv(2,wh3)*arrsv(1,wh3))/num3
  276. rms3=sqrt(total(arrsv(3,wh3)^2*arrsv(1,wh3))/num3)
  277. print,num3
  278. num0=total(arrsv(1,wh0))
  279. mean0=total(arrsv(2,wh0)*arrsv(1,wh0))/num0
  280. rms0=sqrt(total(arrsv(3,wh0)^2*arrsv(1,wh0))/num0)
  281. print,num0
  282. if (keyword_set(notitle)) then begin
  283. title1=""
  284. title=""
  285. endif else begin
  286. subtitle= 'rms (mean), 1 month: '+strtrim(string(rms1,format='(G0.4)'),2)+$
  287. '('+strtrim(string(mean1,format='(G0.3)'),2)+')'
  288. subtitle=subtitle+ ', 3 month: '+strtrim(string(rms3,format='(G0.4)'),2)+$
  289. '('+strtrim(string(mean3,format='(G0.3)'),2)+')'
  290. subtitle=subtitle+ ', all: '+strtrim(string(rms0,format='(G0.4)'),2)+$
  291. '('+strtrim(string(mean0,format='(G0.3)'),2)+')'
  292. fullfiltstr=''
  293. if (filtstr ne '') then fullfiltstr=' Type: '+filtstr
  294. title=obstypestr+typestr+' lons ('+strtrim(string(xrange(0),format='(F0.2)'),2)+$
  295. ','+strtrim(string(xrange(1),format='(F0.2)'),2)+$
  296. ') lats ('+strtrim(string(yrange(0),format='(F0.2)'),2)+','+$
  297. strtrim(string(yrange(1),format='(F0.2)'),2)+')'+fullfiltstr
  298. title1=title+'!C'+subtitle
  299. endelse
  300. if (keyword_set(gif)) then begin
  301. thisDevice = !D.Name
  302. Set_Plot, 'Z' ; do graphics in the background
  303. ; Device, Set_Resolution=[640,512], decomposed=0
  304. Device, Set_Resolution=[800,512], decomposed=0
  305. Erase ; clear any existing stuff
  306. !p.charsize=0.75
  307. ; setupct, r, g, b ; setup color table
  308. plotts1, arrsv, title1, typestr, minperc=minperc, $
  309. juldatemin=juldatemin, juldatemax=juldatemax, $
  310. emax=emax, emin=emin
  311. snapshot = TVRD()
  312. WRITE_GIF,'dataplot_timeseries.gif',snapshot, r, g, b
  313. plotts2, arrsv, title, typestr, minperc=minperc, $
  314. juldatemin=juldatemin, juldatemax=juldatemax
  315. snapshot = TVRD()
  316. WRITE_GIF,'dataplot_numtimeseries.gif',snapshot, r, g, b
  317. Device, Z_Buffer=1 ; reset graphics mode
  318. Set_Plot, thisDevice
  319. !p.charsize=0.0
  320. endif
  321. if (keyword_set(ps)) then begin
  322. ps=1
  323. eps=0
  324. landscape=1
  325. pr2o,file='dataplot_timeseries.ps',landscape=landscape,ps=ps,eps=eps,color=1
  326. plotts1, arrsv, title1, typestr, minperc=minperc, $
  327. juldatemin=juldatemin, juldatemax=juldatemax, $
  328. emax=emax, emin=emin
  329. prend2o,view=view
  330. pr2o,file='dataplot_numtimeseries.ps',landscape=landscape,ps=ps,eps=eps,color=1
  331. plotts2, arrsv, title, typestr, minperc=minperc, $
  332. juldatemin=juldatemin, juldatemax=juldatemax
  333. prend2o,view=view
  334. endif
  335. end