def busmap_from_psql(network, session, scn_name):
    """ Retrieves busmap from `model_draft.ego_grid_pf_hv_busmap` on the
    <OpenEnergyPlatform>[www.openenergy-platform.org] by a given scenario
    name. If this busmap does not exist, it is created with default values.

    Parameters
    ----------
    network : pypsa.Network object
        Container for all network components.

    session : sqlalchemy.orm.session.Session object
        Establishes interactions with the database.

    scn_name : str
        Name of the scenario.

    Returns
    -------
    busmap : dict
        Maps old bus_ids to new bus_ids.
    """

    def fetch():

        query = session.query(EgoGridPfHvBusmap.bus0, EgoGridPfHvBusmap.bus1).\
            filter(EgoGridPfHvBusmap.scn_name == scn_name)

        return dict(query.all())

    busmap = fetch()

    # TODO: Or better try/except/finally
    if not busmap:
        print('Busmap does not exist and will be created.\n')

        cpu_cores = input('cpu_cores (default 4): ') or '4'

        busmap_by_shortest_path(network, session, scn_name,
                                fromlvl=[110], tolvl=[220, 380, 400, 450],
                                cpu_cores=int(cpu_cores))
        busmap = fetch()

    return busmap
def busmap_from_psql ( network , session , scn_name ) : def fetch ( ) : query = session . query ( EgoGridPfHvBusmap . bus0 , EgoGridPfHvBusmap . bus1 ) . filter ( EgoGridPfHvBusmap . scn_name == scn_name ) return dict ( query . all ( ) ) busmap = fetch ( ) if not busmap : print ( 'Busmap does not exist and will be created.\n' ) cpu_cores = input ( 'cpu_cores (default 4): ' ) or '4' busmap_by_shortest_path ( network , session , scn_name , fromlvl = [ 110 ] , tolvl = [ 220 , 380 , 400 , 450 ] , cpu_cores = int ( cpu_cores ) ) busmap = fetch ( ) return busmap
Retrieves busmap from `model_draft.ego_grid_pf_hv_busmap` on the
    <OpenEnergyPlatform>[www.openenergy-platform.org] by a given scenario
    name. If this busmap does not exist, it is created with default values.

    Parameters
    ----------
    network : pypsa.Network object
        Container for all network components.

    session : sqlalchemy.orm.session.Session object
        Establishes interactions with the database.

    scn_name : str
        Name of the scenario.

    Returns
    -------
    busmap : dict
        Maps old bus_ids to new bus_ids.