defdap.base module

class defdap.base.Map[source]

Bases: object

Base class for a map. Contains common functionality for all maps.

grainList

List of grains.

Type:

list of defdap.base.Grain

currGrainId

ID of last selected grain.

Type:

int

property shape
checkGrainsDetected(raiseExc=True)[source]

Check if grains have been detected.

Parameters:

raiseExc (bool) – If True then an expception is raised if grains have not been detected.

Returns:

True if grains detected, False otherwise.

Return type:

bool

Raises:

Exception – If grains not detected.

plotGrainNumbers(dilateBoundaries=False, ax=None, **kwargs)[source]

Plot a map with grains numbered.

Parameters:
Return type:

defdap.plotting.MapPlot

locateGrainID(clickEvent=None, displaySelected=False, **kwargs)[source]

Interactive plot for identifying grains.

Parameters:
  • clickEvent (optional) – Click handler to use.

  • displaySelected (bool, optional) – If true, plot slip traces for grain selected by click.

  • kwargs (dict, optional) – Keyword arguments passed to defdap.base.Map.plotDefault()

clickGrainID(event, plot, displaySelected)[source]

Event handler to capture clicking on a map.

Parameters:
  • event – Click event.

  • plot (defdap.plotting.MapPlot) – Plot to capture clicks from.

  • displaySelected (bool) – If true, plot the selected grain alone in pop-out window.

drawLineProfile(**kwargs)[source]

Interactive plot for drawing a line profile of data.

Parameters:

kwargs (dict, optional) – Keyword arguments passed to defdap.base.Map.plotDefault()

calcLineProfile(plot, startEnd, **kwargs)[source]

Calculate and plot the line profile.

Parameters:
setHomogPoint(binSize=1, points=None, **kwargs)[source]

Interactive tool to set homologous points. Right-click on a point then click ‘save point’ to append to the homologous points list.

Parameters:
  • binSize (int, optional) – Binning applied to image, if applicable.

  • points (numpy.ndarray, optional) – Array of (x,y) homologous points to set explicitly.

  • kwargs (dict, optional) – Keyword arguments passed to defdap.base.Map.plotHomog()

clickHomog(event, plot)[source]

Event handler for capturing position when clicking on a map.

Parameters:
keyHomog(event, plot)[source]

Event handler for moving position using keyboard after clicking on a map.

Parameters:
clickSaveHomog(event, plot, binSize)[source]

Append the selected point on the map to homogPoints.

Parameters:
  • event – Button click event.

  • plot (defdap.plotting.MapPlot) – Plot to monitor.

  • binSize (int, optional) – Binning applied to image, if applicable.

updateHomogPoint(homogID, newPoint=None, delta=None)[source]

Update a homog point by either over writing it with a new point or incrementing the current values.

Parameters:
  • homogID (int) – ID (place in list) of point to update or -1 for all.

  • newPoint (tuple, optional) – (x, y) coordinates of new point.

  • delta (tuple, optional) – Increments to current point (dx, dy).

buildNeighbourNetwork()[source]

Construct a list of neighbours

displayNeighbours(**kwargs)[source]
clickGrainNeighbours(event, plot)[source]

Event handler to capture clicking and show neighbours of selected grain.

Parameters:
property proxigram

Proxigram for a map.

Returns:

Distance from a grain boundary at each point in map.

Return type:

numpy.ndarray

calcProxigram(numTrials=500, forceCalc=True)[source]

Calculate distance from a grain boundary at each point in map.

Parameters:
  • numTrials (int, optional) – number of trials.

  • forceCalc (bool, optional) – Force calculation even is proxigramArr is populated.

calcGrainAv(mapData, grainIds=- 1)[source]

Calculate grain average of any DIC map data.

Parameters:
  • mapData (numpy.ndarray) – Array of map data to grain average. This must be cropped!

  • grainIds (list, optional) – grainIDs to perform operation on, set to -1 for all grains.

Returns:

Array containing the grain average values.

Return type:

numpy.ndarray

grainDataToMapData(grainData, grainIds=- 1, bg=0)[source]

Create a map array with each grain filled with the given values.

Parameters:
  • grainData (list or numpy.ndarray) – Grain values. This can be a single value per grain or RGB values.

  • grainIds (list of int or int, optional) – IDs of grains to plot for. Use -1 for all grains in the map.

  • bg (int or real, optional) – Value to fill the background with.

Returns:

grainMap – Array filled with grain data values

Return type:

numpy.ndarray

plotGrainDataMap(mapData=None, grainData=None, grainIds=- 1, bg=0, **kwargs)[source]

Plot a grain map with grains coloured by given data. The data can be provided as a list of values per grain or as a map which a grain average will be applied.

Parameters:
  • mapData (numpy.ndarray, optional) – Array of map data. This must be cropped! Either mapData or grainData must be supplied.

  • grainData (list or np.array, optional) – Grain values. This an be a single value per grain or RGB values. You must supply either mapData or grainData.

  • grainIds (list of int or int, optional) – IDs of grains to plot for. Use -1 for all grains in the map.

  • bg (int or real, optional) – Value to fill the background with.

  • kwargs (dict, optional) – Keyword arguments passed to defdap.plotting.MapPlot.create()

Returns:

plot – Plot object created

Return type:

defdap.plotting.MapPlot

plotGrainDataIPF(direction, mapData=None, grainData=None, grainIds=- 1, **kwargs)[source]

Plot IPF of grain reference (average) orientations with points coloured by grain average values from map data.

Parameters:
  • direction (numpy.ndarray) – Vector of reference direction for the IPF.

  • mapData (numpy.ndarray) – Array of map data. This must be cropped! Either mapData or grainData must be supplied.

  • grainData (list or np.array, optional) – Grain values. This an be a single value per grain or RGB values. You must supply either mapData or grainData.

  • grainIds (list of int or int, optional) – IDs of grains to plot for. Use -1 for all grains in the map.

  • kwargs (dict, optional) – Keyword arguments passed to defdap.quat.Quat.plotIPF()

class defdap.base.Grain(grainID, ownerMap)[source]

Bases: object

Base class for a grain.

grainID
Type:

int

ownerMap
Type:

defdap.base.Map

coordList
Type:

list of tuples

property extremeCoords

Coordinates of the bounding box for a grain.

Returns:

minimum x, minimum y, maximum x, maximum y.

Return type:

int, int, int, int

centreCoords(centreType='box', grainCoords=True)[source]

Calculates the centre of the grain, either as the centre of the bounding box or the grains centre of mass.

Parameters:
  • centreType (str, optional, {'box', 'com'}) – Set how to calculate the centre. Either ‘box’ for centre of bounding box or ‘com’ for centre of mass. Default is ‘box’.

  • grainCoords (bool, optional) – If set True the centre is returned in the grain coordinates otherwise in the map coordinates. Defaults is grain.

Returns:

Coordinates of centre of grain.

Return type:

int, int

grainOutline(bg=nan, fg=0)[source]

Generate an array of the grain outline.

Parameters:
  • bg (int) – Value for points not within grain.

  • fg (int) – Value for points within grain.

Returns:

Bounding box for grain with nan outside the grain and given number within.

Return type:

numpy.ndarray

plotOutline(ax=None, plotScaleBar=False, **kwargs)[source]

Plot the outline of the grain.

Parameters:
Return type:

defdap.plotting.GrainPlot

grainData(mapData)[source]

Extract this grains data from the given map data.

Parameters:

mapData (numpy.ndarray) – Array of map data. This must be cropped!

Returns:

Array containing this grains values from the given map data.

Return type:

numpy.ndarray

grainMapData(mapData=None, grainData=None, bg=nan)[source]

Extract a single grain map from the given map data.

Parameters:
  • mapData (numpy.ndarray) – Array of map data. This must be cropped! Either this or ‘grainData’ must be supplied and ‘grainData’ takes precedence.

  • grainData (numpy.ndarray) – Array of data at each point in the grain. Either this or ‘mapData’ must be supplied and ‘grainData’ takes precedence.

  • bg (various, optional) – Value to fill the background with. Must be same dtype as input array.

Returns:

Grain map extracted from given data.

Return type:

numpy.ndarray

grainMapDataCoarse(mapData=None, grainData=None, kernelSize=2, bg=nan)[source]

Create a coarsed data map of this grain only from the given map data. Data is coarsened using a kernel at each pixel in the grain using only data in this grain.

Parameters:
  • mapData (numpy.ndarray) – Array of map data. This must be cropped! Either this or ‘grainData’ must be supplied and ‘grainData’ takes precedence.

  • grainData (numpy.ndarray) – List of data at each point in the grain. Either this or ‘mapData’ must be supplied and ‘grainData’ takes precedence.

  • kernelSize (int, optional) – Size of kernel as the number of pixels to dilate by i.e 1 gives a 3x3 kernel.

  • bg (various, optional) – Value to fill the background with. Must be same dtype as input array.

Returns:

Map of this grains coarsened data.

Return type:

numpy.ndarray

plotGrainData(mapData=None, grainData=None, **kwargs)[source]

Plot a map of this grain from the given map data.

Parameters:
  • mapData (numpy.ndarray) – Array of map data. This must be cropped! Either this or ‘grainData’ must be supplied and ‘grainData’ takes precedence.

  • grainData (numpy.ndarray) – List of data at each point in the grain. Either this or ‘mapData’ must be supplied and ‘grainData’ takes precedence.

  • kwargs (dict, optional) – Keyword arguments passed to defdap.plotting.GrainPlot.create()