Metadata¶
envlib.metadata.Metadata
¶
Structured envlib dataset metadata with validation and normalization on set.
Construct all at once (Metadata(feature=..., variable=..., ...)) or
incrementally (meta = Metadata(); meta.feature = 'atmosphere'). Every
setter validates and normalizes; cross-field canonicalization (the
utc_offset reduction rule, which depends on frequency_interval) is
applied lazily at every read point, so construction order never matters.
feature, variable, method, processing_level,
aggregation_statistic, frequency_interval, and license are
CV-validated on set; per the validation-on-change-only rule, reading stored
metadata back (from_attrs(..., validate_cv=False)) trusts the stored
canonical values so vocabulary drift never orphans an existing dataset.
Source code in envlib/metadata.py
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 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 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 | |
dataset_id
property
¶
Deterministic id of the dataset, stable across versions (Identity fields minus version).
dataset_version_id
property
¶
Deterministic id of this version of the dataset (all 11 Identity fields; the catalogue entry key).
frequency_interval
property
writable
¶
Canonical envlib frequency code, or None for irregular cadences.
utc_offset
property
writable
¶
The canonical utc_offset, with the frequency reduction rule applied.
For fixed-duration cadences an offset that divides the cadence evenly
(identical binning to UTC) reduces to +00:00; likewise when
frequency_interval is None (no binning at all). Calendar cadences
(month/year) always retain the stored offset.
from_attrs(attrs, *, validate_cv=True)
classmethod
¶
Rebuild Metadata from envlib_-prefixed attrs (ds.attrs or a dict).
Non-envlib keys are ignored. When envlib_dataset_version_id /
envlib_dataset_id are present, the hash is re-derived from the
identity attrs and a mismatch raises (catches attrs hand-edited after
first registration).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attrs
|
Mapping
|
Mapping that may contain |
required |
validate_cv
|
bool
|
When False (re-reads of already-registered metadata), CV-membership checks are skipped and stored canonical values are trusted — the validation-on-change-only rule, so vocabulary drift never orphans existing datasets. Grammar-validated fields are always re-checked (their rules never drift). |
True
|
Source code in envlib/metadata.py
missing_fields()
¶
Identity fields still unset (nullable ones excepted) plus missing required General fields.
Source code in envlib/metadata.py
to_dict()
¶
Emit the envlib_-prefixed attr dict for ds.attrs.update().
Requires complete Identity metadata plus the required General fields (license, attribution). All 11 identity keys are always present (nullable ones as JSON null); optional General fields only when set; the computed dataset_version_id/dataset_id are included (self-identification).
Source code in envlib/metadata.py
envlib.metadata.compute_dataset_id(values)
¶
blake2b-12 hex of the 10 Identity fields excluding version — the dataset identity, stable across versions.
envlib.metadata.compute_dataset_version_id(values)
¶
blake2b-12 hex of all 11 Identity fields — identifies one version of a dataset.
This is the catalogue entry key. values must hold fully
normalized/canonical values (as produced by Metadata — including the
frequency-reduced utc_offset); prefer Metadata.dataset_version_id
unless you are certain the inputs are canonical.
Source code in envlib/metadata.py
envlib.metadata.compute_station_id(geometry)
¶
Deterministic station id from a shapely Point in EPSG:4326.
tethys-compatible derivation: z stripped if present; WKT round-trip with
rounding_precision=5 (~1 m at the equator); signed zero collapsed
(-0.0 -> 0.0, reachable after reprojection); explicit little-endian
WKB; keyless blake2b-12 hex. Same x/y at different z share a station_id.
Source code in envlib/metadata.py
envlib.metadata.ValidationError
¶
Bases: ValueError
Raised when metadata or dataset content fails envlib validation.
Subclasses ValueError so except ValueError keeps working for callers
that don't import envlib's exception.