-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Patrick Curran
committed
Oct 2, 2024
1 parent
97ab620
commit b5452d4
Showing
24 changed files
with
13,203 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from defdap.experiment import Experiment | ||
|
||
defaults = { | ||
# Convention to use when attaching an orthonormal frame to a crystal | ||
# structure. 'hkl' or 'tsl' | ||
# OI/HKL convention - x // [10-10], y // a2 [-12-10] | ||
# TSL convention - x // a1 [2-1-10], y // [01-10] | ||
'crystal_ortho_conv': 'hkl', | ||
# Projection to use when plotting pole figures. 'stereographic' (equal | ||
# angle), 'lambert' (equal area) or arbitrary projection function | ||
'pole_projection': 'stereographic', | ||
# Frequency of find grains algorithm reporting progress | ||
'find_grain_report_freq': 100, | ||
# How to find grain in a HRDIC map, either 'floodfill' or 'warp' | ||
'hrdic_grain_finding_method': 'floodfill', | ||
'slip_system_file': { | ||
'FCC': 'cubic_fcc', | ||
'BCC': 'cubic_bcc', | ||
'HCP': 'hexagonal_withca', | ||
}, | ||
} | ||
|
||
anonymous_experiment = Experiment() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
from numba import njit | ||
import numpy as np | ||
|
||
|
||
@njit | ||
def find_first(arr): | ||
for i in range(len(arr)): | ||
if arr[i]: | ||
return i | ||
|
||
|
||
@njit | ||
def flood_fill(seed, index, points_remaining, grains, boundary_x, boundary_y, | ||
added_coords): | ||
"""Flood fill algorithm that uses the x and y boundary arrays to | ||
fill a connected area around the seed point. The points are inserted | ||
into a grain object and the grain map array is updated. | ||
Parameters | ||
---------- | ||
seed : tuple of 2 int | ||
Seed point x for flood fill | ||
index : int | ||
Value to fill in grain map | ||
points_remaining : numpy.ndarray | ||
Boolean map of the points that have not been assigned a grain yet | ||
Returns | ||
------- | ||
grain : defdap.ebsd.Grain | ||
New grain object with points added | ||
""" | ||
x, y = seed | ||
grains[y, x] = index | ||
points_remaining[y, x] = False | ||
edge = [seed] | ||
added_coords[0] = seed | ||
npoints = 1 | ||
|
||
while edge: | ||
x, y = edge.pop() | ||
moves = [(x+1, y), (x-1, y), (x, y+1), (x, y-1)] | ||
# get rid of any that go out of the map area | ||
if x <= 0: | ||
moves.pop(1) | ||
elif x > grains.shape[1] - 2: | ||
moves.pop(0) | ||
if y <= 0: | ||
moves.pop(-1) | ||
elif y > grains.shape[0] - 2: | ||
moves.pop(-2) | ||
|
||
for (s, t) in moves: | ||
if grains[t, s] > 0: | ||
continue | ||
|
||
add_point = False | ||
|
||
if t == y: | ||
# moving horizontally | ||
if s > x: | ||
# moving right | ||
add_point = not boundary_x[y, x] | ||
else: | ||
# moving left | ||
add_point = not boundary_x[t, s] | ||
else: | ||
# moving vertically | ||
if t > y: | ||
# moving down | ||
add_point = not boundary_y[y, x] | ||
else: | ||
# moving up | ||
add_point = not boundary_y[t, s] | ||
|
||
if add_point: | ||
added_coords[npoints] = s, t | ||
grains[t, s] = index | ||
points_remaining[t, s] = False | ||
npoints += 1 | ||
edge.append((s, t)) | ||
|
||
return added_coords[:npoints] | ||
|
||
|
||
@njit | ||
def flood_fill_dic(seed, index, points_remaining, grains, added_coords): | ||
"""Flood fill algorithm that uses the combined x and y boundary array | ||
to fill a connected area around the seed point. The points are returned and | ||
the grain map array is updated. | ||
Parameters | ||
---------- | ||
seed : tuple of 2 int | ||
Seed point x for flood fill | ||
index : int | ||
Value to fill in grain map | ||
points_remaining : numpy.ndarray | ||
Boolean map of the points remaining to assign a grain yet | ||
grains : numpy.ndarray | ||
added_coords : numpy.ndarray | ||
Buffer for points in the grain | ||
Returns | ||
------- | ||
numpy.ndarray | ||
Flooded points (n, 2) | ||
""" | ||
# add first point to the grain | ||
x, y = seed | ||
grains[y, x] = index | ||
points_remaining[y, x] = False | ||
edge = [seed] | ||
added_coords[0] = seed | ||
npoints = 1 | ||
|
||
while edge: | ||
x, y = edge.pop() | ||
|
||
moves = [(x+1, y), (x-1, y), (x, y+1), (x, y-1)] | ||
# get rid of any that go out of the map area | ||
if x <= 0: | ||
moves.pop(1) | ||
elif x >= grains.shape[1] - 1: | ||
moves.pop(0) | ||
if y <= 0: | ||
moves.pop(-1) | ||
elif y >= grains.shape[0] - 1: | ||
moves.pop(-2) | ||
|
||
for (s, t) in moves: | ||
add_point = False | ||
|
||
if grains[t, s] == 0: | ||
add_point = True | ||
edge.append((s, t)) | ||
|
||
elif grains[t, s] == -1 and (s > x or t > y): | ||
add_point = True | ||
|
||
if add_point: | ||
added_coords[npoints] = (s, t) | ||
grains[t, s] = index | ||
points_remaining[t, s] = False | ||
npoints += 1 | ||
|
||
return added_coords[:npoints] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = '0.93.5dev' |
Oops, something went wrong.