raster_tools.open_dataset#

raster_tools.open_dataset(path, crs=None, ignore_extra_dim_errors=False, xarray_kwargs=None)[source]#

Open a netCDF or GRIB dataset.

This function opens a netCDF or GRIB dataset file and returns a dictionary of Raster objectds where each raster corrersponds to the variables in the the file. netCDF/GRIB files can be N-dimensional, while rasters only comprehend 2 to 3 dimensions (band, y, x), so it may not be possible to map all variables in a file to a raster. See the ignore_extra_dim_errors option below for more information.

Parameters
  • path (str) – THe path to the netCDF or GRIB dataset file.

  • crs (str, rasterio.crs.CRS, optional) – A coordinate reference system definition to attach to the dataset. This can be an EPSG, PROJ, or WKT string. It can also be a rasterio.crs.CRS object. netCDF/GRIB files do not always encode a CRS. This option allows a CRS to be supplied, if known ahead of time. It can also be used to override the CRS encoded in the file.

  • ignore_extra_dim_errors (bool, optional) – If True, ignore dataset variables that cannot be mapped to a raster. An error is raised, otherwise. netCDF/GRIB files allow N-dimensional. Rasters only comprehend 2 or 3 dimensional data so it is not always possible to map a variable to a raster. The default is False.

  • xarray_kwargs (dict, optional) – Keyword arguments to supply to xarray.open_dataset when opening the file.

Raises
  • raster_tools.io.AffineEncodingError – Raised if the affine matrix is improperly encoded.

  • ra

Returns

dataset – A dict of Raster objects. The keys are the variable names in the dataset file and the values are the corresponding variable data as a raster.

Return type

dict of Raster