docs: def build_lv_graph_ria(lvgd, grid_model_params):
      """Build graph for LV grid of sectors retail/industrial and agricultural
  
      Based on structural description of LV grid topology for sectors
      retail/industrial and agricultural (RIA) branches for these sectors are
      created and attached to the LV grid's MV-LV substation bus bar.
  
      LV loads of the sectors retail/industrial and agricultural are located
      in separat branches for each sector (in case of large load multiple of
      these).
      These loads are distributed across the branches by an equidistant
      distribution.
  
      This function accepts the dict `grid_model_params` with particular
      structure
  
      >>> grid_model_params = {
      >>> ... 'agricultural': {
      >>> ...     'max_loads_per_branch': 2
      >>> ...     'single_peak_load': 140,
      >>> ...     'full_branches': 2,
      >>> ...     'remaining_loads': 1,
      >>> ...     'load_distance': 800/3,
      >>> ...     'load_distance_remaining': 400}}
  
      Parameters
      ----------
      lvgd : LVGridDistrictDing0
          Low-voltage grid district object
      grid_model_params : dict
          Dict of structural information of sectoral LV grid branchwith particular 
          structure, e.g.::
  
              grid_model_params = {
                  'agricultural': {
                      'max_loads_per_branch': 2
                      'single_peak_load': 140,
                      'full_branches': 2,
                      'remaining_loads': 1,
                      'load_distance': 800/3,
                      'load_distance_remaining': 400
                  }
              }
  
      Notes
      -----
      We assume a distance from the load to the branch it is connected to of
      30 m. This assumption is defined in the config files.
      """
  
      def lv_graph_attach_branch():
          """Attach a single branch including its equipment (cable dist, loads
          and line segments) to graph of `lv_grid`
          """
  
          # determine maximum current occuring due to peak load
          # of this load load_no
          I_max_load = val['single_peak_load'] / (3 ** 0.5 * 0.4) / cos_phi_load
  
          # determine suitable cable for this current
          suitable_cables_stub = lvgd.lv_grid.network.static_data['LV_cables'][
              (lvgd.lv_grid.network.static_data['LV_cables'][
                  'I_max_th'] * cable_lf) > I_max_load]
          cable_type_stub = suitable_cables_stub.loc[
              suitable_cables_stub['I_max_th'].idxmin(), :
              ]
  
          # cable distributor to divert from main branch
          lv_cable_dist = LVCableDistributorDing0(
              grid=lvgd.lv_grid,
              branch_no=branch_no,
              load_no=load_no)
          # add lv_cable_dist to graph
          lvgd.lv_grid.add_cable_dist(lv_cable_dist)
  
          # cable distributor within building (to connect load+geno)
          lv_cable_dist_building = LVCableDistributorDing0(
              grid=lvgd.lv_grid,
              branch_no=branch_no,
              load_no=load_no,
              in_building=True)
          # add lv_cable_dist_building to graph
          lvgd.lv_grid.add_cable_dist(lv_cable_dist_building)
  
          # create an instance of Ding0 LV load
          lv_load = LVLoadDing0(grid=lvgd.lv_grid,
                                branch_no=branch_no,
                                load_no=load_no,
                                peak_load=val['single_peak_load'],
                                consumption=val['consumption'])
  
          # add lv_load to graph
          lvgd.lv_grid.add_load(lv_load)
  
          # create branch line segment between either (a) station
          # and cable distributor or (b) between neighboring cable
          # distributors
          if load_no == 1:
              # case a: cable dist <-> station
              lvgd.lv_grid._graph.add_edge(
                  lvgd.lv_grid.station(),
                  lv_cable_dist,
                  branch=BranchDing0(
                      length=val['load_distance'],
                      kind='cable',
                      type=cable_type,
                      id_db='branch_{sector}{branch}_{load}'.format(
                          branch=branch_no,
                          load=load_no,
                          sector=sector_short)
                  ))
          else:
              # case b: cable dist <-> cable dist
              lvgd.lv_grid._graph.add_edge(
                  lvgd.lv_grid._cable_distributors[-4],
                  lv_cable_dist,
                  branch=BranchDing0(
                      length=val['load_distance'],
                      kind='cable',
                      type=cable_type,
                      id_db='branch_{sector}{branch}_{load}'.format(
                          branch=branch_no,
                          load=load_no,
                          sector=sector_short)))
  
          # create branch stub that connects the load to the
          # lv_cable_dist located in the branch line
          lvgd.lv_grid._graph.add_edge(
              lv_cable_dist,
              lv_cable_dist_building,
              branch=BranchDing0(
                  length=cfg_ding0.get(
                      'assumptions',
                      'lv_ria_branch_connection_distance'),
                  kind='cable',
                  type=cable_type_stub,
                  id_db='stub_{sector}{branch}_{load}'.format(
                      branch=branch_no,
                      load=load_no,
                      sector=sector_short))
          )
  
          lvgd.lv_grid._graph.add_edge(
              lv_cable_dist_building,
              lv_load,
              branch=BranchDing0(
                  length=1,
                  kind='cable',
                  type=cable_type_stub,
                  id_db='stub_{sector}{branch}_{load}'.format(
                      branch=branch_no,
                      load=load_no,
                      sector=sector_short))
          )
  
      cable_lf = cfg_ding0.get('assumptions',
                               'load_factor_lv_cable_lc_normal')
      cos_phi_load = cfg_ding0.get('assumptions',
                                   'cos_phi_load')
  
      # iterate over branches for sectors retail/industrial and agricultural
      for sector, val in grid_model_params.items():
          if sector == 'retail/industrial':
              sector_short = 'RETIND'
          elif sector == 'agricultural':
              sector_short = 'AGR'
          else:
              sector_short = ''
          if val is not None:
              for branch_no in list(range(1, val['full_branches'] + 1)):
  
                  # determine maximum current occuring due to peak load of branch
                  I_max_branch = (val['max_loads_per_branch'] *
                                  val['single_peak_load']) / (3 ** 0.5 * 0.4) / (
                      cos_phi_load)
  
                  # determine suitable cable for this current
                  suitable_cables = lvgd.lv_grid.network.static_data['LV_cables'][
                      (lvgd.lv_grid.network.static_data['LV_cables'][
                          'I_max_th'] * cable_lf) > I_max_branch]
                  cable_type = suitable_cables.loc[
                      suitable_cables['I_max_th'].idxmin(), :
                  ]
  
                  # create Ding0 grid objects and add to graph
                  for load_no in list(range(1, val['max_loads_per_branch'] + 1)):
                      # create a LV grid string and attached to station
                      lv_graph_attach_branch()
  
              # add remaining branch
              if val['remaining_loads'] > 0:
                  if 'branch_no' not in locals():
                      branch_no = 0
                  # determine maximum current occuring due to peak load of branch
                  I_max_branch = (val['max_loads_per_branch'] *
                                  val['single_peak_load']) / (3 ** 0.5 * 0.4) / (
                      cos_phi_load)
  
                  # determine suitable cable for this current
                  suitable_cables = lvgd.lv_grid.network.static_data['LV_cables'][
                      (lvgd.lv_grid.network.static_data['LV_cables'][
                          'I_max_th'] * cable_lf) > I_max_branch]
                  cable_type = suitable_cables.loc[
                      suitable_cables['I_max_th'].idxmin(), :
                  ]
  
                  branch_no += 1
  
                  for load_no in list(range(1, val['remaining_loads'] + 1)):
                      # create a LV grid string and attach to station
                      lv_graph_attach_branch()