Derive stokes parameters (stokes_parm)#

polsartools.stokes_parm(SxxFile, SxyFile, win=3, fmt='tif', cog=False, ovr=[2, 4, 8, 16], comp=False, max_workers=None, block_size=(512, 512), progress_callback=None)[source]

This function computes the Stokes parameters and child parameters from Single look Scattering Matrix elements.

Examples

>>> # Basic usage with default parameters
>>> stokes_parm("/path/to/s11.bin", "/path/to/s12.bin")
>>> # Advanced usage with custom parameters
>>> stokes_parm(
...     "/path/to/s11.bin",
...     "/path/to/s12.bin",
...     win=5,
...     fmt="tif",
...     cog=True,
...     block_size=(1024, 1024)
... )
Parameters:
  • SxxFile (str) – Path to the Sxx file.

  • SxyFile (str) – Path to the Sxy file.

  • win (int, default=3) – Size of the spatial averaging window.

  • fmt ({'tif', 'bin'}, default='tif') – Output file format: - ‘tif’: GeoTIFF format - ‘bin’: Raw binary format

  • cog (bool, default=False) – If True, creates a Cloud Optimized GeoTIFF (COG) with internal tiling and overviews for efficient web access.

  • ovr (list[int], default=[2, 4, 8, 16]) – Overview levels for COG creation. Each number represents the decimation factor for that overview level.

  • comp (bool, default=False) – If True, applies LZW compression to the output GeoTIFF files.

  • max_workers (int | None, default=None) – Maximum number of parallel processing workers. If None, uses CPU count - 1 workers.

  • block_size (tuple[int, int], default=(512, 512)) – Size of processing blocks (rows, cols) for parallel computation. Larger blocks use more memory but may be more efficient.

Returns:

  • None

  • Writes stkokes and child parameters to disk –

    • stokes_g0 (.bin or .tif)

    • stokes_g1 (.bin or .tif)

    • stokes_g2 (.bin or .tif)

    • stokes_g3 (.bin or .tif)

    • stokes_e1 (.bin or .tif)

    • stokes_e2 (.bin or .tif)

    • stokes_e1norm (.bin or .tif)

    • stokes_e2norm (.bin or .tif)

    • stokes_phi (.bin or .tif)

    • stokes_tau (.bin or .tif)

    • stokes_x_poincare (.bin or .tif)

    • stokes_y_poincare (.bin or .tif)

    • stokes_H (.bin or .tif)

    • stokes_A (.bin or .tif)

    • stokes_contrast (.bin or .tif)

    • stokes_DoL (.bin or .tif)

    • stokes_DoCP (.bin or .tif)

    • stokes_LPR (.bin or .tif)

    • stokes_CPR (.bin or .tif)

Prepare DEM (prepare_dem)#

polsartools.prepare_dem(bbox, out_path='dem.tif', dem_type='SRTM1', hgt_dir='hgt_tiles', apply_correction=True, clip=True, clean_tiles=True)[source]

Prepares a Digital Elevation Model (DEM) from downloaded elevation tiles.

This function downloads elevation tiles based on a bounding box, mosaics them into a single raster, optionally applies ellipsoid height correction, clips to the bounding box, and saves the result as a GeoTIFF. Temporary tile files can be cleaned up after processing.

Examples

>>> bbox = (-70.2, 43.5, -66.2, 45.8)  # xmin, ymin, xmax, ymax
>>> prepare_dem(bbox, out_path="SRTM1_mosaic_clip.tif")
>>> prepare_dem(bbox, out_path="SRTM3_mosaic_clip.tif", dem_type="SRTM3")
Parameters:
  • bbox (tuple of float) – Bounding box in the format (xmin, ymin, xmax, ymax), in geographic coordinates (longitude, latitude).

  • out_path (str, optional) – Path to save the output DEM GeoTIFF file. Defaults to “dem.tif”.

  • dem_type (str, optional) – Type of DEM source. Options include “SRTM1”, “SRTM3”, “COP30”, “COP90”. Defaults to “SRTM1”.

  • hgt_dir (str, optional) – Directory to store downloaded tiles. Defaults to “hgt_tiles”.

  • apply_correction (bool, optional) – Whether to apply WGS84ellipsoid height correction to SRTM tiles. Defaults to True.

  • clip (bool, optional) – Whether to clip the output DEM to the bounding box. Defaults to False.

  • clean_tiles (bool, optional) – Whether to delete the tile directory after processing. Defaults to True.

Returns:

The function saves the DEM to the specified out_path.

Return type:

None

Notes

  • Uses GDAL for mosaicking and warping.

  • Supports ellipsoid correction for SRTM1 and SRTM3.

  • Automatically creates empty tiles for missing SRTM1 data.

HD5 Info (h5_info)#

polsartools.h5_info(file_path, show_unimplemented=True)[source]

Displays the hierarchical structure and metadata of an HDF5 file.

Recursively traverses the HDF5 file and prints information about its groups and datasets, including dataset paths, shapes, and data types.

The function also identifies unimplemented or unsupported HDF5 objects and optionally displays them in the output.

Parameters:
  • file_path (str or pathlib.Path) – Path to the input HDF5 file.

  • show_unimplemented (bool, optional) – If True (default), displays unimplemented or unsupported HDF5 objects along with their paths and shapes. If False, these objects are skipped.

Returns:

Prints the hierarchical structure and metadata of the HDF5 file to the console. Does not return any values.

Return type:

None

Examples

>>> import polsartools as pst
>>> pst.h5_info("path/to/file.h5")
>>> pst.h5_info("path/to/file.h5", show_unimplemented=False)