Commit d2c2e8fb authored by Mario Chirinos Colunga's avatar Mario Chirinos Colunga 💬

class map

parent 2b4add52
......@@ -25,29 +25,25 @@ SENTINEL_PATH = config['PATHS']['PATH_GEOSENTINEL']
sys.path.append(SENTINEL_PATH)
from geosentinel import rasterWkt
CLASS_MAP = {0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:8, 10:8, 11:9}
#-------------------------------------------------------------------------------
def L2ASCLtoDict(filename, wkt):
'''
L2ASCLtoDict
'''
classMap = lambda x: [ CLASS_MAP[xx] for xx in x ]
inputImage = gdal.Open(filename)
rows, cols, geotransform = inputImage.RasterYSize, inputImage.RasterXSize, inputImage.GetGeoTransform()
data = inputImage.GetRasterBand(1).ReadAsArray(0,0,cols,rows)
# count = Counter([])
# for r in data:
# count = count + Counter(r)
# sclDict = {str(k):v for k,v in dict(count).items()}
# print ("data")
# print (sclDict)
data = np.bitwise_and(data, rasterWkt.getPolygonArray(inputImage, wkt))
count = Counter([])
for r in data:
count = count + Counter(r)
count = count + Counter(classMap(r))
sclDict = {str(k):v for k,v in dict(count).items()}
# print ("data & POLY")
# print (sclDict)
return sclDict
#-------------------------------------------------------------------------------
def main(argv):
......
......@@ -20,7 +20,8 @@ SCL_COLOR = [
(102,204,255,255), #THIN_CIRRUS
(255,153,255,255), #SNOW
]
CLASS_MAP = {0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:8, 10:8, 11:9}
CLASS_GROUP = [[0], [1], [2], [3], [4], [5], [6], [7], [8,9,10], [11]]
#-------------------------------------------------------------------------------
def splitSCL(filename, outdir):
inputImage = gdal.Open(filename)
......@@ -33,10 +34,12 @@ def splitSCL(filename, outdir):
sr.ImportFromWkt(projection)
driverTiff = gdal.GetDriverByName('GTiff')
for c in range(len(SCL_COLOR)):
# for c in range(len(SCL_COLOR)):
for c in range(len(CLASS_GROUP)):
outputfile=outdir+filename[:-4]+"_"+str(c)+".tif"
output = driverTiff.Create(outputfile, cols, rows, 4, gdal.GDT_Byte)
classMask = inputImage.GetRasterBand(1).ReadAsArray(0,0,cols,rows)==c
# classMask = inputImage.GetRasterBand(1).ReadAsArray(0,0,cols,rows)==c
classMask = np.isin(inputImage.GetRasterBand(1).ReadAsArray(0,0,cols,rows), CLASS_GROUP[c])
for b in range(1, output.RasterCount+1):
output.GetRasterBand(b).SetNoDataValue(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment