Skip to content

Commit 9ab8b59

Browse files
committed
Minimal updates for compat with DSS-Python 0.13
1 parent fe01d43 commit 9ab8b59

File tree

6 files changed

+53
-110
lines changed

6 files changed

+53
-110
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ html:
1616

1717
github: html
1818
-git branch -D gh-pages
19-
-git push origin --delete gh-pages
2019
ghp-import -n -b gh-pages -m "Update documentation" docs/_build/html
2120
git checkout gh-pages
22-
git push --set-upstream origin gh-pages
21+
git push --force --set-upstream origin gh-pages
2322
git checkout master
2423

opendssdirect/Basic.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,12 @@ def AllowEditor(*args):
116116

117117
def LegacyModels(*args):
118118
"""
119-
If enabled, the legacy/deprecated models for PVSystem, InvControl, Storage and StorageControl are used.
120-
In the official OpenDSS version 9.0, the old models where removed. They are temporarily present here
121-
but may be removed in the near future. If they are important to you, please open an issue on GitHub
122-
or contact the authors from DSS Extensions: https://github.com/dss-extensions/
123-
124-
After toggling LegacyModels, run a "clear" command and the models will be loaded accordingly.
125-
Defaults to False.
126-
127-
This can also be enabled by setting the environment variable DSS_CAPI_LEGACY_MODELS to 1.
128-
129-
NOTE: this option will be removed in a future release.
119+
LegacyModels was a flag used to toggle legacy (pre-2019) models for PVSystem, InvControl, Storage and
120+
StorageControl.
121+
In the official OpenDSS version 9.0, the old models were removed. They were temporarily present here
122+
but were also removed in DSS C-API v0.13.0.
123+
124+
**NOTE**: this function will be removed for v1.0. It is left to avoid breaking the current API too soon.
130125
131126
(API Extension)
132127
"""

opendssdirect/CktElement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def AllVariableNames():
8080

8181
def AllVariableValues():
8282
"""(read-only) Array of doubles. Values of state variables of active element if PC element."""
83-
return get_float64_array(lib.CktElement_Get_AllVariableValues)
83+
return CheckForError(get_float64_array(lib.CktElement_Get_AllVariableValues))
8484

8585

8686
def BusNames(*args):

opendssdirect/Lines.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ def IsSwitch(*args):
371371
"Name",
372372
"NormAmps",
373373
"NumCust",
374-
"Parent",
375374
"Phases",
376375
"R0",
377376
"R1",

opendssdirect/_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
# Bind to the FFI module instance. This should be refined in a future version,
77
# especially after DSS C-API 0.11 is fully released.
8-
lib = dss_py.v7.api_util.lib
9-
ffi = dss_py.v7.api_util.ffi
10-
api_util = dss_py.v7.api_util
8+
lib = dss_py.prime_api_util.lib
9+
ffi = dss_py.prime_api_util.ffi
10+
api_util = dss_py.prime_api_util
1111
codec = api_util.codec
12-
CheckForError = dss_py.v7.DSS_IR.CheckForError
12+
CheckForError = dss_py.DSS_GR.CheckForError
1313
DSSException = dss_py._cffi_api_util.DSSException
1414

1515
# Currently, we prefer the functions that return lists (suffix 2)

tests/test_opendssdirect.py

Lines changed: 41 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def dss():
1616
import opendssdirect as dss
1717

1818
dss.Error.ExtendedErrors(True)
19-
19+
dss.Text.Command("set eventlogdefault=yes")
2020
assert (
2121
dss.utils.run_command("Redirect {}".format(PATH_TO_DSS)) == ""
2222
), "Unable to find test data"
@@ -166,10 +166,6 @@ def test_module_import():
166166

167167
assert inspect.ismodule(m)
168168

169-
from opendssdirect import dss_lib as m
170-
171-
assert inspect.ismodule(m)
172-
173169

174170
def test_ActiveClass(dss):
175171

@@ -206,13 +202,13 @@ def test_configuration():
206202
# Note COM's AllowForms can only be disabled and it ignores
207203
# the user's command to reallow forms if they were previously
208204
# disabled.
209-
assert dss.Basic.AllowForms() is False, "Allow forms should be disabled by default"
205+
assert not dss.Basic.AllowForms(), "Allow forms should be disabled by default"
210206

211207
dss.Basic.AllowForms(True)
212-
assert dss.Basic.AllowForms() is True
208+
assert dss.Basic.AllowForms()
213209

214210
dss.Basic.AllowForms(False)
215-
assert dss.Basic.AllowForms() is False
211+
assert not dss.Basic.AllowForms()
216212

217213

218214
def test_13Node(dss):
@@ -268,6 +264,7 @@ def test_13Node_Basic(dss):
268264
u"Reactor",
269265
u"CapControl",
270266
u"Fault",
267+
"DynamicExp",
271268
u"Generator",
272269
u"GenDispatcher",
273270
u"Storage",
@@ -1177,8 +1174,12 @@ def test_13Node_CktElement(dss):
11771174
u"enabled",
11781175
u"like",
11791176
]
1180-
assert dss.CktElement.AllVariableNames() == []
1181-
assert dss.CktElement.AllVariableValues() == [0.0]
1177+
with pt.raises(dss.DSSException):
1178+
dss.CktElement.AllVariableNames()
1179+
1180+
with pt.raises(dss.DSSException):
1181+
dss.CktElement.AllVariableValues()
1182+
11821183
assert dss.CktElement.BusNames() == [u"671", u"692"]
11831184
assert dss.CktElement.Open(1, 0) is None
11841185
assert dss.CktElement.IsOpen(1, 0)
@@ -1509,6 +1510,15 @@ def test_13Node_CktElement(dss):
15091510
u"watt-pf",
15101511
u"watt-var",
15111512
u"kW_out_desired",
1513+
"Grid voltage",
1514+
"di/dt",
1515+
"it",
1516+
"it History",
1517+
"Rated VDC",
1518+
"Avg duty cycle",
1519+
"Target (Amps)",
1520+
"Series L",
1521+
"Max. Amps (phase)",
15121522
]
15131523
assert dss.CktElement.AllVariableValues() == [
15141524
1.0,
@@ -1524,6 +1534,15 @@ def test_13Node_CktElement(dss):
15241534
9999.0,
15251535
9999.0,
15261536
500.0,
1537+
0.0,
1538+
0.0,
1539+
0.0,
1540+
0.0,
1541+
8000.0,
1542+
0.0,
1543+
0.0,
1544+
0.0,
1545+
0.0,
15271546
]
15281547
assert dss.CktElement.Variablei(2) == 500.0
15291548
assert dss.CktElement.Variable(u"PanelkW") == 500.0
@@ -1623,8 +1642,8 @@ def test_13Node_Executive(dss):
16231642
dss.Executive.NumCommands() == 125
16241643
) # adjusted to the latest version on 2022-03-22
16251644
assert (
1626-
dss.Executive.NumOptions() == 124
1627-
) # adjusted to the latest version on 2022-02-28
1645+
dss.Executive.NumOptions() == 128
1646+
) # adjusted to the latest version on 2023-03-15
16281647
assert dss.Executive.Option(1) == u"type"
16291648
assert (
16301649
dss.Executive.OptionHelp(1)
@@ -2683,20 +2702,6 @@ def test_lines_to_dataframe(dss):
26832702
"684652": 0,
26842703
"692675": 0,
26852704
},
2686-
"Parent": {
2687-
"632633": 0,
2688-
"632645": 0,
2689-
"632670": 0,
2690-
"645646": 0,
2691-
"650632": 0,
2692-
"670671": 0,
2693-
"671680": 0,
2694-
"671684": 0,
2695-
"671692": 0,
2696-
"684611": 0,
2697-
"684652": 0,
2698-
"692675": 0,
2699-
},
27002705
"Phases": {
27012706
"632633": 3,
27022707
"632645": 2,
@@ -4735,71 +4740,6 @@ def test_xycurves_to_dataframe(dss):
47354740

47364741

47374742
def test_storage_to_dataframe(dss):
4738-
dss.dss_lib.DSS_Set_LegacyModels(1)
4739-
assert dss.dss_lib.DSS_Get_LegacyModels()
4740-
4741-
assert (
4742-
dss.utils.run_command("Redirect {}".format(PATH_TO_DSS)) == ""
4743-
), "Unable to find test data"
4744-
4745-
dss.run_command("New Storage.631")
4746-
4747-
# Legacy version
4748-
expected_dict = pd.DataFrame(
4749-
{
4750-
"%Charge": {"Storage.631": "100"},
4751-
"%Discharge": {"Storage.631": "100"},
4752-
"%EffCharge": {"Storage.631": "90"},
4753-
"%EffDischarge": {"Storage.631": "90"},
4754-
"%IdlingkW": {"Storage.631": "1"},
4755-
"%Idlingkvar": {"Storage.631": "0"},
4756-
"%R": {"Storage.631": "0"},
4757-
"%X": {"Storage.631": "50"},
4758-
"%reserve": {"Storage.631": "20"},
4759-
"%stored": {"Storage.631": "100"},
4760-
"Balanced": {"Storage.631": "No"},
4761-
"ChargeTrigger": {"Storage.631": "0"},
4762-
"DischargeTrigger": {"Storage.631": "0"},
4763-
"DispMode": {"Storage.631": "Default"},
4764-
"DynaDLL": {"Storage.631": ""},
4765-
"DynaData": {"Storage.631": ""},
4766-
"LimitCurrent": {"Storage.631": "No"},
4767-
"State": {"Storage.631": "Idling"},
4768-
"TimeChargeTrig": {"Storage.631": "2"},
4769-
"UserData": {"Storage.631": ""},
4770-
"UserModel": {"Storage.631": ""},
4771-
"Vmaxpu": {"Storage.631": "1.1"},
4772-
"Vminpu": {"Storage.631": "0.9"},
4773-
"basefreq": {"Storage.631": "60"},
4774-
"bus1": {"Storage.631": "631_1"},
4775-
"class": {"Storage.631": "1"},
4776-
"conn": {"Storage.631": "wye"},
4777-
"daily": {"Storage.631": ""},
4778-
"debugtrace": {"Storage.631": "No"},
4779-
"duty": {"Storage.631": ""},
4780-
"enabled": {"Storage.631": "Yes"},
4781-
"kVA": {"Storage.631": "25"},
4782-
"kW": {"Storage.631": "0"},
4783-
"kWhrated": {"Storage.631": "50"},
4784-
"kWhstored": {"Storage.631": "50"},
4785-
"kWrated": {"Storage.631": "25"},
4786-
"kv": {"Storage.631": "12.47"},
4787-
"kvar": {"Storage.631": "0"},
4788-
"like": {"Storage.631": ""},
4789-
"model": {"Storage.631": "1"},
4790-
"pf": {"Storage.631": "1"},
4791-
"phases": {"Storage.631": "3"},
4792-
"spectrum": {"Storage.631": ""},
4793-
"yearly": {"Storage.631": ""},
4794-
}
4795-
).to_dict()
4796-
4797-
actual_dict = dss.utils.class_to_dataframe("Storage").to_dict()
4798-
assert_dict_equal(actual_dict, expected_dict)
4799-
4800-
# New version (OpenDSS v9.0+), previsouly Storage2
4801-
dss.dss_lib.DSS_Set_LegacyModels(0)
4802-
48034743
assert not dss.dss_lib.DSS_Get_LegacyModels()
48044744

48054745
assert (
@@ -4864,10 +4804,20 @@ def test_storage_to_dataframe(dss):
48644804
"WattPriority": {"Storage.631": "No"},
48654805
"kvarMax": {"Storage.631": "25"},
48664806
"kvarMaxAbs": {"Storage.631": "25"},
4807+
"%Idlingkvar": {"Storage.631": ""},
4808+
"ControlMode": {"Storage.631": "GFL"},
4809+
"DynOut": {"Storage.631": []},
4810+
"DynamicEq": {"Storage.631": ""},
4811+
"Kp": {"Storage.631": "0.01"},
4812+
"PITol": {"Storage.631": "0"},
4813+
"SafeMode": {"Storage.631": "No"},
4814+
"SafeVoltage": {"Storage.631": "80"},
4815+
"kVDC": {"Storage.631": "8"},
48674816
}
48684817
).to_dict()
48694818

48704819
actual_dict = dss.utils.class_to_dataframe("Storage").to_dict()
4820+
48714821
assert_dict_equal(actual_dict, expected_dict)
48724822

48734823

0 commit comments

Comments
 (0)