Geographic Information Systems Asked on December 28, 2020
The below code has written for ASTER radiometric correction in Google Earth Engine but in visualization step, returns this error:
code link:https://code.earthengine.google.com/3ccaaaa0e9ce68bdf80b8056be5d057d
Map.centerObject(table);
Map.addLayer(table)
var ast = ee.ImageCollection("ASTER/AST_L1T_003")
.filterDate('2000-01-01','2020-01-01')
.filterBounds(table)
.filter(ee.Filter.calendarRange(7,9,'month'))
.select('B0[4-9]')
.map(function(img){
var gain4 = ee.Image(ee.Number(img.select('B04').get('GAIN_COEFFICIENT_B04')));
var gain5 = ee.Image(ee.Number(img.select('B05').get('GAIN_COEFFICIENT_B05')));
var gain6 = ee.Image(ee.Number(img.select('B06').get('GAIN_COEFFICIENT_B06')));
var gain7 = ee.Image(ee.Number(img.select('B07').get('GAIN_COEFFICIENT_B07')));
var gain8 = ee.Image(ee.Number(img.select('B08').get('GAIN_COEFFICIENT_B08')));
var gain9 = ee.Image(ee.Number(img.select('B08').get('GAIN_COEFFICIENT_B09')));
var b4 = img.select('B04').multiply(gain4).clip(table);
var b5 = img.select('B05').multiply(gain5).clip(table);
var b6 = img.select('B06').multiply(gain6).clip(table);
var b7 = img.select('B07').multiply(gain7).clip(table);
var b8 = img.select('B08').multiply(gain8).clip(table);
var b9 = img.select('B09').multiply(gain9).clip(table);
var stack = ee.Image.cat([b4,b5,b6,b7,b8,b9]);
return stack
}).median();
print(ast);
Map.addLayer(ast)
Not every image in the images you've selected has the properties GAIN_COEFFICIENT_B04
and so on. For example, ASTER/AST_L1T_003/20100709070749
has only
GAIN_COEFFICIENT_B01: 0.676
GAIN_COEFFICIENT_B02: 0.708
GAIN_COEFFICIENT_B10: 0.006822
GAIN_COEFFICIENT_B11: 0.00678
GAIN_COEFFICIENT_B12: 0.00659
GAIN_COEFFICIENT_B13: 0.005693
GAIN_COEFFICIENT_B14: 0.005225
GAIN_COEFFICIENT_B3N: 0.862
Thus, .get('GAIN_COEFFICIENT_B04')
returns null, and your image calculation fails because null is not a valid value for a constant image.
You can add a filter on the image collection to ensure those properties are present:
.filter(ee.Filter.notNull([
'GAIN_COEFFICIENT_B04',
'GAIN_COEFFICIENT_B05',
'GAIN_COEFFICIENT_B06',
'GAIN_COEFFICIENT_B07',
'GAIN_COEFFICIENT_B08',
'GAIN_COEFFICIENT_B09',
]))
I noticed some other improvements that could be made to your code.
var gain4 = ee.Image(ee.Number(img.select('B04').get('GAIN_COEFFICIENT_B04')));
Here, the .select('B04')
does nothing (since you're getting a property, and properties are independent of bands). Also, there are variants of .get()
that eliminate needing to write ee.Number
:
var gain4 = ee.Image(img.getNumber('GAIN_COEFFICIENT_B04'));
But this can be even simpler: it isn't necessary to write ee.Image(constant)
in many cases; you can write a number and it will be converted to an image.
var b4 = img.select('B04').multiply(img.getNumber('GAIN_COEFFICIENT_B04')).clip(table);
Finally, it is unnecessarily inefficient to .clip(table)
the individual images rather than the result, and when you are clipping to a table/collection you should use the more efficient .clipToCollection(table)
(though this doesn't matter since you only have one feature).
.map(function(img){
...
}).median().clipToCollection(table);
Putting it all together:
var ast = ee.ImageCollection("ASTER/AST_L1T_003")
.filterDate('2000-01-01','2020-01-01')
.filterBounds(table)
.filter(ee.Filter.calendarRange(7,9,'month'))
.select('B0[4-9]')
.filter(ee.Filter.notNull([
'GAIN_COEFFICIENT_B04',
'GAIN_COEFFICIENT_B05',
'GAIN_COEFFICIENT_B06',
'GAIN_COEFFICIENT_B07',
'GAIN_COEFFICIENT_B08',
'GAIN_COEFFICIENT_B09',
]))
.map(function(img){
return ee.Image.cat([
img.select('B04').multiply(img.getNumber('GAIN_COEFFICIENT_B04')),
img.select('B05').multiply(img.getNumber('GAIN_COEFFICIENT_B05')),
img.select('B06').multiply(img.getNumber('GAIN_COEFFICIENT_B06')),
img.select('B07').multiply(img.getNumber('GAIN_COEFFICIENT_B07')),
img.select('B08').multiply(img.getNumber('GAIN_COEFFICIENT_B08')),
img.select('B09').multiply(img.getNumber('GAIN_COEFFICIENT_B09')),
]);
})
.median()
.clipToCollection(table);
https://code.earthengine.google.com/3ba97a7c2009def6043c614c5aeae4f7
Correct answer by Kevin Reid on December 28, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP