Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opendss ordering #411

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions ditto/writers/opendss/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pandas as pd

from functools import reduce
from functools import cmp_to_key

# DiTTo imports
from ditto.models.node import Node
Expand Down Expand Up @@ -143,6 +144,41 @@ def float_to_str(self, f):
d1 = ctx.create_decimal(repr(f))
return format(d1, "f")

def order_output(self,s1,s2):
""" Order the outputs as:
- wiredata
- CNDATA
- linegeometry
- linecodes
- lines
- transformers
- regulators
- loadshapes
- loads
- capacitors
"""
ordered_elements = ['wiredata','CNDATA','linegeometry','linecodes','lines','transformers','regulators','loadshapes','loads','capacitors','storage','PVSystems']
for element_key in ordered_elements:
element = self.output_filenames[element_key]
if element in s1 and not element in s2:
return -1
if element in s2 and not element in s1:
return 1
if element in s1 and element in s2:
if s1<s2:
return -1
if s2<s1:
return 1
if s1==s2:
return 0
if s1<s2:
return -1
if s2<s1:
return 1
if s1==s2:
return 0


def write(self, model, separate_feeders = False, separate_substations = False, write_taps=False, verbose=False):
"""General writing function responsible for calling the sub-functions.

Expand Down Expand Up @@ -4056,17 +4092,15 @@ def write_master_file(self, model):
substation_name in self.substations_redirect
and feeder_name == ""
): # i.e. it's a substation
for element in self.substations_redirect[substation_name]:
for element in sorted(self.substations_redirect[substation_name],key=cmp_to_key(self.order_output)):
fp.write("Redirect " + element + "\n")
if (
os.path.join(substation_name, feeder_name)
in self.feeders_redirect
and not os.path.join(substation_name, feeder_name).strip("/")
in self.substations_redirect
): # i.e. it's a feeder
for element in self.feeders_redirect[
os.path.join(substation_name, feeder_name)
]:
for element in sorted(self.feeders_redirect[os.path.join(substation_name, feeder_name)], key=cmp_to_key(self.order_output)):
fp.write("Redirect " + element + "\n")
if i.substation_name + "_" + i.feeder_name in self._baseKV_feeders_:
_baseKV_list_ = list(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def run(self):
"Programming Language :: Python :: 3.6",
],
test_suite="tests",
install_requires=["click~=8.0.4", "future~=0.18.2", "networkx~=2.5.1", "six~=1.16.0", "traitlets~=5.1.1", "json_tricks~=3.16.1", numpy_dependency],
install_requires=["click~=8.0.4", "future~=0.18.2", "networkx~=2.5.1", "six~=1.16.0", "traitlets~=5.1.1", "json_tricks~=3.16.1", "pandas~=1.3.5", numpy_dependency],
extras_require={
"all": extras_requires
+ opendss_requires
Expand Down