Skip to content

Commit

Permalink
Merged in cuihantao/andes_github/psse-read-improve (pull request #9)
Browse files Browse the repository at this point in the history
Improve PSS/E RAW file read speed.

Approved-by: Qiwei Zhang <qzhang41@vols.utk.edu>
  • Loading branch information
cuihantao authored and qzhang41 committed Oct 26, 2018
2 parents e21c04a + ab76f23 commit 6d28043
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
20 changes: 13 additions & 7 deletions andes/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,21 @@ def get_field(self, field, idx=None, astype=None):
# =================================================================

uid = self.get_uid(idx)
if not astype:
astype = type(self.__dict__[field])

ret = matrix(self.__dict__[field])[uid]
field_data = self.__dict__[field]

if isinstance(idx, (float, int, str)):
return ret
else:
return astype(ret)
if isinstance(field_data, matrix):
ret = field_data[uid]
elif isinstance(field_data, list):
if isinstance(idx, (float, int, str)):
ret = field_data[uid]
else:
ret = [field_data[x] for x in uid]

if astype is not None:
ret = astype(ret)

return ret

def _alloc(self):
"""
Expand Down
2 changes: 2 additions & 0 deletions andes/models/zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class Area(Zone):
def __init__(self, system, name):
super().__init__(system, name)
self._name = 'Area'
self._group = 'Collection'
self._init()

def setup(self):
Expand All @@ -221,6 +222,7 @@ class Region(Zone):
def __init__(self, system, name):
super().__init__(system, name)
self._name = 'Region'
self._group = 'Balancing'
self._params.extend(['Ptol', 'slack'])
self._descr.update({
'Ptol': 'Total transfer capacity',
Expand Down
8 changes: 7 additions & 1 deletion andes/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ def __init__(self, system, name):
self.name = name
self.all_models = []
self._idx_model = {}
self._idx = []

def register_model(self, model):
"""
Expand All @@ -650,9 +651,14 @@ def register_element(self, model, idx):
if idx is None:
idx = model + '_' + str(len(self._idx_model))

assert idx not in self._idx_model.values()
# TODO: `in` a list test is slow for large lists. Consider `bisect`
if idx in self._idx:
raise IndexError("Model {} idx {} already exist in model {}".
format(model, idx, self._idx_model[idx]))

self._idx_model[idx] = model
self._idx.append(idx)

return idx

def get_field(self, field, idx):
Expand Down

0 comments on commit 6d28043

Please sign in to comment.