Reference¶
This is the reference for the classes and functions defined in the phasemap
module.
-
phasemap.
run
(fct, limits, mesh=5, num_steps=5, all_corners=False, init_result=None, save_file=None, load=False, load_quiet=True, serializer='auto', save_interval=5.0)[source]¶ Run the PhaseMap algorithm.
Create an initial set of boxes, and then recursively split boxes of undefined phase until they reach a given minimum size.
- Parameters
fct – The function which evaluates the phase at a given point. Can be either a synchronous or asynchronous (async def) function.
limits – Boundaries of the region where the phase diagram is evaluated.
mesh – Size of the initial grid, either as an integer, or a list of integers (one for each dimension).
num_steps (int) – The maximum number of times each box is split.
all_corners (bool) – Determines whether all corners of a box should be calculated, or only the vertices and middle point of the parent box.
init_result (Result) – Input result, which is used to cache function evaluations.
save_file (str) – Path of the file where the intermediate results should be stored. A format string can also be passed, and will be formatted with an incrementing index.
load (bool) – Determines whether the initial result is loaded from the
save_file
.load_quiet (bool) – Determines if the error is suppressed when the initial result cannot be loaded from the
save_file
.serializer (module) – Serializer used to save and load the result.
save_interval (float) – Minimum time between saving the result.
- Returns
Contains the resulting boxes and points, and the given ‘limits’.
- Return type
Plotting Results¶
This module contains functions for plotting the phase diagram. The functions are based upon the matplotlib
package.
-
phasemap.plot.
boxes
(result, *, ax=None, scale_val=None, plot_undefined=False, cmap=None, **kwargs)[source]¶ Plots the phase diagram as a collection of boxes, which are colored according to the estimate of the phase in a given box.
- Parameters
result (Result) – Result of the
run()
phase diagram calculation.ax (
matplotlib
ax) – Axes where the plot is drawn.add_cbar (bool) – Determines whether a colorbar is added to the figure.
scale_val (list) – Values to which the colormap is scaled. By default, the colormap is scaled to the set of values which occur in the boxes.
plot_undefined (bool) – Specifies whether the boxes of undefined phase should be plotted (in white).
cmap – The colormap which is used to plot the phases. The colormap should take values normalized to [0, 1] and return a 4-tuple specifying the RGBA value (again normalized to [0, 1].
kwargs – Keyword arguments passed to
matplotlib.patches.Rectangle
.
-
phasemap.plot.
points
(result, *, ax=None, scale_val=None, cmap=None, **kwargs)[source]¶ Plots the phase diagram as a collection of boxes, which are colored according to the estimate of the phase in a given box.
- Parameters
result (Result) – Result of the
run()
phase diagram calculation.ax (
matplotlib
ax) – Axes where the plot is drawn.add_cbar (bool) – Determines whether a colorbar is added to the figure.
scale_val (list) – Values to which the colormap is scaled. By default, the colormap is scaled to the set of values which occur in the boxes.
cmap – The colormap which is used to plot the phases. The colormap should take values normalized to [0, 1] and return a 4-tuple specifying the RGBA value (again normalized to [0, 1].
kwargs – Keyword arguments passed to
scatter
.
Saving and Loading Results¶
This module contains functions for saving and loading PhaseMap objects.
-
phasemap.io.
save
(obj, file_path, serializer='auto')¶ Saves an object to the file given in
file_path
. The saving is made atomic (on systems whereos.replace()
is atomic) by first creating a temporary file and then moving to thefile_path
.
-
phasemap.io.
load
(file_path, serializer='auto')¶ Loads the object that was saved to
file_path
.- Parameters
file_path (str) – Path to the file.
serializer (module) – The serializer which should be used to load the result. By default, is deduced from the file extension. If no serializer is given and it cannot be deduced from the file ending, a
ValueError
is raised, to avoid loading corrupted data.
-
phasemap.io.
load
(file_path, serializer='auto')¶ Loads the object that was saved to
file_path
.- Parameters
file_path (str) – Path to the file.
serializer (module) – The serializer which should be used to load the result. By default, is deduced from the file extension. If no serializer is given and it cannot be deduced from the file ending, a
ValueError
is raised, to avoid loading corrupted data.
-
phasemap.io.
save
(obj, file_path, serializer='auto')¶ Saves an object to the file given in
file_path
. The saving is made atomic (on systems whereos.replace()
is atomic) by first creating a temporary file and then moving to thefile_path
.
Data classes¶
-
class
phasemap._result.
Result
(*, points, boxes, limits)[source]¶ Container class for the result of a
run()
calculation. Contains the boxes, points and limits of the calculation.
-
class
phasemap._box.
Box
(*, corner, size)[source]¶ Class describing a “box” (or n-dimensional hyperrectangle).
-
corner
¶ The vertex with the lowest indices.
- Type
-
size
¶ Size of the box.
- Type
-
phase
¶ The phase of the box, determined by the evaluated points it contains: If all points have the same phase, the box will have that phase. Otherwise, the phase of the box is undefined.
-