utils
canari_ml.preprocess.utils
¶
canari_ml.preprocess.utils.logger = logging.getLogger(__name__)
module-attribute
¶
canari_ml.preprocess.utils.IterableNamespace
¶
Bases: SimpleNamespace
Allows contains check
canari_ml.preprocess.utils.generate_hash(inputs)
¶
Generate a SHAKE-256 hash from input data.
Reference this page
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
list
|
List of input data to be hashed. The contents are serialized using orjson with sorted keys for deterministic output. |
required |
Returns:
| Type | Description |
|---|---|
str
|
4-character hexadecimal digest of the hash. |
Source code in src/canari_ml/preprocess/utils.py
canari_ml.preprocess.utils.compute_step_hash(nodes, name)
¶
Compute hash from multiple OmegaConf nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
ListConfig
|
List of OmegaConf nodes to process. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Hash generated from the combined input data of all nodes |
str
|
converted to dicts. |
Source code in src/canari_ml/preprocess/utils.py
canari_ml.preprocess.utils.compute_loader_hash(steps)
¶
Compute hash from step hashes of multiple OmegaConf nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steps
|
ListConfig
|
List of OmegaConf nodes containing step_hash attributes. Each step's step_hash is collected and used as input for the final hash. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Hash generated from the combined step hashes of all provided steps. |
Source code in src/canari_ml/preprocess/utils.py
canari_ml.preprocess.utils.symlink(target, run_dir)
¶
Symlinks a target file or directory to the specified run directory as relative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
The path of the file or directory to be symlinked. |
required |
run_dir
|
str
|
The path to the run directory where the symlink will be created. |
required |
Source code in src/canari_ml/preprocess/utils.py
canari_ml.preprocess.utils.parse_shape(value)
¶
Parse a shape argument into a tuple of integers.
This function takes a string representing shape dimensions. If the input is a single value, it is duplicated to form a tuple of length two. If multiple values are provided, they are converted into a tuple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
A string containing one or more integers separated by commas, representing shape dimensions. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
A tuple of two integers derived from the input string. |
Examples:
parse_shape("5") returns (5, 5) parse_shape("5,6") returns (5, 6)
Source code in src/canari_ml/preprocess/utils.py
canari_ml.preprocess.utils.parse_crs(crs_string)
¶
Parse a string representing a Cartopy CRS expression into a CRS object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crs_string
|
str
|
A string specifying the Cartopy CRS, such as 'ccrs.PlateCarree()' or 'cartopy.crs.Mercator(central_longitude=0)'. |
required |
Returns:
| Type | Description |
|---|---|
CRS
|
A Cartopy CRS instance corresponding to the input string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided string does not conform to expected formats, or if it doesn't result in a valid CRS object. |
Examples:
>>> parse_crs('cartopy.crs.Mercator(central_longitude=0)')
<cartopy.crs.mercator.Mercator object at ...>
Source code in src/canari_ml/preprocess/utils.py
canari_ml.preprocess.utils.get_nc_encoding(data, chunksizes=None, comp=None)
¶
Source code in src/canari_ml/preprocess/utils.py
canari_ml.preprocess.utils.preprocess_register_resolvers()
¶
Register custom OmegaCon resolvers for preprocessing config files.