🔸NISAR#
RSLC (import_nisar_rslc)#
The import_nisar_rslc function extracts Sxy/C2/T2 (for dual-pol), S2/C4/T4/C3/T3/C2/T2 (for full-pol) matrix elements from the given NISAR RSLC .h5 file and saves them into a C2 directory.
- polsartools.import_nisar_rslc(inFile, mat='T3', azlks=22, rglks=10, fmt='tif', cog=False, ovr=[2, 4, 8, 16], comp=False, out_dir=None, recip=False, max_workers=None, progress_callback=None)[source]
Extracts the C2 (for dual-pol), S2/C3/T3 (for full-pol) matrix elements from a NISAR RSLC HDF5 file and saves them into respective binary files.
Example:#
>>> import_nisar_rslc("path_to_file.h5", azlks=30, rglks=15) This will extract the C2 (for dual-pol), S2/C3/T3 (for full-pol) matrix elements from the specified NISAR RSLC file and save them in the respective folders.
Parameters:#
- inFilestr
The path to the NISAR RSLC HDF5 file containing the radar data.
- matstr, optional (default = ‘T3’ or ‘C2)
Type of matrix to extract. Valid options for Full-pol: ‘S2’, ‘C4, ‘C3’, ‘T4’, ‘T3’, ‘C2HX’, ‘C2VX’, ‘C2HV’,’T2HV’, ‘M4’ and Dual-pol: ‘Sxy’,’C2’.
- azlksint, optional (default=3)
The number of azimuth looks for multi-looking.
- rglksint, optional (default=3)
The number of range looks for multi-looking.
- fmt{‘tif’, ‘bin’}, optional (default=’tif’)
Output format: - ‘tif’: GeoTIFF - ‘bin’: Raw binary format
- cogbool, optional (default=False)
If True, outputs will be saved as Cloud Optimized GeoTIFFs with internal tiling and overviews.
- ovrlist of int, optional (default=[2, 4, 8, 16])
Overview levels for COG generation. Ignored if cog=False.
- compbool, optional (default=False)
If True, applies LZW compression to GeoTIFF outputs.
- out_dirstr or None, optional (default=None)
Directory to save output files. If None, a folder named after the matrix type will be created in the same location as the input file.
- recipbool, optional (default=False)
If True, scattering matrix reciprocal symmetry is applied, i.e, S_HV = S_VH.
GSLC (import_nisar_gslc)#
The import_nisar_gslc function extracts Sxy/C2/T2 (for dual-pol), S2/C4/T4/C3/T3/C2/T2 (for full-pol) matrix elements from the given NISAR GSLC .h5 file and saves them into a C2 directory.
- polsartools.import_nisar_gslc(inFile, mat='T3', azlks=2, rglks=2, inc=False, clip=None, clip_crs=None, clip_mode='crop', fmt='tif', cog=False, ovr=[2, 4, 8, 16], comp=False, out_dir=None, recip=False, max_workers=None, progress_callback=None)[source]
Extracts the C2 matrix elements (C11, C22, and C12) from a NISAR GSLC HDF5 file and saves them into respective binary files.
Example:#
>>> import_nisar_gslc("path_to_file.h5", azlks=30, rglks=15) This will extract the C2 matrix elements from the dual-pol NISAR GSLC file and save them in the 'C2' folder. or for full-pol 'T3'
Parameters:#
- inFilestr
The path to the NISAR GSLC HDF5 file containing the radar data.
- matstr, optional (default = ‘C2’ for Dual-pol, ‘T3’ for Full-pol)
Type of matrix to extract. Valid options for Full-pol: ‘S2’, ‘C4, ‘C3’, ‘T4’, ‘T3’, ‘C2HX’, ‘C2VX’, ‘C2HV’,’T2HV’,’M4’ and Dual-pol: ‘Sxy’,’C2’.
- azlksint, optional (default=3)
The number of azimuth looks for multi-looking.
- rglksint, optional (default=3)
The number of range looks for multi-looking.
- incbool, optional (default=False)
If True, extracts the incidence angle data and saves it as a GeoTIFF (.tif).
- clipstr, os.PathLike, tuple, list, or None, optional (default=None)
Defines the Area of Interest (AOI) for clipping output rasters. Accepts a vector file path (Shapefile, GeoPackage, GeoJSON) or a bounding box (xmin, ymin, xmax, ymax). Vector files must have a valid CRS. If None, the entire raster is processed.
- clip_crsint or None, optional (default=None)
EPSG code of the bounding box CRS. Required when clip is a bounding box. For vector inputs, the CRS is read automatically.
- clip_mode{‘crop’, ‘mask’}, optional (default=’crop’)
Clipping method: - ‘crop’: Crops the raster to the AOI bounding extent. - ‘mask’: Masks pixels outside the AOI while preserving the raster dimensions and georeferencing.
- fmt{‘tif’, ‘bin’}, optional (default=’tif’)
Output format: - ‘tif’: GeoTIFF with georeferencing - ‘bin’: Raw binary format
- cogbool, optional (default=False)
If True, outputs will be saved as Cloud Optimized GeoTIFFs with internal tiling and overviews.
- ovrlist of int, optional (default=[2, 4, 8, 16])
Overview levels for COG generation. Ignored if cog=False.
- compbool, optional (default=False)
If True, applies LZW compression to GeoTIFF outputs.
- out_dirstr or None, optional (default=None)
Directory to save output files. If None, a folder named after the matrix type will be created in the same location as the input file.
- recipbool, optional (default=False)
If True, scattering matrix reciprocal symmetry is applied, i.e, S_HV = S_VH.
GCOV (import_nisar_gcov)#
The import_nisar_gcov function extracts intensity elements (dual-pol: HHHH,HVHV or VVVV,VHVH; Full-pol: HHHH,HVHV,VHVH,VVVV; sigma0 or gamma0) from the given NISAR GCOV .h5 file and saves them into a II directory.
- polsartools.import_nisar_gcov(inFile, azlks=1, rglks=1, bsc='sigma0', inc=False, clip=None, clip_crs=None, clip_mode='crop', fmt='tif', cog=False, ovr=[2, 4, 8, 16], comp=False, out_dir=None, max_workers=None, progress_callback=None)[source]
Extracts the backscatter intensity elements from a NISAR GCOV HDF5 file and saves them into respective tif/binar files.
Example:#
>>> import_nisar_gcov("path_to_file.h5") This will extract the intensity elements from NISAR GCOV HDF5 file without multi-looking
>>> import_nisar_gcov("path_to_file.h5", azlks=3, rglks=3) This will extract the intensity elements from NISAR GCOV HDF5 file with 3x3 multi-looking.
Parameters:#
- inFilestr
The path to the NISAR GCOV HDF5 file containing the radar data.
- azlksint, optional (default=1)
The number of azimuth looks for multi-looking.
- rglksint, optional (default=1)
The number of range looks for multi-looking.
- bscstr, optional (default=’sigma0’)
Backscatter type to extract. Valid options are: - ‘sigma0’: Sigma nought backscatter - ‘gamma0’: Gamma nought backscatter
- incbool, optional (default=False)
If True, extracts the incidence angle data and saves it as a GeoTIFF (.tif).
- clipstr, os.PathLike, tuple, list, or None, optional (default=None)
Defines the Area of Interest (AOI) for clipping output rasters. Accepts a vector file path (Shapefile, GeoPackage, GeoJSON) or a bounding box (xmin, ymin, xmax, ymax). Vector files must have a valid CRS. If None, the entire raster is processed.
- clip_crsint or None, optional (default=None)
EPSG code of the bounding box CRS. Required when clip is a bounding box. For vector inputs, the CRS is read automatically.
- clip_mode{‘crop’, ‘mask’}, optional (default=’crop’)
Clipping method: - ‘crop’: Crops the raster to the AOI bounding extent. - ‘mask’: Masks pixels outside the AOI while preserving the raster dimensions and georeferencing.
- fmt{‘tif’, ‘bin’}, optional (default=’tif’)
Output format: - ‘tif’: GeoTIFF with georeferencing - ‘bin’: Raw binary format
- cogbool, optional (default=False)
If True, outputs will be saved as Cloud Optimized GeoTIFFs with internal tiling and overviews.
- ovrlist of int, optional (default=[2, 4, 8, 16])
Overview levels for COG generation. Ignored if cog=False.
- compbool, optional (default=False)
If True, applies LZW compression to GeoTIFF outputs.
- out_dirstr or None, optional (default=None)
Directory to save output files. If None, a folder named after the matrix type will be created in the same location as the input file.
metadata (nisar_product_info)#
The nisar_product_info function extracts and displays metadata information for a given NISAR HDF5 product file.
- polsartools.nisar_product_info(product_file)[source]
Prints a metadata summary of a NISAR HDF5 product.
Automatically identifies the NISAR frequency band (L-band or S-band) and product type (RSLC, GSLC, or GCOV), then extracts and displays relevant acquisition and spatial metadata.
- The metadata summary includes:
Product filename
Frequency band and product type
Available polarization channels
Acquired range bandwidth
Orbit pass direction
Acquisition date, time, and duration
Along-track, ground-range, and slant-range spacing (where available)
X and Y coordinate spacing for geocoded products
Projection / EPSG code for geocoded products
Geographic coverage coordinates (bounding rectangle corners)
Near-range, mid-range, and far-range incidence angles
- Parameters:
product_file (str or pathlib.Path) – Path to the NISAR HDF5 product file. Supported product types are RSLC, GSLC, and GCOV.
- Returns:
Prints the extracted metadata summary to the console. Does not return any values.
- Return type:
None
- Raises:
FileNotFoundError – If the specified HDF5 product file does not exist.
ValueError – If the product contains unsupported or invalid metadata.
KeyError – If required metadata groups or datasets are missing.
Examples
>>> import polsartools as pst
>>> pst.nisar_product_info("path/to/NISAR_RSLC.h5")
>>> pst.nisar_product_info("path/to/NISAR_GSLC.h5")
>>> pst.nisar_product_info("path/to/NISAR_GCOV.h5")
convert NISAR .h5 to .tif (nisar_h5_tif)#
The nisar_h5_tif function extracts and converts NISAR HDF5 product files to GeoTIFF format.
- polsartools.nisar_h5_tif(h5_path, layer_to_extract=None, out_dir=None, fmt='tif', cog=False, ovr=[2, 4, 8, 16], comp=False)[source]
Extract data layers from NISAR HDF5 files and export them as GeoTIFF, Cloud Optimized GeoTIFF (COG), or ENVI binary files.
Supported products#
SME2: Soil Moisture
GUNW: Geocoded Unwrapped Interferogram
GOFF: Geocoded Offset
Examples
>>> # Extract a single layer >>> nisar_h5_tif("file.h5", layer_to_extract="SM")
>>> # Extract multiple layers >>> nisar_h5_tif( ... h5_path="file.h5", ... layer_to_extract=["UWP", "WI", "COH"] ... )
>>> # Extract all supported layers >>> nisar_h5_tif("file.h5", layer_to_extract="ALL")
- param h5_path:
Path to the input NISAR HDF5 file.
- type h5_path:
str
- param layer_to_extract:
Layer or layers to extract. Accepts a single layer key, a list or tuple of layer keys, or “ALL” to extract all supported layers.
- type layer_to_extract:
str, list[str], tuple[str], or None, default=None
- param output_directory:
Parent directory where a subfolder named after the input file is created to store the output files. If None, defaults to the input file’s directory.
- type output_directory:
str or None, default=None
- param fmt:
Output file format: - ‘tif’: GeoTIFF format - ‘bin’: ENVI binary format
- type fmt:
{‘tif’, ‘bin’}, default=’tif’
- param cog:
If True, generates Cloud Optimized GeoTIFFs with internal tiling and overviews.
- type cog:
bool, default=False
- param ovr:
Overview levels for COG generation. Ignored if cog=False.
- type ovr:
list[int], default=[2, 4, 8, 16]
- param comp:
If True, applies LZW compression to GeoTIFF outputs.
- type comp:
bool, default=False
- raises ValueError:
If the input format is unsupported or an invalid layer key is provided.
- raises FileNotFoundError:
If the specified input HDF5 file does not exist.