-
Notifications
You must be signed in to change notification settings - Fork 265
/
reducing_feature_collection.py
39 lines (32 loc) · 1.41 KB
/
reducing_feature_collection.py
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
import ee
from ee_plugin import Map
def areaDiff(feature):
area = feature.geometry().area().divide(1000 * 1000)
# Compute the differece between computed area and the area property.
diff = area.subtract(ee.Number.parse(feature.get('areasqkm')))
# Return the feature with the squared difference set to the 'diff' property.
return feature.set('diff', diff.pow(2))
# Load watersheds from a data table and filter to the continental US.
sheds = ee.FeatureCollection('USGS/WBD/2017/HUC06') \
.filterBounds(ee.Geometry.Rectangle(-127.18, 19.39, -62.75, 51.29))
# This function computes the squared difference between an area property
# and area computed directly from the feature's geometry.
# areaDiff = function(feature) {
# # Compute area in sq. km directly from the geometry.
# area = feature.geometry().area().divide(1000 * 1000)
# # Compute the differece between computed area and the area property.
# diff = area.subtract(ee.Number.parse(feature.get('areasqkm')))
# # Return the feature with the squared difference set to the 'diff' property.
# return feature.set('diff', diff.pow(2))
# }
# Calculate RMSE for population of difference pairs.
rmse = ee.Number(
# Map the difference function over the collection.
sheds.map(areaDiff)
# Reduce to get the mean squared difference. \
.reduceColumns(ee.Reducer.mean(), ['diff']) \
.get('mean')
) \
.sqrt()
# Print the result.
print('RMSE=', rmse.getInfo())