;************************************************* ; regress_1.ncl ;************************************************* load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" begin ;************************************************ ; create pointer to file and read in temperature ;************************************************ in = addfile("b003_TS_200-299.nc","r") ts = in->TS(:,{60},{180}) ; extract time series at 60N,90W ;************************************************ ; smooth data so that seasonal cycle is less ; prominate. This is for demo purposes only ; so that the regression line is more sloped ;************************************************ ts = runave(ts,40,0) ;************************************************ ; create x and calculate the regression coefficient ; note regline works on one dimensional arrays. ;************************************************ x = ispan(0,dimsizes(ts)-1,1)*1. rc = regline(x,ts) ;************************************************ ; create an array to hold both the original data ; and the calculated regression line ;************************************************ data = new ( (/2,dimsizes(ts)/), typeof(ts)) data(0,:) = ts ; y = mx+b ; m is the slope: rc returned from regline ; b is the y intercept: rc@yave attribute of rc returned from regline data(1,:) = rc*(x-rc@xave) + rc@yave ;************************************************ ; plotting parameters ;************************************************ wks = gsn_open_wks("ps","regress") ; specifies a ps plot res = True ; plot mods desired res@xyMarkLineModes = (/"Markers","Lines"/) ; choose which have markers res@xyMarkers = 16 ; choose type of marker res@xyMarkerColor = "red" ; Marker color res@xyMarkerSizeF = 0.005 ; Marker size (default 0.01) res@xyDashPatterns = 1 ; solid line res@xyLineThicknesses = (/1,2/) ; set second line to 2 res@tiMainString = "Output from regline" ; title plot = gsn_csm_xy (wks,ts&time,data,res) ; create plot ;************************************************ end