# Load third-party packages
import numpy as np
%matplotlib qt
import matplotlib.pyplot as plt
# Load quat, ebsd and hrdic packages from defdap package
from defdap.quat import Quat
import defdap.ebsd as ebsd
import defdap.hrdic as hrdic
#Load in DIC map
DicFilePath = "example_data/B00005.txt"
DicMap = hrdic.Map(DicFilePath)
#Set crop
DicMap.setCrop(xMin=15, xMax=28, yMin=30, yMax=15)
DicMap.setScale(micrometrePerPixel=0.02)
# Display max shear map
DicMap.plotMaxShear(plotColourBar=True, plotScaleBar=True, vmin=0, vmax=0.1)
DicMap.printStatsTable(percentiles=['Min', 5, 'Mean', 95,'Max'], components = ['mss', 'f11', 'f22'])
histData = DicMap.crop(DicMap.max_shear).flatten()
fig, ax = plt.subplots(1)
counts, bins, bars = ax.hist(histData, bins=np.linspace(0,0.1,100), color='r', histtype='step')
ax.set_xlabel("Effective shear strain")
ax.set_ylabel("Frequency")
fig.show()
# Load in EBSD map
EbsdFilePath = "example_data/Map Data 2-DIC area.cpr"
EbsdMap = ebsd.Map(EbsdFilePath, "cubic")
# Load in slip system definitions (optional)
EbsdMap.loadSlipSystems("cubic_fcc")
# Rotate the map 180 degrees if necessary
EbsdMap.transformData()
# Create the internal array of quaternions for orientation calculations
EbsdMap.buildQuatArray()
# Find boundaries with given misorientation tolerance (in degrees)
EbsdMap.findBoundaries(boundDef = 6)
# Find grains, minGrainSize is the minimum number of pixels for a grain
EbsdMap.findGrains(minGrainSize = 10)
# Calculate grain local misorientation (Grain Reference Orientation Deviation (GROD) w.r.t grain mean orientations)
EbsdMap.calcGrainMisOri(calcAxis = True)
EbsdMap.plotEulerMap()
EbsdMap.plotMisOriMap(plotGBs=True, vmin=0, vmax=4)
# Calculate grain mean orientations (but is already done here as part of calcGrainMisOri above)
# EbsdMap.calcGrainAvOris()
grainMeanOris = [grain.refOri for grain in EbsdMap]
refDir = np.array([1, 0, 0])
Quat.plotIPF(grainMeanOris, refDir, EbsdMap.crystalSym)
EbsdMap.locateGrainID()
currEbsdGrain = EbsdMap[EbsdMap.currGrainId]
currEbsdGrain.plotMisOri()
currEbsdGrain.plotMisOri(component=3)
plot = currEbsdGrain.plotOriSpread(direction=refDir, c='b', s=1, alpha=0.2)
currEbsdGrain.plotRefOri(direction=refDir, c='k', s=100, plot=plot)
EbsdMap.plotPhaseMap()
# Example of use of interactive tool coming soon...
# Set homologous points (x, y)
DicMap.homogPoints = np.array((
(303, 408), (120, 392), (275, 25)
))
EbsdMap.homogPoints = np.array((
(536, 776), (236, 790), (466, 160)
))
EbsdMap.plotBoundaryMap()
plt.scatter(x=EbsdMap.homogPoints[:, 0], y=EbsdMap.homogPoints[:, 1], c='y', s=60)
DicMap.plotMaxShear()
plt.scatter(x=DicMap.homogPoints[:, 0], y=DicMap.homogPoints[:, 1], c='y', s=60)
DicMap.linkEbsdMap(EbsdMap)
DicMap.plotMaxShear(plotGBs=True, plotColourBar=True, plotScaleBar=True, vmin=0, vmax=0.1)
DicMap.findGrains(minGrainSize=10)
DicMap.locateGrainID(displaySelected=True)
# displaySelected will show the selcted grain in a separate figure window
currDicGrain = DicMap[DicMap.currGrainId]
currDicGrain.plotMaxShear()
plt.figure()
plt.hist(currDicGrain.maxShearList, bins=100, histtype='step');
plt.xlabel("Effective shear strain")
plt.ylabel("Frequency")
ebsdGrainId = DicMap.ebsdGrainIds[DicMap.currGrainId]
currEbsdGrain = EbsdMap[ebsdGrainId]
currEbsdGrain.plotMisOri()
currDicGrain.calcSlipTraces()
currDicGrain.plotMaxShear(plotSlipTraces=True)