Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
21 changes: 3 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.7
rev: v0.11.2
hooks:
- id: ruff
- id: ruff-format
Expand All @@ -12,21 +12,6 @@ repos:
exclude: ^(examples/dyna_decks\/|tests/heart/assets\/)
args: [-L solf, "--ignore-words", "doc/styles/config/vocabularies/ANSYS/accept.txt", "-w"]

- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
additional_dependencies: [toml]
args: ["--convention=numpy"]
exclude: |
(?x)^(
tests/|
examples/|
src/ansys/heart/misc/|
src/ansys/heart/writer/custom_keywords/|
.*__init__.py
)

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
Expand All @@ -37,12 +22,12 @@ repos:
exclude: ^(tests/heart/assets\/)

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.31.2
rev: 0.32.1
hooks:
- id: check-github-workflows

- repo: https://github.com/ansys/pre-commit-hooks
rev: v0.5.1
rev: v0.5.2
hooks:
- id: add-license-headers
files: '(ansys|examples|tests)/.*\.(py)'
Expand Down
1 change: 1 addition & 0 deletions doc/source/changelog/972.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add todos and docstring
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "flit_core.buildapi"
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
name = "pyansys-heart"
version = "0.11.dev0"
description = "Python framework for heart modeling using ANSYS tools."
description = "Python framework for heart modeling using Ansys tools."
readme = "README.rst"
requires-python = ">=3.10,<4"
license = { file = "LICENSE" }
Expand All @@ -21,6 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]

dependencies = [
Expand Down Expand Up @@ -93,6 +94,8 @@ select = [
"I", # isort, see https://docs.astral.sh/ruff/rules/#isort-i
"N", # pep8-naming, see https://docs.astral.sh/ruff/rules/#pep8-naming-n
"TD", # flake8-todos, https://docs.astral.sh/ruff/rules/#flake8-todos-td
# TODO: convert the path to pathlib in all modules
#"PTH", # flake8-use-pathlib, https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
]
ignore = [
"TD002", # Missing author in TODOs comment
Expand Down
1 change: 1 addition & 0 deletions src/ansys/heart/core/utils/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def _dfs(visited, graph, node):
for edge_group in edge_groups:
counts = np.unique(edge_group, return_counts=True)[1]
if np.all(counts == 2):
# TODO: @mhoeijm - remove all print statements
# print("Closed edge loop")
group_types.append("closed")
elif np.any(counts != 2):
Expand Down
13 changes: 6 additions & 7 deletions src/ansys/heart/postprocessor/auto_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@ def zerop_post(directory: str, model: HeartModel) -> tuple[dict, np.ndarray, np.
Parameters
----------
directory : str
Path to simulation folder
Path to simulation folder.
model : HeartModel
model to post-process
model to post-process.

Returns
-------
tuple[dict, np.ndarray, np.ndarray]
dictionary with convergence information
stress free configuration
computed end-of-diastolic configuration
dictionary with convergence information, stress free configuration,
computed end-of-diastolic configuration.
"""
folder = "post"
os.makedirs(os.path.join(directory, folder), exist_ok=True)
Expand Down Expand Up @@ -149,9 +148,9 @@ def mech_post(directory: str, model: HeartModel):
Parameters
----------
directory : str
d3plot folder
d3plot folder.
model : HeartModel
heart model
heart model.
"""
last_cycle_duration = 800
folder = "post"
Expand Down
37 changes: 24 additions & 13 deletions src/ansys/heart/postprocessor/dpf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,18 @@ def get_initial_coordinates(self):
return self.model.results.initial_coordinates.eval()[0].data

def get_ep_fields(self, at_step: int = None) -> dpf.FieldsContainer:
"""Get EP fields container."""
"""Get EP fields container.

Parameters
----------
at_step : int, optional
At this step, by default None.

Returns
-------
dpf.FieldsContainer
Fields container.
"""
fields = dpf.FieldsContainer()

time_ids = (
Expand Down Expand Up @@ -300,7 +311,7 @@ def get_time(self) -> np.ndarray:
Returns
-------
np.ndarray
time array
time array.
"""
# see pydpf examples, lsdyna-operators
icvout_op = dpf.Operator("lsdyna::binout::ICV_P")
Expand All @@ -318,12 +329,12 @@ def get_pressure(self, icv_id: int) -> np.ndarray:
Parameters
----------
icv_id : int
control volume id
control volume id.

Returns
-------
np.ndarray
pressure array
pressure array.
"""
if icv_id not in self._icv_ids:
raise ValueError("icv_id not found.")
Expand All @@ -336,12 +347,12 @@ def get_volume(self, icv_id: int) -> np.ndarray:
Parameters
----------
icv_id : int
control volume id
control volume id.

Returns
-------
np.ndarray
volume array
volume array.
"""
if icv_id not in self._icv_ids:
raise ValueError("icv_id not found.")
Expand All @@ -359,12 +370,12 @@ def get_flowrate(self, icvi_id: int) -> np.ndarray:
Parameters
----------
icvi_id : int
control volume interaction id
control volume interaction id.

Returns
-------
np.ndarray
flowrate array
flowrate array.
"""
if icvi_id not in self._icvi_ids:
raise ValueError("icvi_id not found.")
Expand Down Expand Up @@ -588,15 +599,15 @@ def compute_12_lead_ECGs( # noqa: N802
ECGs : np.ndarray
mxn array containing ECGs, where m is the number of time steps
and n the 10 electrodes in this order:
"V1" "V2" "V3" "V4" "V5" "V6" "RA" "LA" "RL" "LL"
"V1" "V2" "V3" "V4" "V5" "V6" "RA" "LA" "RL" "LL".
plot : bool, optional
plot option, by default True
plot option, by default True.

Returns
-------
np.ndarray
12-Lead ECGs in this order:
"I" "II" "III" "aVR" "aVL" "aVF" "V1" "V2" "V3" "V4" "V5" "V6"
"I" "II" "III" "aVR" "aVL" "aVF" "V1" "V2" "V3" "V4" "V5" "V6".
"""
right_arm = ECGs[:, 6]
left_arm = ECGs[:, 7]
Expand Down Expand Up @@ -713,12 +724,12 @@ def convert_to_pvgrid_at_t(self, time: float, fname: str = None) -> pv.Unstructu
time : float
time to convert
fname : str
filename to be save save data, default is None
filename to be save save data, default is None.

Returns
-------
pv.UnstructuredGrid
result in pyvista object
result in pyvista object.
"""
mesh = self.data.meshgrid.copy()
i_frame = np.where(self.data.time == time)[0][0]
Expand Down
14 changes: 7 additions & 7 deletions src/ansys/heart/postprocessor/klotz_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def __init__(self, vm: float, pm: float):
Parameters
----------
vm : float
Volume in mL
Volume in mL.
pm : float
Pressure in mmHg
Pressure in mmHg.
"""
self.vm = vm
self.pm = pm
Expand Down Expand Up @@ -78,7 +78,7 @@ def get_pressure(self, volume: float | np.ndarray) -> float | np.ndarray:
Returns
-------
float| np.ndarray
pressure in mmHg
pressure in mmHg.
"""
return self.Alpha * volume**self.Beta

Expand All @@ -88,12 +88,12 @@ def get_volume(self, pressure: np.ndarray) -> np.ndarray:
Parameters
----------
pressure : np.ndarray
pressure in mmHg
pressure in mmHg.

Returns
-------
np.ndarray
volume in mmL
volume in mmL.
"""
if not isinstance(pressure, np.ndarray):
raise TypeError("Input must be 1-dimensioanl np.array.")
Expand All @@ -111,12 +111,12 @@ def plot_EDPVR(self, simulation_data: list = None) -> matplotlib.figure.Figure:
Parameters
----------
simulation_data : list, optional
[volume, pressure] from simulation, by default None
[volume, pressure] from simulation, by default None.

Returns
-------
matplotlib.figure.Figure
figure
figure.
"""
vv = np.linspace(0, 1.1 * self.vm, num=101)
pp = self.get_pressure(vv)
Expand Down
32 changes: 16 additions & 16 deletions src/ansys/heart/postprocessor/laplace_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def read_laplace_solution(
Parameters
----------
directory : str
directory of d3plot files
directory of d3plot files.
field_list : list[str]
name of each d3plot file/field
name of each d3plot file/field.

Returns
-------
pv.UnstructuredGrid
grid with point data of each field
grid with point data of each field.
"""
data = D3plotReader(os.path.join(directory, field_list[0] + ".d3plot"))
grid: pv.UnstructuredGrid = data.model.metadata.meshed_region.grid
Expand Down Expand Up @@ -84,19 +84,19 @@ def update_transmural_by_normal(grid: pv.UnstructuredGrid, surface: pv.PolyData)
Note
----
Assume mesh is coarse compared to the thinkness, solid cell normal
is interpolated from closest surface normal
is interpolated from closest surface normal.

Parameters
----------
grid : pv.UnstructuredGrid
grid : pv.UnstructuredGrid.
atrium grid
surface : pv.PolyData
atrium endocardium surface
atrium endocardium surface.

Returns
-------
np.ndarray
cell transmural direction vector
cell transmural direction vector.
"""
surface_normals = surface.clean().compute_normals()

Expand All @@ -120,14 +120,14 @@ def orthogonalization(
Parameters
----------
grad_trans : np.ndarray
transmural vector
transmural vector.
k : np.ndarray
Bundle selection vector
Bundle selection vector.

Returns
-------
tuple[np.ndarray, np.ndarray, np.ndarray]
local coordinate system e_l,e_n,e_t
local coordinate system e_l,e_n,e_t.
"""
norm = np.linalg.norm(grad_trans, axis=1)
bad_cells = np.argwhere(norm == 0).ravel()
Expand Down Expand Up @@ -241,7 +241,7 @@ def compute_ra_fiber_cs(
settings : AtrialFiber
Atrial fiber settings.
endo_surface : pv.PolyData, optional
_description_, by default None
_description_, by default None.
If given, normal direction will be updated by surface normal instead of Laplace solution.

Notes
Expand Down Expand Up @@ -376,18 +376,18 @@ def set_rotation_bounds(
Parameters
----------
w : np.ndarray
intra-ventricular interpolation weight if outflow_tracts is not None
intra-ventricular interpolation weight if outflow_tracts is not None.
endo : float
rotation angle at endocardium
rotation angle at endocardium.
epi : float
rotation angle at epicardium
rotation angle at epicardium.
outflow_tracts : list[float, float], optional
rotation angle of enendocardium do and epicardium on outflow tract, by default None
rotation angle of enendocardium do and epicardium on outflow tract, by default None.

Returns
-------
tuple[np.ndarray, np.ndarray]
cell-wise rotation bounds for endocardium and epicardium
cell-wise rotation bounds for endocardium and epicardium.
"""

def _sigmoid(z):
Expand Down
Loading
Loading