1

I am trying to transform some weather ee.Image to vector format. For context, my final goal is to export data as shapefile, read into GeoPandas and use it as input to a deep learning model, so there may be easier ways to do this since I am pretty noob with gee.

# load the image collection and filter
collection_idx = "JAXA/GPM_L3/GSMaP/v6/operational"
collection = ee.ImageCollection(collection_idx)\
  .filter(ee.Filter.date('2020-01-01', '2020-01-02'))\
  .select("hourlyPrecipRate")

# define amazon region
region = ee.Geometry.Rectangle(
      [
          [-73.99097222, -18.04176667], [-43.95182736,   5.272225]
      ]
  )


# sum hourly values
reduced_quarter_image = collection.reduce(ee.Reducer.sum()).clip(region)

# reduce to vectors using 3 km scale
vector = reduced_quarter_image.gt(0).reduceToVectors({
  "reducer": ee.Reducer.sum(),
  "geometry": region,
  "scale": 3e3,
  "geometryType": 'polygon',
  "crs": reduced_quarter_image.projection()
})

I am receveing the following error:

EEException: Invalid argument for ee.Reducer(): ({'reducer': <ee.Reducer...

What is wrong here?

1 Answer 1

0

The JavaScript and Python APIs in EE are very similar, but here is one place where they differ a bit. Almost everywhere, the JavaScript API allow you to provide a single object as argument, just like you tried to do in reduceToVectors(). That's a quite convenient way to emulate named arguments, which JavaScript doesn't support. In Python, however, there are real named argument, so there is no need for this workaround. That's why the Python API does not allow you to provide a dictionary.

You have two simple options to fix this. You either use real named arguments:

vector = reduced_quarter_image.gt(0).reduceToVectors(
  reducer=ee.Reducer.sum(),
  geometry=region,
  scale=3e3,
  geometryType='polygon',
  crs=reduced_quarter_image.projection()
)

Or you convert the dictionary to arguments by simply prepending it with **:

vector = reduced_quarter_image.gt(0).reduceToVectors(**{
  "reducer": ee.Reducer.sum(),
  "geometry": region,
  "scale": 3e3,
  "geometryType": 'polygon',
  "crs": reduced_quarter_image.projection()
})
1
  • Thank you! That's what happens when you just copy paste code from documentation example hahah Oct 24, 2023 at 12:07

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.