synthetmic 0.1.0__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.
@@ -0,0 +1,12 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+ assets/
12
+ plots/
@@ -0,0 +1 @@
1
+ 3.12.3
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2025 synthetic-miscrostructures
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: synthetmic
3
+ Version: 0.1.0
4
+ Summary: A Python package for generating synthetic Laguerre polycrystalline microstructures
5
+ Project-URL: homepage, https://github.com/lpm-dev/lpm
6
+ Project-URL: issues, https://github.com/lpm-dev/lpm/issues
7
+ Author-email: "R. O. Ibraheem" <ibraheem.abdulrasheed@gmail.com>, "D. P. Bourne" <D.Bourne@hw.ac.uk>, "S. M. Roper" <Steven.Roper@glasgow.ac.uk>
8
+ Maintainer-email: "R. O. Ibraheem" <ibraheem.abdulrasheed@gmail.com>, "D. P. Bourne" <D.Bourne@hw.ac.uk>, "S. M. Roper" <Steven.Roper@glasgow.ac.uk>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Requires-Python: >=3.12.3
18
+ Requires-Dist: matplotlib>=3.10.3
19
+ Requires-Dist: numpy>=2.3.0
20
+ Requires-Dist: pysdot>=0.2.36
21
+ Requires-Dist: pyvista[jupyter]>=0.45.2
22
+ Requires-Dist: scipy>=1.15.3
23
+ Requires-Dist: vtk>=9.4.2
24
+ Provides-Extra: cli
25
+ Requires-Dist: click>=8.2.1; extra == 'cli'
26
+ Provides-Extra: examples
27
+ Provides-Extra: tests
28
+ Requires-Dist: pytest>=8.4.1; extra == 'tests'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # SynthetMic
32
+ A Python package for generating synthetic polycrystalline microstructures using Laguerre diagrams, powered by [pysdot](https://github.com/sd-ot/pysdot).
33
+
34
+ ## Installation
35
+ To install the latest version of the package via `pip`, run
36
+ ```
37
+ pip install synthetmic
38
+ ```
39
+ > If you are using `uv` to manage your project, run the following command instead:
40
+ >
41
+ > uv add synthetmic
42
+
43
+ ## Usage
44
+ To use this package to generate synthetic microstructures, you need to import the generator class as follows:
45
+ ```python
46
+ from synthetmic import LaguerreDiagramGenerator
47
+ ```
48
+
49
+ Create an instance of the class with the default arguments:
50
+ ```python
51
+ generator = LaguerreDiagramGenerator()
52
+ ```
53
+ or with custom parameters:
54
+ ```python
55
+ generator = LaguerreDiagramGenerator(
56
+ tol=0.1,
57
+ n_iter=5,
58
+ damp_param=1.0,
59
+ verbose=True,
60
+ )
61
+ ```
62
+
63
+ We can fit this class to some data by calling the `fit` method. For example, we can create a Laguerre tessellation of the unit cube [0, 1] x [0, 1] x [0, 1] with 1000 cells of equal volume as follows:
64
+ ```python
65
+ import numpy as np
66
+
67
+ domain = np.array([[0, 1],[0, 1],[0, 1]])
68
+ domain_vol = np.prod(domain[:, 1] - domain[:, 0])
69
+
70
+ n_grains = 1000
71
+
72
+ seeds = np.column_stack(
73
+ [np.random.uniform(low=d[0], high=d[1], size=n_grains) for d in domain]
74
+ )
75
+ volumes = (np.ones(n_grains) / n_grains) * domain_vol
76
+
77
+ # call the fit method on data
78
+ generator.fit(
79
+ seeds=seeds,
80
+ volumes=volumes,
81
+ domain=domain,
82
+ )
83
+ ```
84
+
85
+ After calling the fit method, you can use the instance to get various properties of the diagram, e.g., get the centroids and vertices of the cells:
86
+ ```python
87
+ centroids = generator.get_centroids()
88
+ vertices = generator.get_vertices()
89
+
90
+ print("diagram centroids:\n", centroids)
91
+ print("diagram vertices:\n", vertices)
92
+ ```
93
+
94
+ You can plot the diagram in static or interactive mode by using the fitted instance:
95
+ ```python
96
+ from synthetmic.plot import plot_cells_as_pyvista_fig
97
+ plot_cells_as_pyvista_fig(
98
+ generator=generator,
99
+ interactive=True,
100
+ save_path="./example_diagram.html",
101
+ )
102
+ ```
103
+
104
+ The generated HTML file can be viewed via any browser of your choice.
105
+
106
+ If you prefer a static figure, turn off `interactive` and save figure as pdf (can also be saved as eps, ps, tex, and svg):
107
+ ```python
108
+ plot_cells_as_pyvista_fig(
109
+ generator=generator,
110
+ interactive=False,
111
+ save_path="./example_diagram.pdf",
112
+ )
113
+ ```
114
+
115
+ To see more usage examples, see the `examples` folder or check below on how to run them via `cli.py`.
116
+
117
+
118
+ ## Working with source codes
119
+ ### Build from source
120
+ If you would like to build this project from source either for development purposes or for any other reason, it is recommended to install [uv](https://docs.astral.sh/uv/). This is what is adopted in this project. To install uv, follow the instructions in this [link](https://docs.astral.sh/uv/getting-started/installation/).
121
+
122
+ If you don't want to use uv, you can use other alternatives like [pip](https://pip.pypa.io/en/stable/).
123
+
124
+ The following instructions use uv for building synthetmic from source.
125
+
126
+ 1. Clone the repository by running
127
+
128
+ ```
129
+ git clone https://github.com/synthetic-microstructures/synthetmic
130
+ ```
131
+
132
+ 1. Create a python virtual environment by running
133
+
134
+ ```
135
+ uv venv .venv --python PYTHON_VERSION
136
+ ```
137
+ > Here, PYTHON_VERSION is the supported Python version. Note that this project requires version >=3.12.3
138
+
139
+ 1. Activate the virtual environment by running
140
+
141
+ ```
142
+ source .venv/bin/activate
143
+ ```
144
+
145
+ 1. Prepare all modules and dependencies by running the following:
146
+
147
+ ```
148
+ uv sync --all-extras
149
+ ```
150
+
151
+ ### Running examples
152
+ We created a command line interface (cli) for recreating some of the examples provided in the this [paper](https://www.tandfonline.com/doi/full/10.1080/14786435.2020.1790053) (and lots more!).
153
+
154
+ To check the available commands in the cli, run
155
+
156
+ ```
157
+ python cli.py --help
158
+ ```
159
+
160
+ There are currently two commands available in the cli: `recreate` and `analyse`.
161
+
162
+ You can check information about each of these commands by running
163
+
164
+ ```
165
+ python cli.py COMMAND --help
166
+ ```
167
+ where `COMMAND` is any of the commands.
168
+
169
+ Running a command with its appropriate args is simple. For instance, if you would like to recreate some of the two-dimensional examples in the above-mentioned paper, and save the generated plots in the ./plots dir, run
170
+
171
+ ```
172
+ python cli.py recreate --example 2d --save-dir ./plots
173
+ ```
174
+ You can do the same for three-dimension examples. You can pass the flag `--interactive` or `-i` to save the generated plots as a `.html` file, which can then be opened in a browser to interact with them:
175
+
176
+ ```
177
+ python cli.py recreate --example 2d --save-dir ./plots --interactive
178
+ ```
179
+
180
+ > Note: by default, the generated plots will be saved as `.pdf`. Passing `--interactive` flag to 2d case will be skipped since this is not that interesting for interactivity.
181
+
182
+ ### Running tests
183
+ To run all tests, run
184
+
185
+ ```
186
+ pytest -v tests
187
+ ```
188
+
189
+ ## References
190
+ If you use this package in your research, please refer to the link to this project. Additionally, please consider citing the following paper:
191
+ ```bibtex
192
+ @article{Bourne01112020,
193
+ author = {D. P. Bourne and P. J. J. Kok and S. M. Roper and W. D. T. Spanjer},
194
+ title = {Laguerre tessellations and polycrystalline microstructures: a fast algorithm for generating grains of given volumes},
195
+ journal = {Philosophical Magazine},
196
+ volume = {100},
197
+ number = {21},
198
+ pages = {2677--2707},
199
+ year = {2020},
200
+ publisher = {Taylor \& Francis},
201
+ doi = {10.1080/14786435.2020.1790053},
202
+ URL = {https://doi.org/10.1080/14786435.2020.1790053},
203
+ eprint = {https://doi.org/10.1080/14786435.2020.1790053}
204
+ }
205
+ ```
206
+ You may also be interested in some of our other libraries:
207
+ * [LPM](https://github.com/DPBourne/Laguerre-Polycrystalline-Microstructures) - MATLAB code for generating synthetic polycrystalline microstructures using Laguerre diagrams
208
+ * [pyAPD](https://github.com/mbuze/PyAPD) - a Python library for computing *anisotropic* Laguerre diagrams
@@ -0,0 +1,178 @@
1
+ # SynthetMic
2
+ A Python package for generating synthetic polycrystalline microstructures using Laguerre diagrams, powered by [pysdot](https://github.com/sd-ot/pysdot).
3
+
4
+ ## Installation
5
+ To install the latest version of the package via `pip`, run
6
+ ```
7
+ pip install synthetmic
8
+ ```
9
+ > If you are using `uv` to manage your project, run the following command instead:
10
+ >
11
+ > uv add synthetmic
12
+
13
+ ## Usage
14
+ To use this package to generate synthetic microstructures, you need to import the generator class as follows:
15
+ ```python
16
+ from synthetmic import LaguerreDiagramGenerator
17
+ ```
18
+
19
+ Create an instance of the class with the default arguments:
20
+ ```python
21
+ generator = LaguerreDiagramGenerator()
22
+ ```
23
+ or with custom parameters:
24
+ ```python
25
+ generator = LaguerreDiagramGenerator(
26
+ tol=0.1,
27
+ n_iter=5,
28
+ damp_param=1.0,
29
+ verbose=True,
30
+ )
31
+ ```
32
+
33
+ We can fit this class to some data by calling the `fit` method. For example, we can create a Laguerre tessellation of the unit cube [0, 1] x [0, 1] x [0, 1] with 1000 cells of equal volume as follows:
34
+ ```python
35
+ import numpy as np
36
+
37
+ domain = np.array([[0, 1],[0, 1],[0, 1]])
38
+ domain_vol = np.prod(domain[:, 1] - domain[:, 0])
39
+
40
+ n_grains = 1000
41
+
42
+ seeds = np.column_stack(
43
+ [np.random.uniform(low=d[0], high=d[1], size=n_grains) for d in domain]
44
+ )
45
+ volumes = (np.ones(n_grains) / n_grains) * domain_vol
46
+
47
+ # call the fit method on data
48
+ generator.fit(
49
+ seeds=seeds,
50
+ volumes=volumes,
51
+ domain=domain,
52
+ )
53
+ ```
54
+
55
+ After calling the fit method, you can use the instance to get various properties of the diagram, e.g., get the centroids and vertices of the cells:
56
+ ```python
57
+ centroids = generator.get_centroids()
58
+ vertices = generator.get_vertices()
59
+
60
+ print("diagram centroids:\n", centroids)
61
+ print("diagram vertices:\n", vertices)
62
+ ```
63
+
64
+ You can plot the diagram in static or interactive mode by using the fitted instance:
65
+ ```python
66
+ from synthetmic.plot import plot_cells_as_pyvista_fig
67
+ plot_cells_as_pyvista_fig(
68
+ generator=generator,
69
+ interactive=True,
70
+ save_path="./example_diagram.html",
71
+ )
72
+ ```
73
+
74
+ The generated HTML file can be viewed via any browser of your choice.
75
+
76
+ If you prefer a static figure, turn off `interactive` and save figure as pdf (can also be saved as eps, ps, tex, and svg):
77
+ ```python
78
+ plot_cells_as_pyvista_fig(
79
+ generator=generator,
80
+ interactive=False,
81
+ save_path="./example_diagram.pdf",
82
+ )
83
+ ```
84
+
85
+ To see more usage examples, see the `examples` folder or check below on how to run them via `cli.py`.
86
+
87
+
88
+ ## Working with source codes
89
+ ### Build from source
90
+ If you would like to build this project from source either for development purposes or for any other reason, it is recommended to install [uv](https://docs.astral.sh/uv/). This is what is adopted in this project. To install uv, follow the instructions in this [link](https://docs.astral.sh/uv/getting-started/installation/).
91
+
92
+ If you don't want to use uv, you can use other alternatives like [pip](https://pip.pypa.io/en/stable/).
93
+
94
+ The following instructions use uv for building synthetmic from source.
95
+
96
+ 1. Clone the repository by running
97
+
98
+ ```
99
+ git clone https://github.com/synthetic-microstructures/synthetmic
100
+ ```
101
+
102
+ 1. Create a python virtual environment by running
103
+
104
+ ```
105
+ uv venv .venv --python PYTHON_VERSION
106
+ ```
107
+ > Here, PYTHON_VERSION is the supported Python version. Note that this project requires version >=3.12.3
108
+
109
+ 1. Activate the virtual environment by running
110
+
111
+ ```
112
+ source .venv/bin/activate
113
+ ```
114
+
115
+ 1. Prepare all modules and dependencies by running the following:
116
+
117
+ ```
118
+ uv sync --all-extras
119
+ ```
120
+
121
+ ### Running examples
122
+ We created a command line interface (cli) for recreating some of the examples provided in the this [paper](https://www.tandfonline.com/doi/full/10.1080/14786435.2020.1790053) (and lots more!).
123
+
124
+ To check the available commands in the cli, run
125
+
126
+ ```
127
+ python cli.py --help
128
+ ```
129
+
130
+ There are currently two commands available in the cli: `recreate` and `analyse`.
131
+
132
+ You can check information about each of these commands by running
133
+
134
+ ```
135
+ python cli.py COMMAND --help
136
+ ```
137
+ where `COMMAND` is any of the commands.
138
+
139
+ Running a command with its appropriate args is simple. For instance, if you would like to recreate some of the two-dimensional examples in the above-mentioned paper, and save the generated plots in the ./plots dir, run
140
+
141
+ ```
142
+ python cli.py recreate --example 2d --save-dir ./plots
143
+ ```
144
+ You can do the same for three-dimension examples. You can pass the flag `--interactive` or `-i` to save the generated plots as a `.html` file, which can then be opened in a browser to interact with them:
145
+
146
+ ```
147
+ python cli.py recreate --example 2d --save-dir ./plots --interactive
148
+ ```
149
+
150
+ > Note: by default, the generated plots will be saved as `.pdf`. Passing `--interactive` flag to 2d case will be skipped since this is not that interesting for interactivity.
151
+
152
+ ### Running tests
153
+ To run all tests, run
154
+
155
+ ```
156
+ pytest -v tests
157
+ ```
158
+
159
+ ## References
160
+ If you use this package in your research, please refer to the link to this project. Additionally, please consider citing the following paper:
161
+ ```bibtex
162
+ @article{Bourne01112020,
163
+ author = {D. P. Bourne and P. J. J. Kok and S. M. Roper and W. D. T. Spanjer},
164
+ title = {Laguerre tessellations and polycrystalline microstructures: a fast algorithm for generating grains of given volumes},
165
+ journal = {Philosophical Magazine},
166
+ volume = {100},
167
+ number = {21},
168
+ pages = {2677--2707},
169
+ year = {2020},
170
+ publisher = {Taylor \& Francis},
171
+ doi = {10.1080/14786435.2020.1790053},
172
+ URL = {https://doi.org/10.1080/14786435.2020.1790053},
173
+ eprint = {https://doi.org/10.1080/14786435.2020.1790053}
174
+ }
175
+ ```
176
+ You may also be interested in some of our other libraries:
177
+ * [LPM](https://github.com/DPBourne/Laguerre-Polycrystalline-Microstructures) - MATLAB code for generating synthetic polycrystalline microstructures using Laguerre diagrams
178
+ * [pyAPD](https://github.com/mbuze/PyAPD) - a Python library for computing *anisotropic* Laguerre diagrams
@@ -0,0 +1,60 @@
1
+ [project]
2
+ name = "synthetmic"
3
+ version = "0.1.0"
4
+ description = "A Python package for generating synthetic Laguerre polycrystalline microstructures"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "R. O. Ibraheem", email = "ibraheem.abdulrasheed@gmail.com" },
8
+ { name = "D. P. Bourne", email = "D.Bourne@hw.ac.uk" },
9
+ { name = "S. M. Roper", email = "Steven.Roper@glasgow.ac.uk" },
10
+ ]
11
+ maintainers = [
12
+ { name = "R. O. Ibraheem", email = "ibraheem.abdulrasheed@gmail.com" },
13
+ { name = "D. P. Bourne", email = "D.Bourne@hw.ac.uk" },
14
+ { name = "S. M. Roper", email = "Steven.Roper@glasgow.ac.uk" }
15
+ ]
16
+ requires-python = ">=3.12.3"
17
+ dependencies = [
18
+ "matplotlib>=3.10.3",
19
+ "numpy>=2.3.0",
20
+ "pysdot>=0.2.36",
21
+ "pyvista[jupyter]>=0.45.2",
22
+ "scipy>=1.15.3",
23
+ "vtk>=9.4.2",
24
+ ]
25
+ classifiers = [
26
+ "Programming Language :: Python",
27
+ "Programming Language :: Python :: 3",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3.13",
31
+ "Operating System :: OS Independent",
32
+ ]
33
+ license = "MIT"
34
+ license-files = ["LICEN[CS]E*"]
35
+
36
+ [project.urls]
37
+ homepage = "https://github.com/lpm-dev/lpm"
38
+ issues = "https://github.com/lpm-dev/lpm/issues"
39
+
40
+ [project.optional-dependencies]
41
+ cli = [
42
+ "click>=8.2.1",
43
+ ]
44
+ examples = []
45
+ tests = [
46
+ "pytest>=8.4.1",
47
+ ]
48
+
49
+ [build-system]
50
+ requires = ["hatchling"]
51
+ build-backend = "hatchling.build"
52
+
53
+ [tool.hatch.build.targets.sdist]
54
+ exclude = [
55
+ "/.github",
56
+ "/tests",
57
+ "examples",
58
+ "assets",
59
+ "cli.py",
60
+ ]
@@ -0,0 +1,5 @@
1
+ from .generate import LaguerreDiagramGenerator
2
+
3
+ __all__ = [
4
+ "LaguerreDiagramGenerator",
5
+ ]