def download(self): ee.Initialize(); gridDownload = self.getGridDownload(); tilesCount = gridDownload.GetFeatureCount(); for i in xrange(tilesCount): feature = gridDownload.GetNextFeature(); x1, x2, y1, y2 = feature.geometry().GetEnvelope(); tile = feature.GetFieldAsString(self.tileAttribute); print( "{0} Tile {1}".format(time.strftime("%d/%m/%Y"), tile) ); path = int(tile[:3]) row = int(tile[3:]) bbox = { 'x1': x1, 'y1': y1, 'x2': x2, 'y2': y2 }; mvcFile = self.getMvcFile(tile); if not os.path.exists(mvcFile): print(" calculate MVC"); gapfill = self.gapfill; if self.gapfill == 'L1': gapfill = -1; mvcs = newmvc.getImages(path, row, bbox, self.cloudThreshold , gapfill); #NDVI_PALETTE = 'ec1413, e8dfa0, 0aa73c'; #ee.mapclient.addToMap(mvcs['months'][2], { 'palette': NDVI_PALETTE }, 'cs2'); #ee.mapclient.centerMap(-49.25,-16.66,5) tileFiles = []; monthIndex = 1; for mvcMonth in mvcs['months']: tileFile = self.temppath(tile + '-' + str(monthIndex) ); print(" download MVC {0}".format(tileFile)); download.eeImage(mvcMonth, 30, 'EPSG:4326', bbox, tileFile); tileFiles.append(tileFile + '.NDVI.tif'); monthIndex += 1; for devIndexes in [ 'cs1', 'cs2', 'stdDev' ]: tileFile = self.temppath(tile + '-' + devIndexes); print(" download MVC {0}".format(tileFile)); download.eeImage(mvcs[devIndexes], 30, 'EPSG:4326', bbox, tileFile); tileFiles.append(tileFile + '.NDVI.tif'); vrtFile = self.temppath(tile + '.vrt'); tileFilesStr = ' '.join(tileFiles); gdalbuildvrt = 'gdalbuildvrt -separate {0} {1}'.format(vrtFile, tileFilesStr); gdalTranslate = "gdal_translate -co TILED=YES -co BIGTIFF=YES -co COMPRESS=DEFLATE {0} {1}".format(vrtFile, mvcFile); print(" merge bands"); os.system(gdalbuildvrt); os.system(gdalTranslate); print(" remove temp files"); tileFiles.append(vrtFile); for f in tileFiles: os.remove(f); else: print(" MVC exists... Next !!!")
import ee import ee.mapclient import shapefile from lapig.ee import newmvc from lapig.ee import download ee.Initialize(); NDVI_PALETTE = 'ec1413, e8dfa0, 0aa73c'; #sf = shapefile.Reader("/data/lapig/GEO/SHP/cenas_landsat_MT_WGS84.shp"); sf = shapefile.Reader("/data/lapig/GEO/SHP/MT/pa_br_landsat_norte_mt.shp"); shapeRecs = sf.shapeRecords(); shpBbox = sf.bbox; bbox = { 'x1': shpBbox[0], 'y1': shpBbox[1], 'x2': shpBbox[2], 'y2': shpBbox[3] }; mvcs = newmvc.getImages(bbox); basename = 'NORTE-MT-1'; i=1; for mvcMonth in mvcs['months']: download.eeImage(mvcMonth, 30, 'EPSG:4326', bbox, basename + str(i)); i += 1 download.eeImage(mvcs['cs1'], 30, 'EPSG:4326', bbox, basename + 'cs1'); download.eeImage(mvcs['cs2'], 30, 'EPSG:4326', bbox, basename + 'cs2'); download.eeImage(mvcs['min'], 30, 'EPSG:4326', bbox, basename + 'min'); download.eeImage(mvcs['max'], 30, 'EPSG:4326', bbox, basename + 'max'); download.eeImage(mvcs['mean'], 30, 'EPSG:4326', bbox, basename + 'mean'); download.eeImage(mvcs['stdDev'], 30, 'EPSG:4326', bbox, basename + 'stdDev');
for rec in sf.shapeRecords(): path = rec.record[0] row = rec.record[1] for pathRow in pathRows: if path == pathRow[0] and row == pathRow[1]: shpBbox = rec.shape.bbox; bbox = { 'x1': shpBbox[0], 'y1': shpBbox[1], 'x2': shpBbox[2], 'y2': shpBbox[3] }; for gapFillValue in gapFillValues: basename = str(path) + '_' + str(row) + '_gapfill_' + str(gapFillValue) + '_'; print('GENERATE ' + basename); mvcs = newmvc.getImages(path, row, bbox, cloudThreshold, gapFillValue); #ee.mapclient.addToMap(mvcs['cs1'], { 'palette': NDVI_PALETTE }, 'dez/jan'); #ee.mapclient.centerMap(-49.25,-16.66,5) #print(mvcs['months']); #download.eeImage(mvcs['months'][4], 30, 'EPSG:4326', bbox, basename + str(5)); #download.eeImage(mvcs['months'][5], 30, 'EPSG:4326', bbox, basename + str(6)); #print(mvcs['months'][4].getInfo()); i=1; for mvcMonth in mvcs['months']: download.eeImage(mvcMonth, 30, 'EPSG:4326', bbox, basename + str(i)); i += 1