Re: removing degenerate dimensions

From: Rob Nicholas <rnicholas_at_nyahnyahspammersnyahnyah>
Date: Fri Apr 16 2010 - 19:22:49 MDT

To answer Dennis's question about context, in the work I'm doing now,
I frequently run into situations where I have a 1x1x12 monthly
climatology that I want to put into a single row of a Nx12 array (say
results from N different model runs that I want to use for later
calculations). In this case,

      big_array(i,:) = clm_array(0,0,:)

fails because of a dimension mismatch. There are obviously good
reasons for retaining degenerate dimensions, but, coming to NCL from
Matlab (which seems to remove degenerate dimensions by default), this
error left me perplexed. The approach suggested by Mary and Dennis
takes care of this situation nicely, though.

I'd like to recommend that something akin to the sample functions
posted by Mary and Dennis be included in a subsequent version of NCL.
I suspect it would be useful to a fair number of users and it would
serve to highlight a unique feature of NCL: retention of degenerate
dimensions.

My own take on this approach, incorporating bits from both Mary and
Dennis (and separated into Wrap and non-Wrap versions) is attached for
those who might find it useful.

~Rob

On Fri, Apr 16, 2010 at 3:48 PM, Dennis Shea <shea@ucar.edu> wrote:
> I had started the following but someone came to my office.
> I saw Mary's reply and Rob's response. Basicaly, this was
> the same approach suggested by MH.
>
> =========================================
>
> In what context? reading from a file?
>
> http://www.ncl.ucar.edu/Document/Functions/Built-in/setfileoption.shtml
> has an option for GRIB files "SingleElementDimensions"
>
>
> Otherwise ... *untested*
>
> undef("elimDimOne")
> function elimDimOne (x)
> local dimx, i
> begin
>  dimx = dimsizes(x)
>  i    = ind(dimx.ne.1)
>  if (.not.ismissing(i(0))) then
>      return( onedtond(ndtooned(x),dimx(i)) )
>  else
>      return( x )
>  end if
> end
>
>
>
> On 04/16/2010 02:24 PM, Rob Nicholas wrote:
>>
>> Is there a *general* way to remove degenerate dimensions from a
>> variable?  In other words, is it possible to remove all degenerate
>> dimensions without having to know which dimensions might be degenerate
>> or even how many dimensions a variable has?
>>
>> Thanks,
>> Rob
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
> --
> ======================================================
> Dennis J. Shea                  tel: 303-497-1361    |
> P.O. Box 3000                   fax: 303-497-1333    |
> Climate Analysis Section                             |
> Climate & Global Dynamics Div.                       |
> National Center for Atmospheric Research             |
> Boulder, CO  80307                                   |
> USA                        email: shea 'at' ucar.edu |
> ======================================================
>

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

Received on Fri Apr 16 19:23:12 2010

This archive was generated by hypermail 2.1.8 : Fri Apr 23 2010 - 14:40:07 MDT