[ncl-talk] Complicated nd to 1d to nd

Buzan, Jonathan jbuzan at purdue.edu
Tue May 11 07:03:19 MDT 2021


Hi Dennis,

Thanks. ndtooned is what I thought would work, but I wasn’t sure if the ndtooned would put “Humpty Dumpty” back together again correctly.

Cheers,
-Jonathan



On May 11, 2021, at 2:54 PM, Dennis Shea <shea at ucar.edu<mailto:shea at ucar.edu>> wrote:

Is this what you want?

nlat   = dimsizes(lat)
mlon = dimsizes(lon)
nmdl = dimsizes(model)
npct  = dimsizes(percentile)
nst4  = dimsizes(statfour)
ngrd = nlat*mlon
percentileStatsT = new((/ngrd,nmdl,npct,nst4/),"double")

pST_1d = ndtooned(percentileStatsT)
pST_5d = onedtond(pST_1d,(/nlat,mlon,nmdl,npct,nst4/))
delete([/percentileStatsT, pST_1d/] )         ; <== only if memory is a problem

On Tue, May 11, 2021 at 1:36 AM Buzan, Jonathan via ncl-talk <ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>> wrote:
Hi NCL-Talk,

My script is taking forever to execute because of loops.
I am attempting to remedy this situation by using ndtooned, then executing the commands, followed by rebuilding the array back to nd.

In my example below percentileStatsT is an array 4d array that is percentileStatsT(lat*lon,model,percentile,statistics), but I need to convert the lat*lon to lat, lon aka a 5d array:
nd_T_percentileStats(lat,lon,model,percentile,statistics)

However, I am not sure how to convert lat*lon into lat,lon. Is there a command in ncl that will do this?

Cheers,
-Jonathan


Code snippet:
ex.
T(time,lat,lon)  ;my data of temperatures

;;;create new array to store statistics.;;;;;
model = ispan(0,0,1) ; this will be the unlimited domain
model!0 = "model"
model&model = model
model at long_name = "model"

percentile = ispan(1,99,1)
percentile!0 = "percentile"
percentile&percentile = percentile
percentile at long_name = "percentile"

statfour = ispan(0,3,1)
statfour!0 = "statfour"
statfour&statfour = statfour
statfour at long_name = "Mean, SD, Skewness, Kurtosis"

percentileStatsT  = new((/dimsizes(lat)*dimsizes(lon),dimsizes(model),dimsizes(percentile),dimsizes(statfour)/), "double")


;;;;; manipulate data to calculate statistics;;;;;;
T_1d = ndtooned(T(lat|:,lon|:,time|:) ; reorder dimensions and convert to 1d

;;;;; operate on data;;;;;;;
;;;;; breaks;;;;;;;
do k = 0, (dimsizes(lat) * dimsizes(lon) -1)
        index_time_st = dimsizes(time) * k
        index_time_end = dimsizes(time) * k + (dimsizes(time) -1)
        onedT = T_1d(index_time_st:index_time_end)
        workT_Index = dim_pqsort_n(onedT,2,0)
        manip_T = onedT(workT_Index)    ; reorder data from lowest to highest
        percentile = new((/99/),"integer”)
        do l = 0, dimsizes(percentile) -1 ; time is 29200 data points. dividing the array into percentiles
                starti = 292*l + 146
                endi = 292*(l+1) + 146 -1
                percentileStatsT(k,:,l,:) = dim_stat4(onedT(starti:endi))
        end do
end do




_______________________________________________
ncl-talk mailing list
ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>
List instructions, subscriber options, unsubscribe:
https://mailman.ucar.edu/mailman/listinfo/ncl-talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210511/39c8163f/attachment.html>


More information about the ncl-talk mailing list