0

I have a dataset of historic wildfires in California with long/lat coordinates and dates. I would like to determine the windspeed at the day/location each fire started. I have written a function that should do this for a feature, and I'm trying to iterate over all the points (a feature collection) using featurecollection.Map

However, I'm getting this error and I don't know why: "EEException: ValueNode is empty". I'm probably not understanding the rules for .Map functions or am mistranslating between Python code and the JavaScript documentation. I'm also not entirely sure if I'm pulling date/location info from the feature collection properly or if the output will be an updated column in my feature collections.

Here is my code:

import ee

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

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

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

# selects windspeed band from GRIDMET
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):
    #convert feat to ee.feature
    feature = ee.Feature(feat)
    
    #get data for that feature from date column
    date = ee.Date(feature.get('DISCOVERY_DT'))
    
    #for single date: filter image collection to just the image for the feature's date
    windImage = windspeed_ca.filterDate(date).mean() #.select('vs')
    
    #get point value at the feature's location
    point = ee.Geometry.Point(feature.get('LONGITUDE'), feature.get('LATITUDE'))
    scale = 30
    point_value = windImage.sample(point, scale).first().get('vs').getInfo()
    
    #alt approach?
    #var data = image.reduceRegion(ee.Reducer.first(), feat.geometry(), 500)
    
    return ee.Feature(feat.setMulti(point_value))

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

2 Answers 2

1

When you are writing a function that is going to be used in FeatureCollection.map (here get_single_date_value), the function is not actually executed in Python for each element in the collection — your Python code is not sent to Earth Engine's servers. Rather, the function is executed once (more or less) with a special placeholder for the argument (feat), and the return value is not the actual answer but an abstract description of what that function should do.

(This is why you have to use all Earth Engine functions rather than any Python operators like if or +.)

But, inside get_single_date_value you've called .getInfo(), and .getInfo() means "please compute this value right now and download it to my computer". This cannot be done to the placeholder value, so it fails.

In this case, simply remove the .getInfo() call as it is unnecessary. (I haven't checked your script for other errors hidden by this one.)

6
  • Thanks, I have modified the code and removed the .getInfo() line. The last few lines of the function to read: point = ee.Geometry.Point(feature.get('LONGITUDE'), feature.get('LATITUDE')) scale = 30 point_value = windImage.sample(point, scale) return feature.set({'wind_speed': point_value}) I'm now getting an error "Parameter 'crs' is required" whenever I try to export the output feature collection. It seems like my function is outputting an entire feature class instead of a float value associated with a single feature. Commented Jul 11, 2021 at 15:16
  • @global_playa Exports always export entire features. You can't export just numbers, but you can choose what properties/columns those features have.
    – Kevin Reid
    Commented Jul 11, 2021 at 15:26
  • So if I want my .Map function to add pixel values from each point into a column in my input Feature Collection, what data type should get_single_date_value() be outputting? Right now I'm outputting a feature collection, if I understand you correctly, you are saying I should be outputting a single feature. But even that would result in a column with features in it rather than pixel values right? I'm fairly new to GEE so all these objects are a bit overwhelming. Commented Jul 11, 2021 at 15:36
  • When I look at the metadata for the WF_pts wind feature collection (after running code), I see all the original columns with their expected data types, and then 'wind_speed': 'FeatureCollection' Commented Jul 11, 2021 at 15:41
  • @global_playa Please post a new question — it helps keeps things organized. Describe there exactly what data format you want in the export and what you have so far. Comments are best used for asking for clarification about a single question or answer.
    – Kevin Reid
    Commented Jul 11, 2021 at 20:28
0

I realize this is an old post, however, I ran into what I think is a related issue for this style of ImageCollection sampling. I would like to post a solution for what I think is a common error new EE users run into. Since this stackexchange thread is currently the first (and most relevant?) resource from my google searching about sampling an ImageCollection inside of a FeatureCollection mapping, I would like to explain here what I was dealing with in case anyone else comes across this thread.

Please let me know if there's a better place to post this.

The Goal
We have a list of point-date pairs and want to (left)join the pixel value of an image collection onto the point-date pairs. Here's the general algorithm:

  1. Create a FeatureCollection where each feature contains a latitude-longitude and a date.
  2. Create a function that takes a feature and samples the ImageCollection at the latitude-longitude-date of the feature. This is done by filtering the image collection to a single image for the desired date, then sampling the image at the latitude-longitude.
  3. map the function over the FeatureCollection, resulting in another FeatureCollection of latitude-longitude-date-pixelvalue features.

The Issue
The mapping errors out with a strange error like "Element.get: Parameter 'object' is required." or that some function applied inside the user-defined function requires a parameter that you clearly already gave it.

A Solution
In the OP's case, the two stated errors resulted from incorrect printing inside a map function and not setting the CRS of a geometry. But I've found that some of these error can also occur when you run a method or function on a null value. The issue I specifically had was that the ImageCollection filtering was returning a null value instead of an Image, and the .get() method cannot be called on null.

It's sometimes hard to tell the difference between an error coming from a null value and an error coming from legitimate missing parameters. So I want to note two helpful hints if you sampling an image collection based on a feature collection map and run into one of the issues I've mentioned above:

  1. In the user-defined function that will be mapped over, try returning the earliest possible feature that could be null. The map() function has a second parameter, dropNulls, which if set to true will allow the map to skip any iteration of the for loop that returns null. You may want to stop here and just use this as a way to filter out the null values, and do the rest of the necessary computations in a second mapping.

  2. If dropNulls=false, map can error out if the feature being returned is null. In this case, it gives you a helpful error message indicating the ID of the feature that resulted in the error. You can use that ID to find the problem feature by filtering the feature collection on 'system:index'. For example, if the ID given in the error is '0004854', then you can filter your feature collection using:
    var problemFeature = featureCollection.filter(ee.Filter.eq('system:index', '0004854'));
    This will allow you to test if it is the lat-lon or the date of the feature that are generating the null return value. Is it a null from the filtering of the image collection for the date? Then you don't have an image for that date and you need to decide if that's okay or how to deal with the missing date. Is it a null from the sampling of the image at the point? Then you are sampling outside the valid data of the image and need to decide if that's just a point you should have filtered out beforehand. Either way, the result may be that you need to do more filtering of the features before you map over the feature collection.

  3. Use reduceRegion instead of sample. sample returns a feature, and will be a nulltype if the point is outside the non-null pixels of the image. reduceRegion will instead return a dictionary with the key being the name of the image band you wanted to sample, and the value being null. If the user-defined function is returning a feature with a property set to the result of reduceRegion, then this property will be null for that feature and you can sort through the resulting features after the map to see which resulted in null. Note: if you set a feature property with a dictionary like {prop1: null}, the property will simply not be set. So when you look in the feature collection, some of the features will have prop1 set, and the problem features will simply not have the prop1 property. You can still filter out these problem features using:
    var FCfiltered= FCout.filter(ee.Filter.neq('prop1', null));
    where FCout is the feature collection resulting from the mapping.

The last hint was based on another stackexchange post that I found when solving this problem. However, I haven't been able to recover that post, so please feel free to comment/edit the link to that post here if you find it.

2
  • Welcome to GIS SE. This is not a discussion site. Please edit your post to keep your answer to-the-point
    – Padmanabha
    Commented Oct 2, 2023 at 6:13
  • I guess I might just delete this post then? I'm not sure where to put the content, but it seems like important information for people getting started in Earth Engine that need to build panel data. This was one of the only places I've found that discusses the process of sampling an Image Collection inside of a Feature Collection mapping...
    – ACWatt
    Commented Oct 7, 2023 at 1:02

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.