0

I try to print the value of precipitation sum of a given pixel (point location)

 # pixel location
loc_point = ee.Geometry.Point([-0.627983, 52.074361])
# get precip
precip = ee.ImageCollection('NASA/GPM_L3/IMERG_MONTHLY_V06')\
.filterDate('2019-06-01', '2020-06-30')\
.filterBounds(loc_point)\
.select('precipitation')

# sum  
precip_sum = precip.reduce(ee.Reducer.sum())

# print sum precip value
precip_sum.get('precipitation_sum').getInfo()
Juba
  • 3
  • 3
  • A backslash at the end of a line is *unreadable evil* in almost any Python code. If you are trying to avoid 79 characters (pep8) do it in a readable way such as: create a function, use multiple variables, break the line on `(` and `)`. That way a language that's made with **blocks** and pseudo-code syntax in mind will be easily readable so you can simply fly over the code with your eyes and know what's going on instead of reversing the code in your head just to read it. Make the code readable, it'll make your life easier in the future. – Peter Badida Jul 19 '20 at 14:42

1 Answers1

0

The reduce operation gets you an image which contains the sum across the image collection; it's a reduction over time, in this case. In order to get the value at a single pixel, you need to use reduceRegion also.

reduceRegion is designed to work on 2D areas, so you do have to specify some things that arent' strictly necessary to define a point:

precip_sum = (precip
  .reduce(ee.Reducer.sum())
  .reduceRegion(
    geometry=loc_point,
    reducer=ee.Reducer.first(),  # take one pixel (there will be only one)
    crs=precip.first().projection()  # doesn't matter but must pick one
  ))

Note: I haven't tested this exact Python; I converted the syntax from this Earth Engine JavaScript which I did test.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108