@@ -759,6 +759,7 @@ def _point_not_in_cell(nodes_x, nodes_y, point):
759
759
# with 'ind', but that's OK because we're not
760
760
# going to use 'ind' again as 'create_mask' is
761
761
# False.
762
+ reduced_halo = False
762
763
for axis in item_axes :
763
764
index = indices [axis ]
764
765
size = domain_axes [axis ].get_size ()
@@ -815,12 +816,27 @@ def _point_not_in_cell(nodes_x, nodes_y, point):
815
816
816
817
if step > 0 :
817
818
# Increasing cyclic slice
818
- start = max (start - halo , stop - size )
819
- stop = min (stop + halo , size + start )
819
+ start = start - halo
820
+ if start < stop - size :
821
+ start = stop - size
822
+ reduced_halo = True
823
+
824
+ stop = stop + halo
825
+ if stop > size + start :
826
+ stop = size + start
827
+ reduced_halo = True
828
+
820
829
else :
821
830
# Decreasing cyclic slice
822
- start = min (start + halo , size + stop )
823
- stop = max (stop - halo , start - size )
831
+ start = start + halo
832
+ if start > size + stop :
833
+ start = size + stop
834
+ reduced_halo = True
835
+
836
+ stop = stop - halo
837
+ if stop < start - size :
838
+ stop = start - size
839
+ reduced_halo = True
824
840
825
841
index = slice (start , stop , step )
826
842
else :
@@ -889,16 +905,34 @@ def _point_not_in_cell(nodes_x, nodes_y, point):
889
905
# Extend the list at each end, but not
890
906
# exceeding the axis limits.
891
907
if increasing_L :
892
- left = range (max (* (0 , iL - halo )), iL )
908
+ start = iL - halo
909
+ if start < 0 :
910
+ start = 0
911
+ reduced_halo = True
912
+
913
+ left = range (start , iL )
893
914
else :
894
- left = range (min (* (size - 1 , iL + halo )), iL , - 1 )
915
+ start = iL + halo
916
+ if start > size - 1 :
917
+ start = size - 1
918
+ reduced_halo = True
919
+
920
+ left = range (start , iL , - 1 )
895
921
896
922
if increasing_R :
897
- right = range (iR + 1 , min (* (iR + 1 + halo , size )))
923
+ stop = iR + 1 + halo
924
+ if stop > size :
925
+ stop = size
926
+ reduced_halo = True
927
+
928
+ right = range (iR + 1 , stop )
898
929
else :
899
- right = range (
900
- iR - 1 , max (* (iR - 1 - halo , - 1 )), - 1
901
- )
930
+ stop = iR - 1 - halo
931
+ if stop < - 1 :
932
+ stop = - 1
933
+ reduced_halo = True
934
+
935
+ right = range (iR - 1 , stop , - 1 )
902
936
903
937
index = index .tolist ()
904
938
index [:0 ] = left
@@ -907,6 +941,11 @@ def _point_not_in_cell(nodes_x, nodes_y, point):
907
941
# Reset the returned index
908
942
indices [axis ] = index
909
943
944
+ if reduced_halo :
945
+ logger .warning (
946
+ "Halo reduced to keep subspace within axis limits"
947
+ )
948
+
910
949
# Create an ancillary mask for these axes
911
950
if debug :
912
951
logger .debug (
0 commit comments