standardize_grid_mapping#

geobricks.standardize_grid_mapping(data, crs=None, to_file=False, var_list=None)[source]#

Some visualization softwares (such as GIS) need a standard structure for grid_mapping information in netCDF datasets:

  • grid_mapping info should be in encodings and not in attrs

  • grid_mapping info should be stored in a coordinate names ‘spatial_ref’

This function standardizes grid_mapping information, so that it is compatible with such softwares as QGIS.

Parameters#

datapath (str or pathlib.Path), or variable (xarray.Dataset, xarray.DataArray)

Dataset (netCDF or xarray variable) whose nodata information will be standardized.

Note that data will be loaded into a xarray.Dataset or xarray.DataArray.

crsint or str or rasterio.crs.CRS, optional

Coordinate reference system of the source (data). When passed as an integer, src_crs refers to the EPSG code. When passed as a string, src_crs can be OGC WKT string or Proj.4 string.

to_filebool or path (str or pathlib.Path), default False

If True and if data is a path (str or pathlib.Path), the resulting dataset will be exported to a file with the same pathname and the suffix ‘_std_grid_map’. If to_file is a path, the resulting dataset will be exported to this specified filepath.

var_list(list of) str, optional

List of main variables can be specified by user, to avoid any prompt.

Returns#

data_dsxarray.Dataset

Standard GEOP4TH variable (xarray.Dataset) with corrected nodata information.

If to_file argument is used, the resulting dataset can also be exported to a file.