Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.3 kB
1
Indexable
Never
import os
import pathlib
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import scipy.sparse as scsp

from warnings import simplefilter
simplefilter(action="ignore", category=pd.errors.PerformanceWarning)

import py_dss_interface

from dss import DSS as dss

script_path = os.path.dirname(os.path.abspath(__file__))

dss_file = pathlib.Path(script_path).joinpath(
    "feeders", "13bus", "IEEE13Nodeckt_com_loadshape.dss")

#dss = py_dss_interface.DSS()


# Acessa objetos DSS
DSSText = dss.Text
DSSCircuit = dss.ActiveCircuit
DSSMonitors = DSSCircuit.Monitors

# Executa 1 de 2: obtém tensão no "node" 670.3 usando monitor
DSSText.Command = f"compile [{dss_file}]"
DSSText.Command = "solve"
DSSText.Command = "Export monitors load_670c_vi"
DSSText.Command = "Plot monitor object= load_670c_vi channels=(1 )"

# Executa 2 de 2: obtém tensão no "node" 670.3 usando loop 24x
DSSText.Command = f"compile [{dss_file}]"

# cria df de resultados
df_voltage = pd.DataFrame(
    index=DSSCircuit.AllNodeNames,
    columns=[f'hora_{h}' for h in range(24)])

DSSText.Command = "set stepsize=1h"
DSSText.Command = "set mode=yearly"
DSSText.Command = "set number=1"

basekv = 2.4
total_number = 24

for h in range(total_number):
    DSSCircuit.Solution.Solve()
    print(scsp.csr_matrix(dss.YMatrix.GetCompressedYMatrix()))
    vri = DSSCircuit.AllBusVolts
    #print(vri)
    # Gera valores aleatórios com distribuição normal (média 1, desvio padrão 0.05)
    random_factors = np.random.normal(1, 0.005, len(vri)//2)
    # Limita os valores na faixa de 0.9 a 1.1
    random_factors = np.clip(random_factors, 0.95, 1.05)
    
    # Calcula os valores de tensão e aplica a aleatoriedade
    df_voltage[f'hora_{h}'] = [
        ((vri[j] + 1j * vri[j+1]) / (basekv * 1000)) * random_factors[j//2] 
        for j in range(0, len(vri), 2)
    ]

#print(df_voltage)



'''
fig, ax = plt.subplots()
ax.plot(range(1, total_number+1), df_voltage.loc['670.3'].abs())
ax.ticklabel_format(useOffset=False)

plt.xlabel("Tempo [Hora]")
plt.ylabel("Tensão na barra 670.3 [PU]")
plt.grid()
plt.show()
'''

# dict_voltage = df_voltage.to_dict(orient='list')
dict_voltage = df_voltage.apply(lambda row: row.tolist(), axis=1).to_dict()

#print(dict_voltage)
Leave a Comment