Skip to content

Commit 906347f

Browse files
committed
updated ellipse/ellipsoid exp. volume, fixed bug in verif. module
1 parent 3d4ea0c commit 906347f

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

CHANGELOG.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ All notable changes to this project will be documented in this file.
66
The format is based on `Keep a Changelog`_,
77
and this project adheres to `Semantic Versioning`_.
88

9-
`Unreleased`_
9+
`1.3.1`_ - 2020-07-09
1010
--------------------------
1111
Added
1212
'''''
1313
- VTK output for seed lists and polyhedral meshes.
14+
- Option to compute expected area of ellipse from area distribution.
15+
- Option to compute expected volume of ellipsoid from volume distribution.
16+
17+
Fixed
18+
'''''
19+
- Error in verification module for 2D uniform random orientations.
1420

1521
`1.3.0`_ - 2020-06-25
1622
--------------------------
@@ -113,7 +119,8 @@ Added
113119

114120
.. LINKS
115121
116-
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.0...HEAD
122+
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.1...HEAD
123+
.. _`1.3.1`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.0...v1.3.1
117124
.. _`1.3.0`: https://github.com/kip-hart/MicroStructPy/compare/v1.2.2...v1.3.0
118125
.. _`1.2.2`: https://github.com/kip-hart/MicroStructPy/compare/v1.2.1...v1.2.2
119126
.. _`1.2.1`: https://github.com/kip-hart/MicroStructPy/compare/v1.2.0...v1.2.1

src/microstructpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
import microstructpy.seeding
55
import microstructpy.verification
66

7-
__version__ = '1.3.0'
7+
__version__ = '1.3.1'

src/microstructpy/geometry/ellipse.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def __init__(self, **kwargs):
7676
self.center = (0, 0)
7777

7878
# axes
79+
if 'area' in kwargs:
80+
kwargs['size'] = 2 * np.sqrt(kwargs['area'] / np.pi)
7981
if ('a' in kwargs) and ('b' in kwargs):
8082
assert kwargs['a'] > 0
8183
assert kwargs['b'] > 0
@@ -369,10 +371,17 @@ def area_expectation(cls, **kwargs):
369371

370372
if type(s_dist) in (float, int):
371373
return 0.25 * np.pi * s_dist * s_dist
372-
else:
373-
return 0.25 * np.pi * s_dist.moment(2)
374+
return 0.25 * np.pi * s_dist.moment(2)
375+
376+
if 'area' in kwargs:
377+
a_dist = kwargs['area']
378+
try:
379+
a_exp = a_dist.moment(1)
380+
except AttributeError:
381+
a_exp = a_dist
382+
return a_exp
374383

375-
elif ('a' in kwargs) and ('b' in kwargs):
384+
if ('a' in kwargs) and ('b' in kwargs):
376385
exp = np.pi
377386
for kw in ('a', 'b'):
378387
dist = kwargs[kw]
@@ -382,7 +391,8 @@ def area_expectation(cls, **kwargs):
382391
mu = dist.moment(1)
383392
exp *= mu
384393
return exp
385-
elif ('b' in kwargs) and ('aspect_ratio' in kwargs):
394+
395+
if ('b' in kwargs) and ('aspect_ratio' in kwargs):
386396
exp = np.pi
387397
try:
388398
exp *= kwargs['b'].moment(2)
@@ -394,7 +404,8 @@ def area_expectation(cls, **kwargs):
394404
except AttributeError:
395405
exp *= kwargs['aspect_ratio']
396406
return exp
397-
elif ('a' in kwargs) and ('aspect_ratio' in kwargs):
407+
408+
if ('a' in kwargs) and ('aspect_ratio' in kwargs):
398409
n = 1000
399410
try:
400411
a = kwargs['a'].rvs(size=n)
@@ -406,10 +417,10 @@ def area_expectation(cls, **kwargs):
406417
except AttributeError:
407418
k = np.full(n, kwargs['aspect_ratio'])
408419
return np.pi * np.mean((a * a) / k)
409-
else:
410-
e_str = 'Could not calculate expected area from keywords '
411-
e_str += str(kwargs.keys()) + '.'
412-
raise KeyError(e_str)
420+
421+
e_str = 'Could not calculate expected area from keywords '
422+
e_str += str(kwargs.keys()) + '.'
423+
raise KeyError(e_str)
413424

414425
# ----------------------------------------------------------------------- #
415426
# Bounding Circles #

src/microstructpy/geometry/ellipsoid.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,15 @@ def volume_expectation(cls, **kwargs):
533533
s_dist = kwargs['size']
534534
if type(s_dist) in (float, int):
535535
return 0.5 * np.pi * s_dist * s_dist * s_dist / 3
536-
else:
537-
return 0.5 * np.pi * s_dist.moment(3) / 3
536+
return 0.5 * np.pi * s_dist.moment(3) / 3
537+
538+
if 'volume' in kwargs:
539+
v_dist = kwargs['volume']
540+
try:
541+
v_exp = v_dist.moment(1)
542+
except AttributeError:
543+
v_exp = v_dist
544+
return v_exp
538545

539546
# check for a, b, and c distribution
540547
try:

src/microstructpy/verification.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,11 @@ def error_stats(fit_seeds, seeds, phases, poly_mesh=None, verif_mask=None):
893893
i_phase = init_phases[i]
894894
o_phase = outp_phases[i]
895895
phase = phases[i]
896+
for kw in phase:
897+
if kw in ('angle', 'angle_deg') and phase[kw] == 'random':
898+
phase[kw] = scipy.stats.uniform(loc=0, scale=360)
899+
if kw == 'angle_rad':
900+
phase[kw] = scipy.stats.uniform(loc=0, scale=2 * np.pi)
896901

897902
err_io = {kw: _kw_errs(i_phase[kw], o_phase[kw]) for kw in i_phase}
898903
err_po = {kw: _kw_stats(phase[kw], o_phase[kw]) for kw in o_phase}

0 commit comments

Comments
 (0)