morphogen 1.0.0__py3-none-any.whl
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.
- morphogen/__init__.py +60 -0
- morphogen/__main__.py +7 -0
- morphogen/_platform.py +55 -0
- morphogen/_public.py +153 -0
- morphogen/_utils.py +80 -0
- morphogen/_version.py +1 -0
- morphogen/analysis/__init__.py +174 -0
- morphogen/analysis/anisotropy.py +135 -0
- morphogen/analysis/basic.py +38 -0
- morphogen/analysis/cells.py +54 -0
- morphogen/analysis/connectivity.py +156 -0
- morphogen/analysis/correlation.py +195 -0
- morphogen/analysis/covariance.py +80 -0
- morphogen/analysis/fractal.py +54 -0
- morphogen/analysis/measures.py +188 -0
- morphogen/analysis/morphology.py +265 -0
- morphogen/analysis/particles.py +160 -0
- morphogen/analysis/percolation.py +2034 -0
- morphogen/analysis/power_laws.py +143 -0
- morphogen/analysis/random_sets.py +351 -0
- morphogen/analysis/stereology.py +289 -0
- morphogen/analysis/surface.py +107 -0
- morphogen/analysis/topology.py +92 -0
- morphogen/automata/__init__.py +74 -0
- morphogen/automata/engine.py +211 -0
- morphogen/automata/growth.py +686 -0
- morphogen/automata/lattice.py +143 -0
- morphogen/automata/reaction.py +255 -0
- morphogen/automata/rules.py +353 -0
- morphogen/automata/tilings.py +1715 -0
- morphogen/cli.py +3526 -0
- morphogen/config.py +2167 -0
- morphogen/contact/__init__.py +113 -0
- morphogen/contact/experiments.py +368 -0
- morphogen/contact/hertz.py +104 -0
- morphogen/contact/kernels.py +827 -0
- morphogen/contact/periodic.py +278 -0
- morphogen/contact/problem.py +578 -0
- morphogen/contact/surfaces.py +310 -0
- morphogen/coupling/__init__.py +43 -0
- morphogen/coupling/ageing.py +143 -0
- morphogen/coupling/diffusion.py +226 -0
- morphogen/coupling/fenicsx.py +484 -0
- morphogen/coupling/oxidation.py +447 -0
- morphogen/coupling/plates.py +247 -0
- morphogen/design/__init__.py +51 -0
- morphogen/design/csp.py +616 -0
- morphogen/design/frames.py +277 -0
- morphogen/design/search.py +287 -0
- morphogen/design/tiles.py +336 -0
- morphogen/distributions.py +312 -0
- morphogen/domain.py +203 -0
- morphogen/dynamics/__init__.py +179 -0
- morphogen/dynamics/model.py +638 -0
- morphogen/dynamics/openradioss.py +643 -0
- morphogen/dynamics/results.py +515 -0
- morphogen/fracture/__init__.py +170 -0
- morphogen/fracture/bulk.py +349 -0
- morphogen/fracture/cohesive.py +1614 -0
- morphogen/fracture/ductile.py +557 -0
- morphogen/fracture/lefm.py +1168 -0
- morphogen/fracture/mixed.py +1178 -0
- morphogen/fracture/periodic.py +733 -0
- morphogen/fracture/phasefield.py +714 -0
- morphogen/fracture/phasefield_finite.py +368 -0
- morphogen/fracture/surface.py +572 -0
- morphogen/fracture/toughness.py +566 -0
- morphogen/gpu.py +108 -0
- morphogen/gui/__init__.py +8 -0
- morphogen/gui/api.py +1927 -0
- morphogen/gui/desktop.py +387 -0
- morphogen/gui/icon.png +0 -0
- morphogen/gui/index.html +1909 -0
- morphogen/gui/server.py +229 -0
- morphogen/gui/tools/__init__.py +629 -0
- morphogen/gui/tools/compare.py +149 -0
- morphogen/gui/tools/contact.py +391 -0
- morphogen/gui/tools/couplings.py +1085 -0
- morphogen/gui/tools/crackfront.py +245 -0
- morphogen/gui/tools/design.py +224 -0
- morphogen/gui/tools/dynamics.py +824 -0
- morphogen/gui/tools/fracture.py +2586 -0
- morphogen/gui/tools/interop.py +1654 -0
- morphogen/gui/tools/learning.py +595 -0
- morphogen/gui/tools/mechanics.py +3881 -0
- morphogen/gui/tools/nonlocal_damage.py +1321 -0
- morphogen/gui/tools/phasefield.py +215 -0
- morphogen/gui/tools/physics.py +597 -0
- morphogen/gui/tools/stability.py +1756 -0
- morphogen/gui/tools/statistics.py +1408 -0
- morphogen/gui/viewer.js +1100 -0
- morphogen/homogenization/__init__.py +210 -0
- morphogen/homogenization/acoustics.py +566 -0
- morphogen/homogenization/amg.py +1005 -0
- morphogen/homogenization/apparent.py +1046 -0
- morphogen/homogenization/behaviours.cu +2285 -0
- morphogen/homogenization/behaviours.py +944 -0
- morphogen/homogenization/beremin.py +263 -0
- morphogen/homogenization/bifurcation.py +1085 -0
- morphogen/homogenization/bloch.py +507 -0
- morphogen/homogenization/bounds.py +226 -0
- morphogen/homogenization/core.py +458 -0
- morphogen/homogenization/coupled.py +1135 -0
- morphogen/homogenization/crystal.py +2967 -0
- morphogen/homogenization/dilatation.py +454 -0
- morphogen/homogenization/elements.py +157 -0
- morphogen/homogenization/fatigue.py +768 -0
- morphogen/homogenization/fe.py +1739 -0
- morphogen/homogenization/fenicsx.py +307 -0
- morphogen/homogenization/fft.py +499 -0
- morphogen/homogenization/fft_nonlinear.py +391 -0
- morphogen/homogenization/finite.py +613 -0
- morphogen/homogenization/flow.py +361 -0
- morphogen/homogenization/frames.py +1125 -0
- morphogen/homogenization/gpu.py +1241 -0
- morphogen/homogenization/harmonic.py +427 -0
- morphogen/homogenization/identification.py +579 -0
- morphogen/homogenization/kernels.py +760 -0
- morphogen/homogenization/laws.py +2061 -0
- morphogen/homogenization/materials.py +1080 -0
- morphogen/homogenization/mfront.py +589 -0
- morphogen/homogenization/networks.py +880 -0
- morphogen/homogenization/nonlinear.py +2612 -0
- morphogen/homogenization/ntfa.py +577 -0
- morphogen/homogenization/paths.py +476 -0
- morphogen/homogenization/photonic.py +467 -0
- morphogen/homogenization/poroelastic.py +212 -0
- morphogen/homogenization/porous.py +1120 -0
- morphogen/homogenization/postprocess.py +290 -0
- morphogen/homogenization/solvers.py +1140 -0
- morphogen/homogenization/tensors.py +240 -0
- morphogen/homogenization/voxel_fe.py +457 -0
- morphogen/homogenization/xfem.py +1016 -0
- morphogen/homogenization/zmat.py +1258 -0
- morphogen/iga/__init__.py +48 -0
- morphogen/iga/analysis.py +508 -0
- morphogen/iga/basis.py +214 -0
- morphogen/iga/geometry.py +501 -0
- morphogen/iga/homogenization.py +219 -0
- morphogen/iga/optimization.py +700 -0
- morphogen/iga/shapes.py +331 -0
- morphogen/image.py +128 -0
- morphogen/io/__init__.py +246 -0
- morphogen/io/amitex.py +741 -0
- morphogen/io/ebsd.py +881 -0
- morphogen/io/export.py +196 -0
- morphogen/io/geometry.py +158 -0
- morphogen/io/medit.py +147 -0
- morphogen/io/meshes.py +844 -0
- morphogen/io/metaimage.py +97 -0
- morphogen/io/mfront.py +1104 -0
- morphogen/io/native.py +57 -0
- morphogen/io/radioss.py +764 -0
- morphogen/io/solvers.py +371 -0
- morphogen/io/tables.py +278 -0
- morphogen/io/tiff.py +66 -0
- morphogen/io/vtk.py +701 -0
- morphogen/io/xdmf.py +200 -0
- morphogen/kernels/__init__.py +5 -0
- morphogen/kernels/annealing.py +192 -0
- morphogen/kernels/cells.py +69 -0
- morphogen/kernels/collective.py +87 -0
- morphogen/kernels/force_biased.py +595 -0
- morphogen/kernels/implicit.py +145 -0
- morphogen/kernels/leaves.py +132 -0
- morphogen/kernels/packing.py +304 -0
- morphogen/kernels/raster.py +279 -0
- morphogen/kernels/rsa.py +371 -0
- morphogen/kernels/union.py +135 -0
- morphogen/kernels/watershed.py +190 -0
- morphogen/laser/__init__.py +234 -0
- morphogen/laser/architectures.py +375 -0
- morphogen/laser/bending.py +216 -0
- morphogen/laser/cells.py +1694 -0
- morphogen/laser/design.py +940 -0
- morphogen/laser/figures.py +227 -0
- morphogen/laser/heat.py +804 -0
- morphogen/laser/materials.py +691 -0
- morphogen/laser/mechanics.py +1670 -0
- morphogen/laser/metallurgy.py +615 -0
- morphogen/laser/patterns.py +828 -0
- morphogen/laser/periodic.py +392 -0
- morphogen/laser/process.py +362 -0
- morphogen/laser/run.py +534 -0
- morphogen/laser/solid.py +216 -0
- morphogen/laser/specimen.py +200 -0
- morphogen/laser/structures.py +708 -0
- morphogen/learning/__init__.py +81 -0
- morphogen/learning/behaviour.py +398 -0
- morphogen/learning/data.py +328 -0
- morphogen/learning/learned.cpp +668 -0
- morphogen/learning/logarithmic.py +202 -0
- morphogen/learning/mfront.py +409 -0
- morphogen/learning/networks.py +767 -0
- morphogen/learning/run.py +212 -0
- morphogen/learning/standard.py +814 -0
- morphogen/learning/training.py +235 -0
- morphogen/mesh/__init__.py +29 -0
- morphogen/mesh/conforming.py +1423 -0
- morphogen/mesh/curved.py +600 -0
- morphogen/mesh/exact.py +1717 -0
- morphogen/mesh/octree.py +350 -0
- morphogen/mesh/polycrystal.py +1041 -0
- morphogen/mesh/polyhedra.py +677 -0
- morphogen/mesh/regularize.py +570 -0
- morphogen/mesh/surface.py +97 -0
- morphogen/mesh/tetra.py +512 -0
- morphogen/mesh/voxel.py +124 -0
- morphogen/micromorphic/__init__.py +31 -0
- morphogen/micromorphic/damage.py +359 -0
- morphogen/micromorphic/ductile.py +534 -0
- morphogen/micromorphic/finite.py +220 -0
- morphogen/micromorphic/microfoam.py +787 -0
- morphogen/micromorphic/space.py +341 -0
- morphogen/models/__init__.py +195 -0
- morphogen/models/affine.py +384 -0
- morphogen/models/automata.py +592 -0
- morphogen/models/base.py +500 -0
- morphogen/models/boolean.py +310 -0
- morphogen/models/bouligand.py +331 -0
- morphogen/models/branching.py +241 -0
- morphogen/models/combination.py +430 -0
- morphogen/models/deadleaves.py +766 -0
- morphogen/models/design.py +289 -0
- morphogen/models/ebsd.py +206 -0
- morphogen/models/fibers.py +1476 -0
- morphogen/models/foam.py +594 -0
- morphogen/models/gaussian.py +314 -0
- morphogen/models/growth.py +459 -0
- morphogen/models/hardcore.py +317 -0
- morphogen/models/hierarchical.py +269 -0
- morphogen/models/honeycomb.py +749 -0
- morphogen/models/implicit.py +177 -0
- morphogen/models/laminate.py +470 -0
- morphogen/models/lattice.py +351 -0
- morphogen/models/lattice_field.py +345 -0
- morphogen/models/levelset_foam.py +563 -0
- morphogen/models/nacre.py +411 -0
- morphogen/models/nested.py +924 -0
- morphogen/models/osteons.py +374 -0
- morphogen/models/pieces.py +167 -0
- morphogen/models/planar.py +126 -0
- morphogen/models/reconstruction.py +203 -0
- morphogen/models/scale_rich.py +1409 -0
- morphogen/models/scale_rich_3d.py +1616 -0
- morphogen/models/tessellation.py +735 -0
- morphogen/models/tiling_field.py +302 -0
- morphogen/models/tpms.py +197 -0
- morphogen/models/transparent.py +406 -0
- morphogen/models/union.py +141 -0
- morphogen/optimization/__init__.py +43 -0
- morphogen/optimization/cell.py +295 -0
- morphogen/optimization/filters.py +115 -0
- morphogen/optimization/mma.py +226 -0
- morphogen/optimization/run.py +219 -0
- morphogen/optimization/topology.py +632 -0
- morphogen/orientations.py +568 -0
- morphogen/parallel.py +599 -0
- morphogen/pipeline.py +978 -0
- morphogen/primitives.py +188 -0
- morphogen/results.py +564 -0
- morphogen/rve/__init__.py +73 -0
- morphogen/rve/report.py +627 -0
- morphogen/rve/scaling.py +363 -0
- morphogen/rve/study.py +1054 -0
- morphogen/rve/windows.py +345 -0
- morphogen/seeding.py +51 -0
- morphogen/settings.py +118 -0
- morphogen/stopping.py +48 -0
- morphogen/symmetry.py +384 -0
- morphogen/templates/activator_inhibitor.yaml +22 -0
- morphogen/templates/aggregation.yaml +23 -0
- morphogen/templates/boolean_cylinders.yaml +20 -0
- morphogen/templates/boolean_spheres.yaml +22 -0
- morphogen/templates/bouligand.yaml +28 -0
- morphogen/templates/cellular_automaton.yaml +25 -0
- morphogen/templates/coated_spheres.yaml +26 -0
- morphogen/templates/contact_fibers.yaml +27 -0
- morphogen/templates/cox_nanocomposite.yaml +22 -0
- morphogen/templates/cross_linked_fibers.yaml +26 -0
- morphogen/templates/curved_arcs.yaml +28 -0
- morphogen/templates/curved_fibers.yaml +24 -0
- morphogen/templates/dead_leaves.yaml +22 -0
- morphogen/templates/delaunay_network.yaml +22 -0
- morphogen/templates/dense_packing.yaml +22 -0
- morphogen/templates/diffusion.yaml +33 -0
- morphogen/templates/ebsd.yaml +34 -0
- morphogen/templates/ebsd_map.ctf +3087 -0
- morphogen/templates/fracture_composite.yaml +42 -0
- morphogen/templates/fracture_rubber.yaml +47 -0
- morphogen/templates/gaussian_excursion.yaml +17 -0
- morphogen/templates/graded_lattice.yaml +24 -0
- morphogen/templates/hardcore_fibers.yaml +22 -0
- morphogen/templates/hardcore_spheres.yaml +22 -0
- morphogen/templates/hierarchical_lattice.yaml +22 -0
- morphogen/templates/homogenization_acoustic_foam.yaml +36 -0
- morphogen/templates/homogenization_beremin.yaml +50 -0
- morphogen/templates/homogenization_cleavage.yaml +51 -0
- morphogen/templates/homogenization_cleavage_band.yaml +55 -0
- morphogen/templates/homogenization_contact.yaml +43 -0
- morphogen/templates/homogenization_crack_closure.yaml +49 -0
- morphogen/templates/homogenization_crystal_plasticity.yaml +50 -0
- morphogen/templates/homogenization_crystal_plasticity_fft.yaml +52 -0
- morphogen/templates/homogenization_crystallization.yaml +30 -0
- morphogen/templates/homogenization_debonding.yaml +43 -0
- morphogen/templates/homogenization_detwinning.yaml +58 -0
- morphogen/templates/homogenization_ductile_damage.yaml +47 -0
- morphogen/templates/homogenization_fatigue.yaml +40 -0
- morphogen/templates/homogenization_grain_fracture.yaml +56 -0
- morphogen/templates/homogenization_gyroid.yaml +30 -0
- morphogen/templates/homogenization_intergranular.yaml +43 -0
- morphogen/templates/homogenization_interphase.yaml +42 -0
- morphogen/templates/homogenization_mixed_loading.yaml +33 -0
- morphogen/templates/homogenization_ntfa.yaml +56 -0
- morphogen/templates/homogenization_piezoelectric.yaml +27 -0
- morphogen/templates/homogenization_polycrystal.yaml +30 -0
- morphogen/templates/homogenization_polycrystal_inclusions.yaml +30 -0
- morphogen/templates/homogenization_poroelastic.yaml +26 -0
- morphogen/templates/homogenization_rubber.yaml +40 -0
- morphogen/templates/homogenization_slip_cleavage.yaml +50 -0
- morphogen/templates/homogenization_spheres.yaml +31 -0
- morphogen/templates/homogenization_transport.yaml +29 -0
- morphogen/templates/homogenization_twinning.yaml +54 -0
- morphogen/templates/homogenization_viscoelastic.yaml +34 -0
- morphogen/templates/homogenization_viscoplastic.yaml +42 -0
- morphogen/templates/homogenization_voronoi.yaml +26 -0
- morphogen/templates/homogenization_xfem.yaml +23 -0
- morphogen/templates/hyperuniform_cells.yaml +24 -0
- morphogen/templates/laguerre.yaml +18 -0
- morphogen/templates/laser_bending.yaml +35 -0
- morphogen/templates/laser_cells.yaml +38 -0
- morphogen/templates/laser_corrugated.yaml +36 -0
- morphogen/templates/level_set_foam.yaml +29 -0
- morphogen/templates/menger_sponge.yaml +17 -0
- morphogen/templates/nacre.yaml +25 -0
- morphogen/templates/nucleation_growth.yaml +25 -0
- morphogen/templates/optimize_auxetic.yaml +29 -0
- morphogen/templates/optimize_auxetic_3d.yaml +27 -0
- morphogen/templates/optimize_bulk.yaml +23 -0
- morphogen/templates/optimize_conductivity.yaml +20 -0
- morphogen/templates/osteons.yaml +28 -0
- morphogen/templates/penetrable_spheres.yaml +21 -0
- morphogen/templates/poisson_fibers.yaml +21 -0
- morphogen/templates/random_laminate.yaml +26 -0
- morphogen/templates/random_lattice.yaml +27 -0
- morphogen/templates/random_walk_fibers.yaml +26 -0
- morphogen/templates/reaction_diffusion.yaml +22 -0
- morphogen/templates/reconstruction.yaml +22 -0
- morphogen/templates/rve_cellular_automaton.yaml +23 -0
- morphogen/templates/rve_crystal_plasticity_fft.yaml +51 -0
- morphogen/templates/rve_multiphysics.yaml +43 -0
- morphogen/templates/rve_poisson_fibers.yaml +22 -0
- morphogen/templates/rve_poisson_fibers_fe.yaml +33 -0
- morphogen/templates/rve_voronoi_windows.yaml +20 -0
- morphogen/templates/scale_rich_network.yaml +29 -0
- morphogen/templates/scale_rich_plates.yaml +30 -0
- morphogen/templates/sequential_dead_leaves.yaml +25 -0
- morphogen/templates/strut_lattice.yaml +21 -0
- morphogen/templates/tile_assembly.yaml +28 -0
- morphogen/templates/tpms.yaml +19 -0
- morphogen/templates/trabecular_bone.yaml +29 -0
- morphogen/templates/transparent_dead_leaves.yaml +23 -0
- morphogen/templates/vascular_tree.yaml +23 -0
- morphogen/templates/voronoi.yaml +20 -0
- morphogen/templates/wood.yaml +34 -0
- morphogen/templates/workflow.yaml +56 -0
- morphogen/texture.py +665 -0
- morphogen/theory.py +162 -0
- morphogen/viz/__init__.py +12 -0
- morphogen/viz/export.py +244 -0
- morphogen/viz/figures.py +707 -0
- morphogen/viz/png.py +148 -0
- morphogen/viz/sections.py +696 -0
- morphogen/viz/surfaces.py +1352 -0
- morphogen/viz/video.py +904 -0
- morphogen/viz/workflow.py +488 -0
- morphogen-1.0.0.dist-info/METADATA +2316 -0
- morphogen-1.0.0.dist-info/RECORD +381 -0
- morphogen-1.0.0.dist-info/WHEEL +4 -0
- morphogen-1.0.0.dist-info/entry_points.txt +5 -0
- morphogen-1.0.0.dist-info/licenses/LICENSE +674 -0
morphogen/__init__.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""morphoGen: morphological modelling and generation of virtual microstructures.
|
|
2
|
+
|
|
3
|
+
Typical use::
|
|
4
|
+
|
|
5
|
+
import morphogen as mg
|
|
6
|
+
|
|
7
|
+
model = mg.models.BooleanSpheres(radius=1.0, volume_fraction=0.3)
|
|
8
|
+
micro = model.generate(mg.Domain.cube(20.0), seed=1) # explicit ("vector") geometry
|
|
9
|
+
image = micro.voxelize(shape=128) # phase image (uint8)
|
|
10
|
+
print(mg.analysis.volume_fraction(image), model.theory()["volume_fraction"])
|
|
11
|
+
mg.io.save_image(image, "spheres.vti")
|
|
12
|
+
|
|
13
|
+
mesh = mg.mesh.conforming_mesh(micro, size=0.5) # conforming tetrahedra (MMG)
|
|
14
|
+
materials = {0: mg.homogenization.Material(young=1.0, poisson=0.3),
|
|
15
|
+
1: mg.homogenization.Material(young=10.0, poisson=0.3)}
|
|
16
|
+
results = mg.homogenization.homogenize(mesh, materials, bcs=["kubc", "periodic"])
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from morphogen import (
|
|
20
|
+
analysis,
|
|
21
|
+
automata,
|
|
22
|
+
design,
|
|
23
|
+
distributions,
|
|
24
|
+
homogenization,
|
|
25
|
+
io,
|
|
26
|
+
mesh,
|
|
27
|
+
models,
|
|
28
|
+
orientations,
|
|
29
|
+
rve,
|
|
30
|
+
texture,
|
|
31
|
+
)
|
|
32
|
+
from morphogen._version import __version__
|
|
33
|
+
from morphogen.domain import Domain, Grid
|
|
34
|
+
from morphogen.image import VoxelImage
|
|
35
|
+
from morphogen.io.export import export
|
|
36
|
+
from morphogen.models import get_model, list_models, model_from_config
|
|
37
|
+
from morphogen.settings import set_num_threads
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
"Domain",
|
|
41
|
+
"Grid",
|
|
42
|
+
"VoxelImage",
|
|
43
|
+
"__version__",
|
|
44
|
+
"analysis",
|
|
45
|
+
"automata",
|
|
46
|
+
"design",
|
|
47
|
+
"distributions",
|
|
48
|
+
"export",
|
|
49
|
+
"get_model",
|
|
50
|
+
"homogenization",
|
|
51
|
+
"io",
|
|
52
|
+
"list_models",
|
|
53
|
+
"mesh",
|
|
54
|
+
"model_from_config",
|
|
55
|
+
"models",
|
|
56
|
+
"orientations",
|
|
57
|
+
"rve",
|
|
58
|
+
"set_num_threads",
|
|
59
|
+
"texture",
|
|
60
|
+
]
|
morphogen/__main__.py
ADDED
morphogen/_platform.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Settings of the process that depend on the operating system."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def full_speed() -> bool:
|
|
9
|
+
"""Opt the process out of the power throttling of Windows (EcoQoS).
|
|
10
|
+
|
|
11
|
+
Windows 11 moves a process that it deems in the background, such as one started by
|
|
12
|
+
an agent, to the efficiency cores at a low clock after a few seconds of computing,
|
|
13
|
+
where the compiled kernels run several times slower. A process whose execution speed
|
|
14
|
+
is set to "never throttled" stays on the performance cores. The processes that it
|
|
15
|
+
starts do not inherit the setting: each one makes it (the command line, the
|
|
16
|
+
processes of :func:`morphogen.parallel.process_pool`; the processes of the tests in
|
|
17
|
+
``tests/conftest.py``, the build of the documentation in ``docs/conf.py``).
|
|
18
|
+
|
|
19
|
+
Returns whether the setting was made: ``False`` on the other systems, where it does
|
|
20
|
+
nothing, and on the versions of Windows without it (before Windows 10 1709). Never
|
|
21
|
+
raises.
|
|
22
|
+
"""
|
|
23
|
+
if sys.platform != "win32":
|
|
24
|
+
return False
|
|
25
|
+
try:
|
|
26
|
+
import ctypes
|
|
27
|
+
from ctypes import wintypes
|
|
28
|
+
|
|
29
|
+
class State(ctypes.Structure): # PROCESS_POWER_THROTTLING_STATE
|
|
30
|
+
_fields_ = (
|
|
31
|
+
("Version", wintypes.ULONG),
|
|
32
|
+
("ControlMask", wintypes.ULONG),
|
|
33
|
+
("StateMask", wintypes.ULONG),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
kernel32 = ctypes.WinDLL("kernel32") # an instance of its own: its argtypes
|
|
37
|
+
kernel32.GetCurrentProcess.restype = wintypes.HANDLE
|
|
38
|
+
kernel32.SetProcessInformation.argtypes = (
|
|
39
|
+
wintypes.HANDLE,
|
|
40
|
+
ctypes.c_int,
|
|
41
|
+
ctypes.c_void_p,
|
|
42
|
+
wintypes.DWORD,
|
|
43
|
+
)
|
|
44
|
+
kernel32.SetProcessInformation.restype = wintypes.BOOL
|
|
45
|
+
# version 1; the execution speed (bit 1) controlled and not throttled
|
|
46
|
+
state = State(1, 1, 0)
|
|
47
|
+
done = kernel32.SetProcessInformation(
|
|
48
|
+
kernel32.GetCurrentProcess(),
|
|
49
|
+
4, # ProcessPowerThrottling
|
|
50
|
+
ctypes.byref(state),
|
|
51
|
+
ctypes.sizeof(state),
|
|
52
|
+
)
|
|
53
|
+
return bool(done)
|
|
54
|
+
except Exception: # left as it is (an older Windows, a restricted process)
|
|
55
|
+
return False
|
morphogen/_public.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""The public interface of morphoGen (docs/stability.md): its modules and their public
|
|
2
|
+
names, for the API reference of the documentation site (docs/conf.py) and for the test
|
|
3
|
+
that keeps the list of these names (tests/test_public_api.py)."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import ast
|
|
8
|
+
import importlib
|
|
9
|
+
import inspect
|
|
10
|
+
import pkgutil
|
|
11
|
+
import re
|
|
12
|
+
from pathlib import PurePath
|
|
13
|
+
|
|
14
|
+
import morphogen
|
|
15
|
+
|
|
16
|
+
#: The modules left out of the public interface: the command line (its commands are
|
|
17
|
+
#: public, not the functions behind them), the graphical interface (a web page and its
|
|
18
|
+
#: server) and the compiled kernels
|
|
19
|
+
INTERNAL = ("morphogen.cli", "morphogen.gui", "morphogen.kernels")
|
|
20
|
+
|
|
21
|
+
#: The types of the module attributes counted as public data
|
|
22
|
+
DATA = (bool, int, float, complex, str, bytes, tuple, list, dict, set, frozenset)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def is_public_module(name: str) -> bool:
|
|
26
|
+
"""Whether a module of morphoGen is part of the public interface."""
|
|
27
|
+
if any(part.startswith("_") for part in name.split(".")):
|
|
28
|
+
return False
|
|
29
|
+
return not any(name == m or name.startswith(m + ".") for m in INTERNAL)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def public_modules() -> list[tuple[str, bool]]:
|
|
33
|
+
"""The modules of the public interface, ``(name, is a package)``, sorted by name."""
|
|
34
|
+
found = [("morphogen", True)]
|
|
35
|
+
for info in pkgutil.walk_packages(morphogen.__path__, "morphogen."):
|
|
36
|
+
if is_public_module(info.name):
|
|
37
|
+
found.append((info.name, info.ispkg))
|
|
38
|
+
return sorted(found)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _compiled(obj) -> bool: # a Numba or CUDA kernel
|
|
42
|
+
return type(obj).__module__.split(".")[0] in ("numba", "cupy")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _assigned(module) -> set[str] | None:
|
|
46
|
+
"""The names that a module assigns at its top level (in its branches too), from its
|
|
47
|
+
source; None without a source."""
|
|
48
|
+
try:
|
|
49
|
+
tree = ast.parse(inspect.getsource(module))
|
|
50
|
+
except (OSError, TypeError, SyntaxError):
|
|
51
|
+
return None
|
|
52
|
+
names = set()
|
|
53
|
+
nodes = list(tree.body)
|
|
54
|
+
while nodes:
|
|
55
|
+
node = nodes.pop()
|
|
56
|
+
if isinstance(node, (ast.Assign, ast.AnnAssign, ast.AugAssign)):
|
|
57
|
+
targets = node.targets if isinstance(node, ast.Assign) else [node.target]
|
|
58
|
+
names.update(n.id for t in targets for n in ast.walk(t) if isinstance(n, ast.Name))
|
|
59
|
+
elif isinstance(node, (ast.If, ast.Try, ast.With)):
|
|
60
|
+
nodes.extend(node.body)
|
|
61
|
+
nodes.extend(getattr(node, "orelse", []))
|
|
62
|
+
nodes.extend(getattr(node, "finalbody", []))
|
|
63
|
+
for handler in getattr(node, "handlers", []):
|
|
64
|
+
nodes.extend(handler.body)
|
|
65
|
+
return names
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def defined_names(module) -> list[tuple[str, object]]:
|
|
69
|
+
"""The public names that a module defines: its functions and classes, and the data
|
|
70
|
+
that it assigns (not what it imports), sorted by name."""
|
|
71
|
+
names = []
|
|
72
|
+
assigned = _assigned(module)
|
|
73
|
+
for attr, obj in vars(module).items():
|
|
74
|
+
if attr.startswith("_") or inspect.ismodule(obj) or _compiled(obj):
|
|
75
|
+
continue
|
|
76
|
+
if inspect.isfunction(obj) or inspect.isclass(obj):
|
|
77
|
+
if obj.__module__ == module.__name__:
|
|
78
|
+
names.append((attr, obj))
|
|
79
|
+
elif isinstance(obj, DATA) and (assigned is None or attr in assigned):
|
|
80
|
+
names.append((attr, obj))
|
|
81
|
+
return sorted(names, key=lambda item: item[0])
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _default(value) -> str:
|
|
85
|
+
if isinstance(value, PurePath): # the same on every system (not WindowsPath, PosixPath)
|
|
86
|
+
return f"Path({value.as_posix()!r})"
|
|
87
|
+
return re.sub(r" at 0x[0-9A-Fa-f]+", "", repr(value))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def parameters(obj) -> str:
|
|
91
|
+
"""The parameters of a function or class, without their annotations: their names,
|
|
92
|
+
kinds and defaults (``(a, b=1, *, c=None, **options)``)."""
|
|
93
|
+
try:
|
|
94
|
+
signature = inspect.signature(obj)
|
|
95
|
+
except (TypeError, ValueError):
|
|
96
|
+
return "(...)"
|
|
97
|
+
parts, positional_only, keyword_only = [], False, False
|
|
98
|
+
for p in signature.parameters.values():
|
|
99
|
+
if p.kind is p.POSITIONAL_ONLY:
|
|
100
|
+
positional_only = True
|
|
101
|
+
elif positional_only:
|
|
102
|
+
parts.append("/")
|
|
103
|
+
positional_only = False
|
|
104
|
+
if p.kind is p.KEYWORD_ONLY and not keyword_only:
|
|
105
|
+
parts.append("*")
|
|
106
|
+
keyword_only = True
|
|
107
|
+
if p.kind is p.VAR_POSITIONAL:
|
|
108
|
+
parts.append(f"*{p.name}")
|
|
109
|
+
keyword_only = True
|
|
110
|
+
elif p.kind is p.VAR_KEYWORD:
|
|
111
|
+
parts.append(f"**{p.name}")
|
|
112
|
+
elif p.default is p.empty:
|
|
113
|
+
parts.append(p.name)
|
|
114
|
+
else:
|
|
115
|
+
parts.append(f"{p.name}={_default(p.default)}")
|
|
116
|
+
if positional_only:
|
|
117
|
+
parts.append("/")
|
|
118
|
+
return "(" + ", ".join(parts) + ")"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _members(cls) -> list[str]:
|
|
122
|
+
"""The public methods and properties that a class defines."""
|
|
123
|
+
lines = []
|
|
124
|
+
for attr, raw in sorted(vars(cls).items()):
|
|
125
|
+
if attr.startswith("_"):
|
|
126
|
+
continue
|
|
127
|
+
if isinstance(raw, property):
|
|
128
|
+
lines.append(f".{attr}")
|
|
129
|
+
elif isinstance(raw, (classmethod, staticmethod)):
|
|
130
|
+
lines.append(f".{attr}{parameters(raw.__func__)}")
|
|
131
|
+
elif inspect.isfunction(raw):
|
|
132
|
+
lines.append(f".{attr}{parameters(raw)}")
|
|
133
|
+
return lines
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def public_interface() -> list[str]:
|
|
137
|
+
"""One line per public name: the names of the ``__all__`` of each package, then the
|
|
138
|
+
functions (with their parameters), classes (with their public methods and
|
|
139
|
+
properties) and data that each module defines."""
|
|
140
|
+
lines = []
|
|
141
|
+
for name, is_package in public_modules():
|
|
142
|
+
module = importlib.import_module(name)
|
|
143
|
+
if is_package:
|
|
144
|
+
lines.extend(f"{name}: {attr}" for attr in getattr(module, "__all__", []))
|
|
145
|
+
for attr, obj in defined_names(module):
|
|
146
|
+
if inspect.isclass(obj):
|
|
147
|
+
lines.append(f"{name}.{attr}{parameters(obj)}")
|
|
148
|
+
lines.extend(f"{name}.{attr}{member}" for member in _members(obj))
|
|
149
|
+
elif inspect.isfunction(obj):
|
|
150
|
+
lines.append(f"{name}.{attr}{parameters(obj)}")
|
|
151
|
+
else:
|
|
152
|
+
lines.append(f"{name}.{attr}")
|
|
153
|
+
return lines
|
morphogen/_utils.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Small validation and conversion helpers shared by the package."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
from collections.abc import Iterable
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def as_triplet(value, name: str, *, positive: bool = False, integer: bool = False) -> tuple:
|
|
12
|
+
"""Return ``value`` as a tuple of three numbers (a scalar is repeated)."""
|
|
13
|
+
try:
|
|
14
|
+
arr = np.asarray(value, dtype=float)
|
|
15
|
+
except (TypeError, ValueError):
|
|
16
|
+
raise ValueError(
|
|
17
|
+
f"{name}: expected a number or a list of 3 numbers, got {value!r}"
|
|
18
|
+
) from None
|
|
19
|
+
if arr.ndim == 0:
|
|
20
|
+
arr = np.repeat(arr, 3)
|
|
21
|
+
if arr.shape != (3,):
|
|
22
|
+
raise ValueError(f"{name}: expected a number or a list of 3 numbers, got {value!r}")
|
|
23
|
+
if not np.all(np.isfinite(arr)):
|
|
24
|
+
raise ValueError(f"{name}: values must be finite, got {value!r}")
|
|
25
|
+
if positive and np.any(arr <= 0):
|
|
26
|
+
raise ValueError(f"{name}: values must be positive, got {value!r}")
|
|
27
|
+
if integer:
|
|
28
|
+
if np.any(arr != np.round(arr)):
|
|
29
|
+
raise ValueError(f"{name}: values must be integers, got {value!r}")
|
|
30
|
+
return tuple(int(v) for v in arr)
|
|
31
|
+
return tuple(float(v) for v in arr)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def check_fraction(value: float, name: str, *, open_interval: bool = True) -> float:
|
|
35
|
+
"""Check that ``value`` lies in (0, 1) (or [0, 1])."""
|
|
36
|
+
v = float(value)
|
|
37
|
+
ok = 0.0 < v < 1.0 if open_interval else 0.0 <= v <= 1.0
|
|
38
|
+
if not ok:
|
|
39
|
+
bounds = "(0, 1)" if open_interval else "[0, 1]"
|
|
40
|
+
raise ValueError(f"{name}: must lie in {bounds}, got {value!r}")
|
|
41
|
+
return v
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def check_positive(value: float, name: str, *, allow_zero: bool = False) -> float:
|
|
45
|
+
v = float(value)
|
|
46
|
+
if not math.isfinite(v) or v < 0 or (v == 0 and not allow_zero):
|
|
47
|
+
sign = "non-negative" if allow_zero else "positive"
|
|
48
|
+
raise ValueError(f"{name}: must be a finite {sign} number, got {value!r}")
|
|
49
|
+
return v
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def exactly_one(name_a: str, a, name_b: str, b) -> None:
|
|
53
|
+
"""Raise unless exactly one of two alternative parameters is given."""
|
|
54
|
+
if (a is None) == (b is None):
|
|
55
|
+
raise ValueError(f"give exactly one of '{name_a}' and '{name_b}'")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def unit_vector(v: Iterable[float], name: str) -> np.ndarray:
|
|
59
|
+
arr = np.asarray(v, dtype=float)
|
|
60
|
+
if arr.shape != (3,):
|
|
61
|
+
raise ValueError(f"{name}: expected 3 components, got {v!r}")
|
|
62
|
+
norm = np.linalg.norm(arr)
|
|
63
|
+
if not norm > 0:
|
|
64
|
+
raise ValueError(f"{name}: must be a non-zero vector, got {v!r}")
|
|
65
|
+
return arr / norm
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def to_jsonable(value):
|
|
69
|
+
"""Convert numpy scalars/arrays (recursively) to plain Python types."""
|
|
70
|
+
if isinstance(value, dict):
|
|
71
|
+
return {str(k): to_jsonable(v) for k, v in value.items()}
|
|
72
|
+
if isinstance(value, (list, tuple)):
|
|
73
|
+
return [to_jsonable(v) for v in value]
|
|
74
|
+
if isinstance(value, np.ndarray):
|
|
75
|
+
return value.tolist()
|
|
76
|
+
if isinstance(value, np.generic):
|
|
77
|
+
return value.item()
|
|
78
|
+
if isinstance(value, float) and not math.isfinite(value):
|
|
79
|
+
return str(value)
|
|
80
|
+
return value
|
morphogen/_version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"""Morphological measurements on voxel images."""
|
|
2
|
+
|
|
3
|
+
from morphogen.analysis.anisotropy import (
|
|
4
|
+
Fabric,
|
|
5
|
+
HoleEffect,
|
|
6
|
+
covariance_minima,
|
|
7
|
+
fabric_tensor,
|
|
8
|
+
mean_intercept_length,
|
|
9
|
+
)
|
|
10
|
+
from morphogen.analysis.basic import indicator, phase_fractions, volume_fraction
|
|
11
|
+
from morphogen.analysis.cells import cell_adjacency, cell_neighbors, cell_volumes
|
|
12
|
+
from morphogen.analysis.connectivity import Components, connected_components, wrapping
|
|
13
|
+
from morphogen.analysis.correlation import (
|
|
14
|
+
PoreSizes,
|
|
15
|
+
lineal_path,
|
|
16
|
+
pore_size_function,
|
|
17
|
+
radial_distribution,
|
|
18
|
+
structure_factor,
|
|
19
|
+
two_point_cluster,
|
|
20
|
+
)
|
|
21
|
+
from morphogen.analysis.covariance import AxisCovariance, AxisFunction, covariance, covariance_map
|
|
22
|
+
from morphogen.analysis.fractal import box_counting, box_dimension
|
|
23
|
+
from morphogen.analysis.measures import MEASURES, measure
|
|
24
|
+
from morphogen.analysis.morphology import (
|
|
25
|
+
Granulometry,
|
|
26
|
+
Minkowski,
|
|
27
|
+
chord_lengths,
|
|
28
|
+
euler_characteristic,
|
|
29
|
+
geodesic_distance,
|
|
30
|
+
geometric_tortuosity,
|
|
31
|
+
granulometry,
|
|
32
|
+
local_thickness,
|
|
33
|
+
mean_chord_length,
|
|
34
|
+
minkowski,
|
|
35
|
+
)
|
|
36
|
+
from morphogen.analysis.particles import Particles, particle_sizes
|
|
37
|
+
from morphogen.analysis.percolation import (
|
|
38
|
+
DirectionalPercolation,
|
|
39
|
+
Fire,
|
|
40
|
+
PercolationAnisotropy,
|
|
41
|
+
PercolationExponent,
|
|
42
|
+
PercolationScaling,
|
|
43
|
+
PercolationThreshold,
|
|
44
|
+
RigidityThreshold,
|
|
45
|
+
burn,
|
|
46
|
+
burn_along,
|
|
47
|
+
directional_percolation,
|
|
48
|
+
percolation_anisotropy,
|
|
49
|
+
percolation_exponent,
|
|
50
|
+
percolation_scaling,
|
|
51
|
+
percolation_threshold,
|
|
52
|
+
rigidity_threshold,
|
|
53
|
+
)
|
|
54
|
+
from morphogen.analysis.power_laws import PowerLawTail, power_law_tail
|
|
55
|
+
from morphogen.analysis.random_sets import (
|
|
56
|
+
Capacity,
|
|
57
|
+
MorphologicalCovariance,
|
|
58
|
+
choquet_capacity,
|
|
59
|
+
closing,
|
|
60
|
+
dilation,
|
|
61
|
+
erosion,
|
|
62
|
+
minkowski_curves,
|
|
63
|
+
morphological_covariance,
|
|
64
|
+
opening,
|
|
65
|
+
)
|
|
66
|
+
from morphogen.analysis.stereology import (
|
|
67
|
+
Sections,
|
|
68
|
+
Unfolding,
|
|
69
|
+
consistent_shape,
|
|
70
|
+
saltykov_matrix,
|
|
71
|
+
section_scales,
|
|
72
|
+
section_sizes,
|
|
73
|
+
shape_consistency,
|
|
74
|
+
unfold_sections,
|
|
75
|
+
)
|
|
76
|
+
from morphogen.analysis.surface import (
|
|
77
|
+
boundary_density,
|
|
78
|
+
crofton_weights,
|
|
79
|
+
interface_density,
|
|
80
|
+
specific_surface,
|
|
81
|
+
)
|
|
82
|
+
from morphogen.analysis.topology import (
|
|
83
|
+
Betti,
|
|
84
|
+
betti_numbers,
|
|
85
|
+
connectivity_density,
|
|
86
|
+
mean_curvature_density,
|
|
87
|
+
section_euler_density,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
__all__ = [
|
|
91
|
+
"MEASURES",
|
|
92
|
+
"AxisCovariance",
|
|
93
|
+
"AxisFunction",
|
|
94
|
+
"Betti",
|
|
95
|
+
"Capacity",
|
|
96
|
+
"Components",
|
|
97
|
+
"DirectionalPercolation",
|
|
98
|
+
"Fabric",
|
|
99
|
+
"Fire",
|
|
100
|
+
"Granulometry",
|
|
101
|
+
"HoleEffect",
|
|
102
|
+
"Minkowski",
|
|
103
|
+
"MorphologicalCovariance",
|
|
104
|
+
"Particles",
|
|
105
|
+
"PercolationAnisotropy",
|
|
106
|
+
"PercolationExponent",
|
|
107
|
+
"PercolationScaling",
|
|
108
|
+
"PercolationThreshold",
|
|
109
|
+
"PoreSizes",
|
|
110
|
+
"PowerLawTail",
|
|
111
|
+
"RigidityThreshold",
|
|
112
|
+
"Sections",
|
|
113
|
+
"Unfolding",
|
|
114
|
+
"betti_numbers",
|
|
115
|
+
"boundary_density",
|
|
116
|
+
"box_counting",
|
|
117
|
+
"box_dimension",
|
|
118
|
+
"burn",
|
|
119
|
+
"burn_along",
|
|
120
|
+
"cell_adjacency",
|
|
121
|
+
"cell_neighbors",
|
|
122
|
+
"cell_volumes",
|
|
123
|
+
"choquet_capacity",
|
|
124
|
+
"chord_lengths",
|
|
125
|
+
"closing",
|
|
126
|
+
"connected_components",
|
|
127
|
+
"connectivity_density",
|
|
128
|
+
"consistent_shape",
|
|
129
|
+
"covariance",
|
|
130
|
+
"covariance_map",
|
|
131
|
+
"covariance_minima",
|
|
132
|
+
"crofton_weights",
|
|
133
|
+
"dilation",
|
|
134
|
+
"directional_percolation",
|
|
135
|
+
"erosion",
|
|
136
|
+
"euler_characteristic",
|
|
137
|
+
"fabric_tensor",
|
|
138
|
+
"geodesic_distance",
|
|
139
|
+
"geometric_tortuosity",
|
|
140
|
+
"granulometry",
|
|
141
|
+
"indicator",
|
|
142
|
+
"interface_density",
|
|
143
|
+
"lineal_path",
|
|
144
|
+
"local_thickness",
|
|
145
|
+
"mean_chord_length",
|
|
146
|
+
"mean_curvature_density",
|
|
147
|
+
"mean_intercept_length",
|
|
148
|
+
"measure",
|
|
149
|
+
"minkowski",
|
|
150
|
+
"minkowski_curves",
|
|
151
|
+
"morphological_covariance",
|
|
152
|
+
"opening",
|
|
153
|
+
"particle_sizes",
|
|
154
|
+
"percolation_anisotropy",
|
|
155
|
+
"percolation_exponent",
|
|
156
|
+
"percolation_scaling",
|
|
157
|
+
"percolation_threshold",
|
|
158
|
+
"phase_fractions",
|
|
159
|
+
"pore_size_function",
|
|
160
|
+
"power_law_tail",
|
|
161
|
+
"radial_distribution",
|
|
162
|
+
"rigidity_threshold",
|
|
163
|
+
"saltykov_matrix",
|
|
164
|
+
"section_euler_density",
|
|
165
|
+
"section_scales",
|
|
166
|
+
"section_sizes",
|
|
167
|
+
"shape_consistency",
|
|
168
|
+
"specific_surface",
|
|
169
|
+
"structure_factor",
|
|
170
|
+
"two_point_cluster",
|
|
171
|
+
"unfold_sections",
|
|
172
|
+
"volume_fraction",
|
|
173
|
+
"wrapping",
|
|
174
|
+
]
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Anisotropy of a phase: the mean intercept length (MIL) along directions and its fabric
|
|
2
|
+
tensor (Whitehouse 1974; Harrigan & Mann 1984), as BoneJ computes it for trabecular bone
|
|
3
|
+
and Degdeg & Dirrenberger for an open-cell copper foam.
|
|
4
|
+
|
|
5
|
+
Along a direction ``d``, the test lines cross the boundary of the phase ``P_L(d)`` times
|
|
6
|
+
per unit length; the mean intercept length of the phase is ``MIL(d) = 2 V_V / P_L(d)``,
|
|
7
|
+
the mean length of its chords along ``d``. The MIL of an ellipsoidal structure follows an
|
|
8
|
+
ellipsoid: ``1 / MIL(d)^2 = d . M . d``, the fabric tensor ``M`` fitted by least squares to
|
|
9
|
+
the 13 directions of the grid (the three axes, the six face and the four body diagonals,
|
|
10
|
+
in physical units for anisotropic voxels); its principal MILs ``1 / sqrt(m_i)`` give the
|
|
11
|
+
anisotropy ratios and the degree of anisotropy ``1 - MIL_min / MIL_max``.
|
|
12
|
+
|
|
13
|
+
The covariance of a cellular phase passes through a first minimum below its plateau
|
|
14
|
+
``p^2`` before reaching it (the hole effect), at lags of the order of the cell radii:
|
|
15
|
+
Degdeg & Dirrenberger take these lags along the three axes as a second measure of the
|
|
16
|
+
aspect of the cells.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from dataclasses import dataclass
|
|
22
|
+
|
|
23
|
+
import numpy as np
|
|
24
|
+
|
|
25
|
+
from morphogen.analysis.basic import indicator
|
|
26
|
+
from morphogen.analysis.covariance import covariance
|
|
27
|
+
from morphogen.analysis.surface import DIRECTIONS_13, transitions
|
|
28
|
+
from morphogen.image import VoxelImage
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class Fabric:
|
|
33
|
+
"""The MIL along the ``directions`` (unit vectors), the fabric tensor ``M``, its
|
|
34
|
+
principal MILs (decreasing) and their ``axes`` (columns), the degree of anisotropy."""
|
|
35
|
+
|
|
36
|
+
directions: np.ndarray
|
|
37
|
+
mil: np.ndarray
|
|
38
|
+
tensor: np.ndarray
|
|
39
|
+
principal: np.ndarray
|
|
40
|
+
axes: np.ndarray
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def ratios(self) -> np.ndarray:
|
|
44
|
+
"""Principal MILs over the smallest one (the anisotropy ratios)."""
|
|
45
|
+
return self.principal / self.principal[-1]
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def degree(self) -> float:
|
|
49
|
+
"""Degree of anisotropy ``1 - MIL_min / MIL_max`` (0: isotropic)."""
|
|
50
|
+
return float(1.0 - self.principal[-1] / self.principal[0])
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def mean_intercept_length(image, phase: int = 1, *, periodic=None) -> tuple[np.ndarray, np.ndarray]:
|
|
54
|
+
"""Unit directions (13 x 3) and the mean intercept length of ``phase`` along each."""
|
|
55
|
+
x = indicator(image, phase)
|
|
56
|
+
spacing = np.asarray(image.spacing if isinstance(image, VoxelImage) else (1.0, 1.0, 1.0), float)
|
|
57
|
+
if periodic is None:
|
|
58
|
+
periodic = bool(image.periodic) if isinstance(image, VoxelImage) else False
|
|
59
|
+
fraction = float(x.mean())
|
|
60
|
+
dirs, mils = [], []
|
|
61
|
+
for d in DIRECTIONS_13:
|
|
62
|
+
if not periodic and any(abs(c) >= n for c, n in zip(d, x.shape, strict=True)):
|
|
63
|
+
continue
|
|
64
|
+
n_cross, n_pairs = transitions(x, d, periodic)
|
|
65
|
+
vec = np.asarray(d, dtype=float) * spacing
|
|
66
|
+
step = float(np.linalg.norm(vec))
|
|
67
|
+
p_l = n_cross / (n_pairs * step) if n_pairs else 0.0
|
|
68
|
+
dirs.append(vec / step)
|
|
69
|
+
mils.append(2.0 * fraction / p_l if p_l > 0 else np.inf)
|
|
70
|
+
return np.asarray(dirs), np.asarray(mils)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def fabric_tensor(image, phase: int = 1, *, periodic=None) -> Fabric:
|
|
74
|
+
"""The MIL fabric tensor of ``phase`` (see the module)."""
|
|
75
|
+
dirs, mil = mean_intercept_length(image, phase, periodic=periodic)
|
|
76
|
+
finite = np.isfinite(mil)
|
|
77
|
+
if finite.sum() < 6:
|
|
78
|
+
raise ValueError("fabric_tensor: the phase crosses too few lines")
|
|
79
|
+
u = dirs[finite]
|
|
80
|
+
rows = np.column_stack(
|
|
81
|
+
[
|
|
82
|
+
u[:, 0] ** 2,
|
|
83
|
+
u[:, 1] ** 2,
|
|
84
|
+
u[:, 2] ** 2,
|
|
85
|
+
2 * u[:, 1] * u[:, 2],
|
|
86
|
+
2 * u[:, 2] * u[:, 0],
|
|
87
|
+
2 * u[:, 0] * u[:, 1],
|
|
88
|
+
]
|
|
89
|
+
)
|
|
90
|
+
m, *_ = np.linalg.lstsq(rows, 1.0 / mil[finite] ** 2, rcond=None)
|
|
91
|
+
tensor = np.array([[m[0], m[5], m[4]], [m[5], m[1], m[3]], [m[4], m[3], m[2]]])
|
|
92
|
+
values, vectors = np.linalg.eigh(tensor)
|
|
93
|
+
principal = 1.0 / np.sqrt(np.clip(values, 1e-300, None)) # increasing values: decreasing MILs
|
|
94
|
+
return Fabric(dirs, mil, tensor, principal, vectors)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@dataclass
|
|
98
|
+
class HoleEffect:
|
|
99
|
+
"""The first minimum of the covariance below its ``plateau`` ``p^2`` along the x, y
|
|
100
|
+
and z axes: its ``lags`` (physical units; NaN where the covariance has none) and
|
|
101
|
+
``values``."""
|
|
102
|
+
|
|
103
|
+
lags: np.ndarray
|
|
104
|
+
values: np.ndarray
|
|
105
|
+
plateau: float
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def ratios(self) -> np.ndarray:
|
|
109
|
+
"""The lags in decreasing order over the smallest (``c/a``, ``b/a``, 1)."""
|
|
110
|
+
lags = np.sort(self.lags)[::-1]
|
|
111
|
+
return lags / lags[-1]
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def covariance_minima(
|
|
115
|
+
image, phase: int = 1, *, max_lag: int | None = None, periodic=None
|
|
116
|
+
) -> HoleEffect:
|
|
117
|
+
"""The first local minimum of the covariance of ``phase`` along each axis after it
|
|
118
|
+
falls below its plateau, refined by the parabola through the three nearest lags."""
|
|
119
|
+
cov = covariance(image, phase, max_lag=max_lag, periodic=periodic)
|
|
120
|
+
plateau = cov.volume_fraction**2
|
|
121
|
+
lags, values = np.full(3, np.nan), np.full(3, np.nan)
|
|
122
|
+
for k, name in enumerate("xyz"):
|
|
123
|
+
c, h = cov.values[name], cov.lags[name]
|
|
124
|
+
below = np.flatnonzero(c < plateau)
|
|
125
|
+
if below.size == 0:
|
|
126
|
+
continue
|
|
127
|
+
for i in range(max(int(below[0]), 1), len(c) - 1):
|
|
128
|
+
if c[i] <= c[i - 1] and c[i] <= c[i + 1]:
|
|
129
|
+
left, mid, right = c[i - 1], c[i], c[i + 1]
|
|
130
|
+
curvature = left - 2.0 * mid + right
|
|
131
|
+
shift = 0.5 * (left - right) / curvature if curvature > 0 else 0.0
|
|
132
|
+
lags[k] = h[i] + shift * (h[1] - h[0])
|
|
133
|
+
values[k] = mid - 0.25 * (left - right) * shift
|
|
134
|
+
break
|
|
135
|
+
return HoleEffect(lags, values, plateau)
|