Package netCDF4 :: Module utils
[hide private]
[frames] | no frames]

Module utils

source code

Classes [hide private]
  unicode
str(object='') -> string
  bytes
str(object='') -> string
Functions [hide private]
 
_sortbylist(A, B) source code
 
_find_dim(grp, dimname) source code
 
_walk_grps(topgrp)
Iterate through all (sub-) groups of topgrp, similar to os.walktree.
source code
 
_quantize(data, least_significant_digit)
quantize data to improve compression.
source code
 
_StartCountStride(elem, shape, dimensions=None, grp=None, datashape=None, put=False)
Return start, count, stride and indices needed to store/extract data into/from a netCDF variable.
source code
 
_out_array_shape(count)
Return the output array shape given the count array created by getStartCountStride
source code
 
_is_container(a) source code
 
_is_int(a) source code
 
_tostr(s) source code
 
_getgrp(g, p) source code
 
ncinfo() source code
 
_nc4tonc3(filename4, filename3, clobber=False, nchunk=10, quiet=False, format='NETCDF3_64BIT')
convert a netcdf 4 file (filename4) in NETCDF4_CLASSIC format to a netcdf 3 file (filename3) in NETCDF3_64BIT format.
source code
 
nc4tonc3() source code
 
_nc3tonc4(filename3, filename4, unpackshort=True, zlib=True, complevel=6, shuffle=True, fletcher32=False, clobber=False, lsd_dict=None, nchunk=10, quiet=False, classic=0, vars=None, istart=0, istop=-1)
convert a netcdf 3 file (filename3) to a netcdf 4 file The default format is 'NETCDF4', but can be set to NETCDF4_CLASSIC if classic=1.
source code
 
nc3tonc4() source code
Variables [hide private]
  python3 = False
  __package__ = 'netCDF4'
Function Details [hide private]

_quantize(data, least_significant_digit)

source code 

quantize data to improve compression. data is quantized using around(scale*data)/scale, where scale is 2**bits, and bits is determined from the least_significant_digit. For example, if least_significant_digit=1, bits will be 4.

_StartCountStride(elem, shape, dimensions=None, grp=None, datashape=None, put=False)

source code 
Return start, count, stride and indices needed to store/extract data
into/from a netCDF variable.

This function is used to convert a slicing expression into a form that is
compatible with the nc_get_vars function. Specifically, it needs
to interpret integers, slices, Ellipses, and 1-d sequences of integers
and booleans.

Numpy uses "broadcasting indexing" to handle array-valued indices.
"Broadcasting indexing" (a.k.a "fancy indexing") treats all multi-valued
indices together to allow arbitrary points to be extracted. The index
arrays can be multidimensional, and more than one can be specified in a
slice, as long as they can be "broadcast" against each other.
This style of indexing can be very powerful, but it is very hard
to understand, explain, and implement (and can lead to hard to find bugs).
Most other python packages and array processing
languages (such as netcdf4-python, xray, biggus, matlab and fortran)
use "orthogonal indexing" which only allows for 1-d index arrays and
treats these arrays of indices independently along each dimension.

The implementation of "orthogonal indexing" used here requires that
index arrays be 1-d boolean or integer. If integer arrays are used,
the index values must be sorted and contain no duplicates.

In summary, slicing netcdf4-python variable objects with 1-d integer or
boolean arrays is allowed, but may give a different result than slicing a
numpy array.

Numpy also supports slicing an array with a boolean array of the same
shape. For example x[x>0] returns a 1-d array with all the positive values of x.
This is also not supported in netcdf4-python, if x.ndim > 1.

Orthogonal indexing can be used in to select netcdf variable slices
using the dimension variables. For example, you can use v[lat>60,lon<180]
to fetch the elements of v obeying conditions on latitude and longitude.
Allow for this sort of simple variable subsetting is the reason we decided to
deviate from numpy's slicing rules.

This function is used both by the __setitem__ and __getitem__ method of
the Variable class.

Parameters
----------
elem : tuple of integer, slice, ellipsis or 1-d boolean or integer
sequences used to slice the netCDF Variable (Variable[elem]).
shape : tuple containing the current shape of the netCDF variable.
dimensions : sequence
  The name of the dimensions. This is only useful to find out
  whether or not some dimensions are unlimited. Only needed within
  __setitem__.
grp  : netCDF Group
  The netCDF group to which the variable being set belongs to.
  Only needed within __setitem__.
datashape : sequence
  The shape of the data that is being stored. Only needed by __setitime__
put : True|False (default False).  If called from __setitem__, put is True.

Returns
-------
start : ndarray (..., n)
  A starting indices array of dimension n+1. The first n
  dimensions identify different independent data chunks. The last dimension
  can be read as the starting indices.
count : ndarray (..., n)
  An array of dimension (n+1) storing the number of elements to get.
stride : ndarray (..., n)
  An array of dimension (n+1) storing the steps between each datum.
indices : ndarray (..., n)
  An array storing the indices describing the location of the
  data chunk in the target/source array (__getitem__/__setitem__).

Notes:

netCDF data is accessed via the function:
   nc_get_vars(grpid, varid, start, count, stride, data)

Assume that the variable has dimension n, then

start is a n-tuple that contains the indices at the beginning of data chunk.
count is a n-tuple that contains the number of elements to be accessed.
stride is a n-tuple that contains the step length between each element.

_nc3tonc4(filename3, filename4, unpackshort=True, zlib=True, complevel=6, shuffle=True, fletcher32=False, clobber=False, lsd_dict=None, nchunk=10, quiet=False, classic=0, vars=None, istart=0, istop=-1)

source code 

convert a netcdf 3 file (filename3) to a netcdf 4 file The default format is 'NETCDF4', but can be set to NETCDF4_CLASSIC if classic=1. If unpackshort=True, variables stored as short integers with a scale and offset are unpacked to floats. in the netcdf 4 file. If the lsd_dict is not None, variable names corresponding to the keys of the dict will be truncated to the decimal place specified by the values of the dict. This improves compression by making it 'lossy'.. If vars is not None, only variable names in the list will be copied (plus all the dimension variables). The zlib, complevel and shuffle keywords control how the compression is done.