docs: def process_pfa_results(network, pypsa, timesteps):
      """
      Assing values from PyPSA to
      :meth:`results <edisgo.grid.network.Network.results>`
  
      Parameters
      ----------
      network : Network
          The eDisGo grid topology model overall container
      pypsa : :pypsa:`pypsa.Network<network>`
          The PyPSA `Network container
          <https://www.pypsa.org/doc/components.html#network>`_
      timesteps : :pandas:`pandas.DatetimeIndex<datetimeindex>` or :pandas:`pandas.Timestamp<timestamp>`
          Time steps for which latest power flow analysis was conducted for and
          for which to retrieve pypsa results.
  
      Notes
      -----
      P and Q (and respectively later S) are returned from the line ending/
      transformer side with highest apparent power S, exemplary written as
  
      .. math::
          S_{max} = max(\sqrt{P0^2 + Q0^2}, \sqrt{P1^2 + Q1^2})
          P = P0P1(S_{max})
          Q = Q0Q1(S_{max})
  
      See Also
      --------
      :class:`~.grid.network.Results`
          Understand how results of power flow analysis are structured in eDisGo.
  
      """
      # get the absolute losses in the system
      # subtracting total generation (including slack) from total load
      grid_losses = {'p': 1e3 * (pypsa.generators_t['p'].sum(axis=1) -
                                 pypsa.loads_t['p'].sum(axis=1)),
                     'q': 1e3 * (pypsa.generators_t['q'].sum(axis=1) -
                                 pypsa.loads_t['q'].sum(axis=1))}
  
      network.results.grid_losses = pd.DataFrame(grid_losses).loc[timesteps, :]
  
      # get slack results
      grid_exchanges = {'p': 1e3 * (pypsa.generators_t['p']['Generator_slack']),
                        'q': 1e3 * (pypsa.generators_t['q']['Generator_slack'])}
  
      network.results.hv_mv_exchanges = pd.DataFrame(grid_exchanges).loc[timesteps, :]
  
      # get p and q of lines, LV transformers and MV Station (slack generator)
      # in absolute values
      q0 = pd.concat(
          [np.abs(pypsa.lines_t['q0']),
           np.abs(pypsa.transformers_t['q0']),
           np.abs(pypsa.generators_t['q']['Generator_slack'].rename(
               repr(network.mv_grid.station)))], axis=1).loc[timesteps, :]
      q1 = pd.concat(
          [np.abs(pypsa.lines_t['q1']),
           np.abs(pypsa.transformers_t['q1']),
           np.abs(pypsa.generators_t['q']['Generator_slack'].rename(
               repr(network.mv_grid.station)))], axis=1).loc[timesteps, :]
      p0 = pd.concat(
          [np.abs(pypsa.lines_t['p0']),
           np.abs(pypsa.transformers_t['p0']),
           np.abs(pypsa.generators_t['p']['Generator_slack'].rename(
              repr(network.mv_grid.station)))], axis=1).loc[timesteps, :]
      p1 = pd.concat(
          [np.abs(pypsa.lines_t['p1']),
           np.abs(pypsa.transformers_t['p1']),
           np.abs(pypsa.generators_t['p']['Generator_slack'].rename(
               repr(network.mv_grid.station)))], axis=1).loc[timesteps, :]
  
      # determine apparent power and line endings/transformers' side
      s0 = np.hypot(p0, q0)
      s1 = np.hypot(p1, q1)
  
      # choose p and q from line ending with max(s0,s1)
      network.results.pfa_p = p0.where(s0 > s1, p1) * 1e3
      network.results.pfa_q = q0.where(s0 > s1, q1) * 1e3
  
      lines_bus0 = pypsa.lines['bus0'].to_dict()
      bus0_v_mag_pu = pypsa.buses_t['v_mag_pu'].T.loc[
                      list(lines_bus0.values()), :].copy()
      bus0_v_mag_pu.index = list(lines_bus0.keys())
  
      lines_bus1 = pypsa.lines['bus1'].to_dict()
      bus1_v_mag_pu = pypsa.buses_t['v_mag_pu'].T.loc[
                      list(lines_bus1.values()), :].copy()
      bus1_v_mag_pu.index = list(lines_bus1.keys())
  
      line_voltage_avg = 0.5 * (bus0_v_mag_pu.loc[:, timesteps] +
                                bus1_v_mag_pu.loc[:, timesteps])
  
      # Get voltage levels at line (avg. of buses at both sides)
      network.results._i_res = \
          network.results.s_res()[pypsa.lines_t['q0'].columns].truediv(
              pypsa.lines['v_nom'] * line_voltage_avg.T,
              axis='columns') * sqrt(3)
      # process results at nodes
      generators_names = [repr(g) for g in network.mv_grid.generators]
      generators_mapping = {v: k for k, v in
                            pypsa.generators.loc[generators_names][
                                'bus'].to_dict().items()}
      storages_names = [repr(g) for g in
                        network.mv_grid.graph.nodes_by_attribute('storage')]
      storages_mapping = {v: k for k, v in
                          pypsa.storage_units.loc[storages_names][
                              'bus'].to_dict().items()}
      branch_t_names = [repr(bt) for bt in
                        network.mv_grid.graph.nodes_by_attribute('branch_tee')]
      branch_t_mapping = {'_'.join(['Bus', v]): v for v in branch_t_names}
      mv_station_names = [repr(m) for m in
                          network.mv_grid.graph.nodes_by_attribute('mv_station')]
      mv_station_mapping_sec = {'_'.join(['Bus', v]): v for v in
                                mv_station_names}
      mv_switch_disconnector_names = [repr(sd) for sd in
                                      network.mv_grid.graph.nodes_by_attribute(
                                          'mv_disconnecting_point')]
      mv_switch_disconnector_mapping = {'_'.join(['Bus', v]): v for v in
                                        mv_switch_disconnector_names}
  
      lv_station_mapping_pri = {
          '_'.join(['Bus', l.__repr__('mv')]): repr(l)
          for l in network.mv_grid.graph.nodes_by_attribute('lv_station')}
      lv_station_mapping_sec = {
          '_'.join(['Bus', l.__repr__('lv')]): repr(l)
          for l in network.mv_grid.graph.nodes_by_attribute('lv_station')}
      loads_names = [repr(lo) for lo in
                     network.mv_grid.graph.nodes_by_attribute('load')]
      loads_mapping = {v: k for k, v in
                       pypsa.loads.loc[loads_names][
                           'bus'].to_dict().items()}
  
      lv_generators_names = []
      lv_storages_names = []
      lv_branch_t_names = []
      lv_loads_names = []
      for lv_grid in network.mv_grid.lv_grids:
          lv_generators_names.extend([repr(g) for g in
                                      lv_grid.graph.nodes_by_attribute(
                                          'generator')])
          lv_storages_names.extend([repr(g) for g in
                                    lv_grid.graph.nodes_by_attribute(
                                        'storage')])
          lv_branch_t_names.extend([repr(bt) for bt in
                               lv_grid.graph.nodes_by_attribute('branch_tee')])
          lv_loads_names.extend([repr(lo) for lo in
                            lv_grid.graph.nodes_by_attribute('load')])
  
      lv_generators_mapping = {v: k for k, v in
                               pypsa.generators.loc[lv_generators_names][
                                   'bus'].to_dict().items()}
      lv_storages_mapping = {v: k for k, v in
                             pypsa.storage_units.loc[lv_storages_names][
                                 'bus'].to_dict().items()}
      lv_branch_t_mapping = {'_'.join(['Bus', v]): v for v in lv_branch_t_names}
      lv_loads_mapping = {v: k for k, v in pypsa.loads.loc[lv_loads_names][
          'bus'].to_dict().items()}
  
      names_mapping = {
          **generators_mapping,
          **storages_mapping,
          **branch_t_mapping,
          **mv_station_mapping_sec,
          **lv_station_mapping_pri,
          **lv_station_mapping_sec,
          **mv_switch_disconnector_mapping,
          **loads_mapping,
          **lv_generators_mapping,
          **lv_storages_mapping,
          **lv_loads_mapping,
          **lv_branch_t_mapping
      }
  
      # write voltage levels obtained from power flow to results object
      pfa_v_mag_pu_mv = (pypsa.buses_t['v_mag_pu'][
          list(generators_mapping) +
          list(storages_mapping) +
          list(branch_t_mapping) +
          list(mv_station_mapping_sec) +
          list(mv_switch_disconnector_mapping) +
          list(lv_station_mapping_pri) +
          list(loads_mapping)]).rename(columns=names_mapping)
      pfa_v_mag_pu_lv = (pypsa.buses_t['v_mag_pu'][
          list(lv_station_mapping_sec) +
          list(lv_generators_mapping) +
          list(lv_storages_mapping) +
          list(lv_branch_t_mapping) +
          list(lv_loads_mapping)]).rename(columns=names_mapping)
      network.results.pfa_v_mag_pu = pd.concat(
          {'mv': pfa_v_mag_pu_mv.loc[timesteps, :],
           'lv': pfa_v_mag_pu_lv.loc[timesteps, :]}, axis=1)