Generate Pauli RGB for FP data (pauli_rgb)#

polsartools.pauli_rgb(infolder, save_tif=False, window_size=None)[source]

Generate Pauli RGB image from polarimetric SAR data (C4, C3, T4, T3, or S2 matrices).

This function creates a Pauli decomposition RGB composite image from full polarimetric SAR data.

Examples

>>> # Generate Pauli RGB from a polarimetric folder
>>> pauli_rgb("/path/to/polSAR_data")
>>> # Output both PNG and GeoTIFF versions
>>> pauli_rgb("/path/to/polSAR_data", tif_flag=True)
Parameters:
  • infolder (str) – Path to the folder containing polarimetric matrix files (.bin or .tif). Supports full- and dual-pol data in formats: C4, C3, T4, T3, or S2.

  • save_tif (bool, default=False) – If True, generates both PNG and GeoTIFF (.tif) versions of the Pauli RGB image.

  • window_size (int, optional) – Size of the moving average window for smoothing. If None, no smoothing is applied.

Returns:

  • None

  • Writes output to –

    • PauliRGB.png: RGB composite with world file for georeferencing

    • PauliRGB.tif: Optional GeoTIFF output if tif_flag=True

Generate false color RGB for DP/CP data (rgb_dp)#

polsartools.rgb_dp(infolder, type=1, save_tif=False, window_size=None)[source]

Generate false-color RGB visualization from dual-polarimetric Sxy, C2 SAR data.

This function creates an RGB image from dual-pol (Sxy, C2) matrix inputs.

Examples

>>> # Generate type-1 false-color RGB from C2 folder
>>> rgb_dp("/path/to/data")
>>> # Output both PNG and GeoTIFF versions
>>> rgb_dp("/path/to/data", type=3, tif_flag=True)
Parameters:
  • infolder (str) – Path to the input folder containing C2 matrix components (C11, C22, C12_real).

  • type (int, {1, 2, 3, 4}, default=1) – RGB combination type: - 1: Blue=C11, Red=C22, Green=|C11 + C22 - 2·C12_real| - 2: Blue=C22, Red=C11, Green=|C11 + C22 - 2·C12_real| - 3: Blue=C11, Red=C22, Green=|C11 - C22| - 4: Blue=C22, Red=C11, Green=|C22 - C11| - 5: Blue=C11, Red=C11, Green=C22

  • save_tif (bool, default=False) – If True, generates a GeoTIFF (.tif) file alongside the PNG image.

Returns:

Writes RGB visualization to disk: - ‘RGB#.png’: False-color PNG image (with world file for georeferencing) - ‘RGB#.tif’: Optional GeoTIFF output if tif_flag=True

Return type:

None

Generate false color RGB for decomposed powers (rgb)#

polsartools.rgb(Rpath, Gpath, Bpath, norm_each=True, lp=5, gp=95, norm_span=False, save_tif=False, window_size=None)[source]

Generate false-color RGB visualization from three input raster files.

Examples

>>> # Generate Pauli RGB from a polarimetric folder
>>> rgb("/path/to/red.tif", "/path/to/green.tif", "/path/to/blue.tif")
>>> # Output both PNG and GeoTIFF versions
>>> rgb("/path/to/red.tif", "/path/to/green.tif", "/path/to/blue.tif", tif_flag=True)
Parameters:
  • Rpath (str) – Path to the red channel raster file.

  • Gpath (str) – Path to the green channel raster file.

  • Bpath (str) – Path to the blue channel raster file.

  • norm_each (bool, default=True) – If True, normalize each channel separately.

  • lp (int, default=5) – Lower percentile for normalization (0-100). Only used if norm_each=True.

  • gp (int, default=95) – Upper percentile for normalization(0-100). Only used if norm_each=True.

  • norm_span (bool, default=False) – If True, normalize each channel with total power.

  • save_tif (bool, default=False) – If True, generates a GeoTIFF (.tif) file alongside the PNG image.

  • window_size (int, optional) – Size of the moving average window for smoothing. If None, no smoothing is applied.

Returns:

  • None

  • Writes output to

  • - RGB.png (RGB composite with world file for georeferencing)

  • - RGB.tif (Optional GeoTIFF output if tif_flag=True)

Generate polarimetric signatures for FP data (signature_fp)#

polsartools.signature_fp(mat=None, title='', ppath='', cmap='jet', plotType=1, fig=None, axes=None, start_index=0)[source]

Generates and visualizes polarimetric signatures from a 2x2 scattering matrix (S2) or a 3x3 coherency matrix (T3).

Examples

>>> mat = np.array([[1, 0], [0, 1]]) # Trihedral
>>> signature_fp(mat, title='Trihedral', plotType=1)
Parameters:
  • mat (np.ndarray (2x2 or 3x3) or None) – Input matrix. If shape is (2, 2), treated as S2. If (3, 3), treated as T3. If None, only theoretical/canonical plots will be generated.

  • title (str, optional) – Title of the plot. Default is an empty string.

  • ppath (str, optional) – Name of the output file (*.png). Default is an empty string.

  • cmap (str, optional) – Colormap used for visualizing the data. Default is ‘jet’.

  • plotType (int, optional) –

    Determines the type of plot to generate:

    • 1: Standard polarimetric signature via pol_sign.

    • 2: 2D polarimetric signature via pol_sign2d.

    • 3: Poincaré sphere mapping via poincare_plot.

    • 4: Render empty or canonical Poincaré sphere via poincare_sphere (S2 not required).

Samples pixel values from rasters(sample_rasters)#

polsartools.sample_rasters(raster_files, vector_file, output_file, window=1, custom_column_names=None)[source]

Samples pixel values from one or more raster files at point locations specified in a vector file, with automatic spatial reference verification and reprojection.

This function automatically checks if the vector file’s coordinate reference system (CRS) matches the reference raster. If they mismatch, it reprojects the vector file on-the-fly to a temporary GeoPackage, extracts the raster values (or windowed averages if window > 1), appends them as new attributes, saves the resulting GeoDataFrame, and cleans up any temporary files.

Parameters:#

raster_filesstr or list of str

A single file path string or a list of file paths pointing to the target raster dataset(s).

vector_filestr

File path to the input vector dataset (e.g., Shapefile, GeoJSON, GeoPackage) containing point geometries.

output_filestr

File path where the final sampled vector dataset will be saved.

windowint, optional

The size of the square neighborhood window (in pixels) to sample around each point. - If window=1 (default), it extracts the exact pixel value at the point location. - If window > 1, it computes the local spatial mean (ignoring NoData values) within the window.

custom_column_namesdict, optional

A dictionary mapping raster base names to custom column names for the output attributes. If None, column names are automatically generated from the raster file names using create_column_names(). Example: { “NISAR_HH_band_20260119”: “backscatter_hh”, “NISAR_HV_band_20260119”: “backscatter_hv”}

Returns:#

None

The sampled dataset is written directly to output_file.

Examples:#

>>> # Example 1: Sampling multiple rasters with default settings
>>> raster_list = ['/ratser1.tif', '/raster2.tif', '/raster3.tif']
>>> sample_rasters(
...     raster_files=raster_list,
...     vector_file="test_points.geojson",
...     output_file="test_points_sampled.geojson",
...     window=1
... )
>>> # Example 2: Using a 3x3 window mean for neighborhood extraction
>>> sample_rasters(
...     raster_files=raster_list,
...     vector_file="test_points.geojson",
...     output_file="test_points_window_sampled.geojson",
...     window=3
... )
>>> # Example 3: Passing a single raster file path string
>>> sample_rasters(
...     raster_files="raster1.tif",
...     vector_file="test_points.geojson",
...     output_file="single_raster_sampled.geojson",
...     window=1
... )