geometry
The geometry module contains core classes that support the INGRID geometrical object hierarchy. This module also contains various helper functions that work in tandem with the LineTracing class to generate Patch maps and grids.
- class INGRID.geometry.Cell(lines)
Bases:
object
Define a Cell that resides within a grid.
- Parameters
lines (array-like) – A collection of 4 Line objects that define the borders of a Cell.
- Variables
lines (array-like) – The 4 Lines that create the border of the Cell.
vertices (dict) – A lookup for accessing NW, NE, SE, SW, and CENTER spatial information.
p (list) – A list of Point objects along the North and South border.
Notes
When accessing vertices, we have the following convention:
Location
Accepted Key (str)
NW Corner
NW
NE Corner
NE
SW Corner
SW
SE Corner
SE
Center
CENTER
- as_np() numpy.ndarray
Get the ndarray representation of a Cell object
- Returns
An ndarray representing a cell
- plot_border(color: str = 'red', ax: Optional[matplotlib.axes.Axes] = None) None
Plot the Cell.
- Parameters
color (str, optional) – Color of the Cell border. Defaults to ‘red’
ax (matplotlib.axes.Axes, optional) – The Axes instance to plot the Cell to.
- plot_center(color='black', ax: Optional[matplotlib.axes.Axes] = None) None
Plot the center of a Cell.
- Parameters
color (str, optional) – The color of the marker. Defaults to ‘black’
ax (matplotlib.axes.Axes, optional) – The Axes instance to plot the Cell center to.
- class INGRID.geometry.Line(points: list)
Bases:
object
Define an arbitrary line/curve.
This is ordered collection of Point objects can later be used to define a Patch object.
- Parameters
points (list) – The Point objects that define the Line.
- Variables
p (list) – The list of Point objects that define this Line.
xval (list) – A list consisting the x-coordinates for each Point.
yval (list) – A list consisting the y-coordinates for each Point.
- GetAngle(Line)
Return the angle between two lines in degree (between 0 and 180 degrees) :param Line: DESCRIPTION. :type Line: TYPE
- Returns
None.
- Norm()
Return norm of the lines :returns: None.
- RemoveDuplicatePoints()
Remove any duplicate points from list of points
- as_np() numpy.ndarray
Get the calling Line object represented as an ndarray.
- Returns
An ndarray representation of the Line.
Notes
Format of ndarray is of shape (2, n), with n being the number of Point objects in the Line.
The first entry of the ndarray is the
xval
attribute. The second entry of the ndarray is theyval
attribute.This method is used to encode the patch_data file.
- copy() INGRID.geometry.Line
Create a copy of this Line object.
- Returns
A new Line instance.
- fluff(num: int = 1000, verbose: bool = False) tuple
Obtain linspaced copies of the
xval
andyval
attributes.- Parameters
num (int, optional) – Number of entries to include between each segment within the Line. Defaults to 100.
verbose (bool, optional) – Print full output to terminal. Defaults to False
- Returns
A 2-tuple consisting of ‘fluffed’
xval
andyval
.
- fluff_copy(num: int = 5) INGRID.geometry.Line
Create a ‘fluffed’ copy of this Line.
Calls the method
fluff
internally.- Parameters
num (int, optional) – Number of entries to include between each segment within the Line copy.
- Returns
A ‘fluffed’ copy of the calling Line object.
- plot(color: str = '#1f77b4', label: str = '', ax: Optional[matplotlib.axes.Axes] = None, linewidth: float = 1.0) matplotlib.axes.Axes
Plot the Line.
- Parameters
color (str, optional) – Defaults to a light blue.
label (str, optional) – A label to plot with. Defaults to None.
ax (matplotlib.axes.Axes, optional) – The Axes instance to plot the Line to.
linewidth (float, optional) – The linewidth to plot with.
- Returns
The matplotlib.axes.Axes instance plotted on.
- points() list
Get a list of all coordinates within the Line object.
- Returns
A list of tuples representing (x, y) coordinates of the Line.
- print_points() None
Prints each point in the line to the terminal.
- reverse_copy() INGRID.geometry.Line
Create a copy of this Line in reversed order.
- Returns
A new Line instance
- split(split_point, add_split_point=False) tuple
Split a line object into two line objects at a particular point.
Returns two Line objects Segment A and Segment B (corresponding to both subsets of Points) The split_point is always included in Segment B.
- Parameters
split_point (Point) – Point that determines splitting location.
add_split_point (bool) – Append the split point to Segment A while still including the split point in Segment B.
- Returns
A tuple with Line objects representing Segment A and Segment B.
- class INGRID.geometry.Patch(lines: array - like, patch_name: str = '', PatchTagMap: dict = None, plate_patch: bool = False, plate_location: str = None, color: str = 'blue')
Bases:
object
Define a Patch representing a portion of the tokamak domain.
Each Patch can be refined into a subgrid that can then create a global grid.
- Parameters
lines (array-like) – The four Line objects defining the boundary of this Patch (N, E, S, W).
patch_name –
- AdjustBorder(face, patch)
- CheckPatch(grid, verbose=False)
- RemoveDuplicatePoints()
- adjust_corner(point, corner)
- as_np()
- cell_grid_as_np()
- fill(color='lightsalmon', ax=None, alpha=1.0)
Shades in the patch with a given color
- Parameters
color (str, optional) – Defaults to a light salmon.
- get_settings()
- get_tag()
- make_subgrid(grid, np_cells=2, nr_cells=2, _poloidal_f=<function Patch.<lambda>>, _radial_f=<function Patch.<lambda>>, verbose=False, visual=False, ShowVertices=False)
Generate a refined grid within a patch. This ‘refined-grid’ within a Patch is a collection of num x num Cell objects
- Parameters
grid (Ingrid) – To be used for obtaining Efit data and all other class information.
num (int, optional) – Number to be used to generate num x num cells within our Patch.
- plot_border(color='red', ax=None)
Draw solid borders around the patch.
- Parameters
color (str, optional) – Defaults to red.
- plot_subgrid(fig=None, ax=None, color='blue')
- class INGRID.geometry.Point(*pts)
Bases:
object
Define a Point.
Can be used to later define Line objects.
- Parameters
pts (array-like) – Accepts either two values x, y as floats, or a single tuple/list value (x, y).
- Variables
x (float) – x coordinate of the point
y (float) – y coordinate of the point
coor (tuple) – x and y coordinates together as a tuple
- as_np() numpy.ndarray
Return the Point object as a numpy ndarray.
- Returns
An ndarray representation of the Point object.
- plot(ax: Optional[matplotlib.axes.Axes] = None) None
Plot the Point.
- Parameters
ax (matplotlib.axes.Axes, optional) – The Axes instance to plot to. Default is None and calls function matplotlib.pyplot.gca.
- psi(grid: EfitData, tag: str = 'v') float
Get the psi value of this Point from an EfitData instance.
- Parameters
grid (EfitData) – The grid upon which the value of psi is to be calculated on.
tag (str, optional) – Char to specify the type of psi derivative. Defaults ‘v’ (no derivative).
- Returns
The psi value at the Point.
- class INGRID.geometry.Vector(xy: array - like, origin: array - like)
Bases:
object
Defines a vector from a nontrivial origin.
- Parameters
xy (array-like) – Location of the vector. It if of the form (x, y).
origin (array-like) – Location of the origin. This is to adjust for not being at the origin of the axes. Of the form (x, y).
- Variables
x (float) – x-coordinate
y (float) – y-coordinate
xorigin (float) – x-coordinate of vector origin
yorigin (float) – y-coordinate of vector origin
xnorm (float) – x relative to origin
ynorm (float) – y relative to origin
quadrant (int) – Quadrant vector resides in
- arr() numpy.ndarray
Return the vector object as an array.
- Returns
The vector as an numpy ndarray.
- mag() float
Return the L2 norm of the vector.
- Returns
Vector norm.
- INGRID.geometry.CorrectDistortion(u, Pt, Pt1, Pt2, spl, ThetaMin, ThetaMax, umin, umax, Resolution, visual, Tag, MinTol=1.02, MaxTol=0.98, Verbose=False)
- INGRID.geometry.UnfoldLabel(Dic: dict, Name: str) str
Unfold Patch label (e.g. “C1” -> “Inner Core Top”)
- Parameters
Dic (dict) – Dictionnary containing description of acronym characters
Name (str) – patch label
- Returns
str – Unfolded patch label.
- INGRID.geometry.angle_between(u, v, origin, relative=False)
Compute angle in radians between vectors u and v
- INGRID.geometry.calc_mid_point(v1, v2)
Calculates the bisection of two vectors of equal length, and returns the point on the circle at that angle.
- Parameters
v1 (geometry.Vector) – v1 must be furthest right in a counter clockwise direction.
v2 (geometry.Vector) – Vector on the left.
- Returns
tuple – The point at the bisection of two vectors.
- INGRID.geometry.find_split_index(split_point: INGRID.geometry.Point, line: INGRID.geometry.Line) tuple
Determine which index a Point would best split a Line.
This method is useful for modifying Line objects during line tracing (searching for intersection of two line objects and trimming excess)
- Parameters
- Returns
A 2-tuple containing the split-index and a boolean flag indicating – whether the split_point was contained within the Line
Notes
Should no appropriate split index be found, the method will return a None value in place of an integer index.
The second entry of the tuple return value would be a value of True if the split_point parameter was used to define the line parameter.
- INGRID.geometry.intersect(line1, line2, verbose=False)
Finds the intersection of two line segments
- Parameters
line1 (array-like) –
line2 (array-like) – Both lines of the form A = ((x, y), (x, y)).
- Returns
tuple – Coordinates of the intersection.
- INGRID.geometry.is_between(end_u: array - like, split_v: array - like) bool
- INGRID.geometry.limiter_split(start, end, limiter)
- INGRID.geometry.non_decreasing(L: array - like) bool
Determine if non-decreasing.
- Parameters
L (array-like) – Values to test.
- Returns
True if non-decreasing and False otherwise
- INGRID.geometry.non_increasing(L: array - like) bool
Determine if non-increasing.
- Parameters
L (array-like) – Values to test.
- Returns
True if non-increasing and False otherwise
- INGRID.geometry.orientation_between(u, v, origin)
Compute angle in radians between vectors u and v
- INGRID.geometry.reorder_limiter(new_start, limiter)
- INGRID.geometry.rotate(vec, theta, origin)
- INGRID.geometry.rotmatrix(theta: float) numpy.ndarray
Construct a rotation matrix
- Parameters
theta (float) – Angle in radians.
- Returns
An ndarray with shape (2, 2) representing a 2D rotation matrix.
- INGRID.geometry.segment_intersect(line1, line2, verbose=False)
Finds the intersection of two FINITE line segments. :param line1: :type line1: array-like :param line2: Both lines of the form line1 = (P1, P2), line2 = (P3, P4) :type line2: array-like
- Returns
bool, tuple – True/False of whether the segments intersect Coordinates of the intersection
- INGRID.geometry.strictly_decreasing(L: array - like) bool
Determine if strictly decreasing.
- Parameters
L (array-like) – Values to test.
- Returns
True if strictly decreasing and False otherwise
- INGRID.geometry.strictly_increasing(L: array - like) bool
Determine if strictly increasing.
- Parameters
L (array-like) – Values to test.
- Returns
True if strictly increasing and False otherwise
- INGRID.geometry.test2points(p1, p2, line)
Check if two points are on opposite sides of a given line.
- Parameters
p1 (tuple) – First point, (x, y)
p2 (tuple) – Second point, (x, y)
line (array-like) – The line is comprised of two points ((x, y), (x, y)).
- Returns
tuple – Returns two numbers, if the signs are different the points are on opposite sides of the line.
- INGRID.geometry.trim_geometry(geoline, start, end)
- INGRID.geometry.unit_vector(v)
Returns unit vector
- INGRID.geometry.which_increasing(L: array - like) list
Determine increasing values.
- Parameters
L (array-like) – Values to test.
- Returns
A list of 2-tuples containing index and increasing element
- INGRID.geometry.which_non_increasing(L: array - like) list
Determine non-increasing values.
- Parameters
L (array-like) – Values to test.
- Returns
A list of 2-tuples containing index and non-increasing element.