pyafv 0.4.0__tar.gz → 0.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {pyafv-0.4.0 → pyafv-0.4.2}/PKG-INFO +6 -3
  2. {pyafv-0.4.0 → pyafv-0.4.2}/README.md +5 -2
  3. {pyafv-0.4.0 → pyafv-0.4.2}/examples/active_FV.py +1 -1
  4. {pyafv-0.4.0 → pyafv-0.4.2}/examples/relaxation.py +1 -1
  5. pyafv-0.4.2/pyafv/_version.py +2 -0
  6. {pyafv-0.4.0 → pyafv-0.4.2}/pyafv/calibrate/core.py +4 -4
  7. {pyafv-0.4.0 → pyafv-0.4.2}/pyafv/calibrate/deformable_polygon.py +2 -2
  8. {pyafv-0.4.0 → pyafv-0.4.2}/pyafv/finite_voronoi.py +2 -1
  9. {pyafv-0.4.0 → pyafv-0.4.2}/pyafv/physical_params.py +35 -12
  10. {pyafv-0.4.0 → pyafv-0.4.2}/tests/test_benchmarks.py +11 -0
  11. {pyafv-0.4.0 → pyafv-0.4.2}/tests/test_core.py +4 -1
  12. {pyafv-0.4.0 → pyafv-0.4.2}/tests/test_vary_A0.py +1 -1
  13. pyafv-0.4.0/pyafv/_version.py +0 -2
  14. {pyafv-0.4.0 → pyafv-0.4.2}/.gitignore +0 -0
  15. {pyafv-0.4.0 → pyafv-0.4.2}/LICENSE +0 -0
  16. {pyafv-0.4.0 → pyafv-0.4.2}/examples/calibrate_DP.py +0 -0
  17. {pyafv-0.4.0 → pyafv-0.4.2}/examples/connections.py +0 -0
  18. {pyafv-0.4.0 → pyafv-0.4.2}/pyafv/__init__.py +0 -0
  19. {pyafv-0.4.0 → pyafv-0.4.2}/pyafv/backend.py +0 -0
  20. {pyafv-0.4.0 → pyafv-0.4.2}/pyafv/calibrate/__init__.py +0 -0
  21. {pyafv-0.4.0 → pyafv-0.4.2}/pyafv/cell_geom.pyx +0 -0
  22. {pyafv-0.4.0 → pyafv-0.4.2}/pyafv/cell_geom_fallback.py +0 -0
  23. {pyafv-0.4.0 → pyafv-0.4.2}/pyproject.toml +0 -0
  24. {pyafv-0.4.0 → pyafv-0.4.2}/tests/conftest.py +0 -0
  25. {pyafv-0.4.0 → pyafv-0.4.2}/tests/data/debug_pts.npy +0 -0
  26. {pyafv-0.4.0 → pyafv-0.4.2}/tests/data/init_forces.csv +0 -0
  27. {pyafv-0.4.0 → pyafv-0.4.2}/tests/data/init_pts.csv +0 -0
  28. {pyafv-0.4.0 → pyafv-0.4.2}/tests/data/init_seed407_pts.csv +0 -0
  29. {pyafv-0.4.0 → pyafv-0.4.2}/tests/data/init_seed46_pts.csv +0 -0
  30. {pyafv-0.4.0 → pyafv-0.4.2}/tests/data/varying_A0.csv +0 -0
  31. {pyafv-0.4.0 → pyafv-0.4.2}/tests/data/varying_A0_forces.csv +0 -0
  32. {pyafv-0.4.0 → pyafv-0.4.2}/tests/test_calibrate.py +0 -0
  33. {pyafv-0.4.0 → pyafv-0.4.2}/tests/test_geom.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyafv
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Python implementation of the active-finite-Voronoi (AFV) model
5
5
  Project-URL: Homepage, https://pyafv.github.io
6
6
  Project-URL: Download, https://pypi.org/project/pyafv/#files
@@ -36,6 +36,7 @@ Description-Content-Type: text/markdown
36
36
  [![PyPi](https://img.shields.io/pypi/v/pyafv?cacheSeconds=300)](https://pypi.org/project/pyafv/)
37
37
  [![Downloads](https://img.shields.io/pypi/dm/pyafv.svg?cacheSeconds=43200)](https://pypi.org/project/pyafv/)
38
38
  [![Documentation](https://img.shields.io/badge/documentation-pyafv.readthedocs.io-yellow.svg?logo=readthedocs)](https://pyafv.readthedocs.io)
39
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pyafv/assets/blob/main/jupyter/getting_started.ipynb)
39
40
  <!--[![pytest](https://github.com/wwang721/pyafv/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/wwang721/pyafv/actions/workflows/tests.yml?query=branch:main)-->
40
41
  [![Tests on all platforms](https://github.com/wwang721/pyafv/actions/workflows/tests_all_platform.yml/badge.svg)](https://github.com/wwang721/pyafv/actions/workflows/tests_all_platform.yml)
41
42
  [![pytest](https://github.com/wwang721/pyafv/actions/workflows/tests.yml/badge.svg)](https://github.com/wwang721/pyafv/actions/workflows/tests.yml)
@@ -101,7 +102,9 @@ Alternatively, you can build **PyAFV** from source as described in the previous
101
102
 
102
103
  ## Usage
103
104
 
104
- Here is a simple example to get you started, demonstrating how to construct a finite-Voronoi diagram:
105
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pyafv/assets/blob/main/jupyter/getting_started.ipynb)
106
+
107
+ Here is a simple example to get you started, demonstrating how to construct a finite-Voronoi diagram (click the **Google Colab** badge above to run the notebook directly):
105
108
  ```python
106
109
  import numpy as np
107
110
  import pyafv as afv
@@ -136,7 +139,7 @@ Below are representative simulation snapshots generated using the code:
136
139
 
137
140
  - **Full documentation** on [readthedocs](https://pyafv.readthedocs.io) or as [a single PDF file](https://pyafv.readthedocs.io/_/downloads/en/latest/pdf/).
138
141
 
139
- - See [CONTRIBUTING.md](https://github.com/wwang721/pyafv/blob/main/CONTRIBUTING.md) or the [documentation](https://pyafv.readthedocs.io/latest/contributing.html) for **local development instructions**.
142
+ - See [CONTRIBUTING.md](https://github.com/wwang721/pyafv/blob/main/.github/CONTRIBUTING.md) or the [documentation](https://pyafv.readthedocs.io/latest/contributing.html) for **local development instructions**.
140
143
 
141
144
  - See some important [**issues**](https://github.com/wwang721/pyafv/issues?q=is%3Aissue%20state%3Aclosed) for additional context, such as:
142
145
  * [QhullError when 3+ points are collinear #1](https://github.com/wwang721/pyafv/issues/1) [Closed - see [comments](https://github.com/wwang721/pyafv/issues/1#issuecomment-3701355742)]
@@ -1,6 +1,7 @@
1
1
  [![PyPi](https://img.shields.io/pypi/v/pyafv?cacheSeconds=300)](https://pypi.org/project/pyafv/)
2
2
  [![Downloads](https://img.shields.io/pypi/dm/pyafv.svg?cacheSeconds=43200)](https://pypi.org/project/pyafv/)
3
3
  [![Documentation](https://img.shields.io/badge/documentation-pyafv.readthedocs.io-yellow.svg?logo=readthedocs)](https://pyafv.readthedocs.io)
4
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pyafv/assets/blob/main/jupyter/getting_started.ipynb)
4
5
  <!--[![pytest](https://github.com/wwang721/pyafv/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/wwang721/pyafv/actions/workflows/tests.yml?query=branch:main)-->
5
6
  [![Tests on all platforms](https://github.com/wwang721/pyafv/actions/workflows/tests_all_platform.yml/badge.svg)](https://github.com/wwang721/pyafv/actions/workflows/tests_all_platform.yml)
6
7
  [![pytest](https://github.com/wwang721/pyafv/actions/workflows/tests.yml/badge.svg)](https://github.com/wwang721/pyafv/actions/workflows/tests.yml)
@@ -66,7 +67,9 @@ Alternatively, you can build **PyAFV** from source as described in the previous
66
67
 
67
68
  ## Usage
68
69
 
69
- Here is a simple example to get you started, demonstrating how to construct a finite-Voronoi diagram:
70
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pyafv/assets/blob/main/jupyter/getting_started.ipynb)
71
+
72
+ Here is a simple example to get you started, demonstrating how to construct a finite-Voronoi diagram (click the **Google Colab** badge above to run the notebook directly):
70
73
  ```python
71
74
  import numpy as np
72
75
  import pyafv as afv
@@ -101,7 +104,7 @@ Below are representative simulation snapshots generated using the code:
101
104
 
102
105
  - **Full documentation** on [readthedocs](https://pyafv.readthedocs.io) or as [a single PDF file](https://pyafv.readthedocs.io/_/downloads/en/latest/pdf/).
103
106
 
104
- - See [CONTRIBUTING.md](https://github.com/wwang721/pyafv/blob/main/CONTRIBUTING.md) or the [documentation](https://pyafv.readthedocs.io/latest/contributing.html) for **local development instructions**.
107
+ - See [CONTRIBUTING.md](https://github.com/wwang721/pyafv/blob/main/.github/CONTRIBUTING.md) or the [documentation](https://pyafv.readthedocs.io/latest/contributing.html) for **local development instructions**.
105
108
 
106
109
  - See some important [**issues**](https://github.com/wwang721/pyafv/issues?q=is%3Aissue%20state%3Aclosed) for additional context, such as:
107
110
  * [QhullError when 3+ points are collinear #1](https://github.com/wwang721/pyafv/issues/1) [Closed - see [comments](https://github.com/wwang721/pyafv/issues/1#issuecomment-3701355742)]
@@ -25,7 +25,7 @@ phys = afv.PhysicalParams(
25
25
 
26
26
  # Do not set delta unless you know what you are doing.
27
27
  # We set it to zero here for comparison with the our primitive results.
28
- phys = phys.with_delta(0.0)
28
+ phys = phys.replace(delta=0.0)
29
29
 
30
30
  # Initial positions and orientations
31
31
  pts = np.random.rand(N, 2)*0.3 + 0.35 # shape (N,2)
@@ -23,7 +23,7 @@ phys = afv.PhysicalParams(
23
23
 
24
24
  # Do not set delta unless you know what you are doing.
25
25
  # We set it to zero here for comparison with the our primitive results.
26
- phys = phys.with_delta(0.0)
26
+ phys = phys.replace(delta=0.0)
27
27
 
28
28
  # Initial positions
29
29
  pts = np.random.rand(N, 2)*0.3 + 0.35 # shape (N,2)
@@ -0,0 +1,2 @@
1
+ # pyafv/_version.py
2
+ __version__ = "0.4.2"
@@ -35,7 +35,7 @@ def auto_calibrate(phys: PhysicalParams, ext_forces: np.ndarray | None = None,
35
35
  """
36
36
  Auto-calibrate the parameters *phys* against the deformable-polygon (DP) model.
37
37
 
38
- In this calibration, we simulate the DP model under increasing external force dipoles, starting from 0 to max(*ext_forces*).
38
+ In this calibration, we simulate an initially steady-state cell doublet under increasing external force dipoles using the DP model; the external force starts from 0 to max(*ext_forces*).
39
39
  We identify the detachment force as the first external force at which detachment occurs.
40
40
  We then search for the :py:attr:`delta` value in the finite-Voronoi (FV) model to match this detachment force.
41
41
 
@@ -69,7 +69,7 @@ def auto_calibrate(phys: PhysicalParams, ext_forces: np.ndarray | None = None,
69
69
 
70
70
  if sim.detached: # already detached at zero force (steady state)
71
71
  detachment_force = 0.0
72
- return float(detachment_force), sim.phys.with_delta(0.0)
72
+ return float(detachment_force), sim.phys.replace(delta=0.0)
73
73
  else:
74
74
  if ext_forces is None: # pragma: no cover
75
75
  ext_forces = np.linspace(0, 10, 101)[1:]
@@ -84,7 +84,7 @@ def auto_calibrate(phys: PhysicalParams, ext_forces: np.ndarray | None = None,
84
84
  sim.simulate(ext_force, dt, nsteps)
85
85
  if sim.detached:
86
86
  detachment_force = ext_force
87
- return float(detachment_force), sim.phys.with_delta(target_delta(sim.phys, detachment_force))
87
+ return float(detachment_force), sim.phys.replace(delta=target_delta(sim.phys, detachment_force))
88
88
 
89
89
  # did not detach within given forces
90
- return float('nan'), sim.phys.with_delta(0.45 * sim.phys.r) # pragma: no cover
90
+ return float('nan'), sim.phys.replace(delta=0.45*sim.phys.r) # pragma: no cover
@@ -172,7 +172,7 @@ class DeformablePolygonSimulator:
172
172
 
173
173
  Args:
174
174
  phys: An instance of PhysicalParams containing the physical parameters, while *phys.r* and *phys.delta* are ignored.
175
- num_vertices: Number of vertices :math:`M` to use for each polygon.
175
+ num_vertices: Number of vertices :math:`M` to use for each cell.
176
176
 
177
177
  Raises:
178
178
  TypeError: If *phys* is not an instance of *PhysicalParams*.
@@ -309,7 +309,7 @@ class DeformablePolygonSimulator:
309
309
  """
310
310
  Simulate the DP model for a number of time steps under an external force.
311
311
 
312
- This basically is just a wrapper around :py:meth:`_step_update` and :py:func:`resample_polyline` with some bookkeeping.
312
+ This is basically a wrapper around :py:meth:`_step_update` and :py:func:`resample_polyline` with some bookkeeping.
313
313
 
314
314
  Args:
315
315
  ext_force: The external force applied to the cell doublet.
@@ -43,6 +43,7 @@ class FiniteVoronoiSimulator:
43
43
  pts (numpy.ndarray): (N,2) array of initial cell center positions.
44
44
  phys: Physical parameters used within this simulator.
45
45
  backend: Optional, specify "python" to force the use of the pure Python fallback implementation.
46
+ Otherwise, the "cython" backend is used.
46
47
 
47
48
  Raises:
48
49
  ValueError: If *pts* does not have shape (N,2).
@@ -726,7 +727,7 @@ class FiniteVoronoiSimulator:
726
727
  very marginal) when connectivity is not needed.
727
728
 
728
729
  Returns:
729
- dict[str, object]: A dictionary containing geometric properties with keys:
730
+ dict[str, object]: A dictionary containing forces and geometric properties with keys:
730
731
 
731
732
  - **forces**: (N,2) array of forces on cell centers
732
733
  - **areas**: (N,) array of cell areas
@@ -76,7 +76,7 @@ class PhysicalParams:
76
76
  raise TypeError(f"delta must be a real scalar (float-like) or None, got {type(self.delta).__name__}") from None
77
77
 
78
78
  def get_steady_state(self) -> tuple[float, float]:
79
- r"""Compute steady-state :math:`(\ell,d)` for the given physical parameters.
79
+ r"""Search for the steady-state :math:`(\ell,d)` of a cell doublet for the given physical parameters (by minimizing total energy).
80
80
 
81
81
  Returns:
82
82
  Steady-state (optimal) :math:`(\ell_0,d_0)` values.
@@ -89,30 +89,50 @@ class PhysicalParams:
89
89
  l, d = result[0]
90
90
  return l, d
91
91
 
92
- def with_optimal_radius(self) -> PhysicalParams:
93
- """Returns a new instance with the radius updated to steady state.
94
- Other parameters remain unchanged (with the exception that :py:attr:`delta` is scaled with :py:attr:`r`).
92
+ def with_optimal_radius(self, digits: int | None = None, delta: float | None = None) -> PhysicalParams:
93
+ r"""Returns a new instance of :py:class:`PhysicalParams` with the maximum radius :math:`\ell` (or :py:attr:`r`) updated to the steady state value :math:`\ell_0` of cell doublets.
94
+ Other parameters (except :py:attr:`delta`) remain unchanged.
95
95
 
96
96
  Basically a wrapper around :py:meth:`get_steady_state` + creating a new instance.
97
97
 
98
+ Args:
99
+ digits: If not None, round the optimal radius :math:`\ell_0` to the specified number of decimal places.
100
+ Only intended for randomized tests to avoid floating-point precision issues.
101
+ delta: If not None, set the contact truncation threshold :py:attr:`delta` to this value in the returned instance.
102
+
98
103
  Returns:
99
104
  New instance with optimal radius.
105
+
106
+ .. important::
107
+ In the returned instance, the contact truncation threshold :py:attr:`delta` is set to 0.45*r by default.
100
108
  """
101
109
  l, d = self.get_steady_state()
102
- new_params = replace(self, r=l, delta=0.45*l)
110
+
111
+ if digits is not None:
112
+ l = round(l, digits)
113
+
114
+ if delta is not None:
115
+ delta_new = delta
116
+ else:
117
+ delta_new = 0.45 * l
118
+
119
+ new_params = replace(self, r=l, delta=delta_new)
103
120
  return new_params
104
121
 
105
- def with_delta(self, delta_new: float) -> PhysicalParams:
106
- """Returns a new instance with the specified delta.
107
- Other parameters remain unchanged.
122
+ def replace(self, **changes: float | None) -> PhysicalParams:
123
+ """Returns a new instance of :py:class:`PhysicalParams` with specified fields replaced by new values.
108
124
 
109
125
  Args:
110
- delta_new: New delta value.
126
+ **changes: Field names and their new values to be replaced.
111
127
 
112
128
  Returns:
113
- New instance with updated delta.
129
+ New instance with the updated fields.
130
+
131
+ .. hint::
132
+ This is a convenience method wrapping :py:func:`dataclasses.replace`,
133
+ e.g., to change :py:attr:`A0` and :py:attr:`delta` of an existing instance *phys*: ``phys_new = phys.replace(A0=5.0, delta=0.3)``.
114
134
  """
115
- return replace(self, delta=delta_new)
135
+ return replace(self, **changes)
116
136
 
117
137
  def _energy_unconstrained(self, z, params):
118
138
  v, u = float(z[0]), float(z[1])
@@ -170,7 +190,10 @@ def target_delta(params: PhysicalParams, target_force: float) -> float:
170
190
  Corresponding value of the truncation threshold :math:`\delta`.
171
191
 
172
192
  .. note::
173
- We search for the cell-cell distance at which the intercellular force matches (last one) the target force, from :math:`10^{-6}\ell` to :math:`(2-10^{-6})\ell` with a step :math:`10^{-6}\ell`.
193
+ We search for the cell-cell separation at which the intercellular force
194
+ equals the target force, scanning distances from :math:`10^{-6}\ell` to
195
+ :math:`(2-10^{-6})\ell` in steps of :math:`10^{-6}\ell`, and select the
196
+ **largest distance** at which the match occurs.
174
197
  """
175
198
 
176
199
  if not isinstance(params, PhysicalParams): # pragma: no cover
@@ -11,6 +11,7 @@ The first two routines depend on specific backends.
11
11
  import numpy as np
12
12
  import pytest
13
13
  import pyafv as afv
14
+ from scipy.spatial import Voronoi
14
15
 
15
16
 
16
17
  @pytest.fixture(scope="module")
@@ -78,3 +79,13 @@ def test_assemble_forces(benchmark, initial_pts):
78
79
  def test_full_build(benchmark, simulator, initial_pts):
79
80
  simulator.update_positions(initial_pts)
80
81
  benchmark(simulator.build)
82
+
83
+ def test_scipy_voronoi(benchmark, initial_pts):
84
+
85
+ def scipy_voronoi(pts: np.ndarray) -> tuple:
86
+ """ Measure only the Voronoi construction time. """
87
+ vor = Voronoi(pts)
88
+ rv_arr = np.asarray(vor.ridge_vertices, dtype=int) # (R,2) may contain -1
89
+ return rv_arr.shape
90
+
91
+ benchmark(scipy_voronoi, initial_pts)
@@ -7,7 +7,7 @@ def test_MATLAB(data_dir, simulator):
7
7
 
8
8
  # temporarily change delta to 0.0 for this test
9
9
  original_phys = simulator.phys
10
- new_phys = original_phys.with_delta(0.0)
10
+ new_phys = original_phys.replace(delta=0.0)
11
11
  simulator.update_params(new_phys)
12
12
 
13
13
  pts = np.loadtxt(data_dir / "init_pts.csv", delimiter=',')
@@ -38,6 +38,7 @@ def test_MATLAB(data_dir, simulator):
38
38
  def test_physical_params(phys):
39
39
  l, d = phys.get_steady_state()
40
40
  params = phys.with_optimal_radius()
41
+ params2 = phys.with_optimal_radius(digits=1, delta=0.5)
41
42
 
42
43
  # For the default physical params in the fixture
43
44
  l_real = 0.87
@@ -52,3 +53,5 @@ def test_physical_params(phys):
52
53
  assert l >= 0 and d >= 0, "Optimal (l,d) should be non-negative."
53
54
  assert np.abs(delta_t - delta_t_real) < 1.0e-4, f"Computed delta not correct."
54
55
  assert delta_t >= 0, "Computed delta should be non-negative."
56
+ assert params2.r == round(l, 1), "Optimal radius with digits not set correctly."
57
+ assert params2.delta == 0.5, "Delta not set correctly in with_optimal_radius."
@@ -6,7 +6,7 @@ def test_MATLAB_varying_A0(data_dir, simulator):
6
6
  # Now with varying preferred areas A0
7
7
  # temporarily change delta to 0.0 for this test
8
8
  original_phys = simulator.phys
9
- new_phys = original_phys.with_delta(0.0)
9
+ new_phys = original_phys.replace(delta=0.0)
10
10
 
11
11
  assert np.max(simulator.preferred_areas - original_phys.A0) < 1.0e-12, "Preferred areas not initialized correctly."
12
12
 
@@ -1,2 +0,0 @@
1
- # pyafv/_version.py
2
- __version__ = "0.4.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes