xradarsat2.load_digital_number

xradarsat2.load_digital_number(dt, resolution=None, chunks={'line': 5000, 'sample': 5000}, resampling=Resampling.rms)

Add to the initial datatree (that contains all datasets) a new dataset with digital numbers (name of the dataset = digital_numbers)

With resolution=None, the imagery files are read lazily at full resolution, in uint16.

Otherwise, the files are resampled while reading, on a grid of whole cells of r_line x r_sample pixels (r is the cell size in pixels):

  • cell k covers the pixels [k * r, (k + 1) * r), and its coordinate is the cell center k * r + (r - 1) / 2, in pixels of the full resolution image;

  • there are int(size / r) cells: the pixels left over at the bottom and right edges of the image (less than one cell) are not used;

  • the pixels at 0 (outside the swath) are not counted: a cell straddling the swath border is the resampling mean of its valid pixels only, and a cell without any valid pixel is 0;

  • the cell values are kept in float32, they are not rounded to integers;

  • r may be non-integer (e.g. 50 m pixels at “125m” give 2.5 pixels): a pixel cut by a cell edge is weighted by the part of it inside the cell.

The dataset also holds valid_pixel_fraction: the fraction of non-zero pixels in each cell (0: outside the swath, 1: full cell), computed for each polarisation (the swath borders of the polarisations can differ by a few pixels).

Parameters:
  • dt (xr.Datatree) – datatree containing every dataset

  • resolution (str, dict[str, int], None or number) –

    cell size, None by default:

    • None: full resolution, no resampling;

    • str ending with “m”, like “1000m”: size in meters, converted to pixels with the sampled line and pixel spacings of the product;

    • number: size in meters, as for a str;

    • dict like {“line”: 20, “sample”: 20}: size in pixels.

  • chunks (dict[str, int]) – dask chunks, with keys “line” and “sample”. A “pol” key is set to 1.

  • resampling (rasterio.enums.Resampling) – mean used for the cells, only with a resolution. rasterio.enums.Resampling.rms by default.

Returns:

Initial datatree + dataset with digital_number and, if resampled, valid_pixel_fraction (dims “pol”, “line”, “sample”).

Return type:

xr.Datatree