290 lines
9 KiB
Python
290 lines
9 KiB
Python
'''
|
|
JMK Engineering Inc. Python Library for design and such.
|
|
by: Jeff MacKinnon
|
|
|
|
email: jeff@jmkengineering.com
|
|
|
|
Commandline tools for JEPL functions
|
|
|
|
'''
|
|
|
|
import argparse
|
|
import jepl.jepl as jmk
|
|
|
|
|
|
#
|
|
# functions for the functions
|
|
#
|
|
|
|
# General
|
|
|
|
def va(args):
|
|
x = [1,3,None]
|
|
if args.phases in x:
|
|
if args.phases == None:
|
|
phases = 3
|
|
else:
|
|
phases = args.phases
|
|
result = jmk.va(args.voltage, args.current, phases=phases)
|
|
print ( str(round(result,2))+ "VA")
|
|
else:
|
|
print(args.phases)
|
|
|
|
|
|
# Circuits
|
|
|
|
def condsize(args):
|
|
if args.temp == None:
|
|
temp = 60
|
|
else:
|
|
temp = args.temp
|
|
if args.material == None:
|
|
material = 'cu'
|
|
else:
|
|
material = args.material
|
|
if args.code == None:
|
|
code = 'CEC'
|
|
else:
|
|
code = args.code
|
|
if args.raceway == None:
|
|
raceway = True
|
|
elif args.raceway == 'n':
|
|
raceway = False
|
|
else:
|
|
raceway = True
|
|
if args.ambient == None:
|
|
ambient = 30
|
|
else:
|
|
ambient = args.ambient
|
|
if args.maxsize == None:
|
|
maxsize = 500
|
|
else:
|
|
maxsize = 500
|
|
if args.type == None:
|
|
loadtype = None
|
|
else:
|
|
valid_load_type = ['normal','xfmr','xfmrp','xfmrs','motor',None]
|
|
if args.type not in valid_load_type:
|
|
print(args.type + " is not a valid load_type.")
|
|
else:
|
|
loadtype = args.type
|
|
|
|
result = jmk.conductor_size(args.current, temp = temp, material = material, code = code, raceway = raceway, max = maxsize, load_type = loadtype )
|
|
print(result)
|
|
|
|
def condamp(args):
|
|
if args.temp == None:
|
|
temp = 60
|
|
else:
|
|
temp = args.temp
|
|
if args.material == None:
|
|
material = 'cu'
|
|
else:
|
|
material = args.material
|
|
if args.code == None:
|
|
code = 'CEC'
|
|
else:
|
|
code = args.code
|
|
if args.raceway == None:
|
|
raceway = True
|
|
elif args.raceway == 'n':
|
|
raceway = False
|
|
else:
|
|
raceway = True
|
|
if args.ambient == None:
|
|
ambient = 30
|
|
else:
|
|
ambient = args.ambient
|
|
result = jmk.conductor_ampacity(args.conductor, temp = temp, material = material, code = code, raceway = raceway)
|
|
print(result)
|
|
|
|
def bonding(args):
|
|
|
|
if args.material == None:
|
|
material = 'cu'
|
|
else:
|
|
material = args.material
|
|
if args.code == None:
|
|
code = 'CEC'
|
|
else:
|
|
code = args.code
|
|
if args.bus == None:
|
|
bus = False
|
|
else:
|
|
bus = args.bus
|
|
|
|
result = jmk.bonding_conductor(args.circuit_ampacity, bus = bus, material = material, code = code)
|
|
print(result)
|
|
|
|
|
|
def voltagedrop(args):
|
|
|
|
voltage = args.voltage
|
|
current = args.current
|
|
size = args.conductor_size
|
|
length = args.length
|
|
if args.phases == None:
|
|
num_phase = 3
|
|
elif args.phases == '1':
|
|
num_phase = 1
|
|
elif args.phases == '3':
|
|
num_phase = 3
|
|
else:
|
|
print('--phase must be 1 or 2.')
|
|
if args.material == None:
|
|
material = 'cu'
|
|
else:
|
|
material = args.material
|
|
if args.runs == None:
|
|
num_runs = 1
|
|
else:
|
|
num_runs = args.runs
|
|
if args.runs == None:
|
|
num_runs = 1
|
|
else:
|
|
num_runs = args.runs
|
|
if args.code == None:
|
|
code = 'CEC'
|
|
else:
|
|
code = args.code
|
|
if args.powerfactor == None:
|
|
power_factor = 'dc'
|
|
else:
|
|
power_factor = args.powerfactor
|
|
if args.raceway == None:
|
|
raceway = True
|
|
elif args.raceway == 'n':
|
|
raceway = False
|
|
else:
|
|
raceway = True
|
|
|
|
|
|
|
|
if args.temp == None:
|
|
insul_temp = 75
|
|
else:
|
|
insul_temp = args.temp
|
|
|
|
result = jmk.voltage_drop(voltage, current, size, length, num_phase = num_phase, material = material, num_runs = num_runs, code = code, power_factor = power_factor, raceway = raceway, insul_temp = insul_temp)
|
|
print(result)
|
|
|
|
# Solar
|
|
|
|
def temp_adj_Voc(args):
|
|
if args.beta == None:
|
|
beta = -0.5
|
|
else:
|
|
beta = args.beta
|
|
if args.stctemp == None:
|
|
stctemp = 25
|
|
else:
|
|
stctemp = args.stctemp
|
|
result = jmk.temp_adj_Voc(args.voc, args.temperature, beta, stctemp)
|
|
print(str(round(result,2))+"V")
|
|
|
|
|
|
#
|
|
# Parse the options
|
|
#
|
|
|
|
try:
|
|
parser = argparse.ArgumentParser()
|
|
subparsers = parser.add_subparsers(
|
|
title="tools",
|
|
help="Commandline Functions"
|
|
)
|
|
|
|
#
|
|
# This section is for the jepl_general functions
|
|
#
|
|
|
|
# Calcuating VA
|
|
|
|
va_parser = subparsers.add_parser("va", help="calculate VA (S)")
|
|
va_parser.add_argument("voltage", type=float,help="Voltage of the circuit")
|
|
va_parser.add_argument("current", type=float,help="Current of the circuit.")
|
|
va_parser.add_argument("-p","--phases", type=int,help="Phases of the circuit. It should be either 1 or 3, and we will assume 3 if it is not used.")
|
|
va_parser.set_defaults(func=va)
|
|
|
|
|
|
#
|
|
# Circuit Tools
|
|
#
|
|
|
|
|
|
condsize_parser = subparsers.add_parser("condsize", help="Determine the conductor size for a defined current and load type.")
|
|
condsize_parser.add_argument("current", type=float, help="The current of the circuit.")
|
|
condsize_parser.add_argument("-t", "--temp", type=int, help="The temperature rating for the insulation, if none included is 60C. default: 60" )
|
|
condsize_parser.add_argument("-m", "--material", type=str, help="This should be cu or al, for copper or aluminum. If none defined cu will be used.")
|
|
condsize_parser.add_argument("-c", "--code", type=str, help="Currently this will either be CEC or NEC. default CEC")
|
|
condsize_parser.add_argument("-r", "--raceway", type=str, help="If the conductors are in a raceway use y for yes and n for no.")
|
|
condsize_parser.add_argument("-a", "--ambient", type=float, help="Ambient temperature in celsious. default: 30")
|
|
condsize_parser.add_argument("-x", "--maxsize", type=str, help="Maximum conductor size in AWG/kcmil. default: 500")
|
|
condsize_parser.add_argument("--type",type=str, help="Load type {}'normal','xfmr','xfmrp','xfmrs','motor',None}, default: None")
|
|
condsize_parser.set_defaults(func=condsize)
|
|
|
|
condamp_parser = subparsers.add_parser("condamp", help="Determine the ampacity of a conductor.")
|
|
condamp_parser.add_argument("conductor", type=str, help="The conductor size in AWG/kcmil")
|
|
condamp_parser.add_argument("-t", "--temp", type=int, help="The temperature rating for the insulation, if none included is 60C. default: 60" )
|
|
condamp_parser.add_argument("-m", "--material", type=str, help="This should be cu or al, for copper or aluminum. If none defined cu will be used.")
|
|
condamp_parser.add_argument("-c", "--code", type=str, help="Currently this will either be CEC or NEC. default CEC")
|
|
condamp_parser.add_argument("-r", "--raceway", type=str, help="If the conductors are in a raceway use y for yes and n for no.")
|
|
condamp_parser.add_argument("-a", "--ambient", type=float, help="Ambient temperature in celsious. default: 30")
|
|
condamp_parser.set_defaults(func=condamp)
|
|
|
|
bonding_parser = subparsers.add_parser("bonding", help="Bonding conductor for the circuit, wire or bus.")
|
|
bonding_parser.add_argument("circuit_ampacity", type=float, help="Circuit ampacity.")
|
|
bonding_parser.add_argument("-m", "--material", type=str, help="This should be cu or al, for copper or aluminum. If none defined cu will be used.")
|
|
bonding_parser.add_argument("-c", "--code", type=str, help="Currently this will either be CEC or NEC. default CEC")
|
|
bonding_parser.add_argument("-b", "--bus", type=bool, help="Bus or wire bond, bus =True, wire = False.")
|
|
bonding_parser.set_defaults(func=bonding)
|
|
|
|
|
|
|
|
voltagedrop_parser = subparsers.add_parser("voltagedrop", help="Determine the voltage drop of a circuit.")
|
|
voltagedrop_parser.add_argument("voltage", type=float, help="The circuit voltage.")
|
|
voltagedrop_parser.add_argument("current", type=float, help="The circuit current")
|
|
voltagedrop_parser.add_argument("conductor_size", type=str, help="The conductor size.")
|
|
voltagedrop_parser.add_argument("length", type=float, help="The circuit length, in metres.")
|
|
voltagedrop_parser.add_argument("-t", "--temp", type=int, help="The temperature rating for the insulation, if none included is 60C. default: 75" )
|
|
voltagedrop_parser.add_argument("-m", "--material", type=str, help="This should be cu or al, for copper or aluminum. If none defined cu will be used.")
|
|
voltagedrop_parser.add_argument("-c", "--code", type=str, help="Currently this will either be CEC or NEC. default CEC")
|
|
voltagedrop_parser.add_argument("-r", "--raceway", type=str, help="If the conductors are in a raceway use y for yes and n for no.")
|
|
voltagedrop_parser.add_argument("-pf","--powerfactor", type=str, help="Power Factor. Valid options DC, 1, 0.9, 0.8. default dc")
|
|
voltagedrop_parser.add_argument("--phases", type=str, help="Number of phases, 1 or 3, default = 3.")
|
|
voltagedrop_parser.add_argument("--runs", type=int, help="Number of circuits in parallel, default 1.")
|
|
voltagedrop_parser.set_defaults(func=voltagedrop)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
# Solar Tools
|
|
#
|
|
|
|
tempvoc = subparsers.add_parser("tempVoc", help="Calculate the temperature adjusted Voc of a PV panel.")
|
|
tempvoc.add_argument("voc", type=float,help="Open circuit voltage of the panel.")
|
|
tempvoc.add_argument("temperature", type=float, help="Temperature the panel will be at.")
|
|
tempvoc.add_argument("-b", "--beta", type=float, help="Panel Beta value, if none is added -0.5 will be used.")
|
|
tempvoc.add_argument("-t", "--stctemp", type=float, help="The STC temp. If none is added 25C will be used.")
|
|
tempvoc.set_defaults(func=temp_adj_Voc)
|
|
|
|
|
|
|
|
# This runs the function that was selected with the arguments in the command.
|
|
args = parser.parse_args()
|
|
args.func(args)
|
|
|
|
|
|
|
|
except argparse.ArgumentError as e:
|
|
#log.error("Error parsing arguments")
|
|
raise e
|
|
|
|
|
|
#else:
|
|
# print(f"Something clever")
|
|
|