AbstractDataSource#
Base classes that define the interface for all data source implementations.
earthlens.base.AbstractDataSource
#
Bases: ABC
Blueprint for every concrete data-source backend.
Subclasses encapsulate the request shape, authentication, and
download orchestration for a single provider (CHIRPS, ERA5 on AWS
S3, ECMWF CDS, Google Earth Engine). The base class wires the
abstract hooks (:meth:_initialize, :meth:_create_grid,
:meth:_check_input_dates) into a uniform __init__ shape and
exposes a single :meth:download entry point.
Attributes:
| Name | Type | Description |
|---|---|---|
OUTPUT_KIND |
OutputKind
|
Class-level declaration of the natural output
shape this backend emits. Read by
:class: |
Source code in src/earthlens/base/abstractdatasource.py
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 574 575 576 577 | |
__init__(start, end, variables, lat_lim, lon_lim, temporal_resolution='daily', fmt='%Y-%m-%d', path='')
#
Initialize a data source instance.
Captures the return values of the abstract hooks so subclasses
do not have to wire them onto self themselves:
self.client— whatever :meth:_initializereturns (a CDS client, an S3 client,Nonefor FTP). Subclasses that assignself.clientinside :meth:_initialize(e.g. :class:S3) keep their own assignment; the parent only sets the attribute when :meth:_initializereturns a non-Nonevalue.self.space— the dict returned by :meth:_create_grid, containinglat_limandlon_lim. Subclasses that override :meth:_create_gridto set attributes directly (e.g. :class:CHIRPS) and returnNoneare unaffected.self.time— the dict returned by :meth:_check_input_dates, containingstart_date,end_date,time_freqanddates. Same opt-in semantics asself.space.self.root_dir— the absolute :class:pathlib.Pathof the output directory.self.pathis kept as a legacy alias so older backends (CHIRPS, S3) continue to work.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
str
|
Inclusive start date as a string. Format controlled
by |
required |
end
|
str
|
Inclusive end date as a string. Defaults to |
required |
variables
|
dict[str, list[str]] | list[str]
|
List of variable short codes to download. |
required |
temporal_resolution
|
str
|
|
'daily'
|
lat_lim
|
list[float]
|
|
required |
lon_lim
|
list[float]
|
|
required |
fmt
|
str
|
|
'%Y-%m-%d'
|
path
|
Path | str
|
Output directory. Created if it does not exist. Defaults to the current working directory. |
''
|
Source code in src/earthlens/base/abstractdatasource.py
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 | |
download()
abstractmethod
#
Wrapper over all the given variables.
earthlens.base.AbstractCatalog
#
Bases: BaseModel
Abstract base class for per-data-source variable catalogs.
Subclasses load a backend-specific catalog (a YAML file, an
in-code dict, or a remote query) in :meth:get_catalog and
expose individual entries via :meth:get_variable. The
:func:model_post_init hook eagerly populates :attr:catalog
after pydantic validation runs, so subclasses can treat the
catalog as a dict thereafter without writing their own
__init__.
Subclasses pass through pydantic's normal BaseModel.__init__
— declare any backend-specific construction parameters as
pydantic fields rather than __init__ arguments. Override
:meth:get_catalog (and optionally :meth:get_variable); the
base implementations raise :class:NotImplementedError to flag
a missing override at first use rather than silently returning
an empty mapping.
Attributes:
| Name | Type | Description |
|---|---|---|
catalog |
dict[str, Any]
|
The full catalog mapping returned by
:meth: |
Source code in src/earthlens/base/abstractdatasource.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 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 | |
__getitem__(name)
#
cat[name] — dict-style lookup; raises KeyError on miss.
__repr__()
#
Compact developer repr — counts, not contents.
__str__()
#
Pretty-print the curated datasets map as YAML.
None-valued fields are omitted so the output stays readable;
the ordering of keys follows insertion. Concrete subclasses
whose dataset values aren't pydantic BaseModels (rare) must
override.
Source code in src/earthlens/base/abstractdatasource.py
get_catalog()
#
Read the catalog of the datasource from disk or retrieve it from server.
Abstract; concrete subclasses must override and return their
backend-specific catalog object (e.g. a pydantic Catalog
instance, a dict, or whatever shape the backend uses).
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always, until overridden by a subclass. |
Source code in src/earthlens/base/abstractdatasource.py
get_dataset(name)
#
Return the dataset record for name, with a did-you-mean hint on miss.
Backend-generic: looks up name in :attr:datasets and raises
ValueError (not KeyError) with the closest known name when
absent. Concrete subclasses can override to narrow the return
type or customise the error message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Catalog key (e.g. CDS dataset short name, EE asset id, CHC dataset key). |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The matching dataset record (type depends on the subclass). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/earthlens/base/abstractdatasource.py
get_provider(slug)
#
Return the :class:Provider for slug (with a did-you-mean hint on miss).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
A registered provider slug (e.g. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The matching :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/earthlens/base/abstractdatasource.py
model_post_init(__context)
#
Populate :attr:catalog after pydantic validation runs.
Pydantic calls this hook automatically; subclasses that need
their own post-init wiring should override it and call
super().model_post_init(__context) first to keep the
catalog-loading behaviour.