1616from raster2dggs .interfaces import RasterIndexer
1717
1818
19+ def is_valid_a5_cell (cell : str , min_resolution : int , max_resolution : int ):
20+ cell = a5py .hex_to_u64 (cell )
21+ try :
22+ c : a5py .A5Cell = a5py .core .serialization .deserialize (cell )
23+ except TypeError :
24+ return False
25+ if not (min_resolution <= c ["resolution" ] <= max_resolution ):
26+ return False
27+ return True
28+
29+
1930class A5RasterIndexer (RasterIndexer ):
2031 """
2132 Provides integration for the A5 DGGS.
@@ -106,15 +117,6 @@ def cell_to_children_size(self, cell: int, desired_resolution: int) -> int:
106117 cell_level = a5py .get_resolution (cell )
107118 return 4 ** (desired_resolution - cell_level )
108119
109- def is_valid_cell (self , cell : str , min_resolution : int , max_resolution : int ):
110- cell = a5py .hex_to_u64 (cell )
111- try :
112- c : a5py .A5Cell = a5py .core .serialization .deserialize (cell )
113- except TypeError :
114- return False
115- if not (min_resolution <= c ["resolution" ] <= max_resolution ):
116- return False
117- return True
118120
119121 def compaction (
120122 self , df : pd .DataFrame , resolution : int , parent_res : int
@@ -130,7 +132,7 @@ def compaction(
130132 unprocessed_indices = set (
131133 filter (
132134 lambda c : (not pd .isna (c ))
133- and self . is_valid_cell (c , parent_res , resolution ),
135+ and is_valid_a5_cell (c , parent_res , resolution ),
134136 set (df .index ),
135137 ),
136138 )
0 commit comments