0

I have a feature collection with point locations of historic wildfires. I would like to map over this feature collection and for each feature, sample windspeed ('vs' band) from GRIDMET for the corresponding location and day. I have written the code (see below), which I believe should do this. However, when I attempt to export to drive, the task fails with the following error in the asset manager: "Error: Error in map(ID=000000000000000023db): SampleImage.AggregationContainer: Invalid numInputs: 0"

When I test the code on just a single feature (using .first() ) the script returns the expected pixel value correctly:

#USE THIS FOR SPOT CHECKING
date = ee.Date(WF_pts.first().get('DISCOVERY_DT'))
date2 = date.advance(1, 'day')

projection_obj = ee.Projection('EPSG:4326')
point = WF_pts.first().get('LONGITUDE_LATITUDE')
windImage = windspeed_ca.filterBounds(point_test).filterDate(date,date2).mean()
scale = 30

point_value_fc = windImage_test.sample(point, scale=scale, projection=projection_obj)
point_value = point_value_fc.first().get("vs")

point_value.getInfo()

Returns: 4.09441614151001

When I run the full script, and call WF_pts_wind.first().getInfo() to see the first row, I see the same expected value in the 'wind_speed' column. So it seems like the values are getting added to the feature class by the .map function properly.

However, when I try export the feature class via task_wind = ee.batch.Export.table.toDrive(collection=WF_pts_wind, description='Wind_fc', fileFormat='CSV') task_wind.start() the task fails with the following error in the asset manager: "Error: Error in map(ID=000000000000000023db): SampleImage.AggregationContainer: Invalid numInputs: 0"

There are ~83,000 features in the feature class.

I wonder if this large size might be causing an error when exporting?

However, the error message makes me think there is something wrong with the way I am sampling the image within the function.

Here is the full code. I have made the feature collection publicly viewable for testing.

#wildfire points/dates
WF_pts = ee.FeatureCollection('users/allanbkapoor/wildfires2')

# retrieve geometry for california
ca = ee.FeatureCollection('TIGER/2018/States').filterMetadata('NAME', 'equals', 'California').geometry()

# clip GRIDMENT image to california geometry
GRIDMET = ee.ImageCollection('IDAHO_EPSCOR/GRIDMET').filterBounds(ca)

# selects dataset to be mapped
windspeed = GRIDMET.select('vs')

# Clip to bounds of geometry
windspeed_ca = windspeed.map(lambda image: image.clip(ca))

# define function that gets pixels value for a single feature based on long/lat and date
def get_single_date_value(feat):
    
    #get data for that feature from date column
    date = ee.Date(feat.get('DISCOVERY_DT'))
    date2 = date.advance(1, 'day')
    
    projection_obj = ee.Projection('EPSG:4326')
    point = feat.get('LONGITUDE_LATITUDE')
    scale = 30
    
    #for single date: filter image collection to just the image for the feature's date
    windImage = windspeed_ca.filterBounds(point).filterDate(date,date2).mean()
    
    point_value_fc = windImage.sample(point, scale, projection=projection_obj)
    point_value = point_value_fc.first().get("vs")

    return feat.set({'wind_speed': point_value})

#map the function over the feature collection
WF_pts_wind = WF_pts.map(get_single_date_value)

1 Answer 1

3

You've clipped the image collection to only include data inside california, but that point is in Arizona. Either don't clip, or filter out points outside of the clip region.

You debug issues like this by filtering the collection down to just the offending ID, and then call the function on collection.first(), so you can print things in the function (you can't print within a mapped function, so call it without mapping):

get_single_date_value(
    WF_pts.filter("system:index == '000000000000000023db'").first())
2
  • Of course! That makes perfect sense. I also didn't know how filter to just the ID causing the error. That will be very helpful going forward so thanks for that info. I'm curious - the clip was originally in there to reduce processing time (assuming it will take less time to calculate the mean for just CA rather than the entire US) - but is this actually true? The Google Earth Engine best practices page recommends against clipping. Jul 15, 2021 at 1:30
  • Earth Engine only computes the values needed to produce the requested output. In this case, the clip isn't doing anything and could be completely removed. Jul 30, 2021 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.