Skip to content

Commit c1b7f52

Browse files
committed
Batch: Include more metadata in the DSS Obj classes to allow filtering collections by a float property.
1 parent 00a64c6 commit c1b7f52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1124
-14
lines changed

altdss/AutoTrans.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,46 @@ class AutoTrans(DSSObj, CircuitElementMixin, PDElementMixin, TransformerObjMixin
1616
__slots__ = DSSObj._extra_slots + CircuitElementMixin._extra_slots + PDElementMixin._extra_slots + TransformerObjMixin._extra_slots
1717
_cls_name = 'AutoTrans'
1818
_cls_idx = 41
19+
_cls_int_idx = {
20+
1,
21+
2,
22+
3,
23+
11,
24+
30,
25+
33,
26+
39,
27+
40,
28+
48,
29+
}
30+
_cls_float_idx = {
31+
6,
32+
7,
33+
8,
34+
9,
35+
10,
36+
17,
37+
18,
38+
19,
39+
21,
40+
22,
41+
23,
42+
24,
43+
25,
44+
26,
45+
27,
46+
28,
47+
29,
48+
31,
49+
32,
50+
35,
51+
36,
52+
42,
53+
43,
54+
44,
55+
45,
56+
46,
57+
47,
58+
}
1959
_cls_prop_idx = {
2060
'phases': 1,
2161
'windings': 2,

altdss/Batch.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,27 +196,44 @@ def __init__(self, api_util, **kwargs):
196196
return
197197

198198
idx = kwargs.get('idx')
199-
if regexp is not None:
200-
idx, idx_ptr, idx_cnt = self._prepare_int32_array(idx)
199+
if idx is not None:
200+
idx, idx_ptr, idx_cnt = self._prepare_int32_array(np.asarray(idx) + 1)
201201
self._lib.Batch_CreateByIndex(ptrptr, countptr, self._cls_idx, idx_ptr, idx_cnt)
202202
self._wrap_ptr(ptrptr, countptr)
203203
self._check_for_error()
204204
return
205205

206-
(prop_name, intval), = kwargs.items()
206+
(prop_name, val), = kwargs.items()
207207
prop_idx = self._obj_cls._cls_prop_idx.get(prop_name.lower())
208208
if prop_idx is None:
209-
raise ValueError('Invalid property name "{}"'.format(prop_name))
210-
self._lib.Batch_CreateByInt32Property(ptrptr, countptr, self._cls_idx, prop_idx, intval)
209+
raise ValueError(f'Invalid property name "{prop_name}"')
210+
211+
if isinstance(val, int) and prop_idx in self._obj_cls._cls_int_idx:
212+
# Single integer value for an integer property
213+
self._lib.Batch_CreateByInt32Property(ptrptr, countptr, self._cls_idx, prop_idx, val)
214+
kwargs = None
215+
elif prop_idx in self._obj_cls._cls_float_idx:
216+
if isinstance(val, LIST_LIKE) and len(val) == 2 and isinstance(val[0], (int, float)):
217+
# Range of values for a float property
218+
self._lib.Batch_CreateByFloat64PropertyRange(ptrptr, countptr, self._cls_idx, prop_idx, *val)
219+
kwargs = None
220+
elif isinstance(val, (int, float)):
221+
# Single value for a float property
222+
self._lib.Batch_CreateByFloat64PropertyRange(ptrptr, countptr, self._cls_idx, prop_idx, val, val)
223+
kwargs = None
224+
225+
if kwargs is not None:
226+
raise ValueError(f'Property "{prop_name}" cannot be used to create a filtered batch with value {repr(val)}.')
227+
211228
self._wrap_ptr(ptrptr, countptr)
212229
self._check_for_error()
213230

214231
def begin_edit(self) -> None:
215232
'''
216233
Marks for editing all DSS objects in the batch
217234
218-
In the editing mode, some final side-effects of changing properties are post-poned
219-
until `_end_edit` is called. This side-effects can be somewhat costly, like updating
235+
In the editing mode, some final side-effects of changing properties are postponed
236+
until `end_edit` is called. This side-effects can be somewhat costly, like updating
220237
the model parameters or internal matrices.
221238
222239
If you don't have any performance constraint, you may edit each property individually

altdss/CNData.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@ class CNData(DSSObj):
1313
__slots__ = DSSObj._extra_slots
1414
_cls_name = 'CNData'
1515
_cls_idx = 10
16+
_cls_int_idx = {
17+
1,
18+
11,
19+
13,
20+
15,
21+
19,
22+
}
23+
_cls_float_idx = {
24+
2,
25+
3,
26+
4,
27+
5,
28+
6,
29+
7,
30+
8,
31+
9,
32+
10,
33+
12,
34+
14,
35+
16,
36+
17,
37+
18,
38+
21,
39+
}
1640
_cls_prop_idx = {
1741
'k': 1,
1842
'diastrand': 2,

altdss/CapControl.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ class CapControl(DSSObj, CircuitElementMixin):
1616
__slots__ = DSSObj._extra_slots + CircuitElementMixin._extra_slots
1717
_cls_name = 'CapControl'
1818
_cls_idx = 24
19+
_cls_int_idx = {
20+
2,
21+
4,
22+
10,
23+
15,
24+
16,
25+
18,
26+
25,
27+
}
28+
_cls_float_idx = {
29+
5,
30+
6,
31+
7,
32+
8,
33+
9,
34+
11,
35+
12,
36+
13,
37+
14,
38+
21,
39+
24,
40+
}
1941
_cls_prop_idx = {
2042
'element': 1,
2143
'terminal': 2,

altdss/Capacitor.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ class Capacitor(DSSObj, CircuitElementMixin, PDElementMixin):
1515
__slots__ = DSSObj._extra_slots + CircuitElementMixin._extra_slots + PDElementMixin._extra_slots
1616
_cls_name = 'Capacitor'
1717
_cls_idx = 22
18+
_cls_int_idx = {
19+
3,
20+
6,
21+
12,
22+
20,
23+
}
24+
_cls_float_idx = {
25+
5,
26+
14,
27+
15,
28+
16,
29+
17,
30+
18,
31+
19,
32+
}
1833
_cls_prop_idx = {
1934
'bus1': 1,
2035
'bus2': 2,

altdss/DSSObj.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ def begin_edit(self) -> None:
260260
'''
261261
Marks a DSS object for editing
262262
263-
In the editing mode, some final side-effects of changing properties are post-poned
264-
until `_end_edit` is called. This side-effects can be somewhat costly, like updating
263+
In the editing mode, some final side-effects of changing properties are postponed
264+
until `end_edit` is called. This side-effects can be somewhat costly, like updating
265265
the model parameters or internal matrices.
266266
267267
If you don't have any performance constraint, you may edit each property individually

altdss/DynamicExp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ class DynamicExp(DSSObj):
1313
__slots__ = DSSObj._extra_slots
1414
_cls_name = 'DynamicExp'
1515
_cls_idx = 26
16+
_cls_int_idx = {
17+
1,
18+
4,
19+
6,
20+
}
21+
_cls_float_idx = {
22+
}
1623
_cls_prop_idx = {
1724
'nvariables': 1,
1825
'varnames': 2,

altdss/ESPVLControl.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ class ESPVLControl(DSSObj, CircuitElementMixin):
1414
__slots__ = DSSObj._extra_slots + CircuitElementMixin._extra_slots
1515
_cls_name = 'ESPVLControl'
1616
_cls_idx = 38
17+
_cls_int_idx = {
18+
2,
19+
3,
20+
13,
21+
}
22+
_cls_float_idx = {
23+
4,
24+
5,
25+
12,
26+
}
1727
_cls_prop_idx = {
1828
'element': 1,
1929
'terminal': 2,

altdss/EnergyMeter.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,30 @@ class EnergyMeter(DSSObj, CircuitElementMixin, EnergyMeterObjMixin, ElementHasRe
1616
__slots__ = DSSObj._extra_slots + CircuitElementMixin._extra_slots + EnergyMeterObjMixin._extra_slots + ElementHasRegistersMixin._extra_slots
1717
_cls_name = 'EnergyMeter'
1818
_cls_idx = 48
19+
_cls_int_idx = {
20+
2,
21+
9,
22+
11,
23+
12,
24+
13,
25+
14,
26+
15,
27+
16,
28+
17,
29+
26,
30+
}
31+
_cls_float_idx = {
32+
5,
33+
6,
34+
18,
35+
19,
36+
20,
37+
21,
38+
22,
39+
23,
40+
24,
41+
25,
42+
}
1943
_cls_prop_idx = {
2044
'element': 1,
2145
'terminal': 2,

altdss/ExpControl.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ class ExpControl(DSSObj, CircuitElementMixin):
1313
__slots__ = DSSObj._extra_slots + CircuitElementMixin._extra_slots
1414
_cls_name = 'ExpControl'
1515
_cls_idx = 43
16+
_cls_int_idx = {
17+
10,
18+
12,
19+
16,
20+
}
21+
_cls_float_idx = {
22+
2,
23+
3,
24+
4,
25+
5,
26+
6,
27+
7,
28+
8,
29+
9,
30+
11,
31+
13,
32+
15,
33+
}
1634
_cls_prop_idx = {
1735
'pvsystemlist': 1,
1836
'vreg': 2,

0 commit comments

Comments
 (0)