@@ -792,6 +792,10 @@ class SpatialHash:
792
792
Source grid used to construct the hash grid and hash table
793
793
reconstruct : bool, default=False
794
794
If true, reconstructs the spatial hash
795
+
796
+ Note
797
+ ----
798
+ Does not currently support queries on periodic elements.
795
799
"""
796
800
797
801
def __init__ (
@@ -806,11 +810,21 @@ def __init__(
806
810
807
811
# Hash grid size
808
812
self ._dh = self ._hash_cell_size ()
813
+
809
814
# Lower left corner of the hash grid
810
- self ._xmin = np .deg2rad (self ._source_grid .node_lon .min ().to_numpy ()) - self ._dh
811
- self ._ymin = np .deg2rad (self ._source_grid .node_lat .min ().to_numpy ()) - self ._dh
812
- self ._xmax = np .deg2rad (self ._source_grid .node_lon .max ().to_numpy ()) + self ._dh
813
- self ._ymax = np .deg2rad (self ._source_grid .node_lat .max ().to_numpy ()) + self ._dh
815
+ lon_min = np .deg2rad (self ._source_grid .node_lon .min ().to_numpy ())
816
+ lat_min = np .deg2rad (self ._source_grid .node_lat .min ().to_numpy ())
817
+ lon_max = np .deg2rad (self ._source_grid .node_lon .max ().to_numpy ())
818
+ lat_max = np .deg2rad (self ._source_grid .node_lat .max ().to_numpy ())
819
+
820
+ self ._xmin = lon_min - self ._dh
821
+ self ._ymin = lat_min - self ._dh
822
+ self ._xmax = lon_max + self ._dh
823
+ self ._ymax = lat_max + self ._dh
824
+
825
+ print (self ._xmin , self ._xmax )
826
+ print (self ._ymin , self ._ymax )
827
+
814
828
# Number of x points in the hash grid; used for
815
829
# array flattening
816
830
Lx = self ._xmax - self ._xmin
@@ -866,10 +880,15 @@ def _initialize_face_hash_table(self):
866
880
)
867
881
i2 , j2 = self ._hash_index2d (coords )
868
882
869
- for eid in range (self ._source_grid .n_face ):
870
- for j in range (j1 [eid ], j2 [eid ] + 1 ):
871
- for i in range (i1 [eid ], i2 [eid ] + 1 ):
872
- index_to_face [i + self ._nx * j ].append (eid )
883
+ try :
884
+ for eid in range (self ._source_grid .n_face ):
885
+ for j in range (j1 [eid ], j2 [eid ] + 1 ):
886
+ for i in range (i1 [eid ], i2 [eid ] + 1 ):
887
+ index_to_face [i + self ._nx * j ].append (eid )
888
+ except IndexError :
889
+ raise IndexError (
890
+ "list index out of range. This may indicate incorrect `edge_node_distances` values."
891
+ )
873
892
874
893
return index_to_face
875
894
0 commit comments