Index
subsurfaceio.reference_figure
Published geotechnical reference charts.
Catalog specs are preloaded once, immutable, and safe to share. Plot
data_frame and optional overlays are passed at render time.
This package exports only the specifications and catalog. Each backend figure is imported from its own module, so consumers that only look up or interpolate a spec never pay for a rendering stack:
from subsurfaceio.reference_figure import reference_figure_catalog
from subsurfaceio.reference_figure.figure_plotly import PlotlyReferenceFigure
spec = reference_figure_catalog.get("USCSPlasticityChart")
fig = spec.render_plotly(data_frame=df).fig
MplReferenceFigure
renders the same specification with matplotlib and requires the mpl extra;
importing that module is what enforces the requirement.
Modules:
| Name | Description |
|---|---|
figure_mpl |
Matplotlib renderer for reference figure specs. |
figure_plotly |
Plotly renderer for reference figure specs. |
overlays |
Builders for annotation overlays drawn on reference figures. |
Classes:
| Name | Description |
|---|---|
CartesianLineShape |
Cartesian reference curve (non-filled line). |
CartesianPolygonShape |
Cartesian filled polygon region. |
Overlay |
User or computed trace drawn on top of a reference figure. |
ReferenceFigureCatalog |
Namespace for predefined reference figures. |
ReferenceFigureSpec |
Specification of a published reference figure — not a rendered plot. |
SecondaryAxis |
Top or right axis tick mapping for dual-scale reference charts. |
TernaryPolygonShape |
Ternary filled polygon region. |
Attributes:
| Name | Type | Description |
|---|---|---|
ReferenceFigureName |
TypeAlias
|
Literal union of all catalog figure names. |
ReferenceFigureShape |
TypeAlias
|
Discriminated background shape: line, cartesian polygon, or ternary polygon. |
reference_figure_catalog |
Default catalog instance; preferred entry point for predefined figures. |
ReferenceFigureName
module-attribute
Literal union of all catalog figure names.
ReferenceFigureShape
module-attribute
ReferenceFigureShape: TypeAlias = Annotated[
CartesianLineShape
| CartesianPolygonShape
| TernaryPolygonShape,
Field(discriminator="kind"),
]
Discriminated background shape: line, cartesian polygon, or ternary polygon.
reference_figure_catalog
module-attribute
Default catalog instance; preferred entry point for predefined figures.
CartesianLineShape
pydantic-model
Bases: ShapeBase
Cartesian reference curve (non-filled line).
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['line']
|
Union tag; must be |
x |
list[float]
|
Abscissa samples. |
y |
list[float]
|
Ordinate samples. |
line_dash |
str | None
|
Dash style, or |
Fields:
-
name(str) -
label(str | None) -
color(str | None) -
kind(Literal['line']) -
x(list[float]) -
y(list[float]) -
line_dash(str | None)
Validators:
-
_coords_same_length
CartesianPolygonShape
pydantic-model
Bases: ShapeBase
Cartesian filled polygon region.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['polygon']
|
Union tag; must be |
x |
list[float]
|
Vertex abscissas. |
y |
list[float]
|
Vertex ordinates. |
centroid |
tuple[float, float] | None
|
Optional label position. |
alpha |
float
|
Fill opacity. |
Fields:
-
name(str) -
label(str | None) -
color(str | None) -
kind(Literal['polygon']) -
x(list[float]) -
y(list[float]) -
centroid(tuple[float, float] | None) -
alpha(float)
Validators:
-
_coords_same_length
Overlay
pydantic-model
Bases: BaseModel
User or computed trace drawn on top of a reference figure.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Any
|
Abscissa value(s). |
y |
Any
|
Ordinate value(s). |
name |
str | None
|
Legend label. |
mode |
TraceMode
|
Plotly trace mode ( |
color |
Color | None
|
Marker or line color. |
marker_symbol |
MarkerSymbol | None
|
Plotly marker symbol when |
Config:
frozen:Trueextra:forbid
Fields:
-
x(Any) -
y(Any) -
name(str | None) -
mode(TraceMode) -
color(Color | None) -
marker_symbol(MarkerSymbol | None)
model_config
class-attribute
instance-attribute
ReferenceFigureCatalog
Namespace for predefined reference figures.
Use reference_figure_catalog.get(name) and
reference_figure_catalog.names(). Pass annotation overlays at render
time via overlays on
render_mpl
/
render_plotly.
Methods:
| Name | Description |
|---|---|
get |
Return the cached immutable spec for |
names |
Return all catalog figure names. |
get
Return the cached immutable spec for name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
ReferenceFigureName
|
Catalog figure name. |
required |
Returns:
| Type | Description |
|---|---|
ReferenceFigureSpec
|
Cached immutable spec. |
Raises:
| Type | Description |
|---|---|
KeyError
|
When |
ReferenceFigureSpec
pydantic-model
Bases: BaseModel
Specification of a published reference figure — not a rendered plot.
Cached catalog specs are immutable and shareable. Annotation overlays (sieve
D-values, Atterberg flow curves) are passed via the overlays argument to
render_plotly
/
render_mpl.
Attributes:
| Name | Type | Description |
|---|---|---|
plot_model |
DiscriminatedPlotModel
|
Discriminated Plotly Express / matplotlib-express model. |
reference_data |
list[ReferenceFigureShape] | None
|
Background lines and polygon regions from the catalog. |
secondary_axis |
SecondaryAxis | None
|
Optional top/right tick label maps. |
reference |
str | None
|
Bibliography id from the catalog, or |
Config:
frozen:Trueextra:forbid
Fields:
-
plot_model(DiscriminatedPlotModel) -
reference_data(list[ReferenceFigureShape] | None) -
secondary_axis(SecondaryAxis | None) -
reference(str | None)
model_config
class-attribute
instance-attribute
as_reference_data
Convert line-family background curves to a ReferenceDataSet.
Returns:
| Type | Description |
|---|---|
ReferenceDataSet
|
Tabular curves sharing a common x-column. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
For ternary plot models. |
ValueError
|
When background data is empty, not cartesian lines, or
the lines do not share the same |
assign_polygons_labels_from_xy_data
assign_polygons_labels_from_xy_data(
x: ndarray,
y: ndarray,
clip_xy_to_axis_limits: bool = False,
not_found_label: object = STRING_DTYPE_NA,
) -> np.ndarray
Assign each (x, y) pair the polygon name that contains it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Abscissa values. |
required |
y
|
ndarray
|
Ordinate values. |
required |
clip_xy_to_axis_limits
|
bool
|
Clip inputs to |
False
|
not_found_label
|
object
|
Label for points outside all polygons. |
STRING_DTYPE_NA
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of polygon names (string dtype). |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
For ternary plot models. |
ValueError
|
When background data is missing or not cartesian polygons. |
get_reference_data_by_id
Return the background element whose name matches reference_data_label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_data_label
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
ReferenceFigureShape | None
|
Matching shape, or |
interpolate_at_x
interpolate_at_x(
x: float | ndarray,
reference_data_label: str = "self",
kind: str = "linear",
fill_value: float | None = None,
label_search_closest_value: float | None = None,
switch_x_and_y: bool = False,
) -> float | np.ndarray
Interpolate along a reference curve at one or more abscissa values.
Catalog curves that represent the primary relationship use the
conventional name 'self'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float | ndarray
|
Value(s) on the plot x-axis (or y-axis when |
required |
reference_data_label
|
str
|
|
'self'
|
kind
|
str
|
Interpolation kind passed to |
'linear'
|
fill_value
|
float | None
|
Value for out-of-range |
None
|
label_search_closest_value
|
float | None
|
When set, pick the curve whose |
None
|
switch_x_and_y
|
bool
|
Interpolate |
False
|
Returns:
| Type | Description |
|---|---|
float | ndarray
|
Interpolated ordinate value(s). |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
For ternary plot models. |
ValueError
|
When no matching cartesian line exists. |
render_mpl
Render a MplReferenceFigure with optional plot overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**plot_kwargs
|
Any
|
Overrides forwarded to the figure constructor
(for example |
{}
|
Returns:
| Type | Description |
|---|---|
MplReferenceFigure
|
Plotted matplotlib figure. |
render_plotly
Render a PlotlyReferenceFigure with optional plot overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**plot_kwargs
|
Any
|
Overrides forwarded to the figure constructor
(for example |
{}
|
Returns:
| Type | Description |
|---|---|
PlotlyReferenceFigure
|
Plotted Plotly figure. |
SecondaryAxis
pydantic-model
Bases: BaseModel
Top or right axis tick mapping for dual-scale reference charts.
Used by sieve and hydrometer charts to show particle size alongside sieve numbers. Keys are axis data values; values are tick labels.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
dict[float, str] | None
|
Map of x-axis data values to tick labels. |
y |
dict[float, str] | None
|
Map of y-axis data values to tick labels. |
font_size |
float
|
Tick label size in CSS pixels. |
Config:
frozen:Trueextra:forbid
Fields:
TernaryPolygonShape
pydantic-model
Bases: ShapeBase
Ternary filled polygon region.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
Literal['ternary']
|
Union tag; must be |
a |
list[float]
|
First barycentric coordinate samples. |
b |
list[float]
|
Second barycentric coordinate samples. |
c |
list[float]
|
Third barycentric coordinate samples. |
centroid |
tuple[float, float, float] | None
|
Optional label position. |
alpha |
float
|
Fill opacity. |
Fields:
-
name(str) -
label(str | None) -
color(str | None) -
kind(Literal['ternary']) -
a(list[float]) -
b(list[float]) -
c(list[float]) -
centroid(tuple[float, float, float] | None) -
alpha(float)
Validators:
-
_coords_same_length