Last active
December 29, 2015 05:39
-
-
Save hallahan/7623253 to your computer and use it in GitHub Desktop.
Creates a binary mask of cloud vs no cloud using BQA values that are classified as cloud.
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
import os | |
import sys | |
import arcpy | |
import numpy | |
import math | |
from arcpy.sa import * | |
arcpy.CheckOutExtension('Spatial') | |
arcpy.env.overwriteOutput = True | |
cwd = os.getcwd() | |
inputPath = cwd + "\\input\\" | |
outputPath = cwd + "\\intermediate\\" | |
inputFiles = os.listdir(inputPath) | |
print("Creating a binary mask for each individual cloud classification value...") | |
for img in inputFiles: | |
if img.split('.')[-1] == 'TIF': | |
imgPath = inputPath + img | |
r61440 = Raster(imgPath) == 61440 | |
r59424 = Raster(imgPath) == 59424 | |
r57344 = Raster(imgPath) == 57344 | |
r56320 = Raster(imgPath) == 56320 | |
r53248 = Raster(imgPath) == 53248 | |
r52256 = Raster(imgPath) == 52256 | |
r52224 = Raster(imgPath) == 52224 | |
r49184 = Raster(imgPath) == 49184 | |
r49152 = Raster(imgPath) == 49152 | |
r48128 = Raster(imgPath) == 48128 | |
r45056 = Raster(imgPath) == 45056 | |
r43040 = Raster(imgPath) == 43040 | |
r39936 = Raster(imgPath) == 39936 | |
r36896 = Raster(imgPath) == 36896 | |
r36864 = Raster(imgPath) == 36864 | |
r32768 = Raster(imgPath) == 32768 | |
r31744 = Raster(imgPath) == 31744 | |
r28672 = Raster(imgPath) == 28672 | |
r16380 = Raster(imgPath) == 16380 | |
r13246 = Raster(imgPath) == 13246 | |
print("Summing the binary rasters for each clouded BQA value for " + img) | |
rSum = r61440 + r59424 + r57344 + r56320 + r53248 + r52256 + r52224 + r49184 + r49152 + r48128 + r45056 + r43040 + r39936 + r36896 + r36864 + r32768 + r31744 + r28672 + r16380 + r13246 | |
# we want all the pixels that are NOT cloud to be flagged as 1 | |
rSum = 1 - rSum | |
outputFileName = img.split('_')[0] + '_BINMASK.TIF' | |
print("Saving final binary mask raster as " + outputFileName) | |
rSum.save(outputPath + outputFileName) | |
print("Success!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment