dsf.utils.validators module¶
Validation scripts.
- dsf.utils.validators.as_1d_float_array(values, name, *, min_size=1)[source]¶
Return values as a finite one-dimensional float array.
- Parameters:
values (Any) – Input values.
name (str) – Name used in error messages.
min_size (int) – Minimum allowed number of values.
- Returns:
Finite one-dimensional float array.
- Raises:
ValueError – If the input is not one-dimensional, too short, or non-finite.
- Return type:
ndarray[tuple[Any, …], dtype[float64]]
- dsf.utils.validators.as_2d_float_array(values, name)[source]¶
Return values as a finite two-dimensional float array.
- Parameters:
values (Any) – Input values.
name (str) – Name used in error messages.
- Returns:
Finite two-dimensional float array.
- Raises:
ValueError – If the input is not two-dimensional or contains non-finite values.
- Return type:
ndarray[tuple[Any, …], dtype[float64]]
- dsf.utils.validators.is_non_negative_integer(value)[source]¶
Return whether a value is a non-negative integer.
- Parameters:
value (float | int)
- Return type:
bool
- dsf.utils.validators.normalize_axis(axis, ndim)[source]¶
Return a non-negative axis index for an array with
ndimdimensions.- Parameters:
axis (int) – Axis index, allowing negative indexing.
ndim (int) – Number of dimensions of the target array.
- Returns:
Equivalent non-negative axis index.
- Raises:
ValueError – If
ndimis not positive or ifaxisis out of bounds.- Return type:
int
- dsf.utils.validators.occupied_redshift_range_from_nz(z, nz, *, threshold=0.0, name='nz')[source]¶
Return the redshift range occupied by a redshift distribution.
The occupied range is defined by the first and last redshift values where the redshift distribution is above
threshold. This is useful when an approximate tomographic-bin extent is needed but explicit bin edges are not available.- Parameters:
z (Any) – Redshift grid.
nz (Any) – Redshift distribution evaluated on
z.threshold (float) – Minimum
n(z)value used to define the occupied range.name (str) – Name of the redshift distribution used in error messages.
- Returns:
Lower and upper occupied redshift values.
- Raises:
ValueError – If the redshift distribution is invalid, if
thresholdis negative, or if fewer than two redshift cells are occupied.- Return type:
tuple[float, float]
- dsf.utils.validators.redshift_window_mask(z, *, z_min=None, z_max=None)[source]¶
Return a mask selecting redshifts inside optional window limits.
- Parameters:
z (ndarray[tuple[Any, ...], dtype[float64]])
z_min (float | None)
z_max (float | None)
- Return type:
ndarray[tuple[Any, …], dtype[bool]]
- dsf.utils.validators.validate_1d_pair(x, y, *, x_name='x', y_name='y')[source]¶
Validate two matching one-dimensional arrays.
- Parameters:
x (Any) – First array. This array must be strictly increasing.
y (Any) – Second array.
x_name (str) – Name of the first array for error messages.
y_name (str) – Name of the second array for error messages.
- Raises:
ValueError – If arrays are not finite, one-dimensional, matching, or if
xis not strictly increasing.- Return type:
None
- dsf.utils.validators.validate_finite_scalar(value, name)[source]¶
Validate that a scalar is finite.
- Parameters:
value (float) – Scalar value to validate.
name (str) – Name used in error messages.
- Raises:
ValueError – If
valueis not finite.- Return type:
None
- dsf.utils.validators.validate_forecast_vector_and_covariance(data_vector, covariance, *, data_vector_name='data_vector', covariance_name='covariance')[source]¶
Validate and return a forecast data vector and matching covariance.
- Parameters:
data_vector (Any) – Forecast data vector.
covariance (Any) – Forecast covariance matrix.
data_vector_name (str) – Name of the data vector used in error messages.
covariance_name (str) – Name of the covariance matrix used in error messages.
- Returns:
Validated one-dimensional data vector and two-dimensional covariance matrix.
- Raises:
ValueError – If the data vector or covariance is invalid, or if the covariance shape does not match the data-vector length.
- Return type:
tuple[ndarray[tuple[Any, …], dtype[float64]], ndarray[tuple[Any, …], dtype[float64]]]
- dsf.utils.validators.validate_integration_axis(values, x, *, axis=-1)[source]¶
Validate that
xmatches an integration axis ofvalues.- Parameters:
values (Any) – Array of values to integrate.
x (Any) – Coordinate array for the integration axis.
axis (int) – Integration axis.
- Raises:
ValueError – If
xis invalid or does not match the chosen axis.- Return type:
None
- dsf.utils.validators.validate_integration_params(params)[source]¶
Validate lens-magnification integration settings.
- Parameters:
params (dict[str, Any]) – Integration settings dictionary.
- Raises:
ValueError – If any setting is invalid.
- Return type:
None
- dsf.utils.validators.validate_joint_covariance_blocks(cov_gm_gm, cov_gg_gg, cov_gm_gg)[source]¶
Validate and return covariance blocks for a joint Delta Sigma covariance.
- Parameters:
cov_gm_gm (Any) – Auto-covariance block for the galaxy-matter signal.
cov_gg_gg (Any) – Auto-covariance block for the galaxy-galaxy signal.
cov_gm_gg (Any) – Cross-covariance block between the two signals.
- Returns:
Validated covariance blocks as finite float arrays.
- Raises:
ValueError – If any block has an invalid shape.
- Return type:
tuple[ndarray[tuple[Any, …], dtype[float64]], ndarray[tuple[Any, …], dtype[float64]], ndarray[tuple[Any, …], dtype[float64]]]
- dsf.utils.validators.validate_nonnegative_1d_array(values, name, *, min_size=1)[source]¶
Return values as a non-negative one-dimensional float array.
- Parameters:
values (Any) – Input values.
name (str) – Name used in error messages.
min_size (int) – Minimum allowed number of values.
- Returns:
Non-negative one-dimensional float array.
- Raises:
ValueError – If the input is invalid or contains negative values.
- Return type:
ndarray[tuple[Any, …], dtype[float64]]
- dsf.utils.validators.validate_nonnegative_scalar(value, name)[source]¶
Validate that a scalar is finite and non-negative.
- Parameters:
value (float) – Scalar value to validate.
name (str) – Name used in error messages.
- Raises:
ValueError – If
valueis not finite or is negative.- Return type:
None
- dsf.utils.validators.validate_parameter_names(parameter_names, theta0, *, parameter_names_name='parameter_names', theta0_name='theta0')[source]¶
Validate parameter names against a fiducial parameter vector.
- Parameters:
parameter_names (Any) – Names associated with the forecast parameters.
theta0 (Any) – Fiducial parameter vector.
parameter_names_name (str) – Name of the parameter-name sequence used in error messages.
theta0_name (str) – Name of the fiducial parameter vector used in error messages.
- Returns:
Parameter names as a tuple of strings.
- Raises:
ValueError – If the number of names does not match the number of fiducial parameters.
TypeError – If any parameter name is not a string.
- Return type:
tuple[str, …]
- dsf.utils.validators.validate_positive_1d_array(values, name, *, min_size=1)[source]¶
Return values as a positive one-dimensional float array.
- Parameters:
values (Any) – Input values.
name (str) – Name used in error messages.
min_size (int) – Minimum allowed number of values.
- Returns:
Positive one-dimensional float array.
- Raises:
ValueError – If the input is invalid or contains non-positive values.
- Return type:
ndarray[tuple[Any, …], dtype[float64]]
- dsf.utils.validators.validate_positive_scalar(value, name)[source]¶
Validate that a scalar is finite and positive.
- Parameters:
value (float) – Scalar value to validate.
name (str) – Name used in error messages.
- Raises:
ValueError – If
valueis not finite or is not positive.- Return type:
None
- dsf.utils.validators.validate_positive_strictly_increasing_1d_array(values, name, *, min_size=2)[source]¶
Return values as a positive strictly increasing one-dimensional array.
This is useful for physical coordinate grids such as wavenumber, radius, or frequency grids where values must be finite, positive, and ordered.
- Parameters:
values (Any) – Input coordinate values.
name (str) – Name used in error messages.
min_size (int) – Minimum allowed number of values.
- Returns:
Positive strictly increasing one-dimensional float array.
- Raises:
ValueError – If the input is invalid, non-positive, or not strictly increasing.
- Return type:
ndarray[tuple[Any, …], dtype[float64]]
- dsf.utils.validators.validate_power_spectrum_inputs(k, pk, *, k_name='k', pk_name='pk')[source]¶
Validate a tabulated one-dimensional power spectrum.
- Parameters:
k (Any) – Wavenumber grid.
pk (Any) – Power-spectrum values evaluated on
k.k_name (str) – Name of the wavenumber array for error messages.
pk_name (str) – Name of the power-spectrum array for error messages.
- Raises:
ValueError – If arrays are not finite, one-dimensional, matching, positive in
k, or strictly increasing ink.- Return type:
None
- dsf.utils.validators.validate_redshift_distribution(z, nz, *, name='nz')[source]¶
Validate and return a redshift distribution.
- Parameters:
z (Any) – Redshift grid.
nz (Any) – Redshift distribution evaluated on
z.name (str) – Name used in error messages.
- Returns:
Redshift grid and redshift distribution as float arrays.
- Raises:
ValueError – If the inputs are invalid.
- Return type:
tuple[ndarray[tuple[Any, …], dtype[float64]], ndarray[tuple[Any, …], dtype[float64]]]
- dsf.utils.validators.validate_redshift_distribution_support(z, nz, *, name='redshift_distribution', trim_edge_points=0)[source]¶
Validate and select the positive support of a redshift distribution.
Leading and trailing zero-density points are removed. Interior non-positive values inside the selected support are rejected.
- dsf.utils.validators.validate_redshift_edges(z_min, z_max, *, z_min_name='z_min', z_max_name='z_max')[source]¶
Validate lower and upper redshift edges.
- Parameters:
z_min (float) – Lower redshift edge.
z_max (float) – Upper redshift edge.
z_min_name (str) – Name of the lower edge for error messages.
z_max_name (str) – Name of the upper edge for error messages.
- Raises:
ValueError – If the redshift edges are invalid.
- Return type:
None
- dsf.utils.validators.validate_redshift_pair(z_lens, z_source)[source]¶
Validate a lens/source redshift pair.
- Parameters:
z_lens (float) – Lens redshift.
z_source (float) – Source redshift.
- Raises:
ValueError – If redshifts are invalid or the source is not behind the lens.
- Return type:
None
- dsf.utils.validators.validate_scale_factor(a)[source]¶
Validate a cosmological scale factor.
- Parameters:
a (float) – Scale factor.
- Raises:
ValueError – If
ais not in the interval0 < a <= 1.- Return type:
None
- dsf.utils.validators.validate_strictly_increasing(values, name, *, min_size=2)[source]¶
Return values as a strictly increasing one-dimensional float array.
- Parameters:
values (Any) – Input values.
name (str) – Name used in error messages.
min_size (int) – Minimum allowed number of values.
- Returns:
Strictly increasing one-dimensional float array.
- Raises:
ValueError – If the input is invalid or is not strictly increasing.
- Return type:
ndarray[tuple[Any, …], dtype[float64]]