Skip to content

isimip_utils.utils

Additional utility functions for ISIMIP tools.

Singleton

Base class for implementing the singleton pattern.

Ensures only one instance of a class exists. Subclasses will share a single instance with a 'data' attribute initialized as an empty dict.

cached_property

Decorator that converts a method into a cached property.

The property value is computed once and then cached as an instance attribute. Subsequent accesses return the cached value without re-computing.

Simplified version of Django's cached_property.

exclude_path(exclude, path, match='any')

Check if a path should be excluded based on exclude patterns.

Parameters:

Name Type Description Default
exclude list[str] | None

List of include patterns (strings). Path is excluded if it contains any or all patterns, depending on the match argument or if include list is None/empty.

required
path Path | str

Path to check for exclusion.

required
match (any, all)

Match all or any of the lines in exclude.

'any'

Returns:

Type Description
bool

True if path should be excluded, False otherwise.

include_path(include, path, match='any')

Check if a path should be included based on include patterns.

Parameters:

Name Type Description Default
include list[str] | None

List of include patterns (strings). Path is included if it contains any or all patterns, depending on the match argument or if include list is None/empty.

required
path Path | str

Path to check for inclusion.

required
match (any, all)

Match all or any of the lines in exclude.

'any'

Returns:

Type Description
bool

True if path should be included, False otherwise.

validate_lat(lat)

Validate latitude value is within valid range.

Parameters:

Name Type Description Default
lat float

Latitude value to validate.

required

Raises:

Type Description
ValidationError

If latitude is outside -90 to 90 range.

validate_lon(lon)

Validate longitude value is within valid range.

Parameters:

Name Type Description Default
lon float

Longitude value to validate.

required

Raises:

Type Description
ValidationError

If longitude is outside -180 to 180 range.

get_min_value(values)

Get the minimal value of the input values, excluding None and using None as default.

Parameters:

Name Type Description Default
values list

Input values.

required

Returns:

Type Description
Any

Minimal value

get_max_value(values)

Get the maximum value of the input values, excluding None and using None as default.

Parameters:

Name Type Description Default
values list

Input values.

required

Returns:

Type Description
Any

Maximum value