create.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # -*- coding: utf-8 -*-
  2. # =============================================================================
  3. # Copyright (C) 2018 Mercados Electricos de Centroamérica. All rights reserved
  4. # =============================================================================
  5. """Crea las estructuras con numeración secuencial de buses, circuitos y nombres de circuitos
  6. """
  7. from numpy import array
  8. from numpy import zeros
  9. from utils.idx_brch import BUS_I, BUS_J, CKT
  10. from pandas import DataFrame
  11. def setbus(net):
  12. """Lee la información de la red y crea una serie con los códigos de nodos y su numeración correlativa.
  13. """
  14. b = net['bus_i'].append(net['bus_j']).drop_duplicates().sort_values()
  15. b = b.reset_index(drop=True)
  16. return b
  17. def setbranch(net, b):
  18. """Utiliza la información de la red, lod códigos de nodos y su numeración correlativa para generar un listado con
  19. de los circuitos de acuerdo a la numeración correlativo del nodo.
  20. """
  21. br = net.copy()
  22. for i in range(0, net.shape[0]):
  23. br.loc[i, 'bus_i'] = b[b == br['bus_i'][i]].index[0]
  24. br.loc[i, 'bus_j'] = b[b == br['bus_j'][i]].index[0]
  25. br = br.sort_values(['bus_i', 'bus_j'])
  26. return br.values
  27. def setvariable(variable):
  28. l=variable.shape[0]
  29. z=zeros(l)
  30. for i in range(0,variable.shape[0]):
  31. z[i]=variable[i]
  32. return z
  33. def setvariable_s(variable):
  34. (l,n)=variable.shape
  35. z=zeros((l,n))
  36. for i in range(0,l):
  37. for j in range(0,n):
  38. z[i,j]=variable.iloc[i,j]
  39. return z
  40. def setvariable_p(variable, n):
  41. z=zeros((n,5))
  42. m=0
  43. for j in range(0,n):
  44. for i in range(0,5):
  45. z[j,i]=variable[m]
  46. m=m+1
  47. return z
  48. def branchnames(b, br):
  49. """Devuelve un dataframe con los BUS I BUS J y CKT ordenados.
  50. """
  51. brnames_bi = []
  52. brnames_bj = []
  53. for i in range(0, br.shape[0]):
  54. brnames_bi.append("".join([str(b[br[i, BUS_I]])]))
  55. brnames_bj.append("".join([str(b[br[i, BUS_J]])]))
  56. brnames=DataFrame()
  57. brnames['BUS I']=brnames_bi
  58. brnames['BUS J']=brnames_bj
  59. brnames['CKT']=br[:,2]
  60. return brnames