util
calc_13_category_usda_soil_type(clay, sand, silt)
Calculate the 13 category USDA soil type from clay, sand, and silt percentages.
The categories are: 0 -- WATER 1 -- SAND 2 -- LOAMY SAND 3 -- SANDY LOAM 4 -- SILT LOAM 5 -- SILT 6 -- LOAM 7 -- SANDY CLAY LOAM 8 -- SILTY CLAY LOAM 9 -- CLAY LOAM 10 -- SANDY CLAY 11 -- SILTY CLAY 12 -- CLAY
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clay
|
DataArray or ndarray
|
Percentage of clay (0-100). |
required |
sand
|
DataArray or ndarray
|
Percentage of sand (0-100). |
required |
silt
|
DataArray or ndarray
|
Percentage of silt (0-100). |
required |
Returns:
| Type | Description |
|---|---|
DataArray or ndarray
|
The 13-category USDA soil type. |
Source code in monetio/util.py
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 | |
ds_to_2d(ds, pivot=True, fixed_location=False)
Lazily transform a 1D UGRID dataset into a 2D (time, node) dataset. If 'variable' is present in coordinates and pivot=True, it also pivots the data variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Input 1D dataset with 'time' and 'siteid' coordinates. |
required |
pivot
|
bool
|
Whether to pivot by 'variable' column if present, by default True. |
True
|
fixed_location
|
bool
|
Whether to enforce fixed latitude/longitude/elevation per node, by default False. |
False
|
Returns:
| Type | Description |
|---|---|
Dataset
|
2D expanded dataset with dimensions (time, node). |
Source code in monetio/util.py
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 | |
force_object_strings(df)
Force string columns to 'object' dtype to avoid nullable string issues in Pandas/Dask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
Union[DataFrame, DataFrame]
|
Input dataframe. |
required |
Returns:
| Type | Description |
|---|---|
Union[DataFrame, DataFrame]
|
Dataframe with string columns cast to object. |
Source code in monetio/util.py
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 | |
get_nc_attrs(nc_obj)
Safe retrieval of attributes from both netCDF4 and h5netcdf.
Source code in monetio/util.py
507 508 509 510 511 512 513 | |
get_nc_values(nc_var)
Safe retrieval of masked and scaled values from both netCDF4 and h5netcdf.
Source code in monetio/util.py
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 | |
get_nc_var(dso, group_path, varname)
Safe retrieval of a variable from nested groups in both netCDF4 and h5netcdf.
Source code in monetio/util.py
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 | |
kolmogorov_zurbenko_filter(df, window, iterations)
KZ filter implementation series is a pandas series window is the filter window m in the units of the data (m = 2q+1) iterations is the number of times the moving average is evaluated
Source code in monetio/util.py
115 116 117 118 119 120 121 122 123 124 | |
long_to_wide(df)
Convert a long-format DataFrame (or Dask DataFrame) to wide format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
Union[DataFrame, DataFrame]
|
The input DataFrame in long format, containing 'time', 'siteid', 'variable', 'obs', and 'units'. |
required |
Returns:
| Type | Description |
|---|---|
Union[DataFrame, DataFrame]
|
The DataFrame in wide format. |
Source code in monetio/util.py
135 136 137 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 | |
normalize_pandas_freq(freq)
Normalize pandas frequency codes for compatibility with pandas 3.0+.
'h' instead of 'H' (mandatory in 3.0) 'D' instead of 'd' (recommended in 3.0) 'ME' instead of 'M' or 'm' 'QE' instead of 'Q' or 'q' 'YE' instead of 'A' or 'a' or 'ye' or 'Y' or 'y'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq
|
str
|
Input frequency code. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Normalized frequency code. |
Source code in monetio/util.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 | |