;************************************************* ; regress_1.ncl ;************************************************* 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" begin ;************************************************ ; create pointer to file and read in temperature ;************************************************ in = addfile("/data2/SST_trends/HadISST_sst.nc","r") sst = in->sst(1511:1690,80:100,14:100) ; extract time series at Equatorial Pacific ; sst = in->sst(1,:,:) printVarSummary(sst) ;*********************************************** ; Do Seasonal Mean ;*********************************************** sst_DJF = month_to_season(sst, "MAM") ;************************************************ ; Do average for the whole region ;************************************************ sst_region = wgt_areaave_Wrap(sst_DJF,1.0,1.0,1) printVarSummary(sst_region) ;************************************************ ; smooth data so that seasonal cycle is less ; prominente. This is for demo purposes only ; so that the regression line is more sloped ;************************************************ ; sst_region = runave(sst_region,15,0) ;************************************************ ; create x and calculate the regression coefficient ; note regline works on one dimensional arrays. ;************************************************ x = ispan(0,dimsizes(sst_region)-1,1)*1. rc = regline(x,sst_region) ;************************************************ ; create an array to hold both the original data ; and the calculated regression line ;************************************************ data = new ( (/2,dimsizes(sst_region)/), typeof(sst)) data(0,:) = sst_region ; 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("pdf","regress_MAM") ; 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 ; plot1 = gsn_csm_contour_map_ce(wks,sst(:,:),res) plot = gsn_csm_xy (wks,sst_region&time,data,res) ; create plot ;************************************************ end