From 2b33592c664a82b98f7f7b3ef4dc4547c9ec6705 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Thu, 19 Sep 2019 15:14:01 +0200 Subject: [PATCH] Example renames --- .../GrpcInterface/Python/rips/Properties.py | 18 ++++++++--------- .../rips/PythonExamples/CaseGridGroup.py | 6 +++--- .../CaseInfoStreamingExample.py | 12 +++++------ .../rips/PythonExamples/CommandExample.py | 6 +++--- .../rips/PythonExamples/ErrorHandling.py | 4 ++-- .../rips/PythonExamples/InputPropTestAsync.py | 10 +++++----- .../rips/PythonExamples/InputPropTestSync.py | 6 +++--- .../SetFlowDiagnosticsResult.py | 8 ++++---- .../rips/PythonExamples/SetGridProperties.py | 4 ++-- .../rips/PythonExamples/SoilAverageAsync.py | 4 ++-- .../rips/PythonExamples/SoilAverageSync.py | 4 ++-- .../rips/PythonExamples/SoilPorvAsync.py | 20 +++++++++---------- .../rips/PythonExamples/SoilPorvSync.py | 10 +++++----- .../Python/rips/PythonExamples/ViewExample.py | 6 +++--- .../Python/rips/tests/test_properties.py | 2 +- 15 files changed, 60 insertions(+), 60 deletions(-) diff --git a/ApplicationCode/GrpcInterface/Python/rips/Properties.py b/ApplicationCode/GrpcInterface/Python/rips/Properties.py index 898b527bf7..ae448ada8b 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/Properties.py +++ b/ApplicationCode/GrpcInterface/Python/rips/Properties.py @@ -26,8 +26,8 @@ class Properties: case(Case): A rips case to handle properties for """ self.case = case - self.propertiesStub = Properties_pb2_grpc.PropertiesStub(self.case.channel) - self.chunkSize = 8160 + self._properties_stub = Properties_pb2_grpc.PropertiesStub(self.case.channel) + self.chunk_size = 8160 def __generate_property_input_iterator(self, values_iterator, parameters): @@ -49,7 +49,7 @@ class Properties: chunk.params.CopyFrom(parameters) index += 1 else: - actual_chunk_size = min(len(array) - index + 1, self.chunkSize) + actual_chunk_size = min(len(array) - index + 1, self.chunk_size) chunk.values.CopyFrom(Properties_pb2.PropertyChunk(values = array[index:index+actual_chunk_size])) index += actual_chunk_size @@ -80,7 +80,7 @@ class Properties: request = Properties_pb2.AvailablePropertiesRequest (case_request = Case_pb2.CaseRequest(id=self.case.id), property_type = property_type_enum, porosity_model = porosity_model_enum) - return self.propertiesStub.GetAvailableProperties(request).property_names + return self._properties_stub.GetAvailableProperties(request).property_names def active_cell_property_async(self, property_type, property_name, time_step, porosity_model = 'MATRIX_MODEL'): """Get a cell property for all active cells. Async, so returns an iterator @@ -102,7 +102,7 @@ class Properties: property_name = property_name, time_step = time_step, porosity_model = porosity_model_enum) - for chunk in self.propertiesStub.GetActiveCellProperty(request): + for chunk in self._properties_stub.GetActiveCellProperty(request): yield chunk def active_cell_property(self, property_type, property_name, time_step, porosity_model = 'MATRIX_MODEL'): @@ -147,7 +147,7 @@ class Properties: time_step = time_step, grid_index = gridIndex, porosity_model = porosity_model_enum) - for chunk in self.propertiesStub.GetGridProperty(request): + for chunk in self._properties_stub.GetGridProperty(request): yield chunk def grid_property(self, property_type, property_name, time_step, grid_index = 0, porosity_model = 'MATRIX_MODEL'): @@ -189,7 +189,7 @@ class Properties: porosity_model = porosity_model_enum) request_iterator = self.__generate_property_input_iterator(values_iterator, request) - self.propertiesStub.SetActiveCellProperty(request_iterator) + self._properties_stub.SetActiveCellProperty(request_iterator) def set_active_cell_property(self, values, property_type, property_name, time_step, porosity_model = 'MATRIX_MODEL'): """Set a cell property for all active cells. @@ -209,7 +209,7 @@ class Properties: time_step = time_step, porosity_model = porosity_model_enum) request_iterator = self.__generate_property_input_chunks(values, request) - reply = self.propertiesStub.SetActiveCellProperty(request_iterator) + reply = self._properties_stub.SetActiveCellProperty(request_iterator) if reply.accepted_value_count < len(values): raise IndexError @@ -233,7 +233,7 @@ class Properties: grid_index = grid_index, porosity_model = porosity_model_enum) request_iterator = self.__generate_property_input_chunks(values, request) - reply = self.propertiesStub.SetGridProperty(request_iterator) + reply = self._properties_stub.SetGridProperty(request_iterator) if reply.accepted_value_count < len(values): raise IndexError \ No newline at end of file diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/CaseGridGroup.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/CaseGridGroup.py index 1b2c4a5b6d..6285e823eb 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/CaseGridGroup.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/CaseGridGroup.py @@ -23,7 +23,7 @@ case_group.print_object_info() resinsight.commands.compute_case_group_statistics(case_group_id=case_group.group_id) view = case_group.views()[0] -cellResult = view.set_cell_result() -cellResult.set_value("ResultVariable", "PRESSURE_DEV") -cellResult.update() +cell_result = view.set_cell_result() +cell_result.set_value("ResultVariable", "PRESSURE_DEV") +cell_result.update() \ No newline at end of file diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/CaseInfoStreamingExample.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/CaseInfoStreamingExample.py index 3f5dbb4ca8..6a5ce6d880 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/CaseInfoStreamingExample.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/CaseInfoStreamingExample.py @@ -12,16 +12,16 @@ resinsight = rips.Instance.find() case = resinsight.project.case(id = 0) # Get the cell count object -cellCounts = case.cell_count() -print("Number of active cells: " + str(cellCounts.active_cell_count)) -print("Total number of reservoir cells: " + str(cellCounts.reservoir_cell_count)) +cell_counts = case.cell_count() +print("Number of active cells: " + str(cell_counts.active_cell_count)) +print("Total number of reservoir cells: " + str(cell_counts.reservoir_cell_count)) # Get information for all active cells -activeCellInfos = case.cell_info_for_active_cells() +active_cell_infos = case.cell_info_for_active_cells() # A simple check on the size of the cell info -assert(cellCounts.active_cell_count == len(activeCellInfos)) +assert(cell_counts.active_cell_count == len(active_cell_infos)) # Print information for the first active cell print("First active cell: ") -print(activeCellInfos[0]) +print(active_cell_infos[0]) diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/CommandExample.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/CommandExample.py index 4617563fe8..6835ac7442 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/CommandExample.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/CommandExample.py @@ -36,7 +36,7 @@ with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname: resinsight.commands.export_property_in_views(0, "3D View", 0) # Check that the exported file exists - expectedFileName = case.name + "-" + str("3D_View") + "-" + "T3" + "-SOIL" - fullPath = tmpdirname + "/" + expectedFileName - assert(os.path.exists(fullPath)) + expected_file_name = case.name + "-" + str("3D_View") + "-" + "T3" + "-SOIL" + full_path = tmpdirname + "/" + expected_file_name + assert(os.path.exists(full_path)) diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ErrorHandling.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ErrorHandling.py index 841c9430a2..d3605519f8 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ErrorHandling.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ErrorHandling.py @@ -19,7 +19,7 @@ except grpc.RpcError as e: case = resinsight.project.case(id=0) if case is not None: results = case.properties.active_cell_property('STATIC_NATIVE', 'PORO', 0) - activeCellCount = len(results) + active_cell_count = len(results) # Send the results back to ResInsight inside try / except construct try: @@ -43,7 +43,7 @@ if case is not None: # With a chunk size exactly matching the active cell count the server will not # be able to see any error as it will successfully close the stream after receiving # the correct number of values, even if the python client has more chunks to send - case.properties.chunkSize = activeCellCount + case.properties.chunk_size = active_cell_count try: case.properties.set_active_cell_property(results, 'GENERATED', 'POROAPPENDED', 0) diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/InputPropTestAsync.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/InputPropTestAsync.py index 534fbf0dd0..ca2390d92c 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/InputPropTestAsync.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/InputPropTestAsync.py @@ -7,9 +7,9 @@ import time # Internal function for creating a result from a small chunk of poro and permx results # The return value of the function is a generator for the results rather than the result itself. -def createResult(poroChunks, permxChunks): +def create_result(poro_chunks, permx_chunks): # Loop through all the chunks of poro and permx in order - for (poroChunk, permxChunk) in zip(poroChunks, permxChunks): + for (poroChunk, permxChunk) in zip(poro_chunks, permx_chunks): resultChunk = [] # Loop through all the values inside the chunks, in order for (poro, permx) in zip(poroChunk.values, permxChunk.values): @@ -22,14 +22,14 @@ start = time.time() case = resinsight.project.case(id=0) # Get a generator for the poro results. The generator will provide a chunk each time it is iterated -poroChunks = case.properties.active_cell_property_async('STATIC_NATIVE', 'PORO', 0) +poro_chunks = case.properties.active_cell_property_async('STATIC_NATIVE', 'PORO', 0) # Get a generator for the permx results. The generator will provide a chunk each time it is iterated -permxChunks = case.properties.active_cell_property_async('STATIC_NATIVE', 'PERMX', 0) +permx_chunks = case.properties.active_cell_property_async('STATIC_NATIVE', 'PERMX', 0) # Send back the result with the result provided by a generator object. # Iterating the result generator will cause the script to read from the poro and permx generators # And return the result of each iteration -case.properties.set_active_cell_property_async(createResult(poroChunks, permxChunks), +case.properties.set_active_cell_property_async(create_result(poro_chunks, permx_chunks), 'GENERATED', 'POROPERMXAS', 0) end = time.time() diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/InputPropTestSync.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/InputPropTestSync.py index dd021e3f5d..b38de90a41 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/InputPropTestSync.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/InputPropTestSync.py @@ -12,13 +12,13 @@ start = time.time() case = resinsight.project.case(id=0) # Read poro result into list -poroResults = case.properties.active_cell_property('STATIC_NATIVE', 'PORO', 0) +poro_results = case.properties.active_cell_property('STATIC_NATIVE', 'PORO', 0) # Read permx result into list -permxResults = case.properties.active_cell_property('STATIC_NATIVE', 'PERMX', 0) +permx_results = case.properties.active_cell_property('STATIC_NATIVE', 'PERMX', 0) # Generate output result results = [] -for (poro, permx) in zip(poroResults, permxResults): +for (poro, permx) in zip(poro_results, permx_results): results.append(poro * permx) try: diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SetFlowDiagnosticsResult.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SetFlowDiagnosticsResult.py index d438cf1622..1fdbcc91e5 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SetFlowDiagnosticsResult.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SetFlowDiagnosticsResult.py @@ -8,11 +8,11 @@ import rips resinsight = rips.Instance.find() view = resinsight.project.view(0) -#view.apply_flow_diagnostics_cell_result(resultVariable='Fraction', -# selectionMode='FLOW_TR_INJ_AND_PROD') +#view.apply_flow_diagnostics_cell_result(result_variable='Fraction', +# selection_mode='FLOW_TR_INJ_AND_PROD') # Example of setting individual wells. Commented out because well names are case specific. -view.apply_flow_diagnostics_cell_result(resultVariable='Fraction', - selectionMode='FLOW_TR_BY_SELECTION', +view.apply_flow_diagnostics_cell_result(result_variable='Fraction', + selection_mode='FLOW_TR_BY_SELECTION', injectors = ['C-1H', 'C-2H', 'F-2H'], producers = ['B-1AH', 'B-3H', 'D-1H']) diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SetGridProperties.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SetGridProperties.py index 8038bcb196..837ccf0833 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SetGridProperties.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SetGridProperties.py @@ -6,10 +6,10 @@ import rips resinsight = rips.Instance.find() case = resinsight.project.case(id=0) -totalCellCount = case.cell_count().reservoir_cell_count +total_cell_count = case.cell_count().reservoir_cell_count values = [] -for i in range(0, totalCellCount): +for i in range(0, total_cell_count): values.append(i % 2 * 0.75); print("Applying values to full grid") diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilAverageAsync.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilAverageAsync.py index cd8a86baaf..9aa25c50d3 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilAverageAsync.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilAverageAsync.py @@ -20,13 +20,13 @@ averages = [] for i in range(0, len(timeSteps)): # Get the results from time step i asynchronously # It actually returns a generator object almost immediately - resultChunks = case.properties.active_cell_property_async('DYNAMIC_NATIVE', 'SOIL', i) + result_chunks = case.properties.active_cell_property_async('DYNAMIC_NATIVE', 'SOIL', i) mysum = 0.0 count = 0 # Loop through and append the average. each time we loop resultChunks # We will trigger a read of the input data, meaning the script will start # Calculating averages before the whole resultValue for this time step has been received - for chunk in resultChunks: + for chunk in result_chunks: mysum += sum(chunk.values) count += len(chunk.values) diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilAverageSync.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilAverageSync.py index 374c965a11..ca82dd4218 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilAverageSync.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilAverageSync.py @@ -14,10 +14,10 @@ case = resinsight.project.case(id=0) case = resinsight.project.case(id=0) # Get a list of all time steps -timeSteps = case.time_steps() +time_steps = case.time_steps() averages = [] -for i in range(0, len(timeSteps)): +for i in range(0, len(time_steps)): # Get a list of all the results for time step i results = case.properties.active_cell_property('DYNAMIC_NATIVE', 'SOIL', i) mysum = sum(results) diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilPorvAsync.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilPorvAsync.py index e1c443eba6..fbc6369d9a 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilPorvAsync.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilPorvAsync.py @@ -7,12 +7,12 @@ import time # Internal function for creating a result from a small chunk of soil and porv results # The return value of the function is a generator for the results rather than the result itself. -def createResult(soilChunks, porvChunks): - for (soilChunk, porvChunk) in zip(soilChunks, porvChunks): +def create_result(soil_chunks, porv_chunks): + for (soil_chunk, porv_chunk) in zip(soil_chunks, porv_chunks): resultChunk = [] number = 0 - for (soilValue, porvValue) in zip(soilChunk.values, porvChunk.values): - resultChunk.append(soilValue * porvValue) + for (soil_value, porv_value) in zip(soil_chunk.values, porv_chunk.values): + resultChunk.append(soil_value * porv_value) # Return a Python generator yield resultChunk @@ -22,20 +22,20 @@ case = resinsight.project.case(id=0) timeStepInfo = case.time_steps() # Get a generator for the porv results. The generator will provide a chunk each time it is iterated -porvChunks = case.properties.active_cell_property_async('STATIC_NATIVE', 'PORV', 0) +porv_chunks = case.properties.active_cell_property_async('STATIC_NATIVE', 'PORV', 0) # Read the static result into an array, so we don't have to transfer it for each iteration # Note we use the async method even if we synchronise here, because we need the values chunked # ... to match the soil chunks -porvArray = [] -for porvChunk in porvChunks: - porvArray.append(porvChunk) +porv_array = [] +for porv_chunk in porv_chunks: + porv_array.append(porv_chunk) for i in range (0, len(timeStepInfo)): # Get a generator object for the SOIL property for time step i - soilChunks = case.properties.active_cell_property_async('DYNAMIC_NATIVE', 'SOIL', i) + soil_chunks = case.properties.active_cell_property_async('DYNAMIC_NATIVE', 'SOIL', i) # Create the generator object for the SOIL * PORV derived result - result_generator = createResult(soilChunks, iter(porvArray)) + result_generator = create_result(soil_chunks, iter(porv_array)) # Send back the result asynchronously with a generator object case.properties.set_active_cell_property_async(result_generator, 'GENERATED', 'SOILPORVAsync', i) diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilPorvSync.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilPorvSync.py index c895bf3f43..459ca922b1 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilPorvSync.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/SoilPorvSync.py @@ -10,16 +10,16 @@ start = time.time() case = resinsight.project.case(id=0) # Read the full porv result -porvResults = case.properties.active_cell_property('STATIC_NATIVE', 'PORV', 0) -timeStepInfo = case.time_steps() +porv_results = case.properties.active_cell_property('STATIC_NATIVE', 'PORV', 0) +time_step_info = case.time_steps() -for i in range (0, len(timeStepInfo)): +for i in range (0, len(time_step_info)): # Read the full SOIl result for time step i - soilResults = case.properties.active_cell_property('DYNAMIC_NATIVE', 'SOIL', i) + soil_results = case.properties.active_cell_property('DYNAMIC_NATIVE', 'SOIL', i) # Generate the result by looping through both lists in order results = [] - for (soil, porv) in zip(soilResults, porvResults): + for (soil, porv) in zip(soil_results, porv_results): results.append(soil * porv) # Send back result diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ViewExample.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ViewExample.py index fdde45c8e1..99a1e0a5b8 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ViewExample.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ViewExample.py @@ -21,7 +21,7 @@ if resinsight is not None: # Update the view in ResInsight view.update() # Clone the first view - newView = views[0].clone() + new_view = views[0].clone() view.set_show_grid_box(False) - newView.set_background_color("#FFAA33") - newView.update() \ No newline at end of file + new_view.set_background_color("#FFAA33") + new_view.update() diff --git a/ApplicationCode/GrpcInterface/Python/rips/tests/test_properties.py b/ApplicationCode/GrpcInterface/Python/rips/tests/test_properties.py index ac25a21295..7ba6c08340 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/tests/test_properties.py +++ b/ApplicationCode/GrpcInterface/Python/rips/tests/test_properties.py @@ -55,7 +55,7 @@ def test_10k_set_out_of_bounds_client(rips_instance, initialize_test): case = rips_instance.project.load_case(path=casePath) results = case.properties.active_cell_property('DYNAMIC_NATIVE', 'SOIL', 1) - case.properties.chunkSize = len(results) + case.properties.chunk_size = len(results) results.append(5.0) with pytest.raises(IndexError): assert case.properties.set_active_cell_property(results, 'GENERATED', 'SOIL', 1)