<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Hi Giorgio,
<div class=""><br class="">
</div>
<div class="">The code for the stat_dispersion is in $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl</div>
<div class="">(Search for stat_dispersion for the explicit function)</div>
<div class=""><br class="">
</div>
<div class="">Here are some snippets to help. Ultimately, the stat_dispersion operates on 1d fields, and you have to put your data into that format. Highly recommend that you have more than 100 data points in your time dimension or the function will not work.</div>
<div class=""><br class="">
</div>
<div class="">mastervar = ; new array that is the stat dispersion by lat by lon</div>
<div class="">do k = 0, dimsizes(lat)-1</div>
<div class="">do j = 0, dimsizes(lon)-1</div>
<div class=""><span class="Apple-tab-span" style="white-space:pre"></span>z = data(:,k,j)</div>
<span class="Apple-tab-span" style="white-space:pre"></span>work = ndtooned(z)
<div class=""><span class="Apple-tab-span" style="white-space:pre"></span>nwork = dimsizes(work) <br class="">
<div class=""><span class="Apple-tab-span" style="white-space:pre"></span>qsort(work) ; reordered from lowest to highest<br class="">
<div><span class="Apple-tab-span" style="white-space:pre"></span>mastervar(j,k) = work( min((/nwork-1, nwork*70/100-1 /)) ) ; 70% </div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>delete(z)</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>delete(work)</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>delete(nwork)</div>
<div>
<div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">end do</div>
<div class="">
<div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">end do</div>
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">Cheers,</div>
<div class="">-Jonathan</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
</div>
<div>
<blockquote type="cite" class="">
<div class="">On Mar 15, 2022, at 13:25, Giorgio Graffino via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" class="">ncl-talk@mailman.ucar.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<p style="font-size: 12.0pt;font-family: Arial;" class="">Dear NCLers,</p>
<p style="font-size: 12.0pt;font-family: Arial;" class=""><br class="">
</p>
<p style="font-size: 12.0pt;font-family: Arial;" class="">I have a time,lat,lon monthly-mean SST field and I want to compute the 70th percentile month by month.
<span style="font-size: 12.0pt;font-family: Arial;" class="">I'm trying to adapt Dennis's suggestion
</span><span style="font-family: arial , sans-serif;font-size: 12.0pt;" class="">given here
</span><span style="font-size: 12.0pt;" class="">(</span><span style="font-size: 12.0pt;font-family: arial , sans-serif;" class=""><a href="https://www.ncl.ucar.edu/Support/talk_archives/2013/0954.html" class="">https://www.ncl.ucar.edu/Support/talk_archives/2013/0954.html</a>),
 but I'm ending up with a single 2-D percentile field, calculated across the entire time period.
</span><span style="font-family: arial , sans-serif;font-size: 12.0pt;" class="">The problem is that, since it's historical SST, most of the spatial domain is above the threshold
</span><span style="font-family: arial , sans-serif;font-size: 12.0pt;" class="">at the end of the time period,
</span><span style="font-family: arial , sans-serif;font-size: 12.0pt;" class="">because of global warming.
<br class="">
<br class="">
I'd like to have something similar to stat_dispersion (</span><span style="font-family: arial , sans-serif;font-size: 12.0pt;" class=""><a href="https://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml" class="">https://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml</a></span><span style="font-family: arial , sans-serif;font-size: 12.0pt;" class="">),
 but for a custom percentile and without detrending the data. </span><span style="font-family: arial, sans-serif; font-size: 12pt;" class="">Is there a way to do that?
</span><span style="font-family: arial, sans-serif; font-size: 12pt;" class="">Here is a snippet of my code:</span></p>
<p style="font-size: 12.0pt;font-family: Arial;" class=""><span style="font-family: arial , sans-serif;font-size: 12.0pt;" class=""><br class="">
</span></p>
<p style="font-size: 12.0pt;font-family: Arial;" class="">temp_sort = dim_pqsort_n(temp,2,0) ; (time, lat, lon) -> (time, lat, lon)<span style="font-family: arial , sans-serif;font-size: 12.0pt;" class=""><br class="">
</span></p>
<p style="font-size: 12.0pt;font-family: Arial;" class="">temp_num = dim_num_n(.not.ismissing(temp_sort),0) ; (time, lat, lon) -> (lat, lon)</p>
<p style="font-size: 12.0pt;font-family: Arial;" class="">do n = 0, ntim-1</p>
<p style="font-size: 12.0pt;font-family: Arial;" class="">temp_warmest30(n,:,:) = where(temp_sort(n,:,:).gt.floor(0.7*temp_num),temp(n,:,:),temp@_FillValue) ; (time, lat, lon) -> (time, lat, lon)</p>
<p style="font-size: 12.0pt;font-family: Arial;" class=""><span style="font-size: 12pt; font-family: Arial;" class="">end do</span></p>
<p style="font-size: 12.0pt;font-family: Arial;" class=""><span style="font-family: arial , sans-serif;font-size: 12.0pt;" class=""><br class="">
</span></p>
<p style="font-size: 12.0pt;font-family: Arial;" class=""><span style="font-family: arial , sans-serif;font-size: 12.0pt;" class="">Thanks,</span></p>
<p style="font-size: 12.0pt;font-family: Arial;" class=""><span style="font-family: arial , sans-serif;font-size: 12.0pt;" class="">Giorgio</span></p>
_______________________________________________<br class="">
ncl-talk mailing list<br class="">
<a href="mailto:ncl-talk@mailman.ucar.edu" class="">ncl-talk@mailman.ucar.edu</a><br class="">
List instructions, subscriber options, unsubscribe:<br class="">
https://mailman.ucar.edu/mailman/listinfo/ncl-talk</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</body>
</html>