def extendable(network, args, line_max):

    """
    Function that sets selected components extendable

    'network' for all lines, links and transformers
    'german_network' for all lines, links and transformers located in Germany
    'foreign_network' for all foreign lines, links and transformers
    'transformers' for all transformers
    'storages' for extendable storages
    'overlay_network' for lines, links and trafos in extension scenerio(s)
    
    Parameters
    ----------
    network : :class:`pypsa.Network
        Overall container of PyPSA
    args  : dict
        Arguments set in appl.py


    Returns
    -------
    network : :class:`pypsa.Network
        Overall container of PyPSA
    """

    if 'network' in args['extendable']:
        network.lines.s_nom_extendable = True
        network.lines.s_nom_min = network.lines.s_nom
        
        if not line_max==None:
            network.lines.s_nom_max = line_max * network.lines.s_nom
        
        else:
            network.lines.s_nom_max = float("inf")

        if not network.transformers.empty:
            network.transformers.s_nom_extendable = True
            network.transformers.s_nom_min = network.transformers.s_nom

            if not line_max==None:
                network.transformers.s_nom_max =\
                line_max * network.transformers.s_nom
                
            else:
                network.transformers.s_nom_max = float("inf")

        if not network.links.empty:
            network.links.p_nom_extendable = True
            network.links.p_nom_min = network.links.p_nom
            network.links.p_nom_max = float("inf")
            if not line_max==None:
                network.links.p_nom_max=\
                line_max * network.links.p_nom
                
            else:
                network.links.p_nom_max = float("inf")

        network = set_line_costs(network, args)
        network = set_trafo_costs(network, args)

    if 'german_network' in args['extendable']:
        buses = network.buses[~network.buses.index.isin(
                buses_by_country(network).index)]
        network.lines.loc[(network.lines.bus0.isin(buses.index)) &
                          (network.lines.bus1.isin(buses.index)),
                          's_nom_extendable'] = True
        network.lines.loc[(network.lines.bus0.isin(buses.index)) &
                          (network.lines.bus1.isin(buses.index)),
                          's_nom_min'] = network.lines.s_nom
        network.lines.loc[(network.lines.bus0.isin(buses.index)) &
                          (network.lines.bus1.isin(buses.index)),
                          's_nom_max'] = float("inf")
        
        if not line_max==None:
            network.lines.loc[(network.lines.bus0.isin(buses.index)) &
                    (network.lines.bus1.isin(buses.index)),
                    's_nom_max'] = line_max * network.lines.s_nom
        
        else:
            network.lines.loc[(network.lines.bus0.isin(buses.index)) &
                    (network.lines.bus1.isin(buses.index)),
                    's_nom_max'] = float("inf")

        if not network.transformers.empty:
            network.transformers.loc[network.transformers.bus0.isin(
                    buses.index),'s_nom_extendable'] = True
            network.transformers.loc[network.transformers.bus0.isin(
                    buses.index),'s_nom_min'] = network.transformers.s_nom
                
            if not line_max==None:
                network.transformers.loc[network.transformers.bus0.isin(
                    buses.index),'s_nom_max'] = \
                line_max * network.transformers.s_nom
                
            else:
                network.transformers.loc[network.transformers.bus0.isin(
                    buses.index),'s_nom_max'] = float("inf")

        if not network.links.empty:
            network.links.loc[(network.links.bus0.isin(buses.index)) &
                              (network.links.bus1.isin(buses.index)),
                              'p_nom_extendable'] = True
            network.links.loc[(network.links.bus0.isin(buses.index)) &
                              (network.links.bus1.isin(buses.index)),
                          'p_nom_min'] = network.links.p_nom

            if not line_max==None:
                network.links.loc[(network.links.bus0.isin(buses.index)) &
                        (network.links.bus1.isin(buses.index)),
                          'p_nom_max'] = line_max * network.links.p_nom
                
            else:
                network.links.loc[(network.links.bus0.isin(buses.index)) &
                        (network.links.bus1.isin(buses.index)),
                          'p_nom_max'] = float("inf")
            
        network = set_line_costs(network, args)
        network = set_trafo_costs(network, args)

    if 'foreign_network' in args['extendable']:
        buses = network.buses[network.buses.index.isin(
                buses_by_country(network).index)]
        network.lines.loc[network.lines.bus0.isin(buses.index) |
                          network.lines.bus1.isin(buses.index) ,
                          's_nom_extendable'] = True
        network.lines.loc[network.lines.bus0.isin(buses.index) |
                          network.lines.bus1.isin(buses.index),
                          's_nom_min'] = network.lines.s_nom

        if not line_max==None:
            network.lines.loc[network.lines.bus0.isin(buses.index) |
                          network.lines.bus1.isin(buses.index),
                    's_nom_max'] = line_max * network.lines.s_nom
        
        else:
            network.lines.loc[network.lines.bus0.isin(buses.index) |
                          network.lines.bus1.isin(buses.index),
                    's_nom_max'] = float("inf")
        
        if not network.transformers.empty:
            network.transformers.loc[network.transformers.bus0.isin(
                    buses.index) | network.transformers.bus1.isin(
                    buses.index) ,'s_nom_extendable'] = True
            network.transformers.loc[network.transformers.bus0.isin(
                    buses.index) | network.transformers.bus1.isin(
                    buses.index) ,'s_nom_min'] = network.transformers.s_nom

            if not line_max==None:
                network.transformers.loc[network.transformers.bus0.isin(
                    buses.index) | network.transformers.bus1.isin(
                    buses.index),'s_nom_max'] = \
                line_max * network.transformers.s_nom
                
            else:
                network.transformers.loc[network.transformers.bus0.isin(
                    buses.index) | network.transformers.bus1.isin(
                    buses.index),'s_nom_max'] = float("inf")

        if not network.links.empty:
            network.links.loc[(network.links.bus0.isin(buses.index)) |
                              (network.links.bus1.isin(buses.index)),
                          'p_nom_extendable'] = True
            network.links.loc[(network.links.bus0.isin(buses.index)) |
                              (network.links.bus1.isin(buses.index)),
                          'p_nom_min'] = network.links.p_nom
            
            if not line_max==None:
                network.links.loc[(network.links.bus0.isin(buses.index)) |
                              (network.links.bus1.isin(buses.index)),
                          'p_nom_max'] = line_max * network.links.p_nom
                
            else:
                network.links.loc[(network.links.bus0.isin(buses.index)) |
                              (network.links.bus1.isin(buses.index)),
                          'p_nom_max'] = float("inf")
            
        network = set_line_costs(network, args)
        network = set_trafo_costs(network, args)

    if 'transformers' in args['extendable']:
        network.transformers.s_nom_extendable = True
        network.transformers.s_nom_min = network.transformers.s_nom
        network.transformers.s_nom_max = float("inf")
        network = set_trafo_costs(network)

    if 'storages' in args['extendable'] or 'storage' in args['extendable']:
        if network.storage_units.\
            carrier[network.
                    storage_units.carrier ==
                    'extendable_storage'].any() == 'extendable_storage':
            network.storage_units.loc[network.storage_units.carrier ==
                                      'extendable_storage',
                                      'p_nom_extendable'] = True

    if 'generators' in args['extendable']:
        network.generators.p_nom_extendable = True
        network.generators.p_nom_min = network.generators.p_nom
        network.generators.p_nom_max = float("inf")
        
    if 'foreign_storage' in args['extendable']:
        network.storage_units.p_nom_extendable[(network.storage_units.bus.isin(
                network.buses.index[network.buses.country_code != 'DE'])) & (
                network.storage_units.carrier.isin(
                        ['battery_storage','hydrogen_storage'] ))] = True

        network.storage_units.loc[
                network.storage_units.p_nom_max.isnull(),'p_nom_max'] = \
                network.storage_units.p_nom

        network.storage_units.loc[
                (network.storage_units.carrier == 'battery_storage'),
                'capital_cost'] = network.storage_units.loc[(
                network.storage_units.carrier == 'extendable_storage') 
                & (network.storage_units.max_hours == 6),'capital_cost'].max()

        network.storage_units.loc[ 
                (network.storage_units.carrier == 'hydrogen_storage'),
                'capital_cost'] = network.storage_units.loc[(
                network.storage_units.carrier == 'extendable_storage') &
                (network.storage_units.max_hours == 168),'capital_cost'].max()

        network.storage_units.loc[
                (network.storage_units.carrier == 'battery_storage'),
                'marginal_cost'] = network.storage_units.loc[(
                network.storage_units.carrier == 'extendable_storage') 
                & (network.storage_units.max_hours == 6),'marginal_cost'].max()

        network.storage_units.loc[
                (network.storage_units.carrier == 'hydrogen_storage'),
                'marginal_cost'] = network.storage_units.loc[(
                network.storage_units.carrier == 'extendable_storage') &
                (network.storage_units.max_hours == 168),'marginal_cost'].max()


    # Extension settings for extension-NEP 2035 scenarios
    if 'NEP Zubaunetz' in args['extendable']:
        for i in range(len(args['scn_extension'])):
            network.lines.loc[(network.lines.project != 'EnLAG') & (
            network.lines.scn_name == 'extension_' + args['scn_extension'][i]),
            's_nom_extendable'] = True

            network.transformers.loc[(
                    network.transformers.project != 'EnLAG') & (
                            network.transformers.scn_name == (
                                    'extension_'+ args['scn_extension'][i])),
                                        's_nom_extendable'] = True

            network.links.loc[network.links.scn_name == (
            'extension_' + args['scn_extension'][i]
            ), 'p_nom_extendable'] = True

    if 'overlay_network' in args['extendable']:
        for i in range(len(args['scn_extension'])):
            network.lines.loc[network.lines.scn_name == (
            'extension_' + args['scn_extension'][i]
            ), 's_nom_extendable'] = True
                
            network.lines.loc[network.lines.scn_name == (
            'extension_' + args['scn_extension'][i]
            ), 's_nom_max'] = network.lines.s_nom[network.lines.scn_name == (
            'extension_' + args['scn_extension'][i])]
                
            network.links.loc[network.links.scn_name == (
            'extension_' + args['scn_extension'][i]
            ), 'p_nom_extendable'] = True
                
            network.transformers.loc[network.transformers.scn_name == (
            'extension_' + args['scn_extension'][i]
            ), 's_nom_extendable'] = True
                
            network.lines.loc[network.lines.scn_name == (
            'extension_' + args['scn_extension'][i]
            ), 'capital_cost'] = network.lines.capital_cost/\
                args['branch_capacity_factor']['eHV']   

    if 'overlay_lines' in args['extendable']:
        for i in range(len(args['scn_extension'])):
            network.lines.loc[network.lines.scn_name == (
            'extension_' + args['scn_extension'][i]
            ), 's_nom_extendable'] = True
                
            network.links.loc[network.links.scn_name == (
            'extension_' + args['scn_extension'][i]
            ), 'p_nom_extendable'] = True
                
            network.lines.loc[network.lines.scn_name == (
            'extension_' + args['scn_extension'][i]),
                'capital_cost'] = network.lines.capital_cost + (2 * 14166)

    network.lines.s_nom_min[network.lines.s_nom_extendable == False] =\
        network.lines.s_nom

    network.transformers.s_nom_min[network.transformers.s_nom_extendable == \
        False] = network.transformers.s_nom
                       
    network.lines.s_nom_max[network.lines.s_nom_extendable == False] =\
        network.lines.s_nom

    network.transformers.s_nom_max[network.transformers.s_nom_extendable == \
        False] = network.transformers.s_nom

    return network
Function that sets selected components extendable

    'network' for all lines, links and transformers
    'german_network' for all lines, links and transformers located in Germany
    'foreign_network' for all foreign lines, links and transformers
    'transformers' for all transformers
    'storages' for extendable storages
    'overlay_network' for lines, links and trafos in extension scenerio(s)
    
    Parameters
    ----------
    network : :class:`pypsa.Network
        Overall container of PyPSA
    args  : dict
        Arguments set in appl.py


    Returns
    -------
    network : :class:`pypsa.Network
        Overall container of PyPSA