create.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. def setbus(net):
  11. """Lee la información de la red y crea una serie con los códigos de nodos y su numeración correlativa.
  12. """
  13. b = net['bus_i'].append(net['bus_j']).drop_duplicates().sort_values()
  14. b = b.reset_index(drop=True)
  15. return b
  16. def setbranch(net, b):
  17. """Utiliza la información de la red, lod códigos de nodos y su numeración correlativa para generar un listado con
  18. de los circuitos de acuerdo a la numeración correlativo del nodo.
  19. """
  20. br = net.copy()
  21. for i in range(0, net.shape[0]):
  22. br.loc[i, 'bus_i'] = b[b == br['bus_i'][i]].index[0]
  23. br.loc[i, 'bus_j'] = b[b == br['bus_j'][i]].index[0]
  24. br = br.sort_values(['bus_i', 'bus_j'])
  25. return br.values
  26. def setvariable(variable):
  27. l=variable.shape[0]
  28. z=zeros(l)
  29. for i in range(0,variable.shape[0]):
  30. z[i]=variable[i]
  31. return z
  32. def setvariable_s(variable):
  33. (l,n)=variable.shape
  34. z=zeros((l,n))
  35. for i in range(0,l):
  36. for j in range(0,n):
  37. z[i,j]=variable.iloc[i,j]
  38. return z
  39. def setvariable_p(variable, n):
  40. z=zeros((n,5))
  41. m=0
  42. for j in range(0,n):
  43. for i in range(0,5):
  44. z[j,i]=variable[m]
  45. m=m+1
  46. return z
  47. def branchnames(b, br):
  48. """Devuelve un array con los nombres de los circuitos.
  49. """
  50. brnames = []
  51. for i in range(0, br.shape[0]):
  52. brnames.append("-".join([str(b[br[i, BUS_I]]),str(b[br[i, BUS_J]])]))
  53. brnames = array(brnames)
  54. return brnames