Skip to content

Commit 53f9909

Browse files
committed
Finalize output API; New cython bindings for expanded API; docs; unit tests #204, #162, #163, #184, #180
1 parent 9efa97a commit 53f9909

File tree

3 files changed

+131
-132
lines changed

3 files changed

+131
-132
lines changed

python/epaswmm/output/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
NodeAttribute,
99
LinkAttribute,
1010
SystemAttribute,
11+
SWMMOutputException,
1112
Output,
1213
)

python/epaswmm/output/output.pyx

+107-109
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class SWMMOutputException(Exception):
279279
"""
280280
Exception class for SWMM output file processing errors.
281281
"""
282-
def __init__(self, message:):
282+
def __init__(self, message: str) -> None:
283283
"""
284284
Constructor to initialize the exception message.
285285

@@ -824,137 +824,135 @@ cdef class Output:
824824

825825
return results
826826

827-
# cpdef dict get_subcatchment_values_by_time_and_attribute(self, int time_index, int attribute):
828-
# """
829-
# Method to get the subcatchment values for all subcatchments for a given time index and attribute.
830-
831-
# :param time_index: Time index.
832-
# :type time_index: int
833-
# :param attribute: Subcatchment attribute.
834-
# :type attribute: SubcatchAttribute
835-
# :return: Subcatchment values for all subcatchments.
836-
# :rtype: Dict[str, float]
837-
# """
838-
839-
# cdef int error_code = 0
840-
# cdef float* values = NULL
841-
# cdef int length = 0
842-
843-
# print(f"Testing {time_index} {attribute}")
844-
845-
# error_code = SMO_getSubcatchAttribute(
846-
# self._output_file_handle,
847-
# time_index,
848-
# <SMO_subcatchAttribute>attribute,
849-
# &values,
850-
# &length
851-
# )
827+
cpdef dict get_subcatchment_values_by_time_and_attribute(self, int time_index, int attribute):
828+
"""
829+
Method to get the subcatchment values for all subcatchments for a given time index and attribute.
830+
831+
:param time_index: Time index.
832+
:type time_index: int
833+
:param attribute: Subcatchment attribute.
834+
:type attribute: SubcatchAttribute
835+
:return: Subcatchment values for all subcatchments.
836+
:rtype: Dict[str, float]
837+
"""
838+
839+
cdef int error_code = 0
840+
cdef float* values = NULL
841+
cdef int length = 0
842+
843+
error_code = SMO_getSubcatchAttribute(
844+
self._output_file_handle,
845+
time_index,
846+
<SMO_subcatchAttribute>attribute,
847+
&values,
848+
&length
849+
)
852850

853-
# self.__validate_error_code(error_code)
851+
self.__validate_error_code(error_code)
854852

855-
# subcatchment_values = dict(zip(self.get_element_names(ElementType.SUBCATCHMENT), <float[:length]>values))
853+
subcatchment_values = dict(zip(self.get_element_names(ElementType.SUBCATCHMENT.value), <float[:length]>values))
856854

857-
# if values != NULL:
858-
# free(values)
855+
if values != NULL:
856+
free(values)
859857

860-
# return subcatchment_values
858+
return subcatchment_values
861859

862-
# cpdef dict get_node_values_by_time_and_attribute(self, int time_index, int attribute):
863-
# """
864-
# Method to get the node values for all nodes for a given time index and attribute.
860+
cpdef dict get_node_values_by_time_and_attribute(self, int time_index, int attribute):
861+
"""
862+
Method to get the node values for all nodes for a given time index and attribute.
865863
866-
# :param time_index: Time index.
867-
# :type time_index: int
868-
# :param attribute: Node attribute.
869-
# :type attribute: NodeAttribute
870-
# :return: Node values for all nodes.
871-
# :rtype: Dict[str, float]
872-
# """
864+
:param time_index: Time index.
865+
:type time_index: int
866+
:param attribute: Node attribute.
867+
:type attribute: NodeAttribute
868+
:return: Node values for all nodes.
869+
:rtype: Dict[str, float]
870+
"""
873871

874-
# cdef int error_code = 0
875-
# cdef float* values = NULL
876-
# cdef int length = 0
872+
cdef int error_code = 0
873+
cdef float* values = NULL
874+
cdef int length = 0
877875

878-
# error_code = SMO_getNodeAttribute(
879-
# self._output_file_handle,
880-
# time_index, <SMO_nodeAttribute>attribute,
881-
# &values,
882-
# &length
883-
# )
876+
error_code = SMO_getNodeAttribute(
877+
self._output_file_handle,
878+
time_index, <SMO_nodeAttribute>attribute,
879+
&values,
880+
&length
881+
)
884882

885-
# self.__validate_error_code(error_code)
883+
self.__validate_error_code(error_code)
886884

887-
# node_values = dict(zip(self.get_element_names(ElementType.NODE), <float[:length]>values))
885+
node_values = dict(zip(self.get_element_names(ElementType.NODE.value), <float[:length]>values))
888886

889-
# if values != NULL:
890-
# free(values)
887+
if values != NULL:
888+
free(values)
891889

892-
# return node_values
893-
894-
# cpdef dict get_link_values_by_time_and_attribute(self, int time_index, int attribute):
895-
# """
896-
# Method to get the link values for all links for a given time index and attribute.
897-
898-
# :param time_index: Time index.
899-
# :type time_index: int
900-
# :param attribute: Link attribute.
901-
# :type attribute: LinkAttribute
902-
# :return: Link values for all links.
903-
# :rtype: Dict[str, float]
904-
# """
905-
906-
# cdef int error_code = 0
907-
# cdef float* values = NULL
908-
# cdef int length = 0
909-
910-
# error_code = SMO_getLinkAttribute(
911-
# self._output_file_handle,
912-
# time_index, <SMO_linkAttribute>attribute,
913-
# &values,
914-
# &length
915-
# )
890+
return node_values
891+
892+
cpdef dict get_link_values_by_time_and_attribute(self, int time_index, int attribute):
893+
"""
894+
Method to get the link values for all links for a given time index and attribute.
895+
896+
:param time_index: Time index.
897+
:type time_index: int
898+
:param attribute: Link attribute.
899+
:type attribute: LinkAttribute
900+
:return: Link values for all links.
901+
:rtype: Dict[str, float]
902+
"""
903+
904+
cdef int error_code = 0
905+
cdef float* values = NULL
906+
cdef int length = 0
907+
908+
error_code = SMO_getLinkAttribute(
909+
self._output_file_handle,
910+
time_index, <SMO_linkAttribute>attribute,
911+
&values,
912+
&length
913+
)
916914

917-
# self.__validate_error_code(error_code)
915+
self.__validate_error_code(error_code)
918916

919-
# link_values = dict(zip(self.get_element_names(ElementType.LINK), <float[:length]>values))
917+
link_values = dict(zip(self.get_element_names(ElementType.LINK.value), <float[:length]>values))
920918

921-
# if values != NULL:
922-
# free(values)
919+
if values != NULL:
920+
free(values)
923921

924-
# return link_values
922+
return link_values
925923

926-
# cpdef dict get_system_values_by_time_and_attribute(self, int time_index, int attribute):
927-
# """
928-
# Method to get the system values for a given time index and attribute.
924+
cpdef dict get_system_values_by_time_and_attribute(self, int time_index, int attribute):
925+
"""
926+
Method to get the system values for a given time index and attribute.
929927
930-
# :param time_index: Time index.
931-
# :type time_index: int
932-
# :param attribute: System attribute.
933-
# :type attribute: SystemAttribute
934-
# :return: System values.
935-
# :rtype: Dict[str, float]
936-
# """
937-
938-
# cdef int error_code = 0
939-
# cdef float* values = NULL
940-
# cdef int length = 0
941-
942-
# error_code = SMO_getSystemAttribute(
943-
# self._output_file_handle,
944-
# time_index, <SMO_systemAttribute>attribute,
945-
# &values,
946-
# &length
947-
# )
928+
:param time_index: Time index.
929+
:type time_index: int
930+
:param attribute: System attribute.
931+
:type attribute: SystemAttribute
932+
:return: System values.
933+
:rtype: Dict[str, float]
934+
"""
935+
936+
cdef int error_code = 0
937+
cdef float* values = NULL
938+
cdef int length = 0
939+
940+
error_code = SMO_getSystemAttribute(
941+
self._output_file_handle,
942+
time_index, <SMO_systemAttribute>attribute,
943+
&values,
944+
&length
945+
)
948946

949-
# self.__validate_error_code(error_code)
947+
self.__validate_error_code(error_code)
950948

951-
# system_values = dict(zip([SubcatchAttribute(attribute).name], <float[:length]>values))
949+
system_values = dict(zip([SubcatchAttribute(attribute).name], <float[:length]>values))
952950

953951

954-
# if values != NULL:
955-
# free(values)
952+
if values != NULL:
953+
free(values)
956954

957-
# return system_values
955+
return system_values
958956

959957
cpdef dict get_subcatchment_values_by_time_and_element_index(self, int time_index, int element_index):
960958
"""

0 commit comments

Comments
 (0)