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
- property shape¶
- plotGrainNumbers(dilateBoundaries=False, ax=None, **kwargs)[source]¶
Plot a map with grains numbered.
- Parameters:
dilateBoundaries (bool, optional) – Set to true to dilate boundaries.
ax (matplotlib.axes.Axes, optional) – axis to plot on, if not provided the current active axis is used.
kwargs (dict, optional) – Keyword arguments passed to
defdap.plotting.MapPlot.addGrainNumbers()
- Return type:
- locateGrainID(clickEvent=None, displaySelected=False, **kwargs)[source]¶
Interactive plot for identifying grains.
- 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:
plot (defdap.plotting.MapPlot) – Plot to calculate the line profile for.
startEnd (array_like) – Selected points (x0, y0, x1, y1).
kwargs (dict, optional) – Keyword arguments passed to
matplotlib.pyplot.plot()
- 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:
event – Click event.
plot (defdap.plotting.MapPlot) – Plot to monitor.
- keyHomog(event, plot)[source]¶
Event handler for moving position using keyboard after clicking on a map.
- Parameters:
event – Keypress event.
plot (defdap.plotting.MapPlot) – Plot to monitor.
- 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.
- clickGrainNeighbours(event, plot)[source]¶
Event handler to capture clicking and show neighbours of selected grain.
- Parameters:
event – Click event.
plot (defdap.plotting.MapPlot) – Plot to monitor.
- property proxigram¶
Proxigram for a map.
- Returns:
Distance from a grain boundary at each point in map.
- Return type:
- calcProxigram(numTrials=500, forceCalc=True)[source]¶
Calculate distance from a grain boundary at each point in map.
- 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:
- 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:
- 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:
- 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.
- ownerMap¶
- Type:
- coordList¶
- Type:
list of tuples
- property extremeCoords¶
Coordinates of the bounding box for a grain.
- 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:
- grainOutline(bg=nan, fg=0)[source]¶
Generate an array of the grain outline.
- Parameters:
- Returns:
Bounding box for grain with
nan
outside the grain and given number within.- Return type:
- plotOutline(ax=None, plotScaleBar=False, **kwargs)[source]¶
Plot the outline of the grain.
- Parameters:
ax (matplotlib.axes.Axes) – axis to plot on, if not provided the current active axis is used.
plotScaleBar (bool) – plots the scale bar on the grain if true.
kwargs (dict) – keyword arguments passed to
defdap.plotting.GrainPlot.addMap()
- Return type:
- 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:
- 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:
- 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:
- 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()