Read spaces from netCDF 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 data parameter.
The netCDF dimension names are stored in the nc_dimensions attribute of a space’s grid and the netCDF variable names are stored in the ncvar attributes of the space and its grid components (coordinates, coordinate bounds, cell measures and transformations).
Note that if a single space has been requested by setting the index parameter and that space contains other spaces as part of a coordinate transformation or in a list ancillary variables, then the file in which the returned space resides will be scanned in its entirety so that these supplementary spaces may be located stored in the returned space.
Parameters: |
|
---|---|
Returns: | A list of spaces (a SpaceList object) or, if and only if the index parameter is set to a non-negative integer, a space (a Space object). |
See also
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', units='K')
[<CF Space: temperature(17, 30, 24)>,
<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)>]
Note
cf.read('file.nc', index=1) returns a list of spaces with one element whilst cf.read('file.nc')[1] returns a space.
>>> cf.read('file.nc', index=0)
[<CF Space: pmsl(30, 24)>]
>>> cf.read('file.nc')[0]
<CF Space: pmsl(30, 24)>
>>> cf.read1('file.nc')
<CF Space: pmsl(30, 24)>
>>> cf.read('file.nc').units
['Pa', 'm2', 'K', 'K']
See also
cf.Space.extract() for more examples of space selection by phenomena criteria.