Skip to content

Commit 70b631e

Browse files
fix: Clean verbosity in the function fillAllPartialAttributes (#138)
* Control warning messages in fillAllPartialArray
1 parent 9f54db6 commit 70b631e

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def fillPartialAttributes(
6060
onPoints: bool = False,
6161
listValues: Union[ list[ Any ], None ] = None,
6262
logger: Union[ Logger, None ] = None,
63+
fillAll: bool = False,
6364
) -> bool:
6465
"""Fill input partial attribute of multiBlockDataSet with a constant value per component.
6566
@@ -75,6 +76,8 @@ def fillPartialAttributes(
7576
nan for float VTK arrays.
7677
logger (Union[Logger, None], optional): A logger to manage the output messages.
7778
Defaults to None, an internal logger is used.
79+
fillAll (bool, optional): True if fillPartialAttributes is used by fillAllPartialAttributes, else False.
80+
Defaults to False.
7881
7982
Returns:
8083
bool: True if the attribute was correctly created and filled, False if not.
@@ -105,32 +108,29 @@ def fillPartialAttributes(
105108
# Set the default value depending of the type of the attribute to fill
106109
if listValues is None:
107110
defaultValue: Any
108-
logger.warning( f"The attribute { attributeName } is filled with the default value for each component." )
111+
mess: str = f"The attribute { attributeName } is filled with the default value for each component.\n"
109112
# Default value for float types is nan.
110113
if vtkDataType in ( VTK_FLOAT, VTK_DOUBLE ):
111114
defaultValue = valueType( np.nan )
112-
logger.warning(
113-
f"{ attributeName } vtk data type is { vtkDataType } corresponding to { defaultValue.dtype } numpy type, default value is automatically set to nan."
114-
)
115+
mess = mess + f"{ attributeName } vtk data type is { vtkDataType } corresponding to { defaultValue.dtype } numpy type, default value is automatically set to nan."
115116
# Default value for int types is -1.
116117
elif vtkDataType in ( VTK_CHAR, VTK_SIGNED_CHAR, VTK_SHORT, VTK_LONG, VTK_INT, VTK_LONG_LONG, VTK_ID_TYPE ):
117118
defaultValue = valueType( -1 )
118-
logger.warning(
119-
f"{ attributeName } vtk data type is { vtkDataType } corresponding to { defaultValue.dtype } numpy type, default value is automatically set to -1."
120-
)
119+
mess = mess + f"{ attributeName } vtk data type is { vtkDataType } corresponding to { defaultValue.dtype } numpy type, default value is automatically set to -1."
121120
# Default value for uint types is 0.
122121
elif vtkDataType in ( VTK_BIT, VTK_UNSIGNED_CHAR, VTK_UNSIGNED_SHORT, VTK_UNSIGNED_LONG, VTK_UNSIGNED_INT,
123122
VTK_UNSIGNED_LONG_LONG ):
124123
defaultValue = valueType( 0 )
125-
logger.warning(
126-
f"{ attributeName } vtk data type is { vtkDataType } corresponding to { defaultValue.dtype } numpy type, default value is automatically set to 0."
127-
)
124+
mess = mess + f"{ attributeName } vtk data type is { vtkDataType } corresponding to { defaultValue.dtype } numpy type, default value is automatically set to 0."
128125
else:
129126
logger.error( f"The type of the attribute { attributeName } is not compatible with the function." )
130127
return False
131128

132129
listValues = [ defaultValue ] * nbComponents
133130

131+
if not fillAll:
132+
logger.warning( mess )
133+
134134
else:
135135
if len( listValues ) != nbComponents:
136136
return False
@@ -158,7 +158,12 @@ def fillAllPartialAttributes(
158158
multiBlockDataSet: Union[ vtkMultiBlockDataSet, vtkCompositeDataSet, vtkDataObject ],
159159
logger: Union[ Logger, None ] = None,
160160
) -> bool:
161-
"""Fill all partial attributes of a multiBlockDataSet with the default value. All components of each attributes are filled with the same value. Depending of the type of the attribute, the default value is different 0, -1 and nan for respectively uint, int and float vtk type.
161+
"""Fill all partial attributes of a multiBlockDataSet with the default value.
162+
163+
All components of each attributes are filled with the same value. Depending of the type of the attribute's data, the default value is different:
164+
0 for uint data,
165+
-1 for int data,
166+
nan float data,
162167
163168
Args:
164169
multiBlockDataSet (vtkMultiBlockDataSet | vtkCompositeDataSet | vtkDataObject): MultiBlockDataSet where to fill attributes.
@@ -172,12 +177,16 @@ def fillAllPartialAttributes(
172177
if logger is None:
173178
logger = getLogger( "fillAllPartialAttributes", True )
174179

180+
logger.warning(
181+
"The filling value for the attributes is depending of the type of attribute's data:\n0 for uint data,\n-1 for int data,\nnan for float data."
182+
)
183+
175184
# Parse all partial attributes, onPoints and onCells to fill them.
176185
for onPoints in [ True, False ]:
177186
infoAttributes: dict[ str, int ] = getAttributesWithNumberOfComponents( multiBlockDataSet, onPoints )
178187
for attributeName in infoAttributes:
179188
if not isAttributeGlobal( multiBlockDataSet, attributeName, onPoints ) and \
180-
not fillPartialAttributes( multiBlockDataSet, attributeName, onPoints=onPoints, logger=logger ):
189+
not fillPartialAttributes( multiBlockDataSet, attributeName, onPoints=onPoints, logger=logger, fillAll=True ):
181190
return False
182191

183192
return True

0 commit comments

Comments
 (0)