[Thread Prev][Thread Next][Index]

Re: singleton dimensions



Hi David,

There are two easy solutions to this:

  1. use a transformation such as @AVE on the singleton axis to "compress" it
     out of existence
  2. use the RESHAPE function

Approach 1 is illustrated first below. Then 2.

    - steve

==========

1. Using a compressing transformation to eliminate a "singleton" axis:
> ferret
        NOAA/PMEL TMAP
        Program FERRET
        Version 5.22 - 07/27/00
        17-Aug-00 13:35

yes? define axis/z=50/npoints=1/units=meters z50
yes? define axis/x=1:10:1 xax
yes? let v = z[gz=z50] + x[gx=xax]
yes? stat/brief v

      Total # of data points: 10 (10*1*1*1)
      # flagged as bad  data: 0
      Minimum value: 51
      Maximum value: 60
      Mean    value: 55.5         (unweighted average)

yes? save/file=test.cdf/clobber v[z=@ave]
 LISTing to file test.cdf
yes? spawn ncdump test.cdf

     netcdf test {
     dimensions:
             XAX = 10 ;
     variables:
             double XAX(XAX) ;
                     XAX:point_spacing = "even" ;
     ==>        float V(XAX) ;        <<== NOTE SINGLE DIMENSION
                     V:missing_value = -1.e+34f ;
                     V:_FillValue = -1.e+34f ;
                     V:long_name = "Z[GZ=Z50] + X[GX=XAX]" ;
     ==>             V:long_name_mod = "Z=49.5:50.5@AVE" ; <<== NOTE!

     // global attributes:
                     :history = "FERRET V5.22   17-Aug-00" ;
     data:

      XAX = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;

      V = 51, 52, 53, 54, 55, 56, 57, 58, 59, 60 ;
     }

==========

2. Using a the RESHAPE function to eliminate a "singleton" axis:

You can define a new grid (DEFINE GRID) that matches the old definition but
without the singleton axis. Then use RESHAPE

yes? define axis/z=50/npoints=1/units=meters z50
yes? define axis/x=1:10:1 xax
yes? let v = z[gz=z50] + x[gx=xax]
yes? load v
yes? show grid
 Default grid for DEFINE VARIABLE is ABSTRACT
 Last successful data access was on grid (G001)
    GRID (G001)
 name       axis              # pts   start                end
 XAX       X                   10 r   1                    10
 normal    Y
 Z50       Z (METERS)           1 r   50                   50
 normal    T
yes? define grid/x=xax gcompressed
yes? let dummy = x[g=gcompressed]
yes? load RESHAPE(v,dummy)
yes? show grid
 Default grid for DEFINE VARIABLE is ABSTRACT
 Last successful data access was on grid GCOMPRESSED
    GRID GCOMPRESSED
 name       axis              # pts   start                end
 XAX       X                   10 r   1                    10
 normal    Y
 normal    Z     <<=== !! NOTE THAT THE Z AXIS DISSAPEARED
 normal    T

================================

David Darr wrote:

> Greetings Ferreters -- This may be fairly straightforward but I'm not
> quite sure how to do it. I have several netCDF files that have singleton
> dimensions (in Z). I would like to remove the Z dependence. I can do this
> fairly straightforwardly by using ncdump to create a CDL file, hand
> editing the CDL file, and then using ncgen to create the desired CDF file.
> However, I'd like to automate this process and have a Ferret script remove
> the singleton dimension. I have tried regridding to a grid that has the
> desired dimensionality but it seems the singleton dimensions get tacked on
> anyway. Any suggestions?
>
> thanks, David
>
> --
>             |  School of Oceanography       |
> David Darr  |  University of Washington     |  darr@ocean.washington.edu
>             |  Seattle, WA 98195            |

--

                |  NOAA/PMEL               |  ph. (206) 526-6080
Steve Hankin    |  7600 Sand Point Way NE  |  FAX (206) 526-6744
                |  Seattle, WA 98115-0070  |  hankin@pmel.noaa.gov




[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement