climate_ref.datasets.cmip6_parsers
#
CMIP6 parser functions for extracting metadata from netCDF files
Additional non-official DRS's may be added in the future.
extract_attr_with_regex(input_str, regex, strip_chars=None, ignore_case=True)
#
Extract an attribute from a string using a regex pattern
If multiple matches are found, the longest match is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_str
|
str
|
String to search |
required |
regex
|
str
|
Regular expression pattern |
required |
strip_chars
|
str | None
|
Characters to strip from the match |
None
|
ignore_case
|
bool
|
Whether to ignore case when matching |
True
|
Returns:
| Type | Description |
|---|---|
str | None
|
The longest match, or None if no match is found |
Source code in packages/climate-ref/src/climate_ref/datasets/cmip6_parsers.py
parse_cmip6_complete(file, **kwargs)
#
Complete parser for CMIP6 files
This parser loads each file and extracts all available metadata.
For some filesystems this may be slow, as it involves a lot of I/O operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
File to parse |
required |
kwargs
|
Any
|
Additional keyword arguments (not used, but required for compatibility) |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with extracted metadata |
Source code in packages/climate-ref/src/climate_ref/datasets/cmip6_parsers.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
parse_cmip6_drs(file, **kwargs)
#
DRS parser for CMIP6 files
This parser extracts metadata according to the CMIP6 Data Reference Syntax (DRS). This includes the essential metadata required to identify the dataset and is included in the filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
File to parse |
required |
kwargs
|
Any
|
Additional keyword arguments (not used, but required for compatibility) |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with extracted metadata |
Source code in packages/climate-ref/src/climate_ref/datasets/cmip6_parsers.py
parse_cmip6_using_directories(file)
#
Extract attributes of a file using information from CMIP6 DRS
The CMIP6 filename convention uses _ as a delimiter between fields.
Fields may contain - internally but never _.
Filename format::
<variable_id>_<table_id>_<source_id>_<experiment_id>_<member_id>_<grid_label>[_<time_range>].nc
For time-invariant fields the time_range segment is omitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
Path to the CMIP6 file |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with extracted metadata, or INVALID_ASSET dict on failure |