errorintegrator¶
- class pyvale.errorintegrator.ErrIntOpts(force_dependence: EErrDep | None = None, store_all_errs: bool = False)[source]¶
Bases:
object
Error integration options dataclass. Allows the user to control how errors are calculated and stored in memory for later use.
- force_dependence: EErrDep | None¶
Forces all errors to be calculated with the specified dependence. If set to None then all errors will use their default/preset dependence.
Note that some errors are inherently independent so will not change. For example: ErrRandNormal is purely independent whereas ErrRandNormPercent can have the percentage error calculated based on the ground truth (independent) or based on the accumulated sensor measurement (dependent).
- store_all_errs: bool¶
Stores all errors for individual error in the chain if True. Also stores a list of SensorData objects showing perturbations to the sensor array parameters caused by individual errors. Consumes significantly more memory but is useful for finding which errors contribute most to the total measurement error. For large sensor arrays (>100 sensors)
- class pyvale.errorintegrator.ErrIntegrator(err_chain: list[IErrCalculator], sensor_data_initial: SensorData, meas_shape: tuple[int, int, int], err_int_opts: ErrIntOpts | None = None)[source]¶
Bases:
object
Class for managing sensor error integration. Takes a list of objects that implement the IErrCalculator interface (i.e. the error chain) and loops through them calculating each errors contribution to the total measurement error and sums this over all errors in the chain. In addition to the total error a sum of the random and systematic errors (see EErrType) is calculated and stored.
This class also accumulates perturbations to the sensor array parameters due to errors (i.e. sensor positioning error or temporal drift). The accumulated sensor array parameters are stored as a SensorData object.
The errors are calculated in the order specified in the list. For dependent errors (EErrDependence.DEPENDENT) the position of the error within the error chain determines the accumulated sensor measurement that will be used to calculate the error.
The user can control how the errors are calculated using the ErrIntOpts dataclass.
- Parameters:
err_chain (list[IErrCalculator]) -- List of error objects implementing the IErrCalculator interface.
sensor_data_initial (SensorData) -- Object holding the initial sensor array parameters before they are modified by the error chain.
meas_shape (tuple[int,int,int]) -- Shape of the sensor measurement array. shape=(num_sensors, num_field_components,num_time_steps)
err_int_opts (ErrIntOpts | None, optional) -- Options for controlling how errors are calculated/summed and how they are store in memory, by default None. If None then the default options dataclass is used.
- calc_errors_from_chain(truth: ndarray) ndarray [source]¶
- Calculates all errors by looping over the error chain. The total
measurement error is summed as each error is calculated in order. Note that this causes all errors based on probability distributions to be resampled and any required interpolations to be performed (e.g. from randomly perturbing the sensor positions). Accumulated errors are also stored for random and systematic errors separately (see EErrType).
If the store_all_errs = True in the ErrIntOpts dataclass then each individual error is stored in a numpy array (see get_errs_by_chain()) along with the accumulated errors in another numpy array.
- Parameters:
truth (np.ndarray) -- Array of ground truth sensor measurements interpolated from the simulated physical field. shape=(num_sensors,num_field_components, num_time_steps).
- Returns:
np.ndarray -- Array of total errors summed over all errors in the chain. shape=( num_sensors,num_field_components,num_time_steps).
- get_errs_by_chain() ndarray | None [source]¶
Gets the array of errors for each error in chain. If store_all_errs is False in ErrIntOpts then this will return None.
- Returns:
np.ndarray | None -- Array of all errors in the chain. shape=(num_errs_in_chain, num_sensors,num_field_components,num_time_steps). Returns None if ErrIntOpts.store_all_errs=False.
- get_errs_random() ndarray [source]¶
Gets the array of summed random errors over the error chain. If the errors have not been calculated then an array of zeros is returned.
- Returns:
np.ndarray -- Array of total random errors. shape=(num_sensors, num_field_components,num_time_steps)
- get_errs_systematic() ndarray [source]¶
Gets the array of summed systematic errors over the error chain. If the errors have not been calculated then an array of zeros is returned.
- Returns:
np.ndarray -- Array of total systematic errors. shape=(num_sensors, num_field_components,num_time_steps)
- get_errs_total() ndarray [source]¶
Gets the array of total errors. If the errors have not been calculated then an array of zeros is returned. Note that this function just returns the most recently calculated errors and will not resample from probability distributions.
- Returns:
np.ndarray -- Array of total errors. shape=(num_sensors,num_field_components, num_time_steps)
- get_sens_data_accumulated() SensorData [source]¶
Gets the final accumulated sensor array parameters based on all errors in the chain as a SensorData object. If no errors modify the sensor array parameters then the SensorData object returns will be identical to the SensorData object used to create the sensor array.
- Returns:
SensorData -- The final sensor array parameters based on accumulating all perturbations from all errors in the error chain.
- get_sens_data_by_chain() list[SensorData] | None [source]¶
Gets the list of sensor data objects storing how each error in the chain has perturbed the underlying sensor parameters. If store_all_errs is False in ErrIntOpts then this will return None. If no sensor array parameters are modified by the error chain then all SensorData objects in the list will be identical to the SensorData object used to create the sensor array.
- Returns:
list[SensorData] | None -- List of perturbed sensors array parameters for each error in the chain. Returns None if ErrIntOpts.store_all_errs=False.
- set_error_chain(err_chain: list[IErrCalculator]) None [source]¶
Sets the error chain that will be looped over to calculate the sensor measurement errors. If the error integration options are forcing error dependence then all errors in the chain will have their dependence set to the specified value.
- Parameters:
err_chain (list[IErrCalculator]) -- List of error calculators implementing the IErrCalculator interface.