nd.tiling package

This module may be used to mosaic and tile multiple satellite image products.

TODO: Contain buffer information in NetCDF metadata?

nd.tiling.auto_merge(datasets, buffer=True, chunks={}, meta_variables=[], use_xarray_combine=True)[source]

Automatically merge a split xarray Dataset. This is designed to behave like xarray.open_mfdataset, except it supports concatenation along multiple dimensions.

  • datasets (str or list of str or list of xarray.Dataset) – Either a glob expression or list of paths as you would pass to xarray.open_mfdataset, or a list of xarray datasets. If a list of datasets is passed, you should make sure that they are represented as dask arrays to avoid reading the whole dataset into memory.

  • buffer (bool, optional) – If True, attempt to automatically remove any buffer from the tiles (default: True).

  • meta_variables (list, optional) – A list of metadata items to concatenate as variables.

  • use_xarray_combine (bool, optional) – Use xr.combine_by_coords to combine the datasets (default: True). Only available from xarray>=0.12.2. Will fallback to a custom implementation if False or unavailable.


The merged dataset.

Return type


nd.tiling.debuffer(datasets, flat=True)[source]

Remove buffer from tiled datasets.

  • datasets (list of xr.Dataset) – The overlapping tiles.

  • flat (bool, optional) – If True, return a flat list. Otherwise, return a numpy array representing the correct order of the tiles (default: True).

nd.tiling.map_over_tiles(files, fn, args=(), kwargs={}, path=None, suffix='', merge=True, overwrite=False, compute=True)[source]

Apply function to each tile.

  • files (str or list of str) – A glob expression matching all tiles. May also be a list of file paths.

  • fn (function) – The function to apply to each tile.

  • args (tuple, optional) – Additional arguments to fn

  • kwargs (dict, optional) – Additional keyword arguments to fn

  • path (str, optional) – The output directory. If None, write to same directory as input files. (default: None)

  • suffix (str, optional) – If input file is part.0.nc, will create part.0{suffix}.nc. (default: ‘’)

  • merge (bool, optional) – If True, return a merged view of the result (default: True).

  • overwrite (bool, optional) – Force overwriting existing files (default: False).

  • compute (bool, optional) – If True, compute result immediately. Otherwise, return a dask.delayed object (default: True).


The (merged) output dataset.

Return type


nd.tiling.sort_into_array(datasets, dims=None)[source]

Create an array corresponding to the way the datasets are tiled.

nd.tiling.sort_key(ds, dims)[source]

To be used as key when sorting datasets.

nd.tiling.tile(ds, path, prefix='part', chunks=None, buffer=0)[source]

Split dataset into tiles and write to disk. If chunks is not given, use chunks in dataset.

  • ds (xarray.Dataset) – The dataset to split into tiles.

  • path (str) – The output directory in which to place the tiles.

  • prefix (str, optional) – The tile names will start with `{prefix}.`

  • chunks (dict, optional) – A dictionary of the chunksize for every dimension along which to split. By default, use the dask array chunksize if the data is represented as dask arrays.

  • buffer (int or dict, optional) – The number of overlapping pixels to store around each tile (default: 0). Can be given as an integer or per dimension as dictionary.