Need help with ctl for netcdf

Arlindo da Silva arlindo.dasilva at GMAIL.COM
Wed May 20 19:50:00 EDT 2009


On Fri, May 15, 2009 at 3:43 PM, P.R. <romero619 at hotmail.com> wrote:

> I need help setting up the control file for a netcdf file.
> The file has a strange variable & dimensions setup, so I couldn’t open it
> automatically with sdfopen.
> Here's an 'ncdump' of the netcdf header
>
> #ncdump -h GEBCO_08.nc
>
> netcdf GEBCO_08 {
> dimensions:
>        side = 2 ;
>        xysize = 933120000 ;
> variables:
>        double x_range(side) ;
>                x_range:units = "user_x_unit" ;
>        double y_range(side) ;
>                y_range:units = "user_y_unit" ;
>        short z_range(side) ;
>                z_range:units = "user_z_unit" ;
>        double spacing(side) ;
>        int dimension(side) ;
>        short z(xysize) ;
>                z:scale_factor = 1. ;
>                z:add_offset = 0. ;
>                z:node_offset = 1 ;
>
> // global attributes:
>                :title = "GEBCO_08 Grid" ;
>                :source = "20090202" ;
> }
>
> This file contains bathymetric/elevation data in meters in the 'z'
> variable.
> However, it doesn’t appear to have x&y variables, just the total x*y grid
> size (933120000).
> Here's a description of the grid from the file's documentation:
>
> The complete data set gives global coverage.
> It consists of 21,600 rows x 43,200 columns, resulting in 9,331,200,000
> data
> points.
>

Yikes, everything is lumped into a single 1D array, I don't think grads will
be able to read it since the array has rank 1.  The simplest solution is to
write a small program to read this data and write it in a more grads
friendly way.  Since I know you have pygrads installed you could try
something like this:

[] ga-> from mpl_toolkits.basemap import NetCDFFile
[] ga-> z = NetCDFFile('GEBCO.nc').variables['z'][:].astype(float32)

at this point point z should be a 1D array of size 933120000. Just write it
to a flat binary file

[] ga-> z.tofile('GEBCO.bin')

and prepare a ctl to go along with it. If you are inspired you could also
reshape z as a 2D array and write it to a coards compatible NetCDF file that
grads can read. Here is the API:

  http://www-md.fsl.noaa.gov/eft/developer/netCDFPythonInterface.html

    Arlindo


-- 
Arlindo da Silva
dasilva at alum.mit.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20090520/18d3f78d/attachment.html 


More information about the gradsusr mailing list