Add mesh_stats checks and field_operations features#51
Add mesh_stats checks and field_operations features#51alexbenedicto wants to merge 36 commits intomainfrom
Conversation
…om/GEOS-DEV/geosPythonPackages into origin/benedicto/followUpMeshStats
…rrays available in the source data + better error handling
| from dataclasses import dataclass | ||
| from geos.mesh.doctor.checks.vtk_utils import ( VtkOutput, get_points_coords_from_vtk, get_cell_centers_array, | ||
| get_vtm_filepath_from_pvd, get_vtu_filepaths_from_vtm, | ||
| get_all_array_names, read_mesh, write_mesh ) |
There was a problem hiding this comment.
I would move the "local" imports at the end
| class Options: | ||
| support: str # choice between 'cell' and 'point' to operate on fields | ||
| source: str # file from where the data is collected | ||
| operations: list[ tuple[ str ] ] # [ ( function0, new_name0 ), ... ] |
There was a problem hiding this comment.
From the comment, it seems like we expect exactly 2 str in the tuple. Would something like list[ tuple[ str, str ] ] work?
|
|
||
| Returns: | ||
| array: [ distance0, distance1, ..., distanceN ] with N being the number of support elements. | ||
| """ |
There was a problem hiding this comment.
Looks like a great opportunity to use your support_construction defined at L30.
| Returns: | ||
| array: Array of size N being the number of support elements. | ||
| """ | ||
| if support == __SUPPORT_CHOICES[ 0 ]: |
There was a problem hiding this comment.
It's tempting to have a seperate function that would return the number of elements, especially if the support_choices list is intended to grow in the future.
That would avoid changing the code everywhere it is repeated, like L209.
|
|
||
|
|
||
| def get_random_field( mesh: vtkUnstructuredGrid, support: str ) -> array: | ||
| f"""For a specific support type {__SUPPORT_CHOICES}, an array with samples from a uniform distribution over [0, 1). |
There was a problem hiding this comment.
In the doc string, "returns an array..."
| for i in range( result.number_cell_types ): | ||
| logging.info( f"\t{result.cell_types[ i ]}\t\t({result.cell_type_counts[ i ]} cells)" ) |
There was a problem hiding this comment.
For readability and as you did L80, we could do:
| for i in range( result.number_cell_types ): | |
| logging.info( f"\t{result.cell_types[ i ]}\t\t({result.cell_type_counts[ i ]} cells)" ) | |
| for cell_type, type_count in zip(result.number_cell_types, result.cell_type_counts ): | |
| logging.info( f"\t{cell_type}\t\t({type_count} cells)" ) |
| for field_name, validity_range in data.items(): | ||
| is_valid: bool = validity_range[ 0 ] | ||
| min_max: tuple[ float ] = validity_range[ 1 ] |
There was a problem hiding this comment.
| for field_name, validity_range in data.items(): | |
| is_valid: bool = validity_range[ 0 ] | |
| min_max: tuple[ float ] = validity_range[ 1 ] | |
| for field_name, (is_valid, min_max) in data.items(): |
| if options.write_stats: | ||
| if is_valid_to_write_folder( options.output_folder ): |
There was a problem hiding this comment.
| if options.write_stats: | |
| if is_valid_to_write_folder( options.output_folder ): | |
| if options.write_stats and is_valid_to_write_folder( options.output_folder ): |
| for i, sub_grid in enumerate( sub_grids ): | ||
| for name, value in sub_grids_values[ i ].items(): |
There was a problem hiding this comment.
| for i, sub_grid in enumerate( sub_grids ): | |
| for name, value in sub_grids_values[ i ].items(): | |
| for sub_grid, sub_grid_value in zip(sub_grids, sub_grids_values): | |
| for name, value in sub_grid_value.items(): |
| } | ||
|
|
||
|
|
||
| def get_vtu_filepaths( options: Options ) -> tuple[ str ]: |
There was a problem hiding this comment.
At some point, could maybe be moved to the vtk utils ?
|
The mesh-doctor features developed here can be readded in future PR to create vtk filters for mesh-doctor. |
Closes #50
Followed the previous work on PR #19 and closes #19.
Two features added: