JEPL/tools.py
2025-12-28 22:06:19 -04:00

100 lines
2.2 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)
# 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)
#
# 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")