grid¶
-
class
javelin.grid.
Grid
[source]¶ Grid class to allow the Q-space grid to be defined in different ways. The grid can be defined be either specifying the corners of the volume or by the axis vectors.
The grid is defined by three vectors v1, v2 and v3; the range of these vectors r1, r2 and r3; and the number of bin in each of these directions.
Examples: Setting grid by defining corners
>>> grid = Grid() >>> grid.set_corners(ll=[-2,-2,-3], lr=[2,2,-3], ul=[-2,-2,3]) >>> grid.bins = 5, 3 >>> grid.v1 array([ 1., 1., 0.]) >>> grid.v2 array([ 0., 0., 1.]) >>> grid.v3 array([ 1., -1., 0.]) >>> grid.r1 array([-2., -1., 0., 1., 2.]) >>> grid.r2 array([-3., 0., 3.]) >>> grid.r3 array([ 0.]) >>> print(grid) lower left corner : [-2. -2. -3.] lower right corner : [ 2. 2. -3.] upper left corner : [-2. -2. 3.] top left corner : [-2. -2. -3.] <BLANKLINE> hor. increment : [ 1. 1. 0.] vert. increment : [ 0. 0. 3.] top increment : [ 1. -1. 0.] <BLANKLINE> # of points : 5 x 3 x 1
Setting grid by vectors and ranges
>>> grid = Grid() >>> grid.v1 = [1, 1, 1] >>> grid.v2 = [2, -1, -1] >>> grid.v3 = [0, 1, -1] >>> grid.r1 = [-1, 1] >>> grid.r2 = [0, 2] >>> grid.r3 = [0, 2] >>> grid.bins = 3, 3, 3 >>> print(grid) lower left corner : [-1 -1 -1] lower right corner : [1 1 1] upper left corner : [ 3 -3 -3] top left corner : [-1 1 -3] <BLANKLINE> hor. increment : [ 1. 1. 1.] vert. increment : [ 2. -1. -1.] top increment : [ 0. 1. -1.] <BLANKLINE> # of points : 3 x 3 x 3
-
bins
¶ The number of bins in each direction
>>> grid = Grid() >>> grid.bins (101, 101, 1)
>>> grid.bins = 5 >>> grid.bins (5, 1, 1)
>>> grid.bins = 5, 6 >>> grid.bins (5, 6, 1)
>>> grid.bins = 5, 6, 7 >>> grid.bins (5, 6, 7)
Getter: Returns the number of bins in each direction Setter: Sets the number of bins, provide 1, 2 or 3 integers Type: numpy.ndarray
of int
-
get_axes_names
()[source]¶ >>> grid = Grid() >>> grid.get_axes_names() ('[ 1. 0. 0.]', '[ 0. 1. 0.]', '[ 0. 0. 1.]')
Returns: Axis names, vector of each direction Return type: tuple of str
-
get_q_meshgrid
()[source]¶ Equivalent to
numpy.mgrid
for this volumeReturns: mesh-grid numpy.ndarray
all of the same dimensionsReturn type: tuple of numpy.ndarray
-
get_squashed_q_meshgrid
()[source]¶ Almost equivalent to
numpy.ogrid
for this volume. It may have more than one dimension not equal to 1. This can be used with numpy broadcasting.Returns: mesh-grid numpy.ndarray
with some dimension equal to 1Return type: tuple of numpy.ndarray
-
ll
¶ Returns: Lower-left corner of reciprocal volume Return type: numpy.ndarray
-
lr
¶ Returns: Lower-right corner of reciprocal volume Return type: numpy.ndarray
-
r1
¶ Set the range of the first axis, two values min and max
Getter: Array of values for each bin in the axis Setter: Range of first axis, two values Type: numpy.ndarray
-
r2
¶ Set the range of the second axis, two values min and max
Getter: Array of values for each bin in the axis Setter: Range of second axis, two values Type: numpy.ndarray
-
r3
¶ Set the range of the third axis, two values min and max
Getter: Array of values for each bin in the axis Setter: Range of third axis, two values Type: numpy.ndarray
-
set_corners
(ll=(0, 0, 0), lr=None, ul=None, tl=None)[source]¶ Define the axis vectors by the corners of the reciprocal volume. The corners values with be converted into axis vectors, see
javelin.grid.corners_to_vectors()
for details.Parameters: - ll (array-like of length 3) – lower-left corner
- lr (array-like of length 3) – lower-right corner
- ul (array-like of length 3) – upper-left corner
- tl (array-like of length 3) – top-left corner
-
tl
¶ Returns: Top-left corner of reciprocal volume Return type: numpy.ndarray
-
ul
¶ Returns: Upper-left corner of reciprocal volume Return type: numpy.ndarray
-
v1
¶ Getter: Set the first axis Setter: Get the first axis Type: numpy.ndarray
-
v1_delta
¶ Returns: Increment vector of first axis Return type: numpy.ndarray
-
v2
¶ Getter: Set the second axis Setter: Get the second axis Type: numpy.ndarray
-
v2_delta
¶ Returns: Increment vector of second axis Return type: numpy.ndarray
-
v3
¶ Getter: Set the third axis Setter: Get the third axis Type: numpy.ndarray
-
v3_delta
¶ Returns: Increment vector of third axis Return type: numpy.ndarray
-
-
javelin.grid.
angle
(v1, v2)[source]¶ Calculates the angle between two vectors
Parameters: - v1 (array-like object of numbers) – vector 1
- v2 (array-like object of numbers) – vector 2
Returns: angle (radians)
Return type: float
Examples: >>> angle([1,0,0], [-1,0,0]) 3.1415926535897931
>>> angle([1,0,0], [0,1,0]) 1.5707963267948966
-
javelin.grid.
check_parallel
(v1, v2)[source]¶ Checks if two vectors are parallel
Parameters: - v1 (array-like object of numbers) – vector1
- v2 (array-like object of numbers) – vector2
Returns: if parallel
Return type: bool
Examples: >>> check_parallel([1,0,0], [-1,0,0]) True
>>> check_parallel([1,0,0], [0,1,0]) False
-
javelin.grid.
corners_to_vectors
(ll=None, lr=None, ul=None, tl=None)[source]¶ This function converts the provided corners into axes vectors and axes ranges. It will also calculate sensible vectors for any unprovided corners.
You must provide at minimum the lower-left (ll) and lower-right (lr) corners.
Parameters: - ll (array-like object of numbers) – lower-left corner (required)
- lr (array-like object of numbers) – lower-right corner (required)
- ul (array-like object of numbers) – upper-left corner
- tl (array-like object of numbers) – top-left corner
Returns: three axes vectors and three axes ranges
Return type: tuple of three
numpy.ndarray
and three tuple rangesExamples: Using only ll and lr, the other two vector are calculated using
javelin.grid.find_other_vectors()
>>> v1, v2, v3, r1, r2, r3 = corners_to_vectors(ll=[-3,-3,0], lr=[3, 3, 0]) >>> print(v1, v2, v3) [ 1. 1. 0.] [ 1. 0. 0.] [ 0. 0. 1.] >>> print(r1, r2, r3) # doctest: +SKIP (-3.0, 3.0) (0.0, 0.0) (0.0, 0.0)
Using ll, lr and ul, the other vector is the
javelin.grid.norm1()
of the cross product of the first two vectors defined by the corners.>>> v1, v2, v3, r1, r2, r3 = corners_to_vectors(ll=[-3,-3,-2], lr=[3, 3, -2], ul=[-3, -3, 2]) >>> print(v1, v2, v3) [ 1. 1. 0.] [ 0. 0. 1.] [ 1. -1. 0.] >>> print(r1, r2, r3) # doctest: +SKIP (-3.0, 3.0) (-2.0, 2.0) (0.0, 0.0)
Finally defining all corners
>>> v1,v2,v3,r1,r2,r3 = corners_to_vectors(ll=[-5,-6,-7],lr=[-5,-6,7],ul=[-5,6,-7],tl=[5,-6,-7]) >>> print(v1, v2, v3) [ 0. 0. 1.] [ 0. 1. 0.] [ 1. 0. 0.] >>> print(r1, r2, r3) (-7.0, 7.0) (-6.0, 6.0) (-5.0, 5.0)
If you provided corners which will create parallel vectors you will get a ValueError
>>> corners_to_vectors(ll=[0, 0, 0], lr=[1, 0, 0], ul=[1, 0, 0]) Traceback (most recent call last): ... ValueError: Vector from ll to lr is parallel with vector from ll to ul
-
javelin.grid.
find_other_vectors
(v)[source]¶ This will find two new vectors which in combination with the provided vector (v) will form a basis for a complete space filling set.
Parameters: v (array-like object of numbers) – vector Returns: two new space filling vectors Return type: tuple of two numpy.ndarray
Examples: >>> find_other_vectors([1, 0, 0]) (array([ 0., 1., 0.]), array([ 0., 0., 1.]))
>>> find_other_vectors([0, 0, 1]) (array([ 1., 0., 0.]), array([ 0., 1., 0.]))
>>> find_other_vectors([1, 1, 0]) (array([ 1., 0., 0.]), array([ 0., 0., 1.]))
-
javelin.grid.
get_vector_from_points
(p1, p2)[source]¶ Calculates the vector form two points
Parameters: - p1 (array-like object of numbers) – point 1
- p2 (array-like object of numbers) – point 2
Returns: vector between points
Return type: Examples: >>> get_vector_from_points([-1, -1, 0], [1, 1, 0]) array([ 1., 1., 0.])
>>> get_vector_from_points([0, 0, 0], [2, 2, 4]) array([ 1., 1., 2.])
-
javelin.grid.
length
(v)[source]¶ Calculates the length of a vector
Parameters: v (array-like object of numbers) – vector Returns: length of vector Return type: float Examples: >>> length([1,0,0]) 1.0
>>> length([1,-1,0]) 1.4142135623730951
>>> length([2,2,2]) 3.4641016151377544
-
javelin.grid.
norm
(v)[source]¶ Calculates the normalised vector
Parameters: v (array-like object of numbers) – vector Returns: normalised vector Return type: numpy.ndarray
Examples: >>> norm([5, 0, 0]) array([ 1., 0., 0.])
>>> norm([1, 1, 0]) array([ 0.70710678, 0.70710678, 0. ])
-
javelin.grid.
norm1
(v)[source]¶ Calculate the equivalent vector with the smallest non-zero component equal to one.
Parameters: v (array-like object of numbers) – vector Returns: normalised1 vector Return type: numpy.ndarray
Examples: >>> norm1([5, 10, 0]) array([ 1., 2., 0.])
>>> norm1([1, 1, 0]) array([ 1., 1., 0.])