Re: Slices with addfile

From: Dennis Shea (shea AT XXXXXX)
Date: Fri Jan 16 2004 - 10:39:35 MST

  • Next message: K Smith: "natgrids"

    The answer to your question is "yes" you can read arbitrary slices.
    Any format accessed via addfile (nc[,cdf], grb[,grib], hdf, ccm)
    allows the user to input data subsections (aka, hyperslabs, slices).
    NCL handles the meta data such that the input data object reflects the
    the data subsetting.

    Basically, you can user standard subscripting or, when appropriate,
    coordinate subscripting. See:
          http://ngwww.ucar.edu/ngdoc/ng4.1/ref/ncl/Overview.html
    Specifically, look at the subscript description.

       f = addfile ("foo.grb" , "r")
       X = f->X ; read entire variable
       x = f->X(3:9,6,:,:) ; read times corresponding
                                       ; to indices 3 to 9 and level 6
                                       ; remember NCL starts at 0.
                                       
    if they data array can be accessed via coordinate variables

      x = f->X(:,{500},{-30:30},{0:90}) ; coordinate subscripting
      
      x = f->X(:,{200:850}, 18:49:2, 10) ; coord and index subscripting
      
      x = f->X(::4,:,:,:) ; every 4th time step
      
    Further, let's say the file has 100 time steps and u want
    the times at some specific times at 500 hPa, then you could

      i = (/0,13,56,57,58,69,81/) ; user specified times [index values]
      
      x = f->X(i,{500},:,:) ; will contain the 7 requested time steps
                                  ; at 500 hPa

    >Date: Thu, 15 Jan 2004 20:05:53 +0000
    >From: "Marquardt, Christian" <christian.marquardt@metoffice.com>
    >To: ncl-talk@ucar.edu
    >
    >Hello,
    >
    >I'm more or less new to ncl, so I apologise in advance if I have missed
    >the obvious...
    >
    >I'm reading data from a large grib file which contains several variables
    >on multiple levels and for a number of valid times. The usual approach
    >
    > gribfile = addfile(<filename>)
    > data = gribfile-><varname>
    >
    >works fine, but seems to slurp in the full 4d block of data at once (or
    >am I wrong here?). However, I usually only a slice of the full data set
    >(say, all times, but a single level only, or a vertical slice, or only
    >part of the entire time series, or...). So reading the entire data block
    >at once seems to be unnecessary slow; it also requires huge amounts of
    >memory.
    >
    >Is there a way to read only slices of the data? For example, when using
    >data in a netCDF from a fortran (or so) program, I could specify the
    >start indices in each dimension, etc.
    >
    >Thanks a lot,
    >
    > Christian.
    >
    >
    >--
    >Dr Christian Marquardt Research Scientist
    >Met Office FitzRoy Road Exeter EX1 3PB United Kingdom
    >Tel: +44 (0)1392 88 4820 Fax: +44 (0)1392 885681
    >E-mail: christian.marquardt AT metoffice.com http://www.metoffice.com
    >
    >
    >_______________________________________________
    >ncl-talk mailing list
    >ncl-talk@ucar.edu
    >http://mailman.ucar.edu/mailman/listinfo/ncl-talk

    _______________________________________________
    ncl-talk mailing list
    ncl-talk@ucar.edu
    http://mailman.ucar.edu/mailman/listinfo/ncl-talk



    This archive was generated by hypermail 2b29 : Fri Jan 16 2004 - 10:29:54 MST