code: def createNetwork(dataSource, enableTP=False, temporalImp="py"):
      """Create the Network instance.
  
      The network has a sensor region reading data from `dataSource` and passing
      the encoded representation to an SPRegion. The SPRegion output is passed to
      a TMRegion.
  
      :param dataSource: a RecordStream instance to get data from
      :returns: a Network instance ready to run
      """
      network = Network()
  
      # Our input is sensor data from the gym file. The RecordSensor region
      # allows us to specify a file record stream as the input source via the
      # dataSource attribute.
      network.addRegion(
          "sensor",
          "py.RecordSensor",
          json.dumps({"verbosity": _VERBOSITY}),
      )
      sensor = network.regions["sensor"].getSelf()
      # The RecordSensor needs to know how to encode the input values
      sensor.encoder = createEncoder()
      # Specify the dataSource as a file record stream instance
      sensor.dataSource = dataSource
  
      # Create the spatial pooler region
      SP_PARAMS["inputWidth"] = sensor.encoder.getWidth()
      network.addRegion(
          "spatialPoolerRegion", "py.SPRegion", json.dumps(SP_PARAMS)
      )
  
      # Link the SP region to the sensor input
      network.link("sensor", "spatialPoolerRegion", "UniformLink", "")
      network.link(
          "sensor",
          "spatialPoolerRegion",
          "UniformLink",
          "",
          srcOutput="resetOut",
          destInput="resetIn",
      )
      network.link(
          "spatialPoolerRegion",
          "sensor",
          "UniformLink",
          "",
          srcOutput="spatialTopDownOut",
          destInput="spatialTopDownIn",
      )
      network.link(
          "spatialPoolerRegion",
          "sensor",
          "UniformLink",
          "",
          srcOutput="temporalTopDownOut",
          destInput="temporalTopDownIn",
      )
  
      if enableTP:
          # Add the TMRegion on top of the SPRegion
          TM_PARAMS["temporalImp"] = temporalImp
          network.addRegion(
              "temporalPoolerRegion",
              "py.TMRegion",
              json.dumps(TM_PARAMS),
          )
  
          network.link(
              "spatialPoolerRegion",
              "temporalPoolerRegion",
              "UniformLink",
              "",
          )
          network.link(
              "temporalPoolerRegion",
              "spatialPoolerRegion",
              "UniformLink",
              "",
              srcOutput="topDownOut",
              destInput="topDownIn",
          )
  
      spatialPoolerRegion = network.regions["spatialPoolerRegion"]
  
      # Make sure learning is enabled
      spatialPoolerRegion.setParameter("learningMode", True)
      # We want temporal anomalies so disable anomalyMode in the SP. This mode is
      # used for computing anomalies in a non-temporal model.
      spatialPoolerRegion.setParameter("anomalyMode", False)
  
      if enableTP:
          temporalPoolerRegion = network.regions["temporalPoolerRegion"]
  
          # Enable topDownMode to get the predicted columns output
          temporalPoolerRegion.setParameter("topDownMode", True)
          # Make sure learning is enabled (this is the default)
          temporalPoolerRegion.setParameter("learningMode", True)
          # Enable inference mode so we get predictions
          temporalPoolerRegion.setParameter("inferenceMode", True)
          # Enable anomalyMode to compute the anomaly score. This actually doesn't work
          # now so doesn't matter. We instead compute the anomaly score based on
          # topDownOut (predicted columns) and SP bottomUpOut (active columns).
          temporalPoolerRegion.setParameter("anomalyMode", True)
  
      return network
  
file_path: nupic-legacy/tests/integration/nupic/engine/network_creation_common.py
imports: import copy
  import csv
  import json
  import os
  import tempfile
  from pkg_resources import resource_filename
  from nupic.data.file_record_stream import FileRecordStream
  from nupic.engine import Network
  from nupic.encoders import MultiEncoder, ScalarEncoder, DateEncoder
  from nupic.regions.record_sensor import RecordSensor
  from nupic.regions.sp_region import SPRegion
  from nupic.regions.tm_region import TMRegion
label_desc: Use image node_id 2 for calling a global function with example usage: createNetwork(dataSource, enableTP, temporalImp) and returns: network