pytroll / pytroll-schedule

Reception scheduling of polar weather satellites
http://pytroll-schedule.readthedocs.org/
GNU General Public License v3.0
9 stars 12 forks source link

Test failure with PyResample 1.23 #68

Closed avalentino closed 1 year ago

avalentino commented 2 years ago

Code Sample, a minimal, complete, and verifiable piece of code

$ python3 -m pytest -k test_bool .

Problem description

The test_bool unittest fails. The issue seems to be relate to the normalization of spherical coordinates (+/- 2*pi). The problem seems to only happen with the latest version of pyresample (v1.23).

Expected Output

All tests pass.

Actual Result, Traceback if applicable

$ python3 -m pytest -k test_bool .
======================================================== test session starts ========================================================
platform linux -- Python 3.10.4, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /home/antonio/debian/git/pytroll-schedule
plugins: timeout-2.1.0, doctestplus-0.12.0, remotedata-0.3.3
collected 39 items / 38 deselected / 1 selected                                                                                     

trollsched/tests/test_spherical.py F                                                                                          [100%]

============================================================= FAILURES ==============================================================
__________________________________________________ TestSphericalPolygon.test_bool ___________________________________________________

self = <trollsched.tests.test_spherical.TestSphericalPolygon testMethod=test_bool>

    def test_bool(self):
        """Test the intersection and union functions.
        """
        vertices = np.array([[180, 90, 0, -90],
                             [89, 89, 89, 89]]).T
        poly1 = SphPolygon(np.deg2rad(vertices))
        vertices = np.array([[-45, -135, 135, 45],
                             [89, 89, 89, 89]]).T
        poly2 = SphPolygon(np.deg2rad(vertices))

        uni = np.array([[157.5,   89.23460094],
                        [-225.,   89.],
                        [112.5,   89.23460094],
                        [90.,   89.],
                        [67.5,   89.23460094],
                        [45.,   89.],
                        [22.5,   89.23460094],
                        [0.,   89.],
                        [-22.5,   89.23460094],
                        [-45.,   89.],
                        [-67.5,   89.23460094],
                        [-90.,   89.],
                        [-112.5,   89.23460094],
                        [-135.,   89.],
                        [-157.5,   89.23460094],
                        [-180.,   89.]])
        inter = np.array([[157.5,   89.23460094],
                          [112.5,   89.23460094],
                          [67.5,   89.23460094],
                          [22.5,   89.23460094],
                          [-22.5,   89.23460094],
                          [-67.5,   89.23460094],
                          [-112.5,   89.23460094],
                          [-157.5,   89.23460094]])
        poly_inter = poly1.intersection(poly2)
        poly_union = poly1.union(poly2)

        self.assertTrue(poly_inter.area() <= poly_union.area())

        self.assertTrue(np.allclose(poly_inter.vertices,
                                    np.deg2rad(inter)))
>       self.assertTrue(np.allclose(poly_union.vertices,
                                    np.deg2rad(uni)))
E       AssertionError: False is not true

trollsched/tests/test_spherical.py:492: AssertionError
========================================================= warnings summary ==========================================================
../../../../../usr/lib/python3/dist-packages/blosc/toplevel.py:12
  /usr/lib/python3/dist-packages/blosc/toplevel.py:12: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
    from distutils.version import LooseVersion

-- Docs: https://docs.pytest.org/en/stable/warnings.html
====================================================== short test summary info ======================================================
FAILED trollsched/tests/test_spherical.py::TestSphericalPolygon::test_bool - AssertionError: False is not true
============================================ 1 failed, 38 deselected, 1 warning in 1.83s ============================================

Versions of Python, package at hand and relevant dependencies

Python 3.10.4 pyresample 1.23 pytroll-schedule v0.6.0

djhoese commented 2 years ago

The wrapping of longitudes was fixed in pyresample. This test is probably wrong and "just" needs to be updated. @ghiggi have more guesses since he did the updates on pyresample.

ghiggi commented 2 years ago

@djhoese Yes the test in pytroll-schedule should be updated as the following pyresample test. There is lot of duplicated code in pytroll-schedule/spherical.py. The definition of SCoordinate, CCoordinate and Arc class is the same as the one in pyresample/spherical.py, and such classes could be simply imported from pyresample.

djhoese commented 2 years ago

Yes, the code originally lived in pytroll-schedule and was copied to pyresample. I don't use pytroll-schedule so I haven't worked on removing the duplication. I wonder what @pnuu and @mraspaud think or if they have a plan to remove the duplication?

pnuu commented 1 year ago

I just noticed this while looking at open PRs and saw the tests in Dependabot were failing. I have no understanding of the internals, so I guess we need to wait and see what @mraspaud thinks after holidays. My "fix" would be to just update the test reference values..

I think I don't use the package directly anywhere :thinking: The geographic gatherer in pytroll-collector uses this, but that's a part I doubt I have looked into in depth.

pnuu commented 1 year ago

Oh, I think @mraspaud already started at least with the duplication of Pyresample code in https://github.com/pytroll/pytroll-schedule/pull/72