hertzforge.drawing.plot¶
plot
¶
Drawing decisions for plots: what a figure needs to know, with none of the code that draws it.
Functions:
| Name | Description |
|---|---|
axis_label |
Axis label for a dimension, or a note when units are undefined. |
pair_label |
How a DOF pair is written in a label. |
cmif_curves |
The CMIF's singular values (k, frequencies) and display abscissa. |
display_factor |
The factor that converts one curve's SI values to displayed ones. |
drawing_shape |
How this object's curve is drawn: 'steps', 'law' or 'line'. |
step_outline |
The flat-across-each-bin trace as explicit points. |
bin_edges |
The edges of the bins that a set of line centers represents. |
as_power_law |
A breakpoint curve resampled densely enough to draw as a curve. |
zone_key |
The legend entries for a specification's shading. |
Classes¶
Functions:¶
axis_label
¶
axis_label(dimension: str, unit_system: UnitSystem, hint: str | None = None) -> str
Axis label for a dimension, or a note when units are undefined.
The unit is written as HTML, which pyqtgraph renders, so a quotient dimension is shown as a stacked fraction and not as '(in/s**2)/lbf'.
A hint is the quantity the source named without giving its units.
The label includes it, as in 'acceleration [units undefined]',
because that is more useful than an axis with no name at all.
pair_label
¶
How a DOF pair is written in a label.
The DOF alone when it is its own reference, otherwise 'response/reference'.
cmif_curves
¶
cmif_curves(data: Any, records: Sequence[int] | None = None, unit_system: UnitSystem | None = None) -> tuple[ndarray, ndarray]
The CMIF's singular values (k, frequencies) and display abscissa.
The records are assembled into the response-by-reference matrix they belong to, with a missing pair set to zero (the usual practical treatment of an incomplete matrix), and a singular value decomposition is taken at every frequency line. The largest singular value peaks at every mode. A second singular value peaking at the same frequency indicates a repeated root. A line holding an entry that is not a finite number has no decomposition, and its singular values are NaN, as the conditioning reading leaves such a line unjudged.
display_factor
¶
The factor that converts one curve's SI values to displayed ones.
A unit conversion is one factor, so it is read from the first point where both values are finite and the SI value is positive. Returns 1 when there is no such point. The plot and the report page both scale a compliance verdict's level by it.
drawing_shape
¶
How this object's curve is drawn: 'steps', 'law' or 'line'.
The rule, for the 2-D plot and the 3-D waterfall alike, is that a
density is drawn so that its RMS is the area under the curve on
screen. A PSD, a CPSD's terms and an octave-band PSD (interpolation
== 'bin') are drawn flat across each bin ('steps'), which is what
is summed when the object is integrated, and a specification
(interpolation == 'log_log') follows the power law between its
breakpoints ('law'). Anything that is a value at a frequency and not
an area, such as an FRF, a coherence, a linear spectrum or any
signed component, is drawn as a line ('line'). The exception is a
value that belongs to a whole band, which is drawn flat across the
band whatever component is read: a banded coherence, or the phase of
a banded cross term, is one number for its band and not a sample at
its center. Data that is not on a frequency axis is always a line.
There is one implementation, used by build_plots and by
viz.waterfall, because a curve that disagrees with Psd.area()
shows a number nobody computed. tagged says a signed component
(real, imag or phase) is being drawn, which is never a density,
though for a banded array it is still a band's value.
step_outline
¶
step_outline(centers: ArrayLike, values: ArrayLike, widths: ArrayLike | None = None) -> tuple[ndarray, ndarray]
The flat-across-each-bin trace as explicit points.
This is what stepMode='center' has pyqtgraph draw in the 2-D plot,
written out for a renderer that only takes polylines, the 3-D
waterfall. There are two points per bin, on the bin's edges (from
bin_edges), with the value repeated, so the area under the trace
is exactly sum(value * width) and the RMS is the area drawn.
values may be (records, lines), in which case each row is
outlined. Returns (x, values).
bin_edges
¶
The edges of the bins that a set of line centers represents.
A line of a discrete spectrum is a density over its own bin, so with no other information each bin runs to the midpoint of the gap on either side, and the outer edges are as far beyond the end lines as the nearest midpoints are inside them. Arithmetic midpoints are used because FFT lines are evenly spaced in frequency.
widths is for a spectrum that knows its bins. One more value than
there are centers is taken as the edges themselves
(Psd.bin_edges). Otherwise widths is each band's width. An
octave band's center is the geometric mean of its edges, so neither
the midpoints between neighbors nor the center plus and minus half a
width gives them. From the center and the width the edges follow
exactly: with c = sqrt(l u) and w = u - l,
u = (w + sqrt(w^2 + 4 c^2)) / 2, l = u - w
which is the positive root and does not assume the bands tile. These bands do tile, so one array of edges serves them all.
as_power_law
¶
as_power_law(frequencies: ArrayLike, values: ArrayLike, per_decade: int = POWER_LAW_POINTS) -> tuple[ndarray, ndarray]
A breakpoint curve resampled densely enough to draw as a curve.
A specification's segments are power laws, and the plot's frequency
axis is linear, so a straight line drawn between two breakpoints is
not the curve the breakpoints define. For a decade-wide segment it
runs well above that curve through the middle. Resampled at
per_decade points per decade (POWER_LAW_POINTS by default), the
polyline is within a pixel of the power law.
Points already that dense are not resampled: a controller writes its specification on the same line grid as everything else, and there is nothing between two adjacent lines to fill in.
Only the band the specification is written for is returned. A
controller writes zero outside it, and zero cannot be drawn on a log
axis (it maps to -inf), while interpolating across it gives NaN.
Either way the curve would have gaps, and pyqtgraph cannot safely
build a path from an array with gaps (see gapless). With fewer
than two points that can be drawn, the input is returned unchanged.
zone_key
¶
The legend entries for a specification's shading.
The entries are the warning band, the zones above and below abort,
and the exceedance marks, each only when it was drawn: zones holds
any of 'warning', 'above' and 'below', and exceeded any of
'exceed_over' and 'exceed_under'. When the specification holds a
band at one value, its level in decibels is added to the name, as in
'warning band (±3 dB)'. found is the decibel values gathered by
_zone_decibels.
The app's plots (build_plots) and the report's both use this, so
their legends match.
Returns:
| Type | Description |
|---|---|
list of (str, str)
|
(zone, name), in the order a legend lists them. |