Skip to content

Postprocessors

Postprocessors act on the output of a run.

rompy.postprocess.config

Postprocessor configuration classes for ROMPY.

This module provides Pydantic-based configuration classes for different postprocessor types. These configurations handle transient execution parameters while maintaining type safety and validation.

ProcessorConfig module-attribute

ProcessorConfig = Union[NoopPostprocessorConfig]

BasePostprocessorConfig pydantic-model

Bases: BaseModel, ABC

Base class for all postprocessor configurations.

This class defines common configuration parameters that apply to all postprocessor types, such as timeouts and environment variables.

Config:

  • validate_assignment: True
  • extra: forbid
  • use_enum_values: True

Fields:

Validators:

timeout pydantic-field

timeout: int = 3600

Maximum execution time in seconds (1 minute to 24 hours)

env_vars pydantic-field

env_vars: Dict[str, str]

Additional environment variables to set during execution

working_dir pydantic-field

working_dir: Optional[Path] = None

Working directory for execution (defaults to model output directory)

validate_working_dir pydantic-validator

validate_working_dir(v)

Validate working directory exists if specified.

validate_env_vars pydantic-validator

validate_env_vars(v)

Validate environment variables.

get_postprocessor_class abstractmethod

get_postprocessor_class() -> type

Return the postprocessor class that should handle this configuration.

Returns:

Type Description
type

The postprocessor class to use for execution

NoopPostprocessorConfig pydantic-model

Bases: BasePostprocessorConfig

Configuration for no-operation postprocessor.

This configuration is used when no postprocessing is required but output validation may still be needed. It provides the simplest postprocessor that can optionally validate that model outputs exist.

Config:

  • json_schema_extra: {'examples': [{'type': 'noop', 'timeout': 3600, 'validate_outputs': True}, {'type': 'noop', 'timeout': 1800, 'validate_outputs': False, 'env_vars': {'DEBUG': '1'}}, {'type': 'noop', 'working_dir': '/path/to/output/dir'}]}

Fields:

Validators:

type pydantic-field

type: Literal['noop'] = 'noop'

validate_outputs pydantic-field

validate_outputs: bool = True

Whether to validate that expected outputs exist

timeout pydantic-field

timeout: int = 3600

Maximum execution time in seconds (1 minute to 24 hours)

env_vars pydantic-field

env_vars: Dict[str, str]

Additional environment variables to set during execution

working_dir pydantic-field

working_dir: Optional[Path] = None

Working directory for execution (defaults to model output directory)

get_postprocessor_class

get_postprocessor_class()

Return the NoopPostprocessor class.

validate_working_dir pydantic-validator

validate_working_dir(v)

Validate working directory exists if specified.

validate_env_vars pydantic-validator

validate_env_vars(v)

Validate environment variables.

validate_postprocessor_config

validate_postprocessor_config(
    config_file: str | Path,
    processor_type: str | None = None,
) -> tuple[bool, str, BasePostprocessorConfig | None]

Validate a postprocessor configuration file.

This function validates that a configuration file is valid YAML/JSON, contains a valid processor type, and can be instantiated.

Parameters:

Name Type Description Default
config_file str | Path

Path to the configuration file to validate

required
processor_type str | None

Optional specific processor type to validate against. If None, validates against the type in the config.

None

Returns:

Type Description
tuple[bool, str, BasePostprocessorConfig | None]

Tuple of (is_valid: bool, message: str, config: Optional[BasePostprocessorConfig])

rompy.postprocess

Postprocessor module for ROMPY.

This module provides postprocessor classes and their configurations for processing model outputs after execution.

ProcessorConfig module-attribute

ProcessorConfig = Union[NoopPostprocessorConfig]

logger module-attribute

logger = logging.getLogger(__name__)

BasePostprocessorConfig pydantic-model

Bases: BaseModel, ABC

Base class for all postprocessor configurations.

This class defines common configuration parameters that apply to all postprocessor types, such as timeouts and environment variables.

Config:

  • validate_assignment: True
  • extra: forbid
  • use_enum_values: True

Fields:

Validators:

timeout pydantic-field

timeout: int = 3600

Maximum execution time in seconds (1 minute to 24 hours)

env_vars pydantic-field

env_vars: Dict[str, str]

Additional environment variables to set during execution

working_dir pydantic-field

working_dir: Optional[Path] = None

Working directory for execution (defaults to model output directory)

validate_working_dir pydantic-validator

validate_working_dir(v)

Validate working directory exists if specified.

validate_env_vars pydantic-validator

validate_env_vars(v)

Validate environment variables.

get_postprocessor_class abstractmethod

get_postprocessor_class() -> type

Return the postprocessor class that should handle this configuration.

Returns:

Type Description
type

The postprocessor class to use for execution

NoopPostprocessorConfig pydantic-model

Bases: BasePostprocessorConfig

Configuration for no-operation postprocessor.

This configuration is used when no postprocessing is required but output validation may still be needed. It provides the simplest postprocessor that can optionally validate that model outputs exist.

Config:

  • json_schema_extra: {'examples': [{'type': 'noop', 'timeout': 3600, 'validate_outputs': True}, {'type': 'noop', 'timeout': 1800, 'validate_outputs': False, 'env_vars': {'DEBUG': '1'}}, {'type': 'noop', 'working_dir': '/path/to/output/dir'}]}

Fields:

Validators:

timeout pydantic-field

timeout: int = 3600

Maximum execution time in seconds (1 minute to 24 hours)

env_vars pydantic-field

env_vars: Dict[str, str]

Additional environment variables to set during execution

working_dir pydantic-field

working_dir: Optional[Path] = None

Working directory for execution (defaults to model output directory)

type pydantic-field

type: Literal['noop'] = 'noop'

validate_outputs pydantic-field

validate_outputs: bool = True

Whether to validate that expected outputs exist

validate_working_dir pydantic-validator

validate_working_dir(v)

Validate working directory exists if specified.

validate_env_vars pydantic-validator

validate_env_vars(v)

Validate environment variables.

get_postprocessor_class

get_postprocessor_class()

Return the NoopPostprocessor class.

NoopPostprocessor

A postprocessor that does nothing.

This is a placeholder implementation that simply returns a success message. It's useful as a base class or for testing.

process

process(
    model_run: ModelRun,
    validate_outputs: bool = True,
    output_dir: Optional[Union[str, Path]] = None,
    **kwargs: Any,
) -> Dict[str, Any]

Process the output of a model run (does nothing).

Parameters:

Name Type Description Default
model_run ModelRun

The ModelRun instance whose outputs to process

required
validate_outputs bool

Whether to validate that output directory exists

True
output_dir Optional[Union[str, Path]]

Override output directory to check (defaults to model_run output)

None
**kwargs Any

Additional parameters (unused)

{}

Returns:

Type Description
Dict[str, Any]

Dictionary with processing results

Raises:

Type Description
ValueError

If model_run is invalid