1

I am using the Google Earth Engine API in Python. I am trying to reconvert undefined (i.e. null) values onto a value of choice. Inspired by a discussion here, my code is as follows:

import ee

ee.Initialize()
c = ee.ImageCollection('MODIS/006/MOD13Q1').filterDate('2003-12-19', '2004-01-19').select('NDVI')
p = ee.Geometry.Point([-8.802372,  41.722677])
data = c.getRegion(p, scale = 1000).getInfo()
print 'data=',data

def filterNull(img):
    ndviU = img.select('NDVI')
    ndviF = ee.Algorithms.If(ee.Algorithms.IsEqual(ndviU, None), -2000, ndviU)
    return img.addBands(ndviF) 

cf = c.map(filterNull)
dataf = cf.getRegion(p, scale = 1000).getInfo()
print 'dataf=',dataf

It doesn't work though, the output indicates no change for the None value.

data= [[u'id', u'longitude', u'latitude', u'time', u'NDVI'], 
       [u'2003_12_19', -8.798998207950714, 41.72225337093118, 1071792000000L, None], 
       [u'2004_01_01', -8.798998207950714, 41.72225337093118, 1072915200000L, 7339], 
       [u'2004_01_17', -8.798998207950714, 41.72225337093118, 1074297600000L, 7090]]
dataf= [[u'id', u'longitude', u'latitude', u'time', u'NDVI', u'NDVI_1'], 
        [u'2003_12_19', -8.798998207950714, 41.72225337093118, 1071792000000L, None, None], 
        [u'2004_01_01', -8.798998207950714, 41.72225337093118, 1072915200000L, 7339, 7339], 
        [u'2004_01_17', -8.798998207950714, 41.72225337093118, 1074297600000L, 7090, 7090]]
3

Yes, ee.Image.unmask() is used to convert an image's masked values to actual values. To apply to all images in a collection, use ee.ImageCollection.map() to map a function that operates on a single image.

| improve this answer | |
1

Meanwhile, I was able to solve the problem by using unmask as follows:

def filterNull(img):
    return img.addBands(img.select('NDVI').unmask(-2000))
cf = c.map(filterNull)

Is this the most appropriate mechanism?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.