docs: def extension_preselection(network, args, method, days = 3):
      
      """
      Function that preselects lines which are extendend in snapshots leading to 
      overloading to reduce nubmer of extension variables. 
      
      Parameters
      ----------
      network : :class:`pypsa.Network
          Overall container of PyPSA
      args  : dict
          Arguments set in appl.py
      method: str
          Choose method of selection:
          'extreme_situations' for remarkable timsteps 
          (e.g. minimal resiudual load)
          'snapshot_clustering' for snapshot clustering with number of days
      days: int
          Number of clustered days, only used when method = 'snapshot_clustering'
  
      Returns
      -------
      network : :class:`pypsa.Network
          Overall container of PyPSA
      """
  
      weighting = network.snapshot_weightings
  
      if method == 'extreme_situations':
          snapshots = find_snapshots(network, 'residual load')
          snapshots = snapshots.append(find_snapshots(network, 'wind_onshore'))
          snapshots = snapshots.append(find_snapshots(network, 'solar'))
          snapshots = snapshots.drop_duplicates()
          snapshots = snapshots.sort_values()
  
      if method == 'snapshot_clustering':
          network_cluster = snapshot_clustering(network, how='daily', 
                                                clusters=days)
          snapshots = network_cluster.snapshots
          network.snapshot_weightings = network_cluster.snapshot_weightings
  
      # Set all lines and trafos extendable in network
      network.lines.loc[:, 's_nom_extendable'] = True
      network.lines.loc[:, 's_nom_min'] = network.lines.s_nom
      network.lines.loc[:, 's_nom_max'] = np.inf
      
      network.links.loc[:, 'p_nom_extendable'] = True
      network.links.loc[:, 'p_nom_min'] = network.links.p_nom
      network.links.loc[:, 'p_nom_max'] = np.inf
  
      network.transformers.loc[:, 's_nom_extendable'] = True
      network.transformers.loc[:, 's_nom_min'] = network.transformers.s_nom
      network.transformers.loc[:, 's_nom_max'] = np.inf
  
      network = set_line_costs(network)
      network = set_trafo_costs(network)
      network = convert_capital_costs(network, 1, 1)
      extended_lines = network.lines.index[network.lines.s_nom_opt >
                                           network.lines.s_nom]
      extended_links = network.links.index[network.links.p_nom_opt >
                                           network.links.p_nom]
  
      x = time.time()
      for i in range(int(snapshots.value_counts().sum())):
          if i > 0:
              network.lopf(snapshots[i], solver_name=args['solver'])
              extended_lines = extended_lines.append(
                      network.lines.index[network.lines.s_nom_opt >
                                          network.lines.s_nom])
              extended_lines = extended_lines.drop_duplicates()
              extended_links = extended_links.append(
                      network.links.index[network.links.p_nom_opt >
                                          network.links.p_nom])
              extended_links = extended_links.drop_duplicates()
  
      print("Number of preselected lines: ", len(extended_lines))
  
      network.lines.loc[~network.lines.index.isin(extended_lines),
                        's_nom_extendable'] = False
      network.lines.loc[network.lines.s_nom_extendable, 's_nom_min']\
          = network.lines.s_nom
      network.lines.loc[network.lines.s_nom_extendable, 's_nom_max']\
          = np.inf
          
      network.links.loc[~network.links.index.isin(extended_links),
                        'p_nom_extendable'] = False
      network.links.loc[network.links.p_nom_extendable, 'p_nom_min']\
          = network.links.p_nom
      network.links.loc[network.links.p_nom_extendable, 'p_nom_max']\
          = np.inf
  
      network.snapshot_weightings = weighting
      network = set_line_costs(network)
      network = set_trafo_costs(network)
      network = convert_capital_costs(network, args['start_snapshot'],
                                      args['end_snapshot'])
  
      y = time.time()
      z1st = (y - x) / 60
  
      print("Time for first LOPF [min]:", round(z1st, 2))
  
      return network