-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannual_forest_land_cover.py
More file actions
71 lines (61 loc) · 2.24 KB
/
Copy pathannual_forest_land_cover.py
File metadata and controls
71 lines (61 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# ---
# title: Annual Forest Land Cover
# author: Brendan Casey
# created: 2026-07-10
# notes:
# Get annual land cover data from the High-resolution
# Annual Forest Land Cover Maps for Canada's Forested
# Ecosystems (1984-2019).
#
# Data citation:
# Hermosilla, T., Wulder, M.A., White, J.C., Coops, N.C.,
# 2022. Land cover classification in an era of big and
# open data: Optimizing localized implementation and
# training data selection to improve mapping outcomes.
# Remote Sensing of Environment. No. 112780.
# doi:10.1016/j.rse.2022.112780
# ---
import ee
def lc_fn(start_date, end_date, aoi=None):
"""Get annual forest land cover images for a date range.
Filters the CA_FOREST_LC_VLCE2 collection to the given
date range, optionally clips to an area of interest,
and renames the land cover band.
Args:
start_date (str): Start date string (YYYY-MM-DD).
end_date (str): End date string (YYYY-MM-DD).
aoi (ee.Geometry): Optional area of interest. When
provided, the collection is filtered and each
image is clipped to this geometry.
Returns:
ee.ImageCollection: Land cover images with a single
'forest_lc_class' band, clipped to the AOI when
provided.
"""
# Get the land cover collection for the date range
lc_collection = ee.ImageCollection(
"projects/sat-io/open-datasets/CA_FOREST_LC_VLCE2"
).filterDate(start_date, end_date)
# Apply area of interest (AOI) filter if provided
if aoi is not None:
lc_collection = lc_collection.filterBounds(aoi)
def _process(image):
# Select and rename the band, clip to AOI if provided
img = image.select("b1").rename("forest_lc_class")
if aoi is not None:
img = img.clip(aoi)
return img.set(
{
"start_date": ee.Date(start_date).format(
"YYYY-MM-dd"
),
"end_date": ee.Date(end_date).format(
"YYYY-MM-dd"
),
"year": ee.Date(
image.get("system:time_start")
).get("year"),
}
)
lc_collection = lc_collection.map(_process)
return lc_collection