drawing#
Import: ad_hoc_diffractometer.drawing
Provides interactive Plotly figures for diffractometer geometry diagrams:
StageAxisFigure3D interactive diagram for a single stage rotation axis.
GeometryAxisFigureComposite diagram showing all stages of a geometry arranged in a directed-graph layout with parent-child relationships.
These are the preferred output for documentation; pre-generate them
with tools/generate_geometry_drawings.py and embed the resulting
HTML files as <iframe> elements in the Sphinx pages.
Plotly is an optional dependency. Both classes raise
ImportError with a helpful message if it is not installed.
Classes#
Interactive Plotly figure showing all stages of a geometry. |
|
Interactive Plotly figure for a single stage rotation-axis diagram. |
Functions#
|
Return a human-readable axis label with physical direction if possible. |
Import and return plotly.graph_objects, or raise ImportError. |
|
|
Paper-coordinate domain for a scene at grid position (col, row). |
|
Compute bottom-to-top tree layout positions for a stage dict. |
Module Contents#
- class ad_hoc_diffractometer.drawing.GeometryAxisFigure(geometry_name: str, axis_labels: bool = True, **kwargs)[source]#
Import:
ad_hoc_diffractometer.drawing.GeometryAxisFigureInteractive Plotly figure showing all stages of a geometry.
Stages are arranged as a directed graph following parent relationships. The graph flows bottom-to-top: root stages (
parent=None) are at the bottom; each child is one row above its parent. Leaf nodes are assigned integer column slots; parents are centered over their children.Role is indicated by scene background color:
sample → aliceblue
detector → seashell
other → honeydew
Parent-child relationships are drawn as arrows on the figure.
- Parameters:
Examples
>>> from ad_hoc_diffractometer.drawing import GeometryAxisFigure >>> fig = GeometryAxisFigure("fourcv") >>> fig.write_html("fourcv.html")
- property data#
Plotly traces (delegated to the internal Figure).
- property layout#
Plotly layout (delegated to the internal Figure).
- write_html(path, **kwargs)[source]#
Write the figure to an HTML file.
- Parameters:
path (str or pathlib.Path)
**kwargs – Forwarded to
plotly.graph_objects.Figure.write_html().
- write_image(path, **kwargs)[source]#
Write the figure to a static image file (SVG, PNG, etc.).
- Parameters:
path (str or pathlib.Path)
**kwargs – Forwarded to
plotly.graph_objects.Figure.write_image().
- class ad_hoc_diffractometer.drawing.StageAxisFigure(geometry_name: str, axis_name: str, axis_labels: bool = False, **kwargs)[source]#
Import:
ad_hoc_diffractometer.drawing.StageAxisFigureInteractive Plotly figure for a single stage rotation-axis diagram.
Draws the geometry’s basis vectors (grey, semi-transparent) and the stage’s rotation axis (red) with a direction arc, in a 3-D interactive Plotly scene.
- Parameters:
Examples
>>> from ad_hoc_diffractometer.drawing import StageAxisFigure >>> fig = StageAxisFigure("fourcv", "omega") >>> fig.write_html("omega.html")
- R = None#
- _draw_axis_arc(axis_norm: ndarray, direction: int = 1) None[source]#
Draw the rotation arc and arrowhead.
- _draw_axis_vector() ndarray[source]#
Draw the rotation axis as a red line; return positive unit vector.
- _draw_basis_vectors(axis_labels: bool = False) None[source]#
Draw basis vectors as lines with cone tips.
- property data#
Plotly traces (delegated to the internal Figure).
- geometry#
- property layout#
Plotly layout (delegated to the internal Figure).
- stage#
- write_html(path, **kwargs)[source]#
Write the figure to an HTML file.
- Parameters:
path (str or pathlib.Path)
**kwargs – Forwarded to
plotly.graph_objects.Figure.write_html().
- write_image(path, **kwargs)[source]#
Write the figure to a static image file (SVG, PNG, etc.).
- Parameters:
path (str or pathlib.Path)
**kwargs – Forwarded to
plotly.graph_objects.Figure.write_image().
- ad_hoc_diffractometer.drawing._physical_label(axis_vec: ndarray, basis: dict | None) str[source]#
Import:
ad_hoc_diffractometer.drawing._physical_labelReturn a human-readable axis label with physical direction if possible.
For standard signed basis vectors, returns e.g.
"-transverse"or"+vertical". For tilted axes (kappa), returns the numeric label.
- ad_hoc_diffractometer.drawing._require_plotly()[source]#
Import:
ad_hoc_diffractometer.drawing._require_plotlyImport and return plotly.graph_objects, or raise ImportError.
- ad_hoc_diffractometer.drawing._scene_domain(col, row, n_cols, n_rows, title_frac)[source]#
Import:
ad_hoc_diffractometer.drawing._scene_domainPaper-coordinate domain for a scene at grid position (col, row).
row=0 is the bottom (roots); row=n_rows-1 is the top (deepest leaves). title_frac is the fraction of each row height reserved for the title. Returns (x_domain, y_domain) as two [lo, hi] lists.
- ad_hoc_diffractometer.drawing._tree_layout(stages)[source]#
Import:
ad_hoc_diffractometer.drawing._tree_layoutCompute bottom-to-top tree layout positions for a stage dict.
- Returns:
depth (dict stage_name -> int) – 0 for roots (bottom), increasing toward leaves (top).
x_pos (dict stage_name -> float) – Leaf nodes get integer slots 0, 1, 2, … Parent nodes are centered over their children (may be half-integer).
children (dict stage_name -> list[str])
roots (list[str])