georef#

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

Description#

Standardize the metadata required for georeferencing the data:

  • standardize spatial dimension names (and attributes for netCDF/rasters)

  • standardize the time dimension name and format (and attributes for netCDF/rasters)

  • standardize the nodata encoding (for netCDF/rasters): under the key ‘_FillValue’ in the encodings of the relevant data

  • standardize (and include if absent) the CRS: ‘grid_mapping’ key in the encoding of the relevant data, and ‘spatial_ref’ dimensionless coordinate containing CRS info

This function corrects the minor format defaults, according to Climate and Forecast Convention (https://cfconventions.org/conventions.html), thus facilitating further processing and visualization operations. For most data, these corrections are enough to solve the issues encountered in visualization softwares (such as QGIS). If some data require deeper corrections, this should be done with standardize scripts (in geop4th/workflows/standardize folder).

Parameters#

datapath (str or pathlib.Path), or variable (xarray.Dataset, xarray.DataArray, geopandas.GeoDataFrame, pandas.DataFrame or numpy.array)

Data to georeference.

Note that if data is not a variable, it will be loaded into a standard GEOP4TH variable:

  • all vector data (GeoPackage, shapefile, GeoJSON) will be loaded as a geopandas.GeoDataFrame

  • all raster data (ASCII, GeoTIFF) and netCDF will be loaded as a xarray.Dataset

  • other data will be loaded either as a pandas.DataFrame (CSV and JSON) or as a numpy.array (TIFF)

crsint or str or rasterio.crs.CRS, optional

Coordinate reference system of the source (data), that will be embedded in the 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 the same location as data, while appending ‘_georef’ to its name. If to_file is a path, the resulting dataset will be exported to this specified filepath.

var_list(list of) str, optional

Main variables, in case data variables are too excentric to be automatically inferred.

**time_kwargs
Arguments for standardize_time_coord function:
  • var : time variable name (str), optional, default None

  • infer_from : {‘dims’, ‘coords’, ‘all’}, optional, default ‘dims’

Returns#

xarray.Dataset or geopandas.GeoDataFrame with a standard georeferencement. If to_file argument is used, the resulting dataset can also be exported to a file.

Example#

>>> geo.georef(r"<path/to/my/file>", to_file = True)