code: def test_optical_flow():
      # --- create scene and attach a renderer to it
      scene = Scene(resolution=(7, 7), frame_end=2)
  
      renderer = Blender(scene)
  
      # --- populate the scene with two balls and a cameras
      ball_horiz = objects.Sphere(
          name="ball_horiz", scale=1, position=(0, 1, 1.0)
      )
      ball_vert = objects.Sphere(
          name="ball_vert", scale=1, position=(1, 0, 1.0)
      )
      scene += ball_horiz
      scene += ball_vert
      scene += cameras.PerspectiveCamera(
          name="camera", position=(1e-5, 0, 20), look_at=(0, 0, 0)
      )
      # make the balls move horizontally to the right, and vertically down
      # these motions should correspond to positive optical flow
      ball_horiz.keyframe_insert("position", 0)
      ball_horiz.position = (0, 10, 1)
      ball_horiz.keyframe_insert("position", 5)
  
      ball_vert.keyframe_insert("position", 0)
      ball_vert.position = (10, 0, 1)
      ball_vert.keyframe_insert("position", 5)
  
      frames = renderer.render()
  
      # assert flow for vertical ball (at bottom) is [>0, =0]
      assert np.max(frames["backward_flow"][1, -1, :, 0]) >= 0.05
      assert np.min(frames["backward_flow"][1, -1, :, 0]) >= 0.0
      assert np.all(np.abs(frames["backward_flow"][1, -1, :, 1]) < 1e-5)
      assert np.max(frames["forward_flow"][1, -1, :, 0]) >= 0.05
      assert np.min(frames["forward_flow"][1, -1, :, 0]) >= 0.0
      assert np.all(np.abs(frames["forward_flow"][1, -1, :, 1]) < 1e-5)
  
      # assert flow for horizontal ball (at the right side) is [=0, >0]
      assert np.all(np.abs(frames["backward_flow"][1, :, -1, 0]) < 1e-5)
      assert np.max(frames["backward_flow"][1, :, -1, 1]) >= 0.05
      assert np.min(frames["backward_flow"][1, :, -1, 1]) >= 0.0
      assert np.all(np.abs(frames["forward_flow"][1, :, -1, 0]) < 1e-5)
      assert np.max(frames["forward_flow"][1, :, -1, 1]) >= 0.05
      assert np.min(frames["forward_flow"][1, :, -1, 1]) >= 0.0
  
file_path: kubric/test/test_postprocessing.py
imports: from kubric.renderer import blender_utils
  from kubric.core.scene import Scene
  from kubric.core import cameras
  from kubric.core import objects
  from kubric.renderer.blender import Blender
  import numpy
  import pytest
label_desc: Use image node_id 2 for calling a global function with example usage: test_optical_flow() without return types