Skip to content

Commit

Permalink
Fix Variable Calculator bug and add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
lucduron committed Nov 23, 2017
1 parent 5dce599 commit e47de88
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pyteltools/slf/Serafin.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def _get_var_index(self, var_ID):
"""!
@brief Handle data request by variable ID
@param var_ID <str>: the ID of the requested variable
@return index <int> the index (0-based) of the requested variable
@return index <int> the index of the frame (0-based)
"""
if self.header is None:
raise SerafinRequestError('Cannot extract variable from empty list (forgot read_header ?)')
Expand All @@ -553,7 +553,7 @@ def _get_var_index(self, var_ID):
def read_var_in_frame(self, time_index, var_ID):
"""!
@brief Read a single variable in a frame
@param time_index <float>: 0-based index of simulation time from the target frame
@param time_index <int>: the index of the frame (0-based)
@param var_ID <str>: variable ID
@return <numpy 1D-array>: values of the variables, of length equal to the number of nodes
"""
Expand All @@ -570,7 +570,7 @@ def read_var_in_frame(self, time_index, var_ID):
def read_var_in_frame_as_3d(self, time_index, var_ID):
"""!
@brief Read a single variable in a 3D frame
@param time_index <float>: 0-based index of simulation time from the target frame
@param time_index <int>: the index of the frame (0-based)
@param var_ID <str>: variable ID
@return <numpy 2D-array>: values of the variables with shape (planes number, number of 2D nodes)
"""
Expand All @@ -582,7 +582,7 @@ def read_var_in_frame_as_3d(self, time_index, var_ID):
def read_var_in_frame_at_layer(self, time_index, var_ID, iplan):
"""!
@brief Read a single variable in a frame at specific layer
@param time_index <float>: 0-based index of simulation time from the target frame
@param time_index <int>: the index of the frame (0-based)
@param var_ID <str>: variable ID
@param iplan <int>: 1-based index of layer
@return <numpy 1D-array>: values of the variables, of length equal to the number of nodes
Expand Down
16 changes: 15 additions & 1 deletion pyteltools/slf/expression/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ def evaluate_expressions(self, augmented_path, input_stream, selected_expression
yield time_value, value_array

def decode(self, input_stream, time_index, node_code):
"""
@param input_stream <slf.Serafin.Read>: the input Serafin
@param time_index <int>: the index of the frame (0-based)
@param node_code <str>: expression abbreviation (?)
@return <(numpy 1D-array, ???)>: node_values, node_object
"""
if node_code == 'COORDX':
return self.x, None
elif node_code == 'COORDY':
Expand All @@ -328,6 +334,11 @@ def decode(self, input_stream, time_index, node_code):
return None, self.expressions[index]

def _evaluate_expressions(self, input_stream, time_index, path):
"""!
@param input_stream <slf.Serafin.Read>: the input Serafin
@param time_index <int>: the index of the frame (0-based)
@param path <[str]>: list of expressions (?)
"""
# evaluate each node on the augmented path
values = {node: None for node in path}
for node in path:
Expand Down Expand Up @@ -357,6 +368,9 @@ def clear(self):
self.representative = None

def get_data(self, input_data):
"""!
@param input_data <slf.datatypes.SerafinData>: input SerafinData stream
"""
self.input_data = input_data
self.nb_pools = len(input_data)

Expand Down Expand Up @@ -467,7 +481,7 @@ def output_headers(self, selected_names):
output_header = data.header.copy()
output_header.empty_variables()
for name in selected_names:
output_header.add_variables_str('DUMMY', name, '')
output_header.add_variable_str('DUMMY', name, '')
yield output_header

def build_augmented_path(self, selected_expressions):
Expand Down
2 changes: 1 addition & 1 deletion pyteltools/slf/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def do_calculations_in_frame(equations, input_serafin, time_index, selected_outp
@brief Return the selected 2D variables values in a single time frame
@param equations <[slf.variables_utils.Equation]>: list of all equations necessary to compute selected variables
@param input_serafin <Serafin.Read>: input stream for reading necessary variables
@param time_index <int>: the position of time frame to read
@param time_index <int>: the index of the frame (0-based)
@param selected_output_IDs <[str]>: the short names of the selected output variables
@param output_float_type <numpy.dtype>: float32 or float64 according to the output file type
@param is_2d <bool>: True if input data is 2D
Expand Down

0 comments on commit e47de88

Please sign in to comment.