Convert Covariance matrix (C4/C3/C2) (convert_C)#

polsartools.convert_C(in_dir, mat='T3', azlks=1, rglks=1, win=1, fmt='tif', cog=False, ovr=[2, 4, 8, 16], comp=False, recip=True, cf=1, out_dir=None, max_workers=None, block_size=(512, 512), phi=0.0, chi=0.0, progress_callback=None)[source]

Convert covariance matrices (C2, C3, C4) into coherency (T2, T3, T4) or covariance (C2, C3, C2HX, C2VX, C2HV, C2CP) matrices.

Supports GeoTIFF and PolSARpro-compatible binary output formats, multilooking and spatial filtering.

Examples

>>> # Convert C3 to T3 matrix
>>> convert_C("/path/to/C3_data", mat="T3")
>>> # Convert C4 to T4 matrix
>>> convert_C("/path/to/C4_data", mat="T4")
>>> # Convert C4 to C3 matrix
>>> convert_C("/path/to/C4_data", mat="C3")
>>> # Extract dual-pol C2HV from C4
>>> convert_C("/path/to/C4_data", mat="C2HV")
>>> # Convert C3 to compact-pol C2
>>> convert_C(
...     "/path/to/C3_data",
...     mat="C2CP",
...     phi=0.0,
...     chi=0.0
... )
>>> # Apply multilooking and spatial filtering
>>> convert_C(
...     "/path/to/C3_data",
...     mat="T3",
...     azlks=4,
...     rglks=4,
...     win=5
... )
>>> # Generate Cloud Optimized GeoTIFF output
>>> convert_C(
...     "/path/to/C4_data",
...     mat="T4",
...     fmt="tif",
...     cog=True,
...     comp=True
... )
Parameters:
  • in_dir (str) –

    Path to the input directory containing covariance matrix components. The input matrix type (C2, C3, or C4) is automatically detected based on the available components.

    Supported input components:

    C2:

    C11, C12_real, C12_imag, C22

    C3:

    C11, C12_real, C12_imag, C13_real, C13_imag, C22, C23_real, C23_imag, C33

    C4:

    C11, C12_real, C12_imag, C13_real, C13_imag, C14_real, C14_imag, C22, C23_real, C23_imag, C24_real, C24_imag, C33, C34_real, C34_imag, C44

    All input components must have the same file format (.bin or .tif), dimensions, and georeferencing.

  • mat (str, default='T3') –

    Desired output matrix.

    Supported conversions:

    C2 input:
    • ’C2’

    • ’T2’

    C3 input:
    • ’T3’

    • ’C2’

    • ’C2HX’

    • ’C2VX’

    • ’C2HV’

    • ’C2CP’

    C4 input:
    • ’T4’

    • ’C3’

    • ’C2’

    • ’C2HX’

    • ’C2VX’

    • ’C2HV’

  • azlks (int, default=1) – Number of looks in the azimuth direction. Must be a positive integer.

  • rglks (int, default=1) – Number of looks in the range direction. Must be a positive integer.

  • win (int, default=1) – Size of the square moving-average spatial filtering window. A value of 1 disables spatial filtering.

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

  • cog (bool, default=False) – If True, generates Cloud Optimized GeoTIFF output. Requires fmt=’tif’.

  • ovr (list[int], default=[2, 4, 8, 16]) – Overview pyramid levels used during COG generation.

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

  • recip (bool, default=True) – If True, applies reciprocal symmetry to the scattering matrix. Retained for compatibility with the processing interface.

  • cf (float, default=1) – Calibration factor (linear) retained for compatibility with the processing interface.

  • out_dir (str or None, default=None) – Path to the output directory. If None, creates an output directory named after the requested matrix inside in_dir.

  • max_workers (int or None, default=None) – Maximum number of parallel worker processes. If None, uses the default worker count provided by process_chunks_parallel.

  • block_size (tuple[int, int], default=(512, 512)) – Processing block size in pixels, specified as (range, azimuth). Block dimensions are automatically adjusted to align with the multilooking factors.

  • phi (float, default=0.0) – Compact-pol orientation angle in radians. Used only for C3-to-C2CP conversion.

  • chi (float, default=0.0) – Compact-pol ellipticity angle in radians. Used only for C3-to-C2CP conversion.

  • progress_callback (callable or None, default=None) – Optional callback function for monitoring processing progress, primarily intended for QGIS plugin integration. Receives a float between 0.0 and 1.0 representing the fraction of completed processing blocks.

Returns:

Writes the converted matrix components to the output directory. Each matrix component is saved as an individual raster file.

Return type:

None

Raises:
  • ValueError – If input parameters are invalid or input raster properties are inconsistent.

  • FileNotFoundError – If the required covariance matrix components are missing or an input raster cannot be opened.

  • NotImplementedError – If the requested input-to-output matrix conversion is not supported.