[ncl-talk] Advice on extracting point locations from array

Hoffman Cheung hoffmancheung at gmail.com
Tue Oct 16 23:51:53 MDT 2018


Hi Will,

Given that your 4-D ocean data is
T4D(time|nTime,depth|nDepth,lat|nLat,lon|nLon) and you are trying to
extract the profile pInd(nProfile,3),
where pInd(:,0), pInd(:,1) and pInd(:,2) corresponds to the index of time,
lat and lon dimension, respectively.

I would try to do the following way:

; rearrange the 4-D ocean data
T4DR = T4D(depth|:,time|:,lat|:,lon|:) ; make sure all dimensions are named

; convert the 4-D data into 2-D data
T2D = reshape(T4DR, (/nDepth, nTime*nLat*nLon/))

; convert pInd
pInd1D = pInd(:,0)*(nLat*nLon) + pInd(:,1)*nLon + pInd(:,2)

; extract the profile from 2-D data
TProfile = T2D(:,pInd1D)

If the above method runs out of memory, you might perform a do loop over
the dimension depth, instead of every profile (if you have a huge amount of
profiles).

Regards,
Hoffman




Will Hobbs <will.hobbs at utas.edu.au> 於 2018年10月16日 週二 下午1:53寫道:

> Hi all
>
>
>
> This one is for the NCL ‘Brains Trust’. I’m extracting a large number of
> ocean profiles from a 4-d array (dimensioned time,depth,lat,lon), using
> coordinate triplets based on time,lat and lon, (i.e. a 2-d array of indices
> dimensioned nprofile, 3),  but it’s a slow process and I wonder if anyone
> has any smart ideas on speeding it up.
>
>
>
> At the moment (partly to manage memory), I’m reading each profile in a
> loop, viz:
>
>
>
>
>
> Tprof = new((/nlev,nprofile/),float)
>
> do i = 0, nprofile-1
>
>      Tprof(:,i) = fi->T(pInd(i,0),:,pInd(i,1),pInd(i,2))    ;pInd is an
> array with coord triplets
>
> end do
>
>
>
> Obviously one obvious way of speeding things up would be to read the
> entire array of input data and extract the locations, to avoid multiple i/o
> calls. What I really want to do though is somehow get rid of the loop
> entirely. Is there any way of extracting coordinate pairs (or in this case
> triplets) without looping through each profile?
>
>
>
> The only way I can think of is to turn the input array (T in my example
> above) into a 1-d array, and somehow convert ‘pInd’ into the elements of
> that 1-d array – this seems fraught with opportunity for error though.
> Catastrophic error I can deal with – it’s the sneaky, inobvious error that
> scares me….
>
>
>
> Hoping someone has a great idea….
>
>
>
> Will
>
>
>
> University of Tasmania Electronic Communications Policy (December, 2014).
> This email is confidential, and is for the intended recipient only.
> Access, disclosure, copying, distribution, or reliance on any of it by
> anyone outside the intended recipient organisation is prohibited and may be
> a criminal offence. Please delete if obtained in error and email
> confirmation to the sender. The views expressed in this email are not
> necessarily the views of the University of Tasmania, unless clearly
> intended otherwise.
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20181017/0d45f357/attachment.html>


More information about the ncl-talk mailing list