I am trying to extract values from an ImageCollection for a set of coordinates in Google Earth Engine using the Python API.
First, I set up my EE environment:
import ee
import pprint
ee.Authenticate()
ee.Initialize()
Then I load the image collection and points. Pts is intended to be read into a table with latitude, longitude, and siteID as columns.
img = ee.ImageCollection('UMT/NTSG/v2/MODIS/NPP')
pts = ee.FeatureCollection('users/name/sites_unique.csv');
The image collection contains many images, each representing a year. I would like to iterate through each year and extract the associated NPP (band: ‘annual_npp’) for each point in pts. I anticipate this looking like (pseudocode):
For year in [2010, 2011, 2012, 2013]:
img_selection = img.select(year = yr)
output = img_selection.sample(pts, 1000).get('annual_npp').getInfo()
Does anyone know a generalizable way to extract this information from an ImageCollection?
Edit I get something close to the intended outcome in Earth Engine using the following:
var dataset = ee.ImageCollection('UMT/NTSG/v2/MODIS/NPP')
.filter(ee.Filter.date('2010-01-01', '2013-01-01'));
var npp = dataset.select('annualNPP').mean();
var out = npp.select(['annualNPP']).sampleRegions({
collection: pts,
properties: ['SiteID'],
geometries: true,
scale: 1000
})