Skip to content

Commit 55657f5

Browse files
committed
Update to the last version of the main and fix conflicts
2 parents 8cf9037 + 168105c commit 55657f5

File tree

40 files changed

+1095
-820
lines changed

40 files changed

+1095
-820
lines changed

.github/workflows/typing-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
# working-directory: ./${{ matrix.package-name }}
3131
run: |
3232
python -m pip install --upgrade pip
33-
python -m pip install mypy ruff types-PyYAML
33+
python -m pip install mypy ruff types-PyYAML types-pytz
3434
3535
- name: Typing check with mypy
3636
# working-directory: ./${{ matrix.package-name }}

docs/geos-utils.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ PhysicalConstants module
6363
:undoc-members:
6464
:show-inheritance:
6565

66+
pieceEnum module
67+
------------------------------
68+
69+
.. automodule:: geos.utils.pieceEnum
70+
:members:
71+
:undoc-members:
72+
:show-inheritance:
73+
6674
UnitRepository module
6775
-------------------------------------
6876

geos-mesh/src/geos/mesh/utils/arrayHelpers.py

Lines changed: 166 additions & 135 deletions
Large diffs are not rendered by default.

geos-mesh/src/geos/mesh/utils/arrayModifiers.py

Lines changed: 100 additions & 82 deletions
Large diffs are not rendered by default.

geos-mesh/tests/conftest.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
# ruff: noqa: E402 # disable Module level import not at top of file
66
import os
77
import pytest
8-
from typing import Union, Any, Tuple, Dict
8+
from typing import Union, Any
99
import numpy as np
1010
import numpy.typing as npt
1111

1212
from vtkmodules.vtkCommonDataModel import vtkDataSet, vtkMultiBlockDataSet, vtkPolyData
1313
from vtkmodules.vtkIOXML import vtkXMLGenericDataObjectReader
1414

15+
from geos.utils.pieceEnum import Piece
16+
1517

1618
@pytest.fixture
1719
def arrayExpected( request: pytest.FixtureRequest ) -> npt.NDArray[ np.float64 ]:
@@ -198,19 +200,19 @@ def getElementMap() -> Any:
198200
"""Get the element indexes mapping dictionary using the function _get_elementMap() between two meshes.
199201
200202
Returns:
201-
elementMap (Dict[int, npt.NDArray[np.int64]]): The cell mapping dictionary.
203+
elementMap (dict[int, npt.NDArray[np.int64]]): The cell mapping dictionary.
202204
"""
203205

204-
def _get_elementMap( meshFromName: str, meshToName: str, points: bool ) -> Dict[ int, npt.NDArray[ np.int64 ] ]:
206+
def _get_elementMap( meshFromName: str, meshToName: str, piece: Piece ) -> dict[ int, npt.NDArray[ np.int64 ] ]:
205207
"""Get the element indexes mapping dictionary between two meshes.
206208
207209
Args:
208210
meshFromName (str): The name of the meshFrom.
209211
meshToName (str): The name of the meshTo.
210-
points (bool): True if elements to map is points, False if it is cells.
212+
piece (Piece): The element to map.
211213
212214
Returns:
213-
elementMap (Dict[int, npt.NDArray[np.int64]]): The element mapping dictionary.
215+
elementMap (dict[int, npt.NDArray[np.int64]]): The element mapping dictionary.
214216
"""
215217
sharedCells2D3DId: npt.NDArray[ np.int64 ] = np.array(
216218
[ [ 0, 0 ], [ 1, 1 ], [ 2, 2 ], [ 3, 3 ], [ 4, 4 ], [ 5, 5 ], [ 6, 6 ], [ 7, 7 ], [ 8, 8 ], [ 9, 9 ],
@@ -238,8 +240,8 @@ def _get_elementMap( meshFromName: str, meshToName: str, points: bool ) -> Dict[
238240
)
239241
sharedPoints1D2DId: npt.NDArray[ np.int64 ] = np.array( [ [ 0, 26 ] ], dtype=np.int64 )
240242
sharedPoints1D3DId: npt.NDArray[ np.int64 ] = np.array( [ [ 0, 475 ] ], dtype=np.int64 )
241-
elementMap: Dict[ int, npt.NDArray[ np.int64 ] ] = {}
242-
nbElements: Tuple[ int, int, int ] = ( 4092, 212, 11 ) if points else ( 1740, 156, 10 )
243+
elementMap: dict[ int, npt.NDArray[ np.int64 ] ] = {}
244+
nbElements: tuple[ int, int, int ] = ( 4092, 212, 11 ) if piece == Piece.POINTS else ( 1740, 156, 10 )
243245
if meshFromName == "well":
244246
if meshToName == "emptyWell":
245247
elementMap[ 0 ] = np.array( [ [ 0, element ] for element in range( nbElements[ 2 ] ) ] )

geos-mesh/tests/test_arrayHelpers.py

Lines changed: 131 additions & 133 deletions
Large diffs are not rendered by default.

geos-mesh/tests/test_arrayModifiers.py

Lines changed: 144 additions & 146 deletions
Large diffs are not rendered by default.

geos-processing/src/geos/processing/generic_processing_tools/AttributeMapping.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from geos.mesh.utils.arrayModifiers import transferAttributeWithElementMap
1111
from geos.mesh.utils.arrayHelpers import ( computeElementMapping, getAttributeSet, isAttributeGlobal )
1212
from geos.utils.Logger import ( Logger, getLogger )
13+
from geos.utils.pieceEnum import Piece
1314

1415
__doc__ = """
1516
AttributeMapping is a vtk filter that transfers global attributes from a source mesh to a final mesh with same
@@ -41,15 +42,15 @@
4142
meshTo: Union[ vtkDataSet, vtkMultiBlockDataSet ]
4243
attributeNames: set[ str ]
4344
# Optional inputs.
44-
onPoints: bool # defaults to False
45+
piece: Piece # defaults to Piece.CELLS
4546
speHandler: bool # defaults to False
4647
4748
# Instantiate the filter
4849
attributeMappingFilter: AttributeMapping = AttributeMapping(
4950
meshFrom,
5051
meshTo,
5152
attributeNames,
52-
onPoints,
53+
piece,
5354
speHandler,
5455
)
5556
@@ -77,7 +78,7 @@ def __init__(
7778
meshFrom: Union[ vtkDataSet, vtkMultiBlockDataSet ],
7879
meshTo: Union[ vtkDataSet, vtkMultiBlockDataSet ],
7980
attributeNames: set[ str ],
80-
onPoints: bool = False,
81+
piece: Piece = Piece.CELLS,
8182
speHandler: bool = False,
8283
) -> None:
8384
"""Transfer global attributes from a source mesh to a final mesh.
@@ -88,22 +89,20 @@ def __init__(
8889
meshFrom (Union[vtkDataSet, vtkMultiBlockDataSet]): The source mesh with attributes to transfer.
8990
meshTo (Union[vtkDataSet, vtkMultiBlockDataSet]): The final mesh where to transfer attributes.
9091
attributeNames (set[str]): Names of the attributes to transfer.
91-
onPoints (bool): True if attributes are on points, False if they are on cells.
92-
Defaults to False.
92+
piece (Piece): The piece of the attribute.
93+
Defaults to Piece.CELLS.
9394
speHandler (bool, optional): True to use a specific handler, False to use the internal handler.
9495
Defaults to False.
9596
"""
9697
self.meshFrom: Union[ vtkDataSet, vtkMultiBlockDataSet ] = meshFrom
9798
self.meshTo: Union[ vtkDataSet, vtkMultiBlockDataSet ] = meshTo
9899
self.attributeNames: set[ str ] = attributeNames
99-
self.onPoints: bool = onPoints
100-
# TODO/refact (@RomainBaville) make it an enum
101-
self.piece: str = "points" if self.onPoints else "cells"
100+
self.piece: Piece = piece
102101

103-
# cell map
102+
# Element map
104103
self.ElementMap: dict[ int, npt.NDArray[ np.int64 ] ] = {}
105104

106-
# Logger.
105+
# Logger
107106
self.logger: Logger
108107
if not speHandler:
109108
self.logger = getLogger( loggerTitle, True )
@@ -149,41 +148,40 @@ def applyFilter( self: Self ) -> None:
149148
self.logger.info( f"Apply filter { self.logger.name }." )
150149

151150
if len( self.attributeNames ) == 0:
152-
raise ValueError( f"Please enter at least one { self.piece } attribute to transfer." )
151+
raise ValueError( "Please enter at least one attribute to transfer." )
153152

154-
attributesInMeshFrom: set[ str ] = getAttributeSet( self.meshFrom, self.onPoints )
153+
attributesInMeshFrom: set[ str ] = getAttributeSet( self.meshFrom, self.piece )
155154
wrongAttributeNames: set[ str ] = self.attributeNames.difference( attributesInMeshFrom )
156155
if len( wrongAttributeNames ) > 0:
157-
raise AttributeError(
158-
f"The { self.piece } attributes { wrongAttributeNames } are not present in the source mesh." )
156+
raise AttributeError( f"The attributes { wrongAttributeNames } are not present in the source mesh." )
159157

160-
attributesInMeshTo: set[ str ] = getAttributeSet( self.meshTo, self.onPoints )
158+
attributesInMeshTo: set[ str ] = getAttributeSet( self.meshTo, self.piece )
161159
attributesAlreadyInMeshTo: set[ str ] = self.attributeNames.intersection( attributesInMeshTo )
162160
if len( attributesAlreadyInMeshTo ) > 0:
163161
raise AttributeError(
164-
f"The { self.piece } attributes { attributesAlreadyInMeshTo } are already present in the final mesh." )
162+
f"The attributes { attributesAlreadyInMeshTo } are already present in the final mesh." )
165163

166164
if isinstance( self.meshFrom, vtkMultiBlockDataSet ):
167165
partialAttributes: list[ str ] = []
168166
for attributeName in self.attributeNames:
169-
if not isAttributeGlobal( self.meshFrom, attributeName, self.onPoints ):
167+
if not isAttributeGlobal( self.meshFrom, attributeName, self.piece ):
170168
partialAttributes.append( attributeName )
171169

172170
if len( partialAttributes ) > 0:
173171
raise AttributeError(
174-
f"All { self.piece } attributes to transfer must be global, { partialAttributes } are partials." )
172+
f"All attributes to transfer must be global, { partialAttributes } are partials." )
175173

176-
self.ElementMap = computeElementMapping( self.meshFrom, self.meshTo, self.onPoints )
174+
self.ElementMap = computeElementMapping( self.meshFrom, self.meshTo, self.piece )
177175
sharedElement: bool = False
178176
for key in self.ElementMap:
179177
if np.any( self.ElementMap[ key ] > -1 ):
180178
sharedElement = True
181179

182180
if not sharedElement:
183-
raise ValueError( f"The two meshes do not have any shared { self.piece }." )
181+
raise ValueError( f"The two meshes do not have any shared { self.piece.value }." )
184182

185183
for attributeName in self.attributeNames:
186-
transferAttributeWithElementMap( self.meshFrom, self.meshTo, self.ElementMap, attributeName, self.onPoints,
184+
transferAttributeWithElementMap( self.meshFrom, self.meshTo, self.ElementMap, attributeName, self.piece,
187185
self.logger )
188186

189187
# Log the output message.
@@ -195,5 +193,5 @@ def _logOutputMessage( self: Self ) -> None:
195193
"""Create and log result messages of the filter."""
196194
self.logger.info( f"The filter { self.logger.name } succeeded." )
197195
self.logger.info(
198-
f"The { self.piece } attributes { self.attributeNames } have been transferred from the source mesh to the final mesh with the { self.piece } mapping."
196+
f"The attributes { self.attributeNames } have been transferred from the source mesh to the final mesh with the { self.piece.value } mapping."
199197
)

geos-processing/src/geos/processing/generic_processing_tools/CreateConstantAttributePerRegion.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import vtkmodules.util.numpy_support as vnp
1212
from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet, vtkDataSet
1313

14+
from geos.utils.pieceEnum import Piece
1415
from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler )
1516
from geos.mesh.utils.arrayHelpers import ( getArrayInObject, getComponentNames, getNumberOfComponents,
1617
getVtkDataTypeInObject, isAttributeGlobal, getAttributePieceInfo,
@@ -116,9 +117,7 @@ def __init__(
116117
# Region attribute settings.
117118
self.regionName: str = regionName
118119
self.dictRegionValues: dict[ Any, Any ] = dictRegionValues
119-
self.onPoints: Union[ None, bool ]
120-
self.onBoth: bool
121-
self.onPoints, self.onBoth = getAttributePieceInfo( self.mesh, self.regionName )
120+
self.piece: Piece = getAttributePieceInfo( self.mesh, self.regionName )
122121

123122
# Check if the new component have default values (information for the output message).
124123
self.useDefaultValue: bool = False
@@ -165,15 +164,15 @@ def applyFilter( self: Self ) -> None:
165164
self.logger.addHandler( self.counter )
166165

167166
# Check the validity of the attribute region.
168-
if self.onPoints is None:
167+
if self.piece == Piece.NONE:
169168
raise AttributeError( f"The attribute { self.regionName } is not in the mesh." )
170169

171-
if self.onBoth:
170+
if self.piece == Piece.BOTH:
172171
raise AttributeError(
173172
f"There are two attributes named { self.regionName }, one on points and the other on cells. The region attribute must be unique."
174173
)
175174

176-
nbComponentsRegion: int = getNumberOfComponents( self.mesh, self.regionName, self.onPoints )
175+
nbComponentsRegion: int = getNumberOfComponents( self.mesh, self.regionName, self.piece )
177176
if nbComponentsRegion != 1:
178177
raise AttributeError( f"The region attribute { self.regionName } has to many components, one is requires." )
179178

@@ -192,11 +191,11 @@ def applyFilter( self: Self ) -> None:
192191
newArray: npt.NDArray[ Any ]
193192
if isinstance( self.mesh, vtkMultiBlockDataSet ):
194193
# Check if the attribute region is global.
195-
if not isAttributeGlobal( self.mesh, self.regionName, self.onPoints ):
194+
if not isAttributeGlobal( self.mesh, self.regionName, self.piece ):
196195
raise AttributeError( f"The region attribute { self.regionName } has to be global." )
197196

198197
validIndexes, invalidIndexes = checkValidValuesInMultiBlock( self.mesh, self.regionName, listIndexes,
199-
self.onPoints )
198+
self.piece )
200199
if len( validIndexes ) == 0:
201200
if len( self.dictRegionValues ) == 0:
202201
self.logger.warning( "No region index entered." )
@@ -208,7 +207,7 @@ def applyFilter( self: Self ) -> None:
208207
self.defaultValue,
209208
self.newAttributeName,
210209
componentNames=self.componentNames,
211-
onPoints=self.onPoints,
210+
piece=self.piece,
212211
logger=self.logger )
213212

214213
else:
@@ -221,18 +220,18 @@ def applyFilter( self: Self ) -> None:
221220
for flatIdDataSet in listFlatIdDataSet:
222221
dataSet: vtkDataSet = vtkDataSet.SafeDownCast( self.mesh.GetDataSet( flatIdDataSet ) )
223222

224-
regionArray = getArrayInObject( dataSet, self.regionName, self.onPoints )
223+
regionArray = getArrayInObject( dataSet, self.regionName, self.piece )
225224
newArray = self._createArrayFromRegionArrayWithValueMap( regionArray )
226225
createAttribute( dataSet,
227226
newArray,
228227
self.newAttributeName,
229228
componentNames=self.componentNames,
230-
onPoints=self.onPoints,
229+
piece=self.piece,
231230
logger=self.logger )
232231

233232
else:
234233
validIndexes, invalidIndexes = checkValidValuesInDataSet( self.mesh, self.regionName, listIndexes,
235-
self.onPoints )
234+
self.piece )
236235
if len( validIndexes ) == 0:
237236
if len( self.dictRegionValues ) == 0:
238237
self.logger.warning( "No region index entered." )
@@ -244,21 +243,21 @@ def applyFilter( self: Self ) -> None:
244243
self.defaultValue,
245244
self.newAttributeName,
246245
componentNames=self.componentNames,
247-
onPoints=self.onPoints,
246+
piece=self.piece,
248247
logger=self.logger )
249248

250249
else:
251250
if len( invalidIndexes ) > 0:
252251
self.logger.warning(
253252
f"The region indexes { invalidIndexes } are not in the region attribute { self.regionName }." )
254253

255-
regionArray = getArrayInObject( self.mesh, self.regionName, self.onPoints )
254+
regionArray = getArrayInObject( self.mesh, self.regionName, self.piece )
256255
newArray = self._createArrayFromRegionArrayWithValueMap( regionArray )
257256
createAttribute( self.mesh,
258257
newArray,
259258
self.newAttributeName,
260259
componentNames=self.componentNames,
261-
onPoints=self.onPoints,
260+
piece=self.piece,
262261
logger=self.logger )
263262

264263
# Log the output message.
@@ -274,7 +273,7 @@ def _setInfoRegion( self: Self ) -> None:
274273
"""
275274
# Get the numpy type from the vtk typecode.
276275
dictType: dict[ int, Any ] = vnp.get_vtk_to_numpy_typemap()
277-
regionVtkType: int = getVtkDataTypeInObject( self.mesh, self.regionName, self.onPoints )
276+
regionVtkType: int = getVtkDataTypeInObject( self.mesh, self.regionName, self.piece )
278277
regionNpType: type = dictType[ regionVtkType ]
279278

280279
# Set the correct type of values and region index.
@@ -348,11 +347,10 @@ def _logOutputMessage( self: Self, trueIndexes: list[ Any ] ) -> None:
348347

349348
# Info about the created attribute.
350349
# The piece where the attribute is created.
351-
piece: str = "points" if self.onPoints else "cells"
352-
self.logger.info( f"The new attribute { self.newAttributeName } is created on { piece }." )
350+
self.logger.info( f"The new attribute { self.newAttributeName } is created on { self.piece.value }." )
353351

354352
# The number of component and they names if multiple.
355-
componentNamesCreated: tuple[ str, ...] = getComponentNames( self.mesh, self.newAttributeName, self.onPoints )
353+
componentNamesCreated: tuple[ str, ...] = getComponentNames( self.mesh, self.newAttributeName, self.piece )
356354
if self.nbComponents > 1:
357355
messComponent: str = ( f"The new attribute { self.newAttributeName } has { self.nbComponents } components"
358356
f" named { componentNamesCreated }." )

geos-processing/src/geos/processing/generic_processing_tools/FillPartialArrays.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing_extensions import Self
66
from typing import Union, Any
77

8+
from geos.utils.pieceEnum import Piece
89
from geos.utils.Logger import ( Logger, getLogger )
910
from geos.mesh.utils.arrayModifiers import fillPartialAttributes
1011
from geos.mesh.utils.arrayHelpers import getAttributePieceInfo
@@ -120,22 +121,19 @@ def applyFilter( self: Self ) -> None:
120121
ValueError: Error during the filling of the attribute.
121122
"""
122123
self.logger.info( f"Apply filter { self.logger.name }." )
123-
124-
onPoints: Union[ None, bool ]
125-
onBoth: bool
124+
piece: Piece
126125
for attributeName in self.dictAttributesValues:
127-
onPoints, onBoth = getAttributePieceInfo( self.multiBlockDataSet, attributeName )
128-
if onPoints is None:
126+
piece = getAttributePieceInfo( self.multiBlockDataSet, attributeName )
127+
if piece == Piece.NONE:
129128
raise AttributeError( f"The attribute { attributeName } is not in the mesh." )
130-
131-
if onBoth:
129+
elif piece == Piece.BOTH:
132130
raise AttributeError(
133131
f"There is two attribute named { attributeName }, one on points and the other on cells. The attribute name must be unique."
134132
)
135133

136134
fillPartialAttributes( self.multiBlockDataSet,
137135
attributeName,
138-
onPoints=onPoints,
136+
piece=piece,
139137
listValues=self.dictAttributesValues[ attributeName ],
140138
logger=self.logger )
141139

0 commit comments

Comments
 (0)