Google Earth Engine – Get Probability Time-Series from Dynamic World Dataset

google-earth-enginegoogle-earth-engine-javascript-apigoogle-earth-engine-python-apiland-cover

I am trying to use the Dynamic World service in earth engine.

For each 10sq meters every 10 min, it contains probabilities associated with 8 possibilities of land cover, like forest, grass, water… I have seen many code examples on how to use it to generate maps, but I wanted to be able to extract the probability values, preferably in python. I have seen many tutorials teaching how to plot graphs using this data, but I can't manage to get the probabilities themselves, like this one.

This code for example:

import ee
# Trigger the authentication flow.
ee.Authenticate()
# Initialize the library.
ee.Initialize()

geometry = ee.Geometry.Point([-89.4235, 43.0469])
startDate = '2020-01-01';
endDate = '2021-01-01';

dw = (ee.ImageCollection('GOOGLE/DYNAMICWORLD/V1')
             .filterDate(startDate, endDate)
             .filterBounds(geometry))
        
probabilityBands = [
  'water', 'trees', 'grass', 'flooded_vegetation', 'crops', 'shrub_and_scrub',
  'built', 'bare', 'snow_and_ice'
]

dwTimeSeries = dw.select(probabilityBands)
dwTimeSeries.getInfo()

Returns a bunch of metadata info, but no probabilities.

Best Answer

The best approach for you will depend on the details of what you're trying to do, and you didn't specify much details on that. In any case, here's one options when you want the values from a single pixel. It's in JavaScript, but it should be easy enough for you to translate to Python.

var dwTimeSeries = dw
  .map(function (image) {
    var probabilityDict = image
      .select(probabilityBands)
      .reduceRegion({
        reducer: ee.Reducer.mean(), 
        geometry: geometry, 
        scale: 10
      })
    return ee.Feature(null, probabilityDict)
      .set('date', image.date().format('yyyy-MM-dd'))
  })
  .filter(ee.Filter.notNull(probabilityBands)) // Filter out masked pixels

https://code.earthengine.google.com/a290edec822ae52f45f2d8105ab76a95

Related Question