climakitae.new_core.param_validation package#

Submodules#

climakitae.new_core.param_validation.abc_param_validation module#

Parameter validation module for climakitae.

This module provides a comprehensive framework for validating query parameters used throughout the climakitae package. It includes:

  • Abstract base class for parameter validation (ParameterValidator)

  • Registry system for catalog and processor validators

  • Validation logic for dataset queries and processing parameters

  • Helper functions for finding closest matching options when validation fails

The validation system operates on two levels: 1. Catalog validation: Ensures query parameters match available datasets 2. Processor validation: Validates processing parameters for data transformations

Classes#

ParameterValidator

Abstract base class defining the parameter validation interface. Subclasses must implement is_valid_query() method.

Functions#

register_catalog_validator

Decorator for registering catalog validator classes.

register_processor_validator

Decorator for registering processor validator classes.

Module Variables#

_CATALOG_VALIDATOR_REGISTRYdict

Registry mapping validator names to catalog validator classes.

_PROCESSOR_VALIDATOR_REGISTRYdict

Registry mapping validator names to processor validator classes.

Examples

>>> @register_catalog_validator("my_catalog")
... class MyCatalogValidator(ParameterValidator):
...     def is_valid_query(self, query):
...         # Implementation here
...         pass
class climakitae.new_core.param_validation.abc_param_validation.ParameterValidator#

Bases: ABC

Abstract base class for parameter validation in climakitae.

This class provides a framework for validating user queries containing dataset selection parameters and processing parameters. It handles:

  • Catalog parameter validation (dataset selection)

  • Processor parameter validation (data transformations)

  • Error handling and user-friendly suggestions

  • Parameter conversion and normalization

The validation process includes: 1. Converting user input to catalog keys 2. Searching for matching datasets in the catalog 3. Providing suggestions for invalid parameters 4. Validating processing parameters

catalog_path#

Path to the catalog CSV file.

Type:

str

catalog#

Data catalog instance for dataset searching.

Type:

object

all_catalog_keys#

Dictionary of catalog keys populated from user query.

Type:

dict

catalog_df#

DataFrame containing catalog information.

Type:

pandas.DataFrame

is_valid_query(query)#

Abstract method to validate query parameters. Must be implemented by subclasses.

populate_catalog_keys(query)#

Populate catalog keys from user query.

load_catalog_df()#

Load the catalog DataFrame.

Notes

Subclasses must implement the is_valid_query method to define specific validation logic for their use case.

Examples

>>> class MyValidator(ParameterValidator):
...     def is_valid_query(self, query):
...         # Custom validation logic
...         return self._is_valid_query(query)
abstract is_valid_query(query: Dict[str, Any]) Dict[str, Any] | None#

Validate the query parameters (abstract method).

This method must be implemented by subclasses to define specific validation logic for their use case. It should validate both catalog parameters (for dataset selection) and processing parameters.

Parameters:

query (Dict[str, Any]) – Query parameters to validate. Expected to contain: - Dataset selection parameters (e.g., variable, experiment_id, etc.) - Processing parameters under the ‘processes’ key - Any other relevant validation parameters

Returns:

Dict[str, Any] | None – Validated and processed query parameters if valid, None if invalid. When returning a dictionary, it should contain the cleaned and validated parameters ready for dataset retrieval.

Notes

Implementations typically call _is_valid_query() to leverage the common validation logic provided by the base class.

Examples

>>> def is_valid_query(self, query):
...     # Custom pre-processing
...     processed_query = self.preprocess_query(query)
...     # Use base class validation
...     return self._is_valid_query(processed_query)
load_catalog_df()#

Load the data catalog DataFrame and assign to instance attribute.

Creates a DataCatalog instance and extracts its catalog DataFrame for use in parameter validation. The DataFrame contains metadata about available datasets.

Returns:

None – Sets self.catalog_df attribute.

Notes

This method is called during initialization and provides access to the catalog data needed for parameter validation and suggestion generation.

Side Effects#

Sets self.catalog_df attribute with the loaded catalog DataFrame.

populate_catalog_keys(query: Dict[str, Any]) None#

Populate catalog keys from user query, filtering out unset values.

This method extracts relevant catalog parameters from the user query and stores them in self.all_catalog_keys. Only parameters that are actually set (not UNSET) are retained.

Parameters:

query (Dict[str, Any]) – User query containing potential catalog parameters.

Returns:

None – Updates self.all_catalog_keys in-place.

Notes

This method assumes self.all_catalog_keys already contains the expected catalog parameter names (typically initialized by subclasses). The method: 1. Maps query values to catalog keys 2. Removes any UNSET values 3. Stores the result in self.all_catalog_keys

Side Effects#

Modifies self.all_catalog_keys attribute.

climakitae.new_core.param_validation.abc_param_validation.register_catalog_validator(name: str)#

Decorator to register a catalog validator class in the global registry.

This decorator allows validator classes to be registered for use with specific catalog types. Registered validators can be retrieved and instantiated by name from the global registry.

Parameters:

name (str) – Unique name to register the validator under. This name will be used to look up the validator class in the registry.

Returns:

function – Decorator function that registers the class and returns it unchanged.

Examples

>>> @register_catalog_validator("my_catalog")
... class MyCatalogValidator(ParameterValidator):
...     def is_valid_query(self, query):
...         return self._is_valid_query(query)
>>> # Later retrieval:
>>> validator_class = _CATALOG_VALIDATOR_REGISTRY["my_catalog"]
>>> validator = validator_class()

Notes

The registered class is stored in the module-level _CATALOG_VALIDATOR_REGISTRY dictionary.

climakitae.new_core.param_validation.abc_param_validation.register_processor_validator(name: str)#

Decorator to register a processor validator function in the global registry.

This decorator allows processor validation functions to be registered for use with specific processing parameters. Registered validators can be retrieved and called by name from the global registry.

Parameters:

name (str) – Unique name to register the processor validator under. This should match the processor parameter name that the validator handles.

Returns:

function – Decorator function that registers the validator function and returns it unchanged.

Examples

>>> @register_processor_validator("spatial_subset")
... def validate_spatial_subset(value, query=None):
...     # Validation logic for spatial_subset processor
...     return isinstance(value, dict) and 'bounds' in value
>>> # Later retrieval and use:
>>> validator_func = _PROCESSOR_VALIDATOR_REGISTRY["spatial_subset"]
>>> is_valid = validator_func(subset_params, query=user_query)

Notes

  • The registered function is stored in the module-level _PROCESSOR_VALIDATOR_REGISTRY dictionary

  • Processor validators should accept value and optional query parameters

  • Validators may modify the query in-place for parameter normalization

climakitae.new_core.param_validation.concat_param_validator module#

Validator for parameters provided to Concat Processor.

climakitae.new_core.param_validation.concat_param_validator.validate_concat_param(value: str, **kwargs: Any) bool#

Validate the parameters provided to the Concat Processor.

Parameters:

value (str) – The dimension name along which to concatenate datasets. Default: “sim”

Returns:

bool – True if all parameters are valid, False otherwise

climakitae.new_core.param_validation.data_param_validator module#

Validator for data catalog parameters.

class climakitae.new_core.param_validation.data_param_validator.DataValidator(catalog: DataCatalog)#

Bases: ParameterValidator

Validator for data catalog parameters.

Parameters:

catalog (DataCatalog) – the DataCatalog object to validate against

is_valid_query(query: Dict[str, Any]) Dict[str, Any] | None#

Catalog specific validation for the query.

Parameters:

query (Dict[str, Any]) – The query to validate.

Returns:

Dict[str, Any] | None – The validated query if valid, None otherwise.

Notes

A list of checks that are performed on the query:

  1. Check if the query contains the localize processor.

    Localize is not supported for LOCA2 datasets.

climakitae.new_core.param_validation.filter_unadjusted_models_param_validator module#

Validator for parameters provided to FilterunadjustedModels Processor.

climakitae.new_core.param_validation.filter_unadjusted_models_param_validator.validate_filter_unadjusted_models_param(value: str, **kwargs: Any) bool#

Validate the parameters provided to the FilterUnadjustedModels Processor.

Parameters:

value (str) – The value to control filtering behavior. Supported values: “yes” (default): Filter out unadjusted models “no”: Include unadjusted models

Returns:

bool – True if all parameters are valid, False otherwise

climakitae.new_core.param_validation.param_validation_tools module#

Tools for validating user input

climakitae.new_core.param_validation.renewables_param_validator module#

Validator for renewable energy dataset parameters.

class climakitae.new_core.param_validation.renewables_param_validator.RenewablesValidator(catalog: DataCatalog)#

Bases: ParameterValidator

Validator for renewable energy dataset parameters.

Parameters:

catalog (str) – path to the renewables dataset catalog

is_valid_query(query: Dict[str, Any]) Dict[str, Any] | None#

Validate the query parameters (abstract method).

This method must be implemented by subclasses to define specific validation logic for their use case. It should validate both catalog parameters (for dataset selection) and processing parameters.

Parameters:

query (Dict[str, Any]) – Query parameters to validate. Expected to contain: - Dataset selection parameters (e.g., variable, experiment_id, etc.) - Processing parameters under the ‘processes’ key - Any other relevant validation parameters

Returns:

Dict[str, Any] | None – Validated and processed query parameters if valid, None if invalid. When returning a dictionary, it should contain the cleaned and validated parameters ready for dataset retrieval.

Notes

Implementations typically call _is_valid_query() to leverage the common validation logic provided by the base class.

Examples

>>> def is_valid_query(self, query):
...     # Custom pre-processing
...     processed_query = self.preprocess_query(query)
...     # Use base class validation
...     return self._is_valid_query(processed_query)

climakitae.new_core.param_validation.update_attributes_param_validator module#

Validator for parameters provided to UpdateAttributes Processor.

climakitae.new_core.param_validation.update_attributes_param_validator.validate_update_attributes_param(value: Any, **kwargs: Any) bool#

Validate the parameters provided to the UpdateAttributes Processor.

Parameters:

value (Any) – The value to update the attributes with. Can be any type, including UNSET for default behavior.

Returns:

bool – True if all parameters are valid, False otherwise

Module contents#

Import param validation classes ensuring they are registered.