0

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.

1 Answer 1

1

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

5
  • Thank you so much! It worked for me. One question, is it normal for a specific location to have new probabilities only after every few months? Is it only when the data changes? For the following location I have only 2 results in a 5 month period: Commented Dec 6, 2022 at 15:29
  • Lat=-15.117374, lon=39.268612, from 2021-12-01 to 2022-05-01 Commented Dec 6, 2022 at 15:30
  • It seems like a cloudy area and while you have observations every 5 days, everything except two of them are masked out. Commented Dec 6, 2022 at 15:42
  • Dynamic World is very aggressive with the cloud masking. Inspect your coordinate in this script and look at the series of s1. It shows the red band. Notice how you only have higher values for two observations. code.earthengine.google.com/569ebb9d7a234f10b73ff498ee45edff Commented Dec 6, 2022 at 15:44
  • Yeah, when I check the image at sentinel, it is pretty cloudy indeed. Thanks a lot!! I will add below the code in python in case someone needs in the future Commented Dec 8, 2022 at 16:28

Your Answer

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