Skip to content

Commit

Permalink
Merge pull request #85 from dss-extensions/dss_python-0.10.6
Browse files Browse the repository at this point in the history
ODD.py 0.5.0 based on DSS C-API/Python 0.10.6

- Add CheckForError for most API calls
- Add settings for LegacyModels (including test with the two versions of `Storage`) and ExtendedErrors
- Adjust iterator
- Add and test new PDElements functions
- Added `Bus.LineList` and `Bus.LoadList`
- Update test suite to include both `ExtendedErrors(False)` and `ExtendedErrors(True)`
- Testing running both debug and release builds of DSS C-API, using env var DSS_EXTENSIONS_DEBUG
- Added Python 3.8 to AppVeyor tests (Conda Python 3.8 on Windows was broken for awhile)
- Update version to 0.5.0
  • Loading branch information
PMeira committed Aug 2, 2020
2 parents 627eef4 + 7f8aece commit 7123a67
Show file tree
Hide file tree
Showing 50 changed files with 7,792 additions and 2,039 deletions.
7 changes: 4 additions & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ build: false

environment:
matrix:
# - PYTHON_VERSION: 3.8
# TARGET_ARCH: "x64"
# MINICONDA: C:\Miniconda3-x64
- PYTHON_VERSION: 3.8
TARGET_ARCH: "x64"
MINICONDA: C:\Miniconda3-x64
- PYTHON_VERSION: 3.7
TARGET_ARCH: "x64"
MINICONDA: C:\Miniconda3-x64
Expand Down Expand Up @@ -49,6 +49,7 @@ install:

test_script:
- py.test -vv
- set DSS_EXTENSIONS_DEBUG=1 && py.test -vv

init:
- "ECHO %PYTHON_VERSION% %MINICONDA%"
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ clean:

test:
PYTHONPATH=. py.test -vv --cov=opendssdirect tests
export DSS_EXTENSIONS_DEBUG=1
PYTHONPATH=. py.test -vv tests

html:
@cd docs; pandoc ../README.md -o readme.rst; make html
Expand Down
19 changes: 9 additions & 10 deletions opendssdirect/ActiveClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,50 @@

def ActiveClassName():
"""(read-only) Returns name of active class."""
return get_string(lib.ActiveClass_Get_ActiveClassName())
return get_string(CheckForError(lib.ActiveClass_Get_ActiveClassName()))


def AllNames():
"""(read-only) Array of strings consisting of all element names in the active class."""
return get_string_array(lib.ActiveClass_Get_AllNames)
return CheckForError(get_string_array(lib.ActiveClass_Get_AllNames))


def Count():
"""(read-only) Number of elements in Active Class. Same as NumElements Property."""
return lib.ActiveClass_Get_Count()
return CheckForError(lib.ActiveClass_Get_Count())


def First():
"""(read-only) Sets first element in the active class to be the active DSS object. If object is a CktElement, ActiveCktELment also points to this element. Returns 0 if none."""
return lib.ActiveClass_Get_First()
return CheckForError(lib.ActiveClass_Get_First())


def Name(*args):
"""Name of the Active Element of the Active Class"""
# Getter
if len(args) == 0:
return get_string(lib.ActiveClass_Get_Name())
return get_string(CheckForError(lib.ActiveClass_Get_Name()))

# Setter
Value, = args
if type(Value) is not bytes:
Value = Value.encode(codec)
lib.ActiveClass_Set_Name(Value)
CheckForError()
CheckForError(lib.ActiveClass_Set_Name(Value))


def Next():
"""(read-only) Sets next element in active class to be the active DSS object. If object is a CktElement, ActiveCktElement also points to this element. Returns 0 if no more."""
return lib.ActiveClass_Get_Next()
return CheckForError(lib.ActiveClass_Get_Next())


def NumElements():
"""(read-only) Number of elements in this class. Same as Count property."""
return lib.ActiveClass_Get_NumElements()
return CheckForError(lib.ActiveClass_Get_NumElements())


def ActiveClassParent():
"""Get the name of the parent class of the active class"""
return get_string(lib.ActiveClass_Get_ActiveClassParent())
return get_string(CheckForError(lib.ActiveClass_Get_ActiveClassParent()))


_columns = ["ActiveClassName", "Name", "NumElements", "ActiveClassParent"]
Expand Down
64 changes: 43 additions & 21 deletions opendssdirect/Basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,82 +4,80 @@


def ClearAll():
lib.DSS_ClearAll()
CheckForError(lib.DSS_ClearAll())


def Reset():
lib.DSS_Reset()
CheckForError(lib.DSS_Reset())


def SetActiveClass(ClassName):
if type(ClassName) is not bytes:
ClassName = ClassName.encode(codec)
return lib.DSS_SetActiveClass(ClassName)
return CheckForError(lib.DSS_SetActiveClass(ClassName))


def Start(code):
return lib.DSS_Start(code) != 0
return CheckForError(lib.DSS_Start(code)) != 0


def Classes():
"""(read-only) List of DSS intrinsic classes (names of the classes)"""
return get_string_array(lib.DSS_Get_Classes)
return CheckForError(get_string_array(lib.DSS_Get_Classes))


def DataPath(*args):
"""DSS Data File Path. Default path for reports, etc. from DSS"""
# Getter
if len(args) == 0:
return get_string(lib.DSS_Get_DataPath())
return get_string(CheckForError(lib.DSS_Get_DataPath()))

# Setter
Value, = args
if type(Value) is not bytes:
Value = Value.encode(codec)
lib.DSS_Set_DataPath(Value)
CheckForError()
CheckForError(lib.DSS_Set_DataPath(Value))


def DefaultEditor():
"""(read-only) Returns the path name for the default text editor."""
return get_string(lib.DSS_Get_DefaultEditor())
return get_string(CheckForError(lib.DSS_Get_DefaultEditor()))


def NumCircuits():
"""(read-only) Number of Circuits currently defined"""
return lib.DSS_Get_NumCircuits()
return CheckForError(lib.DSS_Get_NumCircuits())


def NumClasses():
"""(read-only) Number of DSS intrinsic classes"""
return lib.DSS_Get_NumClasses()
return CheckForError(lib.DSS_Get_NumClasses())


def NumUserClasses():
"""(read-only) Number of user-defined classes"""
return lib.DSS_Get_NumUserClasses()
return CheckForError(lib.DSS_Get_NumUserClasses())


def UserClasses():
"""(read-only) List of user-defined classes"""
return get_string_array(lib.DSS_Get_UserClasses)
return CheckForError(get_string_array(lib.DSS_Get_UserClasses))


def Version():
"""(read-only) Get version string for the DSS."""
return get_string(lib.DSS_Get_Version())
return get_string(CheckForError(lib.DSS_Get_Version()))


def AllowForms(*args):
"""Gets/sets whether text output is allowed"""
# Getter
if len(args) == 0:
return lib.DSS_Get_AllowForms() != 0
return CheckForError(lib.DSS_Get_AllowForms()) != 0

# Setter
Value, = args
lib.DSS_Set_AllowForms(Value)
CheckForError()
value, = args
CheckForError(lib.DSS_Set_AllowForms(value))


def ShowPanel():
Expand All @@ -100,6 +98,7 @@ def NewCircuit(name):

return "New Circuit"


def AllowEditor(*args):
"""
Gets/sets whether running the external editor for "Show" is allowed
Expand All @@ -110,12 +109,34 @@ def AllowEditor(*args):
"""
# Getter
if len(args) == 0:
return lib.DSS_Get_AllowEditor() != 0
return CheckForError(lib.DSS_Get_AllowEditor()) != 0

# Setter
value, = args
lib.DSS_Set_AllowEditor(value)
CheckForError()
CheckForError(lib.DSS_Set_AllowEditor(value))


def LegacyModels(*args):
"""
If enabled, the legacy/deprecated models for PVSystem, InvControl, Storage and StorageControl are used.
In the official OpenDSS version 9.0, the old models where removed. They are temporarily present here
but may be removed in the near future. If they are important to you, please open an issue on GitHub
or contact the authors from DSS Extensions: https://github.com/dss-extensions/
After toggling LegacyModels, run a "clear" command and the models will be loaded accordingly.
Defaults to False.
This can also be enabled by setting the environment variable DSS_CAPI_LEGACY_MODELS to 1.
(API Extension)
"""
# Getter
if len(args) == 0:
return CheckForError(lib.DSS_Get_LegacyModels()) != 0

# Setter
Value, = args
return CheckForError(lib.DSS_Set_LegacyModels(Value))


_columns = [
Expand Down Expand Up @@ -145,4 +166,5 @@ def AllowEditor(*args):
"ShowPanel",
"NewCircuit",
"AllowEditor",
"LegacyModels",
]
Loading

0 comments on commit 7123a67

Please sign in to comment.