vectorose 0.2.1__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.
- vectorose-0.2.1/LICENSE +22 -0
- vectorose-0.2.1/PKG-INFO +295 -0
- vectorose-0.2.1/README.md +263 -0
- vectorose-0.2.1/pyproject.toml +62 -0
- vectorose-0.2.1/src/vectorose/__init__.py +15 -0
- vectorose-0.2.1/src/vectorose/io.py +400 -0
- vectorose-0.2.1/src/vectorose/mock_data.py +458 -0
- vectorose-0.2.1/src/vectorose/plotting.py +2549 -0
- vectorose-0.2.1/src/vectorose/polar_data.py +315 -0
- vectorose-0.2.1/src/vectorose/sphere_base.py +693 -0
- vectorose-0.2.1/src/vectorose/stats.py +921 -0
- vectorose-0.2.1/src/vectorose/tregenza_sphere.py +935 -0
- vectorose-0.2.1/src/vectorose/triangle_sphere.py +177 -0
- vectorose-0.2.1/src/vectorose/util.py +839 -0
vectorose-0.2.1/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-, Benjamin Z. Rudski, Joseph Deering
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
vectorose-0.2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: vectorose
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Plot polar and spherical histograms from orientation data.
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Benjamin Z. Rudski
|
|
7
|
+
Author-email: benjamin.rudski@mail.mcgill.ca
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Requires-Dist: imageio-ffmpeg (>=0.5.1,<1)
|
|
16
|
+
Requires-Dist: imageio[ffmpeg,pyav] (>=2.27.0)
|
|
17
|
+
Requires-Dist: importlib-metadata (>=7.0.1)
|
|
18
|
+
Requires-Dist: ipywidgets (>=8.1.5,<9)
|
|
19
|
+
Requires-Dist: matplotlib (>=3.3.4)
|
|
20
|
+
Requires-Dist: numpy (>=1.19.5,<2)
|
|
21
|
+
Requires-Dist: openpyxl (>=3.1.2,<4)
|
|
22
|
+
Requires-Dist: pandas (>=1.1.3)
|
|
23
|
+
Requires-Dist: pyvista[all,jupyter,trame] (>=0.44.1,<1)
|
|
24
|
+
Requires-Dist: scipy (>=1.14,<2)
|
|
25
|
+
Requires-Dist: trame (>=3.6.5,<4)
|
|
26
|
+
Requires-Dist: trimesh[easy] (>=4.3.0,<5)
|
|
27
|
+
Project-URL: Documentation, https://vectorose.readthedocs.io/en/latest/index.html
|
|
28
|
+
Project-URL: Homepage, https://github.com/bzrudski/vectorose
|
|
29
|
+
Project-URL: Repository, https://github.com/bzrudski/vectorose
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# VectoRose
|
|
33
|
+
|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
Spherical and polar histogram plotting for non-unit vectorial and axial
|
|
37
|
+
data.
|
|
38
|
+
|
|
39
|
+
## Overview
|
|
40
|
+
|
|
41
|
+
Many fields of science rely on oriented data. In these contexts, scalar
|
|
42
|
+
values alone can't describe the quantities under consideration. The values
|
|
43
|
+
of interest are **vectors**, consisting of a *direction* or *orientation*,
|
|
44
|
+
in addition to an optional magnitude (length). Examples include wind
|
|
45
|
+
velocities, trabecular bone co-alignment (anisotropy) and cardiac fibre
|
|
46
|
+
orientations.
|
|
47
|
+
|
|
48
|
+
Traditional histograms and statistical tools can't be directly applied to
|
|
49
|
+
analyse these data. To be able to visualise and quantitatively describe and
|
|
50
|
+
analyse oriented datasets in 3D, we present **VectoRose**.
|
|
51
|
+
|
|
52
|
+
### Features
|
|
53
|
+
|
|
54
|
+
**VectoRose** provides tools for *visualising* and quantitatively
|
|
55
|
+
*analysing* data sets consisting of vectors and orientations of unit and
|
|
56
|
+
non-unit length.
|
|
57
|
+
|
|
58
|
+
Using VectoRose, it is possible to:
|
|
59
|
+
|
|
60
|
+
* Construct spherical histograms of directions and orientations in 3D.
|
|
61
|
+
* Construct 1D scalar histograms of vector magnitudes.
|
|
62
|
+
* Construct nested spherical histograms to understand collections of
|
|
63
|
+
non-unit vectors and axes.
|
|
64
|
+
* Construct 1D polar histograms of vector orientation spherical coordinate
|
|
65
|
+
angles.
|
|
66
|
+
* Compute directional statistics to understand the distributions of
|
|
67
|
+
orientations and directions, as described by Fisher, Lewis and
|
|
68
|
+
Embleton.[^fle]
|
|
69
|
+
|
|
70
|
+

|
|
71
|
+
|
|
72
|
+

|
|
73
|
+
|
|
74
|
+
## Installation
|
|
75
|
+
|
|
76
|
+
VectoRose can be installed from PyPI using `pip`.
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
$ pip install vectorose
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Alternatively, you can install it from source by cloning this repository.
|
|
83
|
+
|
|
84
|
+
## Usage
|
|
85
|
+
|
|
86
|
+
To use VectoRose, you must have a collection of **3D vectors** stored in a
|
|
87
|
+
NumPy array. These may be read from a NumPy file (`*.npy`) or a
|
|
88
|
+
comma-separated values (`*.csv`) file using the functions provided in
|
|
89
|
+
VectoRose.
|
|
90
|
+
|
|
91
|
+
VectoRose must be imported in order to be used. We recommend using the
|
|
92
|
+
alias `vr` when importing VectoRose:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
import vectorose as vr
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Histogram Construction
|
|
99
|
+
|
|
100
|
+
Histogram construction requires two steps:
|
|
101
|
+
|
|
102
|
+
1. Assigning all vectors to magnitude and orientation bins.
|
|
103
|
+
2. Computing histograms and generating the histogram plots.
|
|
104
|
+
|
|
105
|
+
The first step requires a discrete representation of a sphere, such as a
|
|
106
|
+
fine Tregenza sphere, which divides the surface of the sphere into 5806
|
|
107
|
+
faces, most of which are rectangular, of approximately equal surface area.
|
|
108
|
+
Two keyword arguments can be used to set the number of magnitude bins
|
|
109
|
+
(`number_of_shells`) and to fix the histogram domain (`magnitude_range`).
|
|
110
|
+
|
|
111
|
+
In the second step, a variety of histograms can be constructed. These
|
|
112
|
+
histograms may consider the counts (or frequencies) of vectors at each
|
|
113
|
+
combination of magnitude and direction (*bivariate histogram*), or within
|
|
114
|
+
the bins of each variable separately (*marginal histograms*). Histograms
|
|
115
|
+
can also be constructed that consider relative frequencies of one variable
|
|
116
|
+
within a specific range of the other (*conditional histograms*).
|
|
117
|
+
|
|
118
|
+
In this brief code snippet, we will generate some random vectors from a
|
|
119
|
+
von Mises-Fisher unimodal directional distribution, with some noise in the
|
|
120
|
+
magnitude. We'll then construct the bivariate histogram and visualise it in
|
|
121
|
+
3D using PyVista.
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
import vectorose as vr
|
|
125
|
+
import vectorose.mock_data
|
|
126
|
+
|
|
127
|
+
# Create random vectors for demonstration
|
|
128
|
+
my_vectors = vr.mock_data.create_vonmises_fisher_vectors_single_direction(
|
|
129
|
+
phi=45,
|
|
130
|
+
theta=70,
|
|
131
|
+
kappa=20,
|
|
132
|
+
number_of_points=10000,
|
|
133
|
+
magnitude=1.0,
|
|
134
|
+
magnitude_std=0.25,
|
|
135
|
+
use_degrees=True,
|
|
136
|
+
seed=20250317,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# Construct the discrete sphere representation
|
|
140
|
+
my_sphere = vr.tregenza_sphere.FineTregenzaSphere(number_of_shells=10)
|
|
141
|
+
my_binned_vectors, magnitude_bin_edges = my_sphere.assign_histogram_bins(my_vectors)
|
|
142
|
+
|
|
143
|
+
# Compute the bivariate histogram
|
|
144
|
+
my_histogram = my_sphere.construct_histogram(my_binned_vectors, return_fraction=False)
|
|
145
|
+
|
|
146
|
+
# Generate the histogram meshes
|
|
147
|
+
my_histogram_meshes = my_sphere.create_histogram_meshes(my_histogram, magnitude_bin_edges)
|
|
148
|
+
|
|
149
|
+
# Create a 3D SpherePlotter to view the histogram in 3D and show it
|
|
150
|
+
my_sphere_plotter = vr.plotting.SpherePlotter(my_histogram_meshes)
|
|
151
|
+
my_sphere_plotter.produce_plot()
|
|
152
|
+
my_sphere_plotter.show()
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+

|
|
156
|
+
|
|
157
|
+
When this code is run in a Jupyter notebook, an interactive plotting output
|
|
158
|
+
will appear beneath the code cell. When this code is run in a Python
|
|
159
|
+
console, a new interactive window will appear that blocks the main thread.
|
|
160
|
+
|
|
161
|
+
In addition to showing the plot in 3D, VectoRose includes various functions
|
|
162
|
+
to produce animations and screenshots of spherical histograms.
|
|
163
|
+
|
|
164
|
+
### Directional Statistics
|
|
165
|
+
|
|
166
|
+
The functions in the `vectorose.stats` module enable directional statistics
|
|
167
|
+
to be computed. These functions have been adapted from the work by Fisher,
|
|
168
|
+
Lewis and Embleton.[^fle]
|
|
169
|
+
|
|
170
|
+
VectoRose implements a variety of descriptive statistics and hypothesis
|
|
171
|
+
tests. Most of these consider pure directions or orientations, which are
|
|
172
|
+
represented as unit vectors.
|
|
173
|
+
|
|
174
|
+
In this code snippet, we generate two sets of mock vectors: a cluster,
|
|
175
|
+
following a von Mises-Fisher distribution, and a girdle, following a Watson
|
|
176
|
+
distribution with a negative parameter value. We then compute Woodcock's
|
|
177
|
+
shape and strength parameters, as described by Woodcock[^woodcock] and as
|
|
178
|
+
explained by Fisher, Lewis and Embleton.[^fle]
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
import vectorose as vr
|
|
182
|
+
import vectorose.mock_data
|
|
183
|
+
import numpy as np
|
|
184
|
+
|
|
185
|
+
# Create random vectors for demonstration
|
|
186
|
+
my_cluster_vectors = vr.mock_data.create_vonmises_fisher_vectors_single_direction(
|
|
187
|
+
phi=45,
|
|
188
|
+
theta=70,
|
|
189
|
+
kappa=20,
|
|
190
|
+
number_of_points=10000,
|
|
191
|
+
magnitude=1.0,
|
|
192
|
+
magnitude_std=0,
|
|
193
|
+
use_degrees=True,
|
|
194
|
+
seed=20250318,
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
direction = np.array([1, 0, 0])
|
|
198
|
+
my_girdle_vectors = vr.mock_data.generate_watson_distribution(
|
|
199
|
+
direction, -20, n=10000, seed=20250318
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
# Compute Woodcock's parameters for both sets of vectors
|
|
203
|
+
cluster_orientation_matrix_eigs, _ = vr.stats.compute_orientation_matrix_eigs(
|
|
204
|
+
my_cluster_vectors
|
|
205
|
+
)
|
|
206
|
+
girdle_orientation_matrix_eigs, _ = vr.stats.compute_orientation_matrix_eigs(
|
|
207
|
+
my_girdle_vectors
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
cluster_woodcock_parameters = vr.stats.compute_orientation_matrix_parameters(
|
|
211
|
+
cluster_orientation_matrix_eigs
|
|
212
|
+
)
|
|
213
|
+
girdle_woodcock_parameters = vr.stats.compute_orientation_matrix_parameters(
|
|
214
|
+
girdle_orientation_matrix_eigs
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
print(f"The VMF distribution has shape parameter {cluster_woodcock_parameters.shape_parameter:.3f}"
|
|
218
|
+
f" and strength parameter {cluster_woodcock_parameters.strength_parameter:.3f}.")
|
|
219
|
+
|
|
220
|
+
print(f"The Watson distribution has shape parameter {girdle_woodcock_parameters.shape_parameter:.3f}"
|
|
221
|
+
f" and strength parameter {girdle_woodcock_parameters.strength_parameter:.3f}.")
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Running this code produces the following output:
|
|
225
|
+
```
|
|
226
|
+
The VMF distribution has shape parameter 48.085 and strength parameter 2.987.
|
|
227
|
+
The Watson distribution has shape parameter 0.005 and strength parameter 2.955.
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Additional statistical operations are provided in the VectoRose API and are
|
|
231
|
+
described in the **User's Guide**.
|
|
232
|
+
|
|
233
|
+
## Citation
|
|
234
|
+
|
|
235
|
+
If you've found VectoRose helpful for your research, please cite our
|
|
236
|
+
publication:
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
TBA
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
If you've modelled your analysis based on our sample case studies, please
|
|
243
|
+
also cite the following:
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
TBA
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Contributing
|
|
250
|
+
|
|
251
|
+
Interested in contributing? Check out the contributing guidelines. Please
|
|
252
|
+
note that this project is released with a Code of Conduct. By contributing
|
|
253
|
+
to this project, you agree to abide by its terms.
|
|
254
|
+
|
|
255
|
+
VectoRose is built on a number of existing, well-supported open-source
|
|
256
|
+
packages, including: [NumPy](https://numpy.org/),
|
|
257
|
+
[PyVista](https://docs.pyvista.org/),
|
|
258
|
+
[Matplotlib](https://matplotlib.org/),
|
|
259
|
+
[pandas](https://pandas.pydata.org/),
|
|
260
|
+
[SciPy](https://scipy.org/) and [trimesh](https://trimesh.org/).
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
## License
|
|
264
|
+
|
|
265
|
+
VectoRose was created by Benjamin Z. Rudski and Joseph Deering. It is
|
|
266
|
+
licensed under the terms of the MIT license. See the `LICENSE` file for
|
|
267
|
+
more details.
|
|
268
|
+
|
|
269
|
+
## Acknowledgements
|
|
270
|
+
|
|
271
|
+
The VectoRose project is developed by Benjamin Z. Rudski and Joseph Deering
|
|
272
|
+
under the supervision of Dr. Natalie Reznikov at McGill University, in
|
|
273
|
+
Montreal, Quebec, Canada 🇨🇦.
|
|
274
|
+
|
|
275
|
+
Works consult in this project are available in our online documentation, as
|
|
276
|
+
well as in [`docs/refs.bib`](./docs/refs.bib). For the directional
|
|
277
|
+
statistics approaches, we made extensive use of *Statistic analysis of
|
|
278
|
+
spherical data* by Fisher, Lewis and Embleton.[^fle]
|
|
279
|
+
|
|
280
|
+
We also made extensive use of the book [*Python Packages*](https://py-pkgs.org/)
|
|
281
|
+
by Tomas Beuzen and Tiffany Timbers to inform the structure and development
|
|
282
|
+
of this package.
|
|
283
|
+
|
|
284
|
+
## Credits
|
|
285
|
+
|
|
286
|
+
`vectorose` was created with [`cookiecutter`](https://cookiecutter.readthedocs.io/en/latest/) and the `py-pkgs-cookiecutter` [template](https://github.com/py-pkgs/py-pkgs-cookiecutter).
|
|
287
|
+
|
|
288
|
+
[^fle]: Fisher, N. I., Lewis, T., & Embleton, B. J. J. (1993).
|
|
289
|
+
*Statistical analysis of spherical data* ([New ed.], 1. paperback ed).
|
|
290
|
+
Cambridge Univ. Press. <https://www.cambridge.org/ca/universitypress/subjects/physics/astronomy-general/statistical-analysis-spherical-data?format=PB>
|
|
291
|
+
|
|
292
|
+
[^woodcock]: Woodcock, N. H. (1977). Specification of fabric shapes using
|
|
293
|
+
an eigenvalue method. *Geological Society of America Bulletin, 88*(9), 1231.
|
|
294
|
+
[https://doi.org/10.1130/0016-7606(1977)88<1231:SOFSUA>2.0.CO;2](https://doi.org/10.1130/0016-7606(1977)88<1231:SOFSUA>2.0.CO;2)
|
|
295
|
+
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# VectoRose
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Spherical and polar histogram plotting for non-unit vectorial and axial
|
|
6
|
+
data.
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Many fields of science rely on oriented data. In these contexts, scalar
|
|
11
|
+
values alone can't describe the quantities under consideration. The values
|
|
12
|
+
of interest are **vectors**, consisting of a *direction* or *orientation*,
|
|
13
|
+
in addition to an optional magnitude (length). Examples include wind
|
|
14
|
+
velocities, trabecular bone co-alignment (anisotropy) and cardiac fibre
|
|
15
|
+
orientations.
|
|
16
|
+
|
|
17
|
+
Traditional histograms and statistical tools can't be directly applied to
|
|
18
|
+
analyse these data. To be able to visualise and quantitatively describe and
|
|
19
|
+
analyse oriented datasets in 3D, we present **VectoRose**.
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
**VectoRose** provides tools for *visualising* and quantitatively
|
|
24
|
+
*analysing* data sets consisting of vectors and orientations of unit and
|
|
25
|
+
non-unit length.
|
|
26
|
+
|
|
27
|
+
Using VectoRose, it is possible to:
|
|
28
|
+
|
|
29
|
+
* Construct spherical histograms of directions and orientations in 3D.
|
|
30
|
+
* Construct 1D scalar histograms of vector magnitudes.
|
|
31
|
+
* Construct nested spherical histograms to understand collections of
|
|
32
|
+
non-unit vectors and axes.
|
|
33
|
+
* Construct 1D polar histograms of vector orientation spherical coordinate
|
|
34
|
+
angles.
|
|
35
|
+
* Compute directional statistics to understand the distributions of
|
|
36
|
+
orientations and directions, as described by Fisher, Lewis and
|
|
37
|
+
Embleton.[^fle]
|
|
38
|
+
|
|
39
|
+

|
|
40
|
+
|
|
41
|
+

|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
VectoRose can be installed from PyPI using `pip`.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
$ pip install vectorose
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Alternatively, you can install it from source by cloning this repository.
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
To use VectoRose, you must have a collection of **3D vectors** stored in a
|
|
56
|
+
NumPy array. These may be read from a NumPy file (`*.npy`) or a
|
|
57
|
+
comma-separated values (`*.csv`) file using the functions provided in
|
|
58
|
+
VectoRose.
|
|
59
|
+
|
|
60
|
+
VectoRose must be imported in order to be used. We recommend using the
|
|
61
|
+
alias `vr` when importing VectoRose:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import vectorose as vr
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Histogram Construction
|
|
68
|
+
|
|
69
|
+
Histogram construction requires two steps:
|
|
70
|
+
|
|
71
|
+
1. Assigning all vectors to magnitude and orientation bins.
|
|
72
|
+
2. Computing histograms and generating the histogram plots.
|
|
73
|
+
|
|
74
|
+
The first step requires a discrete representation of a sphere, such as a
|
|
75
|
+
fine Tregenza sphere, which divides the surface of the sphere into 5806
|
|
76
|
+
faces, most of which are rectangular, of approximately equal surface area.
|
|
77
|
+
Two keyword arguments can be used to set the number of magnitude bins
|
|
78
|
+
(`number_of_shells`) and to fix the histogram domain (`magnitude_range`).
|
|
79
|
+
|
|
80
|
+
In the second step, a variety of histograms can be constructed. These
|
|
81
|
+
histograms may consider the counts (or frequencies) of vectors at each
|
|
82
|
+
combination of magnitude and direction (*bivariate histogram*), or within
|
|
83
|
+
the bins of each variable separately (*marginal histograms*). Histograms
|
|
84
|
+
can also be constructed that consider relative frequencies of one variable
|
|
85
|
+
within a specific range of the other (*conditional histograms*).
|
|
86
|
+
|
|
87
|
+
In this brief code snippet, we will generate some random vectors from a
|
|
88
|
+
von Mises-Fisher unimodal directional distribution, with some noise in the
|
|
89
|
+
magnitude. We'll then construct the bivariate histogram and visualise it in
|
|
90
|
+
3D using PyVista.
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import vectorose as vr
|
|
94
|
+
import vectorose.mock_data
|
|
95
|
+
|
|
96
|
+
# Create random vectors for demonstration
|
|
97
|
+
my_vectors = vr.mock_data.create_vonmises_fisher_vectors_single_direction(
|
|
98
|
+
phi=45,
|
|
99
|
+
theta=70,
|
|
100
|
+
kappa=20,
|
|
101
|
+
number_of_points=10000,
|
|
102
|
+
magnitude=1.0,
|
|
103
|
+
magnitude_std=0.25,
|
|
104
|
+
use_degrees=True,
|
|
105
|
+
seed=20250317,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
# Construct the discrete sphere representation
|
|
109
|
+
my_sphere = vr.tregenza_sphere.FineTregenzaSphere(number_of_shells=10)
|
|
110
|
+
my_binned_vectors, magnitude_bin_edges = my_sphere.assign_histogram_bins(my_vectors)
|
|
111
|
+
|
|
112
|
+
# Compute the bivariate histogram
|
|
113
|
+
my_histogram = my_sphere.construct_histogram(my_binned_vectors, return_fraction=False)
|
|
114
|
+
|
|
115
|
+
# Generate the histogram meshes
|
|
116
|
+
my_histogram_meshes = my_sphere.create_histogram_meshes(my_histogram, magnitude_bin_edges)
|
|
117
|
+
|
|
118
|
+
# Create a 3D SpherePlotter to view the histogram in 3D and show it
|
|
119
|
+
my_sphere_plotter = vr.plotting.SpherePlotter(my_histogram_meshes)
|
|
120
|
+
my_sphere_plotter.produce_plot()
|
|
121
|
+
my_sphere_plotter.show()
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+

|
|
125
|
+
|
|
126
|
+
When this code is run in a Jupyter notebook, an interactive plotting output
|
|
127
|
+
will appear beneath the code cell. When this code is run in a Python
|
|
128
|
+
console, a new interactive window will appear that blocks the main thread.
|
|
129
|
+
|
|
130
|
+
In addition to showing the plot in 3D, VectoRose includes various functions
|
|
131
|
+
to produce animations and screenshots of spherical histograms.
|
|
132
|
+
|
|
133
|
+
### Directional Statistics
|
|
134
|
+
|
|
135
|
+
The functions in the `vectorose.stats` module enable directional statistics
|
|
136
|
+
to be computed. These functions have been adapted from the work by Fisher,
|
|
137
|
+
Lewis and Embleton.[^fle]
|
|
138
|
+
|
|
139
|
+
VectoRose implements a variety of descriptive statistics and hypothesis
|
|
140
|
+
tests. Most of these consider pure directions or orientations, which are
|
|
141
|
+
represented as unit vectors.
|
|
142
|
+
|
|
143
|
+
In this code snippet, we generate two sets of mock vectors: a cluster,
|
|
144
|
+
following a von Mises-Fisher distribution, and a girdle, following a Watson
|
|
145
|
+
distribution with a negative parameter value. We then compute Woodcock's
|
|
146
|
+
shape and strength parameters, as described by Woodcock[^woodcock] and as
|
|
147
|
+
explained by Fisher, Lewis and Embleton.[^fle]
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
import vectorose as vr
|
|
151
|
+
import vectorose.mock_data
|
|
152
|
+
import numpy as np
|
|
153
|
+
|
|
154
|
+
# Create random vectors for demonstration
|
|
155
|
+
my_cluster_vectors = vr.mock_data.create_vonmises_fisher_vectors_single_direction(
|
|
156
|
+
phi=45,
|
|
157
|
+
theta=70,
|
|
158
|
+
kappa=20,
|
|
159
|
+
number_of_points=10000,
|
|
160
|
+
magnitude=1.0,
|
|
161
|
+
magnitude_std=0,
|
|
162
|
+
use_degrees=True,
|
|
163
|
+
seed=20250318,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
direction = np.array([1, 0, 0])
|
|
167
|
+
my_girdle_vectors = vr.mock_data.generate_watson_distribution(
|
|
168
|
+
direction, -20, n=10000, seed=20250318
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
# Compute Woodcock's parameters for both sets of vectors
|
|
172
|
+
cluster_orientation_matrix_eigs, _ = vr.stats.compute_orientation_matrix_eigs(
|
|
173
|
+
my_cluster_vectors
|
|
174
|
+
)
|
|
175
|
+
girdle_orientation_matrix_eigs, _ = vr.stats.compute_orientation_matrix_eigs(
|
|
176
|
+
my_girdle_vectors
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
cluster_woodcock_parameters = vr.stats.compute_orientation_matrix_parameters(
|
|
180
|
+
cluster_orientation_matrix_eigs
|
|
181
|
+
)
|
|
182
|
+
girdle_woodcock_parameters = vr.stats.compute_orientation_matrix_parameters(
|
|
183
|
+
girdle_orientation_matrix_eigs
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
print(f"The VMF distribution has shape parameter {cluster_woodcock_parameters.shape_parameter:.3f}"
|
|
187
|
+
f" and strength parameter {cluster_woodcock_parameters.strength_parameter:.3f}.")
|
|
188
|
+
|
|
189
|
+
print(f"The Watson distribution has shape parameter {girdle_woodcock_parameters.shape_parameter:.3f}"
|
|
190
|
+
f" and strength parameter {girdle_woodcock_parameters.strength_parameter:.3f}.")
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Running this code produces the following output:
|
|
194
|
+
```
|
|
195
|
+
The VMF distribution has shape parameter 48.085 and strength parameter 2.987.
|
|
196
|
+
The Watson distribution has shape parameter 0.005 and strength parameter 2.955.
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Additional statistical operations are provided in the VectoRose API and are
|
|
200
|
+
described in the **User's Guide**.
|
|
201
|
+
|
|
202
|
+
## Citation
|
|
203
|
+
|
|
204
|
+
If you've found VectoRose helpful for your research, please cite our
|
|
205
|
+
publication:
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
TBA
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
If you've modelled your analysis based on our sample case studies, please
|
|
212
|
+
also cite the following:
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
TBA
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Contributing
|
|
219
|
+
|
|
220
|
+
Interested in contributing? Check out the contributing guidelines. Please
|
|
221
|
+
note that this project is released with a Code of Conduct. By contributing
|
|
222
|
+
to this project, you agree to abide by its terms.
|
|
223
|
+
|
|
224
|
+
VectoRose is built on a number of existing, well-supported open-source
|
|
225
|
+
packages, including: [NumPy](https://numpy.org/),
|
|
226
|
+
[PyVista](https://docs.pyvista.org/),
|
|
227
|
+
[Matplotlib](https://matplotlib.org/),
|
|
228
|
+
[pandas](https://pandas.pydata.org/),
|
|
229
|
+
[SciPy](https://scipy.org/) and [trimesh](https://trimesh.org/).
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
|
|
234
|
+
VectoRose was created by Benjamin Z. Rudski and Joseph Deering. It is
|
|
235
|
+
licensed under the terms of the MIT license. See the `LICENSE` file for
|
|
236
|
+
more details.
|
|
237
|
+
|
|
238
|
+
## Acknowledgements
|
|
239
|
+
|
|
240
|
+
The VectoRose project is developed by Benjamin Z. Rudski and Joseph Deering
|
|
241
|
+
under the supervision of Dr. Natalie Reznikov at McGill University, in
|
|
242
|
+
Montreal, Quebec, Canada 🇨🇦.
|
|
243
|
+
|
|
244
|
+
Works consult in this project are available in our online documentation, as
|
|
245
|
+
well as in [`docs/refs.bib`](./docs/refs.bib). For the directional
|
|
246
|
+
statistics approaches, we made extensive use of *Statistic analysis of
|
|
247
|
+
spherical data* by Fisher, Lewis and Embleton.[^fle]
|
|
248
|
+
|
|
249
|
+
We also made extensive use of the book [*Python Packages*](https://py-pkgs.org/)
|
|
250
|
+
by Tomas Beuzen and Tiffany Timbers to inform the structure and development
|
|
251
|
+
of this package.
|
|
252
|
+
|
|
253
|
+
## Credits
|
|
254
|
+
|
|
255
|
+
`vectorose` was created with [`cookiecutter`](https://cookiecutter.readthedocs.io/en/latest/) and the `py-pkgs-cookiecutter` [template](https://github.com/py-pkgs/py-pkgs-cookiecutter).
|
|
256
|
+
|
|
257
|
+
[^fle]: Fisher, N. I., Lewis, T., & Embleton, B. J. J. (1993).
|
|
258
|
+
*Statistical analysis of spherical data* ([New ed.], 1. paperback ed).
|
|
259
|
+
Cambridge Univ. Press. <https://www.cambridge.org/ca/universitypress/subjects/physics/astronomy-general/statistical-analysis-spherical-data?format=PB>
|
|
260
|
+
|
|
261
|
+
[^woodcock]: Woodcock, N. H. (1977). Specification of fabric shapes using
|
|
262
|
+
an eigenvalue method. *Geological Society of America Bulletin, 88*(9), 1231.
|
|
263
|
+
[https://doi.org/10.1130/0016-7606(1977)88<1231:SOFSUA>2.0.CO;2](https://doi.org/10.1130/0016-7606(1977)88<1231:SOFSUA>2.0.CO;2)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "vectorose"
|
|
3
|
+
version = "0.2.1"
|
|
4
|
+
description = "Plot polar and spherical histograms from orientation data."
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "Benjamin Z. Rudski", email = "benjamin.rudski@mail.mcgill.ca"},
|
|
7
|
+
{name = "Joseph Deering", email = "joseph.deering@mcgill.ca"},
|
|
8
|
+
]
|
|
9
|
+
license = "MIT"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"numpy (>=1.19.5, <2)",
|
|
14
|
+
"matplotlib>=3.3.4",
|
|
15
|
+
"pandas>=1.1.3",
|
|
16
|
+
"openpyxl (>=3.1.2, <4)",
|
|
17
|
+
"trimesh[easy] (>=4.3.0, <5)",
|
|
18
|
+
"imageio-ffmpeg (>=0.5.1, <1)",
|
|
19
|
+
"scipy (>=1.14, <2)",
|
|
20
|
+
"importlib-metadata>=7.0.1",
|
|
21
|
+
"pyvista[all, jupyter, trame] (>=0.44.1, <1)",
|
|
22
|
+
"imageio[ffmpeg, pyav]>=2.27.0",
|
|
23
|
+
"trame (>=3.6.5, <4)",
|
|
24
|
+
"ipywidgets (>=8.1.5, <9)",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
homepage = "https://github.com/bzrudski/vectorose"
|
|
29
|
+
repository = "https://github.com/bzrudski/vectorose"
|
|
30
|
+
documentation = "https://vectorose.readthedocs.io/en/latest/index.html"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
[tool.poetry.group.dev.dependencies]
|
|
34
|
+
pytest = "^7.4.4"
|
|
35
|
+
pytest-cov = "^4.1.0"
|
|
36
|
+
jupyter = "^1.0.0"
|
|
37
|
+
myst-nb = "^1.0.0"
|
|
38
|
+
sphinx-autoapi = "^3.0.0"
|
|
39
|
+
python-semantic-release = "^8.7.0"
|
|
40
|
+
ipympl = "^0.9.4"
|
|
41
|
+
pydata-sphinx-theme = "^0.15.3"
|
|
42
|
+
jupyterlab = ">=3"
|
|
43
|
+
black = "^24.10.0"
|
|
44
|
+
sphinxcontrib-bibtex = "^2.6.3"
|
|
45
|
+
jupytext = "^1.16.4"
|
|
46
|
+
sphinxcontrib-video = "^0.3.1"
|
|
47
|
+
sphinx-design = "^0.6.1"
|
|
48
|
+
sphinx-copybutton = "^0.5.2"
|
|
49
|
+
|
|
50
|
+
[tool.semantic_release]
|
|
51
|
+
version_toml = [
|
|
52
|
+
"pyproject.toml:project.version"
|
|
53
|
+
]
|
|
54
|
+
branch = "main" # branch to make releases of
|
|
55
|
+
build_command = "poetry build" # build dists
|
|
56
|
+
|
|
57
|
+
[tool.semantic_release.publish]
|
|
58
|
+
upload_to_vcs_release = true
|
|
59
|
+
|
|
60
|
+
[build-system]
|
|
61
|
+
requires = ["poetry-core>=1.0.0"]
|
|
62
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""VectoRose: A new tool for visualising and analysing directional data."""
|
|
2
|
+
|
|
3
|
+
from vectorose import polar_data
|
|
4
|
+
from vectorose import plotting
|
|
5
|
+
from vectorose import io
|
|
6
|
+
from vectorose import triangle_sphere
|
|
7
|
+
from vectorose import tregenza_sphere
|
|
8
|
+
from vectorose import util
|
|
9
|
+
from vectorose import stats
|
|
10
|
+
|
|
11
|
+
from vectorose.sphere_base import SphereBase
|
|
12
|
+
|
|
13
|
+
from importlib_metadata import version
|
|
14
|
+
|
|
15
|
+
__version__ = version("vectorose")
|