question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different results from reduceRegion after running mosaicSameDay utility

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jonschwenkcommented, Sep 12, 2019

Thank you for yours!

1reaction
fitoprincipecommented, Sep 12, 2019

Hi @jonschwenk ,

Sorry for the late reply. I just uploaded a new geetools version making mosaicSameDay simpler using just ee.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 a compositeSameDay 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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ee.Image.reduceRegion - Earth Engine - Google Developers
Apply a reducer to all the pixels in a specific region. Either the reducer must have the same number of inputs as the...
Read more >
Clipping and Reduce Region vs Reduce region alone gives ...
However, when I use reduceRegion to compute average areal average rainfall, the two images give different results.
Read more >
ee.ReduceRegions unexpected length of results when ...
But I am getting very different length outputs. I have made sure my input data has no missing values and tried using both...
Read more >
Calculating Area in Google Earth Engine - Spatial Thoughts
The following code snippet shows how to select the image and visualize it. ... The result of reduceRegion() with a grouped reducer is...
Read more >
Google Earth Engine Community gee_tools Issues - Giters
Error when trying to batch export VIIRS images to Google Drive ... Different results from reduceRegion after running mosaicSameDay utility.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found