docstr: Extract metadata from SPE v2 files
  
  Parameters
  ----------
  char_encoding
      String character encoding
  sdt_control
      If `True`, try to decode special metadata written by the
      SDT-control software.
  
  Returns
  -------
  dict mapping metadata names to values.
docstr_tok: ["Extract","metadata","from","SPE","v2","files","Parameters","--","--","--","--","--","char_encoding","String","character","encoding","sdt_control","If","`","True","`",",","try","to","decode","special","metadata","written","by","the","SDT-control","software",".","Returns","--","--","--","-","dict","mapping","metadata","names","to","values","."]
code: def _metadata_pre_v3(
      self, char_encoding: str, sdt_control: bool
  ) -> Dict[str, Any]:
      """Extract metadata from SPE v2 files
  
      Parameters
      ----------
      char_encoding
          String character encoding
      sdt_control
          If `True`, try to decode special metadata written by the
          SDT-control software.
  
      Returns
      -------
      dict mapping metadata names to values.
  
      """
  
      m = self._parse_header(Spec.metadata, char_encoding)
  
      nr = m.pop("NumROI", None)
      nr = 1 if nr < 1 else nr
      m["ROIs"] = roi_array_to_dict(m["ROIs"][:nr])
  
      # chip sizes
      m["chip_size"] = [m.pop(k, None) for k in ("xDimDet", "yDimDet")]
      m["virt_chip_size"] = [
          m.pop(k, None) for k in ("VChipXdim", "VChipYdim")
      ]
      m["pre_pixels"] = [
          m.pop(k, None) for k in ("XPrePixels", "YPrePixels")
      ]
      m["post_pixels"] = [
          m.pop(k, None) for k in ("XPostPixels", "YPostPixels")
      ]
  
      # convert comments from numpy.str_ to str
      m["comments"] = [str(c) for c in m["comments"]]
  
      # geometric operations
      g = []
      f = m.pop("geometric", 0)
      if f & 1:
          g.append("rotate")
      if f & 2:
          g.append("reverse")
      if f & 4:
          g.append("flip")
      m["geometric"] = g
  
      # Make some additional information more human-readable
      t = m["type"]
      if 1 <= t <= len(Spec.controllers):
          m["type"] = Spec.controllers[t - 1]
      else:
          m["type"] = None
      r = m["readout_mode"]
      if 1 <= r <= len(Spec.readout_modes):
          m["readout_mode"] = Spec.readout_modes[r - 1]
      else:
          m["readout_mode"] = None
  
      # bools
      for k in (
          "absorb_live",
          "can_do_virtual_chip",
          "threshold_min_live",
          "threshold_max_live",
      ):
          m[k] = bool(m[k])
  
      # Extract SDT-control metadata if desired
      if sdt_control:
          SDTControlSpec.extract_metadata(m, char_encoding)
  
      return m
  
imports: from datetime import datetime
  import logging
  import os
  from typing import Any, Callable, Dict, Iterator, List, Mapping, Optional, Sequence, Tuple, Union
  import warnings
  import numpy
  from ..core.request import Request, IOMode, InitializationError
  from ..core.v3_plugin_api import PluginV3, ImageProperties
label_desc: Use image node_id 5 for calling the SpePlugin obj's underlying member method code with example usage: obj._metadata_pre_v3(char_encoding, sdt_control) and returns: m