Geemap: Find the greenest day of the year by location

GeoSense ✅
2 min readApr 11

How to find the greenest day of the year by location?

In this article, you’ll learn how to determine the greenest day of the year for every pixel location. The approach can be extended to identify the time when a pixel’s timeseries reaches its peak value, such as the hottest temperature or the highest rainfall in a year for each location over the past decades.

Import libraries

import ee
import geemap

Create an interactive map

Map = geemap.Map(center=(-41.270634, 173.283966), zoom=5)

Load a region of interest (ROI), here is New Zealand. The roi is in a shapefile. Example here.

import geopandas as gpd
shapefile = gpd.read_file("nzshp/nzl.shp")

features = []
for i in range(shapefile.shape[0]):
geom = shapefile.iloc[i:i+1,:]
jsonDict = eval(geom.to_json())
geojsonDict = jsonDict['features'][0]

roi = ee.FeatureCollection(features)
Map.addLayer(roi, {}, 'roi')

Filter ImageCollection

start_date = '2022-01-01'
end_date = '2022-12-31'

l8 = (
ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA') #LANDSAT/LC08/C01/T1_8DAY_TOA /LANDSAT/LC08/C01/T1_TOA
.filterDate(start_date, end_date)

Number of images:


Create a median composite

median = l8.median()

visParams = {
'bands': ['B4', 'B3', 'B2'],
'min': 0,
'max': 0.4,

Map.addLayer(median, visParams, 'Median')

Define functions to add time bands

def addNDVI(image):
ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI')
return image.addBands(ndvi)

def addDate(image):
img_date = ee.Date(
img_date = ee.Number.parse(img_date.format('YYYYMMdd'))
return image.addBands(ee.Image(img_date).rename('date').toInt())

def addMonth(image):
img_date = ee.Date(
img_doy = ee.Number.parse(img_date.format('M'))
return image.addBands(ee.Image(img_doy).rename('month').toInt())

def addDOY(image):
img_date = ee.Date(
GeoSense ✅

🌏 Remote sensing | 🛰️ Geographic Information Systems (GIS) | ℹ️