- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
feat: adding SISO decorator #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 24 commits
1a57322
              84c0ba8
              f32fe2e
              6f6e652
              5437cc0
              1f65fe7
              adaa26b
              2ec2a52
              9992917
              f08e059
              9ed4ec4
              4e4b704
              4919f5d
              ee309ff
              827fa23
              4b468e8
              39c2b2f
              82e8996
              840dcca
              0fdc32a
              8ca7bf6
              731421c
              ecd13f7
              a149214
              c68f4b1
              e943d4c
              358a45f
              08bd8e2
              da3aab5
              6694540
              984273f
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|  | 
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|  | @@ -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 | ||||||
|  | @@ -30,6 +22,7 @@ | |||||
|  | ||||||
| update_paths() | ||||||
|  | ||||||
| from geos.pv.utils.details import SISOFilter, FilterCategory | ||||||
| from geos.mesh.processing.ClipToMainFrame import ClipToMainFrame | ||||||
|  | ||||||
| __doc__ = """ | ||||||
|  | @@ -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 | ||||||
| outputMesh : a mesh transformed | ||||||
|          | ||||||
| outputMesh : a mesh transformed | |
| outputMesh : A mesh transformed. | 
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|  | @@ -5,23 +5,18 @@ | |||||
| import sys | ||||||
|         
                  RomainBaville marked this conversation as resolved.
              Show resolved
            Hide resolved | ||||||
| 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 | ||||||
|  | ||||||
|         
                  RomainBaville marked this conversation as resolved.
              Show resolved
            Hide resolved | ||||||
| from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase | ||||||
| from vtkmodules.vtkCommonCore import ( | ||||||
| vtkInformation, | ||||||
| vtkInformationVector, | ||||||
| ) | ||||||
|  | ||||||
| from vtkmodules.vtkCommonDataModel import ( | ||||||
| vtkMultiBlockDataSet, | ||||||
| vtkDataSet, | ||||||
| ) | ||||||
|  | ||||||
|  | @@ -32,6 +27,7 @@ | |||||
|  | ||||||
| update_paths() | ||||||
|  | ||||||
| from geos.pv.utils.details import SISOFilter, FilterCategory | ||||||
| from geos.mesh.processing.CreateConstantAttributePerRegion import CreateConstantAttributePerRegion, vnp, np | ||||||
|         
                  paloma-martinez marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||
|  | ||||||
| __doc__ = """ | ||||||
|  | @@ -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: | ||||||
|  | @@ -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. | ||||||
|  | @@ -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: | ||||||
|  | @@ -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> | ||||||
|  | @@ -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: | ||||||
|  | @@ -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() | ||||||
|  | ||||||
|  | @@ -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: | ||||||
|  | @@ -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: | ||||||
|  | @@ -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: | ||||||
|  | @@ -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: | ||||||
|  | @@ -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 | ||||||
|          | ||||||
| inputMesh : a mesh to transform | |
| inputMesh : A mesh to transform. | 
        
          
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| outputMesh : a mesh transformed | |
| outputMesh : A mesh transformed. | 
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.