Different results from reduceRegion after running mosaicSameDay utility
See original GitHub issueI am not sure if this is a bug, but I’ll report it and you can hopefully determine. I am using the python API and gee_tools. I have shared my shapefile asset so hopefully you can just plug this in.
I am computing the area of a Landsat image within a polygon, and then computing it again after using the mosaicSameDay tool. The image I’m using completely covers the polygon, so one would expect the area to be the same before or after running the tool. However, this is not the case and the areas are substantially different.
import ee
from geetools.tools import imagecollection as ictools
# function to compute overlap area between polygon and image
def valid_area(img):
"""
Returns a feature containing the total valid area (as defined by the
append_vo_band function) within an image. Requires a 'valid_obs' band to
be present in an image.
"""
# Convert image to binary
bin_im = ee.Image(img.select('B1'))
bin_im = bin_im.where(bin_im.neq(0), 1)
bin_im = bin_im.where(bin_im.neq(1), 0)
# Convert valid observation band to pixel areas band (no valid obs are still zeros)
pix_areas = ee.Image.multiply(bin_im, ee.Image.pixelArea())
# Number of pixels in valid region
validarea = pix_areas.reduceRegion(
reducer = ee.Reducer.sum(),
geometry = feat.geometry(),
scale = scale,
maxPixels = 1e12,
bestEffort = False)
return ee.Feature(None, {'valid_area':validarea.get('B1')})
# Set things up
ee.Initialize()
start_date = '2010-01-01'
end_date = '2019-01-01'
scale = 30 # The scale to do the analysis
n_images = 10 # Maximum number of images to fetch--used for testing
provinces = ee.FeatureCollection('users/jonschwenk/Ecuador_provinces')
feat = provinces.first() # work on first polygon
# Landsat 8 analysis
L8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA') \
.filterDate(start_date, end_date) \
.filterBounds(feat.geometry()) \
L8_m = ictools.mosaicSameDay(L8)
# Now check results
L8_m = ee.ImageCollection(L8_m.toList(n_images))
L8area = valid_area(L8.first()).getInfo()['properties']['valid_area']
L8marea = valid_area(L8_m.first()).getInfo()['properties']['valid_area']
print(L8area)
shows 3,943,647,359,
while print(L8marea)
shows 3,161,128.
To reiterate: the L8 image completely covers the polygon (and the area of the polygon is roughtly 3.9x10^9, matching the L8area value), so mosaicing additional images to it should not change its area value.
I also know that the images come from the same date, so my question is: why is the area different after running the sameDayMosaic tool? My best guess is that the tool does not preserve the CRS or CRS transform, although I thought GEE would handle those things under the hood through the ee.Image.pixelArea() function.
Let me know if there’s any more info you need 😃
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
Thank you for yours!
Hi @jonschwenk ,
Sorry for the late reply. I just uploaded a new geetools version making
mosaicSameDay
simpler using justee.ImageCollection.mosaic
to fix the previus issue you had with it (preserving the data type). I thought it’d fix this issue too… but it doesn’t! I’m thinking in making acompositeSameDay
for more complex operations.I discover it is due to the projection (as you mentioned in the question), so I’ll modify again the function to preserve the projection. I’ll close this issue when I push the fixing commit.
Thanks!