climate_ref_core.pycmec.metric
#
CMEC diagnostic bundle class
Following the CMEC diagnostic bundle standards at https://github.com/Earth-System-Diagnostics-Standards/EMDS
To validate that a dictionary is compatible with the CMEC diagnostic bundle standards, please use: - class instantiation: cmec = CMECMetric(**result_dict) - class model_validate method: cmec = CMECMetric.model_validate(result_dict) Both ways will create the CMECMetric instance (cmec)
CMECGenerateJsonSchema
#
Bases: GenerateJsonSchema
Customized CMEC JSON schema generation
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
generate(schema, mode='validation')
#
Generate customized json schema
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
CMECMetric
#
Bases: BaseModel
CMEC diagnostic bundle object
Contains the diagnostics calculated during a diagnostic execution, in a standardised format.
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | |
DIMENSIONS
instance-attribute
#
Describes the dimensionality of the diagnostics produced.
This includes the order of dimensions in RESULTS
DISCLAIMER = None
class-attribute
instance-attribute
#
Disclaimer information
Not currently used in the REF.
NOTES = None
class-attribute
instance-attribute
#
Additional notes.
Not currently used in the REF.
PROVENANCE = None
class-attribute
instance-attribute
#
Provenance information
Not currently used in the REF. The provenance information from the output bundle is used instead
RESULTS
instance-attribute
#
The diagnostic values.
Results is a nested dictionary of values. The order of the nested dictionaries corresponds to the order of the dimensions.
create_template()
staticmethod
#
Return an empty dictionary in CMEC diagnostic bundle format
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
dump_to_json(json_file='./cmec.json')
#
Save the CMECMetric object to a file in JSON format
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_file
|
str | Path
|
JSON file path in the CMEC format to be saved |
'./cmec.json'
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
iter_results()
#
Iterate over the executions in the diagnostic bundle
This will yield a dictionary for each result, with the dimensions and the value
Returns:
| Type | Description |
|---|---|
A generator of diagnostic values
|
|
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
load_from_json(json_file)
classmethod
#
Create CMECMetric object from a compatible json file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_file
|
FilePath
|
JSON file path to be read |
required |
Returns:
| Type | Description |
|---|---|
Self
|
CMEC Diagnostic object if the file is CMEC-compatible |
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
merge(metric_obj1, metric_obj2)
classmethod
#
Merge two CMECMetric objects with the same json_structure
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_obj1
|
Any
|
First CMECMetric object to be merged |
required |
metric_obj2
|
Any
|
Second CMECMetric object to be merged |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Merged CMEC Diagnostic object |
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
prepend_dimensions(values)
#
Prepend the existing metric values with additional dimensions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
dict[str, str]
|
Additional metric dimensions and their values to be added to the metric bundle |
required |
Returns:
| Type | Description |
|---|---|
CMECMetric
|
A new CMECMetric object with the additional dimensions prepended to the existing metric bundle |
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
remove_dimensions(dimensions)
#
Remove the dimensions from the metric bundle
Currently only the first dimension is supported to be removed. Multiple dimensions can be removed at once, but only if they are in order from the first dimension..
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimensions
|
str | list[str]
|
The name of the dimension to be removed |
required |
Returns:
| Type | Description |
|---|---|
CMECMetric
|
A new CMECMetric object with the dimensions removed |
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
MetricCV
#
Bases: Enum
CMEC diagnostic bundle controlled vocabulary
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
MetricDimensions
#
Bases: RootModel[Any]
CMEC diagnostic bundle DIMENSIONS object
This describes the order of the dimensions and their possible values. The order of the dimensions matter as that determines how the executions are nested.
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 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 | |
add_dimension(dim_name, dim_content)
#
Add or update one dimension to MetricDimensions object
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dim_name
|
str
|
Name of new dimension to be added |
required |
dim_content
|
dict[str, Any]
|
Dictionary contains contents associated with dim_name |
required |
Returns:
| Type | Description |
|---|---|
None
|
CMEC MetricDimensions object with dim_name added |
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
merge_dimension(metric_dim1, metric_dim2)
classmethod
#
Merge two MetricDimensions objects
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_dim1
|
Any
|
First CMEC MetricDimensions object to be merged |
required |
metric_dim2
|
Any
|
Second CMEC MetricDimensions object to be merged |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Return a merged CMEC MetricDimensions object |
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
MetricResults
#
Bases: RootModel[Any]
CMEC diagnostic bundle RESULTS object
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
StrNumDict
#
Bases: RootModel[Any]
A class contains string key and numeric value
Source code in packages/climate-ref-core/src/climate_ref_core/pycmec/metric.py
remove_dimensions(raw_metric_bundle, dimensions)
#
Remove the dimensions from the raw metric bundle
Currently only the first dimension is supported to be removed. Multiple dimensions can be removed at once, but only if they are in order from the first dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_metric_bundle
|
dict[str, Any]
|
The raw metric bundle to be modified |
required |
dimensions
|
str | list[str]
|
The name of the dimensions to be removed |
required |
Returns:
| Type | Description |
|---|---|
The new, modified metric bundle with the dimension removed
|
|