pyvale.validation.validprep module¶
Sample sim fields and prepare exp data with named valid axes.
- sample_field_for_valid(field, observable, *, sensor_data=None)[source]¶
Sample a bound field into point/component/time axes without rebinding it.
Observable coordinates and times specify the sampling locations. Optional SensorData supplies orientations and spatial averaging, with matching positions and sample times. Component order follows the observable.
- Parameters:
field (
IField) – Spatial field bound to the simulation to be sampled.observable (
ValidObservable) – Spatial observable with xyz coordinates and evaluation times.sensor_data (
SensorDataorNone, optional) – Optional sensor orientation and footprint settings at the same coordinates and times.
- Returns:
ValidArray– Sampled values of shape (n_points, n_components, n_times), in observable component order and units.
- sample_sim_globals(sim_data, observable)[source]¶
Interpolate stored global variables at the observable times.
Return one point with components in observable order and an explicit time axis. This reads existing global variables; it does not reduce nodal fields.
- Parameters:
sim_data (
SimData) – Simulation with named global traces and a one-dimensional time array.observable (
ValidObservable) – Global observable naming stored variables and target times.
- Returns:
ValidArray– Interpolated values of shape (1, n_components, n_times). The point axis is a singleton.
- sample_sim_sweep_for_valid(fields, observables, runs, *, sample_axes=(), sample_shape=(), sensor_data=None)[source]¶
Sample simulation runs and assemble their values along named axes.
- Parameters:
fields (
dict[str,IField]) – Sampling fields keyed by spatial observable name. Supply exactly one entry per spatial observable. Global observables are sampled from the simulation’s stored global variables.observables (
dict[str,ValidObservable]) – Observable definitions keyed by name. Every observable must specify evaluation times. Spatial observables also specify sampling coordinates.runs (
list[SimData]oriterableoftuple[tuple[int,],SimData]) – For one sample axis, pass a flat list of simulations in axis order. For multiple axes, pass pairs of zero-based index tuples and simulations. For example, ((1, 2), sim_data) selects transferable case 1 and nuisance case 2 when the axes are (EPISTEMIC_TRANS, EPISTEMIC_NUIS). Indexed pairs can arrive in any order and must supply each cell exactly once. Indexed pairs also work for a single axis. With no sample axes, pass one pair with an empty index tuple, ((), sim_data).sample_axes (
tupleofEValidAxis, optional) – Axes addressed by the run indices, in canonical order. Use any subset of transferable epistemic, nuisance epistemic, and aleatory, in that order. The default is no sample axes.sample_shape (
tupleofint, optional) – Number of runs along each sample axis, in the same order as sample_axes. Supply this for indexed sweeps with sample axes. For a flat list, it defaults to the list length as a one-element tuple.sensor_data (
dict[str,SensorData]orNone, optional) – Sensor settings keyed by spatial observable name. Entries can supply sensor orientations and spatial averaging. Their positions and sample times must match the corresponding observable. For an omitted entry, the field is sampled directly at the observable’s coordinates and times.
- Returns:
dict[str,ValidArray]– Sampled values keyed by observable name. Each array has point, component, and time axes followed by sample_axes. Global observables have a singleton point axis.
Notes
Each distinct field is rebound in place through set_sim_data once per run and remains bound to the last run processed. Use separate field instances for concurrent sampling.
- assemble_exp_arrays(sources, observables, *, steady_window=None, channel_map=None)[source]¶
Assemble single-component validation arrays from experimental traces.
By default, keys in sources must match the observables, and acquisition rows are used as points in their existing order. Supply channel_map to select one row per observable by (source key, sensor label). Coordinates are compared when supplied by both the observable and acquisition.
A steady window treats selected trace values as aleatory observations. Without a window, acquisition times must match the observable’s times.
- Parameters:
sources (
dict[str,ExpData]) – Experimental acquisitions. Each fields array has shape (n_channels, n_samples).observables (
dict[str,ValidObservable]) – Target single-component observable definitions keyed by tag.steady_window (
sliceorNone, optional) – Slice of trace samples used as aleatory observations for a steady observable.channel_map (
dict[str,tuple[str,str]]orNone, optional) – Optional mapping from observable tag to (acquisition key, sensor label).
- Returns:
dict[str,ValidArray]– Arrays keyed by observable tag. Steady data have shape (n_points, 1, n_aleatory); transient data have shape (n_points, 1, n_times).
- class SensorOutputSelection(sensor, component, coords)[source]¶
Bases:
objectSelect a component and supply nominal sensor coordinates for SensorSim import.
- Variables:
- sensor¶
- component¶
- coords¶
- __init__(sensor, component, coords)¶
- extract_exp_sim_data(output, *, sim_key, selections, measurement_key='meas', time_key='sens_times')[source]¶
Split SensorSim experiments into per-run, per-component ExpData.
selectionsmaps observable names to SensorOutputSelection records. The caller supplies coordinates because SensorSim output contains measurements but does not guarantee a nominal position array.- Parameters:
output (
dict[tuple[str,],ndarray]) – SensorSim export keyed by (simulation, sensor, data key). Measurements have shape (n_runs, n_sensors, n_components, n_times); times have shape (n_times,).sim_key (
str) – Simulation key in the SensorSim export.selections (
dict[str,SensorOutputSelection]) – Sensor array, component and nominal coordinates for each output observable.measurement_key (
str, optional) – Export key for the measurement arrays.time_key (
str, optional) – Export key for the evaluation times.
- Returns:
list[dict[str,ExpData]]– One dictionary per run, keyed by observable tag. Each ExpData fields array has shape (n_sensors, n_times).
- concatenate_valid_cases(*cases)[source]¶
Join compatible acquisitions on the experimental aleatory axis.
Simulations and observables metadata must be identical. For transient cases, each complete trace becomes a joint aleatory realization at every time.
- Parameters:
*cases (
ValidCase) – Cases with matching simulation observations and physical metadata.- Returns:
ValidCase– Case with experimental observations concatenated along the aleatory dimension. Transient samples remain aligned across time.