Module: sarpyx.utils.nisar_utils
File: sarpyx/utils/nisar_utils.py
NISAR Product Reader and Cutter Utilities. This module provides tools for reading NISAR GSLC (Geocoded Single Look Complex) products and subsetting them based on WKT polygon geometries. Classes: NISARMetadata: Metadata container for NISAR products NISARReader: Reader for NISAR HDF5 products NISARCutter: Polygon-based product subsetting tool Example: >>> from nisar_utils import NISARReader, NISARCutter >>> >>> # Read product >>> reader = NISARReader('nisar_product.h5') >>> info = reader.info() >>> >>> # Cut by WKT polygon >>> cutter = NISARCutter(reader) >>> wkt_polygon = 'POLYGON((x1 y1, x2 y2, x3 y3, x4 y4, x1 y1))' >>> subset = cutter.cut_by_wkt(wkt_polygon, 'HH') >>> cutter.save_subset(subset, 'output.tif')
Exported Symbols (__all__)
No explicit __all__ list. Public symbols inferred from implementation.
Public Functions (0)
No public top-level functions detected.
Public Classes (3)
NISARMetadata class
Metadata container for NISAR GSLC products. Attributes: product_path: Path to the NISAR product file frequency: Frequency band (e.g., 'frequencyA') polarizations: List of available polarizations grid_name: Grid name shape: Data shape as (rows, cols) epsg: EPSG code for coordinate system x_spacing: Pixel spacing in X direction y_spacing: Pixel spacing in Y direction x_min: Minimum X coordinate y_min: Minimum Y coordinate x_max: Maximum X coordinate y_max: Maximum Y coordinate
File location: sarpyx/utils/nisar_utils.py:41
Class Signature
class NISARMetadata
Constructor Parameters
Return Type
NISARMetadata instances.
Exceptions
Construction/runtime exceptions are inferred from implementation and method-level documentation.
Side Effects
See method-level side effects below.
Example Usage
from sarpyx.utils.nisar_utils import NISARMetadata
obj = NISARMetadata(...) # inferred from implementation
Edge Cases
No class-level edge-case section is explicitly documented; rely on method-level checks and raised exceptions.
Public Methods (2)
NISARMetadata.bounds method
Return bounds as (xmin, ymin, xmax, ymax).
File location: sarpyx/utils/nisar_utils.py:73
Signature
bounds(self) -> Tuple[float, float, float, float]
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
- | - | no | - | No explicit public parameters; behavior inferred from implementation. |
Return Type
Tuple[float, float, float, float]
inferred from implementation.
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.nisar_utils import NISARMetadata
# Constructor arguments are inferred from implementation.
obj = NISARMetadata(...) # inferred from implementation
result = obj.bounds()
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
NISARMetadata.transform method
Return affine transform for georeferencing.
File location: sarpyx/utils/nisar_utils.py:78
Signature
transform(self) -> Affine
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
- | - | no | - | No explicit public parameters; behavior inferred from implementation. |
Return Type
Affine
inferred from implementation.
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.nisar_utils import NISARMetadata
# Constructor arguments are inferred from implementation.
obj = NISARMetadata(...) # inferred from implementation
result = obj.transform()
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
NISARReader class
Reader for NISAR GSLC (Geocoded Single Look Complex) products. This class provides methods to read NISAR HDF5 products and extract geocoded SAR data with proper geospatial metadata. Args: product_path: Path to the NISAR HDF5 product file Example: >>> reader = NISARReader('nisar_product.h5') >>> metadata = reader.get_metadata() >>> data = reader.read_data('HH')
File location: sarpyx/utils/nisar_utils.py:85
Class Signature
class NISARReader
Constructor Parameters
Return Type
NISARReader instances.
Exceptions
Construction/runtime exceptions are inferred from implementation and method-level documentation.
Side Effects
See method-level side effects below.
Example Usage
from sarpyx.utils.nisar_utils import NISARReader
obj = NISARReader(...) # inferred from implementation
Edge Cases
No class-level edge-case section is explicitly documented; rely on method-level checks and raised exceptions.
Public Methods (5)
NISARReader.get_available_polarizations method
Get list of available polarizations in the product.
File location: sarpyx/utils/nisar_utils.py:138
Signature
get_available_polarizations(self, frequency: str='frequencyA') -> List[str]
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
frequency | str | no | 'frequencyA' | 'frequencyA') |
Return Type
List[str]
List of polarization strings (e.g., ['HH', 'HV', 'VH', 'VV'])
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.nisar_utils import NISARReader
# Constructor arguments are inferred from implementation.
obj = NISARReader(...) # inferred from implementation
result = obj.get_available_polarizations()
Edge Cases
Includes optional parameters with implementation-defined fallback behavior.
NISARReader.get_metadata method
Extract metadata from NISAR product.
File location: sarpyx/utils/nisar_utils.py:158
Signature
get_metadata(self, frequency: str='frequencyA') -> NISARMetadata
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
frequency | str | no | 'frequencyA' | 'frequencyA') |
Return Type
NISARMetadata
NISARMetadata object containing product metadata
Exceptions
ValueError
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.nisar_utils import NISARReader
# Constructor arguments are inferred from implementation.
obj = NISARReader(...) # inferred from implementation
result = obj.get_metadata()
Edge Cases
May raise: ValueError. Includes optional parameters with implementation-defined fallback behavior.
NISARReader.read_data method
Read SAR data for a specific polarization.
File location: sarpyx/utils/nisar_utils.py:235
Signature
read_data(self, polarization: str, frequency: str='frequencyA', window: Optional[Tuple[Tuple[int, int], Tuple[int, int]]]=None) -> np.ndarray
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
polarization | str | yes | - | Polarization to read (e.g., 'HH', 'HV', 'VH', 'VV') |
frequency | str | no | 'frequencyA' | 'frequencyA') |
window | Optional[Tuple[Tuple[int, int], Tuple[int, int]]] | no | None | Optional window to read as ((row_start, row_stop), (col_start, col_stop)) |
Return Type
np.ndarray
Complex numpy array containing SAR data
Exceptions
ValueError
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.nisar_utils import NISARReader
# Constructor arguments are inferred from implementation.
obj = NISARReader(...) # inferred from implementation
result = obj.read_data(polarization=<polarization>)
Edge Cases
May raise: ValueError. Includes optional parameters with implementation-defined fallback behavior.
NISARReader.get_coordinates method
Get X and Y coordinate arrays.
File location: sarpyx/utils/nisar_utils.py:271
Signature
get_coordinates(self, frequency: str='frequencyA') -> Tuple[np.ndarray, np.ndarray]
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
frequency | str | no | 'frequencyA' | 'frequencyA') |
Return Type
Tuple[np.ndarray, np.ndarray]
Tuple of (x_coordinates, y_coordinates) as 1D arrays
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.nisar_utils import NISARReader
# Constructor arguments are inferred from implementation.
obj = NISARReader(...) # inferred from implementation
result = obj.get_coordinates()
Edge Cases
Includes optional parameters with implementation-defined fallback behavior.
NISARReader.info method
Get comprehensive product information.
File location: sarpyx/utils/nisar_utils.py:291
Signature
info(self) -> Dict
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
- | - | no | - | No explicit public parameters; behavior inferred from implementation. |
Return Type
Dict
Dictionary containing product information
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.nisar_utils import NISARReader
# Constructor arguments are inferred from implementation.
obj = NISARReader(...) # inferred from implementation
result = obj.info()
Edge Cases
No explicit edge-case section found; behavior is inferred from implementation.
NISARCutter class
Cut/subset NISAR products based on WKT polygons. This class provides functionality to subset NISAR GSLC products based on WKT polygon geometries, preserving georeferencing information. Args: reader: NISARReader instance Example: >>> reader = NISARReader('product.h5') >>> cutter = NISARCutter(reader) >>> wkt_polygon = 'POLYGON((lon1 lat1, lon2 lat2, ...))' >>> subset_data = cutter.cut_by_wkt(wkt_polygon, 'HH')
File location: sarpyx/utils/nisar_utils.py:312
Class Signature
class NISARCutter
Constructor Parameters
Return Type
NISARCutter instances.
Exceptions
Construction/runtime exceptions are inferred from implementation and method-level documentation.
Side Effects
See method-level side effects below.
Example Usage
from sarpyx.utils.nisar_utils import NISARCutter
obj = NISARCutter(...) # inferred from implementation
Edge Cases
No class-level edge-case section is explicitly documented; rely on method-level checks and raised exceptions.
Public Methods (2)
NISARCutter.cut_by_wkt method
Cut NISAR product by WKT polygon.
File location: sarpyx/utils/nisar_utils.py:426
Signature
cut_by_wkt(self, wkt_polygon: str, polarization: str, frequency: str='frequencyA', apply_mask: bool=True) -> Dict[str, Union[np.ndarray, NISARMetadata, Affine]]
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
wkt_polygon | str | yes | - | Well-Known Text polygon string defining AOI |
polarization | str | yes | - | Polarization to read (e.g., 'HH', 'HV', 'VH', 'VV') |
frequency | str | no | 'frequencyA' | 'frequencyA') |
apply_mask | bool | no | True | If True, apply polygon mask to data (pixels outside polygon set to NaN) |
Return Type
Dict[str, Union[np.ndarray, NISARMetadata, Affine]]
Dictionary containing: - 'data': Subset SAR data array - 'mask': Boolean mask (True inside polygon) - 'metadata': Updated metadata for subset - 'transform': Affine transform for subset - 'window': Pixel window used for extraction - 'polygon': Original polygon geometry
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- inferred from implementation
Example Usage
from sarpyx.utils.nisar_utils import NISARCutter
# Constructor arguments are inferred from implementation.
obj = NISARCutter(...) # inferred from implementation
result = obj.cut_by_wkt(wkt_polygon=<wkt_polygon>, polarization=<polarization>)
Edge Cases
Includes optional parameters with implementation-defined fallback behavior.
NISARCutter.save_subset method
Save subset result to a georeferenced file.
File location: sarpyx/utils/nisar_utils.py:514
Signature
save_subset(self, subset_result: Dict, output_path: Union[str, Path], driver: str='GTiff', **kwargs) -> None
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
subset_result | Dict | yes | - | Result dictionary from cut_by_wkt() |
output_path | Union[str, Path] | yes | - | Output file path |
driver | str | no | 'GTiff' | 'GTiff') or 'HDF5'/'h5' for HDF5 format |
**kwargs | inferred from implementation | no | - | Additional arguments passed to rasterio.open() or h5py.File.create_dataset() |
Return Type
None
inferred from implementation.
Exceptions
None explicitly documented; inferred from implementation.
Side Effects
- io
Example Usage
from sarpyx.utils.nisar_utils import NISARCutter
# Constructor arguments are inferred from implementation.
obj = NISARCutter(...) # inferred from implementation
result = obj.save_subset(subset_result=<subset_result>, output_path=<output_path>)
Edge Cases
Includes optional parameters with implementation-defined fallback behavior.