code: def _baseline_d_s(
      preds: np.ndarray,
      ms: np.ndarray,
      pan: np.ndarray,
      pan_lr: np.ndarray = None,
      norm_order: int = 1,
      window_size: int = 7,
  ) -> float:
      """NumPy based implementation of Spatial Distortion Index, which uses UQI of TorchMetrics."""
      pan_degraded = pan_lr
      if pan_degraded is None:
          try:
              pan_degraded = uniform_filter(
                  pan, size=window_size, axes=[1, 2]
              )
          except TypeError:
              pan_degraded = np.array(
                  [
                      [
                          uniform_filter(
                              pan[i, ..., j], size=window_size
                          )
                          for j in range(pan.shape[-1])
                      ]
                      for i in range(len(pan))
                  ]
              ).transpose((0, 2, 3, 1))
          pan_degraded = np.array(
              [
                  resize(img, ms.shape[1:3], anti_aliasing=False)
                  for img in pan_degraded
              ]
          )
  
      length = preds.shape[-1]
      m1 = np.zeros(length, dtype=np.float32)
      m2 = np.zeros(length, dtype=np.float32)
  
      # Convert target and preds to Torch Tensors, pass them to metrics UQI
      # this is mainly because reference repo (sewar) uses uniform distribution
      # in their implementation of UQI, and we use gaussian distribution
      # and they have different default values for some kwargs like window size.
      ms = torch.from_numpy(ms).permute(0, 3, 1, 2)
      pan = torch.from_numpy(pan).permute(0, 3, 1, 2)
      preds = torch.from_numpy(preds).permute(0, 3, 1, 2)
      pan_degraded = torch.from_numpy(pan_degraded).permute(0, 3, 1, 2)
      for i in range(length):
          m1[i] = universal_image_quality_index(
              ms[:, i : i + 1], pan_degraded[:, i : i + 1]
          )
          m2[i] = universal_image_quality_index(
              preds[:, i : i + 1], pan[:, i : i + 1]
          )
      diff = np.abs(m1 - m2) ** norm_order
      return np.mean(diff) ** (1 / norm_order)
  
imports: from functools import partial
  from typing import Dict, List, NamedTuple
  import numpy
  import pytest
  import torch
  from scipy.ndimage import uniform_filter
  from skimage.transform import resize
  from torch import Tensor
  from torchmetrics.functional.image.d_s import spatial_distortion_index
  from torchmetrics.functional.image.uqi import universal_image_quality_index
  from torchmetrics.image.d_s import SpatialDistortionIndex
  from unittests import BATCH_SIZE, NUM_BATCHES
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester
label_desc: Use image node_id 1 for calling a global function with example usage: _baseline_d_s(preds, ms, pan, pan_lr, norm_order, window_size) and returns: unknown