Created
October 29, 2025 19:32
-
-
Save asjohnston-asf/bcabaffdf0bbc61b3382fc7bd1f243ca to your computer and use it in GitHub Desktop.
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
| from osgeo import gdal, osr | |
| from nisar.products.readers import open_product | |
| # get the data bands | |
| gcov = open_product('NISAR_L2_PR_GCOV_045_107_A_031_4005_DHDH_A_20240621T144514_20240621T144551_T00410_N_F_J_001.h5') | |
| hhhh = gcov.getImageDataset(frequency='A', polarization='HHHH') | |
| hvhv = gcov.getImageDataset(frequency='A', polarization='HVHV') | |
| # compute your RGB pixel values here | |
| red = hhhh[:,:] | |
| green = hvhv[:,:] | |
| blue = hhhh[:,:] | |
| # create an RGB raster in memory | |
| grid = gcov.getGeoGridParameters(frequency='A', polarization='HHHH') | |
| driver = gdal.GetDriverByName('MEM') | |
| raster = driver.Create('', grid.width, grid.length, 3, gdal.GDT_Float32) | |
| geotransform = (grid.start_x, grid.spacing_x, 0, grid.start_y, 0, grid.spacing_y) | |
| raster.SetGeoTransform(geotransform) | |
| srs = osr.SpatialReference() | |
| srs.ImportFromEPSG(grid.epsg) | |
| raster.SetProjection(srs.ExportToWkt()) | |
| raster.GetRasterBand(1).WriteArray(red) | |
| raster.GetRasterBand(2).WriteArray(green) | |
| raster.GetRasterBand(3).WriteArray(blue) | |
| # write RGB raster to disk as a cloud optimized geotiff | |
| gdal.GetDriverByName('COG').CreateCopy('out.tiff', raster, options=['NUM_THREADS=ALL_CPUS', 'BIGTIFF=YES', 'RESAMPLING=NEAREST']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment