-
Notifications
You must be signed in to change notification settings - Fork 22
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
Try to convert dss.Properties.Value() return to numbers #104
Comments
This will be addressed by the new low-level API. It should be merged very soon to DSS C-API. |
I'm working on the documentation of the new property system for dss-extensions/dss_capi#109, and probably will complement it to achieve better results for the dataframe usage. I'll post a link to the results here when I finish so we can gather feedback on it. For a quick intro, the new system doesn't keep the string copies of the inputs anymore, so we can copy the raw data directly in most cases. I almost integrated Apache Arrow into this, but decided to avoid complicating things in Pascal even more. As an example of my current tests, these are the dtypes that result from building a dataframe for loads using the new Batch API:
Besides the types, a bonus is that this is around 20x faster than the current approach using the old property API. |
That looks great! Thanks. |
No dataframes yet, but in the latest release we have two alternatives. I believe that the next steps of development will address JSONimport json
import opendssdirect as odd
from dss import DSSJSONFlags as flags
odd.Basic.SetActiveClass("Load")
items = json.loads(odd.ActiveClass.ToJSON(flags.Full)) Items is a list of dicts like: {'DSSClass': 'Load',
'name': '25609_a',
'phases': 1,
'bus1': 'ckt7.1',
'kV': 7.2,
'kW': 2351.25,
'pf': 0.95,
'model': 1,
'yearly': '25609_a',
'daily': None,
'duty': None,
'growth': None,
'conn': 'wye',
'kvar': 772.8185023018021,
'Rneut': -1.0,
'Xneut': 0.0,
'status': 'Variable',
'class': 1,
'Vminpu': 0.85,
'Vmaxpu': 1.05,
'Vminnorm': 0.0,
'Vminemerg': 0.0,
'xfkVA': 0.0,
'allocationfactor': 0.5,
'kVA': 2475.0,
'%mean': 50.0,
'%stddev': 10.0,
'CVRwatts': 1.0,
'CVRvars': 2.0,
'kwh': 0.0,
'kwhdays': 30.0,
'Cfactor': 4.0,
'CVRcurve': None,
'NumCust': 1,
'ZIPV': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
'%SeriesRL': 50.0,
'RelWeight': 1.0,
'Vlowpu': 0.5,
'puXharm': 0.0,
'XRharm': 6.0,
'spectrum': 'defaultload',
'basefreq': 60.0,
'enabled': True,
'like': ''} This may not be as fast as the other alternative I mentioned in March (using the batch operations), but should be reliable and shouldn't break. Without The last two (state and debug) will be added for a future version. The dataframe support will be similar in terms of options. Applying New APIThis is more experimental and should change a bit still. Feedback is welcome 🙂 Currently, all OpenDSS objects are exposed in DSS Python in import json
from dss import DSS
obj = DSS.Obj
DSS.Text.Command = 'redirect electricdss-tst/Version8/Distrib/EPRITestCircuits/epri_dpv/J1/Master_withPV.dss'
for item in obj.PVSystem:
print(item) Prints:
We are not restricted to the "Active..." of the classic OpenDSS API, the following works fine: l1, l2 = obj.Load[1], obj.Load[10]
print(l1.name, l2.name) Each item and the batches expose a Everything is using type annotations and enums where possible: load = obj.Load[300]
load.conn
Type completion on IDEs seems to like that. The property help strings from OpenDSS are there too, so it's easier to know what is what: Any property that is an object (or list of objects) can be accessed in two ways, just the name(s), or the actual object(s): DSS.Text.Command = 'redirect electricdss-tst/Version8/Distrib/EPRITestCircuits/ckt5/Master_ckt5.dss'
load = obj.Load[100]
print([load.yearly, load.yearly_obj])
Batch operations work like: load_batch = obj.Load.batch(phases=1)
len(load_batch) # 1381
load_batch = obj.Load.batch(re='^.*cust4$')
len(load_batch) # 65 For ints and floats, batches operate on proxies to avoid copying everything several times: Things like We implement the array protocol though, so other operations return NumPy arrays (and there's a So, the dataframe functions will be basically selecting the columns from a batch and returning a proper dataframe. |
With the latest releases, I added some tests that better illustrate the new API, including creating the whole circuit without any .DSS text/code, creating objects one by one, or through the batch API:
It needs just a bit more work to get to a stable version, notably dss-extensions/dss-extensions#15 |
New notebook with a few notes and examples on the updated JSON export: https://github.com/dss-extensions/dss_python/blob/master/docs/examples/JSON.ipynb |
Feature Request
The return of
dss.Properties.Value()
is always a string. That leaves it to the higher-level application to attempt to convert the strings to a float or int. A secondary effect is thatdss.utils.class_to_dataframe()
also returns numeric data as strings.Can OpenDSSDirect perform the conversion automatically so that users don't have to do it? I'm sure that you don't want to break the existing API. And perhaps you would prefer to push this to users.
The text was updated successfully, but these errors were encountered: