Esempio n. 1
0
def save_net(best_net, path: str, format_='pickle'):
    """ Save pandapower network to some format. """
    filename = 'best_net'
    if format_ == 'pickle':
        pp.to_pickle(best_net, path + filename + '.p')
    elif format_ == 'json':
        pp.to_json(best_net, path + filename + '.json')
    else:
        print(f'File format "{format_}" not implemented yet!')
def deploiement_EV_freqreg(net,
                           dic_param_trajets,
                           profil_mob,
                           dic_nblois,
                           dic_tranchlois,
                           dic_parklois,
                           dic_dureelois,
                           dic_retourdom,
                           df_freq,
                           taux_penet=0.30,
                           p_evse_mw=0.01,
                           k_flotte=False):
    try:
        if k_flotte == True:
            raise UserWarning("")
        net_flotte = pp.from_pickle(
            os.path.join("construction_reseau", "data", "flotte.p"))
        net.storage = net_flotte.storage.copy()
        for control in net_flotte.controller.iterrows():
            control[1].controller.net = net
        net_flotte.controller['name'] = net_flotte.controller.controller.apply(
            lambda x: str(x))
        net.controller = pd.concat([
            net.controller, net_flotte.controller[
                net_flotte.controller.name.str.contains('EV')].drop(['name'],
                                                                    axis=1)
        ],
                                   ignore_index=True)
    except UserWarning:
        print("Calcul de la flotte...")
        nb_ev_fin = 0
        for x in net.load.itertuples():
            bus = x[2]
            p_noeud = x[3]
            nb_ev_max = int(p_noeud / 0.02)
            for i in range(nb_ev_max):
                if rand() <= taux_penet:
                    per = init_personne(dic_param_trajets, profil_mob,
                                        dic_nblois, dic_tranchlois,
                                        dic_parklois, dic_dureelois,
                                        dic_retourdom)
                    if rand() <= 0.2:
                        def_EV_QReg(net, bus, per.creer_df(), per)
                    else:
                        def_EV(net, bus,
                               pd.concat([per.creer_df(), df_freq], axis=1),
                               per)
                    nb_ev_fin += 1
        pp.to_pickle(net,
                     os.path.join("construction_reseau", "data", "flotte.p"))
        print(nb_ev_fin)
Esempio n. 3
0
def execute(app,
            path_src,
            path_dst,
            pv_as_slack,
            scale_feeder_loads=False,
            var_load='plini',
            var_gen='pgini',
            flag_graphics='GPS'):
    """
    Executes import of a .dgs file, runs load flow, and exports net as .p
    Args:
        path_src: full path to the input .dgs file
        path_dst: full path to the result .p file
        pv_as_slack: whether "PV" nodes are to be imported as "Slack
        scale_feeder_loads: whether loads are to be scaled according to feeder scaling factor

    Returns: net

    """
    logger.debug('started')
    echo_off(app)
    prj = import_project(path_src, app)

    logger.info('activating project')

    prj.Activate()
    trafo_name, trafo_desc = check_network(app)

    logger.info('gathering network elements')
    dict_net = create_network_dict(app, flag_graphics=flag_graphics)
    run_load_flow(app, scale_feeder_loads, gen_scaling=0)
    logger.info('exporting network to pandapower')
    app.SetAttributeModeInternal(1)
    net = from_pf(dict_net,
                  pv_as_slack=pv_as_slack,
                  pf_variable_p_loads=var_load,
                  pf_variable_p_gen=var_gen,
                  flag_graphics=flag_graphics)
    app.SetAttributeModeInternal(0)

    logger.info(net)

    prj.Deactivate()
    echo_on(app)

    pp.to_pickle(net, path_dst)

    return net, trafo_name, trafo_desc
Esempio n. 4
0
def test_pickle(net_in, tmp_path):
    filename = os.path.abspath(str(tmp_path)) + "testfile.p"
    pp.to_pickle(net_in, filename)
    net_out = pp.from_pickle(filename)
    assert_net_equal(net_in, net_out)
Esempio n. 5
0
def test_pickle(net_in, tempdir):
    filename = os.path.join(tempdir, "testfile.p")
    pp.to_pickle(net_in, filename)
    net_out = pp.from_pickle(filename)
    assert_net_equal(net_in, net_out)
Esempio n. 6
0
def test_pickle():
    net_in = create_test_network()
    pp.to_pickle(net_in, "testfile.p")
    net_out = pp.from_pickle("testfile.p")
    assert_net_equal(net_in, net_out)
    os.remove('testfile.p')