cwatm.landcover#

cwatm.landcover(data, *, year=None, sep='|', decimal='.', csv_date_format='%y-%m-%d', mask=None, bounds=None, resolution=None, x0=None, y0=None, base_template=None, outpath=None, polygon_file=None, **rio_kwargs)[source]#

This function process a guideline file, typically a tabular CSV file, in which are described where and how to process the data to create CWatM landcover parameters. Therefore, besides this guideline file, cwatm.landcover() will also need a vector file with landcover polygons (or a raster file with area values), and some tabular CSV files containing cropCoefficient and interceptCap timeseries during one year (these timeseries can be parse, they do not need to be complete nor regular).

With these elements, this function generates the following files:

  • at the root (cwatm/ folder):

    • ‘<guideline_filename>_area_<year>_<mask>_<resolution>.nc’: raster file with, in each cell, the area of each landcover described in the guideline file

    • ‘<guideline_filename>_cropgroupnumber_<year>_<mask>_<resolution>.nc’: a oen-year netCDF with the cropgroupnumber values in each cell

    • ‘<guideline_filename>_fracLandcover_<year>_<mask>_<resolution>.nc’: a raster file with the fraction of CWatM landcovers in each cell

  • in landcover sub-folders (grassland/, forest/, irrNonPaddy/, irrPaddy/):

    • ‘<guideline_filename>_cropCoefficient_<year>_<mask>_<resolution>.nc’

    • ‘<guideline_filename>_cropgroupnumber_<year>_<mask>_<resolution>.nc’

    • ‘<guideline_filename>_interceptCap_<year>_<mask>_<resolution>.nc’

    • ‘<guideline_filename>_maxRootDepth_<year>_<mask>_<resolution>.nc’

Nested use#

For each data, this function creates netCDF files in the root folder and in the subfolders of each 6 CWatM landcover. It can be used in a nested way: this function can be called with data guidelines relative to a sub-landcover (for example a ‘crop.csv’ data defining ‘maize’ and ‘wheat’), and the generated files (here for example .cwatmgrasslandcrop_maxRootDepth.nc) can be used as arguments in the guidelines of a ‘final.csv’ data (which defines e.g. ‘wetland’, ‘pasture’, ‘crop’ … and uses the netCDF above for ‘crop’ values). In this example, the ‘crop.csv’ call will generates netCDF files in CWatM landcover subfolders (‘forest’, ‘grassland’, ‘irrNonPaddy’, …), which will be used as arguments in ‘final.csv’, but also some netCDF files in the root folder, such as ‘crop_fracLandcover.nc’ or ‘crop_cropgroupnumber.nc’. These root files are useless, as they are intended to give values weighted by CWatM landcovers, but the ‘crop.csv’ data does not include all CWatM landcovers. The files that should be used in CWatM are ‘final_fracLandcover.nc’ etc. in the root folder, and ‘final_maxRootDepth.nc’ etc. in the 6 landcover subfolders.

Parameters#

datapandas.DataFrame, or str or pathlib.Path

Tabular files listing the rules to differentiate landcovers and to compute CWatM landcover parameters.

maskstr, Path, shapely.geometry, xarray.DataArray or geopandas.GeoDataFrame, optional

Filepath of mask used to clip the data.

boundsiterable or None, optional, default None

Boundaries of the target domain as a tuple (x_min, y_min, x_max, y_max). The values are expected to be given according to bounds_crs if it is not None. If bounds_crs is None, bounds are expected to be given according to the destination CRS dst_crs if it is not None. It dst_crs is also None, bounds are then expected to be given according to the source CRS (src_crs of data’s CRS).

resolutionfloat or tuple, optional

DESCRIPTION. The default is None.

x0: number, optional

Origin of the X-axis, used to align the reprojection grid.

y0: number, optional

Origin of the Y-axis, used to align the reprojection grid.

base_templatestr, Path, xarray.DataArray or geopandas.GeoDataFrame, optional

Filepath, used as a template for spatial profile. Supported file formats are .tif, .nc and vector formats supported by geopandas (.shp, .json, …).

outpathstr or pathlib.Path, optional

Required when data is not a filepath. Define the location where the outputs will be exported (inside a cwatm/ sub-folder). If outpath is None and data is a filepath, the outputs will be exported at the root of data (inside a cwatm/ sub-folder).

**rio_kwargskeyword args, optional

Argument passed to the xarray.Dataset.rio.reproject() function call.

Note: These arguments are prioritary over base_template attributes.

May contain:

  • dst_crs : str

  • resolution : float or tuple

  • shape : tuple (int, int) of (height, width)

  • transform : Affine

  • nodata : float or None

  • resampling :

    • see help(rasterio.enums.Resampling)

    • most common are: 5 (average), 13 (sum), 0 (nearest), 9 (min), 8 (max), 1 (bilinear), 2 (cubic)…

    • the functionality 'std' (standard deviation) is also available

  • see help(xarray.Dataset.rio.reproject)

Returns#

Generates the landcover files required by CWatM:

  • at the root (cwatm/ folder):

    • ‘<guideline_filename>_cropgroupnumber_<year>_<mask>_<resolution>.nc’: a oen-year netCDF with the cropgroupnumber values in each cell

    • ‘<guideline_filename>_fracLandcover_<year>_<mask>_<resolution>.nc’: a raster file with the fraction of CWatM landcovers in each cell

    • ‘<guideline_filename>_area_<year>_<mask>_<resolution>.nc’: raster file with, in each cell, the area of each landcover described in the guideline file (not required for CWatM, but usefull for other inputs formatting)

  • in landcover sub-folders (grassland/, forest/, irrNonPaddy/, irrPaddy/):

    • ‘<guideline_filename>_cropCoefficient_<year>_<mask>_<resolution>.nc’

    • ‘<guideline_filename>_cropgroupnumber_<year>_<mask>_<resolution>.nc’

    • ‘<guideline_filename>_interceptCap_<year>_<mask>_<resolution>.nc’

    • ‘<guideline_filename>_maxRootDepth_<year>_<mask>_<resolution>.nc’