Re: How to convert 3-d array into a 2-d array without missing beforeusing SVD function?

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Sun, 05 Oct 2008 08:30:11 -0600

Hello,

[1]
The following will *not* work:

       numbers(i,j) = num(x(:,i,j).ne.x@_FillValue)

The *only* way to test of missing values is:

   http://www.ncl.ucar.edu/Document/Functions/Built-in/ismissing.shtml

[2]

The following illustrates how to remove missing values from 1D arrays:

   http://www.ncl.ucar.edu/FAQ/#array_funcs_003

This is far more efficient ... no loops.

[3]
Untested and assuming that all time steps are present.

        x(time,lat,lon) , y(time,lat,lon)

        x1D = ndtooned( x(lat|:,lon|:,time|:) ) ; (nlat*nlon*ntim)
        y1D = ndtooned( y(lat|:,lon|:,time|:) )

        ii = ind( .not.ismissing(x1D) .and. .not.ismissing(y1D))
        nii = dimsizes(ii)

        ngrd = nii/ntim

        xsvd = onedtond( x1D(ii), (/ngrd,ntim/) )
        ysvd = onedtond( y1D(ii), (/ngrd,ntim/) )

leo.aries.g wrote:
>
> Hi, all
>
> I want to do a SVD analysis between sea ice (time,lat,lon) and
> slp(time,lat,lon).
> The SVD function of NCL do not allow the missing value, but the sea ice
> grid datas often
> contain some missing values. So My question is how to change the
> 3-dimension array of sea
> ice with some _FillValue points into a 2-dimension(required by the SVD
> function) array without
> _FillValue points.
>
> I write some script to solve it, but it is a little fussy.
> Anyone could show me a easy way?
> possiblely, without using loops. Thanks!
>
> Here below is my script:
>
> +2 begin
> +3
> +6 fi = addfile("/dgpfs/fs1/linxiang/Seaice/HadISST_ice.nc","r")
> +7 x = fi->ice(1308:1655,{-50.5:},:) ; Jan
> 1979 to Dec 2007, 348 months in total
> +8
> +9 lat = x&lat
> +10 lon = x&lon
> +11 printVarSummary(x)
> +12
> +13 numbers = new((/dimsizes(x&lat),dimsizes(x&lon)/),"integer")
> +14 do i = 0,dimsizes(x&lat)-1
> +15 do j = 0,dimsizes(x&lon)-1
> +16 numbers(i,j) = num(x(:,i,j).ne.x@_FillValue)
> +17 end do
> +18 end do
> +19
> +20 nx = num(numbers.eq.348)
> +21
> +22 y = new((/nx,348/),"float")
> +23 ylat = new((/nx/),"float")
> +24 ylon = new((/nx/),"float")
> +25
> +26 n = 0
> +27 do i = 0,dimsizes(x&lat)-1
> +28 do j = 0,dimsizes(x&lon)-1
> +29 if(all(.not.ismissing(x(:,i,j)))) then
> +30 y(n,:) = x(:,i,j)
> +31 ylat(n) = lat(i)
> +32 ylon(n) = lon(j)
> +33 n = n+1
> +34 end if
> +35 end do
> +36 end do
> end
>
> Regards
>
> Lin
>
> 2008-10-04
> leo.aries.g
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sun Oct 05 2008 - 08:30:11 MDT

This archive was generated by hypermail 2.2.0 : Tue Oct 07 2008 - 09:09:48 MDT