code: def splitSerieIfRequired(serie, series, progressIndicator):
      """
      Split the serie in multiple series if this is required. The choice
      is based on examing the image position relative to the previous
      image. If it differs too much, it is assumed that there is a new
      dataset. This can happen for example in unspitted gated CT data.
      """
  
      # Sort the original list and get local name
      serie._sort()
      L = serie._entries
      # Init previous slice
      ds1 = L[0]
      # Check whether we can do this
      if "ImagePositionPatient" not in ds1:
          return
      # Initialize a list of new lists
      L2 = [[ds1]]
      # Init slice distance estimate
      distance = 0
  
      for index in range(1, len(L)):
          # Get current slice
          ds2 = L[index]
          # Get positions
          pos1 = float(ds1.ImagePositionPatient[2])
          pos2 = float(ds2.ImagePositionPatient[2])
          # Get distances
          newDist = abs(pos1 - pos2)
          # deltaDist = abs(firstPos-pos2)
          # If the distance deviates more than 2x from what we've seen,
          # we can agree it's a new dataset.
          if distance and newDist > 2.1 * distance:
              L2.append([])
              distance = 0
          else:
              # Test missing file
              if distance and newDist > 1.5 * distance:
                  progressIndicator.write(
                      "Warning: missing file after %r" % ds1._filename
                  )
              distance = newDist
          # Add to last list
          L2[-1].append(ds2)
          # Store previous
          ds1 = ds2
  
      # Split if we should
      if len(L2) > 1:
          # At what position are we now?
          i = series.index(serie)
          # Create new series
          series2insert = []
          for L in L2:
              newSerie = DicomSeries(serie.suid, progressIndicator)
              newSerie._entries = L
              series2insert.append(newSerie)
          # Insert series and remove self
          for newSerie in reversed(series2insert):
              series.insert(i, newSerie)
          series.remove(serie)
  
imports: import sys
  import os
  import struct
  import logging
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: splitSerieIfRequired(serie, series, progressIndicator) without return types