-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_annual_forest_tree_species.py
More file actions
72 lines (62 loc) · 2.28 KB
/
Copy pathget_annual_forest_tree_species.py
File metadata and controls
72 lines (62 loc) · 2.28 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
72
# ---
# title: Get Annual Forest Tree Species
# author: Brendan Casey
# created: 2026-07-10
# notes:
# Get annual species data from the High-resolution Annual
# Forest Species Maps for Canada's Forested Ecosystems.
#
# 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 species_fn(start_date, end_date, aoi=None):
"""Get annual forest species images for a date range.
Filters the CA_FOREST_SPECIES collection to the given
date range, optionally clips to an area of interest,
and renames the species 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: Species images with a single
'forest_species_class' band, clipped to the AOI
when provided.
"""
# Get the species collection for the date range
species_collection = ee.ImageCollection(
"projects/sat-io/open-datasets/CA_FOREST_SPECIES"
).filterDate(start_date, end_date)
# Apply area of interest (AOI) filter if provided
if aoi is not None:
species_collection = species_collection.filterBounds(aoi)
def _process(image):
# Select and rename the band, clip to AOI if provided
img = image.select("species").rename(
"forest_species_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"),
}
)
species_collection = species_collection.map(_process)
return species_collection