NetCDF Data Models#
Immutable dataclasses for NetCDF metadata: variables, dimensions,
groups, CF info, and the top-level NetCDFMetadata container.
pyramids.netcdf.models.NetCDFMetadata
dataclass
#
Top-level metadata model for a NetCDF MDIM dataset.
Aggregates all structural and scientific metadata extracted from a NetCDF file opened through the GDAL multidimensional API: groups, variables, dimensions, global attributes, and driver information.
This is the single object returned by the metadata extraction pipeline and is intended as a complete, JSON-serializable snapshot of the file's structure.
Note
Dictionary keys for groups, variables, and
dimensions use short names with the leading
/ stripped (e.g. "time" not "/time").
The root group keeps "/" as its key. The
full_name attribute on each object retains the
original GDAL path (e.g. "/time"). Use
get_dimension(name) for lookups that accept
both forms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
driver
|
str
|
Short name of the GDAL driver used to
open the file (e.g. |
required |
root_group
|
str | None
|
Full name of the root group
(typically |
required |
groups
|
dict[str, GroupInfo]
|
Mapping keyed by short name (or |
required |
variables
|
dict[str, VariableInfo]
|
Mapping keyed by short name to
|
required |
dimensions
|
dict[str, DimensionInfo]
|
Mapping keyed by short name to
|
required |
global_attributes
|
dict[str, AttributeValue]
|
Key-value mapping of root-level
NetCDF attributes (e.g. |
required |
structural
|
StructuralInfo | None
|
Driver-level metadata, or |
required |
created_with
|
dict[str, str]
|
Version information for the tools
used to extract metadata (e.g.
|
required |
open_options_used
|
dict[str, str] | None
|
GDAL open options that were
passed when opening the file. |
None
|
Examples:
- Create a minimal NetCDFMetadata instance:
>>> from pyramids.netcdf.models import ( ... NetCDFMetadata, ... GroupInfo, ... VariableInfo, ... DimensionInfo, ... ) >>> dim = DimensionInfo( ... name="time", ... full_name="/time", ... size=12, ... ) >>> arr = VariableInfo( ... name="temp", ... full_name="/temp", ... dtype="float32", ... shape=[12], ... dimensions=["/time"], ... ) >>> grp = GroupInfo( ... name="root", ... full_name="/", ... variables=["/temp"], ... ) >>> meta = NetCDFMetadata( ... driver="netCDF", ... root_group="/", ... groups={"/": grp}, ... variables={"/temp": arr}, ... dimensions={"/time": dim}, ... global_attributes={"Conventions": "CF-1.6"}, ... structural=None, ... created_with={"gdal": "3.9.0"}, ... ) >>> meta.driver 'netCDF' >>> list(meta.dimensions.keys()) ['/time'] >>> meta.get_dimension("time").size 12
See Also
GroupInfo: Metadata for a single group. VariableInfo: Metadata for a single array. DimensionInfo: Metadata for a single dimension. StructuralInfo: Driver-level metadata.
Source code in src/pyramids/netcdf/models.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 | |
__str__()
#
Human-readable summary of the NetCDF structure.
Source code in src/pyramids/netcdf/models.py
__repr__()
#
Technical representation with counts and driver info.
Source code in src/pyramids/netcdf/models.py
get_dimension(name)
#
Look up a dimension by short name or full name.
Tries an exact key match against the dimensions
dictionary first (keys are full names with the leading
/ stripped, e.g. "/time" -> key "time",
"/group/time" -> key "group/time"), then falls
back to matching by the dimension's short name
attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Dimension short name (e.g. |
required |
Returns:
| Type | Description |
|---|---|
DimensionInfo | None
|
DimensionInfo | None: The matching dimension
metadata, or |
Examples:
-
Look up by short name:
>>> from pyramids.netcdf.models import ( ... NetCDFMetadata, ... DimensionInfo, ... ) >>> dim = DimensionInfo( ... name="time", ... full_name="/time", ... size=365, ... ) >>> meta = NetCDFMetadata( ... driver="netCDF", ... root_group="/", ... groups={}, ... variables={}, ... dimensions={"/time": dim}, ... global_attributes={}, ... structural=None, ... created_with={}, ... ) >>> meta.get_dimension("time").size 365 -
Look up by full name:
>>> from pyramids.netcdf.models import ( ... NetCDFMetadata, ... DimensionInfo, ... ) >>> dim = DimensionInfo( ... name="time", ... full_name="/time", ... size=365, ... ) >>> meta = NetCDFMetadata( ... driver="netCDF", ... root_group="/", ... groups={}, ... variables={}, ... dimensions={"/time": dim}, ... global_attributes={}, ... structural=None, ... created_with={}, ... ) >>> meta.get_dimension("/time").size 365 -
Return None for a missing dimension:
>>> from pyramids.netcdf.models import ( ... NetCDFMetadata, ... DimensionInfo, ... ) >>> meta = NetCDFMetadata( ... driver="netCDF", ... root_group="/", ... groups={}, ... variables={}, ... dimensions={}, ... global_attributes={}, ... structural=None, ... created_with={}, ... ) >>> meta.get_dimension("missing") is None True
See Also
NetCDFMetadata.dimensions: The full dimensions dictionary keyed by full name.
Source code in src/pyramids/netcdf/models.py
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 | |
pyramids.netcdf.models.VariableInfo
dataclass
#
Immutable metadata for a single MDIM array (variable).
Stores everything needed to describe a NetCDF variable without holding a reference to the live GDAL object: data type, shape, dimension links, CF attributes (scale, offset, nodata), spatial reference, and chunking information.
Note
frozen=True prevents field reassignment but container
fields (attributes, dimensions, etc.) are
technically mutable. Treat all contents as read-only
after construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Short variable name (e.g. |
required |
full_name
|
str
|
Fully qualified name including the group
path (e.g. |
required |
dtype
|
str
|
NumPy-compatible data type string
(e.g. |
required |
shape
|
list[int]
|
Size along each dimension, in dimension order. |
required |
dimensions
|
list[str]
|
Full names of the dimensions this array
spans, matching the order of |
required |
attributes
|
dict[str, AttributeValue]
|
Key-value mapping of variable-level NetCDF attributes. |
dict()
|
unit
|
str | None
|
Physical unit string from the |
None
|
nodata
|
int | float | str | None
|
No-data / fill value. |
None
|
scale
|
float | None
|
CF |
None
|
offset
|
float | None
|
CF |
None
|
srs_wkt
|
str | None
|
Spatial reference as WKT string.
|
None
|
srs_projjson
|
str | None
|
Spatial reference as PROJJSON string.
|
None
|
coordinate_variables
|
list[str]
|
Full names of coordinate variables associated with this array. |
list()
|
structural_info
|
dict[str, str] | None
|
Driver-specific structural info
dictionary. |
None
|
block_size
|
list[int] | None
|
Chunk sizes along each dimension.
|
None
|
Examples:
-
Create metadata for a 2-D temperature variable:
-
Create metadata for a 3-D variable with scale and offset:
>>> from pyramids.netcdf.models import VariableInfo >>> arr = VariableInfo( ... name="precip", ... full_name="/precip", ... dtype="int16", ... shape=[365, 180, 360], ... dimensions=["/time", "/lat", "/lon"], ... scale=0.01, ... offset=0.0, ... block_size=[1, 180, 360], ... ) >>> arr.scale 0.01 >>> arr.block_size [1, 180, 360]
See Also
DimensionInfo: Metadata for the dimensions that an array spans. GroupInfo: Metadata for the group containing this array.
Source code in src/pyramids/netcdf/models.py
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 | |
from_md_array(md_arr, md_arr_name, group_full_name)
classmethod
#
Build a VariableInfo from a live GDAL MDArray.
Extracts name, data type, shape, dimension links,
attributes, CF conventions (scale, offset, nodata),
spatial reference, structural info, and chunk sizes
from the GDAL MDArray handle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
md_arr
|
MDArray
|
The GDAL multidimensional array object. |
required |
md_arr_name
|
str
|
Fallback short name used when the
array's own |
required |
group_full_name
|
str
|
Full name of the parent group (used as a fallback prefix for constructing the array's full name). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
VariableInfo |
VariableInfo
|
Constructed metadata instance for the array. |
See Also
DimensionInfo.from_gdal_dim: Analogous factory for dimension metadata.
Source code in src/pyramids/netcdf/models.py
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 | |
pyramids.netcdf.models.DimensionInfo
dataclass
#
Immutable metadata for a single NetCDF dimension.
Captures the name, size, type, direction, and any
attributes inherited from the dimension's indexing
variable (e.g. units and calendar for a time
dimension).
Note
frozen=True prevents field reassignment but the
attrs dict is technically mutable. Treat its
contents as read-only after construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Short name of the dimension (e.g. |
required |
full_name
|
str
|
Fully qualified path name
(e.g. |
required |
size
|
int
|
Number of elements along this dimension. |
required |
type
|
str | None
|
Dimension type string reported by GDAL, such
as |
None
|
direction
|
str | None
|
Direction string (e.g. |
None
|
indexing_variable
|
str | None
|
Full name (or short name) of the
variable that indexes this dimension.
|
None
|
attrs
|
dict[str, Any]
|
Attributes read from the indexing variable
(e.g. |
dict()
|
Examples:
-
Create a spatial dimension:
-
Create a time dimension with calendar attributes:
See Also
VariableInfo: Metadata for variables that reference these dimensions. NetCDFMetadata.get_dimension: Look up a dimension by name.
Source code in src/pyramids/netcdf/models.py
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 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 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
from_gdal_dim(d, group_full_name)
classmethod
#
Build a DimensionInfo from a live GDAL Dimension.
Reads name, size, type, direction, and indexing
variable information from the GDAL Dimension
handle. Attributes are extracted from the indexing
variable when one exists (e.g. units and
calendar on a time coordinate).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Dimension
|
The GDAL multidimensional |
required |
group_full_name
|
str
|
Full name of the parent group (used as a fallback prefix when the dimension does not report its own full name). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
DimensionInfo |
DimensionInfo
|
Constructed metadata instance for the dimension. |
See Also
GroupInfo.from_group: Analogous factory for group metadata.
Source code in src/pyramids/netcdf/models.py
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 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
pyramids.netcdf.models.GroupInfo
dataclass
#
Immutable metadata for a single MDIM group in a NetCDF file.
All fields are JSON-serializable and use full names
(e.g. "/root/subgroup") for stable cross-references
between groups, variables, and dimensions.
Note
frozen=True prevents field reassignment but container
fields (attributes, children, variables) are
technically mutable. Treat all contents as read-only
after construction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Short name of the group (e.g. |
required |
full_name
|
str
|
Fully qualified name including the path
(e.g. |
required |
attributes
|
dict[str, AttributeValue]
|
Key-value mapping of group-level attributes read from the NetCDF file. |
dict()
|
children
|
list[str]
|
Full names of direct child groups. |
list()
|
variables
|
list[str]
|
Full names of variables belonging to this group. |
list()
|
Examples:
-
Create a GroupInfo for the root group:
>>> from pyramids.netcdf.models import GroupInfo >>> info = GroupInfo( ... name="root", ... full_name="/", ... attributes={"Conventions": "CF-1.6"}, ... children=["/forecast"], ... variables=["/temperature", "/pressure"], ... ) >>> info.name 'root' >>> info.full_name '/' >>> info.attributes {'Conventions': 'CF-1.6'} -
Create a minimal GroupInfo with defaults:
See Also
VariableInfo: Metadata for individual variables within a group. StructuralInfo: Driver-level metadata for the dataset.
Source code in src/pyramids/netcdf/models.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 | |
from_group(group, *, variables, children, attributes=None)
classmethod
#
Build a GroupInfo from a live GDAL Group object.
Extracts the group name, full name, and attributes
from the GDAL Group handle and bundles them into
an immutable GroupInfo instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
Group
|
The GDAL multidimensional group object. |
required |
variables
|
list[str]
|
Full names of variables that belong to
this group (e.g. |
required |
children
|
list[str]
|
Full names of direct child groups
(e.g. |
required |
attributes
|
dict[str, AttributeValue] | None
|
Pre-read attributes dictionary. If
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
GroupInfo |
GroupInfo
|
Constructed metadata instance for the group. |
See Also
VariableInfo.from_md_array: Analogous factory for variable metadata.
Source code in src/pyramids/netcdf/models.py
pyramids.netcdf.models.CFInfo
dataclass
#
CF convention metadata derived by cross-referencing variables.
Computed as a post-processing step in MetadataBuilder.build()
after all variables, dimensions, and attributes are collected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cf_version
|
str | None
|
CF version string parsed from |
None
|
conventions
|
dict[str, str]
|
Parsed |
dict()
|
classifications
|
dict[str, str]
|
Per-variable CF role classification as
|
dict()
|
grid_mappings
|
dict[str, dict[str, Any]]
|
Grid mapping variable attributes as
|
dict()
|
bounds_map
|
dict[str, str]
|
Bounds associations as
|
dict()
|
data_variable_names
|
list[str]
|
Variable names classified as |
list()
|
Source code in src/pyramids/netcdf/models.py
pyramids.netcdf.models.StructuralInfo
dataclass
#
Immutable driver-level metadata for a GDAL dataset.
Captures the driver name and its associated metadata dictionary, providing context about how the file was opened and which GDAL driver capabilities are available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
driver_name
|
str
|
Short name of the GDAL driver
(e.g. |
required |
driver_metadata
|
dict[str, str] | None
|
Key-value metadata reported by the
driver (e.g. creation options, version info).
|
None
|
Examples:
-
Create structural info for a NetCDF driver:
-
Create structural info without driver metadata:
See Also
NetCDFMetadata: Top-level model that includes a
StructuralInfo instance.
Source code in src/pyramids/netcdf/models.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | |
from_dataset(dataset, driver_name)
classmethod
#
Build a StructuralInfo from a live GDAL Dataset.
Reads the driver metadata dictionary from the dataset's driver handle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
An open GDAL |
required |
driver_name
|
str
|
Short name of the GDAL driver
(e.g. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StructuralInfo |
StructuralInfo
|
Constructed metadata instance containing the driver name and its metadata dictionary. |
See Also
NetCDFMetadata: The top-level model that aggregates structural info with groups, variables, and dimensions.