docs: def mv_to_pypsa(network):
      """Translate MV grid topology representation to PyPSA format
  
      MV grid topology translated here includes
  
      * MV station (no transformer, see :meth:`~.grid.network.EDisGo.analyze`)
      * Loads, Generators, Lines, Storages, Branch Tees of MV grid level as well
        as LV stations. LV stations do not have load and generation of LV level.
  
      Parameters
      ----------
      network : Network
          eDisGo grid container
  
      Returns
      -------
      dict of :pandas:`pandas.DataFrame<dataframe>`
          A DataFrame for each type of PyPSA components constituting the grid
          topology. Keys included
  
          * 'Generator'
          * 'Load'
          * 'Line'
          * 'BranchTee'
          * 'Transformer'
          * 'StorageUnit'
  
      .. warning::
  
          PyPSA takes resistance R and reactance X in p.u. The conversion from
          values in ohm to pu notation is performed by following equations
  
          .. math::
  
              r_{p.u.} = R_{\Omega} / Z_{B}
  
              x_{p.u.} = X_{\Omega} / Z_{B}
  
              with
  
              Z_{B} = V_B / S_B
  
          I'm quite sure, but its not 100 % clear if the base voltage V_B is
          chosen correctly. We take the primary side voltage of transformer as
          the transformers base voltage. See
          `#54 <https://github.com/openego/eDisGo/issues/54>`_ for discussion.
      """
  
      generators = network.mv_grid.generators
      loads = network.mv_grid.graph.nodes_by_attribute('load')
      branch_tees = network.mv_grid.graph.nodes_by_attribute('branch_tee')
      lines = network.mv_grid.graph.lines()
      lv_stations = network.mv_grid.graph.nodes_by_attribute('lv_station')
      mv_stations = network.mv_grid.graph.nodes_by_attribute('mv_station')
      disconnecting_points = network.mv_grid.graph.nodes_by_attribute(
          'mv_disconnecting_point')
      storages = network.mv_grid.graph.nodes_by_attribute(
          'storage')
  
      omega = 2 * pi * 50
  
      # define required dataframe columns for components
      generator = {'name': [],
                   'bus': [],
                   'control': [],
                   'p_nom': [],
                   'type': []}
  
      bus = {'name': [], 'v_nom': [], 'x': [], 'y': []}
  
      load = {'name': [], 'bus': []}
  
      line = {'name': [],
              'bus0': [],
              'bus1': [],
              'type': [],
              'x': [],
              'r': [],
              's_nom': [],
              'length': []}
  
      transformer = {'name': [],
                     'bus0': [],
                     'bus1': [],
                     'type': [],
                     'model': [],
                     'x': [],
                     'r': [],
                     's_nom': [],
                     'tap_ratio': []}
  
      storage = {
          'name': [],
          'bus': [],
          'p_nom': [],
          'state_of_charge_initial': [],
          'efficiency_store': [],
          'efficiency_dispatch': [],
          'standing_loss': []}
  
      # create dataframe representing generators and associated buses
      for gen in generators:
          bus_name = '_'.join(['Bus', repr(gen)])
          generator['name'].append(repr(gen))
          generator['bus'].append(bus_name)
          generator['control'].append('PQ')
          generator['p_nom'].append(gen.nominal_capacity / 1e3)
          generator['type'].append('_'.join([gen.type, gen.subtype]))
  
          bus['name'].append(bus_name)
          bus['v_nom'].append(gen.grid.voltage_nom)
          bus['x'].append(gen.geom.x)
          bus['y'].append(gen.geom.y)
  
      # create dataframe representing branch tees
      for bt in branch_tees:
          bus['name'].append('_'.join(['Bus', repr(bt)]))
          bus['v_nom'].append(bt.grid.voltage_nom)
          bus['x'].append(bt.geom.x)
          bus['y'].append(bt.geom.y)
  
      # create dataframes representing loads and associated buses
      for lo in loads:
          bus_name = '_'.join(['Bus', repr(lo)])
          load['name'].append(repr(lo))
          load['bus'].append(bus_name)
  
          bus['name'].append(bus_name)
          bus['v_nom'].append(lo.grid.voltage_nom)
          bus['x'].append(lo.geom.x)
          bus['y'].append(lo.geom.y)
  
      # create dataframe for lines
      for l in lines:
          line['name'].append(repr(l['line']))
  
          if l['adj_nodes'][0] in lv_stations:
              line['bus0'].append(
                  '_'.join(['Bus', l['adj_nodes'][0].__repr__(side='mv')]))
          else:
              line['bus0'].append('_'.join(['Bus', repr(l['adj_nodes'][0])]))
  
          if l['adj_nodes'][1] in lv_stations:
              line['bus1'].append(
                  '_'.join(['Bus', l['adj_nodes'][1].__repr__(side='mv')]))
          else:
              line['bus1'].append('_'.join(['Bus', repr(l['adj_nodes'][1])]))
  
          line['type'].append("")
          line['x'].append(
              l['line'].type['L'] / l['line'].quantity * omega / 1e3 *
              l['line'].length)
          line['r'].append(l['line'].type['R'] / l['line'].quantity *
                           l['line'].length)
          line['s_nom'].append(
              sqrt(3) * l['line'].type['I_max_th'] * l['line'].type['U_n'] *
              l['line'].quantity / 1e3)
          line['length'].append(l['line'].length)
  
      # create dataframe for LV stations incl. primary/secondary side bus
      for lv_st in lv_stations:
          transformer_count = 1
          # add primary side bus (bus0)
          bus0_name = '_'.join(['Bus', lv_st.__repr__(side='mv')])
          bus['name'].append(bus0_name)
          bus['v_nom'].append(lv_st.mv_grid.voltage_nom)
          bus['x'].append(lv_st.geom.x)
          bus['y'].append(lv_st.geom.y)
  
          # add secondary side bus (bus1)
          bus1_name = '_'.join(['Bus', lv_st.__repr__(side='lv')])
          bus['name'].append(bus1_name)
          bus['v_nom'].append(lv_st.transformers[0].voltage_op)
          bus['x'].append(None)
          bus['y'].append(None)
  
          # we choose voltage of transformers' primary side
          v_base = lv_st.mv_grid.voltage_nom
  
          for tr in lv_st.transformers:
              z_base = v_base ** 2 / tr.type.S_nom
              transformer['name'].append(
                  '_'.join([repr(lv_st), 'transformer', str(transformer_count)]))
              transformer['bus0'].append(bus0_name)
              transformer['bus1'].append(bus1_name)
              transformer['type'].append("")
              transformer['model'].append('pi')
              transformer['r'].append(tr.type.R / z_base)
              transformer['x'].append(tr.type.X / z_base)
              transformer['s_nom'].append(tr.type.S_nom / 1e3)
              transformer['tap_ratio'].append(1)
  
              transformer_count += 1
  
      # create dataframe for MV stations (only secondary side bus)
      for mv_st in mv_stations:
          # add secondary side bus (bus1)
          bus1_name = '_'.join(['Bus', mv_st.__repr__(side='mv')])
          bus['name'].append(bus1_name)
          bus['v_nom'].append(mv_st.transformers[0].voltage_op)
          bus['x'].append(mv_st.geom.x)
          bus['y'].append(mv_st.geom.y)
  
      # create dataframe representing disconnecting points
      for dp in disconnecting_points:
          bus['name'].append('_'.join(['Bus', repr(dp)]))
          bus['v_nom'].append(dp.grid.voltage_nom)
          bus['x'].append(dp.geom.x)
          bus['y'].append(dp.geom.y)
  
      # create dataframe representing storages
      for sto in storages:
          bus_name = '_'.join(['Bus', repr(sto)])
  
          storage['name'].append(repr(sto))
          storage['bus'].append(bus_name)
          storage['p_nom'].append(sto.nominal_power / 1e3)
          storage['state_of_charge_initial'].append(sto.soc_initial)
          storage['efficiency_store'].append(sto.efficiency_in)
          storage['efficiency_dispatch'].append(sto.efficiency_out)
          storage['standing_loss'].append(sto.standing_loss)
  
          bus['name'].append(bus_name)
          bus['v_nom'].append(sto.grid.voltage_nom)
          bus['x'].append(sto.geom.x)
          bus['y'].append(sto.geom.y)
  
      # Add separate slack generator at MV station secondary side bus bar
      generator['name'].append("Generator_slack")
      generator['bus'].append(bus1_name)
      generator['control'].append('Slack')
      generator['p_nom'].append(0)
      generator['type'].append('Slack generator')
  
      components = {
          'Generator': pd.DataFrame(generator).set_index('name'),
          'Bus': pd.DataFrame(bus).set_index('name'),
          'Load': pd.DataFrame(load).set_index('name'),
          'Line': pd.DataFrame(line).set_index('name'),
          'Transformer': pd.DataFrame(transformer).set_index('name'),
          'StorageUnit': pd.DataFrame(storage).set_index('name')}
  
      return components