100% found this document useful (1 vote)
1K views5 pages

Python Code For Transmission Line

This document contains code for calculating electrical parameters for a short transmission line. It imports mathematical and GUI libraries, defines functions to perform calculations for lagging and leading power factors, and sets up a GUI with entries for input values and labels to display output values. The functions perform calculations using the input values and display the results.

Uploaded by

Mark Mercado
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
100% found this document useful (1 vote)
1K views5 pages

Python Code For Transmission Line

This document contains code for calculating electrical parameters for a short transmission line. It imports mathematical and GUI libraries, defines functions to perform calculations for lagging and leading power factors, and sets up a GUI with entries for input values and labels to display output values. The functions perform calculations using the input values and display the results.

Uploaded by

Mark Mercado
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 5

from math import *

from numpy import *


from tkinter import *
from tkinter import ttk

def calculate1(*args):
try:
vr = float(voltage.get())
mw = float(megaw.get())
pf = float(pfactor.get())
z = float(impe.get())
zan = float(zang.get())
y = float(admi.get())
yan = float(yang.get())
x = float(dist.get())
pfl = (lela.get())
if pfl == 'lagging' or "lag":
ang = -acos(pf/100)
num1 = mw*1000000*exp(1j*ang)
den1 = vr*pf*10
quo = num1/den1
zt = z*exp(1j*deg2rad(zan))
vs = vr*1000 + quo*zt*x
vsang = angle(vs)
ps = (abs(vs)/1000000*abs(quo)*cos(vsang - ang))

vsend.set(( round(abs(vs/1000), 3)))


vsang2.set(round(rad2deg(angle(vs)),3))
is1.set(round(abs(quo / 1.732050808), 3))
psend.set(round(abs(vs)/1000000*abs(quo)*cos(vsang - ang),3))
eff.set(round( mw*100/ps,3))

print(abs(vs))

elif pfl == 'leading' or 'lead':


ang = acos(pf/100)
num1 = mw * 1000000 * exp(1j * ang)
den1 = vr * pf * 10
quo = num1 / den1
zt = z * exp(1j * deg2rad(zan))
vs = vr * 1000 + quo * zt * x
vsang = angle(vs)
ps = (abs(vs) / 1000000 * abs(quo) * cos(vsang - ang))

vsend.set((round(abs(vs)/1000, 3)))
vsang2.set(round(rad2deg(angle(vs)),3))
is1.set(round(abs(quo/1.732050808),3))
psend.set(round(abs(vs) / 1000000 * abs(quo) * cos(vsang - ang), 3))
eff.set(round( mw*100/ps,3))

except ValueError:
pass

def calculate2(*args):
try:
vr = float(voltage.get())
mw = float(megaw.get())
pf = float(pfactor.get())
z = float(impe.get())
zan = float(zang.get())
y = float(admi.get())
yan = float(yang.get())
x = float(dist.get())
pfl = (lela.get())
if pfl == 'lagging' or "lag":
ang = -acos(pf/100)
num1 = mw*1000000*exp(1j*ang)
den1 = vr*pf*10
quo = num1/den1
zt = z*exp(1j*deg2rad(zan))
vs = vr*1000 + quo*zt*x
vsang = angle(vs)
ps = (abs(vs)/1000000*abs(quo)*cos(vsang - ang))

vsend.set(( round(abs(vs/1000), 3)))


vsang2.set(round(rad2deg(angle(vs)),3))
is1.set(round(abs(quo / 1.732050808), 3))
psend.set(round(abs(vs)/1000000*abs(quo)*cos(vsang - ang),3))
eff.set(round( mw*100/ps,3))

print(abs(vs))

elif pfl == 'leading' or 'lead':


ang = acos(pf/100)
num1 = mw * 1000000 * exp(1j * ang)
den1 = vr * pf * 10
quo = num1 / den1
zt = z * exp(1j * deg2rad(zan))
vs = vr * 1000 + quo * zt * x
vsang = angle(vs)
ps = (abs(vs) / 1000000 * abs(quo) * cos(vsang - ang))

vsend.set((round(abs(vs)/1000, 3)))
vsang2.set(round(rad2deg(angle(vs)),3))
is1.set(round(abs(quo/1.732050808),3))
psend.set(round(abs(vs) / 1000000 * abs(quo) * cos(vsang - ang), 3))
eff.set(round( mw*100/ps,3))

except ValueError:
pass

def calculate3(*args):
try:
vr = float(voltage.get())
mw = float(megaw.get())
pf = float(pfactor.get())
z = float(impe.get())
zan = float(zang.get())
y = float(admi.get())
yan = float(yang.get())
x = float(dist.get())
pfl = (lela.get())
if pfl == 'lagging' or "lag":
ang = -acos(pf/100)
num1 = mw*1000000*exp(1j*ang)
den1 = vr*pf*10
quo = num1/den1
zt = z*exp(1j*deg2rad(zan))
vs = vr*1000 + quo*zt*x
vsang = angle(vs)
ps = (abs(vs)/1000000*abs(quo)*cos(vsang - ang))

vsend.set(( round(abs(vs/1000), 3)))


vsang2.set(round(rad2deg(angle(vs)),3))
is1.set(round(abs(quo / 1.732050808), 3))
psend.set(round(abs(vs)/1000000*abs(quo)*cos(vsang - ang),3))
eff.set(round( mw*100/ps,3))

print(abs(vs))

elif pfl == 'leading' or 'lead':


ang = acos(pf/100)
num1 = mw * 1000000 * exp(1j * ang)
den1 = vr * pf * 10
quo = num1 / den1
zt = z * exp(1j * deg2rad(zan))
vs = vr * 1000 + quo * zt * x
vsang = angle(vs)
ps = (abs(vs) / 1000000 * abs(quo) * cos(vsang - ang))

vsend.set((round(abs(vs)/1000, 3)))
vsang2.set(round(rad2deg(angle(vs)),3))
is1.set(round(abs(quo/1.732050808),3))
psend.set(round(abs(vs) / 1000000 * abs(quo) * cos(vsang - ang), 3))
eff.set(round( mw*100/ps,3))

except ValueError:
pass

root = Tk()
root.title("TRANSMISSION")
#root.geometry("280x480")

mainframe = ttk.Frame(root, padding="6 6 12 12")


mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)

#rows = 0
#while rows < 50:
# root.rowconfigure(rows, weight=1)
# root.columnconfigure(rows, weight=1)
# rows += 1

nb = ttk.Notebook(root, padding = "12 12 12 12")


nb.grid(column=0, row=0, sticky=(N, W, E, S))
nb.columnconfigure(0, weight=1)
nb.rowconfigure(0, weight=1)
# Adds tab 1 of the notebook
page1 = ttk.Frame(nb)
nb.add(page1, text='Tab1')

# Adds tab 2 of the notebook


page2 = ttk.Frame(nb)
nb.add(page2, text='Tab2')

parent=StringVar()
voltage = StringVar()
megaw = StringVar()
pfactor = StringVar()
impe = StringVar()
zang = StringVar()
dist = StringVar()
lela = StringVar()
admi = StringVar()
yang = StringVar()
vsend = StringVar()
vsang2 = StringVar()
is1 = StringVar()
psend = StringVar()
eff = StringVar()

voltage_entry = ttk.Entry(page1, width=6, textvariable=voltage)


voltage_entry.grid(column=2, row=2, sticky=(W, E))

megaw_entry = ttk.Entry(page1, width=2, textvariable=megaw)


megaw_entry.grid(column=2, row=3, sticky=(W, E))

pfactor_entry = ttk.Entry(page1, width=2, textvariable=pfactor)


pfactor_entry.grid(column=2, row=4, sticky=(W, E))

lela_entry = ttk.Entry(page1, width=2, textvariable=lela)


lela_entry.grid(column=2, row=5, sticky=(W, E))

impe_entry = ttk.Entry(page1, width=2, textvariable=impe)


impe_entry.grid(column=2, row=6, sticky=(W, E))

zang_entry = ttk.Entry(page1, width=2, textvariable=zang)


zang_entry.grid(column=2, row=7, sticky=(W, E))

admi_entry = ttk.Entry(page1, width=2, textvariable=admi)


admi_entry.grid(column=2, row=8, sticky=(W, E))

yang_entry = ttk.Entry(page1, width=2, textvariable=yang)


yang_entry.grid(column=2, row=9, sticky=(W, E))

dist_entry = ttk.Entry(page1, width=2, textvariable=dist)


dist_entry.grid(column=2, row=10, sticky=(W, E))

ttk.Label(page2, textvariable=vsend).grid(column=3, row=12, columnspan=5, sticky=W)


ttk.Label(page2, textvariable=vsang2).grid(column=3, row=13, sticky=E)
ttk.Label(page2, textvariable=is1).grid(column=3, row=14, sticky=E)
ttk.Label(page2, textvariable=psend).grid(column=3, row=15, sticky=E)
ttk.Label(page2, textvariable=eff).grid(column=3, row=16, sticky=E)
ttk.Button(page1, text="Calculate", command=calculate1).grid(column=3, row=12,
columnspan=1, sticky=E)
ttk.Label(page1, text=" INPUT GIVEN").grid(column=2, row=1,columnspan =
2 ,sticky=(W, E))
ttk.Label(page1, text="Voltage Receiving (in kV)").grid(column=3, row=2, sticky=W)
ttk.Label(page1, text="Power Receiving (in MW)").grid(column=3, row=3, sticky=W)
ttk.Label(page1, text="Power Factor (in %)").grid(column=3, row=4, sticky=W)
ttk.Label(page1, text="'Leading' or 'Lagging'").grid(column=3, row=5, sticky=W)
ttk.Label(page1, text="Impedance (r)").grid(column=3, row=6, sticky=W)
ttk.Label(page1, text="Impedance Angle (?)").grid(column=3, row=7, sticky=W)
ttk.Label(page1, text="Admittance (r)").grid(column=3, row=8, sticky=W)
ttk.Label(page1, text="Admittance Angle (?)").grid(column=3, row=9, sticky=W)
ttk.Label(page1, text="Distance (m)").grid(column=3, row=10, sticky=W)

ttk.Label(page2, text=" SHORT TRANSMISSION LINE ").grid(column=2, row=1,


columnspan = 3, sticky=W)
ttk.Label(page2, text=" ").grid(column=4, row=2, sticky=W)
ttk.Label(page2, text="Voltage Sending").grid(column=2, row=12, sticky=E)
ttk.Label(page2, text="Current Sending").grid(column=2, row=14, sticky=E)
ttk.Label(page2, text="Voltage Sending Angle").grid(column=2, row=13, sticky=E)
ttk.Label(page2, text="Power Sending").grid(column=2, row=15, sticky=E)
ttk.Label(page2, text="Efficiency").grid(column=2, row=16, sticky=E)
ttk.Label(page2, text="kV").grid(column=4, row=12, sticky=W)
ttk.Label(page2, text="degrees").grid(column=4, row=13, sticky=W)
ttk.Label(page2, text="Ampere").grid(column=4, row=14, sticky=W)
ttk.Label(page2, text="MW").grid(column=4, row=15, sticky=W)
ttk.Label(page2, text="%").grid(column=4, row=16, sticky=W)

for child in page1.winfo_children(): child.grid_configure(padx=5, pady=5)


for child in page2.winfo_children(): child.grid_configure(padx=5, pady=5)

voltage_entry.focus()
root.bind('<Return>', calculate1)

root.mainloop()

You might also like