cmip_branded_variable_mapper.mapper_classes#
Classes for mapping from variable information to branded variable components
These have a custom implementation because there is a coupling between the mapping and the matching algorithms (and the classes ensure that this coupling is respected).
Classes:
| Name | Description |
|---|---|
CellMethodsSubStringMapper |
Mapper that returns values based on matches of sub-strings in cell methods |
CellMethodsSubStringMapperOrdered |
Mapper that returns values based on matches of ordered sub-strings in cell methods |
DimensionMapper |
Mapper that returns values based on whether dimensions are present or not |
CellMethodsSubStringMapper #
Mapper that returns values based on matches of sub-strings in cell methods
Methods:
| Name | Description |
|---|---|
get_value |
Get the metadata value for a given value of cell_methods |
sub_string_map_validator |
Validate the received map |
Attributes:
| Name | Type | Description |
|---|---|---|
sub_string_map |
dict[str, str]
|
Map from sub-strings of cell methods to the metadata value to use |
Source code in src/cmip_branded_variable_mapper/mapper_classes.py
sub_string_map
class-attribute
instance-attribute
#
Map from sub-strings of cell methods to the metadata value to use
get_value #
Get the metadata value for a given value of cell_methods
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cell_methods
|
str
|
Cell methods |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Metadata value. If no matches are found, |
Source code in src/cmip_branded_variable_mapper/mapper_classes.py
sub_string_map_validator #
Validate the received map
The key here is that the keys can't lead to accidental clashes
Source code in src/cmip_branded_variable_mapper/mapper_classes.py
CellMethodsSubStringMapperOrdered #
Mapper that returns values based on matches of ordered sub-strings in cell methods
The ordering matters because it ensures that we don't get accidental clashes by checking for the longest possible match first.
Methods:
| Name | Description |
|---|---|
from_unordered |
Initialise from an unordered map |
get_value |
Get the metadata value for a given value of cell_methods |
sub_string_map_validator |
Validate the received map |
Attributes:
| Name | Type | Description |
|---|---|---|
sub_string_map |
tuple[tuple[str, str], ...]
|
Map from sub-strings of cell methods to the metadata value to use |
Source code in src/cmip_branded_variable_mapper/mapper_classes.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
sub_string_map
class-attribute
instance-attribute
#
Map from sub-strings of cell methods to the metadata value to use
The first element of each tuple is the sub-string to check for matches, the second element is the metadata value to use if this sub-string is a match.
These must be provide as a tuple of tuples to ensure that the ordering is preserved.
from_unordered
classmethod
#
from_unordered(
unordered_map: dict[str, str],
) -> CellMethodsSubStringMapperOrdered
Initialise from an unordered map
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unordered_map
|
dict[str, str]
|
Unordered map |
required |
Returns:
| Type | Description |
|---|---|
CellMethodsSubStringMapperOrdered
|
Initialised instance |
Source code in src/cmip_branded_variable_mapper/mapper_classes.py
get_value #
Get the metadata value for a given value of cell_methods
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cell_methods
|
str
|
Cell methods |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Metadata value. If no matches are found, |
Source code in src/cmip_branded_variable_mapper/mapper_classes.py
sub_string_map_validator #
Validate the received map
The key here is that the keys can't lead to accidental clashes
Source code in src/cmip_branded_variable_mapper/mapper_classes.py
DimensionMapper #
Mapper that returns values based on whether dimensions are present or not
Methods:
| Name | Description |
|---|---|
get_value |
Get the metadata value for a given value of dimensions |
Attributes:
| Name | Type | Description |
|---|---|---|
dimension_map |
dict[str, str]
|
Map from dimensions to the metadata value to use |
Source code in src/cmip_branded_variable_mapper/mapper_classes.py
dimension_map
instance-attribute
#
Map from dimensions to the metadata value to use
get_value #
Get the metadata value for a given value of dimensions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimensions
|
tuple[str, ...]
|
Dimensions to check |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Metadata value. If no matches are found, |