utils module¶
Shared utility functions used across easysnowdata modules.
CredentialError
¶
Bases: Exception
Raised when required credentials are missing or not yet configured.
HLS_xml_url_to_metadata_df(url)
¶
Parse an HLS granule XML metadata URL into a one-row DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Full URL to an HLS XML metadata file (NASA CMR or direct link). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One-row DataFrame with columns:
|
Notes
HLS (Harmonized Landsat Sentinel) metadata is produced by NASA LP DAAC.
Source code in easysnowdata/utils.py
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 | |
convert_bbox_to_geodataframe(bbox_input)
¶
Convert a bounding-box input of any supported type to a GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox_input
|
GeoDataFrame or tuple or geometry or None
|
Accepted forms:
|
required |
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
Single-row GeoDataFrame in EPSG:4326. |
Source code in easysnowdata/utils.py
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 | |
datetime_to_DOWY(date, hemisphere='northern')
¶
Convert a date to the day-of-water-year (DOWY).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
Timestamp or str
|
The date to convert. Strings are parsed by :func: |
required |
hemisphere
|
str
|
|
'northern'
|
Returns:
| Type | Description |
|---|---|
int or float
|
Day of the water year (1-indexed), or |
Source code in easysnowdata/utils.py
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
datetime_to_WY(date, hemisphere='northern')
¶
Convert a date to its water year (WY).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
Timestamp or str
|
The date to convert. Strings are parsed by :func: |
required |
hemisphere
|
str
|
|
'northern'
|
Returns:
| Type | Description |
|---|---|
int or float
|
The water year as a calendar year integer, or |
Notes
For the northern hemisphere, the water year is the calendar year in which the water year ends (i.e. WY 2021 runs Oct 1 2020 – Sep 30 2021).
Source code in easysnowdata/utils.py
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 | |
get_ee_grid_params(ee_obj, bbox_gdf=None)
¶
Build the pixel-grid kwargs required by xarray.open_dataset(engine="ee").
xee >= 0.1 no longer accepts geometry / scale / projection; the
output grid must instead be given explicitly as crs, crs_transform
and shape_2d. This helper derives those from the native grid of an
Earth Engine object and, optionally, crops the grid to a bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ee_obj
|
Image or ImageCollection
|
Object whose native projection defines the grid. For a collection the
first band of the first image is used (via
|
required |
bbox_gdf
|
GeoDataFrame
|
Area of interest, in any CRS. The grid is cropped to the smallest block
of native pixels that fully covers it, so the returned pixels are exact
native values rather than a resampled copy. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in easysnowdata/utils.py
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 | |
get_stac_cfg(sensor='sentinel-2-l2a')
¶
Return an ODC-STAC band configuration dict for common sensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensor
|
str
|
Sensor identifier. Supported values: |
'sentinel-2-l2a'
|
Returns:
| Type | Description |
|---|---|
dict
|
STAC configuration dict suitable for |
Raises:
| Type | Description |
|---|---|
ValueError
|
If sensor is not a recognised identifier. |
Source code in easysnowdata/utils.py
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 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | |
get_water_year_start(date, hemisphere)
¶
Return the start date of the water year containing date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
Timestamp
|
Any date within the water year of interest. |
required |
hemisphere
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
Timestamp
|
The first day of the corresponding water year. |
Source code in easysnowdata/utils.py
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | |
initialize_earthengine(**kwargs)
¶
Initialise Google Earth Engine, honouring EARTHENGINE_TOKEN if set.
With EARTHENGINE_TOKEN set (see :func:_ee_credentials_from_token) the
credentials it encodes are used — this is how CI authenticates. Otherwise
ee.Initialize() falls back to the credentials stored by
ee.Authenticate(). Uses the high-volume endpoint unless opt_url /
url is given. Extra keyword arguments are passed to ee.Initialize.
Source code in easysnowdata/utils.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
requires_earthaccess(func)
¶
Decorator: raise CredentialError with setup instructions if EarthData credentials are missing.
Source code in easysnowdata/utils.py
325 326 327 328 329 330 331 332 333 334 335 336 | |
requires_earthengine(func)
¶
Decorator: raise CredentialError with setup instructions if EE credentials are missing.
Source code in easysnowdata/utils.py
311 312 313 314 315 316 317 318 319 320 321 322 | |
suppress_stdout()
¶
Context manager that silences stdout for noisy third-party calls.
Source code in easysnowdata/utils.py
339 340 341 342 343 | |