Skip to content

Instantly share code, notes, and snippets.

@mlubej
Last active January 22, 2021 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlubej/ed8eab964a222dfb42bf72b3235d8915 to your computer and use it in GitHub Desktop.
Save mlubej/ed8eab964a222dfb42bf72b3235d8915 to your computer and use it in GitHub Desktop.
import subprocess
from sentinelhub import CRS
# rescale to a lower resolution
nres = 120*10
target_crs = CRS.WGS84.epsg
def create_rgb_per_timestamp(batch_tile_name):
subprocess.run(f'gdalwarp -tr {nres} {nres} <INPUT HI-RES RED> <OUTPUT LO_RES RED>', shell=True)
# repeat for green and blue ...
for idx, date in enumerate(dates):
subprocess.run(f'gdal_translate -b {idx+1} <INPUT LO_RES RED> <OUTPUT LO_RES RED>_{idx}.tif', shell=True)
# repeat for green and blue ...
# merge separate bands into a multi-channel tiff and reproject to a common crs
subprocess.run(f'gdal_merge.py -separate -o <OUTPUT LO_RES RGB>_{idx}.tif -co PHOTOMETRIC=MINISBLACK <OUTPUT LO_RES RED>_{idx}.tif <OUTPUT LO_RES GREEN>_{idx}.tif <OUTPUT LO_RES BLUE>_{idx}.tif', shell=True)
subprocess.run(f'gdalwarp -t_srs EPSG:{target_crs} <OUTPUT REPROJECTED RGB>_{idx}.tif <OUTPUT LO_RES RGB>_{idx}.tif', shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment