defdap.base module¶
- class defdap.base.Map(file_name, data_type=None, experiment=None, increment=None, frame=None, map_name=None)[source]¶
Bases:
ABC
Base class for a map. Contains common functionality for all maps.
- _grains¶
List of grains.
- Type:
list of defdap.base.Grain
- sel_grain¶
The last selected grain
- Type:
defdap.base.grain
- property grains¶
- property x_dim¶
- property y_dim¶
- plot_grain_numbers(dilate_boundaries=False, ax=None, **kwargs)[source]¶
Plot a map with grains numbered.
- Parameters:
dilate_boundaries (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.add_grain_numbers()
- Return type:
- locate_grain(click_event=None, display_grain=False, **kwargs)[source]¶
Interactive plot for identifying grains.
- click_grain_id(event, plot, display_grain)[source]¶
Event handler to capture clicking on a map.
- Parameters:
event – Click event.
plot (defdap.plotting.MapPlot) – Plot to capture clicks from.
display_grain (bool) – If true, plot the selected grain alone in pop-out window.
- draw_line_profile(**kwargs)[source]¶
Interactive plot for drawing a line profile of data.
- Parameters:
kwargs (dict, optional) – Keyword arguments passed to
defdap.base.Map.plot_default()
- calc_line_profile(plot, start_end, **kwargs)[source]¶
Calculate and plot the line profile.
- Parameters:
plot (defdap.plotting.MapPlot) – Plot to calculate the line profile for.
start_end (array_like) – Selected points (x0, y0, x1, y1).
kwargs (dict, optional) – Keyword arguments passed to
matplotlib.pyplot.plot()
- click_grain_neighbours(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:
- calc_proxigram(num_trials=500)[source]¶
Calculate distance from a grain boundary at each point in map.
- Parameters:
num_trials (int, optional) – number of trials.
- plot_map(map_name, component=None, **kwargs)[source]¶
Plot a map from the DIC data.
- Parameters:
map_name (str) – Map data name to plot i.e. e, max_shear, euler_angle, orientation.
component (int or tuple of int or str) – Component of the map data to plot. This is either the tensor component (int or tuple of ints) or the name of a calculation to be applied e.g. ‘norm’, ‘all_euler’ or ‘IPF_x’.
kwargs – All arguments are passed to
defdap.plotting.MapPlot.create()
.
- Returns:
Plot containing map.
- Return type:
- calc_grain_average(map_data, grain_ids=- 1)[source]¶
Calculate grain average of any DIC map data.
- Parameters:
map_data (numpy.ndarray) – Array of map data to grain average. This must be cropped!
grain_ids (list, optional) – grain_ids to perform operation on, set to -1 for all grains.
- Returns:
Array containing the grain average values.
- Return type:
- grain_data_to_map_data(grain_data, grain_ids=- 1, bg=0)[source]¶
Create a map array with each grain filled with the given values.
- Parameters:
grain_data (list or numpy.ndarray) – Grain values. This can be a single value per grain or RGB values.
grain_ids (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:
grain_map – Array filled with grain data values
- Return type:
- plot_grain_data_map(map_data=None, grain_data=None, grain_ids=- 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:
map_data (numpy.ndarray, optional) – Array of map data. This must be cropped! Either mapData or grain_data must be supplied.
grain_data (list or np.array, optional) – Grain values. This an be a single value per grain or RGB values. You must supply either mapData or grain_data.
grain_ids (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:
- plot_grain_data_ipf(direction, map_data=None, grain_data=None, grain_ids=- 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.
map_data (numpy.ndarray) – Array of map data. This must be cropped! Either mapData or grain_data must be supplied.
grain_data (list or np.array, optional) – Grain values. This an be a single value per grain or RGB values. You must supply either mapData or grain_data.
grain_ids (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.plot_ipf()
- class defdap.base.Grain(grain_id, owner_map, group_id)[source]¶
Bases:
ABC
Base class for a grain.
- owner_map¶
- Type:
- property extreme_coords¶
Coordinates of the bounding box for a grain.
- centre_coords(centre_type='box', grain_coords=True)[source]¶
Calculates the centre of the grain, either as the centre of the bounding box or the grains centre of mass.
- Parameters:
centre_type (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’.
grain_coords (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:
- grain_outline(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:
- plot_outline(ax=None, plot_scale_bar=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.
plot_scale_bar (bool) – plots the scale bar on the grain if true.
kwargs (dict) – keyword arguments passed to
defdap.plotting.GrainPlot.add_map()
- Return type:
- grain_data(map_data)[source]¶
Extract this grains data from the given map data.
- Parameters:
map_data (numpy.ndarray) – Array of map data. This must be cropped!
- Returns:
Array containing this grains values from the given map data.
- Return type:
- grain_map_data(map_data=None, grain_data=None, bg=nan)[source]¶
Extract a single grain map from the given map data.
- Parameters:
map_data (numpy.ndarray) – Array of map data. This must be cropped! Either this or ‘grain_data’ must be supplied and ‘grain_data’ takes precedence.
grain_data (numpy.ndarray) – Array of data at each point in the grain. Either this or ‘mapData’ must be supplied and ‘grain_data’ 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:
- grain_map_data_coarse(map_data=None, grain_data=None, kernel_size=2, bg=nan)[source]¶
Create a coarsened 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:
map_data (numpy.ndarray) – Array of map data. This must be cropped! Either this or ‘grain_data’ must be supplied and ‘grain_data’ takes precedence.
grain_data (numpy.ndarray) – List of data at each point in the grain. Either this or ‘mapData’ must be supplied and ‘grain_data’ takes precedence.
kernel_size (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:
- plot_grain_data(map_data=None, grain_data=None, **kwargs)[source]¶
Plot a map of this grain from the given map data.
- Parameters:
map_data (numpy.ndarray) – Array of map data. This must be cropped! Either this or ‘grain_data’ must be supplied and ‘grain_data’ takes precedence.
grain_data (numpy.ndarray) – List of data at each point in the grain. Either this or ‘mapData’ must be supplied and ‘grain_data’ takes precedence.
kwargs (dict, optional) – Keyword arguments passed to
defdap.plotting.GrainPlot.create()