Last active
December 30, 2015 17:59
-
-
Save hallahan/7864872 to your computer and use it in GitHub Desktop.
This script just composites bands 4,3,2 into an RGB composite tiff for all of the outputs of holy cloud imagery.
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
# cloud-hole-all.py | |
# Nicholas Hallahan nick@theoutpost.io | |
# Sun Nov 24 2013 | |
# This script just composites bands 4,3,2 into an RGB composite tiff for all of the outputs | |
# of holy cloud imagery. | |
import os | |
import arcpy | |
from arcpy.sa import * | |
arcpy.CheckOutExtension('Spatial') | |
arcpy.env.overwriteOutput = True | |
cwd = os.getcwd() | |
nyriagongoPath = r"C:\vbox-shared\remote-sensing\code\cloud-hole-all\output\nyiragongo" | |
kawahIjenPath = r"C:\vbox-shared\remote-sensing\code\cloud-hole-all\output\kawah-ijen" | |
######################## create output paths ################################# | |
outputPath = cwd + '\\output' | |
if not os.path.exists(outputPath): os.makedirs(outputPath) | |
outputNyiragongoPath = outputPath + '\\nyiragongo' | |
if not os.path.exists(outputNyiragongoPath): os.makedirs(outputNyiragongoPath) | |
outputKawahIjenPath = outputPath + "\\kawah-ijen" | |
if not os.path.exists(outputKawahIjenPath): os.makedirs(outputKawahIjenPath) | |
# Input either nyriagongoPath or kawahIjenPath | |
def createOutputLCDirectories(inputBasePath, outputBasePath): | |
for f in os.listdir(inputBasePath): | |
path = inputBasePath + "\\" + f | |
if os.path.isdir(path) and f[:2] == 'LC': | |
outputLCPath = outputBasePath + '\\' + f | |
if not os.path.exists(outputLCPath): os.makedirs(outputLCPath) | |
createOutputLCDirectories(nyriagongoPath, outputNyiragongoPath) | |
createOutputLCDirectories(kawahIjenPath, outputKawahIjenPath) | |
############################################################################## | |
def composite(rFile, gFile, bFile, rgbFile): | |
arcpy.CompositeBands_management(rFile+';'+gFile+';'+bFile, rgbFile) | |
print("RGB saved to " + rgbFile) | |
# We give this the main directory for Nyriagongo / Kawah Ijen for both | |
# input and output | |
def processBands(inputPath, outputPath): | |
# Here we are iterating through all of the LC directories and executing | |
# cutHoleInBand | |
lcDirs = os.listdir(outputPath) # we know (hope) the output dirs dont have extra crap | |
for lcDir in lcDirs: | |
inputLCPath = inputPath + '\\' + lcDir | |
outputLCPath = outputPath + '\\' + lcDir | |
bands = os.listdir(inputLCPath) | |
# find the red band | |
for band in bands: | |
if band[-6:] == 'B4.TIF': | |
rPath = inputLCPath + '\\' + band | |
break | |
# find the green band | |
for band in bands: | |
if band[-6:] == 'B3.TIF': | |
gPath = inputLCPath + '\\' + band | |
break | |
# find the blue band | |
for band in bands: | |
if band[-6:] == 'B2.TIF': | |
bPath = inputLCPath + '\\' + band | |
break | |
rgbPath = outputLCPath + '.TIF' | |
composite(rPath, gPath, bPath, rgbPath) | |
# Ready... Set... GO!!!! | |
#processBands(nyriagongoPath, outputNyiragongoPath) | |
processBands(kawahIjenPath, outputKawahIjenPath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment