UgridDataset#
Top-level container for UGRID NetCDF mesh data. Provides the user-facing API for reading, writing, inspecting, and operating on unstructured mesh data.
UgridDataset is a thin, GIS-aware facade: its public methods delegate the heavy lifting to the
sibling modules of the subpackage (spatial ops, interpolation, I/O, plotting):
flowchart LR
U["UgridDataset"]
U -->|"clip · subset_by_bounds"| SP["spatial.clip_mesh<br/>spatial.subset_by_bounds"]
U -->|"to_dataset"| IN["interpolation.mesh_to_grid"]
U -->|"read_file · to_file"| IO["io.parse_ugrid_topology<br/>io.write_ugrid_topology"]
U -->|"plot · plot_outline"| PL["plot.plot_mesh_data<br/>plot.plot_mesh_outline"]
U -->|"metadata"| MD["UgridMetadata"]
See the subpackage overview for how UgridDataset composes Mesh2d, Connectivity, and
MeshVariable.
pyramids.netcdf.ugrid.UgridDataset
#
Bases: _UgridFacades
Container for UGRID NetCDF mesh data.
Combines mesh topology, data variables, and global attributes into a single object with GIS-aware operations. Does NOT inherit from Dataset or RasterBase — the raster paradigm does not apply to unstructured meshes.
Attributes:
| Name | Type | Description |
|---|---|---|
_mesh |
Mesh2d topology instance. |
|
_data_variables |
Mapping of variable name to MeshVariable. |
|
_global_attributes |
File-level NetCDF attributes. |
|
_topology_info |
Parsed UGRID topology metadata. |
|
_crs_wkt |
CRS in WKT format. |
|
_file_name |
Source file path, if read from disk. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 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 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 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 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 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 | |
mesh
property
#
The mesh topology.
mesh_name
property
#
Name of the mesh topology variable.
data_variable_names
property
#
Names of all data variables.
crs
property
#
CRS as a pyproj.CRS object, or None. Cached after first access.
epsg
property
#
EPSG code of the CRS, or None.
crs_wkt
property
#
The mesh CRS as WKT, or None when there is none that parses.
Gated on a successful parse rather than returning _crs_wkt verbatim.
_crs_wkt is copied straight out of the file and :attr:crs tolerates
an unparseable one on purpose, swallowing the error and reporting no
CRS. Handing the raw string to a caller would move that parse out from
under the handler, so a malformed WKT would start raising downstream
instead of being reported as "no CRS" here.
bounds
property
#
Mesh bounding box as (xmin, ymin, xmax, ymax).
global_attributes
property
#
File-level NetCDF attributes.
n_node
property
#
Number of mesh nodes.
n_face
property
#
Number of mesh faces.
n_edge
property
#
Number of mesh edges.
data_vars
property
#
A copy of the {name: variable} mapping.
A fresh dict, so mutating it never changes the dataset — variable edits go through
:meth:with_variable / :meth:drop_variables / :meth:rename_variable, which each
return a new dataset.
metadata
property
#
Full metadata summary for this dataset.
time_values
property
#
Parsed time coordinate values from the first temporal variable.
Returns None if no variables have a time dimension.
volume_topology
property
#
The ragged (per-column) vertical layering, or None for a uniform / 2-D mesh.
Present only for a genuinely 3-D mesh whose columns carry different layer counts
(issue #1330): it maps each face to its slice of the flat volume axis that a
location="volume" variable is indexed through. None means the dense
(layer, element) path applies — the uniform-layer behaviour is unchanged.
n_volume
property
#
The total number of volumes, or None when the mesh has no volume topology.
The flat volume-axis length of a ragged 3-D mesh (the sum of every column's layer
count). None for a 2-D or uniform-layer mesh, where :attr:n_layers applies
instead.
n_layers
property
#
The number of layers, or None when no variable is layered.
A 3-D mesh output puts some variables on the n layer centres and others on the
n + 1 layer interfaces, so two counts differing by one is normal rather than a
contradiction; this reports n, the layer count proper. Any other disagreement is
a real inconsistency and raises. :meth:isel_layer is unaffected either way — it
indexes each variable on its own layer axis.
Reporting n means the n + 1 is not visible here, so a caller iterating
range(n_layers) over an interface variable would skip its last interface. Read
:attr:n_layer_interfaces for that count rather than inferring it: it answers None
unless a variable really sits on the interfaces.
For a ragged 3-D mesh (:attr:volume_topology set) there is no single layer count:
this reports the maximum over the columns — the number of layer slots — so
range(n_layers) covers the deepest column, and :meth:isel_layer makes the absent
shallow-column layers explicit (NaN) rather than padding them silently.
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The layer-centre count (the max, for a ragged mesh), or |
int | None
|
no variable is layered. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The layered variables carry counts that are not a layer-centre / layer-interface pair. |
n_layer_interfaces
property
#
The number of layer interfaces, or None when nothing sits on them.
The companion to :attr:n_layers. A 3-D output's vertical velocities and fluxes live on
the n + 1 interfaces between the n layer centres, and n_layers deliberately
reports the centre count -- so this is where the other half of the pair is readable.
It is not simply n_layers + 1, which is always computable: that would assert
that something in the dataset is interface-located. Only a variable actually carrying
that count makes it true, so a centres-only dataset answers None.
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The layer-interface count, or |
int | None
|
every layered variable sits on the centres. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The layered variables carry counts that are not a layer-centre /
layer-interface pair -- the same guard :attr: |
layer_values
property
#
The layer coordinate values, when a layered variable carries them.
Read from a layered variable's layer_values attribute. The UGRID reader does not
populate that attribute -- as with :attr:time_values, the coordinate is supplied by
whoever builds or transforms the dataset -- so this is normally None for a mesh
read straight from a file, and :meth:sel_layer then selects by layer position.
connected_components()
#
Label the mesh's connected face components.
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: One component label per face. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
focal_mean(rings=1, variable_name=None, reach=None)
#
The mean of each face's k-ring neighbourhood, centre included (issue #1376).
The mesh counterpart of the raster focal_mean. The raster version aggregates over a
(2*radius+1) pixel window, which has no meaning here — faces have neither a
row/column address nor a fixed neighbour count. This aggregates over the faces within
rings hops of the face adjacency instead, which is why the parameter is rings
and not radius.
Boundary faces aggregate over whatever neighbours they have: no padding, no fabricated
values. nodata faces are excluded, and so are inactive ones when the variable
carries an active mask — a dry neighbour should not drag a wet face's mean down.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rings
|
int
|
Adjacency hops the neighbourhood spans. Defaults to 1. |
1
|
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
reach
|
Any
|
A neighbourhood matrix to reuse across calls, built with
|
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Per-face mean of length |
ndarray
|
holds no usable value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
See Also
focal_std: Spread over the same neighbourhood. focal_apply: An arbitrary aggregation over the same neighbourhood.
Source code in src/pyramids/netcdf/ugrid/_facades.py
focal_std(rings=1, variable_name=None, reach=None)
#
The standard deviation of each face's k-ring neighbourhood (issue #1376).
The spread counterpart of :meth:focal_mean, with the same neighbourhood, exclusion
and boundary conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rings
|
int
|
Adjacency hops the neighbourhood spans. Defaults to 1. |
1
|
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
reach
|
Any
|
A neighbourhood matrix to reuse across calls, built with
|
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Per-face population standard deviation; |
ndarray
|
neighbourhood holds no usable value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
See Also
focal_mean: The mean over the same neighbourhood.
Source code in src/pyramids/netcdf/ugrid/_facades.py
focal_apply(func, rings=1, variable_name=None, reach=None)
#
Aggregate each face's k-ring neighbourhood with func (issue #1376).
func receives the 1-D array of usable values in one neighbourhood and returns a
scalar, so np.ptp, np.median or a lambda all work. Unlike :meth:focal_mean
and :meth:focal_std this cannot be expressed as a sparse product, so it visits each
face in turn — noticeably slower on a large mesh, which is the price of an arbitrary
aggregation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Any
|
Callable taking a 1-D array and returning a scalar. |
required |
rings
|
int
|
Adjacency hops the neighbourhood spans. Defaults to 1. |
1
|
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
reach
|
Any
|
A neighbourhood matrix to reuse across calls, built with
|
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Per-face aggregate; |
ndarray
|
value, so |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
See Also
focal_mean: The vectorised mean, when that is all you need.
Source code in src/pyramids/netcdf/ugrid/_facades.py
slope(units='degrees', variable_name=None)
#
Per-face slope of a mesh DEM, in degrees (default) or radians (issue #1374).
An unstructured bed-level mesh is a DEM. The raster version reads a 3x3 pixel window, which has no mesh equivalent; this fits a plane through each face's own node elevations and reads the slope off that -- exact for a triangle, least-squares for a polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
units
|
str
|
|
'degrees'
|
variable_name
|
str | None
|
The elevation variable (default: the only one). A face-located one is averaged onto the nodes first. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Per-face slope of length |
ndarray
|
and on any face touching a |
ndarray
|
which is the contract the raster kernels state too. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
See Also
aspect: The direction the slope faces. hillshade: Shaded relief from the same gradient.
Source code in src/pyramids/netcdf/ugrid/_facades.py
aspect(variable_name=None)
#
Per-face aspect of a mesh DEM, in degrees clockwise from north (issue #1374).
Names the direction the slope faces (downhill), matching the raster convention: a surface rising to the east faces west, 270 degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
The elevation variable (default: the only one). |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Per-face aspect in |
ndarray
|
on any face touching a |
Raises:
| Type | Description |
|---|---|
ValueError
|
The variable is edge-located, or is not one value per element. |
See Also
slope: The magnitude of the same gradient.
Source code in src/pyramids/netcdf/ugrid/_facades.py
hillshade(azimuth=315.0, altitude=45.0, variable_name=None)
#
Per-face shaded relief of a mesh DEM, clipped to 0..255 (issue #1374).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
azimuth
|
float
|
Sun azimuth in degrees (0 = north, 90 = east). Defaults to 315 (NW). |
315.0
|
altitude
|
float
|
Sun altitude above the horizon in degrees. Defaults to 45. |
45.0
|
variable_name
|
str | None
|
The elevation variable (default: the only one). |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Per-face intensity in |
ndarray
|
and on any face touching a |
ndarray
|
flat mesh saturates at |
Raises:
| Type | Description |
|---|---|
ValueError
|
The variable is edge-located, or is not one value per element. |
See Also
slope: The slope magnitude the shading is derived from.
Source code in src/pyramids/netcdf/ugrid/_facades.py
cluster(lower, upper, variable_name=None)
#
Label connected groups of faces whose values fall in [lower, upper] (#1379).
The value-aware sibling of :meth:connected_components, and the mesh counterpart of
the raster cluster. :meth:connected_components labels by topology alone, so
it cannot answer "which separate pools of flooded cells are there"; this restricts the
face adjacency to the faces inside the range before labelling.
Faces outside the range — and no-data faces, which cannot be inside one — are labelled
0, so a label is truthy exactly when the face belongs to a cluster. Clusters are
numbered 1..k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lower
|
float
|
Inclusive lower bound. |
required |
upper
|
float
|
Inclusive upper bound. |
required |
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset whose variable carries the per-face cluster labels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The variable is not one value per face (select a step first). |
See Also
connected_components: Topology-only labelling, ignoring values. footprint: The dissolved outline of the faces carrying valid values.
Source code in src/pyramids/netcdf/ugrid/_facades.py
footprint(variable_name=None)
#
The dissolved outline of the faces carrying valid values (#1379).
The mesh counterpart of the raster footprint — "the real coverage of the values".
Distinct from :meth:bounding_polygon, which dissolves every face and so describes
the mesh domain rather than where data exists, and from :meth:polygonize, which
returns one polygon per distinct value.
"Valid" means not nodata and not NaN. It deliberately does not consult the
per-timestep active mask: a dry element has a real value and is still covered by the
data, so excluding it would conflate "no data here" with "dry here", which is the
distinction issue #1331 exists to preserve. For the wet extent, mask first
(:meth:masked_values or :meth:where) and take the footprint of that.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
shapely.Polygon | shapely.MultiPolygon: The dissolved coverage, empty when no face |
Any
|
carries a valid value. Carries no CRS — attach one if you need it. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The variable is not one value per face (select a step first). |
See Also
bounding_polygon: The whole mesh outline, data or not. polygonize: One polygon per distinct value.
Source code in src/pyramids/netcdf/ugrid/_facades.py
exterior_edges()
#
The indices of the edges on the mesh boundary.
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Boundary edge indices. |
exterior_faces()
#
The indices of the faces touching the mesh boundary.
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Boundary face indices. |
bounding_polygon()
#
The mesh footprint as one dissolved polygon, holes preserved.
Returns:
| Type | Description |
|---|---|
Any
|
shapely.geometry.base.BaseGeometry: The (multi)polygon of the mesh outline. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
circumcenters()
#
The circumcentre of every face (triangular meshes only).
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: |
Raises:
| Type | Description |
|---|---|
ValueError
|
The mesh is not triangular. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
voronoi()
#
The Voronoi tesselation of the mesh nodes (the mesh dual).
Returns:
| Type | Description |
|---|---|
Any
|
scipy.spatial.Voronoi: The tesselation. |
sparse_adjacency(kind='face')
#
The mesh adjacency as a sparse matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
|
'face'
|
Returns:
| Type | Description |
|---|---|
Any
|
scipy.sparse.csr_matrix: The symmetric adjacency. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
binary_dilation(variable_name=None, *, iterations=1, border_value=False, fixed=None)
#
Grow a boolean face mask over its neighbours.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
The boolean face variable to dilate, or |
None
|
iterations
|
int
|
How many times to grow. Defaults to 1. |
1
|
border_value
|
bool
|
What lies outside the mesh. Defaults to False. |
False
|
fixed
|
ndarray | None
|
A boolean per-face mask of the cells the result must preserve, whatever the
dilation would do to them — scipy's |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with the dilated mask. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
binary_erosion(variable_name=None, *, iterations=1, border_value=False, fixed=None)
#
Shrink a boolean face mask away from its boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
The boolean face variable to erode, or |
None
|
iterations
|
int
|
How many times to shrink. Defaults to 1. |
1
|
border_value
|
bool
|
What lies outside the mesh. Defaults to False, which erodes the boundary; pass True to erode only the interior. |
False
|
fixed
|
ndarray | None
|
A boolean per-face mask of the cells the result must preserve, whatever the
erosion would do to them — scipy's |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with the eroded mask. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
to_location(location, variable_name=None)
#
Remap a variable onto another facet of the mesh.
Averages the values of the contributing elements, so a face field asked for on the nodes becomes each node's mean of the faces around it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
str
|
The facet to remap onto — |
required |
variable_name
|
str | None
|
The variable to remap, or |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset whose variable sits on |
Raises:
| Type | Description |
|---|---|
ValueError
|
An unknown |
Source code in src/pyramids/netcdf/ugrid/_facades.py
fill_na_spatial(variable_name=None, *, max_distance=None)
#
Fill each gap from the nearest valid element in space.
Where :meth:interpolate_na fills along time, this fills across the mesh: a gap takes
the value of the closest element that has one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
The variable to fill, or |
None
|
max_distance
|
float | None
|
Leave a gap unfilled when no valid element is this close. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with the gaps filled. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
laplace_interpolate(variable_name=None, *, use_weights=True, direct_solve=False)
#
Fill the interior gaps by solving Laplace's equation over the mesh.
The valid values are the boundary condition and each gap becomes the smooth solution between them — a better hole-filler than nearest when the field varies smoothly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
The variable to fill, or |
None
|
use_weights
|
bool
|
Weight the graph Laplacian by inverse distance. Defaults to True. |
True
|
direct_solve
|
bool
|
Solve directly rather than iteratively. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with the interior gaps filled. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
polygonize(variable_name=None, *, decimals=None)
#
Dissolve adjacent faces of equal value into polygons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
The face variable to dissolve by, or |
None
|
decimals
|
int | None
|
Round to this many decimals before grouping, for approximate equality. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
geopandas.GeoDataFrame: One row per merged region, with its value and geometry. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
sample_line(line, variable_name=None)
#
Sample a variable along a line, ordered by distance along it.
One sample per crossing, at the midpoint of each part of the line-face intersection.
A line that leaves a face and re-enters it is sampled once per entry, so
face_indices can repeat -- see :func:pyramids.netcdf.ugrid.vector_ops.sample_line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
Any
|
A shapely |
required |
variable_name
|
str | None
|
The variable to sample, or |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Any
|
|
Any
|
along-line order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/pyramids/netcdf/ugrid/_facades.py
burn(geometry, value, *, name='burned', fill=float('nan'), all_touched=True)
#
Burn vector geometry onto the faces as a new variable.
The mesh analogue of rasterising a vector layer: every face the geometry covers takes
value, the rest take fill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
Any
|
A shapely geometry, GeoDataFrame, FeatureCollection, or iterable of them. |
required |
value
|
float
|
The value burned into the covered faces. |
required |
name
|
str
|
The new variable's name. Defaults to |
'burned'
|
fill
|
float
|
The value for the faces the geometry misses. Defaults to NaN. |
float('nan')
|
all_touched
|
bool
|
Burn every face the geometry touches, rather than only those whose centroid falls inside. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset carrying the burned variable. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
rasterize_like(reference, variable_name=None, *, method='nearest', nodata=-9999.0, max_distance=None)
#
Interpolate a variable onto an existing raster's grid.
Where :meth:to_dataset builds its own grid from a cell size, this snaps to the
geotransform, shape and CRS of a raster you already have, so the result is
co-registered with it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Any
|
The raster whose grid to match (a pyramids |
required |
variable_name
|
str | None
|
The variable to interpolate, or |
None
|
method
|
str
|
|
'nearest'
|
nodata
|
float
|
The value for cells the mesh does not cover. |
-9999.0
|
max_distance
|
float | None
|
How far a |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dataset |
Any
|
A raster on |
Raises:
| Type | Description |
|---|---|
ValueError
|
An unknown |
Source code in src/pyramids/netcdf/ugrid/_facades.py
interp_time(new_times, *, method='linear', bounds='nan')
#
Interpolate every temporal variable onto new time coordinates.
Distinct from :meth:interpolate_na, which fills gaps on the existing axis: this
relabels the axis, resampling the series onto the times you ask for.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_times
|
Any
|
The time coordinates to interpolate onto. |
required |
method
|
str
|
|
'linear'
|
bounds
|
str
|
What a label outside the existing axis answers -- |
'nan'
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset on the requested time coordinates. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension; |
Source code in src/pyramids/netcdf/ugrid/_facades.py
regrid(target, *, method='overlap', variable_name=None)
#
Regrid a variable onto another mesh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Any
|
The destination |
required |
method
|
str
|
|
'overlap'
|
variable_name
|
str | None
|
The variable to regrid, or |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
An unknown |
Source code in src/pyramids/netcdf/ugrid/_facades.py
to_xarray()
#
Hand the mesh and its variables to xarray, in the UGRID-CF encoding.
xarray is a peer dependency, imported only here (as the raster
:meth:pyramids.netcdf.NetCDF.to_xarray does), so nothing here imports it at module
scope. Note the parent pyramids.netcdf package does currently pull xarray and dask
at import time for unrelated reasons, so that cost is not avoided in practice yet.
Returns:
| Type | Description |
|---|---|
Any
|
xarray.Dataset: The mesh's UGRID-CF variables plus the data variables. |
Raises:
| Type | Description |
|---|---|
OptionalPackageDoesNotExist
|
xarray is not installed. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
to_zarr(store, **kwargs)
#
Write the mesh and its variables to a zarr store, through xarray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
Any
|
The zarr store (a path or a mapping). |
required |
**kwargs
|
Any
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The value |
Raises:
| Type | Description |
|---|---|
OptionalPackageDoesNotExist
|
xarray or zarr is not installed. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
fillna(value, variable_name=None)
#
Replace missing values with value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The fill value. |
required |
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with missing values replaced. |
See Also
isnull: Boolean mask of missing positions. fill_na_spatial: Fill gaps from the nearest valid spatial element.
Source code in src/pyramids/netcdf/ugrid/_facades.py
isnull(variable_name=None)
#
Boolean mask of missing positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with boolean data. |
See Also
notnull: Inverse mask (non-missing positions). fillna: Replace missing values with a constant.
Source code in src/pyramids/netcdf/ugrid/_facades.py
notnull(variable_name=None)
#
Boolean mask of non-missing positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with boolean data. |
See Also
isnull: Inverse mask (missing positions).
Source code in src/pyramids/netcdf/ugrid/_facades.py
clip_values(lower, upper, variable_name=None)
#
Clamp variable values to [lower, upper].
Named clip_values to avoid collision with the spatial
:meth:~pyramids.netcdf.ugrid.dataset.UgridDataset.clip method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lower
|
Any
|
Minimum allowed value. |
required |
upper
|
Any
|
Maximum allowed value. |
required |
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with clamped values. |
See Also
round: Round values to a number of decimal places.
Source code in src/pyramids/netcdf/ugrid/_facades.py
round(decimals=0, variable_name=None)
#
Round variable values to decimals decimal places.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decimals
|
int
|
Number of decimal places. |
0
|
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with rounded values. |
See Also
clip_values: Clamp values to a range.
Source code in src/pyramids/netcdf/ugrid/_facades.py
astype(dtype, variable_name=None)
#
Cast variable values to a different dtype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
Any
|
Target numpy dtype. |
required |
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with the new dtype. |
See Also
round: Round floating-point values before an integer cast.
Source code in src/pyramids/netcdf/ugrid/_facades.py
where(cond, other=np.nan, variable_name=None)
#
Keep the elements cond selects and mask the rest (issue #1375).
The mesh counterpart of the raster where. A nodata / NaN element is never
selected — there is no value there to keep — so it goes to other whatever cond
says, leaving the result with one masking convention rather than two.
The per-timestep active mask (:attr:~pyramids.netcdf.ugrid.models.MeshVariable.active)
is not applied here. Keeping "dry" distinct from "missing" is the whole point of
that field (issue #1331), so activity-aware masking is something a caller composes
explicitly: ds.where(ds.active_mask(name) & (values > 0)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cond
|
Any
|
A boolean array broadcastable to the variable's values. |
required |
other
|
Any
|
What an unselected element holds. Defaults to NaN. |
nan
|
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with the unselected elements masked. |
See Also
clip_values: Clamp values to a range instead of masking outside it. masked_values: Apply the active mask to the values, on demand.
Source code in src/pyramids/netcdf/ugrid/_facades.py
apply(func, variable_name=None)
#
Apply func to every element of a variable (issue #1375).
The mesh counterpart of the raster apply. func receives the whole array, so a
numpy ufunc runs vectorised rather than once per element. The shape must survive, since
the result still has to line up with the mesh elements it describes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Any
|
A callable taking and returning an array of the same shape. |
required |
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset carrying the transformed values. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
See Also
astype: Cast values to another dtype. round: Round values to a number of decimal places.
Source code in src/pyramids/netcdf/ugrid/_facades.py
get_histogram(bins=256, value_range=None, variable_name=None)
#
The variable's value distribution as data (issue #1375).
The mesh counterpart of the raster get_histogram. :meth:plot_histogram could
already draw the distribution but gave no way to obtain it; both mask no-data through
the same helper, so these counts describe exactly the samples those bars show.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bins
|
int
|
Number of equal-width bins. Defaults to 256. |
256
|
value_range
|
tuple[float, float] | None
|
|
None
|
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
ndarray
|
|
ndarray
|
variable's own units. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Nothing survives the no-data masking, so there is no distribution. |
See Also
plot_histogram: The same distribution, drawn. summary: Per-variable min / max / mean / std over the whole mesh.
Source code in src/pyramids/netcdf/ugrid/_facades.py
isin(test_values, variable_name=None)
#
Boolean mask where variable values are in test_values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_values
|
Any
|
Values to test membership against. |
required |
variable_name
|
str | None
|
Variable to act on (default: the only one). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with boolean data. |
Source code in src/pyramids/netcdf/ugrid/_facades.py
domain_area()
#
Total area of the mesh domain.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Sum of all face areas in the mesh's coordinate units squared. |
See Also
count_domain_cells: Count of active faces rather than their total area.
Source code in src/pyramids/netcdf/ugrid/_facades.py
count_domain_cells(variable_name=None)
#
Number of active (non-masked) mesh faces.
When the variable carries no active mask, all faces are counted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
Variable whose active mask to consult.
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Active face count. |
See Also
domain_area: Total area rather than face count.
Source code in src/pyramids/netcdf/ugrid/_facades.py
extract(x, y, variable_name=None)
#
Sample variable values at arbitrary (x, y) coordinates.
Uses an STRtree spatial index to locate the containing face for each query point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
Query x-coordinates (scalar or array). |
required |
y
|
Any
|
Query y-coordinates (scalar or array). |
required |
variable_name
|
str | None
|
Variable to extract (default: the only one). |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
numpy array of extracted values. Points outside the mesh |
Any
|
get |
See Also
sample_random: Draw spatially random samples instead of querying specific coordinates. sample: Interpolated point sampling (existing method on UgridDataset).
Source code in src/pyramids/netcdf/ugrid/_facades.py
sample_random(n, variable_name=None, seed=None)
#
Draw n spatially random samples from the mesh domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of samples. |
required |
variable_name
|
str | None
|
Variable to sample (default: the only one). |
None
|
seed
|
int | None
|
RNG seed for reproducibility. |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
See Also
extract: Sample at specific coordinates rather than random ones.
Source code in src/pyramids/netcdf/ugrid/_facades.py
contour(levels=None, variable_name=None)
#
Generate contour lines from face/node values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
levels
|
Any
|
Contour levels (int for count, array for explicit). |
None
|
variable_name
|
str | None
|
Variable to contour (default: the only one). |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
GeoDataFrame with contour |
Any
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the variable has more than one time step; select a single step first. |
See Also
plot_histogram: Distribution of the same variable as a histogram.
Source code in src/pyramids/netcdf/ugrid/_facades.py
plot_histogram(bins=15, variable_name=None, ax=None, **kwargs)
#
Plot the distribution of a variable's values.
Delegates to cleopatra's HistogramGlyph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bins
|
int
|
Number of histogram bins. |
15
|
variable_name
|
str | None
|
Variable to histogram (default: the only one). |
None
|
ax
|
Any
|
Existing matplotlib axes to draw into. |
None
|
**kwargs
|
Any
|
Forwarded to the glyph constructor. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
|
See Also
contour: Spatial contour extraction from the same variable.
Source code in src/pyramids/netcdf/ugrid/_facades.py
proximity(target_faces)
#
Graph distance from every face to the nearest target face.
Uses BFS over the face adjacency graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_faces
|
Any
|
1-D array of face indices that are targets (distance zero). |
required |
Returns:
| Type | Description |
|---|---|
Any
|
numpy array of per-face integer distances. |
Any
|
faces in disconnected components with no target. |
See Also
sieve: Remove small connected regions by area threshold.
Source code in src/pyramids/netcdf/ugrid/_facades.py
sieve(threshold, variable_name=None)
#
Remove small connected regions below threshold faces.
Faces in a connected component smaller than threshold are blanked to NaN. Operates on the face adjacency graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
int
|
Minimum component size (face count) to keep. |
required |
variable_name
|
str | None
|
Variable to sieve (default: the only one). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
Any
|
A new dataset with small-region faces replaced by NaN. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the variable has more than one time step; select a single step first. |
See Also
proximity: Compute graph distances from target faces.
Source code in src/pyramids/netcdf/ugrid/_facades.py
__init__(mesh, data_variables, global_attributes, topology_info=None, crs_wkt=None, file_name=None, volume_topology=None)
#
Assemble a dataset from an already-built mesh and its variables.
The low-level constructor. Prefer :meth:read_file for a file, :meth:from_arrays
for raw arrays, or one of the from_* bridges -- each of those builds the mesh and
the metadata record and then calls this. It is also what every derivation
(:meth:isel, :meth:reduce, :meth:copy, ...) calls through type(self)(...),
which is how a subclass survives them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Mesh2d
|
The topology the variables sit on. |
required |
data_variables
|
dict[str, MeshVariable]
|
Mapping of variable name to :class: |
required |
global_attributes
|
dict[str, Any]
|
The file-level attributes, e.g. |
required |
topology_info
|
MeshTopologyInfo | None
|
The record of the on-disk variable names and the declared
topology dimension. |
None
|
crs_wkt
|
str | None
|
WKT of the mesh CRS. |
None
|
file_name
|
str | None
|
The path this dataset was read from, carried through derivations so a
:meth: |
None
|
volume_topology
|
VolumeTopology | None
|
The ragged (per-column) vertical layering for a genuinely 3-D
mesh — the map from faces to the flat |
None
|
Source code in src/pyramids/netcdf/ugrid/dataset.py
read_file(path, mesh_name=None, driver=None, lazy=True)
classmethod
#
Open a mesh file.
UGRID NetCDF is read here. Any other format — 2DM, Selafin, DFSU, XMDF, … — is read by a
third-party driver registered into the pyramids.mesh_drivers entry-point group. A
non-NetCDF suffix is dispatched by detection; a NetCDF suffix is read by the built-in
reader first, and only a file that opens but carries no UGRID topology falls back to a
driver claiming that suffix. Either way a successful UGRID read triggers no driver
discovery, so a .nc read still pays nothing.
Resolution order:
drivergiven — that driver, or an error. Never falls back.- A
/vsipath or a NetCDF suffix — the built-in UGRID reader. If a NetCDF-suffixed file opens but declares no UGRID topology, a registered driver claiming that suffix is tried before giving up, so 3Di, TUFLOW FV and other NetCDF-based formats are reachable; discovery runs only after the built-in read has already failed. - Otherwise a registered driver claiming the suffix whose
can_openaccepts the file. - Nothing claimed it — the built-in reader anyway, so a NetCDF file under an unusual suffix still opens exactly as it always did.
- That failed too — :class:
UnsupportedMeshFormatError, naming what is installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the file. A GDAL virtual-filesystem path
( |
required |
mesh_name
|
str | None
|
Which topology to read, for a file declaring more than one (see
:meth: |
None
|
driver
|
str | None
|
Name of a registered mesh driver to use, bypassing detection — the
name a plugin declares, not a GDAL driver short name. |
None
|
lazy
|
bool
|
Defer reading variable values until first access. Forwarded to the driver,
which honours it when it declares |
True
|
Returns:
| Type | Description |
|---|---|
UgridDataset
|
UgridDataset instance. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file does not exist. |
DriverNotExistError
|
If |
UnsupportedMeshFormatError
|
If no installed driver reads the file, and the built-in UGRID reader cannot either. |
IsADirectoryError
|
The path is a directory that no driver claims. |
TypeError
|
|
RuntimeError
|
GDAL cannot open a file that reached the built-in reader by its
own suffix. A file whose suffix no driver claimed is reported as
:class: |
ValueError
|
If no UGRID topology is found in the file, or |
Source code in src/pyramids/netcdf/ugrid/dataset.py
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 | |
set_crs(crs=None, epsg=None)
#
Assign a CRS to a mesh that has none — no reprojection.
Exactly one of crs or epsg must be given. The CRS is written
in place to the dataset and the underlying :class:Mesh2d,
so :attr:epsg, :attr:crs_wkt, and :attr:crs all reflect
the new value immediately.
This is the complement of :meth:to_crs, which reprojects
coordinates. set_crs only declares the coordinate system the
existing coordinates are already in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
crs
|
str | None
|
WKT string describing the CRS. |
None
|
epsg
|
int | None
|
EPSG code (e.g. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither crs nor epsg is provided, or if both are provided. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
equals(other)
#
Value equality — same mesh, same variable values at non-missing positions.
Compares node coordinates, face connectivity, CRS (by EPSG), variable names, and per-variable values (ignoring positions where either side is nodata/NaN).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
The object to compare against. Returns |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
See Also
identical: Strict comparison that also checks dtype, nodata sentinels, CRS WKT, and global attributes.
Source code in src/pyramids/netcdf/ugrid/dataset.py
identical(other)
#
Strict equality — same dtype, same values, same nodata, same attributes.
Everything must match exactly, including NaN positions, dtypes, nodata sentinels, CRS WKT, and global attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
The object to compare against. Returns |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
See Also
equals: Looser comparison that ignores nodata positions, dtype differences, and attribute mismatches.
Source code in src/pyramids/netcdf/ugrid/dataset.py
get_data(variable_name)
#
Get a data variable by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str
|
Name of the data variable. |
required |
Returns:
| Type | Description |
|---|---|
MeshVariable
|
MeshVariable instance. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the variable name is not found. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
__getitem__(key)
#
Get a data variable by name using bracket notation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The variable name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MeshVariable |
MeshVariable
|
The variable. |
Raises:
| Type | Description |
|---|---|
KeyError
|
No variable is named |
Source code in src/pyramids/netcdf/ugrid/dataset.py
__contains__(key)
#
Whether key names a data variable of this dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The variable name to test. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True when the dataset carries a variable of that name. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
__len__()
#
The number of data variables.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
How many data variables the dataset carries. Note this counts variables, |
int
|
not elements -- :attr: |
|
int
|
sizes. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
__iter__()
#
Iterate over the data variable names.
Returns:
| Type | Description |
|---|---|
Any
|
Iterator[str]: The variable names, in insertion order -- so |
Any
|
and |
Source code in src/pyramids/netcdf/ugrid/dataset.py
keys()
#
The data variable names (read-only mapping surface).
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The names, in insertion order. A list rather than a view, so it does |
list[str]
|
not track later edits -- every variable edit returns a new dataset anyway. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
values()
#
The data variables (read-only mapping surface).
Returns:
| Type | Description |
|---|---|
list[MeshVariable]
|
list[MeshVariable]: The variables, in the same order as :meth: |
list[MeshVariable]
|
variables themselves are not copied, so reading |
list[MeshVariable]
|
lazy loader. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
items()
#
The (name, variable) pairs (read-only mapping surface).
Returns:
| Type | Description |
|---|---|
list[tuple[str, MeshVariable]]
|
list[tuple[str, MeshVariable]]: One pair per variable, in insertion order. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
get(key, default=None)
#
The variable key, or default when it is absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The variable name to look up. |
required |
default
|
Any
|
What to answer when no variable is named |
None
|
Returns:
| Type | Description |
|---|---|
MeshVariable | Any
|
MeshVariable | Any: The variable, or |
Source code in src/pyramids/netcdf/ugrid/dataset.py
with_variable(name, data, *, location='face', nodata=None)
#
Return a new dataset with name added or replaced.
UGRID derivations are immutable — unlike NetCDF.set_variable this does not mutate
in place but returns a fresh dataset. A 2-D data array is treated as temporal
(leading axis = time); a 1-D array is a static per-element variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variable name to add or replace. |
required |
data
|
ndarray
|
The values; |
required |
location
|
str
|
Mesh location — |
'face'
|
nodata
|
float | None
|
Optional no-data value for the new variable. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset carrying the variable. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
drop_variables(names)
#
Return a new dataset without the named variable(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
str | list[str]
|
A variable name, or a list of them, to drop. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset without those variables. |
Raises:
| Type | Description |
|---|---|
KeyError
|
A named variable is not present. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
rename_variable(old, new)
#
Return a new dataset with variable old renamed to new.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old
|
str
|
The current variable name. |
required |
new
|
str
|
The new name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with the variable renamed. |
Raises:
| Type | Description |
|---|---|
KeyError
|
|
ValueError
|
|
Source code in src/pyramids/netcdf/ugrid/dataset.py
to_dataset(variable_name, cell_size, method='nearest', bounds=None, epsg=None, nodata=-9999.0)
#
Convert a mesh variable to a regular-grid Dataset.
Interpolates mesh data onto a regular grid and returns a standard pyramids Dataset. This is the bridge between unstructured (UGRID) and structured (raster) worlds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str
|
Name of the data variable to rasterize. |
required |
cell_size
|
float
|
Target grid cell size in coordinate units. |
required |
method
|
str
|
Interpolation method ("nearest" or "linear"). |
'nearest'
|
bounds
|
tuple[float, float, float, float] | None
|
Target (xmin, ymin, xmax, ymax). Defaults to mesh bounds. |
None
|
epsg
|
int | None
|
Target EPSG code. Defaults to mesh CRS. |
None
|
nodata
|
float
|
No-data value for the output raster. |
-9999.0
|
Returns:
| Type | Description |
|---|---|
Dataset
|
pyramids Dataset with the interpolated data. |
Raises:
| Type | Description |
|---|---|
KeyError
|
No variable is named |
ValueError
|
The variable exists but holds no data (nothing was loaded and it carries no lazy loader), so there is nothing to interpolate. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
crop(mask=None, touch=True, *, bbox=None, epsg=None)
#
Crop the mesh to a polygon mask or a bbox — the unstructured-mesh analogue of crop.
The mesh equivalent of :meth:pyramids.dataset.Dataset.crop / :meth:NetCDF.crop. Rather
than warping a raster, it selects the faces that fall inside the region (renumbering the
node connectivity for the resulting sub-mesh) and keeps the data on the surviving elements.
Delegates to :meth:clip for a polygon and :meth:subset_by_bounds for a bbox; this method
exists so the spatial-subset call is named crop across the raster and mesh classes alike.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Any
|
Polygon mask — a shapely geometry, |
None
|
touch
|
bool
|
Applies only to a polygon |
True
|
bbox
|
tuple or list of 4 floats, keyword-only
|
|
None
|
epsg
|
(int, keyword - only)
|
CRS of |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new sub-mesh — faces inside the region, connectivity renumbered, and data variables subset to the surviving elements. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
TypeError
|
If neither |
Examples:
- Crop a mesh to a polygon (faces intersecting it survive):
- Crop to a bounding box in the mesh's own CRS:
See Also
clip: Polygon-mask subsetting that crop delegates to when mask is given.
subset_by_bounds: Bounding-box subsetting that crop delegates to when bbox is
given.
pyramids.dataset.Dataset.crop: The raster equivalent on a gridded dataset.
Source code in src/pyramids/netcdf/ugrid/dataset.py
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 | |
clip(mask, touch=True)
#
Clip the mesh to a polygon mask.
Selects faces that intersect (touch=True) or are fully contained within (touch=False) the mask polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Any
|
Polygon mask (GeoDataFrame, FeatureCollection, or Shapely geometry). |
required |
touch
|
bool
|
If True, include faces touching the boundary. |
True
|
Returns:
| Type | Description |
|---|---|
UgridDataset
|
New UgridDataset with clipped mesh and data. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
subset_by_bounds(xmin, ymin, xmax, ymax)
#
Subset mesh to faces within a bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xmin
|
float
|
Minimum x-coordinate. |
required |
ymin
|
float
|
Minimum y-coordinate. |
required |
xmax
|
float
|
Maximum x-coordinate. |
required |
ymax
|
float
|
Maximum y-coordinate. |
required |
Returns:
| Type | Description |
|---|---|
UgridDataset
|
New UgridDataset with subset mesh and data. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
to_crs(to_epsg)
#
Reproject all node coordinates to a new CRS.
Uses pyproj.Transformer to reproject node coordinates. Face/edge center coordinates are recomputed after reprojection. Data values are preserved — only coordinates change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_epsg
|
int
|
Target EPSG code. |
required |
Returns:
| Type | Description |
|---|---|
UgridDataset
|
New UgridDataset with reprojected coordinates. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The mesh declares neither an EPSG code nor a WKT, so there is no source CRS to reproject from. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 | |
sel_time(index)
#
Select a single time step from all temporal variables.
Non-temporal variables are kept unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Time step index. |
required |
Returns:
| Type | Description |
|---|---|
UgridDataset
|
New UgridDataset with single time step data. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
sel_time_range(start, stop)
#
Select a time range from all temporal variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
int
|
Start index (inclusive). |
required |
stop
|
int
|
Stop index (exclusive). |
required |
Returns:
| Type | Description |
|---|---|
UgridDataset
|
New UgridDataset with the selected time range. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
attach_data(path, driver=None, lazy=True)
#
Attach a results-only file's variables to this mesh.
Some formats carry values but no topology — an SMS .dat, an XMDF, an XDMF — and must
be paired with a mesh read from elsewhere. Those drivers declare needs_mesh, and
:meth:read_file refuses them, pointing here.
>>> mesh = UgridDataset.read_file("domain.2dm") # doctest: +SKIP
>>> result = mesh.attach_data("velocity.dat") # doctest: +SKIP
The driver returns only the variables it read; this method merges them onto the dataset. That division is deliberate — it makes a name the dataset already defines an unambiguous collision, and means a driver cannot drop the dataset's own variables by rebuilding the mapping.
The driver checks the file's declared element count against this mesh. That check is the only safeguard there is: a bare results file carries nothing identifying the mesh it belongs to, so attaching it to the wrong one would otherwise produce a plausible and entirely wrong dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
The results file to read. |
required |
driver
|
str | None
|
Name of a registered driver to use, bypassing detection. |
None
|
lazy
|
bool
|
Defer reading variable values until first access. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
UgridDataset
|
A new dataset carrying this mesh plus the attached variables. This dataset is |
UgridDataset
|
unchanged. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the results file does not exist. |
DriverNotExistError
|
If |
UnsupportedMeshFormatError
|
If no installed driver can attach this file, the
named driver does not declare |
ValueError
|
If the driver returns a variable whose name this dataset already uses, or reports an element-count mismatch against this mesh. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 | |
to_file(path, driver=None, **options)
#
Write the dataset to a file.
Writes UGRID-compliant NetCDF by default: a topology variable, node coordinates, connectivity arrays, face/edge centres, data variables, and global attributes following the UGRID convention.
With driver, writes through a registered third-party driver instead — 2DM, Selafin,
PLY and others are writable. The output format is never inferred from the suffix, so
to_file("mesh.slf") still writes NetCDF; name the driver to change that.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Output file path. |
required |
driver
|
str | None
|
Name of a registered mesh driver to write with, as declared by the
plugin providing it (see :func: |
None
|
**options
|
Any
|
Format-specific settings for the driver, passed through uninterpreted
(for example Selafin endianness, or PLY ascii versus binary). The built-in
writer takes none, so passing any without a |
{}
|
Raises:
| Type | Description |
|---|---|
DriverNotExistError
|
If |
UnsupportedMeshFormatError
|
If the named driver cannot write a mesh. |
TypeError
|
If |
Source code in src/pyramids/netcdf/ugrid/dataset.py
to_bytes()
#
Serialise the dataset to an in-memory UGRID NetCDF buffer.
Writes through a temporary file because GDAL's NetCDF driver
does not support /vsimem/ for multidimensional creation.
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The NetCDF file content, suitable for writing to cloud storage or embedding in a response payload. |
See Also
to_file: Write directly to a file on disk. read_file: Class method that reads from a file path or byte buffer.
Source code in src/pyramids/netcdf/ugrid/dataset.py
to_geodataframe(variable_name=None, location='face')
#
Convert mesh to a GeoDataFrame.
For faces: each row is a Polygon with data columns. For nodes: each row is a Point. For edges: each row is a LineString.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
Optional data variable to include as a column. |
None
|
location
|
str
|
Mesh location ("face", "node", or "edge"). |
'face'
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
geopandas GeoDataFrame. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
to_feature_collection(variable_name=None, location='face')
#
Convert mesh to a pyramids FeatureCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
Optional data variable to include. |
None
|
location
|
str
|
Mesh location ("face", "node", or "edge"). |
'face'
|
Returns:
| Type | Description |
|---|---|
FeatureCollection
|
pyramids FeatureCollection. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
from_arrays(node_x, node_y, face_node_connectivity, data=None, data_locations=None, epsg=4326, mesh_name=DEFAULT_MESH_NAME)
classmethod
#
Create a UgridDataset programmatically from arrays.
Plural because an unstructured mesh is not one array: the topology
needs node coordinates and a face-node connectivity table before any
data can be attached. It therefore takes a flat epsg rather than the
:class:~pyramids.base.georeference.GeoReference the gridded
constructors take — a mesh carries its own coordinates, so there is no
affine transform to describe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_x
|
ndarray
|
Node x-coordinates. |
required |
node_y
|
ndarray
|
Node y-coordinates. |
required |
face_node_connectivity
|
ndarray
|
(n_faces, max_nodes) array of node indices. Use -1 as fill value for mixed meshes. |
required |
data
|
dict[str, ndarray] | None
|
Optional dict mapping variable name to data array. |
None
|
data_locations
|
dict[str, str] | None
|
Optional dict mapping variable name to location ("face", "node", "edge"). Defaults to "face". |
None
|
epsg
|
int
|
EPSG code for the CRS. |
4326
|
mesh_name
|
str
|
Name for the topology variable. |
DEFAULT_MESH_NAME
|
Returns:
| Type | Description |
|---|---|
UgridDataset
|
UgridDataset instance. |
Examples:
- Build the smallest possible mesh — two triangles — and inspect
its topology:
>>> import numpy as np >>> from pyramids.netcdf.ugrid import UgridDataset >>> mesh = UgridDataset.from_arrays( ... node_x=np.array([0.0, 1.0, 1.0, 0.0]), ... node_y=np.array([0.0, 0.0, 1.0, 1.0]), ... face_node_connectivity=np.array([[0, 1, 2], [0, 2, 3]]), ... ) >>> (mesh.n_node, mesh.n_face) (4, 2) >>> mesh.bounds (0.0, 0.0, 1.0, 1.0) - Attach a per-face variable and read it back:
>>> import numpy as np >>> from pyramids.netcdf.ugrid import UgridDataset >>> mesh = UgridDataset.from_arrays( ... node_x=np.array([0.0, 1.0, 1.0, 0.0]), ... node_y=np.array([0.0, 0.0, 1.0, 1.0]), ... face_node_connectivity=np.array([[0, 1, 2], [0, 2, 3]]), ... data={"depth": np.array([1.5, 2.5])}, ... ) >>> mesh.data_variable_names ['depth'] >>> mesh["depth"].location 'face' >>> mesh["depth"].data.tolist() [1.5, 2.5]
Source code in src/pyramids/netcdf/ugrid/dataset.py
1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 | |
from_structured(dataset, band_names=None, mesh_name=DEFAULT_MESH_NAME)
classmethod
#
Build a mesh from a raster, one quad face per cell.
The bridge from the structured world: each cell becomes a quad over the corner lattice (shared corners deduplicated) and each band becomes a per-face variable, so a raster can be fed to the mesh operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
The source raster (a pyramids |
required |
band_names
|
list[str] | None
|
Names for the per-face variables, one per band. Defaults to
|
None
|
mesh_name
|
str
|
The topology name to stamp. Defaults to the package default. |
DEFAULT_MESH_NAME
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
The quad mesh carrying the band values. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
from_geodataframe(gdf, mesh_name=DEFAULT_MESH_NAME)
classmethod
#
Build a mesh from polygon geometries, one face per polygon.
Vertices are deduplicated into the node set and each ring is oriented counter-clockwise; the frame's attribute columns become per-face variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
Any
|
A GeoDataFrame of polygons. Its |
required |
mesh_name
|
str
|
The topology name to stamp. Defaults to the package default. |
DEFAULT_MESH_NAME
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
The mesh built from the polygons. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The frame declares no CRS, so the mesh would carry no georeferencing. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
from_xarray(ds)
classmethod
#
Read a mesh back from an xarray.Dataset in the UGRID-CF encoding.
The inverse of :meth:to_xarray. xarray is a peer dependency, imported only inside
the bridge, so nothing in this module imports it at module scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Any
|
The |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
The reconstructed mesh and variables. |
Raises:
| Type | Description |
|---|---|
OptionalPackageDoesNotExist
|
xarray is not installed. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
from_zarr(store, **kwargs)
classmethod
#
Read a mesh from a zarr store written by :meth:to_zarr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
Any
|
The zarr store (a path or a mapping). |
required |
**kwargs
|
Any
|
Passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
The reconstructed mesh and variables. |
Raises:
| Type | Description |
|---|---|
OptionalPackageDoesNotExist
|
xarray or zarr is not installed. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
mesh_names(path, driver=None)
staticmethod
#
The names of every topology a file declares.
A mesh file may carry several topologies; :meth:read_file takes the first unless told
otherwise, so this is how a caller discovers what else is in there.
Dispatch mirrors :meth:read_file exactly, including the short-circuit that keeps a
NetCDF suffix from triggering driver discovery. Every driver is asked, not only those
declaring multi_mesh: a single-mesh format answers with a one-item list, which is
the right answer rather than an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the file. |
required |
driver
|
str | None
|
Name of a registered driver to ask, bypassing detection. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: One name per declared topology, in file order. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The file does not exist. |
DriverNotExistError
|
|
UnsupportedMeshFormatError
|
No installed driver claims the suffix and the built-in reader cannot open it either, or a driver failed or returned something other than a list of topology names. |
IsADirectoryError
|
The path is a directory that no driver claims. |
RuntimeError
|
GDAL cannot open a file that reached the built-in reader by its own suffix. GDAL exceptions are enabled package-wide, so the open failure surfaces as GDAL's own error. |
ValueError
|
The file declares no UGRID topology. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
open_mfdataset(paths, *, driver=None, mesh_name=None, sort=True)
classmethod
#
Open many mesh files sharing one topology and stack them along time (#1378).
The many-files entry point. :meth:read_all answers every topology in one
file; this answers one topology across many files, which is the shape a long run is
written in — one file per day, per month, or per restart.
The topology is read from the first file and every other file must match it; the data
variables are concatenated along time by :meth:concat, so the rules about what may
be joined are that method's rules, stated in one place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
str | Path | Sequence[str | Path]
|
A glob pattern ( |
required |
driver
|
str | None
|
Name of a registered mesh driver, bypassing detection. |
None
|
mesh_name
|
str | None
|
Which topology to take from each file. |
None
|
sort
|
bool
|
Order the files by their first time stamp before stacking, so a run whose
filenames do not sort chronologically still comes back in time order —
|
True
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
One dataset on the shared topology, its time axis spanning every |
UgridDataset
|
file in order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
AlignmentError
|
A file sits on a different topology than the first. |
See Also
read_all: Every topology within one file. concat: The time-axis join this performs, and its rules.
Examples:
- Stack a run written one file per day:
Source code in src/pyramids/netcdf/ugrid/dataset.py
2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 | |
read_all(path, driver=None, lazy=True)
classmethod
#
Read every topology in a file, one dataset each.
:meth:read_file answers a single mesh (the first, or the one named). This answers
all of them, so nothing in a multi-mesh file is silently dropped. Dispatch follows
:meth:mesh_names and :meth:read_file, so a third-party format works here too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the file. |
required |
driver
|
str | None
|
Name of a registered mesh driver to use, bypassing detection.
|
None
|
lazy
|
bool
|
Defer reading variable values until first access. Forwarded to a driver,
which may honour an eager read; the built-in UGRID reader has no eager mode, so
|
True
|
Returns:
| Type | Description |
|---|---|
dict[str, UgridDataset]
|
dict[str, UgridDataset]: Each topology name mapped to its dataset. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The file does not exist. |
DriverNotExistError
|
|
UnsupportedMeshFormatError
|
No installed driver reads the file and the built-in
reader cannot either — raised from :meth: |
IsADirectoryError
|
The path is a directory that no driver claims. |
RuntimeError
|
GDAL cannot open a file that reached the built-in reader by its own suffix. GDAL exceptions are enabled package-wide, so the open failure surfaces as GDAL's own error. |
TypeError
|
|
ValueError
|
The file declares no UGRID topology. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 | |
isel_layer(index)
#
Select along the layer axis by position.
A layered variable — (layer, element), or (time, layer, element) — is indexed
on its layer axis. An integer collapses that axis (the variable loses its layer
dimension); a slice or sequence keeps it, trimmed. Variables with no layer axis are
carried through untouched, as the time selectors carry static variables.
For a ragged 3-D mesh (:attr:volume_topology set) a location="volume"
variable has no rectangular layer axis to index; the selection is per column instead.
index must be an int k: each column yields its k-th layer where it has
one, and a column shallower than k + 1 layers yields NaN — the absent layers are
made explicit, never padded silently. The volume variable becomes a plain
location="face" field; other variables carry through as on the uniform path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int | slice | list[int] | ndarray
|
An |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with the layer selection applied. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a layer dimension, or a non- |
Source code in src/pyramids/netcdf/ugrid/dataset.py
sel_layer(value)
#
Select along the layer axis by coordinate value.
Matches value against :attr:layer_values, falling back to layer positions when
no layer coordinate is present -- which is the usual case, since the reader does not
populate layer_values (see :attr:layer_values). So on a mesh read from a file,
sel_layer(1) selects layer position 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The layer coordinate value to select. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with that layer selected. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No layer dimension, or the value is not among the layer coordinates. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
collapse_layer(layer, *, location='face')
#
Collapse a ragged 3-D mesh's volume variables to a 2-D field (issue #1330).
The explicit 2-D collapse of a ragged mesh: each column's layer-th value becomes a
plain (n_face,) (or (time, n_face)) face field, absent layers NaN. It is
:meth:isel_layer under a name that says "give me a 2-D slice", so a caller can ask for
the surface/bed layer as a flat field without reaching for the per-column internals.
(Named collapse_layer rather than to_location because the latter already moves a
variable between mesh locations by graph interpolation — a different operation.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
int
|
The 0-based layer position to take from each column. |
required |
location
|
str
|
The target mesh location. Only |
'face'
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset whose volume variables are 2-D face fields. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/pyramids/netcdf/ugrid/dataset.py
to_dataframe(variables=None, *, dropna=False)
#
A tidy frame of the mesh values, one row per element (and step).
The mesh counterpart of :meth:pyramids.netcdf.NetCDF.to_dataframe, in the tidy
shape rather than the raster (y, x) MultiIndex one: an unstructured element has no
row/column address, so each row carries the element index, its centroid coordinates,
the time step where the variable has one, and the value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variables
|
Sequence[str] | None
|
Which data variables to include. |
None
|
dropna
|
bool
|
Drop rows whose value is no-data. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame: Columns |
DataFrame
|
|
DataFrame
|
|
DataFrame
|
|
DataFrame
|
the step coordinate, or None for a static one. |
Raises:
| Type | Description |
|---|---|
KeyError
|
A requested variable is not a data variable of this dataset. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
copy()
#
An independent deep copy of this dataset.
Every variable's values are copied, so writing into the copy never shows in the
original — the counterpart of :meth:pyramids.netcdf.NetCDF.copy.
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
The copy. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
from_bytes(data, *, suffix='.nc')
classmethod
#
Read a UGRID mesh from an in-memory buffer.
Writes data into GDAL's in-memory filesystem and reads it as a file, mirroring
:meth:pyramids.netcdf.NetCDF.from_bytes — for a mesh fetched over the network or
held in a database blob. The values are materialised before the buffer is unlinked, so
the result does not depend on it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
The bytes of a UGRID NetCDF file. |
required |
suffix
|
str
|
The extension to present to GDAL. Defaults to |
'.nc'
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
The mesh read from the buffer. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
GDAL cannot read the buffer at all. It is written to |
ValueError
|
The buffer reads as a file but declares no UGRID topology. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
info(buf=None, drivers=False)
#
Print a summary of the mesh, its variables and its attributes.
The mesh counterpart of :meth:pyramids.netcdf.NetCDF.info: one readable block naming
the topology, the element counts, the CRS, and every data variable with its location,
dtype and shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buf
|
Any
|
Where to write. Defaults to |
None
|
drivers
|
bool
|
Also list the mesh file-format drivers available in this interpreter — the built-in UGRID reader plus any installed plugin. Off by default because resolving them walks every installed distribution, which a summary of one dataset should not pay for. |
False
|
Source code in src/pyramids/netcdf/ugrid/dataset.py
set_global_attribute(name, value)
#
Return a new dataset carrying one more global attribute.
A UGRID derivation is immutable here (as :meth:with_variable is), so this answers a
new dataset rather than writing in place; :meth:to_file then persists the attributes
through the shared CF writer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The attribute name. |
required |
value
|
Any
|
The attribute value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset whose global attributes include |
Source code in src/pyramids/netcdf/ugrid/dataset.py
delete_global_attribute(name)
#
Return a new dataset without the global attribute name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The attribute to drop. Dropping an absent attribute is not an error,
mirroring the raster |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset without that attribute. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
active_mask(variable_name)
#
The variable's per-element active (wet/dry) mask, or None when it has none.
The first-class companion of the data (issue #1331): True marks an active/wet
element, False a dry one, kept separate from nodata/NaN so a consumer can tell
a dry element from a missing value. The mask is element-indexed — (n_element,)
when it is static or (n_time, n_element) when it varies per step — and is returned
as read, never applied to the values. Use :meth:masked_values to get the values with
it applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str
|
Name of the data variable. |
required |
Returns:
| Type | Description |
|---|---|
NDArray | None
|
np.ndarray | None: The boolean mask, or |
Raises:
| Type | Description |
|---|---|
KeyError
|
|
Examples:
- A variable with a mask reports it; one without answers
None:>>> import numpy as np >>> from pyramids.netcdf.ugrid import UgridDataset >>> ds = UgridDataset.from_arrays( ... node_x=np.array([0.0, 1.0, 1.0, 0.0]), ... node_y=np.array([0.0, 0.0, 1.0, 1.0]), ... face_node_connectivity=np.array([[0, 1, 2], [0, 2, 3]]), ... data={"depth": np.array([2.0, 4.0])}, ... ) >>> ds["depth"].active = np.array([True, False]) >>> ds.active_mask("depth").tolist() [True, False] >>> ds.active_mask("depth") is not None True
Source code in src/pyramids/netcdf/ugrid/dataset.py
masked_values(variable_name)
#
The variable's values with both nodata and the active mask blanked to NaN.
The opt-in counterpart of a bare .data read (issue #1331): dry elements (where
:meth:active_mask is False) become NaN on top of the usual nodata blanking,
so a caller that wants "treat dry as missing" gets it explicitly — the values are
never masked by default. Keeps the variable's full shape (every time step and layer),
unlike the single-step :meth:sample / :meth:weighted path. When the variable has no
mask the result is just the nodata-blanked values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str
|
Name of the data variable. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
np.ndarray: The float64 values, dry and missing elements alike as NaN. |
Raises:
| Type | Description |
|---|---|
KeyError
|
|
ValueError
|
The variable has no loaded data. |
Examples:
- Dry elements become NaN, so a mean over the wet cells is straightforward:
>>> import numpy as np >>> from pyramids.netcdf.ugrid import UgridDataset >>> ds = UgridDataset.from_arrays( ... node_x=np.array([0.0, 1.0, 1.0, 0.0]), ... node_y=np.array([0.0, 0.0, 1.0, 1.0]), ... face_node_connectivity=np.array([[0, 1, 2], [0, 2, 3]]), ... data={"depth": np.array([2.0, 4.0])}, ... ) >>> ds["depth"].active = np.array([True, False]) >>> ds.masked_values("depth").tolist() [2.0, nan] >>> float(np.nanmean(ds.masked_values("depth"))) 2.0
Source code in src/pyramids/netcdf/ugrid/dataset.py
summary(variables=None, *, metrics=DEFAULT_METRICS, skipna=True, ddof=0)
#
A per-variable summary table over the whole mesh.
The mesh counterpart of :meth:pyramids.netcdf.NetCDF.summary, built on the same shared
assembly (:func:pyramids.base._summary.variable_summary) so the two classes answer in an
identical shape. Each variable is reduced over all of its samples — every element and,
for a temporal variable, every step — with the declared no-data value left out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variables
|
Sequence[str] | None
|
Which data variables to summarise, in output-row order. |
None
|
metrics
|
Sequence[str]
|
Which statistics to report, in column order. Defaults to
|
DEFAULT_METRICS
|
skipna
|
bool
|
Leave no-data out of the statistics (the default) or let it propagate. |
True
|
ddof
|
int
|
Delta degrees of freedom for |
0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame: One row per variable (index name |
DataFrame
|
metric. |
DataFrame
|
element yields NaN statistics and a |
Raises:
| Type | Description |
|---|---|
KeyError
|
A requested variable is not a data variable of this dataset. |
TypeError
|
A requested variable is non-numeric. |
ValueError
|
A requested variable has no loaded data, or an unknown metric. |
Examples:
- Per-variable summary of a two-triangle mesh:
>>> import numpy as np >>> from pyramids.netcdf.ugrid import UgridDataset >>> mesh = UgridDataset.from_arrays( ... node_x=np.array([0.0, 1.0, 1.0, 0.0]), ... node_y=np.array([0.0, 0.0, 1.0, 1.0]), ... face_node_connectivity=np.array([[0, 1, 2], [0, 2, 3]]), ... data={"depth": np.array([2.0, 4.0])}, ... ) >>> mesh.summary().loc["depth", ["count", "min", "max", "mean"]].tolist() [2.0, 2.0, 4.0, 3.0]
Source code in src/pyramids/netcdf/ugrid/dataset.py
3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 | |
sample(variable_name, x, y, *, method='contains', time_index=0)
#
Sample a mesh variable at point locations.
The mesh counterpart of :meth:pyramids.dataset.Dataset.sample. Where the raster
version inverts an affine geotransform to find the pixel under each point, a mesh
resolves the point to an element through :class:MeshSpatialIndex: a face-located
variable by which face contains the point (method="contains") or the nearest
face centroid (method="nearest"); a node-located variable by nearest node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str
|
Name of the data variable. |
required |
x
|
float | ndarray
|
Query x-coordinate(s), in the mesh CRS. |
required |
y
|
float | ndarray
|
Query y-coordinate(s), in the mesh CRS. |
required |
method
|
str
|
|
'contains'
|
time_index
|
int
|
Step for a temporal variable. Defaults to 0. |
0
|
Returns:
| Type | Description |
|---|---|
NDArray
|
numpy.ndarray: One value per query point; NaN where a |
NDArray
|
falls outside every face. |
Raises:
| Type | Description |
|---|---|
ValueError
|
An unknown |
Source code in src/pyramids/netcdf/ugrid/dataset.py
3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 | |
weighted(variable_name, *, how='mean', time_index=0, q=None)
#
Area-weighted statistic of a face variable over the mesh.
An irregular mesh has faces of different sizes, so the meaningful aggregate weights
each face by its area. Delegates to the shared
:func:pyramids.base._reductions.weighted_statistic with :attr:Mesh2d.face_areas
as the weights — the same kernel the raster weighted reduction uses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str
|
Name of a face-located data variable. |
required |
how
|
str
|
One of |
'mean'
|
time_index
|
int
|
Step for a temporal variable. Defaults to 0. |
0
|
q
|
float | None
|
The quantile in |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The area-weighted statistic over all faces. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Examples:
- Area-weighted mean: the larger face (area 4, value 10) outweighs the
smaller (area 2, value 20), pulling the mean below the unweighted 15.0:
>>> import numpy as np >>> from pyramids.netcdf.ugrid import UgridDataset >>> mesh = UgridDataset.from_arrays( ... node_x=np.array([0.0, 4.0, 4.0, 0.0]), ... node_y=np.array([0.0, 0.0, 2.0, 1.0]), ... face_node_connectivity=np.array([[0, 1, 2], [0, 2, 3]]), ... data={"v": np.array([10.0, 20.0])}, ... ) >>> round(mesh.weighted("v"), 3) 13.333 - The area-weighted quantile clamps to the data range at the extremes:
>>> import numpy as np >>> from pyramids.netcdf.ugrid import UgridDataset >>> mesh = UgridDataset.from_arrays( ... node_x=np.array([0.0, 4.0, 4.0, 0.0]), ... node_y=np.array([0.0, 0.0, 2.0, 1.0]), ... face_node_connectivity=np.array([[0, 1, 2], [0, 2, 3]]), ... data={"v": np.array([10.0, 20.0])}, ... ) >>> mesh.weighted("v", how="quantile", q=0.0) 10.0 >>> mesh.weighted("v", how="quantile", q=1.0) 20.0
Source code in src/pyramids/netcdf/ugrid/dataset.py
3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 | |
zonal_stats(zones, *, variable_name, stats=('mean',), weighted=True, time_index=0)
#
Aggregate a face variable within polygons, weighted by face area.
The mesh counterpart of :func:pyramids.dataset.ops._zonal.zonal_stats. Each face
is assigned to the zone whose polygon contains its centroid (the mesh analogue of a
raster pixel's cell centre), then the shared
:func:pyramids.base._reductions.reduce_by_label reduces the face values per zone.
With weighted (the default) the averaging statistics (mean / std /
var) are area-weighted, so a zone's mean is area-exact — a capability the raster
path does not yet have. sum is always the plain Σ value (never an area integral),
and count / min / max are weight-invariant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zones
|
Any
|
Polygons, as a :class: |
required |
variable_name
|
str
|
Name of a face-located data variable. |
required |
stats
|
tuple[str, ...]
|
Statistics per zone, any of |
('mean',)
|
weighted
|
bool
|
Area-weight the averaging statistics ( |
True
|
time_index
|
int
|
Step for a temporal variable. Defaults to 0. |
0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame: Indexed like |
DataFrame
|
containing no face centroid is NaN ( |
Raises:
| Type | Description |
|---|---|
ValueError
|
The variable is not face-located, or the zones' CRS disagrees with the mesh CRS. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 | |
reduce(how, *, skipna=True, q=None, groupby=None)
#
Reduce the time dimension of every temporal variable, whole or in groups.
The mesh counterpart of :meth:pyramids.netcdf.NetCDF.reduce over time. Each
temporal variable is reduced along its time axis through the shared
:func:pyramids.base._reductions.reduce_axis — the very kernel the raster reductions
use. Non-temporal variables are kept unchanged.
Without groupby the whole axis collapses to one statistic and the variable becomes
static. With groupby each group is reduced on its own slab and the results are
stacked back along the time axis, so the variable stays temporal with one step per
group — the same shape contract the raster grouped reduce has. For a (4, 2)
variable over four monthly steps, reduce("mean") answers shape (2,) with
has_time False, while reduce("mean", groupby="MS") answers shape (2, 2)
with has_time still True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
how
|
str
|
One of |
required |
skipna
|
bool
|
Skip the declared no-data value and NaN. Defaults to True. |
True
|
q
|
float | None
|
The quantile for |
None
|
groupby
|
Any
|
Reduce within groups of steps instead of over the whole axis. Two
spellings, matching the raster grouped reduce: a sequence of per-step
labels the same length as the time axis (grouped in first-appearance order,
so the caller controls the order), or a pandas offset alias ( |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset. Without |
UgridDataset
|
collapsed over time into a static per-element variable; with |
|
UgridDataset
|
keeps its time dimension, at one step per group. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Examples:
- Mean over two time steps of a per-face variable:
>>> import numpy as np >>> from pyramids.netcdf.ugrid import UgridDataset >>> mesh = UgridDataset.from_arrays( ... node_x=np.array([0.0, 1.0, 1.0, 0.0]), ... node_y=np.array([0.0, 0.0, 1.0, 1.0]), ... face_node_connectivity=np.array([[0, 1, 2], [0, 2, 3]]), ... data={"d": np.array([[1.0, 2.0], [3.0, 4.0]])}, ... data_locations={"d": "face"}, ... ) >>> mesh["d"].has_time True >>> reduced = mesh.reduce("mean") >>> reduced["d"].data.tolist() [2.0, 3.0] >>> reduced["d"].has_time False
Source code in src/pyramids/netcdf/ugrid/dataset.py
3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 | |
resample(freq, how='mean', *, skipna=True, q=None)
#
Bin the time axis by a calendar frequency and reduce each bin.
Sugar over reduce(how, groupby=freq): the mesh counterpart of the raster
resample. The time coordinates must be date-like, since the bins come from a pandas
offset alias ("1MS", "YS", "7D", …). The time dimension is kept, one step
per non-empty bin, stamped with pandas' own label for that bin — which is the bin's
start for a start-anchored alias and its end for an end-anchored one. Over steps in
January, February and March 2020, "MS" labels the bins 01-01 / 02-01 / 03-01 while
"ME" labels them 01-31 / 02-29 / 03-31, and "W" labels each week by its Sunday.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq
|
str
|
A pandas offset alias naming the bin width. |
required |
how
|
str
|
The statistic each bin is reduced with. Defaults to |
'mean'
|
skipna
|
bool
|
Skip the declared no-data value and NaN. Defaults to True. |
True
|
q
|
float | None
|
The quantile, required when |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with one time step per bin. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension, the coordinates are not date-like,
or |
Source code in src/pyramids/netcdf/ugrid/dataset.py
mean(*, skipna=True)
#
Mean over time of every temporal variable (thin wrapper over :meth:reduce).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skipna
|
bool
|
Skip the declared no-data value and NaN. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset; each temporal variable collapsed to its time mean. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
sum(*, skipna=True)
#
Sum over time of every temporal variable (thin wrapper over :meth:reduce).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skipna
|
bool
|
Skip the declared no-data value and NaN. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset; each temporal variable collapsed to its time sum. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
min(*, skipna=True)
#
Minimum over time of every temporal variable (thin wrapper over :meth:reduce).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skipna
|
bool
|
Skip the declared no-data value and NaN. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset; each temporal variable collapsed to its time minimum. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
max(*, skipna=True)
#
Maximum over time of every temporal variable (thin wrapper over :meth:reduce).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skipna
|
bool
|
Skip the declared no-data value and NaN. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset; each temporal variable collapsed to its time maximum. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
std(*, skipna=True)
#
Std-dev over time of every temporal variable (thin wrapper over :meth:reduce).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skipna
|
bool
|
Skip the declared no-data value and NaN. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset; each temporal variable collapsed to its time std. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
var(*, skipna=True)
#
Variance over time of every temporal variable (thin wrapper over :meth:reduce).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skipna
|
bool
|
Skip the declared no-data value and NaN. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset; each temporal variable collapsed to its time variance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
cumsum()
#
Cumulative sum along time for every temporal variable.
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset in which each temporal variable holds the running |
UgridDataset
|
sum of its steps along the time axis; static variables are unchanged. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension, or a temporal variable has no loaded data. |
Examples:
- Running sum over three time steps of a per-face variable:
>>> import numpy as np >>> from pyramids.netcdf.ugrid import UgridDataset >>> mesh = UgridDataset.from_arrays( ... node_x=np.array([0.0, 1.0, 1.0, 0.0]), ... node_y=np.array([0.0, 0.0, 1.0, 1.0]), ... face_node_connectivity=np.array([[0, 1, 2], [0, 2, 3]]), ... data={"d": np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])}, ... data_locations={"d": "face"}, ... ) >>> mesh.cumsum()["d"].data.tolist() [[1.0, 2.0], [4.0, 6.0], [9.0, 12.0]]
Source code in src/pyramids/netcdf/ugrid/dataset.py
cumprod()
#
Cumulative product along time for every temporal variable.
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset in which each temporal variable holds the running |
UgridDataset
|
product of its steps along the time axis; static variables are unchanged. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension, or a temporal variable has no loaded data. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
shift(periods=1)
#
Shift each temporal variable periods steps along time, vacated steps NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
periods
|
int
|
Steps to shift; negative shifts towards the start. Defaults to 1. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with each temporal variable shifted along time, the |
UgridDataset
|
vacated steps filled with NaN; static variables are unchanged. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension, or a temporal variable has no loaded data. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
polyfit(deg, variable_name=None)
#
Fit a polynomial per element along time, returning its coefficients (#1377).
The mesh counterpart of the raster polyfit, and what produces a trend map: a
degree-1 fit per face gives the slope of that face's series.
The time axis is replaced by a coefficient axis of length deg + 1, highest
power first — the order :func:numpy.polyfit returns. The result is therefore no
longer a time series, so it is marked static.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deg
|
int
|
Polynomial degree. |
required |
variable_name
|
str | None
|
Variable to fit (default: every temporal variable). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset whose variables carry the fitted coefficients. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension, |
See Also
curvefit: Fit an arbitrary model instead of a polynomial. differentiate: The instantaneous rate rather than a fitted trend.
Source code in src/pyramids/netcdf/ugrid/dataset.py
curvefit(func, p0=None, variable_name=None)
#
Fit an arbitrary model per element along time (#1377).
The general form of :meth:polyfit. Each element is fitted in turn, since there is no
closed form; an element whose fit does not converge yields NaN parameters rather
than failing the whole call, so one bad face does not lose the other thousands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Any
|
The model |
required |
p0
|
Any
|
Initial parameter guess. Without one the parameter count is read from |
None
|
variable_name
|
str | None
|
Variable to fit (default: every temporal variable). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset whose variables carry the fitted parameters along a |
UgridDataset
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
See Also
polyfit: The closed-form polynomial case, much faster.
Source code in src/pyramids/netcdf/ugrid/dataset.py
differentiate(variable_name=None)
#
The derivative of every temporal variable along time (#1377).
Honours the time coordinate's own spacing, so an unevenly spaced output interval gives the right rate rather than one assuming a uniform step. With a decoded datetime axis (issue #1381) the result is per second.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
Variable to differentiate (default: every temporal variable). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset of rates, the same shape as the input. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension, or the axis has fewer than two steps. |
See Also
integrate: The inverse operation, which consumes the axis.
Source code in src/pyramids/netcdf/ugrid/dataset.py
cumulative_integrate(variable_name=None)
#
The running integral of every temporal variable along time (#1377).
Keeps the time axis, unlike :meth:integrate. The first step is 0 — nothing has
accumulated yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
Variable to integrate (default: every temporal variable). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset of running integrals, the same shape as the input. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension, or the axis has fewer than two steps. |
See Also
integrate: The definite integral, which consumes the axis.
Source code in src/pyramids/netcdf/ugrid/dataset.py
rank(variable_name=None, *, pct=False)
#
Rank each element's values along time, ties averaged (#1377).
Per face this is an exceedance map: where does each step sit among all the steps at that face. Needs no date coordinate, so it works on a positional axis too.
The declared sentinel and NaN are excluded rather than ranked, as the cube's
rank excludes them — ranking a -9999 as the smallest value would shift every
real rank by one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
Variable to rank (default: every temporal variable). |
None
|
pct
|
bool
|
Report each rank as a fraction of that element's usable values rather than a
count, so its largest usable value is |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset of ranks, the same shape as the input, counting from 1 |
UgridDataset
|
(or in |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
See Also
idxmax: The step at which each element peaks.
Source code in src/pyramids/netcdf/ugrid/dataset.py
integrate(variable_name=None)
#
The definite integral of every temporal variable along time (#1377).
The integral consumes the time axis, so the result is static — one value per
element, as :meth:reduce produces. With a decoded datetime axis the units are
value-seconds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
Variable to integrate (default: every temporal variable). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset whose temporal variables are now static totals. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension, or the axis has fewer than two steps. |
See Also
cumulative_integrate: The running integral, which keeps the axis. differentiate: The inverse operation.
Source code in src/pyramids/netcdf/ugrid/dataset.py
coarsen(window, how='mean', variable_name=None)
#
Block-aggregate the time axis into windows of window steps (#1377).
Not a duplicate of :meth:resample. That one bins by a calendar frequency and so
needs date-like coordinates; this bins by a count of steps and needs no coordinate
at all, which makes it the only option for a mesh whose file carries no CF time units.
Where both work, resample is the calendar-aware choice and this the positional one.
A trailing remainder shorter than a full window is dropped, so every reported bin is a full one rather than a short bin that would read as a dip in the series.
A variable with fewer steps than one window cannot be binned at all. In a sweep
(variable_name=None) it is passed through untouched, so one short variable does not
lose the whole call — the choice :meth:convert_units makes for a variable with no
units. Naming such a variable explicitly raises, since that is a request rather than a
sweep, and so does a sweep in which no variable could be binned: that call did
nothing, and returning the dataset unchanged would look like success.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
int
|
Steps per block, at least 1. |
required |
how
|
str
|
|
'mean'
|
variable_name
|
str | None
|
Variable to aggregate (default: every temporal variable). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset whose time axis holds one step per full block, stamped |
UgridDataset
|
with each block's first coordinate value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension, |
See Also
resample: Calendar-frequency binning, when the axis carries real dates. reduce: Collapse the whole axis instead of binning it.
Source code in src/pyramids/netcdf/ugrid/dataset.py
4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 | |
interp_like(other)
#
Interpolate onto another dataset's time stamps (#1377).
What lines two runs up on a common axis before :meth:concat or an operator. Linear,
and deliberately not extrapolating: a target stamp outside this dataset's span comes
back as a gap (NaN), which is the contract the raster interp already has.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
UgridDataset
|
The dataset whose time coordinate supplies the target stamps. Must sit on the same topology. |
required |
Note
Two dated axes are put on a common decimal-year scale, which means the same
thing in every calendar, so this works across calendars as well as within one. The
result declares other's units and calendar, since those are the stamps it now
carries; an undated other leaves the result positional, with no CF metadata at
all.
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset on |
UgridDataset
|
units and calendar (or none, when |
Raises:
| Type | Description |
|---|---|
AlignmentError
|
|
ValueError
|
Either side has no time dimension; this one has fewer than two steps to interpolate between; or one side is dated and the other positional, which have no common scale. |
See Also
interp_time: Interpolate onto a given number of evenly spaced steps.
Source code in src/pyramids/netcdf/ugrid/dataset.py
4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 | |
convert_calendar(calendar, *, align_on='date')
#
Restamp the time axis onto another CF calendar (issue #1381).
The mesh counterpart of :meth:NetCDF.convert_calendar, and what lets a mesh run on a
model calendar be compared or :meth:concat-enated with one on another.
Only the time coordinate changes. No value is touched and nothing is interpolated:
each step keeps its values and is given the stamp its date has in the target calendar.
A date the target has no day for is dropped, and its step with it — 29 February
moving to noleap, 31 December moving to 360_day — so the axis gets shorter.
:meth:interp_calendar is the lossless counterpart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calendar
|
str
|
The target CF calendar — |
required |
align_on
|
str
|
|
'date'
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset whose time axis is restamped onto |
UgridDataset
|
that calendar and the original units. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The axis carries no CF time units; |
See Also
interp_calendar: Keeps every step by interpolating instead of dropping.
Source code in src/pyramids/netcdf/ugrid/dataset.py
4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 | |
interp_calendar(target)
#
Interpolate the values onto another dataset's stamps, across calendars (#1381).
:meth:convert_calendar's lossless counterpart. Where that one restamps the steps it
has and drops the dates the target calendar lacks, this one interpolates the values
onto the target's own stamps, so no step is lost and the two line up exactly — which is
what :meth:concat or an operator between two runs needs.
Both axes are put on a common decimal-year scale — the year plus the fraction of it
elapsed — which means the same thing in every calendar: a 360-day and a 365-day year
both run from Y.0 to Y+1.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
UgridDataset
|
The dataset whose stamps, units and calendar the result takes. Must sit on the same topology. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset on |
Raises:
| Type | Description |
|---|---|
AlignmentError
|
|
ValueError
|
Either side carries no CF time units; this side has fewer than two steps to interpolate between; or the two spans do not overlap at all, so every step would come back a gap. |
Note
A target stamp inside this dataset's span interpolates; one outside it is a gap, not an extrapolation. A partly overlapping target therefore comes back partly masked, and one that does not overlap at all is refused rather than answered as a fully-masked dataset.
See Also
convert_calendar: Restamps without interpolating, dropping absent dates.
Source code in src/pyramids/netcdf/ugrid/dataset.py
4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 | |
to_image(variable_name=None, cell_size=None, cmap='viridis', method='nearest')
#
Export a mesh variable as a colour-mapped RGB image (issue #1378).
An image is a grid of pixels, so the mesh is rasterised first and the raster's own
:meth:Dataset.to_image does the colour mapping — which keeps the colours going
through cleopatra, as all pyramids rendering does, and keeps one implementation of the
mapping rather than two that can drift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
Variable to render (default: the only one). |
None
|
cell_size
|
float | None
|
Pixel size in coordinate units. |
None
|
cmap
|
str
|
Matplotlib colormap name. |
'viridis'
|
method
|
str
|
Rasterisation method, |
'nearest'
|
Returns:
| Type | Description |
|---|---|
Any
|
PIL.Image.Image: The colour-mapped image. The pixels the rasterisation leaves |
Any
|
empty — those outside the mesh footprint — are no-data, and so are rendered with |
Any
|
the colormap's "bad" fill colour, exactly as the raster version renders them. |
Any
|
Requires the |
Raises:
| Type | Description |
|---|---|
ValueError
|
The variable is not one value per element, or no variable is selected and the dataset holds more than one. |
See Also
to_dataset: The rasterisation this builds on, when you want the grid itself. plot: An annotated figure rather than a bare image.
Source code in src/pyramids/netcdf/ugrid/dataset.py
convert_units(target, variable_name=None)
#
Convert variable values to target units (issue #1378).
Mesh variables carry a units attribute, so the raster's conversion applies
unchanged — and it is the same affine table
(:func:pyramids.dataset.ops.units.convert_array), so the two sides cannot disagree
about what a Kelvin is.
No-data elements keep their sentinel rather than being converted as though they were
data, which would otherwise turn -9999 into a plausible-looking temperature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
Target unit label (e.g. |
required |
variable_name
|
str | None
|
Variable to convert. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with converted values and the new unit recorded. |
Raises:
| Type | Description |
|---|---|
ValueError
|
A selected variable declares no source unit, or the
|
See Also
Dataset.convert_units: The raster counterpart, sharing this table.
Source code in src/pyramids/netcdf/ugrid/dataset.py
to_dask_dataframe(variables=None, *, dropna=False, npartitions=1)
#
Hand the mesh to dask in tidy form — the lazy sibling of :meth:to_dataframe.
The mesh's own frame is already tidy (one row per element and step), so this is the same shape wrapped in a dask dataframe rather than a different layout.
What is and is not deferred: a mesh's values live in memory, not in a per-element
chunked store, so there is nothing to stream and the frame is built then partitioned.
The result is a real dask graph — it composes with the rest of a dask pipeline and
computes lazily from here on — but it does not reduce the peak memory of building it.
That is the same thing :meth:NetCDF.to_dask_dataframe does for a cube with no
on-disk store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variables
|
Sequence[str] | None
|
Which data variables to include. |
None
|
dropna
|
bool
|
Drop rows whose value is no-data. Defaults to False. |
False
|
npartitions
|
int
|
How many partitions to split the frame into. Defaults to 1. |
1
|
Returns:
| Type | Description |
|---|---|
Any
|
dask.dataframe.DataFrame: The tidy frame as a dask dataframe. |
Raises:
| Type | Description |
|---|---|
ImportError
|
dask (the |
ValueError
|
|
See Also
to_dataframe: The eager pandas frame this wraps.
Source code in src/pyramids/netcdf/ugrid/dataset.py
ffill(*, limit=None, dim=None)
#
Forward-fill gaps along time from the last valid step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int | None
|
Maximum consecutive gaps one valid step may fill, or |
None
|
dim
|
str | None
|
The dimension to fill along. A mesh fills along |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with each temporal variable's gaps carried forward |
UgridDataset
|
from the previous valid step; static variables are unchanged. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/pyramids/netcdf/ugrid/dataset.py
bfill(*, limit=None, dim=None)
#
Back-fill gaps along time from the next valid step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int | None
|
Maximum consecutive gaps one valid step may fill, or |
None
|
dim
|
str | None
|
The dimension to fill along. A mesh fills along |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with each temporal variable's gaps carried backward |
UgridDataset
|
from the next valid step; static variables are unchanged. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/pyramids/netcdf/ugrid/dataset.py
interpolate_na(*, method='linear', limit=None, use_coordinate=True, dim=None)
#
Fill each interior time gap by interpolating between the steps on either side.
Distance is measured along the time coordinate by default, so unevenly spaced steps
weight their neighbours accordingly; pass use_coordinate=False to measure by step
position instead. A leading or trailing gap has only one neighbour and is left alone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
One of |
'linear'
|
limit
|
int | None
|
Maximum consecutive gaps a run may fill, or |
None
|
use_coordinate
|
bool
|
Measure distance along the time coordinate rather than by step
position. With time values |
True
|
dim
|
str | None
|
The dimension to interpolate along. A mesh interpolates along |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with each temporal variable's interior gaps |
UgridDataset
|
interpolated along time; static variables are unchanged. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/pyramids/netcdf/ugrid/dataset.py
rolling(window, how='mean', *, center=False, min_periods=None, q=None, dim=None)
#
Rolling-window reduction along time for every temporal variable.
Each time step becomes a statistic of the window of steps it owns (ending at it, or
centred on it), cut where the window runs off the axis. Gaps are skipped; a step whose
window holds fewer than min_periods valid cells is NaN. The time dimension keeps
its length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
int
|
Steps per window. |
required |
how
|
str
|
The reduction over each window ( |
'mean'
|
center
|
bool
|
Centre each window on its step rather than ending at it. Defaults to False. |
False
|
min_periods
|
int | None
|
Valid cells a window needs before its step holds a value. |
None
|
q
|
float | None
|
The quantile in |
None
|
dim
|
str | None
|
The dimension to roll along. A mesh rolls along |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with each temporal variable replaced by its rolling |
UgridDataset
|
statistic along time; static variables are unchanged. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/pyramids/netcdf/ugrid/dataset.py
4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 | |
isel(time=None, *, element=None)
#
Select by position along the time axis, the element axis, or both.
The mesh counterpart of :meth:pyramids.netcdf.NetCDF.isel. Over time an integer
selects a single step and collapses the time dimension (the variables become static);
a slice or sequence keeps the time dimension, trimmed to the chosen steps. Over
element the selection is a topology change: the chosen faces are kept and the mesh
is renumbered around them (as :meth:clip does), so the result is a smaller mesh.
Giving both applies the element selection first, then the time selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
int | slice | list[int] | ndarray | None
|
An |
None
|
element
|
int | slice | list[int] | ndarray | None
|
An |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with the selection applied. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Neither |
IndexError
|
A face index is out of range for this mesh. |
Examples:
- Keep one face, renumbering the mesh around it:
>>> import numpy as np >>> from pyramids.netcdf.ugrid import UgridDataset >>> mesh = UgridDataset.from_arrays( ... node_x=np.array([0.0, 1.0, 1.0, 0.0]), ... node_y=np.array([0.0, 0.0, 1.0, 1.0]), ... face_node_connectivity=np.array([[0, 1, 2], [0, 2, 3]]), ... data={"depth": np.array([2.0, 4.0])}, ... ) >>> one = mesh.isel(element=0) >>> one.n_face, one.n_node (1, 3) >>> one["depth"].data.tolist() [2.0]
Source code in src/pyramids/netcdf/ugrid/dataset.py
5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 | |
head(n=5)
#
Keep the first n time steps (fewer if the axis is shorter).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of leading steps to keep. Defaults to 5. |
5
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset trimmed to the first |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
tail(n=5)
#
Keep the last n time steps (fewer if the axis is shorter).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of trailing steps to keep. Defaults to 5. |
5
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset trimmed to the last |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
thin(step)
#
Keep every step-th time step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
int
|
Stride; must be >= 1. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset keeping every |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/pyramids/netcdf/ugrid/dataset.py
drop_isel(indices)
#
Drop the time steps at indices by position, keeping the rest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
int | list[int] | ndarray
|
A step position, or a sequence of them, to drop (negative indices count from the end). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset without the dropped steps. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
squeeze()
#
Drop the time dimension when it has length 1; otherwise return unchanged.
Mirrors :meth:pyramids.netcdf.NetCDF.squeeze for the time axis: a single-step
temporal variable becomes static, a multi-step one is left alone.
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with single-step temporal variables collapsed to |
UgridDataset
|
static, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
A single-step temporal variable has no loaded data. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
diff(n=1)
#
Discrete difference along time (out[i] = x[i] - x[i-1]), n times.
The time dimension shortens by n; a time_values coordinate, if present, drops
its first n entries to stay aligned with the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of successive differences. Defaults to 1. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with each temporal variable differenced along time |
UgridDataset
|
(its time axis shorter by |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension, or a temporal variable has no loaded data. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
argmin()
#
The time-step position of each element's minimum.
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
Static |
UgridDataset
|
declaring |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
argmax()
#
The time-step position of each element's maximum.
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
Static |
UgridDataset
|
declaring |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
idxmin()
#
The time coordinate of each element's minimum.
Where :meth:argmin answers a step position, this answers the value of the time
coordinate at that step, so it needs numeric time coordinates.
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
Static |
UgridDataset
|
minimum, NaN where an element has no valid step. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension, or the time coordinates are
date-like rather than numeric (use |
Source code in src/pyramids/netcdf/ugrid/dataset.py
idxmax()
#
The time coordinate of each element's maximum.
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
Static |
UgridDataset
|
maximum, NaN where an element has no valid step. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension, or the time coordinates are
date-like rather than numeric (use |
Source code in src/pyramids/netcdf/ugrid/dataset.py
sel(time=None, *, method=None, tolerance=None)
#
Select time steps by coordinate value, exactly or by nearest.
The mesh counterpart of :meth:pyramids.netcdf.NetCDF.sel over time. A scalar selects
one step and collapses the time dimension; a sequence keeps it. Values are matched
against the dataset's :attr:time_values (which fall back to step positions when the
file carries no explicit time coordinate). method="nearest" snaps each value to the
closest coordinate instead of requiring an exact hit, and tolerance caps how far it
may snap — the same contract the raster sel uses, including raising KeyError (not
ValueError) when a snap would exceed tolerance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
Any
|
A coordinate value, or a sequence of them. |
None
|
method
|
str | None
|
|
None
|
tolerance
|
float | None
|
The furthest a |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with the selected steps. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No time dimension; an unknown |
KeyError
|
A |
Source code in src/pyramids/netcdf/ugrid/dataset.py
drop_sel(values)
#
Drop the time steps whose coordinate is in values, keeping the rest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Any
|
A coordinate value, or a sequence of them, to drop. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset without the steps whose coordinate is in |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
sortby()
#
Sort the time steps by their coordinate value (stable).
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with steps ordered by ascending time coordinate. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
drop_duplicates()
#
Keep the first step of each distinct time coordinate value.
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with duplicate-coordinate steps removed, first kept. |
Raises:
| Type | Description |
|---|---|
ValueError
|
No variable has a time dimension. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
dropna(how='any', thresh=None, *, dim=None)
#
Drop time steps that do not hold enough valid cells.
A step is kept only when every temporal variable meets the threshold at that
step, so the variables stay time-aligned. how="any" requires every cell of a
variable to be valid (a single gap drops the step); how="all" requires at least
one; thresh overrides how with an explicit valid-cell count per variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
how
|
str
|
|
'any'
|
thresh
|
int | None
|
Explicit minimum valid-cell count per variable, overriding |
None
|
dim
|
str | None
|
The dimension to drop along. A mesh drops along |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset with the surviving steps. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/pyramids/netcdf/ugrid/dataset.py
concat(others)
#
Concatenate same-topology datasets along time.
The mesh counterpart of :meth:pyramids.netcdf.NetCDF.concat. Every dataset must sit
on the same mesh. Each temporal variable's data is concatenated along its time axis
(and its time_values coordinate, when present); a static variable is taken from
self unchanged. The variable set must match across datasets.
A per-step active mask (:attr:MeshVariable.active of shape (n_time, n_element))
is dropped on concatenation — the parts' masks are not joined along time, and the
concatenated time length no longer matches self's mask, so the implicit carry
discards it (issue #1331). A static (n_element,) mask survives, since it applies
to every step. Re-attach a per-step mask after concatenating if you need one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
others
|
UgridDataset | list[UgridDataset]
|
One dataset, or a list of them, to append after |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset spanning the concatenated time axis. |
Raises:
| Type | Description |
|---|---|
AlignmentError
|
A dataset sits on a different mesh. Note this is not a
|
ValueError
|
A dataset carries a different variable set, or a variable has no loaded data. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
merge(others, *, compat='no_conflicts')
#
Merge the variables of same-topology datasets into one.
The mesh counterpart of :meth:pyramids.netcdf.NetCDF.merge. Every dataset must sit
on the same mesh; the union of their variables is returned. A variable name present
in more than one dataset is a conflict and is refused.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
others
|
UgridDataset | list[UgridDataset]
|
One dataset, or a list of them, whose variables join |
required |
compat
|
str
|
How to handle a variable name present in more than one dataset --
|
'no_conflicts'
|
Returns:
| Name | Type | Description |
|---|---|---|
UgridDataset |
UgridDataset
|
A new dataset carrying every variable. |
Raises:
| Type | Description |
|---|---|
AlignmentError
|
A dataset sits on a different mesh. |
ValueError
|
An unknown |
Source code in src/pyramids/netcdf/ugrid/dataset.py
plot(variable_name, ax=None, cmap='viridis', title=None, basemap=None, colorbar=None, points=None, kind='auto', color=None, contour=None, data_style=None, **kwargs)
#
Plot a mesh data variable.
N-6 — this facade now goes through the same module-level
helper as the raster path. The mesh-specific dispatch lives in
:func:pyramids.dataset._plot_helpers.mesh_render; both
Dataset.plot/NetCDF.plot and UgridDataset.plot share
the "resolve data, hand to a single helper" contract so the
two formats no longer maintain independent plotting code paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str
|
Name of the data variable to plot. |
required |
ax
|
Any
|
matplotlib Axes. Created if None. |
None
|
cmap
|
str
|
Colormap name. |
'viridis'
|
title
|
str | None
|
Plot title. Defaults to variable name. |
None
|
basemap
|
bool | str | None
|
If True, add an OpenStreetMap basemap. If a string, use it as the tile provider name (e.g. "CartoDB.Positron"). Default is None (no basemap). Requires the [viz] extra. |
None
|
colorbar
|
bool or ColorBar
|
Colour-bar spec, part of the
shared plot signature. A |
None
|
points
|
ndarray or PointOverlay
|
Accepted for signature symmetry with the raster plot family, but a no-op here — a mesh has no point-overlay layer (the mesh geometry is the data). Ignored. |
None
|
kind
|
str
|
Accepted for signature symmetry with the raster
plot family, but a no-op here — |
'auto'
|
color
|
ColorScaling
|
Colour-scale spec
|
None
|
contour
|
Contour
|
Contour-line spec
|
None
|
data_style
|
DataStyle
|
Data-style / relief spec
|
None
|
**kwargs
|
Any
|
Additional arguments passed to mesh_render
(forwarded to plot_mesh_data). Notably |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
cleopatra.glyphs.gridded.mesh_glyph.MeshGlyph instance with the plot rendered. Use the returned object to access the matplotlib handles and the mappable:
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the selected variable has no loaded data, or if
|
Source code in src/pyramids/netcdf/ugrid/dataset.py
5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 | |
animate(variable_name=None, *, interval=200, **kwargs)
#
Animate a temporal mesh variable over its time axis (issue #1380).
The mesh had no animation at all, although a mesh time series is one of the most
natural things to animate — a flood propagating across an unstructured grid. The
frames come from cleopatra's :meth:MeshGlyph.animate, so this is wiring rather than
new drawing code: the topology stays fixed and each step is drawn on it in turn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_name
|
str | None
|
Variable to animate (default: the only temporal one). |
None
|
interval
|
int
|
Milliseconds between frames. Defaults to 200. |
200
|
**kwargs
|
Any
|
Forwarded to cleopatra's |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Any
|
matplotlib.animation.FuncAnimation: The animation — save it with |
|
Any
|
|
|
Any
|
meth: |
|
animation |
Any
|
cleopatra's mesh and array glyph families return different objects and |
Any
|
pyramids passes each through rather than wrapping one to look like the other. |
|
Any
|
Keep a reference to it — matplotlib warns and stops an animation that is only |
|
Any
|
a temporary, so |
|
Any
|
not. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The variable has no time dimension (there would be one frame), or it has a dimension besides time and the elements — a layered variable needs a layer picked before it can be drawn. |
See Also
plot: A single frame. Dataset.animate: The raster counterpart, over bands.
Examples:
- Animate a water-depth series and save it:
Source code in src/pyramids/netcdf/ugrid/dataset.py
5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 | |
plot_outline(ax=None, basemap=None, **kwargs)
#
Plot mesh wireframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Any
|
matplotlib Axes. Created if None. |
None
|
basemap
|
bool | str | None
|
|
None
|
**kwargs
|
Any
|
Additional arguments passed to plot_mesh_outline. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
cleopatra.glyphs.gridded.mesh_glyph.MeshGlyph instance with the wireframe
rendered. |
Source code in src/pyramids/netcdf/ugrid/dataset.py
__str__()
#
Human-readable summary of the dataset.
Source code in src/pyramids/netcdf/ugrid/dataset.py
__repr__()
#
Repr string for the dataset.