[ncl-talk] Constraining a domain further in regression analysis

Melissa Lazenby M.Lazenby at sussex.ac.uk
Fri Sep 5 11:06:56 MDT 2014

```Hi All

I have currently worked out the regression and plotted a regression line for max precipitation in a certain domain and want to constrain the domain further. I am looking at a latlon box from 0-30S and 20-50E and would like to know how to constrain that further by only choosing for example at 20E I only want to choose the max precip from 0-20S and at 50E from 10-30S.

I am not quite sure how to code this type of thing and would appreciate if someone could point me to a similar example or provide some advice on how to go about this.

Many thanks!

Kind Regards
Melissa

;*************************************************************
;Calculations of max precip for lat and lon values
;**************************************************************

dimpr2   = dimsizes(pr2)
nlat     = dimpr2(0)
mlon     = dimpr2(1)

pr2MaxLon = new ( mlon, typeof(pr2), pr2 at _FillValue)

do ml=0,mlon-1
imax = maxind(pr2(:,ml))
pr2MaxLon(ml) = dble2flt(lat(imax))
end do

print(pr2MaxLon)
print(pr2&lon)

print("-------------------------------")
print("pr2MaxLon: "+pr2&lon+"   "+pr2MaxLon)

;Regression Line

rcMaxLon = regline(pr2&lon,pr2MaxLon)
print(rcMaxLon)

print(rcMaxLon at yave)

bMaxLon  = rcMaxLon at yintercept
print(bMaxLon)

xMaxLon  = pr2&lon
print(xMaxLon)
yMaxLon  = rcMaxLon*pr2&lon + bMaxLon
print(yMaxLon)

print("-------------------------------")
print(xMaxLon+"   "+yMaxLon)

;************************************************
; create an array to hold both the original data
; and the calculated regression line
;************************************************

data      = new ( (/2,dimsizes(pr2MaxLon)/), typeof(pr2MaxLon))

; y = mx+b
; m is the slope:       rc      returned from regline
; b is the y intercept: rc at yave attribute of rc returned from regline

data(1,:) = dble2flt(rcMaxLon)*(dble2flt(xMaxLon)-dble2flt(rcMaxLon at xave)) + dble2flt(rcMaxLon at yave)
;************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140905/21d35bc0/attachment.html
```