Repository: Project-MONAI/MONAI

Issue:
default spacing mode should be "nearest"
**Describe the bug**
Currently, the default mode of spacing transform is "constant", which will give an all 0 border to the image. If the intensity is not normalized to [0, 1], this border is not expected.
So we should use "nearest" mode as default.


Discussion:

Resolving patch:
diff --git a/monai/transforms/croppad/dictionary.py b/monai/transforms/croppad/dictionary.py
--- a/monai/transforms/croppad/dictionary.py
+++ b/monai/transforms/croppad/dictionary.py
@@ -173,7 +173,7 @@ def __init__(self, keys, source_key, select_fn=lambda x: x > 0, channel_indexes=
     def __call__(self, data):
         d = dict(data)
         box_start, box_end = generate_spatial_bounding_box(
-            data[self.source_key], self.select_fn, self.channel_indexes, self.margin
+            d[self.source_key], self.select_fn, self.channel_indexes, self.margin
         )
         cropper = SpatialCrop(roi_start=box_start, roi_end=box_end)
         for key in self.keys:
diff --git a/monai/transforms/spatial/array.py b/monai/transforms/spatial/array.py
--- a/monai/transforms/spatial/array.py
+++ b/monai/transforms/spatial/array.py
@@ -39,7 +39,7 @@ class Spacing(Transform):
     Resample input image into the specified `pixdim`.
     """
 
-    def __init__(self, pixdim, diagonal=False, mode="constant", cval=0, dtype=None):
+    def __init__(self, pixdim, diagonal=False, mode="nearest", cval=0, dtype=None):
         """
         Args:
             pixdim (sequence of floats): output voxel spacing.
diff --git a/monai/transforms/spatial/dictionary.py b/monai/transforms/spatial/dictionary.py
--- a/monai/transforms/spatial/dictionary.py
+++ b/monai/transforms/spatial/dictionary.py
@@ -50,7 +50,7 @@ class Spacingd(MapTransform):
     """
 
     def __init__(
-        self, keys, pixdim, diagonal=False, mode="constant", cval=0, interp_order=3, dtype=None, meta_key_format="{}.{}"
+        self, keys, pixdim, diagonal=False, mode="nearest", cval=0, interp_order=3, dtype=None, meta_key_format="{}.{}"
     ):
         """
         Args:
@@ -69,7 +69,7 @@ def __init__(
                 axes against the original ones.
             mode (`reflect|constant|nearest|mirror|wrap`):
                 The mode parameter determines how the input array is extended beyond its boundaries.
-                Default is 'constant'.
+                Default is 'nearest'.
             cval (scalar): Value to fill past edges of input if mode is "constant". Default is 0.0.
             interp_order (int or sequence of ints): int: the same interpolation order
                 for all data indexed by `self.keys`; sequence of ints, should


Test patch:
diff --git a/tests/test_spacing.py b/tests/test_spacing.py
--- a/tests/test_spacing.py
+++ b/tests/test_spacing.py
@@ -17,33 +17,33 @@
 from monai.transforms import Spacing
 
 TEST_CASES = [
-    [{"pixdim": (2.0,)}, np.ones((1, 2)), {"affine": np.eye(4)}, np.array([[1.0, 0.0]])],  # data
+    [{"pixdim": (2.0,), "mode": "constant"}, np.ones((1, 2)), {"affine": np.eye(4)}, np.array([[1.0, 0.0]])],  # data
     [
-        {"pixdim": (1.0, 0.2, 1.5)},
+        {"pixdim": (1.0, 0.2, 1.5), "mode": "constant"},
         np.ones((1, 2, 1, 2)),  # data
         {"affine": np.eye(4)},
         np.array([[[[1.0, 0.0]], [[1.0, 0.0]]]]),
     ],
     [
-        {"pixdim": (1.0, 0.2, 1.5), "diagonal": False},
+        {"pixdim": (1.0, 0.2, 1.5), "diagonal": False, "mode": "constant"},
         np.ones((1, 2, 1, 2)),  # data
         {"affine": np.array([[2, 1, 0, 4], [-1, -3, 0, 5], [0, 0, 2.0, 5], [0, 0, 0, 1]])},
         np.zeros((1, 3, 1, 2)),
     ],
     [
-        {"pixdim": (3.0, 1.0)},
+        {"pixdim": (3.0, 1.0), "mode": "constant"},
         np.arange(24).reshape((2, 3, 4)),  # data
         {"affine": np.diag([-3.0, 0.2, 1.5, 1])},
         np.array([[[0, 0], [4, 0], [8, 0]], [[12, 0], [16, 0], [20, 0]]]),
     ],
     [
-        {"pixdim": (3.0, 1.0)},
+        {"pixdim": (3.0, 1.0), "mode": "constant"},
         np.arange(24).reshape((2, 3, 4)),  # data
         {},
         np.array([[[0, 1, 2, 3], [0, 0, 0, 0]], [[12, 13, 14, 15], [0, 0, 0, 0]]]),
     ],
     [
-        {"pixdim": (1.0, 1.0)},
+        {"pixdim": (1.0, 1.0), "mode": "constant"},
         np.arange(24).reshape((2, 3, 4)),  # data
         {},
         np.array(
@@ -51,13 +51,13 @@
         ),
     ],
     [
-        {"pixdim": (4.0, 5.0, 6.0)},
+        {"pixdim": (4.0, 5.0, 6.0), "mode": "constant"},
         np.arange(24).reshape((1, 2, 3, 4)),  # data
         {"affine": np.array([[-4, 0, 0, 4], [0, 5, 0, -5], [0, 0, 6, -6], [0, 0, 0, 1]])},
         np.arange(24).reshape((1, 2, 3, 4)),  # data
     ],
     [
-        {"pixdim": (4.0, 5.0, 6.0), "diagonal": True},
+        {"pixdim": (4.0, 5.0, 6.0), "diagonal": True, "mode": "constant"},
         np.arange(24).reshape((1, 2, 3, 4)),  # data
         {"affine": np.array([[-4, 0, 0, 4], [0, 5, 0, 0], [0, 0, 6, 0], [0, 0, 0, 1]])},
         np.array(