[ncl-talk] generate_sample_indices without replacement

Sri nandini bax8609 at uni-hamburg.de
Fri Feb 18 00:21:45 MST 2022


Thank you!

Would some one help me understand how to modify this if i need to 
subsample multiple times?

Sri

On 17.02.22 19:10, Rashed Mahmood wrote:
> Hi Sri,
> I am not fully sure what your end goal is here. However, if you need 
> to randomly select 40 members only once then you do not need a loop 
> for it. Also, if you want to select from 100 members then the function 
> "generate_sample_indices" should have n=100 instead of 40 that you used.
>
> So if you are interested in randomly selecting *40 members ONLY ONCE 
> *then your code would be:
> Note that I turned OFF the loop because it is not needed for this 
> example. You can use a loop if you need to randomly select 40 members 
> many times.
>
> ;   do j= 0,n-1
>      iwo = generate_sample_indices( nens, 0 )
>      rcp_40= T2m(:,iwo(0:n-1),:,:)
>
> ;   end do
>
>
> On Thu, Feb 17, 2022 at 8:28 AM Sri nandini via ncl-talk 
> <ncl-talk at mailman.ucar.edu> wrote:
>
>     Hello dear ncl-users,
>
>     I would like to know how to properly code for selecting 40 random
>     ensemble from a 100 ensembles of my data.
>
>     I wonder if someone could help me with this code? My original data is
>     [time | 240] x [ens | 100] x [lat | 180] x [lon | 360]
>
>        f     = addfile ("temperature_data.nc
>     <http://temperature_data.nc>", "r")
>        T2m    = f->temp
>
>        printVarSummary(T2m)
>        dimx = dimsizes(T2m)
>        ntim = dimx(0)          ; 240- time dimension
>        nens = dimx(1)          ; 100- ensemble dimension
>        nlat = dimx(2)            ; 180- lat
>        mlon = dimx(3)          ; 360- lon
>
>        T2m at _FillValue = -9.96921e+36
>
>        ; randomly select 40 members from 100 members without replacement
>        ; define a new variable dimensions
>
>        n=40
>        rcp_40=new((/ntim,n,nlat,mlon/),typeof(rcp45_anom))
>        copy_VarCoords(rcp45_anom(:,0,:,:),rcp_40(:,0,:,:))    ; Copy
>     metadata
>        printVarSummary(rcp_40) ==>Dimensions and sizes: [time | 240] x
>     [40] x [lat | 180] x [lon | 360]
>
>        Coordinates:
>                  time: [1192152..1366728]
>                  lat: [-89.5..89.5]
>                  lon: [   0.. 359]
>
>        do j= 0,n-1
>        iwo = generate_sample_indices( n, 0 )
>        rcp_40(:,j,:,:) = T2m(:,iwo,:,:)  ====>error here
>     fatal:VarVarWrite:
>     Number of dimensions on left hand side does not match right hand side
>
>        end do
>        printVarSummary(rcp_40)
>
>     Could someone help me in this code?
>
>     Best
>
>     Sri
>
>     _______________________________________________
>     ncl-talk mailing list
>     ncl-talk at mailman.ucar.edu
>     List instructions, subscriber options, unsubscribe:
>     https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
-- 
Dr. Sri Nandini-Weiss

Center for Earth System Research and Sustainability (CEN)
Cluster of Excellence 'Climate, Climatic Change, and Society' (CLICCS)

Universität Hamburg
Institute of Oceanography
Bundesstraße 53
20146 Hamburg
Germany
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20220218/af9228f0/attachment.html>


More information about the ncl-talk mailing list