Last active
May 4, 2019 06:45
-
-
Save yanofsky/a4fb39d116eb319dc4a41cb46422bc02 to your computer and use it in GitHub Desktop.
This is workflow for downloading, processing, and mosaicing Landsat scenes, as a Makefile
This file contains 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
# lansatutil directory | |
LANDSAT = ~/landsat | |
# scenes to target | |
LANDSAT_IDS = \ | |
LC81220442016038LGN00 \ | |
LC81220452016038LGN00 \ | |
LC81210442014281LGN00 \ | |
LC81210452014281LGN00 | |
# where to put processed files | |
LOCAL_PROCESSED = ./processed | |
# Define projection for the output | |
PROJECTION = +proj=utm +zone=50 +datum=WGS84 | |
# if you run `make` create a stitched auto contrasted mosaic using bands 4, 3, and 2 for the specified IDs | |
all:: $(LOCAL_PROCESSED)/stiched_autocontrast_432.tiff | |
# create a function to use while iterating over the IDs | |
# the variable $1 is always the current ID | |
define landsat-workflow | |
download_all:: $(LANDSAT)/downloads/$1/$1_MTL.txt | |
$(LANDSAT)/downloads/$1/$1_MTL.txt: | |
# download bands 4, 3, 2, and 8 of the specified ID | |
landsat download $1 --bands 4328 | |
process432:: $(LOCAL_PROCESSED)/$1_rgb.tif | |
$(LOCAL_PROCESSED)/$1_rgb.tif: ~/landsat/downloads/$1/$1_MTL.txt $(LOCAL_PROCESSED) | |
# create a 432 composite of the specified IDs bands | |
# $$@ is the target for the rule i.e. $(LOCAL_PROCESSED)/$1_rgb.tif | |
gdal_merge.py \ | |
-co "PHOTOMETRIC=RGB" \ | |
-separate ~/landsat/downloads/$1/$1_B{4,3,2}.TIF \ | |
-o $$@ | |
warptoutm50:: $(LOCAL_PROCESSED)/$1_rgb_resized_utm50.tif | |
$(LOCAL_PROCESSED)/$1_rgb_resized_utm50.tif: $(LOCAL_PROCESSED)/$1_rgb.tif | |
# remove an existing file of the target name because gdal will fail if it's there | |
rm -f $(LOCAL_PROCESSED)/$1_rgb_resized_utm50.tif | |
# reproject the specifed scene to UTM 50 and resize to to be 1000px wide using cubic sampling | |
# $$< are the required files for the rule $$@ is the target for the rule | |
gdalwarp \ | |
-co "PHOTOMETRIC=RGB" \ | |
-t_srs '$(PROJECTION)' \ | |
-ts 1000 0 \ | |
-r cubic \ | |
$$< \ | |
$$@ | |
# if you run `make` create all the resized reprojected scenes | |
all:: $(LOCAL_PROCESSED)/$1_rgb_resized_utm50.tif | |
endef | |
stich_432: $(LOCAL_PROCESSED)/stiched_432.tiff | |
$(LOCAL_PROCESSED)/stiched_432.tiff: $(addprefix $(LOCAL_PROCESSED)/,$(addsuffix _rgb_resized_utm50.tif, $(LANDSAT_IDS))) | |
# stitch together the resized reprojected scenes into one mosaic | |
# $@ is the target for the rule $^ are the requirements | |
schooner-stitch \ | |
$^ \ | |
$@ | |
autocontrast432: $(LOCAL_PROCESSED)/stiched_contrast_432.tiff | |
$(LOCAL_PROCESSED)/stiched_autocontrast_432.tiff: $(LOCAL_PROCESSED)/stiched_432.tiff | |
# create a new version of the mosaic with enhanced contrast | |
schooner-contrast $(LOCAL_PROCESSED)/stiched_432.tiff $(LOCAL_PROCESSED)/stiched_autocontrast_432.tiff | |
$(LOCAL_PROCESSED): | |
#make sure you have your folder to hold processed images | |
mkdir $@ | |
# iterate over the IDs passing each into the landsat-workflow function to create the rules it contains contained | |
$(foreach 1, $(LANDSAT_IDS),$(eval $(call landsat-workflow,$1))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment