Utility methods (sarpy.io.complex.utils)

Common functionality for converting metadata

sarpy.io.complex.utils.two_dim_poly_fit(x: ndarray, y: ndarray, z: ndarray, x_order: int = 2, y_order: int = 2, x_scale: float = 1.0, y_scale: float = 1.0, rcond: float | None = None) Tuple[ndarray, ndarray, int, ndarray]

Perform fit of data to two-dimensional polynomial.

Parameters:
  • x (numpy.ndarray) – the x data

  • y (numpy.ndarray) – the y data

  • z (numpy.ndarray) – the z data

  • x_order (int) – the order for x

  • y_order (int) – the order for y

  • x_scale (float) – In order to help the fitting problem to become better conditioned, the independent variables can be scaled, the fit performed, and then the solution rescaled.

  • y_scale (float) –

  • rcond (None|float) – passed through to scipy.linalg.lstsq() (as cond).

Returns:

  • solution (numpy.ndarray) – the coefficient array

  • residuals (numpy.ndarray) – this is often an empty array

  • rank (int) – the rank of the fitting matrix

  • sing_values (numpy.ndarray) – the singular values of the fitting matrix

sarpy.io.complex.utils.get_im_physical_coords(array, grid, image_data, direction)

Converts one dimension of “pixel” image (row or column) coordinates to “physical” image (range or azimuth in meters) coordinates, for use in the various two-variable sicd polynomials.

Parameters:
Return type:

numpy.array|float

sarpy.io.complex.utils.fit_time_coa_polynomial(inca, image_data, grid, dop_rate_scaled_coeffs, poly_order=2)
Parameters:
Return type:

Poly2DType

sarpy.io.complex.utils.fit_position_xvalidation(time_array: ndarray, position_array: ndarray, velocity_array: ndarray, max_degree: int = 5) Tuple[ndarray, ndarray, ndarray]

Empirically fit the polynomials for the X, Y, Z ECF position array, using cross validation with the velocity array to determine the best fit degree up to a given maximum degree.

Parameters:
  • time_array (numpy.ndarray) –

  • position_array (numpy.ndarray) –

  • velocity_array (numpy.ndarray) –

  • max_degree (int) –

Returns:

  • X_poly (numpy.ndarray)

  • Y_poly (numpy.ndarray)

  • Z_poly (numpy.ndarray)

sarpy.io.complex.utils.sicd_reader_iterator(reader, partitions=None, polarization=None, band=None)

Provides an iterator over a collection of partitions (tuple of tuple of integer indices for the reader) for a sicd type reader object.

Parameters:
  • reader (SICDTypeReader) –

  • partitions (None|tuple) – The partitions collection. If None, then partitioning from reader.get_sicd_partitions() will be used.

  • polarization (None|str) – The polarization string to match.

  • band (None|str) – The band to match.

Returns:

Yields the partition index, the sicd reader index, and the sicd structure.

Return type:

Iterator[tuple]

sarpy.io.complex.utils.get_physical_coordinates(the_sicd, row_value: int | float | ndarray, col_value: int | float | ndarray) Tuple[float | ndarray, float | ndarray]

Transform from image coordinates to physical coordinates, for polynomial evaluation.

Parameters:
Returns:

  • row_coords (float|numpy.ndarray)

  • col_coords (float|numpy.ndarray)

sarpy.io.complex.utils.get_fetch_block_size(start_element: int, stop_element: int, block_size_in_bytes: int, bands: int = 1)

Gets the appropriate block size, given fetch parameters and constraints.

Note: this is a helper function, and no checking of argument validity will be performed.

Parameters:
  • start_element (int) –

  • stop_element (int) –

  • block_size_in_bytes (int) –

  • bands (int) –

Return type:

int

sarpy.io.complex.utils.extract_blocks(the_range: Tuple[int, int, int], index_block_size: None | int | float) Tuple[List[Tuple[int, int, int]], List[Tuple[int, int]]]

Convert the single range definition into a series of range definitions in keeping with fetching of the appropriate block sizes.

Note: this is a helper function, and no checking of argument validity will be performed.

Parameters:
  • the_range (Tuple[int, int, int]) – The input (off processing axis) range.

  • index_block_size (None|int|float) – The size of blocks (number of indices).

Returns:

  • range_def (List[Tuple[int, int, int]]) – The sequence of range definitions (start index, stop index, step) relative to the overall image.

  • index_limits (List[Tuple[int, int]]) – The sequence of start/stop indices for positioning of the given range relative to the original range.

sarpy.io.complex.utils.get_data_mean_magnitude(bounds, reader, index, block_size_in_bytes)

Gets the mean magnitude in the region defined by bounds.

Note: this is a helper function, and no checking of argument validity will be performed.

Parameters:
  • bounds (numpy.ndarray|tuple|list) – Of the form (row_start, row_end, col_start, col_end).

  • reader (SICDTypeReader) – The data reader.

  • index (int) – The reader index to use.

  • block_size_in_bytes (int|float) – The block size in bytes.

Return type:

float

sarpy.io.complex.utils.stats_calculation(data, percentile=None)

Calculate the statistics for input into the nrl remap.

Parameters:
  • data (numpy.ndarray) – The amplitude array, assumed real valued an finite.

  • percentile (None|float|int) – Which percentile to calculate

Returns:

Of the form (`minimum, maximum) or (minimum, maximum, `percentile percentile)

Return type:

tuple

sarpy.io.complex.utils.get_data_extrema(bounds, reader, index, block_size_in_bytes, percentile=None)

Gets the minimum and maximum magnitude in the region defined by bounds, optionally, get as estimate for the percentage percentile point.

Note: this is a helper function, and no checking of argument validity will be performed.

Parameters:
  • bounds (numpy.ndarray|tuple|list) – Of the form (row_start, row_end, col_start, col_end).

  • reader (SICDTypeReader) – The data reader.

  • index (int) – The reader index to use.

  • block_size_in_bytes (int|float) – The block size in bytes.

  • percentile (None|int|float) – The optional percentile to estimate.

Returns:

The minimum (finite) observed, maximum (finite) observed, and optionally, the desired (of finite) percentile.

The minimum, maximum, and percentile values will be None exactly when the reader contains no finite data.

Return type:

Tuple