File: 0005-Fix-compatibility-with-old-dask-versions.patch

package info (click to toggle)
satpy 0.55.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 38,432 kB
  • sloc: python: 89,849; xml: 820; makefile: 150; javascript: 23
file content (80 lines) | stat: -rw-r--r-- 3,367 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
From: Antonio Valentino <antonio.valentino@tiscali.it>
Date: Sun, 11 Dec 2022 22:55:40 +0000
Subject: Fix compatibility with old dask versions

See also: https://github.com/pytroll/satpy/issues/2248

Forwarded: not-needed
---
 satpy/composites/__init__.py | 51 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/satpy/composites/__init__.py b/satpy/composites/__init__.py
index d7518be..f668769 100644
--- a/satpy/composites/__init__.py
+++ b/satpy/composites/__init__.py
@@ -189,6 +189,55 @@ class CompositeBase:
         new_arrays = list(unify_chunks(*new_arrays))
         return new_arrays
 
+    @staticmethod
+    def _sd_eq(self, other):
+        """Test for approximate equality."""
+        from pyresample.geometry import BaseDefinition, DataArray, da
+        if self is other:
+            return True
+        if not isinstance(other, BaseDefinition):
+            return False
+        if other.lons is None or other.lats is None:
+            other_lons, other_lats = other.get_lonlats()
+        else:
+            other_lons = other.lons
+            other_lats = other.lats
+
+        if self.lons is None or self.lats is None:
+            self_lons, self_lats = self.get_lonlats()
+        else:
+            self_lons = self.lons
+            self_lats = self.lats
+
+        if isinstance(self_lons, DataArray) and np.ndarray is not DataArray:
+            self_lons = self_lons.data
+            self_lats = self_lats.data
+        if isinstance(other_lons, DataArray) and np.ndarray is not DataArray:
+            other_lons = other_lons.data
+            other_lats = other_lats.data
+        if self_lons is other_lons and self_lats is other_lats:
+            return True
+
+        arrs_to_comp = (self_lons, self_lats, other_lons, other_lats)
+        all_dask_arrays = da is not None and all(isinstance(x, da.Array) for x in arrs_to_comp)
+        if all_dask_arrays:
+            import dask
+            v = dask.__version__.split("+")[0]
+            if v >= "2022.11.0":
+                # Optimization: We assume that if two dask arrays have the same task name
+                # they are equivalent. This allows for using geometry objects in dict keys
+                # without computing the dask arrays underneath.
+                return self_lons.name == other_lons.name and self_lats.name == other_lats.name
+
+        try:
+            lons_close = np.allclose(self_lons, other_lons, atol=1e-6, rtol=5e-9, equal_nan=True)
+            if not lons_close:
+                return False
+            lats_close = np.allclose(self_lats, other_lats, atol=1e-6, rtol=5e-9, equal_nan=True)
+            return lats_close
+        except ValueError:
+            return False
+
     def check_geolocation(self, data_arrays: Sequence[xr.DataArray]) -> None:
         """Check that the geolocations of the *data_arrays* are compatible.
 
@@ -225,7 +274,7 @@ class CompositeBase:
         if any(a is None for a in areas):
             raise ValueError("Missing 'area' attribute")
 
-        if not all(areas[0] == x for x in areas[1:]):
+        if not all(self._sd_eq(areas[0], x) for x in areas[1:]):
             LOG.debug("Not all areas are the same in "
                       "'{}'".format(self.attrs["name"]))
             raise IncompatibleAreas("Areas are different")