Geographic Information Systems Asked on January 3, 2021
I’m using the Earth Engine API in a Jupyter notebook and I try to translate from JavaScript to Python a cloud masking function (the one given with the dataset)
/**
* Function to mask clouds based on the pixel_qa band of Landsat SR data.
* @param {ee.Image} image Input Landsat SR image
* @return {ee.Image} Cloudmasked Landsat image
*/
var cloudMaskL457 = function(image) {
var qa = image.select('pixel_qa');
// If the cloud bit (5) is set and the cloud confidence (7) is high
// or the cloud shadow bit is set (3), then it's a bad pixel.
var cloud = qa.bitwiseAnd(1 << 5)
.and(qa.bitwiseAnd(1 << 7))
.or(qa.bitwiseAnd(1 << 3));
// Remove edge pixels that don't occur in all bands
var mask2 = image.mask().reduce(ee.Reducer.min());
return image.updateMask(cloud.not()).updateMask(mask2);
};
I already fell in the trap of and
, or
and not
that are protected in Python. I’m now facing an error with the bitewiseAnd
keyword:
def clouMask_landsat(image):
"""
Function to mask clouds based on the pixel_qa band of Landsat SR data.
Args:
image(ee.Image): image Input Landsat SR image
Returns:
(ee.Image): Cloudmasked Landsat image
"""
qa = image.select('pixel_qa')
# If the cloud bit (5) is set and the cloud confidence (7) is high
# or the cloud shadow bit is set (3), then it's a bad pixel.
cloud = qa.bitewiseAnd(1 << 5).And(qa.bitewiseAnd(1 << 7)).Or(qa.bitewiseAnd(1 << 3))
# Remove edge pixels that don't occur in all bands
mask2 = image.mask().reduce(ee.Reducer.min())
return image.updateMask(cloud.Not()).updateMask(mask2)
AttributeError: ‘Image’ object has no attribute ‘bitewiseAnd’
Is it simply a &
or is it something else entirely?
You have a typo - bitwiseAnd
not bitewiseAnd
Correct answer by user2856 on January 3, 2021
You can use the numpy bitewise operations -> https://numpy.org/doc/stable/reference/routines.bitwise.html
numpy.bitwise_and()
Answered by Cary H on January 3, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP