Skip to content

Commit f038dd8

Browse files
committed
warn when reducing halo size
1 parent cb535c4 commit f038dd8

File tree

1 file changed

+49
-10
lines changed

1 file changed

+49
-10
lines changed

cf/mixin/fielddomain.py

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ def _point_not_in_cell(nodes_x, nodes_y, point):
759759
# with 'ind', but that's OK because we're not
760760
# going to use 'ind' again as 'create_mask' is
761761
# False.
762+
reduced_halo = False
762763
for axis in item_axes:
763764
index = indices[axis]
764765
size = domain_axes[axis].get_size()
@@ -815,12 +816,27 @@ def _point_not_in_cell(nodes_x, nodes_y, point):
815816

816817
if step > 0:
817818
# 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+
820829
else:
821830
# 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
824840

825841
index = slice(start, stop, step)
826842
else:
@@ -889,16 +905,34 @@ def _point_not_in_cell(nodes_x, nodes_y, point):
889905
# Extend the list at each end, but not
890906
# exceeding the axis limits.
891907
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)
893914
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)
895921

896922
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)
898929
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)
902936

903937
index = index.tolist()
904938
index[:0] = left
@@ -907,6 +941,11 @@ def _point_not_in_cell(nodes_x, nodes_y, point):
907941
# Reset the returned index
908942
indices[axis] = index
909943

944+
if reduced_halo:
945+
logger.warning(
946+
"Halo reduced to keep subspace within axis limits"
947+
)
948+
910949
# Create an ancillary mask for these axes
911950
if debug:
912951
logger.debug(

0 commit comments

Comments
 (0)