Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix small data discrepancy between Xee and pure computePixels() #40

Closed
alxmrs opened this issue Oct 5, 2023 · 4 comments
Closed

Fix small data discrepancy between Xee and pure computePixels() #40

alxmrs opened this issue Oct 5, 2023 · 4 comments
Labels
bug Something isn't working P1

Comments

@alxmrs
Copy link
Collaborator

alxmrs commented Oct 5, 2023

Description TBD.

@alxmrs alxmrs added bug Something isn't working P1 labels Oct 5, 2023
@alxmrs
Copy link
Collaborator Author

alxmrs commented Oct 6, 2023

Note for the reader: if you are just using Xee, this is not so much of an issue. But, if you need to replace a raw computePixels() call with Xee, this bug will be a concern.

@alxmrs
Copy link
Collaborator Author

alxmrs commented Oct 11, 2023

This is the internal test that fails:

class GetPixelsTest(unittest.TestCase):

  def setUp(self):
    super().setUp()
    init_ee_for_tests()

    self.lnglat = ee.ImageCollection.fromImages([ee.Image.pixelLonLat()])
    self.conus = ee.ImageCollection('GRIDMET/DROUGHT').filterDate(
        '2020-03-30', '2020-04-01'
    )
    self.bbox = ee.Geometry.BBox(-121.55, 39.01, -120.57, 39.38)

  def test_get_pixels__with_or_without_xee__is_the_same(self):
    for name, ic in [
        # ('latlng', self.lnglat),  # TODO(alxr, mahrsee): Support this case.
        ('conus', self.conus),
    ]:
      img = ic.first()
      with self.subTest(f'{name} test'):
        clipped = img.clip(self.bbox)

        y = ee_util.get_pixels(clipped, using_xee=False)
        y_hat = ee_util.get_pixels(clipped, using_xee=True)

        self.assertEqual(y.shape, y_hat.shape, f'{y.shape} != {y_hat.shape}')
        self.assertEqual(y.dtype, y_hat.dtype, f'{y.dtype} != {y_hat.dtype}')
        # np.array_equal better compares structured arrays than np.allclose
        self.assertTrue(np.array_equal(y, y_hat), f'{y}\n!={y_hat}')

It fails with the following error:

Traceback (most recent call last):
  File ".../ee_util_manual_test.py", line 74, in test_get_pixels__with_or_without_xee__is_the_same
    self.assertEqual(y.shape, y_hat.shape, f'{y.shape} != {y_hat.shape}')
AssertionError: Tuples differ: (10, 25) != (9, 24)

First differing element 0:
10
9

- (10, 25)
+ (9, 24) : (10, 25) != (9, 24)

@alxmrs
Copy link
Collaborator Author

alxmrs commented Oct 11, 2023

After talking to @saicheems and other Earth Engine folks, it seems like the root of the issue has to do with rounding the pixel boundaries on the backend that is not mirrored in this Python client.

@mahrsee1997
Copy link
Collaborator

Resolved in #105.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1
Projects
None yet
Development

No branches or pull requests

2 participants