cf.read

cf.read(files, verbose=False, index=None, ignore_ioerror=False, close=False, aggregate=True)

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

All data arrays from all field components are not read from disk but are stored in the returned fields as file pointers.

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

Fields referenced by formula_terms transforms are not included in the returned list of fields. A field may be referenced in the transforms of multiple output fields, so in-place changes to that field in one transform will be seen in the other fields which reference it.

Parameters:
  • files (str or sequence) – A string or sequence of strings giving the file names or OPenDAP URLs from which to read fields. For files on disk, the file names may contain wild cards as understood by the glob module.
  • index (None or int) – Optional. If None then return all possible fields from the input files. If a non-negative integer then only return the field with this index in the otherwise full list of fields.
  • verbose (bool) – Optional. If True then print information to stdout.
  • close (bool) – Optional. If True then close each file after it has been read.
  • ignore_ioerror (bool) – Optional. If True then ignore files which produce IO errors (such as empty files, for example).
  • aggregate (bool) – Optional. If True then aggregate the fields read in from all input files into as few fields as possible using the CF aggregation rules. (Note that this code has not yet been optimsed for speed or memory usage.)
Returns:

A list of fields in a FieldList object.

Examples:

>>> f = cf.read('file*.nc')
>>> type(f)
<class 'cf.field.FieldList'>
>>> f
[<CF Field: pmsl(30, 24)>,
 <CF Field: z-squared(17, 30, 24)>,
 <CF Field: temperature(17, 30, 24)>,
 <CF Field: temperature_wind(17, 29, 24)>]
>>> cf.read('file*.nc')[0:2]
[<CF Field: pmsl(30, 24)>,
 <CF Field: z-squared(17, 30, 24)>]
>>> cf.read('file*.nc', index=0)
[<CF Field: pmsl(30, 24)>]
>>> cf.read('file*.nc')[-1]
<CF Field: temperature_wind(17, 29, 24)>
>>> cf.read('file*.nc').extract(units='K')
[<CF Field: temperature(17, 30, 24)>,
 <CF Field: temperature_wind(17, 29, 24)>]
>>> cf.read('file*.nc').extract(standard_name='.*pmsl*', 
                                units='K|Pa')[0]
<CF Field: pmsl(30, 24)>

Previous topic

cf.aggregate

Next topic

cf.write

This Page