GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — wrf-python/src/wrf/extension.py at develop · xenos-code/wrf-python Expand file tree/ Copy pathextension.pyMore file actions executable file ·1665 lines (1167 loc) · 45.1 KB / Copy pathextension.pyFile metadata and controlsexecutable file ·1665 lines (1167 loc) · 45.1 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 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 from __future__ import (absolute_import, division, print_function) import numpy as np from .constants import Constants, default_fill from wrf._wrffortran import (dcomputetk, dinterp3dz, dinterp2dxy, dinterp1d, dcomputeseaprs, dfilter2d, dcomputerh, dcomputeuvmet, dcomputetd, dcapecalc2d, dcapecalc3d, dcloudfrac2, wrfcttcalc, calcdbz, dcalrelhl, dcalcuh, dcomputepv, dcomputeabsvort, dlltoij, dijtoll, deqthecalc, omgcalc, virtual_temp, wetbulbcalc, dcomputepw, wrf_monotonic, wrf_vintrp, dcomputewspd, dcomputewdir, dinterp3dz_2dlev, fomp_set_num_threads, fomp_get_num_threads, fomp_get_max_threads, fomp_get_thread_num, fomp_get_num_procs, fomp_in_parallel, fomp_set_dynamic, fomp_get_dynamic, fomp_set_nested, fomp_get_nested, fomp_set_schedule, fomp_get_schedule, fomp_get_thread_limit, fomp_set_max_active_levels, fomp_get_max_active_levels, fomp_get_level, fomp_get_ancestor_thread_num, fomp_get_team_size, fomp_get_active_level, fomp_in_final, fomp_init_lock, fomp_init_nest_lock, fomp_destroy_lock, fomp_destroy_nest_lock, fomp_set_lock, fomp_set_nest_lock, fomp_unset_lock, fomp_unset_nest_lock, fomp_test_lock, fomp_test_nest_lock, fomp_get_wtime, fomp_get_wtick, fomp_enabled) from .decorators import (left_iteration, cast_type, extract_and_transpose, check_args) from .util import combine_dims, npbytes_to_str, psafilepath from .py3compat import py3range from .specialdec import (uvmet_left_iter, cape_left_iter, cloudfrac_left_iter, check_cape_args, interplevel_left_iter, check_interplevel_args) class DiagnosticError(Exception): """Raised when an error occurs in a diagnostic routine.""" def __init__(self, message=None): """Initialize a :class:`wrf.DiagnosticError` object. Args: message (:obj:`str`): The error message. """ self._msg = message def __str__(self): return self._msg def __call__(self, message): """Callable method to make the exception object raise itself. This allows the exception to be thrown from inside Fortran routines by using f2py's callback mechanism. This is no longer used within wrf-python, but may be useful to other users. See Also: `f2py doc <http://docs.scipy.org/doc/numpy-1.11.0/f2py/>`_ """ raise self.__class__(message) # The routines below are thin wrappers around the Fortran functions. These # are not meant to be called by end users. Use the public API instead for # that purpose. # IMPORTANT! Unless otherwise noted, all variables used in the routines # below assume that Fortran-ordered views are being used. This allows # f2py to pass the array pointers directly to the Fortran routine. @check_interplevel_args(is2dlev=False) @interplevel_left_iter(is2dlev=False) @cast_type(arg_idxs=(0, 1, 2)) @extract_and_transpose() def _interpz3d(field3d, z, desiredloc, missingval, outview=None): """Wrapper for dinterp3dz. Located in wrf_user.f90. """ if outview is None: outshape = field3d.shape[0:2] + desiredloc.shape outview = np.empty(outshape, np.float64, order="F") result = dinterp3dz(field3d, outview, z, desiredloc, missingval) return result @check_interplevel_args(is2dlev=True) @interplevel_left_iter(is2dlev=True) @cast_type(arg_idxs=(0, 1, 2)) @extract_and_transpose() def _interpz3d_lev2d(field3d, z, lev2d, missingval, outview=None): """Wrapper for dinterp3dz. Located in wrf_user.f90. """ if outview is None: outview = np.empty(field3d.shape[0:2], np.float64, order="F") result = dinterp3dz_2dlev(field3d, outview, z, lev2d, missingval) return result @check_args(0, 3, (3, )) @left_iteration(3, combine_dims([(0, -3), (1, -2)]), ref_var_idx=0, ignore_args=(1, )) @cast_type(arg_idxs=(0, 1)) @extract_and_transpose() def _interp2dxy(field3d, xy, outview=None): """Wrapper for dinterp2dxy. Located in wrf_user.f90. """ if outview is None: outview = np.empty((xy.shape[-1], field3d.shape[-1]), np.float64, order="F") result = dinterp2dxy(field3d, outview, xy) return result @check_args(0, 1, (1, 1, None, None)) @left_iteration(1, combine_dims([(2, 0)]), ref_var_idx=0, ignore_args=(2, 3)) @cast_type(arg_idxs=(0, 1, 2)) @extract_and_transpose() def _interp1d(v_in, z_in, z_out, missingval, outview=None): """Wrapper for dinterp1d. Located in wrf_user.f90. """ if outview is None: outview = np.empty_like(z_out) result = dinterp1d(v_in, outview, z_in, z_out, missingval) return result @left_iteration(3, combine_dims([(3, 0), (1, 0)]), ref_var_idx=0, ignore_args=(1, 3, 4)) @cast_type(arg_idxs=(0, )) @extract_and_transpose(do_transpose=False) def _vertcross(field3d, xy, var2dz, z_var2d, missingval, outview=None): """Return the vertical cross section. This routine was originally written in scripted NCL code and doesn't directly wrap a Fortran routine. Located in WRFUserARW.ncl. """ # Note: This is using C-ordering if outview is None: outview = np.empty((z_var2d.shape[0], xy.shape[0]), dtype=var2dz.dtype) var2dtmp = _interp2dxy(field3d, xy) for i in py3range(xy.shape[0]): outview[:, i] = _interp1d(var2dtmp[:, i], var2dz[:, i], z_var2d, missingval) return outview @left_iteration(2, combine_dims([(1, 0)]), ref_var_idx=0, ignore_args=(1, )) @cast_type(arg_idxs=(0, )) @extract_and_transpose(do_transpose=False) def _interpline(field2d, xy, outview=None): """Return the two-dimensional field interpolated to a line. This routine was originally written in scripted NCL code and doesn't directly wrap a Fortran routine. Located in WRFUserARW.ncl. """ # Note: This is using C-ordering if outview is None: outview = np.empty(xy.shape[0], dtype=field2d.dtype) tmp_shape = (1,) + field2d.shape var2dtmp = np.empty(tmp_shape, field2d.dtype) var2dtmp[0, :, :] = field2d[:, :] var1dtmp = _interp2dxy(var2dtmp, xy) outview[:] = var1dtmp[0, :] return outview @check_args(0, 3, (3, 3, 3, 3)) @left_iteration(3, 2, ref_var_idx=0) @cast_type(arg_idxs=(0, 1, 2, 3)) @extract_and_transpose() def _slp(z, t, p, q, outview=None): """Wrapper for dcomputeseaprs. Located in wrf_user.f90. """ t_surf = np.zeros(z.shape[0:2], np.float64, order="F") t_sea_level = np.zeros(z.shape[0:2], np.float64, order="F") level = np.zeros(z.shape[0:2], np.int32, order="F") if outview is None: outview = np.empty(z.shape[0:2], np.float64, order="F") errstat = np.array(0) errmsg = np.zeros(Constants.ERRLEN, "c") result = dcomputeseaprs(z, t, p, q, outview, t_sea_level, t_surf, level, errstat=errstat, errmsg=errmsg) if int(errstat) != 0: raise DiagnosticError("".join(npbytes_to_str(errmsg)).strip()) return result @check_args(0, 3, (3, 3)) @left_iteration(3, 3, ref_var_idx=0) @cast_type(arg_idxs=(0, 1)) @extract_and_transpose() def _tk(pressure, theta, outview=None): """Wrapper for dcomputetk. Located in wrf_user.f90. """ # No need to transpose here since operations on 1D array shape = pressure.shape if outview is None: outview = np.empty_like(pressure) result = dcomputetk(outview.ravel(order="A"), pressure.ravel(order="A"), theta.ravel(order="A")) result = np.reshape(result, shape, order="F") return result @check_args(0, 2, (2, 2)) @left_iteration(2, 2, ref_var_idx=0) @cast_type(arg_idxs=(0, 1)) @extract_and_transpose() def _td(pressure, qv_in, outview=None): """Wrapper for dcomputetd. Located in wrf_user.f90. """ shape = pressure.shape if outview is None: outview = np.empty_like(pressure) result = dcomputetd(outview.ravel(order="A"), pressure.ravel(order="A"), qv_in.ravel(order="A")) result = np.reshape(result, shape, order="F") return result @check_args(0, 2, (2, 2, 2)) @left_iteration(2, 2, ref_var_idx=0) @cast_type(arg_idxs=(0, 1, 2)) @extract_and_transpose() def _rh(qv, q, t, outview=None): """Wrapper for dcomputerh. Located in wrf_user.f90. """ shape = qv.shape if outview is None: outview = np.empty_like(qv) result = dcomputerh(qv.ravel(order="A"), q.ravel(order="A"), t.ravel(order="A"), outview.ravel(order="A")) result = np.reshape(result, shape, order="F") return result # Note: combining the -3 and -2 dimensions from u, then the -1 dimension # from v @check_args(0, 3, (3, 3, 2, 2, 2, 2), stagger=(-1, -2, -1, -2, None, None), refstagdim=-1) @left_iteration(3, combine_dims([(0, (-3, -2)), (1, (-1, ))]), ref_var_idx=0, ignore_args=(6, 7)) @cast_type(arg_idxs=(0, 1, 2, 3, 4, 5)) @extract_and_transpose() def _avo(u, v, msfu, msfv, msfm, cor, dx, dy, outview=None): """Wrapper for dcomputeabsvort. Located in wrf_pvo.f90. """ if outview is None: outshape = (v.shape[0], ) + u.shape[1:] outview = np.empty(outshape, np.float64, order="F") result = dcomputeabsvort(outview, u, v, msfu, msfv, msfm, cor, dx, dy) return result @check_args(0, 3, (3, 3, 3, 3, 2, 2, 2, 2), stagger=(-1, -2, None, None, -1, -2, None, None), refstagdim=-1) @left_iteration(3, 3, ref_var_idx=2, ignore_args=(8, 9)) @cast_type(arg_idxs=(0, 1, 2, 3, 4, 5, 6, 7)) @extract_and_transpose() def _pvo(u, v, theta, prs, msfu, msfv, msfm, cor, dx, dy, outview=None): """Wrapper for dcomputepv. Located in wrf_pvo.f90. """ if outview is None: outview = np.empty_like(prs) result = dcomputepv(outview, u, v, theta, prs, msfu, msfv, msfm, cor, dx, dy) return result @check_args(0, 3, (3, 3, 3)) @left_iteration(3, 3, ref_var_idx=0) @cast_type(arg_idxs=(0, 1, 2)) @extract_and_transpose() def _eth(qv, tk, p, outview=None): """Wrapper for deqthecalc. Located in eqthecalc.f90. """ if outview is None: outview = np.empty_like(qv) result = deqthecalc(qv, tk, p, outview) return result @uvmet_left_iter() @cast_type(arg_idxs=(0, 1, 2, 3)) @extract_and_transpose() def _uvmet(u, v, lat, lon, cen_long, cone, isstag=0, has_missing=False, umissing=default_fill(np.float64), vmissing=default_fill(np.float64), uvmetmissing=default_fill(np.float64), outview=None): """Wrapper for dcomputeuvmet. Located in wrf_user.f90. """ longca = np.zeros(lat.shape[0:2], np.float64, order="F") longcb = np.zeros(lon.shape[0:2], np.float64, order="F") rpd = Constants.PI/180. if outview is None: outdims = u.shape + (2,) outview = np.empty(outdims, np.float64, order="F") result = dcomputeuvmet(u, v, outview, longca, longcb, lon, lat, cen_long, cone, rpd, isstag, has_missing, umissing, vmissing, uvmetmissing) return result @check_args(0, 3, (3, 3, 3, 3)) @left_iteration(3, 3, ref_var_idx=0) @cast_type(arg_idxs=(0, 1, 2, 3)) @extract_and_transpose() def _omega(qv, tk, w, p, outview=None): """Wrapper for omgcalc. Located in wrf_rip_phys_routines.f90. """ if outview is None: outview = np.empty_like(qv) result = omgcalc(qv, tk, w, p, outview) return result @check_args(0, 3, (3, 3)) @left_iteration(3, 3, ref_var_idx=0) @cast_type(arg_idxs=(0, 1)) @extract_and_transpose() def _tv(tk, qv, outview=None): """Wrapper for virtual_temp. Located in wrf_rip_phys_routines.f90. """ if outview is None: outview = np.empty_like(tk) result = virtual_temp(tk, qv, outview) return result @check_args(0, 3, (3, 3, 3)) @left_iteration(3, 3, ref_var_idx=0, ignore_args=(3,)) @cast_type(arg_idxs=(0, 1, 2)) @extract_and_transpose() def _wetbulb(p, tk, qv, psafile=psafilepath(), outview=None): """Wrapper for wetbulbcalc. Located in wrf_rip_phys_routines.f90. """ if outview is None: outview = np.empty_like(p) errstat = np.array(0) errmsg = np.zeros(Constants.ERRLEN, "c") result = wetbulbcalc(p, tk, qv, outview, psafile, errstat, errmsg) if int(errstat) != 0: raise DiagnosticError("".join(npbytes_to_str(errmsg)).strip()) return result @check_args(0, 3, (3, 3, 3, 2, 2)) @left_iteration(3, 2, ref_var_idx=0, ignore_args=(5, )) @cast_type(arg_idxs=(0, 1, 2, 3, 4)) @extract_and_transpose() def _srhel(u, v, z, ter, lats, top, outview=None): """Wrapper for dcalrelhl. Located in wrf_relhl.f90. """ if outview is None: outview = np.empty_like(ter) result = dcalrelhl(u, v, z, ter, lats, top, outview) return result @check_args(2, 3, (3, 2, 3, 3, 3), stagger=(-3, None, None, None, -3)) @left_iteration(3, 2, ref_var_idx=2, ignore_args=(5, 6, 7, 8)) @cast_type(arg_idxs=(0, 1, 2, 3, 4)) @extract_and_transpose() def _udhel(zstag, mapfct, u, v, wstag, dx, dy, bottom, top, outview=None): """Wrapper for dcalcuh. Located in calc_uh.f90. """ if outview is None: outview = np.empty_like(mapfct) tem1 = np.zeros((u.shape[0], u.shape[1], u.shape[2]), np.float64, order="F") tem2 = np.zeros((u.shape[0], u.shape[1], u.shape[2]), np.float64, order="F") result = dcalcuh(zstag, mapfct, dx, dy, bottom, top, u, v, wstag, outview, tem1, tem2) return result @check_args(0, 3, (3, 3, 3, 3), stagger=(None, None, None, -3)) @left_iteration(3, 2, ref_var_idx=0) @cast_type(arg_idxs=(0, 1, 2, 3)) @extract_and_transpose() def _pw(p, tv, qv, ht, outview=None): """Wrapper for dcomputepw. Located in wrf_pw.f90. """ if outview is None: outview = np.empty(p.shape[0:2], p.dtype, order="F") result = dcomputepw(p, tv, qv, ht, outview) return result @check_args(0, 3, (3, 3, 3, 3, 3, 3)) @left_iteration(3, 3, ref_var_idx=0, ignore_args=(6, 7, 8)) @cast_type(arg_idxs=(0, 1, 2, 3, 4, 5)) @extract_and_transpose() def _dbz(p, tk, qv, qr, qs, qg, sn0, ivarint, iliqskin, outview=None): """Wrapper for calcdbz. Located in wrf_user_dbz.f90. """ if outview is None: outview = np.empty_like(p) result = calcdbz(p, tk, qv, qr, qs, qg, sn0, ivarint, iliqskin, outview) return result @check_cape_args() @cape_left_iter() @cast_type(arg_idxs=(0, 1, 2, 3, 4, 5), outviews=("capeview", "cinview")) @extract_and_transpose(outviews=("capeview", "cinview")) def _cape(p_hpa, tk, qv, ht, ter, sfp, missing, i3dflag, ter_follow, psafile=psafilepath(), capeview=None, cinview=None): """Wrapper for dcapecalc3d. Located in rip_cape.f90. """ if capeview is None: capeview = np.zeros(p_hpa.shape[0:3], p_hpa.dtype, order="F") if cinview is None: cinview = np.zeros(p_hpa.shape[0:3], p_hpa.dtype, order="F") errstat = np.array(0) errmsg = np.zeros(Constants.ERRLEN, "c") if i3dflag: cape_routine = dcapecalc3d else: cape_routine = dcapecalc2d # Work arrays k_left_shape = (p_hpa.shape[2], p_hpa.shape[0], p_hpa.shape[1]) prsf = np.empty(k_left_shape, np.float64, order="F") prs_new = np.empty(k_left_shape, np.float64, order="F") tmk_new = np.empty(k_left_shape, np.float64, order="F") qvp_new = np.empty(k_left_shape, np.float64, order="F") ght_new = np.empty(k_left_shape, np.float64, order="F") # note that p_hpa, tk, qv, and ht have the vertical flipped result = cape_routine(p_hpa, tk, qv, ht, ter, sfp, capeview, cinview, prsf, prs_new, tmk_new, qvp_new, ght_new, missing, ter_follow, psafile, errstat, errmsg) if int(errstat) != 0: raise DiagnosticError("".join(npbytes_to_str(errmsg)).strip()) return result @check_args(0, 3, (3, 3)) @cloudfrac_left_iter() @cast_type(arg_idxs=(0, 1), outviews=("lowview", "midview", "highview")) @extract_and_transpose(outviews=("lowview", "midview", "highview")) def _cloudfrac(vert, rh, vert_inc_w_height, low_thresh, mid_thresh, high_thresh, missing, lowview=None, midview=None, highview=None): """Wrapper for dcloudfrac2. Located in wrf_cloud_fracf.f90. """ if lowview is None: lowview = np.zeros(vert.shape[0:2], vert.dtype, order="F") if midview is None: midview = np.zeros(vert.shape[0:2], vert.dtype, order="F") if highview is None: highview = np.zeros(vert.shape[0:2], vert.dtype, order="F") result = dcloudfrac2(vert, rh, vert_inc_w_height, low_thresh, mid_thresh, high_thresh, missing, lowview, midview, highview) return result def _lltoxy(map_proj, truelat1, truelat2, stdlon, lat1, lon1, pole_lat, pole_lon, known_x, known_y, dx, dy, latinc, loninc, lat, lon, outview=None): """Wrapper for dlltoij. Located in wrf_user_latlon_routines.f90. """ if outview is None: outview = np.zeros((2), dtype=np.float64, order="F") errstat = np.array(0) errmsg = np.zeros(Constants.ERRLEN, "c") result = dlltoij(map_proj, truelat1, truelat2, stdlon, lat1, lon1, pole_lat, pole_lon, known_x, known_y, dx, dy, latinc, loninc, lat, lon, outview, errstat, errmsg) if int(errstat) != 0: raise DiagnosticError("".join(npbytes_to_str(errmsg)).strip()) return result def _xytoll(map_proj, truelat1, truelat2, stdlon, lat1, lon1, pole_lat, pole_lon, known_x, known_y, dx, dy, latinc, loninc, x, y, outview=None): """Wrapper for dijtoll. Located in wrf_user_latlon_routines.f90. """ if outview is None: outview = np.zeros((2), dtype=np.float64, order="F") errstat = np.array(0) errmsg = np.zeros(Constants.ERRLEN, "c") result = dijtoll(map_proj, truelat1, truelat2, stdlon, lat1, lon1, pole_lat, pole_lon, known_x, known_y, dx, dy, latinc, loninc, x, y, outview, errstat, errmsg) if int(errstat) != 0: raise DiagnosticError("".join(npbytes_to_str(errmsg)).strip()) return result @check_args(0, 3, (3, 3, 3, 3, 3, 3, 2)) @left_iteration(3, 2, ref_var_idx=0, ignore_args=(7, 8, 9, 10)) @cast_type(arg_idxs=(0, 1, 2, 3, 4, 5, 6)) @extract_and_transpose() def _ctt(p_hpa, tk, qice, qcld, qv, ght, ter, haveqci, fill_nocloud, missing, opt_thresh, outview=None): """Wrapper for wrfcttcalc. Located in wrf_fctt.f90. """ if outview is None: outview = np.empty_like(ter) pf = np.empty(p_hpa.shape[0:3], np.float64, order="F") result = wrfcttcalc(p_hpa, tk, qice, qcld, qv, ght, ter, outview, pf, haveqci, fill_nocloud, missing, opt_thresh) return result @check_args(0, 2, (2, )) @left_iteration(2, 2, ref_var_idx=0, ignore_args=(1, 2)) @cast_type(arg_idxs=(0, )) @extract_and_transpose() def _smooth2d(field, passes, cenweight, outview=None): """Wrapper for dfilter2d. Located in wrf_user.f90. """ # Unlike NCL, this routine will not modify the values in place, but # copies the original data before modifying it. if isinstance(field, np.ma.MaskedArray): missing = field.fill_value else: missing = default_fill(np.float64) if outview is None: outview = field.copy(order="A") else: outview[:] = field[:] field_tmp = np.zeros(outview.shape, outview.dtype, order="F") dfilter2d(outview, field_tmp, passes, missing, cenweight) return outview @check_args(0, 3, (3, 3, 2)) @left_iteration(3, 3, ref_var_idx=0, ignore_args=(3, 4, 5)) @cast_type(arg_idxs=(0, 1, 2)) @extract_and_transpose() def _monotonic(var, lvprs, coriolis, idir, delta, icorsw, outview=None): """Wrapper for wrf_monotonic. Located in wrf_vinterp.f90. """ # If icorsw is not 0, then the input variable might get modified by the # fortran routine. We don't want this, so make a copy and pass that on. var = var.copy(order="A") if icorsw != 0 else var if outview is None: outview = np.empty_like(var) result = wrf_monotonic(outview, var, lvprs, coriolis, idir, delta, icorsw) return result # Output shape is interp_levels.shape + field.shape[-2:] @check_args(0, 3, (3, 3, 3, 3, 3, 2, 2, 2, 3)) @left_iteration(3, combine_dims([(9, (-1, )), (0, (-2, -1))]), ref_var_idx=0, ignore_args=(9, 10, 11, 12, 13, 14)) @cast_type(arg_idxs=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) @extract_and_transpose() def _vintrp(field, pres, tk, qvp, ght, terrain, sfp, smsfp, vcarray, interp_levels, icase, extrap, vcor, logp, missing, outview=None): """Wrapper for wrf_vintrp. Located in wrf_vinterp.f90. """ if outview is None: outdims = field.shape[0:2] + interp_levels.shape outview = np.empty(outdims, field.dtype, order="F") tempout = np.zeros(field.shape[0:2], np.float64, order="F") errstat = np.array(0) errmsg = np.zeros(Constants.ERRLEN, "c") result = wrf_vintrp(field, outview, pres, tk, qvp, ght, terrain, sfp, smsfp, vcarray, interp_levels, icase, extrap, vcor, logp, tempout, missing, errstat, errmsg) if int(errstat) != 0: raise DiagnosticError("".join(npbytes_to_str(errmsg)).strip()) return result @check_args(0, 2, (2, 2)) @left_iteration(2, 2, ref_var_idx=0) @cast_type(arg_idxs=(0, 1)) @extract_and_transpose() def _wspd(u, v, outview=None): """Wrapper for dcomputewspd. Located in wrf_wind.f90. """ shape = u.shape if outview is None: outview = np.empty_like(u) result = dcomputewspd(outview.ravel(order="A"), u.ravel(order="A"), v.ravel(order="A")) result = np.reshape(result, shape, order="F") return result @check_args(0, 2, (2, 2)) @left_iteration(2, 2, ref_var_idx=0) @cast_type(arg_idxs=(0, 1)) @extract_and_transpose() def _wdir(u, v, outview=None): """Wrapper for dcomputewdir. Located in wrf_wind.f90. """ shape = u.shape if outview is None: outview = np.empty_like(u) result = dcomputewdir(outview.ravel(order="A"), u.ravel(order="A"), v.ravel(order="A")) result = np.reshape(result, shape, order="F") return result # OpenMP runtime wrappers def omp_set_num_threads(num_threads): """Specify the number of threads to use. The omp_set_num_threads routine affects the number of threads to be used for subsequent parallel regions that do not specify a num_threads clause, by setting the value of the first element of the nthreads-var ICV of the current task. Args: num_threads (a positive :obj:`int`): The number of threads. Must be |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |