code: def compute_near_isotropic_downsampling_scales(size,
                                                 voxel_size,
                                                 dimensions_to_downsample,
                                                 max_scales=DEFAULT_MAX_DOWNSAMPLING_SCALES,
                                                 max_downsampling=DEFAULT_MAX_DOWNSAMPLING,
                                                 max_downsampled_size=DEFAULT_MAX_DOWNSAMPLED_SIZE):
      
  
      num_dims = len(voxel_size)
      cur_scale = np.ones((num_dims, ), dtype=int)
      scales = [tuple(cur_scale)]
      while (len(scales) < max_scales and (np.prod(cur_scale) < max_downsampling) and
             (size / cur_scale).max() > max_downsampled_size):
          # Find dimension with smallest voxelsize.
          cur_voxel_size = cur_scale * voxel_size
          smallest_cur_voxel_size_dim = dimensions_to_downsample[np.argmin(cur_voxel_size[
              dimensions_to_downsample])]
          cur_scale[smallest_cur_voxel_size_dim] *= 2
          target_voxel_size = cur_voxel_size[smallest_cur_voxel_size_dim] * 2
          for d in dimensions_to_downsample:
              if d == smallest_cur_voxel_size_dim:
                  continue
              d_voxel_size = cur_voxel_size[d]
              if abs(d_voxel_size - target_voxel_size) > abs(d_voxel_size * 2 - target_voxel_size):
                  cur_scale[d] *= 2
          scales.append(tuple(cur_scale))
      return scales
docs: Compute a list of successive downsampling factors.