-
-
Save jcaceres85/630138065940358d40fefc2b94082238 to your computer and use it in GitHub Desktop.
gee_ndvi
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 ee, geemap | |
Map = geemap.Map() | |
out_dir = 'C:/info_sig/IVCC_Backup/IVCC_SIG/Datos/Rasters/USLE' | |
filename = os.path.join(out_dir, 'NDVI_NoClouds.tif') | |
fc = ee.FeatureCollection("users/josecaceres/Limite_Depto_HN") | |
hn = fc.geometry() | |
def maskL8sr(image): | |
""" | |
Función para enmascarar nubes según la banda pixel_qa de los datos de Landsat 8 SR. | |
Parameters | |
---------- | |
image : ee.Image | |
entrada de imagen Imagen Landsat 8 SR. | |
Returns | |
------- | |
image : ee.Image | |
imagen de Landsat 8 enmascarada | |
""" | |
#Bits 3 and 5 are cloud shadow and cloud, respectively | |
cloudShadowBitMask = (1 << 3) | |
cloudsBitMask = (1 << 5) | |
#Get the pixel QA band. Both flags should be set to zero, indicating clear conditions | |
qaMask = image.select('pixel_qa').bitwiseAnd(cloudShadowBitMask).eq(0) and image.select('pixel_qa').bitwiseAnd(cloudShadowBitMask).eq(0) | |
return image.updateMask(qaMask) | |
dataset = (ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') | |
.filterDate('2021-01-01', '2021-12-31') | |
.filterBounds(hn) | |
.map(maskL8sr) | |
) | |
median = dataset.median() | |
ndvi = median.normalizedDifference(['B5', 'B4']).rename('NDVI') | |
image = ndvi.clip(hn) | |
geemap.download_ee_image(image, filename=filename, region=hn, scale=30, crs='EPSG:4326') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment