Skip to content
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .hooks/pre-commit.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash -e

function run_precommit_checks
{
echo "running mypy"
python -m mypy --config-file ./.mypy.ini --check-untyped-defs $1
echo "running ruff"
python -m ruff check --unsafe-fixes --config .ruff.toml $1
echo "running yapf"
python -m yapf -r -i --style .style.yapf $1

return 0
}


source ${ENV_PYTHON}/bin/activate

#sphinx-build -b html docs/ docs/_build -W
for file in $(git diff --name-only --cached | grep -e "modified\|added" | grep py)
do
run_precommit_checks $file
done

68 changes: 10 additions & 58 deletions geos-pv/src/geos/pv/plugins/PVClipToMainFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@
# ruff: noqa: E402 # disable Module level import not at top of file
import sys
from pathlib import Path
from typing import Union

from paraview.util.vtkAlgorithm import ( # type: ignore[import-not-found]
VTKPythonAlgorithmBase, smdomain, smhint, smproperty, smproxy,
VTKPythonAlgorithmBase,
) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/util/vtkAlgorithm.py
from paraview.detail.loghandler import ( # type: ignore[import-not-found]
VTKHandler,
) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/detail/loghandler.py

from vtkmodules.vtkCommonDataModel import (
vtkMultiBlockDataSet,
vtkUnstructuredGrid,
)

from vtkmodules.vtkCommonCore import (
vtkInformation,
vtkInformationVector,
)
vtkMultiBlockDataSet, )

# update sys.path to load all GEOS Python Package dependencies
geos_pv_path: Path = Path( __file__ ).parent.parent.parent.parent.parent
Expand All @@ -30,6 +22,7 @@

update_paths()

from geos.pv.utils.details import SISOFilter, FilterCategory
from geos.mesh.processing.ClipToMainFrame import ClipToMainFrame

__doc__ = """
Expand All @@ -43,67 +36,26 @@
"""


@smproxy.filter( name="PVClipToMainFrame", label="Clip to the main frame" )
@smhint.xml( '<ShowInMenu category="4- Geos Utils"/>' )
@smproperty.input( name="Input", port_index=0 )
@smdomain.datatype(
dataTypes=[ "vtkMultiBlockDataSet", "vtkUnstructuredGrid" ],
composite_data_supported=True,
)
@SISOFilter( category=FilterCategory.GEOS_UTILS,
decorated_label="Clip to the main frame",
decorated_type=[ "vtkMultiBlockDataSet", "vtkDataSet" ] )
class PVClipToMainFrame( VTKPythonAlgorithmBase ):

def __init__( self ) -> None:
"""Init motherclass, filter and logger."""
VTKPythonAlgorithmBase.__init__( self,
nInputPorts=1,
nOutputPorts=1,
inputType="vtkDataObject",
outputType="vtkDataObject" )

self._realFilter = ClipToMainFrame( speHandler=True )
if not self._realFilter.logger.hasHandlers():
self._realFilter.SetLoggerHandler( VTKHandler() )

#ensure I/O consistency
def RequestDataObject( self, request: vtkInformation, inInfoVec: list[ vtkInformationVector ],
outInfoVec: vtkInformationVector ) -> int:
"""Inherited from VTKPythonAlgorithmBase::RequestDataObject.
Args:
request (vtkInformation): request
inInfoVec (list[vtkInformationVector]): input objects
outInfoVec (vtkInformationVector): output objects
Returns:
int: 1 if calculation successfully ended, 0 otherwise.
"""
inData = self.GetInputData( inInfoVec, 0, 0 )
outData = self.GetOutputData( outInfoVec, 0 )
assert inData is not None
if outData is None or ( not outData.IsA( inData.GetClassName() ) ):
outData = inData.NewInstance()
outInfoVec.GetInformationObject( 0 ).Set( outData.DATA_OBJECT(), outData )
return super().RequestDataObject( request, inInfoVec, outInfoVec ) # type: ignore[no-any-return]

def RequestData( self, request: vtkInformation, inInfo: list[ vtkInformationVector ],
outInfo: vtkInformationVector ) -> int:
"""Inherited from VTKPythonAlgorithmBase::RequestData. Apply ClipToMainFrame filter.
def Filter( self, inputMesh: vtkMultiBlockDataSet, outputMesh: vtkMultiBlockDataSet ) -> None:
"""Is applying CreateConstantAttributePerRegion filter.
Args:
request (vtkInformation): Request
inInfo (list[vtkInformationVector]): Input objects
outInfo (vtkInformationVector): Output objects
Returns:
int: 1 if calculation successfully ended, 0 otherwise.
inputMesh : a mesh to transform
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
inputMesh : a mesh to transform
inputMesh : A mesh to transform.

outputMesh : a mesh transformed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outputMesh : a mesh transformed
outputMesh : A mesh transformed.

"""
inputMesh: Union[ vtkMultiBlockDataSet, vtkUnstructuredGrid ] = self.GetInputData( inInfo, 0, 0 )
outputMesh: Union[ vtkMultiBlockDataSet, vtkUnstructuredGrid ] = self.GetOutputData( outInfo, 0 )

# struct
self._realFilter.SetInputData( inputMesh )
self._realFilter.ComputeTransform()
self._realFilter.Update()
outputMesh.ShallowCopy( self._realFilter.GetOutputDataObject( 0 ) )

return 1
101 changes: 23 additions & 78 deletions geos-pv/src/geos/pv/plugins/PVCreateConstantAttributePerRegion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@
import sys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import sys
import sys
import numpy as np

from pathlib import Path

from typing import Union, Any
from typing import Any
from typing_extensions import Self

from paraview.util.vtkAlgorithm import ( # type: ignore[import-not-found]
smdomain, smhint, smproperty, smproxy,
VTKPythonAlgorithmBase, smdomain, smproperty,
) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/util/vtkAlgorithm.py
from paraview.detail.loghandler import ( # type: ignore[import-not-found]
VTKHandler,
) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/detail/loghandler.py

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import vtkmodules.util.numpy_support as vnp

from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase
from vtkmodules.vtkCommonCore import (
vtkInformation,
vtkInformationVector,
)

from vtkmodules.vtkCommonDataModel import (
vtkMultiBlockDataSet,
vtkDataSet,
)

Expand All @@ -32,6 +27,7 @@

update_paths()

from geos.pv.utils.details import SISOFilter, FilterCategory
from geos.mesh.processing.CreateConstantAttributePerRegion import CreateConstantAttributePerRegion, vnp, np

__doc__ = """
Expand All @@ -42,7 +38,7 @@
Input mesh is either vtkMultiBlockDataSet or vtkDataSet and the region attribute must have one component.
The relation index/values is given by a dictionary. Its keys are the indexes and its items are the list of values for each component.

.. Warning::
.. Warning::
The input mesh should contain an attribute corresponding to the regions.

To use it:
Expand All @@ -54,24 +50,13 @@
* Apply.

"""


@smproxy.filter(
name="PVCreateConstantAttributePerRegion",
label="Create Constant Attribute Per Region",
)
@smhint.xml( """<ShowInMenu category="0- Geos Pre-processing"/>""" )
@smproperty.input( name="Input", port_index=0 )
@smdomain.datatype(
dataTypes=[ "vtkMultiBlockDataSet", "vtkDataSet" ],
composite_data_supported=True,
)
class PVCreateConstantAttributePerRegion( VTKPythonAlgorithmBase ):
@SISOFilter( category=FilterCategory.GEOS_PROP,
decorated_label="Create Constant Attribute Per Region",
decorated_type=[ "vtkMultiBlockDataSet", "vtkDataSet" ])
class PVCreateConstantAttributePerRegion(VTKPythonAlgorithmBase):

def __init__( self: Self ) -> None:
"""Create an attribute with constant value per region."""
super().__init__( nInputPorts=1, nOutputPorts=1, inputType="vtkDataObject", outputType="vtkDataObject" )

self.clearDictRegionValues: bool = True

# Region attribute settings.
Expand Down Expand Up @@ -111,7 +96,7 @@ def __init__( self: Self ) -> None:
<NoDefault />
</Hints>
""" )
def _setRegionAttributeName( self: Self, regionName: str ) -> None:
def setRegionAttributeName( self: Self, regionName: str ) -> None:
"""Set region attribute name.

Args:
Expand All @@ -124,7 +109,7 @@ def _setRegionAttributeName( self: Self, regionName: str ) -> None:
<StringVectorProperty
name="SetDictRegionValues"
number_of_elements="2"
command="_setDictRegionValues"
command="setDictRegionValues"
repeat_command="1"
number_of_elements_per_command="2">
<Documentation>
Expand All @@ -142,7 +127,7 @@ def _setRegionAttributeName( self: Self, regionName: str ) -> None:
</Hints>
</StringVectorProperty>
""" )
def _setDictRegionValues( self: Self, regionIndex: str, value: str ) -> None:
def setDictRegionValues( self: Self, regionIndex: str, value: str ) -> None:
"""Set the dictionary with the region indexes and its corresponding list of values for each components.

Args:
Expand All @@ -166,7 +151,7 @@ def _setDictRegionValues( self: Self, regionIndex: str, value: str ) -> None:
<Property name="SetDictRegionValues"/>
</PropertyGroup>
""" )
def _groupRegionAttributeSettingsWidgets( self: Self ) -> None:
def groupRegionAttributeSettingsWidgets( self: Self ) -> None:
"""Group the widgets to set the settings of the region attribute."""
self.Modified()

Expand All @@ -183,7 +168,7 @@ def _groupRegionAttributeSettingsWidgets( self: Self ) -> None:
</Documentation>
</StringVectorProperty>
""" )
def _setAttributeName( self: Self, newAttributeName: str ) -> None:
def setAttributeName( self: Self, newAttributeName: str ) -> None:
"""Set attribute name.

Args:
Expand Down Expand Up @@ -216,7 +201,7 @@ def _setAttributeName( self: Self, newAttributeName: str ) -> None:
The requested numpy scalar type for values of the new attribute.
</Documentation>
""" )
def _setValueType( self: Self, valueType: int ) -> None:
def setValueType( self: Self, valueType: int ) -> None:
"""Set the type for the value used to create the new attribute.

Args:
Expand All @@ -238,7 +223,7 @@ def _setValueType( self: Self, valueType: int ) -> None:
The number of components for the new attribute to create.
</Documentation>
""" )
def _setNbComponent( self: Self, nbComponents: int ) -> None:
def setNbComponent( self: Self, nbComponents: int ) -> None:
"""Set the number of components of the attribute to create.

Args:
Expand All @@ -261,7 +246,7 @@ def _setNbComponent( self: Self, nbComponents: int ) -> None:
Names of components: X, Y, Z
</Documentation>
""" )
def _setComponentNames( self: Self, componentNames: str ) -> None:
def setComponentNames( self: Self, componentNames: str ) -> None:
"""Set the names of the components of the attribute to create.

Args:
Expand All @@ -283,57 +268,17 @@ def _setComponentNames( self: Self, componentNames: str ) -> None:
<Property name="NumberOfComponents"/>
<Property name="ComponentNames"/>
</PropertyGroup>""" )
def _groupNewAttributeSettingsWidgets( self: Self ) -> None:
def groupNewAttributeSettingsWidgets( self: Self ) -> None:
"""Group the widgets to set the settings of the new attribute."""
self.Modified()

def RequestDataObject(
self: Self,
request: vtkInformation,
inInfoVec: list[ vtkInformationVector ],
outInfoVec: vtkInformationVector,
) -> int:
"""Inherited from VTKPythonAlgorithmBase::RequestDataObject.
def Filter(self, inputMesh: vtkDataSet , outputMesh: vtkDataSet) -> None:
"""Is applying CreateConstantAttributePerRegion filter.

Args:
request (vtkInformation): request
inInfoVec (list[vtkInformationVector]): input objects
outInfoVec (vtkInformationVector): output objects

Returns:
int: 1 if calculation successfully ended, 0 otherwise.
inputMesh : a mesh to transform
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
inputMesh : a mesh to transform
inputMesh : A mesh to transform.

outputMesh : a mesh transformed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outputMesh : a mesh transformed
outputMesh : A mesh transformed.

"""
inData = self.GetInputData( inInfoVec, 0, 0 )
outData = self.GetOutputData( outInfoVec, 0 )
assert inData is not None
if outData is None or ( not outData.IsA( inData.GetClassName() ) ):
outData = inData.NewInstance()
outInfoVec.GetInformationObject( 0 ).Set( outData.DATA_OBJECT(), outData )
return super().RequestDataObject( request, inInfoVec, outInfoVec ) # type: ignore[no-any-return]

def RequestData(
self: Self,
request: vtkInformation, # noqa: F841
inInfoVec: list[ vtkInformationVector ], # noqa: F841
outInfoVec: vtkInformationVector, # noqa: F841
) -> int:
"""Inherited from VTKPythonAlgorithmBase::RequestData.

Args:
request (vtkInformation): Request.
inInfoVec (list[vtkInformationVector]): Input objects.
outInfoVec (vtkInformationVector): Output objects.

Returns:
int: 1 if calculation successfully ended, 0 otherwise.
"""
inputMesh: Union[ vtkDataSet, vtkMultiBlockDataSet ] = self.GetInputData( inInfoVec, 0, 0 )
outputMesh: Union[ vtkDataSet, vtkMultiBlockDataSet ] = self.GetOutputData( outInfoVec, 0 )

assert inputMesh is not None, "Input mesh is null."
assert outputMesh is not None, "Output pipeline is null."

outputMesh.ShallowCopy( inputMesh )
filter: CreateConstantAttributePerRegion = CreateConstantAttributePerRegion(
outputMesh,
self.regionName,
Expand All @@ -352,4 +297,4 @@ def RequestData(

self.clearDictRegion = True

return 1
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use a return here and after but not in PVClipToMainFrame ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Loading