cf.read

cf.read(files, read_data=False, verbose=False, index=None, ignore_ioerror=False, close=False, calendar=None, long_name=None, standard_name=None, units=None, extract={})

Read spaces from input files from disk or from an OPeNDAP server.

By default, all data arrays from all space components are not read from disk but are stored in the returned spaces as file pointers. This behaviour may be changed with the read_data parameter.

NetCDF dimension names are stored in the nc_dimensions attribute of a space’s grid and netCDF variable names are stored in the private attribute ncvar of the space and each of its grid components.

Parameters:
  • files (str or sequence) – A string or sequence of strings giving the file names or OPenDAP URLs from which to read spaces. For files on disk, the file names may contain wild cards as understood by the glob module.
  • read_dataOptional. If True then read the data of each space, including the data of its grid components into memory Otherwise all data are stored as file pointers. data.
  • index (None or int) – Optional. If None then return all possible spaces from the input files. If a non-negative integer then only return the space with this index in the otherwise full list of spaces.
  • verbose (bool) – Optional. If True then print information to stdout.
  • closeOptional. If True then close each file after it has been read.
  • ignore_ioerrorOptional. If True then ignore files which produce IO errors (such as empty files, for example).
  • calendar (str) – Optional. Equivalent to setting ‘calendar’ in the extract keyword dictionary
  • long_name (str) – Optional. Equivalent to setting ‘long_name’ in the extract keyword dictionary
  • standard_name (str) – Optional. Equivalent to setting ‘standard_name’ in the extract keyword dictionary
  • units (str) – Optional. Equivalent to setting ‘units’ in the extract keyword dictionary
  • extract (dict) – Optional. A dictionary of space selection criteria. Only spaces which match the criteria are returned. Refer to ematch for details.
Returns:

A list of spaces in a SpaceList object.

Examples:

>>> s = cf.read('file*.nc')
>>> type(s)
<class 'cf.space.SpaceList'>
>>> s
[<CF Space: pmsl(30, 24)>,
 <CF Space: z-squared(17, 30, 24)>,
 <CF Space: temperature(17, 30, 24)>,
 <CF Space: temperature_wind(17, 29, 24)>]
>>> cf.read('file*.nc')[0:2]
[<CF Space: pmsl(30, 24)>,
 <CF Space: z-squared(17, 30, 24)>]
>>> cf.read('file*.nc', index=0)
[<CF Space: pmsl(30, 24)>]
>>> cf.read('file*.nc')[-1]
<CF Space: temperature_wind(17, 29, 24)>
>>> cf.read('file*.nc', extract={'units': 'K'})
[<CF Space: temperature(17, 30, 24)>,
 <CF Space: temperature_wind(17, 29, 24)>]
>>> cf.read('file*.nc', standard_name='.*pmsl*', extract={'units': 'K|Pa'})[0]
<CF Space: pmsl(30, 24)>

Previous topic

Functions

Next topic

cf.write

This Page