sub.draw_series.ncl 3.67 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; sub.draw_series.ncl
; Carl Schreck (cjschrec@ncsu.edu)
; October 2014
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Description: Draw time series plots
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
;load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
;load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
;load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/diagnostics_cam.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/time_axis_labels.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/cd_string.ncl"
load "$CJS_NCL_LIB/print_clock.ncl"
load "$CJS_NCL_LIB/lib.array.ncl"
load "$CJS_NCL_LIB/lib.cjs_graphics.ncl"


undef ( "draw_series" )
function draw_series( \
  io_wks    [1] : graphic, \
  i_prefix  [1] : string, \
  i_sensor  [*] : string, \
27
  i_seriesType [1] : string, \
28
29
30
31
32
33
  i_minTime [1] : numeric, \
  i_maxTime [1] : numeric, \
  i_res     [1] : logical \
)
begin ; draw_series
  ; These are some parameters that could be useful to have up top
34
35
36
37
38
  if( i_prefix.eq."olr" ) then
    buffer = 0
  else
    buffer = 365
  end if
39
  shortSmooth = 365
40
  longSmooth = shortSmooth*5
41
42
  inPath = "/home/carl/data/olr/compare/time_series/" + i_prefix + "."  \
      + i_sensor + ".20S-20N.nc"
43

44
  res = i_res
45
  res@gsnLeftString = i_prefix
46
47
48
49
50
51
  res@trXMinF = i_minTime
  res@trXMaxF = i_maxTime
  res@xyExplicitLegendLabels = i_sensor
  res@tiXAxisString = ""
  res@xyMarkLineMode = "Lines"
  res@xyMonoLineThickness = True
52
  res@vpHeightF = 0.4
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

  print_clock( "Reading times" )
  do sensorCounter = 0, dimsizes(i_sensor)-1
    inFile = addfile( inPath(sensorCounter), "r" )
    inTime := inFile->time
    inTime = floor(inTime)
    if( sensorCounter.eq.0 ) then
      allTimes = inTime
    else
      newAllTimes := array_append_record( allTimes, inTime, 0 )
      allTimes := newAllTimes
    end if
  end do
  xData = remove_duplicates( allTimes )
  xData@units = inTime@units
68
69
  xData!0 = "time"
  xData&time = xData
70
71
72
73
74
75
76
77
78

  print_clock("Reading data")
  yData = new( (/ dimsizes(i_sensor), dimsizes(xData) /), float )
  yData!1 = "time"
  yData&time = xData

  do sensorCounter = 0, dimsizes(i_sensor)-1
    inFile = addfile( inPath(sensorCounter), "r" )
    inTime := floor(inFile->time)
79
80
    startInd = buffer
    endInd = dimsizes(inTime)-1-buffer
81
    inData := inFile->$i_seriesType$(startInd:endInd)
82
    yData(sensorCounter,{inTime(startInd):inTime(endInd)}) = inData
83
84
  end do

85
86
87
88
89
90
91
92
  print_clock("Trending")
  trendData = new( dimsizes(yData), double )
  do sensorCounter = 0, dimsizes(i_sensor)-1
    rc = regline( xData({i_minTime:i_maxTime}),  \
        yData(sensorCounter,{i_minTime:i_maxTime}) )
    trendData(sensorCounter,:) = rc * xData + rc@yintercept
  end do

93
  print_clock("Smoothing")
94
95
  yData = runave_n_Wrap( yData, shortSmooth, 0, 1 )
  smoothData = runave_n_Wrap( yData, longSmooth, 0, 1 )
96
97
98
99
100
101
102

  print_clock("Plotting")
  resTick = True
  resTick@ttmFormat      = "%Y"
  resTick@ttmAxis        = "XB"
  month_axis_labels( i_minTime, 60, 12, 1, res, resTick )

103
104
  res@xyLineThicknessF = 2
  res@xyBoldColors = False
105
  rawPlot = cjs_draw_xy( io_wks, xData, yData, res )
106

107
108
109
110
111
  res@xyLineThicknessF = 1
  res@xyBoldColors = False
  trendPlot = cjs_draw_xy( io_wks, xData, trendData, res )
  overlay( rawPlot, trendPlot )

112
113
  res@xyLineThicknessF = 6
  res@xyBoldColors = True
114
  smoothPlot = cjs_draw_xy( io_wks, xData, smoothData, res )
115
116
117
  overlay( rawPlot, smoothPlot )

  retVal = rawPlot
118
119
120
121

  return(retVal)
end; draw_series