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');
#!/usr/bin/python import ee from lapig.ee import download from datetime import datetime start = datetime(2014, 12, 01); end = datetime(2014, 12, 31); bbox = { 'x1': -54.2505, 'y1': -19.6136, 'x2': -45.5273, 'y2': -12.3744 }; outputName = 'landsat-8-go'; ee.Initialize(); img = ee.ImageCollection('LANDSAT/LC8_L1T_TOA').filterDate(start, end).mean(); download.eeImage(img, 30, 'EPSG:4326', bbox, outputName);
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 !!!")
image = image.mask(maskedImage) \ .expression(evi2Expression) \ .select([0],['evi2']); return image; monthIntervals = getMonthInterval(starDt, endDt); for m in monthIntervals: img = ee.ImageCollection(collectionId) \ .filterDate(m['dt1'], m['dt2']) \ .filterBounds(bounds); modelImg = img.map(applyCloudScore) \ .median(); imgResult.append({ 'img': modelImg, 'id': 'EVI2-' + str(m['dt1'].month) + str(m['dt1'].year) }); return imgResult bounds = pastagem.reduceToVectors(scale=10000).geometry().bounds(); #"202.07 * b('evi2') - 17.658" result = applyModel('LANDSAT/LC8_L1T_TOA', '10/01/2013', '09/30/2014', bounds, pastagem); bbox = { 'x1': -68.8245687407108, 'y1': -24.307904722689177, 'x2': -41.51588258047489, 'y2': -1.4907825295665782 }; for r in result: print('donwlodeando... ' + r['id']) download.eeImage(r['img'], 30, 'EPSG:4326', bbox, r['id']);