Skip to content

Commit

Permalink
Merge pull request #6 from yasirroni/check_case_16am
Browse files Browse the repository at this point in the history
add example using loadcase
  • Loading branch information
yasirroni authored Jun 30, 2024
2 parents 4e56b40 + d6d8a1a commit b5bf8bb
Show file tree
Hide file tree
Showing 5 changed files with 759 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Octave
octave-workspace

# Local
tests/results/*.xlsx

Expand Down
45 changes: 35 additions & 10 deletions matpowercaseframes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,11 @@ def __init__(self, data, update_index=True):
TypeError: Error input data invalid.
"""
# TODO: support read excel
# TODO: support Path object
if isinstance(data, str):
# TYPE: str of path | str of matpower case name
if not os.path.isfile(data):
# TYPE: str of matpower case name
if MATPOWER_EXIST:
data_ = os.path.join(matpower.path_matpower, f"data/{data}")
if os.path.isfile(data_):
data = data_
else:
raise FileNotFoundError
path = self._get_path(data)
# TYPE: str of path
self._read_matpower(filepath=data)
self._read_matpower(filepath=path)
elif isinstance(data, dict):
# TYPE: dict | oct2py.io.Struct
self._read_oct2py_struct(struct=data)
Expand All @@ -64,6 +57,30 @@ def __init__(self, data, update_index=True):
if update_index:
self._update_index()

@staticmethod
def _get_path(path):
# TYPE: str of path | str of matpower case name
if os.path.isfile(path):
return path

path_added_m = path + '.m'
if os.path.isfile(path_added_m):
return path_added_m

# TYPE: str of matpower case name
if MATPOWER_EXIST:
path_added_matpower = os.path.join(matpower.path_matpower, f"data/{path}")
if os.path.isfile(path_added_matpower):
return path_added_matpower

path_added_matpower_m = os.path.join(
matpower.path_matpower, f"data/{path_added_m}"
)
if os.path.isfile(path_added_matpower_m):
return path_added_matpower_m

raise FileNotFoundError

def _read_matpower(self, filepath):
# ! Old attribute is not guaranted to be replaced in re-read
with open(filepath) as f:
Expand Down Expand Up @@ -259,3 +276,11 @@ def to_dict(self):
else:
data[attribute] = getattr(self, attribute).values.tolist()
return data

def to_mpc(self):
"""
Convert CaseFrames into matpower-compatible data, that is dictionary
The value of the data will be in str, numeric, and list.
"""
return self.to_dict()
Loading

0 comments on commit b5bf8bb

Please sign in to comment.