Skip to content

Instantly share code, notes, and snippets.

@gabrieldance
Forked from dwtkns/l8_pansharp.sh
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrieldance/e747c22881f28a5c09fd to your computer and use it in GitHub Desktop.
Save gabrieldance/e747c22881f28a5c09fd to your computer and use it in GitHub Desktop.
# These are shell functions to quickly create pansharpened RGB images ready for color correction
# from a set of raw Landsat 8 TIF files in a given directory.
# For example:
# l8_pansharp LC81690352014169LGN00
# Creates:
# LC81690352014169LGN00_rgb_pansharp.tif
# l8_rush_pansharp downloads a L8 tile from Google Storage (if they have it), extracts the relevant bands, then creates the pansharpened output.
# Requires:
# GDAL
# Dan's GDAL scripts from https://github.com/gina-alaska/dans-gdal-scripts
# gsutil from https://developers.google.com/storage/docs/gsutil_install (For the rush function)
# On OSX this would go into your ~/.bash_profile file.
# Also useful in conjunction with USGS' Earth Explorer: http://earthexplorer.usgs.gov/
# Also see:
# https://github.com/gina-alaska/dans-gdal-scripts/wiki/Gdal_landsat_pansharp
# http://mtc-m12.sid.inpe.br/col/sid.inpe.br/jeferson/2004/01.13.13.15/doc/simulation.pdf
function l8_pansharp() {
id="$1"
gdal_landsat_pansharp -rgb ${id}_B4.TIF -rgb ${id}_B3.TIF -rgb ${id}_B2.TIF -lum ${id}_B3.TIF 0.5 -lum ${id}_B4.TIF 0.5 -pan ${id}_B8.TIF -ndv 0 -o _TEMPORARY_FILE_.tif
# force proper labeling of bands as RGB
gdal_merge.py -co "PHOTOMETRIC=RGB" _TEMPORARY_FILE_.tif -o ${id}_rgb_pansharp.tif
rm _TEMPORARY_FILE_.tif
}
function l8_rush_pansharp() {
id="$1"
path=${id:3:3}
row=${id:6:3}
yr=${id:9:4}
mkdir -p $id
cd $id
gsutil cp gs://earthengine-public/landsat/L8/$path/$row/$id.tar.bz .
tar -jxvf $id.tar.bz '*_B[4328].TIF'
gdal_landsat_pansharp -rgb ${id}_B4.TIF -rgb ${id}_B3.TIF -rgb ${id}_B2.TIF -lum ${id}_B3.TIF 0.5 -lum ${id}_B4.TIF 0.5 -pan ${id}_B8.TIF -ndv 0 -o ${id}_TEMPORARY_FILE_.tif
# force proper labeling of bands as RGB
gdal_merge.py -co "PHOTOMETRIC=RGB" ${id}_TEMPORARY_FILE_.tif -o ${id}_rgb_pansharp.tif
rm ${id}_TEMPORARY_FILE_.tif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment