Esempio n. 1
0
    def get_bridges(self):
        res = []
        if self.G.is_multigraph():
            raise NotImplementedError("Multi Graph not supported.")
        else:
            for b in nx.bridges(self.G):
                if self.G.edges[b].get('amount', 0) == 1:
                    res.append(b)
        return res


if __name__ == '__main__':
    from core.power import Power
    path = 'D:/PSA_src/psa/localdata/0913/data'
    fmt = 'on'
    power = Power(fmt)
    power.load_power(path, fmt=fmt, lp=False, st=False)
    with timer("graph"):
        graph1 = PowerGraph(power,
                            graph_type='single',
                            node_type='station',
                            on_only=True)
        islands1 = graph1.get_islands(5)
        graph2 = PowerGraph(power,
                            graph_type='multi',
                            node_type='bus',
                            on_only=False,
                            edge_columns=['x'])
        islands2 = graph2.get_islands(10)
Esempio n. 2
0
    def set_index(self, types=None, idx='no'):
        """ 设置表索引

        :param types: list. 需要设置的设备类型。
        :param idx: str, no or name. 按编号设置或按名称设置。
        """
        if not types:
            types = self.format_key['types']
        if idx == 'no':
            indices = self.index_dict
        elif idx == 'name':
            indices = name_index_dict()
        else:
            raise NotImplementedError
        types = [t for t in types if t in indices.keys() and t in self.data.keys()]
        for t in types:
            self.data[t].set_index(indices[t], drop=False, inplace=True)


if __name__ == '__main__':
    # set_format_version({'mdc': 2.3})
    path = 'D:/PSA_src/psa/localdata/0913/data'
    fmt = 'on'
    path = 'D:/PSASP_Pro/2020国调年度/冬低731'
    fmt = 'off'
    power = Power(fmt)
    with timer('Load power'):
        power.load_power(path, fmt=fmt, lp=False, st=True, station=False)
    with timer('Save power'):
        power.save_power(path + '/out', lp=False, st=True, fmt=fmt)
Esempio n. 3
0
                                            dt_train_end=dt_train_end,
                                            dt_test_begin=dt_test_begin,
                                            dt_test_end=dt_test_end,
                                            val_perc=0.1)
        assert (0 in ids) and (1 in ids)
        data_set.make_dataset_tensors(y_columns=y_columns, only_real=only_real)
        train_data, train_labels, _ = data_set.get_dataset(0)
        train_sample_size = train_labels.shape[0]
        steps_per_epoch = train_sample_size // n_batch
        val_data, val_labels, _ = data_set.get_dataset(1)
        val_sample_size = val_labels.shape[0]
        validation_steps = val_sample_size // n_batch
        train_gen = data_set.dataset_generator_multi(train_data, train_labels, n_batch)
        val_gen = data_set.dataset_generator_multi(val_data, val_labels, n_batch)
        dt_run_start = datetime.datetime.now()
        with timer("Timer training"):
            history = net.train_model.fit_generator(train_gen,
                                                    epochs=n_epochs,
                                                    steps_per_epoch=steps_per_epoch,
                                                    validation_data=val_gen,
                                                    validation_steps=validation_steps)
        test_labels, pre = dataset_predict(net.pre_model, data_set, role=2)
        save_model(res_path, args.res_type, net.pre_model, suffix='pb')
        # save_model(res_path, args.res_type, net.pre_model, suffix='json')
        write_input(data_set, res_path + "/input.txt")
        write_output(data_set.y.columns[y_columns], res_path + "/output.txt")
        sys.exit(0)

    net.pre_model.load_weights(res_path + "/" + args.res_type + ".h5")
    dt_begin = datetime.datetime.strptime(args.dt_begin, "%Y_%m_%dT%H_%M_%S")
    dt_end = datetime.datetime.strptime(args.dt_end, "%Y_%m_%dT%H_%M_%S") \
Esempio n. 4
0
                    if max_idx >= len(subs):
                        abbr = name
                    else:
                        abbr = ''.join([subs[i] for i in name_info[k][1]])
                    fp.write(' '.join((abbr, name)) + '\n')
            else:
                fp.write('name\n')
                fp.write('\n'.join(names) + '\n')


if __name__ == '__main__':

    # '''
    file_name = os.path.join(os.path.expanduser('~'), 'data', 'gd', 'E', 'gd_20200729_1300_new.QS')
    # table_names = ['Grid', 'Station', 'Bus']
    with timer('Read E File repeat'):
        tables = read_efile(file_name)
    # with timer('Read E File buffer'):
    #     tables = read_efile_buffer(file_name)
    # '''

    '''
    path = 'D:/python/db/2019_09_12/2019_10_01T01_20_00/'
    headers = {'CCTOUT': 'no desc name cct gen1 gen2 times tmp1 tmp2'}
    update_table_header(path, 'res', headers)
    '''

    '''
    e_file = os.path.join(os.path.expanduser('~'), 'data', 'bj', 'BJ_20200420_000000.QS')
    out_file = os.path.join(os.path.expanduser('~'), 'data', 'bj', 'names.txt')
    name_info = {'Substation': ('name', [1]),
Esempio n. 5
0
def get_model_name(model_type, model_no):
    model_type = model_type.lower()
    if model_type == "avr":
        if model_no in range(3, 11):
            return 'avr310' if 'avr310' in datalib_columns else None
        elif model_no in range(11, 13):
            return 'avr1112' if 'avr1112' in datalib_columns else None
    if model_type in datalib_columns:
        return model_type
    elif model_type + str(model_no) in datalib_columns:
        return model_type + str(model_no)
    return None


if __name__ == '__main__':
    from core.power import Power
    path = 'D:/PSASP_Pro/2020¹úµ÷Äê¶È/¶¬µÍ731'
    fmt = 'off'
    power = Power(fmt)
    power.load_power(path, fmt=fmt, lp=False, st=True, station=True)
    with timer('Load datalib'):
        datalib = load_datalib(path+'/DATALIB.DAT')
    iwant = [('gen', 3, 11),
             ('avr', 12, 18),
             ('gov', 7, 3),
             ('pss', 2, 7)]
    for t, m, p in iwant:
        name = get_model_name(t, m)
        if name is not None:
            print(datalib[name].loc[p])
Esempio n. 6
0
    RGG = rypb.loc[no_gen, no_gen]
    gk = np.zeros((len(indices), len(no_gen)), dtype=np.float32)
    for ii, idx in enumerate(indices):
        if np.isin(idx, no_load):
            gk[ii, :] = RDG.loc[idx]
        elif np.isin(idx, no_gen):
            gk[ii, :] = RGG.loc[idx]
        else:
            print(idx, "is slackbus")

    gk = pd.DataFrame(gk, index=indices, columns=no_gen)
    return gk


if __name__ == '__main__':
    from core.power import Power

    # path = '../dataset/wepri36'
    # fmt = 'off'
    path = 'C:/Users/sdy/data/db/SA_2'
    fmt = 'on'
    power = Power(fmt)
    with timer('gsdf'):
        power.load_power(path, fmt=fmt, lp=False, st=False)
        # ed = calc_ed_from_power(power, island=0, node_type='bus', x_only=False)
        # gkr = calc_gsdf(power, 0, {'acline':[29, 44]})
        gkr = calc_gsdf(power, 0, {'acline': [ 10547, 10317, 10373, 11136],
                                   'transformer': [51188]}, alpha= 'zwt', node_type='station')
        vps = calc_vps(power, 0, {'bus': [878, 914]}, 'bus')

Esempio n. 7
0
            buffer = StringIO()
            with open(os.path.join(root, f), 'r') as fp:
                for line in fp:
                    buffer.write(line)
                    if line[0] == '<' and line[1] != '/':
                        table = line[1:line.index(':')]
                        if table in headers:
                            buffer.write('@ ' + headers[table] + '\n')
                            fp.readline()
            with open(os.path.join(root, f), 'w') as fp:
                buffer.seek(0)
                for line in buffer:
                    fp.write(line)
        i = i + 1
        if i % 100 == 0:
            print('\r%dfiles updated.' % i, end='')


if __name__ == '__main__':
    file_name = 'D:/PSASP_Pro/2020¹úµ÷Äê¶È/¶¬µÍ731/DataMap.txt'
    table_names = ['Grid', 'Station', 'Bus']
    with timer('Read E File repeat'):
        tables = read_efile(file_name)
    with timer('Read E File buffer'):
        tables = read_efile_buffer(file_name)


    path = 'D:/python/db/2019_09_12/2019_10_01T01_20_00/'
    headers = {'CCTOUT': 'no desc name cct gen1 gen2 times tmp1 tmp2'}
    update_table_header(path, 'res', headers)
Esempio n. 8
0
    return res


if __name__ == '__main__':
    path = 'D:/PSASP_Pro/online/package'
    file_name = 'pack.h5'
    fmt = 'on'
    """
    with timer('Pack power'):
        pack_data(path, os.path.join(path, file_name), fmt='on')
    with timer('Get infos of package'):
        model, data = get_package_info(os.path.join(path, file_name))
    print(model, data)
    dir = '2019_12_23T13_10_00'
    with timer('Unpack power'):
        unpack_data(os.path.join(path, 'out'),
                    os.path.join(path, file_name), fmt='on', dirs=[dir])
    """

    path = 'D:/python/db/2019_09_12/data/'
    iwant = {'generator': ['p', 'v'], 'station': ['pl', 'ql'], 'dcline': None}
    for etype in iwant:
        with timer('Collect data [%s] for [%s]' % (path, etype)):
            data = collect_learning_data(path, etype, iwant[etype])
    """

    path = 'D:/python/db/2019_09_12/data/'
    iwant = {'CCTOUT': ['name', 'cct', 'times']}
    collect_learning_res(path, iwant)
    """
Esempio n. 9
0
def group_kmeans(ed, n):
    assert isinstance(ed, pd.DataFrame) and ed.shape[0] == ed.shape[1]
    kmeans = KMeans(n_clusters=n)
    clf = kmeans.fit(ed.values)
    groups = {}
    for i in range(n):
        groups[i] = ed.index[np.where(clf.labels_ == i)[0]].to_list()
    return groups


if __name__ == '__main__':
    from core.power import Power

    path = 'D:/PSA_src/psa/localdata/0913/data'
    fmt = 'on'
    power = Power(fmt)
    power.load_power(path, fmt=fmt, lp=False, st=False)

    island = 0
    with timer('Generate Y matrix'):
        y = generate_y_matrix(power, island, node_type='station', x_only=False)
    with timer('Calculate Z from Y'):
        z = calc_z_from_y(y)
    with timer('Calculate ED matrix'):
        indices = power.stations.index[power.stations.island == island][:100].to_numpy()
        ed = calc_ed_from_z(z, indices=indices)
    # with timer('ED map to 2D by t-SNE'):
    #     x = ed_map_tsne(ed)
    # with timer('Group by kmeans'):
    #     groups = group_kmeans(ed, 10)