Sorting maxes at lat and lon

From: Michelle Cipullo <mlcipull_at_nyahnyahspammersnyahnyah>
Date: Fri Aug 10 2012 - 11:28:22 MDT

Hello,

I am working on a script to calculate return period at each point. I have
most things working, except I'm not sorting correctly. It may be my
confusion on the function. I am looking at dim_pqsort_n, and from that I
want it listed in increasing order (min_wind.....max_wind) at each
individual lat an lon. I have bolded the sort function in this script
since the rest of it is irrelevant for my question. I am confused on if I
want to sort "x" or not from the documentation (I think I do want to sort
x).
Also, using the dim_max_n I sort across time, so there is only two
components in the array (lat,lon). I want the max at each individual lat &
lon so I'm not sure what dimension I should sort across, or if there is a
better function.

Thanks so much for your help,

Michelle

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/wrf/WRFUserARW.ncl"

;__________________________________
;
;Michelle Cipullo
;Return Period
;
;___________________________

begin

wks = gsn_open_wks("x11","Return_Period")
gsn_define_colormap(wks,"precip2_17lev")

nrows = numAsciiRow("Red_var_115_times.txt")
ncols = numAsciiCol("Red_var_115_times.txt")

Red_Var_t = asciiread("Red_var_115_times.txt",(/nrows,ncols/),"float")
Red_Var = Red_Var_t(:,0)

fils = systemfunc("ls /NCL_fixed_up_scripts/*"+".nc")
   F = addfiles(fils,"r")
   f = addfile("wrfout_d01_2010-02-27_00:00:00.nc","r") ;Need one file
for plot info

;_________get wind variables__________

   u_all = addfiles_GetVar(F,fils,"U10")
   v_all = addfiles_GetVar(F,fils,"V10")

   lmask = addfiles_GetVar(F,fils,"LANDMASK")

   u2 = u_all(:,:,:)*u_all(:,:,:)
   v2 = v_all(:,:,:)*v_all(:,:,:)

 speed = sqrt(u2+v2)
 speed = speed*lmask

 maxwind_2002 = dim_max_n(speed,0) ;Find max over 0 dim. (time)
 delete([/u_all,v_all,u2,v2,speed,F,f/])

nj = 106
ni = 193

;_______append all maxes_______

new1 = array_append_record(maxwind_2002,maxwind_2003,0) ;I realize this
is extremely inefficient, fix later
new2 = array_append_record(new1,maxwind_2004,0)
new3 = array_append_record(new2,maxwind_2005,0)
new4 = array_append_record(new3,maxwind_2006,0)
new5 = array_append_record(new4,maxwind_2007,0)
new6 = array_append_record(new5,maxwind_2008,0)
new7 = array_append_record(new6,maxwind_2009,0)
new8 = array_append_record(new7,maxwind_2010,0)

ten_yr_maxes = array_append_record(new8,maxwind_2011,0)
print(dimsizes(all_maxes))

;_______Sort in ascending order_______________
*
sorted_maxes = new((/nj,ni/),float)

sorted_maxes(j,i) = dim_pqsort_n(all_maxes(j,i),2,0) ;Sorting not working
the way I want. want maxes first..
*
;_____the x in RP = mx+b_____

rank = 1/dimsizes(sorted_maxes+1) ;have to +1 b/c starts at 0, can't div.
P = -log(-log(rank)) ;
x_tenyrs = P ;

;______correlation_________

do j = 0, nj-1
do i = 0, ni-1

corr = new((/nj,ni/),float)
Return_Period = new((/nj,ni/),float)
m = new((/nj,ni/),float) ;slope
b = new((/nj,ni/),float) ;intercept

corr(j,i) = regline(Red_Var,sorted_maxes) ;red var y-axis, wind x-axis

yavg = corr@yave
xavg = corr@xave
b = corr@yintercept
m(j,i) = yavg/xavg

Return_Period(j,i) = m(j,i)*x_tenyrs+b(j,i)

end do
end do
end

Michelle Cipullo

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Aug 10 11:28:37 2012

This archive was generated by hypermail 2.1.8 : Wed Aug 15 2012 - 08:12:08 MDT