NetCDF Utilities#
Low-level GDAL helpers for attribute reading, no-data extraction, scale/offset handling, time conversion, and dtype utilities.
pyramids.netcdf.utils
#
create_time_conversion_func(units, out_format='%Y-%m-%d %H:%M:%S', calendar='standard')
#
Create a converter that maps numeric CF time offsets to date strings.
Parses CF-compliant time unit strings (e.g.,
"days since 1979-01-01") and returns a callable that
converts numeric offsets to formatted date strings.
For standard/proleptic_gregorian calendars, uses Python's
datetime + timedelta. For non-standard calendars
(360_day, noleap, all_leap, julian), uses
cftime.num2date() (optional dependency).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
units
|
str
|
CF time unit string in the format
|
required |
out_format
|
str
|
strftime format for the output strings.
Defaults to |
'%Y-%m-%d %H:%M:%S'
|
calendar
|
str
|
CF calendar type. Defaults to |
'standard'
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
A function that takes a numeric value and returns a formatted date string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the unit string cannot be parsed or uses an unsupported time unit. |
ImportError
|
If a non-standard calendar is requested
and |
Examples:
-
Convert day offsets from a 1979 origin:
-
Use hour-based units with a custom format:
See Also
_parse_units_origin: Parses the unit string.
Source code in src/pyramids/netcdf/utils.py
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 537 538 539 540 541 542 543 544 545 546 547 548 549 | |