In [19]:
#!pip install geopandas
#!pip install ipyleaflet ipywidgets
In [53]:
import geemap
import ee
import geopandas as gpd
import numpy as np
import os
In [45]:
# Authenticate GEE
ee.Authenticate()
Out[45]:
True
In [46]:
# Initialize Earth Engine
ee.Initialize()
In [47]:
# Define the area of interest (AOI)
aoi = ee.Feature(ee.Geometry.BBox(120, 21, 122, 26))
In [48]:
# Define function to clip image and clip and reproject image to EPSG:3824
def clip_image(image):
    return image.clip(aoi.geometry())  # Clip each image to the AOI geometry
def clip_and_reproject(image):
    clipped_image = image.clip(aoi.geometry())  # Clip each image to the AOI geometry
    return clipped_image.reproject(crs='EPSG:3824',scale = 250) # Change CRS to EPSG:3824
In [49]:
# Get image and show information. Check CRS should be EPSG:3824

modis_ndvi = ee.ImageCollection("MODIS/061/MOD13Q1").select("NDVI").filterDate(start_date,end_date)
# Apply the clipping function to each image in the collection
clipped_collection = modis_ndvi.map(clip_and_reproject)
print(clipped_collection.size().getInfo())
print(clipped_collection.first().getInfo())
18
{'type': 'Image', 'bands': [{'id': 'NDVI', 'data_type': {'type': 'PixelType', 'precision': 'int', 'min': -32768, 'max': 32767}, 'crs': 'EPSG:3824', 'crs_transform': [0.002245788210298804, 0, 0, 0, -0.002245788210298804, 0]}], 'version': 1706581318482734, 'id': 'MODIS/061/MOD13Q1/2024_01_01', 'properties': {'system:footprint': {'geodesic': False, 'type': 'Polygon', 'coordinates': [[[120, 21], [122, 21], [122, 26], [120, 26], [120, 21]]]}, 'system:time_start': 1704067200000, 'google:max_source_file_timestamp': 1706547936000, 'system:time_end': 1705449600000, 'system:asset_size': 29182569559, 'system:index': '2024_01_01'}}
In [39]:
# set the folder for output
out_dir = os.path.join(os.path.expanduser('~'),'Downloads')
In [42]:
# defind years to download
years = np.arange(2024,2025,1)
years
Out[42]:
array([2024])
In [43]:
# Download Images for each year.

for year in years:
    year = str(year)
    start_date = year+'-01-01'
    end_date = year+'-12-31'
    modis_ndvi = ee.ImageCollection("MODIS/061/MOD13Q1").select("NDVI").filterDate(start_date,end_date)
    # Apply the clipping function to each image in the collection
    clipped_collection = modis_ndvi.map(clip_and_reproject)
    # download images
    geemap.ee_export_image_collection(clipped_collection,out_dir = out_dir)
Total number of images: 18

Exporting 1/18: C:\Users\willi\Downloads\2024_01_01.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/a0def42ad183696a26d2b48f26d54a5e-84b0776c0cf3180755a2645ab0712b51:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_01_01.tif


Exporting 2/18: C:\Users\willi\Downloads\2024_01_17.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/2dd98346457311cd7de3dda96af3b231-f49007236bd5e470bab30c3af49cdec7:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_01_17.tif


Exporting 3/18: C:\Users\willi\Downloads\2024_02_02.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/a4a7e39ef4a658bd8278bc4ff7de27fe-79b68dfc53059c9668f3ffeb273d85cc:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_02_02.tif


Exporting 4/18: C:\Users\willi\Downloads\2024_02_18.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/e03fc2446be6027529ce4fc1f78d90b1-0d17abc90e0ee43d987bc8082b9f6f92:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_02_18.tif


Exporting 5/18: C:\Users\willi\Downloads\2024_03_05.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/ef5ccbf74ce928972c28cf70a494135c-f6bddb11e6c99cc10977aa857c36855f:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_03_05.tif


Exporting 6/18: C:\Users\willi\Downloads\2024_03_21.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/daba91e02c832e3ab52f57b003adf0d6-035a7b5113f7007344d4fda2cecd55f4:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_03_21.tif


Exporting 7/18: C:\Users\willi\Downloads\2024_04_06.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/b1d9ae631c5b2c6360ab24b015ec9175-ac93f2da5bb3ae74a7debe9fc9bfe49e:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_04_06.tif


Exporting 8/18: C:\Users\willi\Downloads\2024_04_22.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/c1bdd39c396b0039d61486ad370a2c59-cb371da8e38c8bcb012fa843fc7468ea:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_04_22.tif


Exporting 9/18: C:\Users\willi\Downloads\2024_05_08.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/c4bafcd1ed0039ac48e27f943e5b696e-8a0c0f40ac79460306352aa38a1307b0:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_05_08.tif


Exporting 10/18: C:\Users\willi\Downloads\2024_05_24.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/f3622119fc880a45f57cd390e2ac6da9-dae825b5c9e5e369d490ee06a95e0c4e:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_05_24.tif


Exporting 11/18: C:\Users\willi\Downloads\2024_06_09.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/41672fee7d6eec4c81d06a58a9995c56-efa325ffdcdfe347618174fd2ede32d7:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_06_09.tif


Exporting 12/18: C:\Users\willi\Downloads\2024_06_25.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/49d46780b94cc6e6ddeb43520ea973af-c2e85c2b82986979d7e9ec17b3756612:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_06_25.tif


Exporting 13/18: C:\Users\willi\Downloads\2024_07_11.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/b517c0f5a51ba4e2afd4431d7aca03dd-1c0e5cee3c2d9bca78a863535104ea4d:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_07_11.tif


Exporting 14/18: C:\Users\willi\Downloads\2024_07_27.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/1d3894faab8610cbc38a17ddcf4a065e-4a6cfedd5e2b8fdec2f03b6b91edcac8:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_07_27.tif


Exporting 15/18: C:\Users\willi\Downloads\2024_08_12.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/a230a04cb8dc79635fc97628c91fc8af-3ef4bbcba774647b444d7e66da1329fb:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_08_12.tif


Exporting 16/18: C:\Users\willi\Downloads\2024_08_28.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/22ef785c2c324f9b69c00ca3d6c592c1-df99a4c52708ed8e64b29ad504a60d62:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_08_28.tif


Exporting 17/18: C:\Users\willi\Downloads\2024_09_13.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/7bc1f74111c01cf597c036c529ab2a16-ce96bc17c94103befc39e64c23bf8899:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_09_13.tif


Exporting 18/18: C:\Users\willi\Downloads\2024_09_29.tif
Generating URL ...
Downloading data from https://earthengine.googleapis.com/v1/projects/earthengine-legacy/thumbnails/4e9438012f28f3385badf5d59c4a5526-e89fd66688e19806e7f2ae242e094fc0:getPixels
Please wait ...
Data downloaded to C:\Users\willi\Downloads\2024_09_29.tif


In [51]:
# Open a blank map
m = geemap.Map()
In [52]:
# get Image collection and add to map
collection = (
    ee.ImageCollection("MODIS/061/MOD13Q1")
    .filterDate("2015-01-01", "2019-12-31")
    .select("NDVI")
)

# Convert the image collection to an image.
image = collection.toBands()

ndvi_vis = {
    "min": 0.0,
    "max": 9000.0,
    "palette": [
        "FFFFFF",
        "CE7E45",
        "DF923D",
        "F1B555",
        "FCD163",
        "99B718",
        "74A901",
        "66A000",
        "529400",
        "3E8601",
        "207401",
        "056201",
        "004C00",
        "023B01",
        "012E01",
        "011D01",
        "011301",
    ],
}

m.addLayer(image, {}, "MODIS NDVI Time-series")
m.addLayer(image.select(0), ndvi_vis, "MODIS NDVI VIS")

m
Out[52]:
Map(center=[0, 0], controls=(WidgetControl(options=['position', 'transparent_bg'], widget=SearchDataGUI(childr…
In [9]:
 
In [ ]: