Skip to content

Commit

Permalink
updated ellipse/ellipsoid exp. volume, fixed bug in verif. module
Browse files Browse the repository at this point in the history
  • Loading branch information
kip-hart committed Jul 9, 2020
1 parent 3d4ea0c commit 906347f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog`_,
and this project adheres to `Semantic Versioning`_.

`Unreleased`_
`1.3.1`_ - 2020-07-09
--------------------------
Added
'''''
- VTK output for seed lists and polyhedral meshes.
- Option to compute expected area of ellipse from area distribution.
- Option to compute expected volume of ellipsoid from volume distribution.

Fixed
'''''
- Error in verification module for 2D uniform random orientations.

`1.3.0`_ - 2020-06-25
--------------------------
Expand Down Expand Up @@ -113,7 +119,8 @@ Added

.. LINKS
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.0...HEAD
.. _`Unreleased`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.1...HEAD
.. _`1.3.1`: https://github.com/kip-hart/MicroStructPy/compare/v1.3.0...v1.3.1
.. _`1.3.0`: https://github.com/kip-hart/MicroStructPy/compare/v1.2.2...v1.3.0
.. _`1.2.2`: https://github.com/kip-hart/MicroStructPy/compare/v1.2.1...v1.2.2
.. _`1.2.1`: https://github.com/kip-hart/MicroStructPy/compare/v1.2.0...v1.2.1
Expand Down
2 changes: 1 addition & 1 deletion src/microstructpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
import microstructpy.seeding
import microstructpy.verification

__version__ = '1.3.0'
__version__ = '1.3.1'
29 changes: 20 additions & 9 deletions src/microstructpy/geometry/ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def __init__(self, **kwargs):
self.center = (0, 0)

# axes
if 'area' in kwargs:
kwargs['size'] = 2 * np.sqrt(kwargs['area'] / np.pi)
if ('a' in kwargs) and ('b' in kwargs):
assert kwargs['a'] > 0
assert kwargs['b'] > 0
Expand Down Expand Up @@ -369,10 +371,17 @@ def area_expectation(cls, **kwargs):

if type(s_dist) in (float, int):
return 0.25 * np.pi * s_dist * s_dist
else:
return 0.25 * np.pi * s_dist.moment(2)
return 0.25 * np.pi * s_dist.moment(2)

if 'area' in kwargs:
a_dist = kwargs['area']
try:
a_exp = a_dist.moment(1)
except AttributeError:
a_exp = a_dist
return a_exp

elif ('a' in kwargs) and ('b' in kwargs):
if ('a' in kwargs) and ('b' in kwargs):
exp = np.pi
for kw in ('a', 'b'):
dist = kwargs[kw]
Expand All @@ -382,7 +391,8 @@ def area_expectation(cls, **kwargs):
mu = dist.moment(1)
exp *= mu
return exp
elif ('b' in kwargs) and ('aspect_ratio' in kwargs):

if ('b' in kwargs) and ('aspect_ratio' in kwargs):
exp = np.pi
try:
exp *= kwargs['b'].moment(2)
Expand All @@ -394,7 +404,8 @@ def area_expectation(cls, **kwargs):
except AttributeError:
exp *= kwargs['aspect_ratio']
return exp
elif ('a' in kwargs) and ('aspect_ratio' in kwargs):

if ('a' in kwargs) and ('aspect_ratio' in kwargs):
n = 1000
try:
a = kwargs['a'].rvs(size=n)
Expand All @@ -406,10 +417,10 @@ def area_expectation(cls, **kwargs):
except AttributeError:
k = np.full(n, kwargs['aspect_ratio'])
return np.pi * np.mean((a * a) / k)
else:
e_str = 'Could not calculate expected area from keywords '
e_str += str(kwargs.keys()) + '.'
raise KeyError(e_str)

e_str = 'Could not calculate expected area from keywords '
e_str += str(kwargs.keys()) + '.'
raise KeyError(e_str)

# ----------------------------------------------------------------------- #
# Bounding Circles #
Expand Down
11 changes: 9 additions & 2 deletions src/microstructpy/geometry/ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,15 @@ def volume_expectation(cls, **kwargs):
s_dist = kwargs['size']
if type(s_dist) in (float, int):
return 0.5 * np.pi * s_dist * s_dist * s_dist / 3
else:
return 0.5 * np.pi * s_dist.moment(3) / 3
return 0.5 * np.pi * s_dist.moment(3) / 3

if 'volume' in kwargs:
v_dist = kwargs['volume']
try:
v_exp = v_dist.moment(1)
except AttributeError:
v_exp = v_dist
return v_exp

# check for a, b, and c distribution
try:
Expand Down
5 changes: 5 additions & 0 deletions src/microstructpy/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,11 @@ def error_stats(fit_seeds, seeds, phases, poly_mesh=None, verif_mask=None):
i_phase = init_phases[i]
o_phase = outp_phases[i]
phase = phases[i]
for kw in phase:
if kw in ('angle', 'angle_deg') and phase[kw] == 'random':
phase[kw] = scipy.stats.uniform(loc=0, scale=360)
if kw == 'angle_rad':
phase[kw] = scipy.stats.uniform(loc=0, scale=2 * np.pi)

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

0 comments on commit 906347f

Please sign in to comment.