diff --git a/pygridsim.egg-info/PKG-INFO b/pygridsim.egg-info/PKG-INFO index e2dd3db..b4213d1 100644 --- a/pygridsim.egg-info/PKG-INFO +++ b/pygridsim.egg-info/PKG-INFO @@ -63,7 +63,7 @@ Package to simulate OpenDSS circuits on Python # Overview -TODO: Provide a short overview of the project here. +PyGridSim aims to make building electrical circuits and corresponding circuit simulations easy for a Python coder. It builds on the distribution system OpenDSS and corresponding python package AltDSS. # Install diff --git a/pygridsim/__init__.py b/pygridsim/__init__.py index d712b60..066174b 100644 --- a/pygridsim/__init__.py +++ b/pygridsim/__init__.py @@ -6,4 +6,4 @@ __email__ = 'amzhao@mit.edu' __version__ = '0.1.0.0' -from pygridsim.core import PyGridSim \ No newline at end of file +from pygridsim.core import PyGridSim as PyGridSim \ No newline at end of file diff --git a/pygridsim/__pycache__/__init__.cpython-312.pyc b/pygridsim/__pycache__/__init__.cpython-312.pyc index d3ebbc9..6cd83ee 100644 Binary files a/pygridsim/__pycache__/__init__.cpython-312.pyc and b/pygridsim/__pycache__/__init__.cpython-312.pyc differ diff --git a/pygridsim/__pycache__/configs.cpython-312.pyc b/pygridsim/__pycache__/configs.cpython-312.pyc index 974acdb..22e4917 100644 Binary files a/pygridsim/__pycache__/configs.cpython-312.pyc and b/pygridsim/__pycache__/configs.cpython-312.pyc differ diff --git a/pygridsim/__pycache__/core.cpython-312.pyc b/pygridsim/__pycache__/core.cpython-312.pyc index 25909de..553349c 100644 Binary files a/pygridsim/__pycache__/core.cpython-312.pyc and b/pygridsim/__pycache__/core.cpython-312.pyc differ diff --git a/pygridsim/__pycache__/defaults.cpython-312.pyc b/pygridsim/__pycache__/defaults.cpython-312.pyc index edbbb4c..8045c98 100644 Binary files a/pygridsim/__pycache__/defaults.cpython-312.pyc and b/pygridsim/__pycache__/defaults.cpython-312.pyc differ diff --git a/pygridsim/__pycache__/enums.cpython-312.pyc b/pygridsim/__pycache__/enums.cpython-312.pyc index e0896e3..3a13154 100644 Binary files a/pygridsim/__pycache__/enums.cpython-312.pyc and b/pygridsim/__pycache__/enums.cpython-312.pyc differ diff --git a/pygridsim/__pycache__/lines.cpython-312.pyc b/pygridsim/__pycache__/lines.cpython-312.pyc index bba4c5c..2b3b7a4 100644 Binary files a/pygridsim/__pycache__/lines.cpython-312.pyc and b/pygridsim/__pycache__/lines.cpython-312.pyc differ diff --git a/pygridsim/__pycache__/parameters.cpython-312.pyc b/pygridsim/__pycache__/parameters.cpython-312.pyc index dfc0714..4058003 100644 Binary files a/pygridsim/__pycache__/parameters.cpython-312.pyc and b/pygridsim/__pycache__/parameters.cpython-312.pyc differ diff --git a/pygridsim/__pycache__/results.cpython-312.pyc b/pygridsim/__pycache__/results.cpython-312.pyc index a015b74..2505c37 100644 Binary files a/pygridsim/__pycache__/results.cpython-312.pyc and b/pygridsim/__pycache__/results.cpython-312.pyc differ diff --git a/pygridsim/configs.py b/pygridsim/configs.py index d1eb8cf..226698f 100644 --- a/pygridsim/configs.py +++ b/pygridsim/configs.py @@ -1,68 +1,68 @@ -from pygridsim.enums import * -from pygridsim.defaults import * +from pygridsim.enums import LoadType, LineType, GeneratorType, SourceType +import pygridsim.defaults as defaults LOAD_CONFIGURATIONS = { LoadType.HOUSE: { - "kV": HOUSE_KV, - "kW": HOUSE_KW, - "kvar": HOUSE_KVAR + "kV": defaults.HOUSE_KV, + "kW": defaults.HOUSE_KW, + "kvar": defaults.HOUSE_KVAR }, LoadType.COMMERCIAL: { - "kV": COMMERCIAL_KV, - "kW": COMMERCIAL_KW, - "kvar": COMMERCIAL_KVAR + "kV": defaults.COMMERCIAL_KV, + "kW": defaults.COMMERCIAL_KW, + "kvar": defaults.COMMERCIAL_KVAR }, LoadType.INDUSTRIAL: { - "kV": INDUSTRIAL_KV, - "kW": INDUSTRIAL_KW, - "kvar": INDUSTRIAL_KVAR + "kV": defaults.INDUSTRIAL_KV, + "kW": defaults.INDUSTRIAL_KW, + "kvar": defaults.INDUSTRIAL_KVAR } } SOURCE_CONFIGURATIONS = { SourceType.TURBINE: { - "kV": TURBINE_BASE_KV + "kV": defaults.TURBINE_BASE_KV }, SourceType.POWER_PLANT: { - "kV": POWER_PLANT_KV + "kV": defaults.POWER_PLANT_KV }, SourceType.LV_SUBSTATION: { - "kV": LV_SUBSTATION_BASE_KV + "kV": defaults.LV_SUBSTATION_BASE_KV }, SourceType.MV_SUBSTATION: { - "kV": MV_SUBSTATION_BASE_KV + "kV": defaults.MV_SUBSTATION_BASE_KV }, SourceType.HV_SUBSTATION: { - "kV": HV_SUBSTATION_BASE_KV + "kV": defaults.HV_SUBSTATION_BASE_KV }, SourceType.SHV_SUBSTATION: { - "kV": SHV_SUBSTATION_BASE_KV + "kV": defaults.SHV_SUBSTATION_BASE_KV }, } LINE_CONFIGURATIONS = { LineType.LV_LINE: { - "length": LV_LINE_LENGTH + "length": defaults.LV_LINE_LENGTH }, LineType.MV_LINE: { - "length": MV_LINE_LENGTH + "length": defaults.MV_LINE_LENGTH }, LineType.HV_LINE: { - "length": HV_LINE_LENGTH + "length": defaults.HV_LINE_LENGTH } } GENERATOR_CONFIGURATIONS = { GeneratorType.SMALL: { - "kV": SMALL_GEN_KV, - "kW": SMALL_GEN_KW, + "kV": defaults.SMALL_GEN_KV, + "kW": defaults.SMALL_GEN_KW, }, GeneratorType.LARGE: { - "kV": LARGE_GEN_KV, - "kW": LARGE_GEN_KW, + "kV": defaults.LARGE_GEN_KV, + "kW": defaults.LARGE_GEN_KW, }, GeneratorType.INDUSTRIAL: { - "kV": INDUSTRIAL_GEN_KV, - "kW": INDUSTRIAL_GEN_KW, + "kV": defaults.INDUSTRIAL_GEN_KV, + "kW": defaults.INDUSTRIAL_GEN_KW, } } \ No newline at end of file diff --git a/pygridsim/core.py b/pygridsim/core.py index 450164f..c3a7b75 100644 --- a/pygridsim/core.py +++ b/pygridsim/core.py @@ -1,11 +1,8 @@ # -*- coding: utf-8 -*- from altdss import altdss -from altdss import AltDSS, Transformer, Vsource, Load, LoadModel, LoadShape -from dss.enums import LineUnits, SolveModes -from pygridsim.parameters import * +from pygridsim.parameters import make_load_node, make_source_node, make_generator, make_pv from pygridsim.results import query_solution, export_results from pygridsim.lines import make_line -from pygridsim.enums import LineType, SourceType, LoadType, GeneratorType """Main module.""" @@ -45,11 +42,8 @@ def update_source(self, source_type: str = "turbine", params = {}): Adds a main voltage source if it doesn't exist, otherwise edits it Args: - params: load parameters for these manual additions source_type: source type as a string - num (optional): number of sources to create with these parameters (removed for now) - (removed) num_in_batch: how many to batch together directly (so they can't be connected to lines separately, etc. - most common use case is if a house has 20 solar panels it's more useful to group them together) + params: load parameters for these manual additions Return: List of source_nodes """ @@ -74,7 +68,7 @@ def add_PVSystem(self, load_nodes: list[str], params = {}, num_panels: int = 1): self.num_pv += 1 return PV_nodes - def add_generator(self, num: int = 1, gen_type: GeneratorType = GeneratorType.SMALL, params = {}): + def add_generator(self, num: int = 1, gen_type: str = "small", params = {}): """ Specify parameters for a generator to add to the circuit @@ -99,63 +93,27 @@ def add_lines(self, connections: list[tuple], line_type: str = "lv", params = {} Args: connections: a list of new connections to add. Each item of the list follows the form (source1, load1) line_type: a string representing linetype if user wants to use preset parameters + params: any custom parameters for lines or transformers + transformer: whether or not to include a transformer, default yes """ for src, dst in connections: make_line(src, dst, line_type, self.num_lines, params, transformer) self.num_lines += 1 - def view_load_nodes(self, indices: list = []): - """ - View load nodes (what their parameters are) at the given indices. - - Args: - indices (optional): Which indices to view the nodes at. - If none given, display all - """ - load_nodes = [] - if not indices: - indices = [i for i in range(self.num_loads)] - - for idx in indices: - load_obj = altdss.Load["load" + str(idx)] - load_info = {} - load_info["name"] = "load" + str(idx) - load_info["kV"] = load_obj.kV - load_info["kW"] = load_obj.kW - load_info["kVar"] = load_obj.kvar - load_nodes.append(load_info) - return load_nodes - - - def view_source_node(self): - """ - View source nodes (what their parameters are) at the given indices. - - Args: - indices (optional): Which indices to view the nodes at. - If none given, display all - - TODO once capability for more source nodes is initialized - """ - source_obj = altdss.Vsource["source"] - source_info = {} - source_info["name"] = "source" - source_info["kV"] = source_obj.BasekV - return source_info - def solve(self): """ Initialize "solve" mode in AltDSS, then allowing the user to query various results on the circuit - - TODO: error handling here """ altdss.Solution.Solve() def results(self, queries: list[str], export_path = ""): """ Allow the user to query for many results at once instead of learning how to manually query - - Returns: + + Args: + queries: List of queries to fetch the result of + export_path: if specified, exports result to this string + Return: Results for each query, in a dictionary """ results = {} @@ -170,7 +128,6 @@ def clear(self): Must call after we are done using the circuit, or will cause re-creation errors. We only work with one circuit at a time, can only have one PyGridSim object at a time. - TODO: maybe this isn't necessary because it's done in the beginning """ altdss.ClearAll() self.num_loads = 0 diff --git a/pygridsim/defaults.py b/pygridsim/defaults.py index cade565..cc081d6 100644 --- a/pygridsim/defaults.py +++ b/pygridsim/defaults.py @@ -1,7 +1,6 @@ """ Set any defaults (i.e. default source voltage, default node load etc.) """ -from altdss import altdss from altdss import Connection """ Overall Defaults, used for load, sources, lines, etc. diff --git a/pygridsim/enums.py b/pygridsim/enums.py index e75a4b1..b6ed6d3 100644 --- a/pygridsim/enums.py +++ b/pygridsim/enums.py @@ -1,7 +1,5 @@ from enum import Enum -import pygridsim.defaults as defaults -# todo: update to have a name so that users can query from name class SourceType(Enum): TURBINE = "turbine" POWER_PLANT = "powerplant" diff --git a/pygridsim/lines.py b/pygridsim/lines.py index 241fad7..c9c6306 100644 --- a/pygridsim/lines.py +++ b/pygridsim/lines.py @@ -1,6 +1,6 @@ from altdss import altdss -from altdss import Transformer, Connection -from pygridsim.configs import * +from altdss import Transformer +from pygridsim.configs import LINE_CONFIGURATIONS import pygridsim.defaults as defaults from pygridsim.enums import LineType from pygridsim.parameters import get_param, random_param, check_valid_params, get_enum_obj diff --git a/pygridsim/parameters.py b/pygridsim/parameters.py index 40c6eef..0f8dcc8 100644 --- a/pygridsim/parameters.py +++ b/pygridsim/parameters.py @@ -2,9 +2,9 @@ Helper functions to parse the parameters used for loads and sources """ from altdss import altdss -from altdss import AltDSS, Transformer, Vsource, Load, PVSystem, Generator -from pygridsim.enums import * -from pygridsim.configs import * +from altdss import Load, PVSystem, Generator +from pygridsim.enums import LoadType, SourceType, GeneratorType +from pygridsim.configs import LOAD_CONFIGURATIONS, SOURCE_CONFIGURATIONS, GENERATOR_CONFIGURATIONS import pygridsim.defaults as defaults import random @@ -27,7 +27,6 @@ def random_param(range): [lower_bound, upper_bound]; range of typical value Return: Randomly selected value in range - TODO: allow for non-uniform distributions """ if type(range) is not list: return range @@ -120,7 +119,6 @@ def make_pv(load_node, params, num_panels, count): pv.Bus1 = load_node pv.Phases = get_param(params, "phases", defaults.PHASES) pv.kV = get_param(params, "kV", random_param(defaults.SOLAR_PANEL_BASE_KV) * num_panels) - # todo: inverter capacity? def make_generator(params, gen_type, count): """ diff --git a/pygridsim/results.py b/pygridsim/results.py index 6883aaa..05b1562 100644 --- a/pygridsim/results.py +++ b/pygridsim/results.py @@ -11,7 +11,6 @@ def query_solution(query): Args: query: a query for the solve function - TODO: only BusVMag, Losses, TotalPower is supported, need to make accessible which queries are supported Return: Query result or the string "Invalid" if the query is not supported """ diff --git a/sim.json b/sim.json index 52d4e25..aa5fffd 100644 --- a/sim.json +++ b/sim.json @@ -1,10 +1,10 @@ { "Voltages": { - "source": 1391.2908459682467, - "load0": 202.6090367072441 + "source": 1735.8007811315708, + "load0": 205.64441923330276 }, "Losses": { - "Active Power Loss": 78708.71838388889, - "Reactive Power Loss": 163597.67777927459 + "Active Power Loss": 198582.96141955358, + "Reactive Power Loss": 412884.39931989944 } } \ No newline at end of file diff --git a/tests/__pycache__/test_circuit.cpython-312.pyc b/tests/__pycache__/test_circuit.cpython-312.pyc index 2ecda2f..330fa56 100644 Binary files a/tests/__pycache__/test_circuit.cpython-312.pyc and b/tests/__pycache__/test_circuit.cpython-312.pyc differ diff --git a/tests/temp.py b/tests/temp.py deleted file mode 100644 index 9147595..0000000 --- a/tests/temp.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -from altdss import altdss -from altdss import AltDSS, Transformer, Vsource, Load, LoadModel, LoadShape -from dss.enums import LineUnits, SolveModes -""" -this is from colab stuff, delete later -""" - -altdss('new circuit.IEEE13Nodeckt') - -# create voltage source -source1 = altdss.Vsource[0] -source1.Bus1 = 'SourceBus' -source1.BasekV = 0.6 -source1.Phases = 3 -source1.Frequency = 60 - -# create load -load1 : Load = altdss.Load.new('load1') -load1.Bus1 = 'LoadBus' -load1.Phases = 3 -load1.kV = 200 -load1.kW = 1.2 -load1.kvar = 0.6 - -# line between voltage source and load -line1 = altdss.Line.new('line1') -line1.Phases = 3 -line1.Bus1 = 'SourceBus' -line1.Bus2 = 'LoadBus' -line1.Length = 0.1 -line1.Units = LineUnits.km - -# "solve" the circuit -altdss.Solution.Solve() -print(altdss.BusVMag()) \ No newline at end of file diff --git a/tests/test_circuit.py b/tests/test_circuit.py index f132abf..a2de2ef 100644 --- a/tests/test_circuit.py +++ b/tests/test_circuit.py @@ -1,15 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from pygridsim.core import PyGridSim -from pygridsim.enums import * -from altdss import altdss -from altdss import Connection - +from pygridsim.enums import LineType, LoadType, SourceType, GeneratorType +import unittest """Tests for `pygridsim` package.""" -import unittest - # from pygridsim import pygridsim @@ -42,9 +38,6 @@ def test_001_one_source_one_load(self): circuit.update_source(source_type="turbine") circuit.add_load_nodes(num=1, load_type="house") circuit.add_lines([("source", "load0")], "MV") - #circuit.add_transformers([("source", "load0")], params={"Conns": [Connection.wye, Connection.delta]}) - print("Load Nodes:", circuit.view_load_nodes()) - print("Source Nodes:", circuit.view_source_node()) circuit.solve() print(circuit.results(["Voltages", "Losses"])) circuit.clear() @@ -98,7 +91,6 @@ def test_006_update_multiple_source(self): circuit.add_lines([("source", "load0")], "HV") circuit.solve() print(circuit.results(["Voltages"])) - # TODO: can add assert to make sure it's in reasonable range? def test_007_export(self): circuit = PyGridSim()