Re: removing zero dimensions ...

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed Jun 01 2011 - 21:08:09 MDT

Saji ... Ha! Ha!
================

Just for fun .... I have attached my entry [rm_degen_dims].
It includes some simple tests.

D

On 6/1/11 8:28 PM, Saji Hameed wrote:
> As you see below, I am not very good at naming functions.. here is a
> function i use for the same purpose..
>
> function removeRedundantDimsOf(var)
> begin
> var_dims=dimsizes(var)
> dim_names=getvardims(var)
> new_indcs=ind(var_dims.gt.1)
> newdims=var_dims(new_indcs)
> new_dimnames=(dim_names(new_indcs))
> ndims=dimsizes(newdims)
> newvar=new(newdims,typeof(var))
> newvar=var
> do i=0,ndims-1
> newvar!i=new_dimnames(i)
> end do
> return(newvar)
> end
>
> function remove_redundant_dims_of(var)
> begin
> return(removeRedundantDimsOf(var))
> end
>
> function remove_empty_dims_of(var)
> begin
> return(removeRedundantDimsOf(var))
> end
>
> saji
>
> On Thu, Jun 2, 2011 at 4:33 AM,<Maurice.McHugh@noaa.gov> wrote:
>> 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: 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: 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:
>>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

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

Received on Wed Jun 1 21:08:16 2011

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