Skip to content

epymorph.adrio.numpy

SliceOrEllipsis module-attribute

SliceOrEllipsis = slice | type(Ellipsis)

Type alias: either a slice object or an ellipsis (...).

ArraySlice module-attribute

ArraySlice = SliceOrEllipsis | tuple[SliceOrEllipsis, ...]

Type alias for a numpy array slice.

See Also

It's very convenient to use numpy's IndexExpression helpers like numpy.s_ to create one of these.

NumpyFile

NumpyFile(
    *,
    file_path: str | Path,
    shape: DataShape,
    dtype: dtype | type[generic],
    array_name: str | None = None,
    array_slice: ArraySlice | None = None,
)

Bases: ADRIO[generic, generic]

Retrieves an array of data from a .npy or .npz file.

Parameters:

  • file_path (str | Path) –

    The path to a .npy or .npz file to load.

  • shape (DataShape) –

    The expected shape of the array. "Arbitrary" axes lengths will not be checked.

  • dtype (dtype | type[generic]) –

    The expected dtype of the array.

  • array_name (str | None, default: None ) –

    If and only if loading an .npz file, the name of the array to load. For .npy files, this must be None.

  • array_slice (ArraySlice | None, default: None ) –

    The optional array slice to apply to the loaded array. numpy provides a helper called np.s_ which is a convenient way to construct these. If None, the entire array is returned.

result_format property

result_format: ResultFormat

Information about the expected format of the ADRIO's resulting data.

validate_context

validate_context(context: Context) -> None

Validates the context before ADRIO evaluation.

Parameters:

  • context (Context) –

    The context to validate.

Raises:

inspect

inspect() -> InspectResult[generic, generic]

Produce an inspection of the ADRIO's data for the current context.

When implementing an ADRIO, override this method to provide data fetching and processing logic. Use self methods and properties to access the simulation context or defer processing to another function.

NOTE: if you are implementing this method, make sure to call validate_context first and _validate_result last.

Returns:

validate_result

validate_result(
    context: Context, result: NDArray[generic]
) -> None

Validates that the result of evaluating the ADRIO adheres to the expected result format.

Parameters:

  • context (Context) –

    The context in which the result has been evaluated.

  • result (NDArray[ResultT]) –

    The result produced by the ADRIO.

Raises: