A method of SO3FunCBF.

a random sample of n orientations drawn from an orientation density, of directions from a density on the sphere, of numbers from a density on an interval, or n random members of a list

Syntax

ori = discreteSample(odf, n)

N orientations of the density.

ori = discreteSample(odf, n, resolution=2*degree)

From a coarser grid.

v = discreteSample(sF, n)

N directions of a density on the sphere.

x = discreteSample(lambda x: np.exp(-x), n, range=(0, 5))

N numbers of a density on an interval.

ori = discreteSample(ori, n, withoutReplacement=True)

N members of a list, none twice.

ebsd = discreteSample(ebsd, n)

N measurements of a map, of any phases.

Description

How the sample is drawn depends on what is sampled:

  • a density on SO(3) or the sphere: grid nodes drawn with probability proportional to the values, each moved by a random rotation of up to 1.5 times the grid resolution and turned by a random element of each symmetry group. A finer resolution gives a more exact sample.
  • a radial function (unimodalODF, calcDensity): exactly, a centre by its weight, the angle by the distribution of the kernel and a uniform axis; a sum of radial functions term by term.
  • a Bingham distribution: exactly, by rejection.
  • any other callable of numbers (a def, a lambda, a NumPy ufunc such as np.exp, an S1Fun): its values at 10000 points of the range.
  • a list, a map, grains or boundary segments: n of its members, with replacement unless withoutReplacement=True, which returns all members when n exceeds their number; an empty list gives none without replacement and is refused otherwise.

MATLAB’s ‘compact’ sampling and the indices of the members drawn from a list are not provided.

Input

f SO3Fun, S2Fun, a callable of numbers, or a list of orientations or directions, an EBSD map, grains or grain boundary segments
n int, the size of the sample

Keywords

keyword default description
resolution None the spacing of the grid sampled, by default 1.5 degree on SO(3) and 1 degree on the sphere
rng None numpy.random.Generator, the random numbers
withoutReplacement False draw no member of a list twice (a list)
range (0, 1) the interval of a callable of numbers

Output

ori orientation, vector3d, ndarray or the class of the list

Example

Draw a reproducible orientation sample from a model texture, then compare its pole positions with the model pole density. No experimental data are needed.

import numpy as np
import matplotlib.pyplot as plt
from mtex import (crystalFrame, orientation, unimodalODF, degree, discreteSample,
                  Miller, plotPF, mtexColorbar)

cs = crystalFrame('m-3m')
centre = orientation.byEuler(25*degree, 35*degree, 45*degree, cs)
odf = unimodalODF(centre, halfwidth=12*degree)
sample = discreteSample(odf, 300, rng=np.random.default_rng(9))
print('Sample size:', sample.size)
print('Median angle to centre (degrees):', round(float(np.median(sample.angle(centre))/degree), 2))
h = Miller(1, 0, 0, cs)
plotPF(odf, h, antipodal=True, resolution=5*degree)
mtexColorbar(title='Model pole density (mrd)')
plotPF(sample, h, antipodal=True, markerSize=3)
plt.show()

The first figure is the model density; the second contains sampled orientation poles. The seed makes this draw reproducible. Sampling from a density differs from selecting members of an existing list, where withoutReplacement=True prevents selecting the same member twice.

Sample size: 300
Median angle to centre (degrees): 15.23
  I'm plotting 208 random orientations out of 300 given orientations
  You can specify the number of points by the option "points".
  The option "all" ensures that all data are plotted

Example output for S2Fun.discreteSample

Example output for S2Fun.discreteSample

See also

SO3Fun.calcComponents, calcDensity, RandomSampling, S2FunSampling

MATLAB’s SO3FunCBF.discreteSample

source

Citing this page. This page is part of the documentation of MTEX, a free and open source MATLAB toolbox for analyzing and modeling crystallographic textures. It was written by The MTEX Developers and is published at https://mtex-toolbox.github.io/SO3FunCBF.discreteSample_py.html. If you use MTEX, or reuse text or figures from this page, in your research, please cite

F. Bachmann, R. Hielscher, H. Schaeben: Texture Analysis with MTEX - Free and Open Source Software Toolbox, Solid State Phenomena 160 (2010), 63-68. 10.4028/www.scientific.net/SSP.160.63

BibTeX
@article{bachmann2010mtex,
  author  = {F. Bachmann and R. Hielscher and H. Schaeben},
  title   = {Texture Analysis with MTEX - Free and Open Source Software Toolbox},
  journal = {Solid State Phenomena},
  volume  = {160},
  pages   = {63-68},
  year    = {2010},
  doi     = {10.4028/www.scientific.net/SSP.160.63},
  url     = {https://doi.org/10.4028/www.scientific.net/SSP.160.63}
}

Other papers describing specific MTEX methods are listed under Publications — please cite the one that best fits your application. The MTEX source code is licensed under the GNU General Public License v2.0; the text and figures of this documentation are licensed under CC BY 4.0, which permits reuse — including by automated systems — provided The MTEX Developers and this page are credited.