code: def _write_dicom(output_name, data, image_number=0):
      """Write the data to a dicom file
      Saves the data for one TR to a dicom.
  
      Dicom files are difficult to set up correctly, this file will likely
      crash when trying to open it using dcm2nii. However, if it is loaded in
      python (e.g., dicom.dcmread) then pixel_array contains the relevant
      voxel data
  
      Parameters
      ----------
  
      output_name : str
          Output name for volume being created
  
      data : 3 dimensional array
          Volume of data to be saved
  
      image_number : int
          Number dicom to be saved. This is critical for setting up dicom file
          header information.
  
      """
  
      # Convert data from float to in
      dataInts = data.astype(np.int16)
  
      # Populate required values for file meta information
      file_meta = dicom.Dataset()
      file_meta.MediaStorageSOPClassUID = (
          "1.2"  # '1.2.840.10008.5.1.4.1.1.2'
      )
      file_meta.MediaStorageSOPInstanceUID = "1.2.3"
      file_meta.ImplementationClassUID = "1.2.3.4"
      file_meta.TransferSyntaxUID = "1.2.840.10008.1.2"
  
      # Create the FileDataset
      ds = dicom.FileDataset(
          output_name, {}, file_meta=file_meta, preamble=b"\0" * 128
      )
  
      # Set image dimensions
      frames, rows, cols = dataInts.shape
      ds.Rows = rows
      ds.Columns = cols
      ds.NumberOfFrames = frames
      ds.SamplesPerPixel = 1
      ds.BitsAllocated = 16
      ds.BitsStored = 16
      ds.PixelRepresentation = 0
      ds.InstanceNumber = image_number
      ds.ImagePositionPatient = [0, 0, 0]
      ds.ImageOrientationPatient = [0.01, 0, 0, 0, 0, 0]
      ds.PhotometricInterpretation = "MONOCHROME1"
  
      # Add the data elements -- not trying to set all required here. Check DICOM
      # standard
      ds.PatientName = "sim"
      ds.PatientID = "sim"
  
      # Set the transfer syntax
      ds.is_little_endian = True
      ds.is_implicit_VR = True
  
      # Set creation date/time
      image_datetime = script_datetime + datetime.timedelta(
          seconds=image_number
      )
      timeStr = image_datetime.strftime("%H%M%S")
      ds.ContentDate = image_datetime.strftime("%Y%m%d")
      ds.ContentTime = timeStr
  
      # Add the data
      ds.PixelData = dataInts.tobytes()
  
      ds.save_as(output_name)
  
file_path: brainiak/brainiak/utils/fmrisim_real_time_generator.py
imports: import os
  import time
  import argparse
  import datetime
  import nibabel
  import numpy
  import pydicom
  from brainiak.utils import fmrisim
  import logging
  from pkg_resources import resource_stream
  from nibabel.nifti1 import Nifti1Image
  import gzip
label_desc: Use image node_id 2 for calling a global function with example usage: _write_dicom(output_name, data, image_number) without return types