removing zero dimensions ...

From: Chad Herman <chad.herman.us_at_nyahnyahspammersnyahnyah>
Date: Wed Jun 01 2011 - 12:04:13 MDT

On 06/01/2011 02:00 PM, ncl-talk-request@ucar.edu wrote:
> Message: 6
> Date: Wed, 01 Jun 2011 11:48:04 +0200
> From: "Ufuk Utku Turuncoglu (BE)"<u.utku.turuncoglu@be.itu.edu.tr>
> Subject: removing zero dimensions ...
> To: NCL USERS<ncl-talk@ucar.edu>
> Message-ID:<4DE60AD4.2010102@be.itu.edu.tr>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hi,
>
> I just wonder that is there any NCL function or procedure (i could not
> find in the documentation) that removes the dimensions that it's actual
> length is one (i call it as zero dimension). For example, i have a 4d
> array and its dimension sizes are "tmp(10, 3, 1, 45)" and i want to
> remove the third dimension and the result array would be "tmp(10,3,45)".
> I actually wrote the following function to do that but i just want to be
> sure it is a generic solution or not
>
> ;---------------------------------------------------------
> ; Removes the zero dimensions from the variable
> ; Input:
> ; data - original data
> ; Output:
> ; tmp - modified data
> ;---------------------------------------------------------
> undef("rm_empty_dims")
> function rm_empty_dims(data:numeric)
> begin
> ;--- get dimension size of the data ---
> dims = dimsizes(data)
> rank1 = dimsizes(dims)
>
> ;--- find the indices of the non-zero dimensions ---
> indx = ind(dims .ne. 1)
> rank2 = dimsizes(indx)
>
> ;--- if zero dimension exist, create new data array ---
> if (rank1 .ne. rank2) then
> tmp = new(dims(indx), typeof(data))
> tmp = data
> return(tmp)
> else
> return(data)
> end if
> end
>
> because, as you can see from the code i could do nothing about
> attributes. How can be sure that result field will have correct
> metadata? May be additional code can be implemented to ensure that. Is
> the "tmp = data" operation safe between variables that are in different
> rank (there could be shifting if it is not safe). Also note that the
> current version of the code is working in my case.
>
> --ufuk

Ufuk,

I've written a function ("squeeze") to drop redundant dimensions and
retain meta data. (See attached).

Chad

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Received on Wed Jun 1 12:04:27 2011

This archive was generated by hypermail 2.1.8 : Wed Jun 01 2011 - 12:41:15 MDT