Here is my code in GEE to attempt this. NDVI values should range from -1 to 1, but because there are some bad pixels in the image, I have a few random values, such as -145 or 25. I am trying to mask out the image (turn those pixels to null) where those bad pixels exist, and keep all other values the same as the original NDVI calculation. I want to make sure the final output is an image which contains all original bands including NDVI.
The section for "badNDVI" is where I get the error: badNDVI.gt is not a function.
var aoi =
/* color: #d63000 */
/* shown: false */
ee.Geometry.Polygon(
[[[-90.28893540845067, 30.185849313602084],
[-90.48119615063817, 29.540364376709284],
[-89.43200181470067, 29.37774455816459],
[-89.21502183423192, 30.15260570786985]]]),
landsat = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR");
//Image reduction
//Image 3: August-November, 2020
var images = ee.ImageCollection(landsat
.filterBounds(point)
.filter(ee.Filter.calendarRange(2020, 2020, 'year')));
var growing = ee.ImageCollection(images
.filter(ee.Filter.calendarRange(8, 11, 'month'))
.sort('CLOUD_COVER_LAND')
.first()
);
var clipGrowing20 = growing.map(function(image){return image.clip(aoi)}) ;
print ('Growing Season 2020:', clipGrowing20);
var addNDVI = function(image) {
var ndvi = image.select('NIR').subtract(image.select('Red'))
.divide(image.select('NIR').add(image.select('Red')))
.rename('NDVI');
return image.addBands(ndvi);
};
var collectionNDVI20 = clipGrowing20.map(addNDVI);
print ('Not Masked NDVI 2020: ', collectionNDVI20);
var badNDVI = collectionNDVI20.select('NDVI');
var threshold1 = badNDVI.updateMask(badNDVI.gt(1))
var threshold2 = threshold1.updateMask(threshold1.lt(-1))
print (threshold2);