Created
March 20, 2026 00:03
-
-
Save asjohnston-asf/7b68e436059f1e8717639658deddbfd2 to your computer and use it in GitHub Desktop.
Convert backscatter data to geotiffs for each NISAR GCOV product in a given directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| from concurrent.futures import ProcessPoolExecutor | |
| from pathlib import Path | |
| from osgeo import gdal | |
| gdal.UseExceptions() | |
| os.environ['GDAL_NUM_THREADS'] = 'ALL_CPUS' | |
| os.environ['GDAL_DISABLE_READDIR_ON_OPEN'] = 'TRUE' | |
| pols = { | |
| 'DH': ['HHHH', 'HVHV'], | |
| 'SH': ['HHHH'], | |
| 'DV': ['VVVV', 'VHVH'], | |
| 'SV': ['VVVV'], | |
| 'QP': ['HHHH', 'HVHV', 'VVVV', 'VHVH'], | |
| 'NA': [], | |
| } | |
| def process_product(product: Path): | |
| print(product) | |
| for frequency in ['A', 'B']: | |
| if frequency == 'A': | |
| index = product.stem[36:38] | |
| else: | |
| index = product.stem[38:40] | |
| for pol in pols[index]: | |
| source = f'NETCDF:"{product}"://science/LSAR/GCOV/grids/frequency{frequency}/{pol}' | |
| dest = f'{product.parent}/{product.stem}_{frequency}_{pol}.tiff' | |
| gdal.Translate( | |
| destName=dest, | |
| srcDS=source, | |
| format='COG', | |
| stats=True, | |
| creationOptions=['OVERVIEW_RESAMPLING=AVERAGE'], | |
| ) | |
| working_dir = Path('.') | |
| products = working_dir.glob('*.h5') | |
| with ProcessPoolExecutor(max_workers=4) as executor: | |
| executor.map(process_product, products) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment