1

I tried to perform a pixel based time series change detection algorithm in GEE for a defined region, so i intended to extract every pixel time series values into something like a table or matrix, and implement the pixel based algorithm by rows or columns.

I find out a similar question and rewrite the code by following the solution given by Nicholas Clinton as follows:

#define the interested path and row to select the images
path = 120
row = 32

#define the time period to filter the images you want
start = ee.Date.fromYMD(1983, 1, 1)
finish = ee.Date.fromYMD(2019, 1, 1)

#rename the OLI images
l8_bandlist = ee.List(['B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B10', 'pixel_qa'])
rename_list = ee.List(['blue', 'green', 'red', 'nir', 'swir1', 'swir2', 'tbb', 'qa'])

#build the image collection
l8_sr = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR').filter(\
ee.Filter.eq('WRS_PATH', path)).filter(ee.Filter.eq('WRS_ROW', row)).filterDate(\
start, finish).select(l8_bandlist, rename_list).sort('system:time_start')

# using shapefile to restrict the area of interest
shp = ee.FeatureCollection('users/myzhenghrsc/testarea').geometry()

#reduce the region restricted by uploaded shapfile into points correspond to OLI pixels
dictionary = ee.Image.pixelLonLat().reduceRegion(
reducer=ee.Reducer.toCollection(['longitude', 'latitude']),
geometry=shp,
scale=30)

#function to build the piont featureCollection
def __rebuildpoints(feature):
lon = feature.get('longitude'),
lat = feature.get('latitude'),
return ee.Feature(ee.Geometry.Point([lon, lat])), {
    'featureID':
    ee.Number(lon).multiply(1000).round().format('%5.0f').cat('_').cat(
        ee.Number(lat).multiply(1000).round().format('%5.0f'))
}

#perform the function above
points = ee.FeatureCollection(dictionary.get('features')).map(__rebuildpoints)

def triplets(image):
  def feature(value):
    return value.set({
        'imageID': pointvalue.id(),
        'timeMillis': pointvalue.get('system:time_start')
    })

  pointvalue = image.reduceRegion({
    'collection': points,
    'reducer': ee.Reducer.first().setOutputs(image.bandNames()),
    'scale': 30
})
return pointvalue

turplets = l8_sr.select('red').map(triplets)

def newformat(table, rowId, colId, rowProperty, colProperty):
rows = table.distinct(rowId),
joined = ee.Join.saveAll('matches').apply({
    primary=rows,
    secondary=table,
    condition=ee.Filter.equals({
        leftField=rowId,
        rightField=colId
    })
})

def __row(row):
    def __feature(feature):
        feature = ee.Feature(feature),
        return [feature.get(colId), feature.get(colProperty)].flatten()

    values = ee.List(row.get('matches')).map(__feature)
    return row.select([rowId, rowProperty]).set(ee.Dictionary(values))

return joined.map(__row)


results = newformat(triplets, 'imageID', 'featureID', 'timemillis', 'RED')

But i got a error as follows when i perform this code:

Invalid argument specified for ee.Number(): ee.ComputedObject({ "type": "Invocation", "arguments": { "object": { "type": "ArgumentRef", "value": null }, "property": "longitude" }, "functionName": "Element.get" })

Your Answer

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

Browse other questions tagged or ask your own question.