defdap.hrdic module

class defdap.hrdic.Map(path, fname, dataType=None)[source]

Bases: Map

Class to encapsulate DIC map data and useful analysis and plotting methods.

format

Software name.

Type:

str

version

Software version.

Type:

str

binning

Sub-window size in pixels.

Type:

int

xdim

Size of map along x (from header).

Type:

int

ydim

Size of map along y (from header).

Type:

int

xc

X coordinates.

Type:

numpy.ndarray

yc

Y coordinates.

Type:

numpy.ndarray

xd

X displacement.

Type:

numpy.ndarray

yd

Y displacement.

Type:

numpy.ndarray

corrVal

Correlation value.

Type:

numpy.ndarray

ebsdMap

EBSD map linked to DIC map.

Type:

defdap.ebsd.Map

ebsdTransform

Transform from EBSD to DIC coordinates.

Type:

various

ebsdTransformInv

Transform from DIC to EBSD coordinates.

Type:

various

ebsdGrainIds

EBSD grain IDs corresponding to DIC map grain IDs.

Type:

list

patternImPath

Path to BSE image of map.

Type:

str

plotHomog

Map to use for defining homologous points (defaults to plotMaxShear).

highlightAlpha

Alpha (transparency) of grain highlight.

Type:

float

bseScale

Size of a pixel in the correlated images.

Type:

float

patScale

Size of pixel in loaded pattern relative to pixel size of dic data i.e 1 means they are the same size and 2 means the pixels in the pattern are half the size of the dic data.

Type:

float

path

File path.

Type:

str

fname

File name.

Type:

str

xDim

Size of map along x (after cropping).

Type:

int

yDim

Size of map along y (after cropping).

Type:

int

self.x_map

Map of u displacement component along x.

Type:

numpy.ndarray

self.y_map

Map of v displacement component along x.

Type:

numpy.ndarray

f11, f22, f12, f21 ; numpy.ndarray

Components of the deformation gradient, where 1=x and 2=y.

e11, e22, e12

Components of the green strain , where 1=x and 2=y.

Type:

numpy.ndarray

eMaxShear

Max shear component np.sqrt(((e11 - e22) / 2.)**2 + e12**2).

Type:

numpy.ndarray

cropDists

Crop distances (default all zeros).

Type:

numpy.ndarray

property crystalSym
loadData(fileDir, fileName, dataType=None)[source]

Load DIC data from file.

Parameters:
  • fileDir (str) – Path to file.

  • fileName (str) – Name of file including extension.

  • dataType (str, {'DavisText'}) – Type of data file.

loadCorrValData(fileDir, fileName, dataType=None)[source]

Load correlation value for DIC data

Parameters:
  • fileDir (str) – Path to file.

  • fileName (str) – Name of file including extension.

  • dataType (str, {'DavisImage'}) – Type of data file.

retrieveName()[source]

Gets the first name assigned to the a map, as a string

setScale(micrometrePerPixel)[source]

Sets the scale of the map.

Parameters:

micrometrePerPixel (float) – Length of pixel in original BSE image in micrometres.

property scale

Returns the number of micrometers per pixel in the DIC map.

printStatsTable(percentiles, components)[source]

Print out a statistics table for a DIC map

Parameters:
  • percentiles (list(float)) – list of percentiles to print i.e. 0, 50, 99.

  • components (list(str)) – list of map components to print i.e. e11, f11, eMaxShear, x_map.

setCrop(xMin=None, xMax=None, yMin=None, yMax=None, updateHomogPoints=False)[source]

Set a crop for the DIC map.

Parameters:
  • xMin (int) – Distance to crop from left in pixels.

  • xMax (int) – Distance to crop from right in pixels.

  • yMin (int) – Distance to crop from top in pixels.

  • yMax (int) – Distance to crop from bottom in pixels.

  • updateHomogPoints (bool, optional) – If true, change homologous points to reflect crop.

crop(mapData, binned=True)[source]

Crop given data using crop parameters stored in map i.e. cropped_data = DicMap.crop(DicMap.data_to_crop).

Parameters:
  • mapData (numpy.ndarray) – Bap data to crop.

  • binned (bool) – True if mapData is binned i.e. binned BSE pattern.

setHomogPoint(points=None, display=None, **kwargs)[source]

Set homologous points. Uses interactive GUI if points is None.

Parameters:
  • points (list, optional) – homologous points to set.

  • display (string, optional) – Use max shear map if set to ‘maxshear’ or pattern if set to ‘pattern’.

linkEbsdMap(ebsdMap, transformType='affine', **kwargs)[source]

Calculates the transformation required to align EBSD dataset to DIC.

Parameters:
  • ebsdMap (defdap.ebsd.Map) – EBSD map object to link.

  • transformType (str, optional) – affine, piecewiseAffine or polynomial.

  • kwargs – All arguments are passed to estimate method of the transform.

checkEbsdLinked()[source]

Check if an EBSD map has been linked.

Returns:

Returns True if EBSD map linked.

Return type:

bool

Raises:

Exception – If EBSD map not linked.

warpToDicFrame(mapData, cropImage=True, order=1, preserve_range=False)[source]

Warps a map to the DIC frame.

Parameters:
  • mapData (numpy.ndarray) – Data to warp.

  • cropImage (bool, optional) – Crop to size of DIC map if true.

  • order (int, optional) – Order of interpolation (0: Nearest-neighbor, 1: Bi-linear…).

  • preserve_range (bool, optional) – Keep the original range of values.

Returns:

Map (i.e. EBSD map data) warped to the DIC frame.

Return type:

numpy.ndarray

warp_lines_to_dic_frame(lines)[source]

Warp a set of lines to the DIC reference frame.

Parameters:

lines (list of tuples) – Lines to warp. Each line is represented as a tuple of start and end coordinates (x, y).

Returns:

List of warped lines with same representation as input.

Return type:

list of tuples

property boundaries

Returns EBSD map grain boundaries warped to DIC frame.

property boundaryLines
property phaseBoundaryLines
generateThresholdMask(mask, dilation=0, preview=True)[source]

Generate a dilated mask, based on a boolean array and previews the appication of this mask to the max shear map.

Parameters:
  • mask (numpy.array(bool)) – A boolean array where points to be removed are True

  • dilation (int, optional) – Number of pixels to dilate the mask by. Useful to remove anomalous points around masked values. No dilation applied if not specified.

  • preview (bool) – If true, show the mask and preview the masked effective shear strain map.

Examples

To remove data points in dicMap where eMaxShear is above 0.8, use:

>>> mask = dicMap.eMaxShear > 0.8

To remove data points in dicMap where e11 is above 1 or less than -1, use:

>>> mask = (dicMap.e11 > 1) | (dicMap.e11 < -1)

To remove data points in dicMap where corrVal is less than 0.4, use:

>>> mask = dicMap.corrVal < 0.4

Note: correlation value data needs to be loaded seperately from the DIC map, see defdap.hrdic.loadCorrValData()

applyThresholdMask()[source]

Apply mask to all DIC map data by setting masked values to nan.

setPatternPath(filePath, windowSize)[source]

Set the path to the image of the pattern.

Parameters:
  • filePath (str) – Path to image.

  • windowSize (float) – Size of pixel in pattern image relative to pixel size of DIC data i.e 1 means they are the same size and 2 means the pixels in the pattern are half the size of the dic data.

plotPattern(**kwargs)[source]

Plot BSE image of Map. For use with setting homog points.

Parameters:

kwargs – All arguments are passed to defdap.plotting.MapPlot.create().

Return type:

defdap.plotting.MapPlot

plotMap(component, **kwargs)[source]

Plot a map from the DIC data.

Parameters:
Returns:

Plot containing map.

Return type:

defdap.plotting.MapPlot

plotMaxShear(**kwargs)[source]

Plot a map of maximum shear strain.

Parameters:

kwargs – All arguments are passed to defdap.hrdic.plotMap().

Returns:

Plot containing map.

Return type:

defdap.plotting.MapPlot

plotGrainAvMaxShear(**kwargs)[source]

Plot grain map with grains filled with average value of max shear. This uses the max shear values stored in grain objects, to plot other data use plotGrainAv().

Parameters:

kwargs – All arguments are passed to defdap.base.Map.plotGrainDataMap().

findGrains(algorithm=None, minGrainSize=10)[source]

Finds grains in the DIC map.

Parameters:
  • algorithm (str {'warp', 'floodfill'}) – Use floodfill or warp algorithm.

  • minGrainSize (int) – Minimum grain area in pixels for floodfill algorithm.

floodFill(x, y, grainIndex, points_left)[source]

Flood fill algorithm that uses the combined x and y boundary array 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:
  • x (int) – Seed point x for flood fill

  • y (int) – Seed point y for flood fill

  • grainIndex (int) – Value to fill in grain map

  • points_left (numpy.ndarray) – Boolean map of the points that have not been assigned a grain yet

Returns:

currentGrain – New grain object with points added

Return type:

defdap.hrdic.Grain

runGrainInspector(vmax=0.1, corrAngle=0)[source]

Run the grain inspector interactive tool.

Parameters:
  • vmax (float) – Maximum value of the colour map.

  • corrAngle (float) – Correction angle in degrees to subtract from measured angles to account for small rotation between DIC and EBSD frames. Approximately the rotation component of affine transform.

class defdap.hrdic.Grain(grainID, dicMap)[source]

Bases: Grain

Class to encapsulate DIC grain data and useful analysis and plotting methods.

dicMap

DIC map this grain is a member of

Type:

defdap.hrdic.Map

ownerMap

DIC map this grain is a member of

Type:

defdap.hrdic.Map

maxShearList

List of maximum shear values for grain.

Type:

list

ebsdGrain

EBSD grain ID that this DIC grain corresponds to.

Type:

defdap.ebsd.Grain

ebsdMap

EBSD map that this DIC grain belongs to.

Type:

defdap.ebsd.Map

pointsList

Start and end points for lines drawn using defdap.inspector.GrainInspector.

Type:

numpy.ndarray

groupsList

Groups, angles and slip systems detected for lines drawn using defdap.inspector.GrainInspector.

property plotDefault
addPoint(coord, maxShear)[source]
plotMaxShear(**kwargs)[source]

Plot a maximum shear map for a grain.

Parameters:

kwargs – All arguments are passed to defdap.base.plotGrainData().

Return type:

defdap.plotting.GrainPlot

property refOri

Returns average grain orientation.

Return type:

defdap.quat.Quat

property slipTraces

Returns list of slip trace angles based on EBSD grain orientation.

Return type:

list

calcSlipTraces(slipSystems=None)[source]

Calculates list of slip trace angles based on EBSD grain orientation.

Parameters:

slipSystems (defdap.crystal.SlipSystem, optional) –

calcSlipBands(grainMapData, thres=None, min_dist=None)[source]

Use Radon transform to detect slip band angles.

Parameters:
  • grainMapData (numpy.ndarray) – Data to find bands in.

  • thres (float, optional) – Normalised threshold for peaks.

  • min_dist (int, optional) – Minimum angle between bands.

Returns:

Detected slip band angles

Return type:

list(float)