code: def parse_bids_filename(img_path):
      r"""Return dictionary with parsed information from file path.
  
      Parameters
      ----------
      img_path : :obj:`str`
          Path to file from which to parse information.
  
      Returns
      -------
      reference : :obj:`dict`
          Returns a dictionary with all key-value pairs in the file name
          parsed and other useful fields like 'file_path', 'file_basename',
          'file_tag', 'file_type' and 'file_fields'.
  
          The 'file_tag' field refers to the last part of the file under the
          :term:`BIDS` convention that is of the form \*_tag.type.
          Contrary to the rest of the file name it is not a key-value pair.
          This notion should be revised in the case we are handling derivatives
          since so far the convention will keep the tag prepended to any fields
          added in the case of preprocessed files that also end with another tag.
          This parser will consider any tag in the middle of the file name as a
          key with no value and will be included in the 'file_fields' key.
  
      """
      reference = {
          "file_path": img_path,
          "file_basename": os.path.basename(img_path),
      }
      parts = reference["file_basename"].split("_")
      tag, type_ = parts[-1].split(".", 1)
      reference["file_tag"] = tag
      reference["file_type"] = type_
      reference["file_fields"] = []
      for part in parts[:-1]:
          field = part.split("-")[0]
          reference["file_fields"].append(field)
          # In derivatives is not clear if the source file name will
          # be parsed as a field with no value.
          if len(part.split("-")) > 1:
              value = part.split("-")[1]
              reference[field] = value
          else:
              reference[field] = None
      return reference
  
file_path: nilearn/nilearn/interfaces/bids/query.py
imports: from __future__ import annotations
  import glob
  import json
  import os
  from pathlib import Path
  from warnings import warn
label_desc: Use image node_id 5 for calling a global function with example usage: parse_bids_filename(img_path) and returns: reference