code: def process_directory(
      request, progressIndicator, readPixelData=False
  ):
      """
      Reads dicom files and returns a list of DicomSeries objects, which
      contain information about the data, and can be used to load the
      image or volume data.
  
      if readPixelData is True, the pixel data of all series is read. By
      default the loading of pixeldata is deferred until it is requested
      using the DicomSeries.get_pixel_array() method. In general, both
      methods should be equally fast.
      """
      # Get directory to examine
      if os.path.isdir(request.filename):
          path = request.filename
      elif os.path.isfile(request.filename):
          path = os.path.dirname(request.filename)
      else:  # pragma: no cover - tested earlier
          raise ValueError(
              "Dicom plugin needs a valid filename to examine the directory"
          )
  
      # Check files
      files = []
      list_files(files, path)  # Find files recursively
  
      # Gather file data and put in DicomSeries
      series = {}
      count = 0
      progressIndicator.start("examining files", "files", len(files))
      for filename in files:
          # Show progress (note that we always start with a 0.0)
          count += 1
          progressIndicator.set_progress(count)
          # Skip DICOMDIR files
          if filename.count("DICOMDIR"):  # pragma: no cover
              continue
          # Try loading dicom ...
          try:
              dcm = SimpleDicomReader(filename)
          except NotADicomFile:
              continue  # skip non-dicom file
          except Exception as why:  # pragma: no cover
              progressIndicator.write(str(why))
              continue
          # Get SUID and register the file with an existing or new series object
          try:
              suid = dcm.SeriesInstanceUID
          except AttributeError:  # pragma: no cover
              continue  # some other kind of dicom file
          if suid not in series:
              series[suid] = DicomSeries(suid, progressIndicator)
          series[suid]._append(dcm)
  
      # Finish progress
      # progressIndicator.finish('Found %i series.' % len(series))
  
      # Make a list and sort, so that the order is deterministic
      series = list(series.values())
      series.sort(key=lambda x: x.suid)
  
      # Split series if necessary
      for serie in reversed([serie for serie in series]):
          splitSerieIfRequired(serie, series, progressIndicator)
  
      # Finish all series
      # progressIndicator.start('analyse series', '', len(series))
      series_ = []
      for i in range(len(series)):
          try:
              series[i]._finish()
              series_.append(series[i])
          except Exception as err:  # pragma: no cover
              progressIndicator.write(str(err))
              pass  # Skip serie (probably report-like file without pixels)
          # progressIndicator.set_progress(i+1)
      progressIndicator.finish(
          "Found %i correct series." % len(series_)
      )
  
      # Done
      return series_
  
imports: import sys
  import os
  import struct
  import logging
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: process_directory(request, progressIndicator, readPixelData) and returns: series_