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 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
|
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Python interface — HARP 1.12 documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="next" title="R interface" href="R.html" />
<link rel="prev" title="MATLAB interface" href="matlab.html" />
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> HARP
</a>
<div class="version">
1.12
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="conventions/index.html">Conventions</a></li>
<li class="toctree-l1"><a class="reference internal" href="algorithms/index.html">Algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="operations.html">Operations</a></li>
<li class="toctree-l1"><a class="reference internal" href="ingestions/index.html">Ingestion definitions</a></li>
<li class="toctree-l1"><a class="reference internal" href="libharp.html">C library</a></li>
<li class="toctree-l1"><a class="reference internal" href="idl.html">IDL interface</a></li>
<li class="toctree-l1"><a class="reference internal" href="matlab.html">MATLAB interface</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Python interface</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#dimension-types">Dimension types</a></li>
<li class="toctree-l2"><a class="reference internal" href="#data-types">Data types</a></li>
<li class="toctree-l2"><a class="reference internal" href="#unicode">Unicode</a></li>
<li class="toctree-l2"><a class="reference internal" href="#examples">Examples</a></li>
<li class="toctree-l2"><a class="reference internal" href="#api-reference">API reference</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#types">Types</a></li>
<li class="toctree-l3"><a class="reference internal" href="#functions">Functions</a></li>
<li class="toctree-l3"><a class="reference internal" href="#exceptions">Exceptions</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="R.html">R interface</a></li>
<li class="toctree-l1"><a class="reference internal" href="tools.html">Command line tools</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">HARP</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Python interface</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="python-interface">
<h1>Python interface</h1>
<p>The Python interface consists of a Python package <code class="docutils literal notranslate"><span class="pre">'harp'</span></code> that provides a set
of functions to <a class="reference internal" href="#harp.import_product" title="harp.import_product"><code class="xref py py-func docutils literal notranslate"><span class="pre">import</span></code></a> and <a class="reference internal" href="#harp.export_product" title="harp.export_product"><code class="xref py py-func docutils literal notranslate"><span class="pre">export</span></code></a> HARP products. The import can be used to read products
using the HARP format or to read non-HARP products of a type <a class="reference internal" href="ingestions/index.html"><span class="doc">supported by
HARP</span></a>. The Python interface depends on the <code class="docutils literal notranslate"><span class="pre">_cffi_backend</span></code>
module, which is part of the C foreign function interface (cffi) package. This
package must be installed in order to be able to use the Python interface. See
the <a class="reference external" href="http://cffi.readthedocs.org/en/latest/installation.html">cffi documentation</a> for details on how to install the cffi package.</p>
<p>Products are represented in Python by instances of <a class="reference internal" href="#harp.Product" title="harp.Product"><code class="xref py py-class docutils literal notranslate"><span class="pre">harp.Product</span></code></a>,
which can be manipulated freely from within Python. A <a class="reference internal" href="#harp.Product" title="harp.Product"><code class="xref py py-class docutils literal notranslate"><span class="pre">harp.Product</span></code></a>
instance contains a <a class="reference internal" href="#harp.Variable" title="harp.Variable"><code class="xref py py-class docutils literal notranslate"><span class="pre">harp.Variable</span></code></a> instance for each variable
contained in the product. A <a class="reference internal" href="#harp.Product" title="harp.Product"><code class="xref py py-class docutils literal notranslate"><span class="pre">harp.Product</span></code></a> also contains special
entries for the global attributes <cite>source_product</cite> and <cite>history</cite>
(a <a class="reference internal" href="#harp.Product" title="harp.Product"><code class="xref py py-class docutils literal notranslate"><span class="pre">harp.Product</span></code></a> will thus not be able to contain variables with
these names). Note that the <cite>Conventions</cite>, <cite>datetime_start</cite> and <cite>datetime_stop</cite>
global attributes are not included in a <a class="reference internal" href="#harp.Product" title="harp.Product"><code class="xref py py-class docutils literal notranslate"><span class="pre">harp.Product</span></code></a> as these are
automatically handled by the import/export functions of HARP.</p>
<p>Products can be <a class="reference internal" href="#harp.export_product" title="harp.export_product"><code class="xref py py-func docutils literal notranslate"><span class="pre">exported</span></code></a> as HARP compliant
products in any of the file formats supported by the HARP C library
(NetCDF/HDF4/HDF5). Such exported products can subsequently be processed further
using the <a class="reference internal" href="tools.html"><span class="doc">HARP command line tools</span></a>. Products can also be
<a class="reference internal" href="#harp.to_dict" title="harp.to_dict"><code class="xref py py-func docutils literal notranslate"><span class="pre">converted</span></code></a> to an <code class="docutils literal notranslate"><span class="pre">OrderedDict</span></code>. This can be
convenient when there is a need to interface with existing code such as plotting
libraries, or when the additional information provided by the
<a class="reference internal" href="#harp.Product" title="harp.Product"><code class="xref py py-class docutils literal notranslate"><span class="pre">harp.Product</span></code></a> representation is not needed.</p>
<div class="section" id="dimension-types">
<h2>Dimension types</h2>
<p>The HARP C library defines several dimension types. Each dimension of a variable
is associated with one of these dimension types. The number of dimension types
should match the number of dimensions of the data array.</p>
<p>In Python, all dimension types are referred to by name, except the
<code class="docutils literal notranslate"><span class="pre">independent</span></code> dimension type. Dimension type names are case-sensitive. The
<code class="docutils literal notranslate"><span class="pre">independent</span></code> dimension type is special because variable dimensions associated
with this dimension type need not be of the same length (in contrast to all
other dimension types). The <code class="docutils literal notranslate"><span class="pre">independent</span></code> dimension type is represented in
Python by <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
<p>Each <a class="reference internal" href="#harp.Variable" title="harp.Variable"><code class="xref py py-class docutils literal notranslate"><span class="pre">harp.Variable</span></code></a> instance contains an attribute <code class="docutils literal notranslate"><span class="pre">dimension</span></code>,
which is a list of dimension types. For each dimension of a variable, the
<code class="docutils literal notranslate"><span class="pre">dimension</span></code> attribute indicates the dimension type it is associated with.</p>
<p>The dimension types supported by HARP are:</p>
<dl class="docutils">
<dt>time</dt>
<dd>Temporal dimension; this is the only appendable dimension.</dd>
<dt>vertical</dt>
<dd>Vertical dimension, indicating height or depth.</dd>
<dt>spectral</dt>
<dd>Spectral dimension, associated with wavelength, wavenumber, or frequency.</dd>
<dt>latitude</dt>
<dd>Latitude dimension, only to be used for the latitude axis of a regular
(latitude, longitude) grid.</dd>
<dt>longitude</dt>
<dd>Longitude dimension, only to be used for the longitude axis of a regular
(latitude, longitude) grid.</dd>
<dt>independent</dt>
<dd>Independent dimension, used to index other quantities, such as the corner
coordinates of ground pixel polygons.</dd>
</dl>
</div>
<div class="section" id="data-types">
<h2>Data types</h2>
<p>The HARP Python interface takes care of the conversion of product and variables
from the C domain to the Python domain and back. This section describes the
relation between types in the C domain and types in the Python domain.</p>
<p>The table below shows the type map that is used to convert the high level
concepts product and variable.</p>
<table border="1" class="docutils">
<colgroup>
<col width="45%" />
<col width="55%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">C type</th>
<th class="head">Python type</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>harp_product</td>
<td>harp.Product</td>
</tr>
<tr class="row-odd"><td>harp_variable</td>
<td>harp.Variable</td>
</tr>
</tbody>
</table>
<p>The table below shows the type map that is used when importing a product, i.e.
when translating from the C domain to the Python domain.</p>
<p>Variable data arrays are converted to NumPy arrays. The NumPy data type used for
the converted array is determined from the HARP data type of the variable
according to the type map shown below. Zero-dimensional arrays of length 1 are
converted to Python scalars using the <code class="docutils literal notranslate"><span class="pre">numpy.asscalar()</span></code> function. The
resulting Python type is also shown in the type map.</p>
<p>Product and variable attributes, being scalars, are converted directly to Python
scalars. The Python type is determined from the HARP data type according to the
type map.</p>
<p>Zero-terminated C strings are always converted to instances of type <code class="docutils literal notranslate"><span class="pre">str</span></code> in
Python. See section <a class="reference internal" href="#unicode-details"><span class="std std-ref">Unicode</span></a> for details on unicode
decoding in Python 3.</p>
<table border="1" class="docutils">
<colgroup>
<col width="28%" />
<col width="25%" />
<col width="20%" />
<col width="28%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">HARP data type</th>
<th class="head">NumPy dtype</th>
<th class="head">Python type</th>
<th class="head">unicode decoding</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>harp_type_int8</td>
<td>numpy.int8</td>
<td>int</td>
<td> </td>
</tr>
<tr class="row-odd"><td>harp_type_int16</td>
<td>numpy.int16</td>
<td>int</td>
<td> </td>
</tr>
<tr class="row-even"><td>harp_type_int32</td>
<td>numpy.int32</td>
<td>int</td>
<td> </td>
</tr>
<tr class="row-odd"><td>harp_type_float</td>
<td>numpy.float32</td>
<td>float</td>
<td> </td>
</tr>
<tr class="row-even"><td>harp_type_double</td>
<td>numpy.float64</td>
<td>float</td>
<td> </td>
</tr>
<tr class="row-odd"><td>harp_type_string</td>
<td>numpy.object_</td>
<td>str</td>
<td>Python 3</td>
</tr>
</tbody>
</table>
<p>The table below shows the type map that is used when exporting a product, i.e.
when translating from the Python domain to the C domain.</p>
<p>NumPy object arrays (that is, NumPy arrays with data type <code class="docutils literal notranslate"><span class="pre">numpy.object_</span></code>)
will be converted to arrays of zero-terminated C strings. The elements of a
NumPy object array must be all <code class="docutils literal notranslate"><span class="pre">str</span></code> or all <code class="docutils literal notranslate"><span class="pre">bytes</span></code>. (Note that on Python 2,
<code class="docutils literal notranslate"><span class="pre">bytes</span></code> is an alias of <code class="docutils literal notranslate"><span class="pre">str</span></code>.) NumPy arrays with data type <code class="docutils literal notranslate"><span class="pre">numpy.str_</span></code> or
<code class="docutils literal notranslate"><span class="pre">numpy.bytes_</span></code> will be converted to arrays of zero-terminated C strings as
well.</p>
<p>NumPy scalars with data type <code class="docutils literal notranslate"><span class="pre">numpy.object_</span></code>, <code class="docutils literal notranslate"><span class="pre">numpy.str_</span></code>, or
<code class="docutils literal notranslate"><span class="pre">numpy.bytes_</span></code> are converted following the same rules as for NumPy arrays.
NumPy scalars are treated as NumPy arrays of length 1 in this respect. Python
scalars of type <code class="docutils literal notranslate"><span class="pre">str</span></code> or <code class="docutils literal notranslate"><span class="pre">bytes</span></code> will also be converted to zero-terminated C
strings.</p>
<p>Unicode encoding is only performed for array elements or scalars of type <code class="docutils literal notranslate"><span class="pre">str</span></code>
or <code class="docutils literal notranslate"><span class="pre">numpy.str_</span></code>, and only on Python 3. See section <a class="reference internal" href="#unicode-details"><span class="std std-ref">Unicode</span></a> for details on unicode encoding in Python 3.</p>
<p>Any NumPy array, NumPy scalar, or Python scalar that cannot be converted
according to the rules described above is assumed to be numeric. An attempt will
be made to determine the minimal HARP data type that it, or its elements, can be
safely cast to (according to the function <code class="docutils literal notranslate"><span class="pre">numpy.can_cast()</span></code> using the
<code class="docutils literal notranslate"><span class="pre">'safe'</span></code> casting option). See the type map for details.</p>
<table border="1" class="docutils">
<colgroup>
<col width="13%" />
<col width="12%" />
<col width="14%" />
<col width="15%" />
<col width="19%" />
<col width="14%" />
<col width="14%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Python type</th>
<th class="head">NumPy dtype</th>
<th class="head">type test</th>
<th class="head">array element type</th>
<th class="head">array element type test</th>
<th class="head">HARP data type</th>
<th class="head">unicode encoding</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td rowspan="9">numpy.ndarray
numpy.generic</td>
<td rowspan="2">numpy.object_</td>
<td rowspan="2">numpy.issubdtype</td>
<td>str</td>
<td>isinstance</td>
<td>harp_type_string</td>
<td>Python 3</td>
</tr>
<tr class="row-odd"><td>bytes</td>
<td>isinstance</td>
<td>harp_type_string</td>
<td>no</td>
</tr>
<tr class="row-even"><td>numpy.str_</td>
<td>numpy.issubdtype</td>
<td> </td>
<td> </td>
<td>harp_type_string</td>
<td>Python 3</td>
</tr>
<tr class="row-odd"><td>numpy.bytes_</td>
<td>numpy.issubdtype</td>
<td> </td>
<td> </td>
<td>harp_type_string</td>
<td>no</td>
</tr>
<tr class="row-even"><td>numpy.int8</td>
<td>numpy.can_cast</td>
<td> </td>
<td> </td>
<td>harp_type_int8</td>
<td> </td>
</tr>
<tr class="row-odd"><td>numpy.int16</td>
<td>numpy.can_cast</td>
<td> </td>
<td> </td>
<td>harp_type_int16</td>
<td> </td>
</tr>
<tr class="row-even"><td>numpy.int32</td>
<td>numpy.can_cast</td>
<td> </td>
<td> </td>
<td>harp_type_int32</td>
<td> </td>
</tr>
<tr class="row-odd"><td>numpy.float32</td>
<td>numpy.can_cast</td>
<td> </td>
<td> </td>
<td>harp_type_float32</td>
<td> </td>
</tr>
<tr class="row-even"><td>numpy.float64</td>
<td>numpy.can_cast</td>
<td> </td>
<td> </td>
<td>harp_type_float64</td>
<td> </td>
</tr>
<tr class="row-odd"><td>str</td>
<td> </td>
<td>isinstance</td>
<td> </td>
<td> </td>
<td>harp_type_string</td>
<td>Python 3</td>
</tr>
<tr class="row-even"><td>bytes</td>
<td> </td>
<td>isinstance</td>
<td> </td>
<td> </td>
<td>harp_type_string</td>
<td>no</td>
</tr>
<tr class="row-odd"><td rowspan="5">any other type</td>
<td>numpy.int8</td>
<td>numpy.can_cast</td>
<td> </td>
<td> </td>
<td>harp_type_int8</td>
<td> </td>
</tr>
<tr class="row-even"><td>numpy.int16</td>
<td>numpy.can_cast</td>
<td> </td>
<td> </td>
<td>harp_type_int16</td>
<td> </td>
</tr>
<tr class="row-odd"><td>numpy.int32</td>
<td>numpy.can_cast</td>
<td> </td>
<td> </td>
<td>harp_type_int32</td>
<td> </td>
</tr>
<tr class="row-even"><td>numpy.float32</td>
<td>numpy.can_cast</td>
<td> </td>
<td> </td>
<td>harp_type_float32</td>
<td> </td>
</tr>
<tr class="row-odd"><td>numpy.float64</td>
<td>numpy.can_cast</td>
<td> </td>
<td> </td>
<td>harp_type_float64</td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="unicode">
<span id="unicode-details"></span><h2>Unicode</h2>
<p>Zero-terminated C strings received from the HARP C library are always converted
to instances of type <code class="docutils literal notranslate"><span class="pre">str</span></code> in Python. Type <code class="docutils literal notranslate"><span class="pre">str</span></code> is a byte string in Python
2, but a unicode string in Python 3.</p>
<p>In Python 2, no unicode encoding or decoding is performed by the HARP Python
interface.</p>
<p>In Python 3, byte strings received from the HARP C library are decoded using a
configurable encoding. Unicode strings (instances of type <code class="docutils literal notranslate"><span class="pre">str</span></code>) are encoded
using the same encoding into byte strings, which are sent to the HARP C library.
Byte strings (instances of type <code class="docutils literal notranslate"><span class="pre">bytes</span></code>) are passed through without encoding.</p>
<p>The encoding used can be configured by the user, see the
<a class="reference internal" href="#harp.set_encoding" title="harp.set_encoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">harp.set_encoding()</span></code></a> and <a class="reference internal" href="#harp.get_encoding" title="harp.get_encoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">harp.get_encoding()</span></code></a> methods. The
default encoding is <code class="docutils literal notranslate"><span class="pre">'ascii'</span></code>.</p>
</div>
<div class="section" id="examples">
<h2>Examples</h2>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">harp</span>
<span class="kn">import</span> <span class="nn">numpy</span>
<span class="c1"># Create a product in Python and export it as a NetCDF file.</span>
<span class="n">product</span> <span class="o">=</span> <span class="n">harp</span><span class="o">.</span><span class="n">Product</span><span class="p">()</span>
<span class="n">harp</span><span class="o">.</span><span class="n">export_product</span><span class="p">(</span><span class="n">product</span><span class="p">,</span> <span class="s2">"empty.nc"</span><span class="p">)</span>
<span class="c1"># Add some variables to the product.</span>
<span class="n">product</span><span class="o">.</span><span class="n">foo</span> <span class="o">=</span> <span class="n">harp</span><span class="o">.</span><span class="n">Variable</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
<span class="n">product</span><span class="o">.</span><span class="n">strings</span> <span class="o">=</span> <span class="n">harp</span><span class="o">.</span><span class="n">Variable</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">((</span><span class="s2">"foo"</span><span class="p">,</span> <span class="s2">"bar"</span><span class="p">,</span> <span class="s2">"baz"</span><span class="p">)),</span> <span class="p">[</span><span class="s2">"time"</span><span class="p">])</span>
<span class="n">product</span><span class="o">.</span><span class="n">temperature</span> <span class="o">=</span> <span class="n">harp</span><span class="o">.</span><span class="n">Variable</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">numpy</span><span class="o">.</span><span class="n">float32</span><span class="p">),</span>
<span class="p">[</span><span class="s2">"time"</span><span class="p">,</span> <span class="bp">None</span><span class="p">])</span>
<span class="n">product</span><span class="o">.</span><span class="n">temperature</span><span class="o">.</span><span class="n">unit</span> <span class="o">=</span> <span class="s2">"K"</span>
<span class="n">product</span><span class="o">.</span><span class="n">temperature</span><span class="o">.</span><span class="n">description</span> <span class="o">=</span> <span class="s2">"temperature"</span>
<span class="c1"># Pretty print information about the product.</span>
<span class="k">print</span><span class="p">(</span><span class="n">product</span><span class="p">)</span>
<span class="c1"># Pretty print information about the variable 'temperature'.</span>
<span class="k">print</span><span class="p">(</span><span class="n">product</span><span class="o">.</span><span class="n">temperature</span><span class="p">)</span>
<span class="c1"># Set valid minimum value of the variable 'temperature'. Note the use of item</span>
<span class="c1"># access syntax instead of attribute access syntax.</span>
<span class="n">product</span><span class="p">[</span><span class="s2">"temperature"</span><span class="p">]</span><span class="o">.</span><span class="n">valid_min</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="k">print</span><span class="p">(</span><span class="n">product</span><span class="o">.</span><span class="n">temperature</span><span class="p">)</span>
<span class="c1"># Export the updated product as an HDF4 file.</span>
<span class="n">harp</span><span class="o">.</span><span class="n">export_product</span><span class="p">(</span><span class="n">product</span><span class="p">,</span> <span class="s2">"non-empty.hdf"</span><span class="p">,</span> <span class="n">file_format</span><span class="o">=</span><span class="s2">"hdf4"</span><span class="p">)</span>
<span class="c1"># Convert the product to an OrderedDict.</span>
<span class="n">dict_product</span> <span class="o">=</span> <span class="n">harp</span><span class="o">.</span><span class="n">to_dict</span><span class="p">(</span><span class="n">product</span><span class="p">)</span>
<span class="c1"># Import an S5P L2 HCHO product.</span>
<span class="n">hcho_product</span> <span class="o">=</span> <span class="n">harp</span><span class="o">.</span><span class="n">import_product</span><span class="p">(</span><span class="s2">"S5P_NRTI_L2__HCHO___20080808T224727_20080808T234211_21635_01_021797_00000000T000000.nc"</span><span class="p">,</span>
<span class="s2">"solar_zenith_angle < 60 [degree]; latitude > 30 [degree_north]; latitude < 60 [degree_north]"</span><span class="p">)</span>
<span class="c1"># Pretty print information about the product.</span>
<span class="k">print</span><span class="p">(</span><span class="n">hcho_product</span><span class="p">)</span>
<span class="c1"># Export the product as a HARP compliant data product.</span>
<span class="n">harp</span><span class="o">.</span><span class="n">export_product</span><span class="p">(</span><span class="n">hcho_product</span><span class="p">,</span> <span class="s2">"hcho.h5"</span><span class="p">,</span> <span class="n">file_format</span><span class="o">=</span><span class="s1">'hdf5'</span><span class="p">,</span> <span class="n">hdf5_compression</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="api-reference">
<h2>API reference</h2>
<p>This section describes the types, functions, and exceptions defined by the HARP
Python interface.</p>
<div class="section" id="types">
<h3>Types</h3>
<p>This section describes the types defined by the HARP Python interface.</p>
<dl class="class">
<dt id="harp.Product">
<em class="property">class </em><code class="descclassname">harp.</code><code class="descname">Product</code><span class="sig-paren">(</span><em>source_product=""</em>, <em>history=""</em><span class="sig-paren">)</span></dt>
<dd><p>Python representation of a HARP product.</p>
<p>A product consists of product attributes and variables. Any attribute of a
Product instance of which the name does not start with an underscore is
either a variable or a product attribute. Product attribute names are
reserved and cannot be used for variables.</p>
<p>The list of names reserved for product attributes is:</p>
<dl class="docutils">
<dt>source_product</dt>
<dd>Name of the original product this product is derived from.</dd>
<dt>history</dt>
<dd>New-line separated list of invocations of HARP command line tools that
have been performed on the product.</dd>
</dl>
<p>Variables can be accessed by name using either the attribute access <code class="docutils literal notranslate"><span class="pre">'.'</span></code>
syntax, or the item access <code class="docutils literal notranslate"><span class="pre">'[]'</span></code> syntax. For example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span>
<span class="c1"># Alternative ways to access the variable 'HCHO_column_number_density'.</span>
<span class="n">density</span> <span class="o">=</span> <span class="n">product</span><span class="o">.</span><span class="n">HCHO_column_number_density</span>
<span class="n">density</span> <span class="o">=</span> <span class="n">product</span><span class="p">[</span><span class="s2">"HCHO_column_number_density"</span><span class="p">]</span>
<span class="c1"># Iterate over all variables in the product. For imported products, the</span>
<span class="c1"># order of the variables is the same as the order in the source product.</span>
<span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">product</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="n">product</span><span class="p">[</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">unit</span><span class="p">)</span>
</pre></div>
</div>
<p>Product attributes can be accessed in the same way as variables, but are
<em>not</em> included when iterating over the variables in a product. For example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span>
<span class="c1"># Print product attributes.</span>
<span class="k">print</span><span class="p">(</span><span class="n">product</span><span class="o">.</span><span class="n">source_product</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="n">product</span><span class="o">.</span><span class="n">history</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>source_product</strong> (<em>str</em>) – Name of the original product this product is
derived from.</li>
<li><strong>history</strong> (<em>str</em>) – New-line separated list of invocations of HARP command
line tools that have been performed on the product.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="class">
<dt id="harp.Variable">
<em class="property">class </em><code class="descclassname">harp.</code><code class="descname">Variable</code><span class="sig-paren">(</span><em>data</em>, <em>dimension=[]</em>, <em>unit=None</em>, <em>valid_min=None</em>, <em>valid_max=None</em>, <em>description=None</em>, <em>enum=None</em><span class="sig-paren">)</span></dt>
<dd><p>Python representation of a HARP variable.</p>
<p>A variable consists of data (either a scalar or NumPy array), a list of
dimension types that describe the dimensions of the data, and a number of
optional attributes: physical unit, minimum valid value, maximum valid value,
human-readable description, and enumeration name list.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>data</strong> – Value(s) associated with the variable; can be either a scalar or
a NumPy array.</li>
<li><strong>dimension</strong> (<em>list</em>) – List of strings indicating the dimensions the variable
depends on.</li>
<li><strong>unit</strong> (<em>str</em>) – Physical unit the values associated with the variable are
expressed in.</li>
<li><strong>valid_min</strong> – Minimum valid value; any value below this threshold is
considered to be invalid.</li>
<li><strong>valid_max</strong> – Maximum valid value; any value above this threshold is
considered to be invalid.</li>
<li><strong>description</strong> (<em>str</em>) – Humand-readble description of the variable.</li>
<li><strong>enum</strong> (<em>list</em>) – List of strings with the names of each enumeration value.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
<div class="section" id="functions">
<h3>Functions</h3>
<p>This section describes the functions defined by the HARP Python library.</p>
<dl class="function">
<dt id="harp.import_product">
<code class="descclassname">harp.</code><code class="descname">import_product</code><span class="sig-paren">(</span><em>filename</em>, <em>operations=""</em>, <em>options=""</em>, <em>reduce_operations=""</em>, <em>post_operations=""</em><span class="sig-paren">)</span></dt>
<dd><p>Import a product from a file.</p>
<p>This will first try to import the file as an HDF4, HDF5, or netCDF file that
complies to the HARP Data Format. If the file is not stored using the HARP
format then it will try to import it using one of the available ingestion
modules.</p>
<p>If the filename argument is a list of filenames, a globbing (glob.glob())
pattern, or a list of globbing patterns then the harp.import_product() function
will be called on each individual matching file. All imported products will then
be appended into a single merged product and that merged product will be returned.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>filename</strong> (<em>str</em><em>,</em><em>list</em>) – Filename, file pattern, or list of filenames/patterns
of the product(s) to import</li>
<li><strong>operations</strong> (<em>str</em>) – Actions to apply as part of the import; should be
specified as a semi-colon separated string of operations;
in case a list of products is ingested these operations will be
performed on each product individually before the data is merged.</li>
<li><strong>options</strong> (<em>str</em>) – Ingestion module specific options; should be specified as
a semi-colon separated string of key=value pairs; only
used if a file is not in HARP format.</li>
<li><strong>reduce_operations</strong> (<em>str</em>) – Actions to apply after each append; should be specified as a
semi-colon separated string of operations;
these operations will only be applied if the filename argument is
a file pattern or a list of filenames/patterns;
this advanced option allows for memory efficient application
of time reduction operations (such as bin()) that would
normally be provided as part of post_operations.</li>
<li><strong>post_operations</strong> (<em>str</em>) – Actions to apply after the list of products is merged;
should be specified as a semi-colon separated string of operations;
these operations will only be applied if the filename argument is
a file pattern or a list of filenames/patterns.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Imported product.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><a class="reference internal" href="#harp.Product" title="harp.Product">harp.Product</a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="harp.import_product_metadata">
<code class="descclassname">harp.</code><code class="descname">import_product_metadata</code><span class="sig-paren">(</span><em>filename</em>, <em>options=""</em><span class="sig-paren">)</span></dt>
<dd><p>Import specific metadata from a single file.</p>
<dl class="docutils">
<dt>This will try to extract the following information from a file.</dt>
<dd><ul class="first last simple">
<li>datetime_start</li>
<li>datetime_stop</li>
<li>dimension lengths for time, latitude, longitude, vertical, and spectral</li>
<li>source_product</li>
</ul>
</dd>
</dl>
<p>If the file is not stored using the HARP format then it will try to import
the metadata using one of the available ingestion modules.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>filename</strong> (<em>str</em>) – Filename of the product from which to extract the metadata</li>
<li><strong>options</strong> (<em>str</em>) – Ingestion module specific options; should be specified as
a semi-colon separated string of key=value pairs; only
used if a file is not in HARP format.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Imported metadata.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">collections.OrderedDict</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="harp.export_product">
<code class="descclassname">harp.</code><code class="descname">export_product</code><span class="sig-paren">(</span><em>product</em>, <em>filename</em>, <em>file_format="netcdf"</em>, <em>operations=""</em>, <em>hdf5_compression=0</em><span class="sig-paren">)</span></dt>
<dd><p>Export a HARP compliant product.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>product</strong> (<em>str</em>) – Product to export.</li>
<li><strong>filename</strong> (<em>str</em>) – Filename of the exported product.</li>
<li><strong>operations</strong> (<em>str</em>) – Actions to apply as part of the export; should be
specified as a semi-colon separated string of operations.</li>
<li><strong>file_format</strong> (<em>str</em>) – File format to use; one of ‘netcdf’, ‘hdf4’, or
‘hdf5’.</li>
<li><strong>hdf5_compression</strong> – Compression level when exporting to hdf5
(0=disabled, 1=low, …, 9=high).</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="harp.concatenate">
<code class="descclassname">harp.</code><code class="descname">concatenate</code><span class="sig-paren">(</span><em>productlist</em><span class="sig-paren">)</span></dt>
<dd><p>Combines all HARP products in the list into a single HARP output product.</p>
<p>All non-time dependent variables from the input products are made time
dependent before concatenating them.</p>
<p>Trying to merge input products that do not have the same types of variables
will result in an error.</p>
<p>The ‘index’ variable will not be included in the concatenated product.</p>
<p>The resulting product will not have a ‘source_product’ or ‘history’ global
attribute set.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>productlist</strong> (<em>list</em>) – List of harp.Product objects.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Single product containing concatenated content.</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><a class="reference internal" href="#harp.Product" title="harp.Product">harp.Product</a></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="harp.execute_operations">
<code class="descclassname">harp.</code><code class="descname">execute_operations</code><span class="sig-paren">(</span><em>productlist</em>, <em>operations=""</em>, <em>post_operations=""</em><span class="sig-paren">)</span></dt>
<dd><p>Apply operations on the given list of products. ‘productlist’ can be either
a single ‘harp.Product()’ instance or a list of ‘harp.Product()’ instances.</p>
<p>If a list of products is provided then the products will be concatenated/merged after
the ‘operations’ on each product has been performed.</p>
<p>If a ‘post_operations’ parameter is provided then these operations will be applied to
the concatenated/merged product before it is returned.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Note that this function will first export all products to the HARP
C library and will import the final result back from the C library to the Python
domain. This can have a considerable performance impact when products are large.
You should therefore only use this function if the operation cannot be performed
easily within the Python domain itself. Also, when using this function try to
pass a ‘harp.Product()’ instance that contains the minimal set of variables that
are needed to execute the operations.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>productlist</strong> (<em>list</em>) – List of harp.Product objects or single harp.Product object.</li>
<li><strong>operations</strong> (<em>str</em>) – Actions to apply on the product(s); should be
specified as a semi-colon separated string of operations;
in case a list of products is provided these operations will be
performed on each product individually before the data is merged.</li>
<li><strong>post_operations</strong> (<em>str</em>) – Actions to apply after the list of products is merged;
should be specified as a semi-colon separated string of operations;
these operations will only be applied if the productlist parameter
is a list of harp.Product objects.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Single product containing concatenated content with operations being performed.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><a class="reference internal" href="#harp.Product" title="harp.Product">harp.Product</a></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="harp.convert_unit">
<code class="descclassname">harp.</code><code class="descname">convert_unit</code><span class="sig-paren">(</span><em>from_unit</em>, <em>to_unit</em>, <em>values</em><span class="sig-paren">)</span></dt>
<dd><p>Perform unit conversion on the list of values.
The list of values will be converted to an array of double values after which the
HARP C library is used to convert the values from ‘from_unit’ to ‘to_unit’.
The function will return a copy of the values with converted units.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>from_unit</strong> (<em>str</em>) – Existing unit of the data that should be converted
(use udunits2 compliant units)</li>
<li><strong>to_unit</strong> (<em>str</em>) – Unit to which the data should be converted
(use udunits2 compliant units).</li>
<li><strong>values</strong> – an array with values on which unit conversion needs to be applied</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Numpy array of unit converted values</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="harp.to_dict">
<code class="descclassname">harp.</code><code class="descname">to_dict</code><span class="sig-paren">(</span><em>product</em><span class="sig-paren">)</span></dt>
<dd><p>Convert a <a class="reference internal" href="#harp.Product" title="harp.Product"><code class="xref py py-class docutils literal notranslate"><span class="pre">harp.Product</span></code></a> instance to an <code class="docutils literal notranslate"><span class="pre">OrderedDict</span></code>.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">OrderedDict</span></code> representation provides direct access to the data
associated with each variable. All product attributes and all variable
attributes except the unit attribute are discarded as part of the conversion.</p>
<p>The unit attribute of a variable is represented by adding a scalar variable
of type string with the name of the corresponding variable suffixed with
<code class="docutils literal notranslate"><span class="pre">'_unit'</span></code> as name and the unit as value.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">OrderedDict</span></code> representation can be convenient when there is a need to
interface with existing code such as plotting libraries, or when the
additional information provided by the Product representation is not needed.</p>
<p>Note that only <a class="reference internal" href="#harp.Product" title="harp.Product"><code class="xref py py-class docutils literal notranslate"><span class="pre">harp.Product</span></code></a> instances can be exported as a HARP
product. The <code class="docutils literal notranslate"><span class="pre">OrderedDict</span></code> representation does not contain enough
information.</p>
<p>For example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span>
<span class="c1"># Convert input product to an OrderedDict.</span>
<span class="n">product</span> <span class="o">=</span> <span class="n">to_dict</span><span class="p">(</span><span class="n">input_product</span><span class="p">)</span>
<span class="c1"># Accessing the variable 'HCHO_column_number_density'.</span>
<span class="n">product</span><span class="p">[</span><span class="s2">"HCHO_column_number_density"</span><span class="p">]</span>
<span class="c1"># Accessing the unit attribute of the variable</span>
<span class="c1"># 'HCHO_column_number_density'.</span>
<span class="n">product</span><span class="p">[</span><span class="s2">"HCHO_column_number_density_unit"</span><span class="p">]</span>
<span class="c1"># Iterate over all variables in the product. For imported products, the</span>
<span class="c1"># order of the variables is the same as the order in the source product.</span>
<span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">product</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">print</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>product</strong> (<a class="reference internal" href="#harp.Product" title="harp.Product"><em>harp.Product</em></a>) – Product to convert.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Converted product.</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">collections.OrderedDict</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="harp.get_encoding">
<code class="descclassname">harp.</code><code class="descname">get_encoding</code><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
<dd><p>Return the encoding used to convert between unicode strings and C strings
(only relevant when using Python 3).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Encoding currently in use.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">str</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="harp.set_encoding">
<code class="descclassname">harp.</code><code class="descname">set_encoding</code><span class="sig-paren">(</span><em>encoding</em><span class="sig-paren">)</span></dt>
<dd><p>Set the encoding used to convert between unicode strings and C strings
(only relevant when using Python 3).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>encoding</strong> (<em>str</em>) – Encoding to use.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="harp.version">
<code class="descclassname">harp.</code><code class="descname">version</code><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
<dd><p>Return the version of the HARP C library.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">HARP C library version.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">str</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
<div class="section" id="exceptions">
<h3>Exceptions</h3>
<p>This sections describes the exceptions defined by the HARP Python interface.</p>
<dl class="exception">
<dt id="harp.Error">
<em class="property">exception </em><code class="descclassname">harp.</code><code class="descname">Error</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span></dt>
<dd><p>Exception base class for all HARP Python interface errors.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>args</strong> (<em>tuple</em>) – Tuple of arguments passed to the constructor; usually a
single string containing an error message.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="exception">
<dt id="harp.CLibraryError">
<em class="property">exception </em><code class="descclassname">harp.</code><code class="descname">CLibraryError</code><span class="sig-paren">(</span><em>errno=None</em>, <em>strerror=None</em><span class="sig-paren">)</span></dt>
<dd><p>Exception raised when an error occurs inside the HARP C library.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>errno</strong> (<em>str</em>) – error code; if None, the error code will be retrieved from
the HARP C library.</li>
<li><strong>strerror</strong> (<em>str</em>) – error message; if None, the error message will be
retrieved from the HARP C library.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="exception">
<dt id="harp.UnsupportedTypeError">
<em class="property">exception </em><code class="descclassname">harp.</code><code class="descname">UnsupportedTypeError</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span></dt>
<dd><p>Exception raised when unsupported types are encountered, either on the Python
or on the C side of the interface.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>args</strong> (<em>tuple</em>) – Tuple of arguments passed to the constructor; usually a
single string containing an error message.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="exception">
<dt id="harp.UnsupportedDimensionError">
<em class="property">exception </em><code class="descclassname">harp.</code><code class="descname">UnsupportedDimensionError</code><span class="sig-paren">(</span><em>*args</em><span class="sig-paren">)</span></dt>
<dd><p>Exception raised when unsupported dimensions are encountered, either on the
Python or on the C side of the interface.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>args</strong> (<em>tuple</em>) – Tuple of arguments passed to the constructor; usually a
single string containing an error message.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="exception">
<dt id="harp.NoDataError">
<em class="property">exception </em><code class="descclassname">harp.</code><code class="descname">NoDataError</code></dt>
<dd><p>Exception raised when the product returned from an import contains no
variables, or variables without data.</p>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="R.html" class="btn btn-neutral float-right" title="R interface" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="matlab.html" class="btn btn-neutral" title="MATLAB interface" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2015-2020 S[&]T, The Netherlands
</p>
</div>
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script async="async" type="text/javascript" src="/usr/share/javascript/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>
|