Re: removing zero dimensions ...

From: <Maurice.McHugh_at_nyahnyahspammersnyahnyah>
Date: Wed Jun 01 2011 - 13:33:41 MDT

I have used the following successfully. ncwa is a netCDF operators, and part of the NCO package.

ncwa ľa z_t fileIn.nc fileOut.nc

where z_t is the vestigial or degenerate dimension of size 1 to be removed from fileIn.

Hope this helps!

Maurice

----- Original Message -----
From: Mary Haley <haley@ucar.edu>
Date: Wednesday, June 1, 2011 2:30 pm
Subject: Re: [ncl-talk] removing zero dimensions ...
To: ncl forum <ncl-talk@ucar.edu>

> Just to answer Ufuk's original question: we don't have any function
> that removes the "zero dimension" or the "degenerate dimension" as we
> call it.
>
> This question was brought up last year, so here's the answer (and a
> function) for that:
>
>
>
> Chad, thanks for contributing your "squeeze" function.
>
> --Mary
>
>
> On Jun 1, 2011, at 12:04 PM, Chad Herman wrote:
>
> > 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: [ncl-talk] 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
> > <squeeze.ncl>_______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> >
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
>
Received on Wed Jun 1 13:33:43 2011

This archive was generated by hypermail 2.1.8 : Thu Jun 09 2011 - 14:56:48 MDT