Skip to content

Index

subsurfaceio.decorators

Reusable function and method decorators.

from subsurfaceio.decorators import set_function_metadata

@set_function_metadata('site_class', scalar=True)
def get_site_class(is_e_site_class: bool) -> str:
    return 'E' if is_e_site_class else 'D'

Functions:

Name Description
set_function_metadata

Attach output metadata to subsurfaceio.functions.

set_ui_metadata

Attach UI configuration metadata to a method.

set_function_metadata

set_function_metadata(
    returns: str | tuple[str, ...], *, scalar: bool = False
) -> Callable[[F], F]

Attach output metadata to subsurfaceio.functions.

scalar is the result-model slot for a single-profile run (metadata vs data), not a numpy rank. Vectorized or parametric calls may still return arrays for scalar outputs.

Parameters:

Name Type Description Default
returns str | tuple[str, ...]

The output variable name or names produced by the decorated function.

required
scalar bool

If True, those names belong on result metadata for a single-profile calculation. If False (default), they belong on result data (e.g. depth-aligned profile).

False

Returns:

Type Description
Callable[[F], F]

A decorator that sets returns, _single_return, and scalar on the target function.

set_ui_metadata

set_ui_metadata(
    exclude: str | tuple[str, ...] | None = None,
    *,
    upload_accept: str | None = None,
    upload_field: str | None = None,
    download_extension: str | None = None,
    download_path_field: str | None = None
) -> Callable[[F], F]

Attach UI configuration metadata to a method.

Parameters:

Name Type Description Default
exclude str | tuple[str, ...] | None

Fields to exclude from rendering.

None
upload_accept str | None

Value for the upload component's accept property (e.g., ".csv", ".csv,.xlsx", "image/*").

None
upload_field str | None

Name of the method parameter that should be rendered as a file upload component. Defaults to "source" when upload_accept is specified.

None
download_extension str | None

File extension (e.g., "csv", "xlsx") of the file produced by the method.

None
download_path_field str | None

Name of the method parameter that receives the output file path. Defaults to "path" when download_extension is specified.

None

Returns:

Type Description
Callable[[F], F]

A decorator function that attaches the specified UI metadata to the target method.