Update upstream source from tag 'upstream/1.6.1'
Update to upstream version '1.6.1'
with Debian dir a1e25de6cbe72ae41040c54dc7eb3317574d3576
Bas Couwenberg
1 year, 7 months ago
17 | 17 | exclude: |
18 | 18 | - os: macos-latest |
19 | 19 | platform: x32 |
20 | fail-fast: false | |
21 | ||
20 | 22 | steps: |
21 | - uses: actions/checkout@v2 | |
23 | - uses: actions/checkout@v3 | |
22 | 24 | |
23 | - name: Setup Conda | |
24 | uses: s-weigand/setup-conda@v1 | |
25 | - name: Setup Micromamba | |
26 | uses: mamba-org/provision-with-micromamba@v13 | |
25 | 27 | with: |
26 | activate-conda: false | |
27 | conda-channels: conda-forge | |
28 | environment-file: false | |
28 | 29 | |
29 | 30 | - name: Python ${{ matrix.python-version }} |
30 | 31 | shell: bash -l {0} |
31 | 32 | run: | |
32 | conda create --name TEST python=${{ matrix.python-version }} numpy cython pip pytest hdf5 libnetcdf cftime --strict-channel-priority | |
33 | source activate TEST | |
33 | micromamba create --name TEST python=${{ matrix.python-version }} numpy cython pip pytest hdf5 libnetcdf cftime zlib --channel conda-forge | |
34 | micromamba activate TEST | |
34 | 35 | export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH" # so setup.py finds nc-config |
35 | 36 | pip install -e . --no-deps --force-reinstall |
36 | conda info --all | |
37 | conda list | |
37 | ||
38 | - name: Debug conda | |
39 | shell: bash -l {0} | |
40 | run: | | |
41 | micromamba activate TEST | |
42 | micromamba info --all | |
43 | micromamba list | |
38 | 44 | |
39 | 45 | - name: Tests |
40 | 46 | shell: bash -l {0} |
41 | 47 | run: | |
42 | source activate TEST | |
48 | micromamba activate TEST | |
43 | 49 | cd test && python run_all.py |
44 | 50 | |
45 | 51 | run-mpi: |
52 | 58 | steps: |
53 | 59 | - uses: actions/checkout@v2 |
54 | 60 | |
55 | - name: Setup Conda | |
56 | uses: s-weigand/setup-conda@v1 | |
61 | - name: Setup Micromamba | |
62 | uses: mamba-org/provision-with-micromamba@main | |
57 | 63 | with: |
58 | activate-conda: false | |
59 | conda-channels: conda-forge | |
64 | environment-file: false | |
60 | 65 | |
61 | 66 | - name: Python ${{ matrix.python-version }} |
62 | 67 | shell: bash -l {0} |
63 | 68 | run: | |
64 | conda create --name TEST python=${{ matrix.python-version }} numpy cython pip pytest mpi4py hdf5=*=mpi* libnetcdf=*=mpi* cftime --strict-channel-priority | |
65 | source activate TEST | |
69 | micromamba create --name TEST python=${{ matrix.python-version }} numpy cython pip pytest mpi4py hdf5=*=mpi* libnetcdf=*=mpi* cftime zlib --channel conda-forge | |
70 | micromamba activate TEST | |
66 | 71 | export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH" # so setup.py finds nc-config |
67 | 72 | pip install -e . --no-deps --force-reinstall |
68 | conda info --all | |
69 | conda list | |
73 | ||
74 | - name: Debug conda | |
75 | shell: bash -l {0} | |
76 | run: | | |
77 | micromamba activate TEST | |
78 | micromamba info --all | |
79 | micromamba list | |
70 | 80 | |
71 | 81 | - name: Tests |
72 | 82 | shell: bash -l {0} |
73 | 83 | run: | |
74 | source activate TEST | |
84 | micromamba activate TEST | |
75 | 85 | cd test && python run_all.py |
76 | 86 | cd ../examples |
77 | 87 | export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH" |
0 | version 1.6.1 (tag v1.6.1rel) | |
1 | ============================== | |
2 | * add Dataset methods has_<name>_filter (where <name>=zstd,blosc,bzip2,szip) | |
3 | to check for availability of extra compression filters. | |
4 | * release GIL for all C-lib calls (issue #1180). | |
5 | * Add support for nc_set_alignment and nc_get_alignment to control alignment | |
6 | of data within HDF5 files. | |
7 | ||
0 | 8 | version 1.6.0 (tag v1.6.0rel) |
1 | 9 | ============================== |
2 | 10 | * add support for new quantization functionality in netcdf-c 4.9.0 via "signficant_digits" |
9 | 9 | ## News |
10 | 10 | For details on the latest updates, see the [Changelog](https://github.com/Unidata/netcdf4-python/blob/master/Changelog). |
11 | 11 | |
12 | ??/??/2022: Version [1.6.0](https://pypi.python.org/pypi/netCDF4/1.6.0) released. Support | |
12 | 09/18/2022: Version [1.6.1](https://pypi.python.org/pypi/netCDF4/1.6.1) released. GIL now | |
13 | released for all C lib calls, `set_alignment` and `get_alignment` module functions | |
14 | added to modify/retrieve HDF5 data alignment properties. Added `Dataset` methods to | |
15 | query availability of optional compression filters. | |
16 | ||
17 | 06/24/2022: Version [1.6.0](https://pypi.python.org/pypi/netCDF4/1.6.0) released. Support | |
13 | 18 | for quantization (bit-grooming and bit-rounding) functionality in netcdf-c 4.9.0 which can |
14 | 19 | dramatically improve compression. Dataset.createVariable now accepts dimension instances (instead |
15 | 20 | of just dimension names). 'compression' kwarg added to Dataset.createVariable to support szip as |
20 | 20 | |
21 | 21 | <h2>Contents</h2> |
22 | 22 | <ul> |
23 | <li><a href="#version-160">Version 1.6.0</a></li> | |
23 | <li><a href="#version-161">Version 1.6.1</a></li> | |
24 | 24 | </ul></li> |
25 | 25 | <li><a href="#introduction">Introduction</a> |
26 | 26 | <ul> |
148 | 148 | </li> |
149 | 149 | <li> |
150 | 150 | <a class="function" href="#Dataset.tocdl">tocdl</a> |
151 | </li> | |
152 | <li> | |
153 | <a class="function" href="#Dataset.has_blosc_filter">has_blosc_filter</a> | |
154 | </li> | |
155 | <li> | |
156 | <a class="function" href="#Dataset.has_zstd_filter">has_zstd_filter</a> | |
157 | </li> | |
158 | <li> | |
159 | <a class="function" href="#Dataset.has_bzip2_filter">has_bzip2_filter</a> | |
160 | </li> | |
161 | <li> | |
162 | <a class="function" href="#Dataset.has_szip_filter">has_szip_filter</a> | |
151 | 163 | </li> |
152 | 164 | <li> |
153 | 165 | <a class="variable" href="#Dataset.name">name</a> |
443 | 455 | <li> |
444 | 456 | <a class="function" href="#set_chunk_cache">set_chunk_cache</a> |
445 | 457 | </li> |
458 | <li> | |
459 | <a class="function" href="#set_alignment">set_alignment</a> | |
460 | </li> | |
461 | <li> | |
462 | <a class="function" href="#get_alignment">get_alignment</a> | |
463 | </li> | |
446 | 464 | </ul> |
447 | 465 | |
448 | 466 | |
459 | 477 | <h1 class="modulename"> |
460 | 478 | netCDF4 </h1> |
461 | 479 | |
462 | <div class="docstring"><h2 id="version-160">Version 1.6.0</h2> | |
480 | <div class="docstring"><h2 id="version-161">Version 1.6.1</h2> | |
463 | 481 | |
464 | 482 | <h1 id="introduction">Introduction</h1> |
465 | 483 | |
520 | 538 | If the dependencies are not found |
521 | 539 | in any of the paths specified by environment variables, then standard locations |
522 | 540 | (such as <code>/usr</code> and <code>/usr/local</code>) are searched.</li> |
523 | <li>if the env var <code>NETCDF_PLUGIN_DIR</code> is set to point to the location netcdf-c compression | |
524 | plugin shared objects, they will be installed inside the package. In this | |
541 | <li>if the env var <code>NETCDF_PLUGIN_DIR</code> is set to point to the location of the netcdf-c compression | |
542 | plugins built by netcdf >= 4.9.0, they will be installed inside the package. In this | |
525 | 543 | case <code>HDF5_PLUGIN_PATH</code> will be set to the package installation path on import, |
526 | so the extra compression algorithms available in netcdf-c 4.9.0 will automatically | |
544 | so the extra compression algorithms available in netcdf-c >= 4.9.0 will automatically | |
527 | 545 | be available. Otherwise, the user will have to set <code>HDF5_PLUGIN_PATH</code> explicitly |
528 | 546 | to have access to the extra compression plugins.</li> |
529 | 547 | <li>run <code>python setup.py build</code>, then <code>python setup.py install</code> (as root if |
1623 | 1641 | the parallel IO example, which is in <code>examples/mpi_example.py</code>. |
1624 | 1642 | Unit tests are in the <code>test</code> directory.</p> |
1625 | 1643 | |
1626 | <p><strong>contact</strong>: Jeffrey Whitaker <a href="mailto:jeffrey.s.whitaker@noaa.gov">jeffrey.s.whitaker@noaa.gov</a></p> | |
1644 | <p><strong>contact</strong>: Jeffrey Whitaker <a href="mailto:jeffrey.s.whitaker@noaa.gov">jeffrey.s.whitaker@noaa.gov</a></p> | |
1627 | 1645 | |
1628 | 1646 | <p><strong>copyright</strong>: 2008 by Jeffrey Whitaker.</p> |
1629 | 1647 | |
1650 | 1668 | <span class="n">__has_bzip2_support__</span><span class="p">,</span> <span class="n">__has_blosc_support__</span><span class="p">,</span> <span class="n">__has_szip_support__</span><span class="p">)</span> |
1651 | 1669 | <span class="kn">import</span> <span class="nn">os</span> |
1652 | 1670 | <span class="n">__all__</span> <span class="o">=</span>\ |
1653 | <span class="p">[</span><span class="s1">'Dataset'</span><span class="p">,</span><span class="s1">'Variable'</span><span class="p">,</span><span class="s1">'Dimension'</span><span class="p">,</span><span class="s1">'Group'</span><span class="p">,</span><span class="s1">'MFDataset'</span><span class="p">,</span><span class="s1">'MFTime'</span><span class="p">,</span><span class="s1">'CompoundType'</span><span class="p">,</span><span class="s1">'VLType'</span><span class="p">,</span><span class="s1">'date2num'</span><span class="p">,</span><span class="s1">'num2date'</span><span class="p">,</span><span class="s1">'date2index'</span><span class="p">,</span><span class="s1">'stringtochar'</span><span class="p">,</span><span class="s1">'chartostring'</span><span class="p">,</span><span class="s1">'stringtoarr'</span><span class="p">,</span><span class="s1">'getlibversion'</span><span class="p">,</span><span class="s1">'EnumType'</span><span class="p">,</span><span class="s1">'get_chunk_cache'</span><span class="p">,</span><span class="s1">'set_chunk_cache'</span><span class="p">]</span> | |
1654 | <span class="c1"># if HDF5_PLUGIN_PATH not set, point to package path if libh5noop.so exists there</span> | |
1655 | <span class="k">if</span> <span class="s1">'HDF5_PLUGIN_PATH'</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span> <span class="ow">and</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">__path__</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="s1">'libh5noop.so'</span><span class="p">)):</span> | |
1656 | <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">'HDF5_PLUGIN_PATH'</span><span class="p">]</span><span class="o">=</span><span class="n">__path__</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> | |
1671 | <span class="p">[</span><span class="s1">'Dataset'</span><span class="p">,</span><span class="s1">'Variable'</span><span class="p">,</span><span class="s1">'Dimension'</span><span class="p">,</span><span class="s1">'Group'</span><span class="p">,</span><span class="s1">'MFDataset'</span><span class="p">,</span><span class="s1">'MFTime'</span><span class="p">,</span><span class="s1">'CompoundType'</span><span class="p">,</span><span class="s1">'VLType'</span><span class="p">,</span><span class="s1">'date2num'</span><span class="p">,</span><span class="s1">'num2date'</span><span class="p">,</span><span class="s1">'date2index'</span><span class="p">,</span><span class="s1">'stringtochar'</span><span class="p">,</span><span class="s1">'chartostring'</span><span class="p">,</span><span class="s1">'stringtoarr'</span><span class="p">,</span><span class="s1">'getlibversion'</span><span class="p">,</span><span class="s1">'EnumType'</span><span class="p">,</span><span class="s1">'get_chunk_cache'</span><span class="p">,</span><span class="s1">'set_chunk_cache'</span><span class="p">,</span><span class="s1">'set_alignment'</span><span class="p">,</span><span class="s1">'get_alignment'</span><span class="p">]</span> | |
1672 | <span class="c1"># if HDF5_PLUGIN_PATH not set, point to package path if plugins live there</span> | |
1673 | <span class="n">pluginpath</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">__path__</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="s1">'plugins'</span><span class="p">)</span> | |
1674 | <span class="k">if</span> <span class="s1">'HDF5_PLUGIN_PATH'</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span> <span class="ow">and</span>\ | |
1675 | <span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">pluginpath</span><span class="p">,</span><span class="s1">'lib__nczhdf5filters.so'</span><span class="p">))</span> <span class="ow">or</span>\ | |
1676 | <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">pluginpath</span><span class="p">,</span><span class="s1">'lib__nczhdf5filters.dylib'</span><span class="p">))):</span> | |
1677 | <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">'HDF5_PLUGIN_PATH'</span><span class="p">]</span><span class="o">=</span><span class="n">pluginpath</span> | |
1657 | 1678 | </pre></div> |
1658 | 1679 | |
1659 | 1680 | </details> |
2644 | 2665 | <p><strong><code>data</code></strong>: if True, write out variable data (Default False).</p> |
2645 | 2666 | |
2646 | 2667 | <p><strong><code>outfile</code></strong>: If not None, file to output ncdump to. Default is to return a string.</p> |
2668 | </div> | |
2669 | ||
2670 | ||
2671 | </div> | |
2672 | <div id="Dataset.has_blosc_filter" class="classattr"> | |
2673 | <div class="attr function"><a class="headerlink" href="#Dataset.has_blosc_filter">#  </a> | |
2674 | ||
2675 | ||
2676 | <span class="def">def</span> | |
2677 | <span class="name">has_blosc_filter</span><span class="signature">(unknown)</span>: | |
2678 | </div> | |
2679 | ||
2680 | ||
2681 | <div class="docstring"><p><strong><code>has_blosc_filter(self)</code></strong> | |
2682 | returns True if blosc compression filter is available</p> | |
2683 | </div> | |
2684 | ||
2685 | ||
2686 | </div> | |
2687 | <div id="Dataset.has_zstd_filter" class="classattr"> | |
2688 | <div class="attr function"><a class="headerlink" href="#Dataset.has_zstd_filter">#  </a> | |
2689 | ||
2690 | ||
2691 | <span class="def">def</span> | |
2692 | <span class="name">has_zstd_filter</span><span class="signature">(unknown)</span>: | |
2693 | </div> | |
2694 | ||
2695 | ||
2696 | <div class="docstring"><p><strong><code>has_zstd_filter(self)</code></strong> | |
2697 | returns True if zstd compression filter is available</p> | |
2698 | </div> | |
2699 | ||
2700 | ||
2701 | </div> | |
2702 | <div id="Dataset.has_bzip2_filter" class="classattr"> | |
2703 | <div class="attr function"><a class="headerlink" href="#Dataset.has_bzip2_filter">#  </a> | |
2704 | ||
2705 | ||
2706 | <span class="def">def</span> | |
2707 | <span class="name">has_bzip2_filter</span><span class="signature">(unknown)</span>: | |
2708 | </div> | |
2709 | ||
2710 | ||
2711 | <div class="docstring"><p><strong><code>has_bzip2_filter(self)</code></strong> | |
2712 | returns True if bzip2 compression filter is available</p> | |
2713 | </div> | |
2714 | ||
2715 | ||
2716 | </div> | |
2717 | <div id="Dataset.has_szip_filter" class="classattr"> | |
2718 | <div class="attr function"><a class="headerlink" href="#Dataset.has_szip_filter">#  </a> | |
2719 | ||
2720 | ||
2721 | <span class="def">def</span> | |
2722 | <span class="name">has_szip_filter</span><span class="signature">(unknown)</span>: | |
2723 | </div> | |
2724 | ||
2725 | ||
2726 | <div class="docstring"><p><strong><code>has_szip_filter(self)</code></strong> | |
2727 | returns True if szip compression filter is available</p> | |
2647 | 2728 | </div> |
2648 | 2729 | |
2649 | 2730 | |
3900 | 3981 | <dd id="Group.get_variables_by_attributes" class="function"><a href="#Dataset.get_variables_by_attributes">get_variables_by_attributes</a></dd> |
3901 | 3982 | <dd id="Group.fromcdl" class="function"><a href="#Dataset.fromcdl">fromcdl</a></dd> |
3902 | 3983 | <dd id="Group.tocdl" class="function"><a href="#Dataset.tocdl">tocdl</a></dd> |
3984 | <dd id="Group.has_blosc_filter" class="function"><a href="#Dataset.has_blosc_filter">has_blosc_filter</a></dd> | |
3985 | <dd id="Group.has_zstd_filter" class="function"><a href="#Dataset.has_zstd_filter">has_zstd_filter</a></dd> | |
3986 | <dd id="Group.has_bzip2_filter" class="function"><a href="#Dataset.has_bzip2_filter">has_bzip2_filter</a></dd> | |
3987 | <dd id="Group.has_szip_filter" class="function"><a href="#Dataset.has_szip_filter">has_szip_filter</a></dd> | |
3903 | 3988 | <dd id="Group.name" class="variable"><a href="#Dataset.name">name</a></dd> |
3904 | 3989 | <dd id="Group.groups" class="variable"><a href="#Dataset.groups">groups</a></dd> |
3905 | 3990 | <dd id="Group.dimensions" class="variable"><a href="#Dataset.dimensions">dimensions</a></dd> |
4066 | 4151 | <dd id="MFDataset.get_variables_by_attributes" class="function"><a href="#Dataset.get_variables_by_attributes">get_variables_by_attributes</a></dd> |
4067 | 4152 | <dd id="MFDataset.fromcdl" class="function"><a href="#Dataset.fromcdl">fromcdl</a></dd> |
4068 | 4153 | <dd id="MFDataset.tocdl" class="function"><a href="#Dataset.tocdl">tocdl</a></dd> |
4154 | <dd id="MFDataset.has_blosc_filter" class="function"><a href="#Dataset.has_blosc_filter">has_blosc_filter</a></dd> | |
4155 | <dd id="MFDataset.has_zstd_filter" class="function"><a href="#Dataset.has_zstd_filter">has_zstd_filter</a></dd> | |
4156 | <dd id="MFDataset.has_bzip2_filter" class="function"><a href="#Dataset.has_bzip2_filter">has_bzip2_filter</a></dd> | |
4157 | <dd id="MFDataset.has_szip_filter" class="function"><a href="#Dataset.has_szip_filter">has_szip_filter</a></dd> | |
4069 | 4158 | <dd id="MFDataset.name" class="variable"><a href="#Dataset.name">name</a></dd> |
4070 | 4159 | <dd id="MFDataset.groups" class="variable"><a href="#Dataset.groups">groups</a></dd> |
4071 | 4160 | <dd id="MFDataset.dimensions" class="variable"><a href="#Dataset.dimensions">dimensions</a></dd> |
4332 | 4421 | </div> |
4333 | 4422 | |
4334 | 4423 | |
4335 | <div class="docstring"><p>date2num(dates, units, calendar=None, has_year_zero=None)</p> | |
4424 | <div class="docstring"><p>date2num(dates, units, calendar=None, has_year_zero=None, longdouble=False)</p> | |
4336 | 4425 | |
4337 | 4426 | <p>Return numeric time values given datetime objects. The units |
4338 | 4427 | of the numeric time values are described by the <strong>units</strong> argument |
4377 | 4466 | This kwarg is not needed to define calendar systems allowed by CF |
4378 | 4467 | (the calendar-specific defaults do this).</p> |
4379 | 4468 | |
4469 | <p><strong>longdouble</strong>: If set True, output is in the long double float type | |
4470 | (numpy.float128) instead of float (numpy.float64), allowing microsecond | |
4471 | accuracy when converting a time value to a date and back again. Otherwise | |
4472 | this is only possible if the discretization of the time variable is an | |
4473 | integer multiple of the units.</p> | |
4474 | ||
4380 | 4475 | <p>returns a numeric time value, or an array of numeric time values |
4381 | 4476 | with approximately 1 microsecond accuracy.</p> |
4382 | 4477 | </div> |
4725 | 4820 | |
4726 | 4821 | |
4727 | 4822 | </section> |
4823 | <section id="set_alignment"> | |
4824 | <div class="attr function"><a class="headerlink" href="#set_alignment">#  </a> | |
4825 | ||
4826 | ||
4827 | <span class="def">def</span> | |
4828 | <span class="name">set_alignment</span><span class="signature">(unknown)</span>: | |
4829 | </div> | |
4830 | ||
4831 | ||
4832 | <div class="docstring"><p><strong><code>set_alignment(threshold,alignment)</code></strong></p> | |
4833 | ||
4834 | <p>Change the HDF5 file alignment. | |
4835 | See netcdf C library documentation for <code>nc_set_alignment</code> for | |
4836 | details.</p> | |
4837 | ||
4838 | <p>This function was added in netcdf 4.9.0.</p> | |
4839 | </div> | |
4840 | ||
4841 | ||
4842 | </section> | |
4843 | <section id="get_alignment"> | |
4844 | <div class="attr function"><a class="headerlink" href="#get_alignment">#  </a> | |
4845 | ||
4846 | ||
4847 | <span class="def">def</span> | |
4848 | <span class="name">get_alignment</span><span class="signature">(unknown)</span>: | |
4849 | </div> | |
4850 | ||
4851 | ||
4852 | <div class="docstring"><p><strong><code><a href="#get_alignment">get_alignment()</a></code></strong></p> | |
4853 | ||
4854 | <p>return current netCDF alignment within HDF5 files in a tuple | |
4855 | (threshold,alignment). See netcdf C library documentation for | |
4856 | <code>nc_get_alignment</code> for details. Values can be reset with | |
4857 | <code><a href="#set_alignment">set_alignment</a></code>.</p> | |
4858 | ||
4859 | <p>This function was added in netcdf 4.9.0.</p> | |
4860 | </div> | |
4861 | ||
4862 | ||
4863 | </section> | |
4728 | 4864 | </main> |
4729 | 4865 | </body> |
4730 | 4866 | </html> |
5 | 5 | # hdf5 version info. |
6 | 6 | cdef extern from "H5public.h": |
7 | 7 | ctypedef int herr_t |
8 | int H5get_libversion( unsigned int *majnum, unsigned int *minnum, unsigned int *relnum ) | |
8 | int H5get_libversion( unsigned int *majnum, unsigned int *minnum, unsigned int *relnum ) nogil | |
9 | 9 | |
10 | 10 | cdef extern from *: |
11 | 11 | ctypedef char* const_char_ptr "const char*" |
125 | 125 | NC_FORMAT_DAP4 |
126 | 126 | NC_FORMAT_PNETCDF |
127 | 127 | NC_FORMAT_UNDEFINED |
128 | # Let nc__create() or nc__open() figure out | |
129 | # as suitable chunk size. | |
130 | 128 | NC_SIZEHINT_DEFAULT |
131 | # In nc__enddef(), align to the chunk size. | |
132 | 129 | NC_ALIGN_CHUNK |
133 | 130 | # 'size' argument to ncdimdef for an unlimited dimension |
134 | 131 | NC_UNLIMITED |
217 | 214 | NC_ENDIAN_BIG |
218 | 215 | const_char_ptr *nc_inq_libvers() nogil |
219 | 216 | const_char_ptr *nc_strerror(int ncerr) |
220 | int nc_create(char *path, int cmode, int *ncidp) | |
221 | int nc__create(char *path, int cmode, size_t initialsz, size_t *chunksizehintp, int *ncidp) | |
222 | int nc_open(char *path, int mode, int *ncidp) | |
223 | int nc__open(char *path, int mode, size_t *chunksizehintp, int *ncidp) | |
217 | int nc_create(char *path, int cmode, int *ncidp) nogil | |
218 | int nc_open(char *path, int mode, int *ncidp) nogil | |
224 | 219 | int nc_inq_path(int ncid, size_t *pathlen, char *path) nogil |
225 | 220 | int nc_inq_format_extended(int ncid, int *formatp, int* modep) nogil |
226 | 221 | int nc_inq_ncid(int ncid, char *name, int *grp_ncid) nogil |
229 | 224 | int nc_inq_grp_parent(int ncid, int *parent_ncid) nogil |
230 | 225 | int nc_inq_varids(int ncid, int *nvars, int *varids) nogil |
231 | 226 | int nc_inq_dimids(int ncid, int *ndims, int *dimids, int include_parents) nogil |
232 | int nc_def_grp(int parent_ncid, char *name, int *new_ncid) | |
233 | int nc_def_compound(int ncid, size_t size, char *name, nc_type *typeidp) | |
227 | int nc_def_grp(int parent_ncid, char *name, int *new_ncid) nogil | |
228 | int nc_def_compound(int ncid, size_t size, char *name, nc_type *typeidp) nogil | |
234 | 229 | int nc_insert_compound(int ncid, nc_type xtype, char *name, |
235 | size_t offset, nc_type field_typeid) | |
230 | size_t offset, nc_type field_typeid) nogil | |
236 | 231 | int nc_insert_array_compound(int ncid, nc_type xtype, char *name, |
237 | 232 | size_t offset, nc_type field_typeid, |
238 | int ndims, int *dim_sizes) | |
233 | int ndims, int *dim_sizes) nogil | |
239 | 234 | int nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size) nogil |
240 | 235 | int nc_inq_compound(int ncid, nc_type xtype, char *name, size_t *size, |
241 | 236 | size_t *nfieldsp) nogil |
257 | 252 | int *ndimsp) nogil |
258 | 253 | int nc_inq_compound_fielddim_sizes(int ncid, nc_type xtype, int fieldid, |
259 | 254 | int *dim_sizes) nogil |
260 | int nc_def_vlen(int ncid, char *name, nc_type base_typeid, nc_type *xtypep) | |
255 | int nc_def_vlen(int ncid, char *name, nc_type base_typeid, nc_type *xtypep) nogil | |
261 | 256 | int nc_inq_vlen(int ncid, nc_type xtype, char *name, size_t *datum_sizep, |
262 | 257 | nc_type *base_nc_typep) nogil |
263 | 258 | int nc_inq_user_type(int ncid, nc_type xtype, char *name, size_t *size, |
264 | 259 | nc_type *base_nc_typep, size_t *nfieldsp, int *classp) nogil |
265 | 260 | int nc_inq_typeids(int ncid, int *ntypes, int *typeids) nogil |
266 | 261 | int nc_put_att(int ncid, int varid, char *name, nc_type xtype, |
267 | size_t len, void *op) | |
262 | size_t len, void *op) nogil | |
268 | 263 | int nc_get_att(int ncid, int varid, char *name, void *ip) nogil |
269 | 264 | int nc_get_att_string(int ncid, int varid, char *name, char **ip) nogil |
270 | 265 | int nc_put_att_string(int ncid, int varid, char *name, size_t len, char **op) nogil |
271 | int nc_def_opaque(int ncid, size_t size, char *name, nc_type *xtypep) | |
272 | int nc_inq_opaque(int ncid, nc_type xtype, char *name, size_t *sizep) | |
266 | int nc_def_opaque(int ncid, size_t size, char *name, nc_type *xtypep) nogil | |
267 | int nc_inq_opaque(int ncid, nc_type xtype, char *name, size_t *sizep) nogil | |
273 | 268 | int nc_put_att_opaque(int ncid, int varid, char *name, |
274 | size_t len, void *op) | |
269 | size_t len, void *op) nogil | |
275 | 270 | int nc_get_att_opaque(int ncid, int varid, char *name, |
276 | void *ip) | |
271 | void *ip) nogil | |
277 | 272 | int nc_put_cmp_att_opaque(int ncid, nc_type xtype, int fieldid, |
278 | char *name, size_t len, void *op) | |
273 | char *name, size_t len, void *op) nogil | |
279 | 274 | int nc_get_cmp_att_opaque(int ncid, nc_type xtype, int fieldid, |
280 | char *name, void *ip) | |
275 | char *name, void *ip) nogil | |
281 | 276 | int nc_put_var1(int ncid, int varid, size_t *indexp, |
282 | void *op) | |
277 | void *op) nogil | |
283 | 278 | int nc_get_var1(int ncid, int varid, size_t *indexp, |
284 | void *ip) | |
279 | void *ip) nogil | |
285 | 280 | int nc_put_vara(int ncid, int varid, size_t *startp, |
286 | size_t *countp, void *op) | |
281 | size_t *countp, void *op) nogil | |
287 | 282 | int nc_get_vara(int ncid, int varid, size_t *startp, |
288 | 283 | size_t *countp, void *ip) nogil |
289 | 284 | int nc_put_vars(int ncid, int varid, size_t *startp, |
290 | 285 | size_t *countp, ptrdiff_t *stridep, |
291 | void *op) | |
286 | void *op) nogil | |
292 | 287 | int nc_get_vars(int ncid, int varid, size_t *startp, |
293 | 288 | size_t *countp, ptrdiff_t *stridep, |
294 | 289 | void *ip) nogil |
295 | 290 | int nc_put_varm(int ncid, int varid, size_t *startp, |
296 | 291 | size_t *countp, ptrdiff_t *stridep, |
297 | ptrdiff_t *imapp, void *op) | |
292 | ptrdiff_t *imapp, void *op) nogil | |
298 | 293 | int nc_get_varm(int ncid, int varid, size_t *startp, |
299 | 294 | size_t *countp, ptrdiff_t *stridep, |
300 | ptrdiff_t *imapp, void *ip) | |
301 | int nc_put_var(int ncid, int varid, void *op) | |
302 | int nc_get_var(int ncid, int varid, void *ip) | |
295 | ptrdiff_t *imapp, void *ip) nogil | |
296 | int nc_put_var(int ncid, int varid, void *op) nogil | |
297 | int nc_get_var(int ncid, int varid, void *ip) nogil | |
303 | 298 | int nc_def_var_deflate(int ncid, int varid, int shuffle, int deflate, |
304 | int deflate_level) | |
305 | int nc_def_var_fletcher32(int ncid, int varid, int fletcher32) | |
299 | int deflate_level) nogil | |
300 | int nc_def_var_fletcher32(int ncid, int varid, int fletcher32) nogil | |
306 | 301 | int nc_inq_var_fletcher32(int ncid, int varid, int *fletcher32p) nogil |
307 | int nc_def_var_chunking(int ncid, int varid, int contiguous, size_t *chunksizesp) | |
308 | int nc_def_var_fill(int ncid, int varid, int no_fill, void *fill_value) | |
309 | int nc_def_var_endian(int ncid, int varid, int endian) | |
302 | int nc_def_var_chunking(int ncid, int varid, int contiguous, size_t *chunksizesp) nogil | |
303 | int nc_def_var_fill(int ncid, int varid, int no_fill, void *fill_value) nogil | |
304 | int nc_def_var_endian(int ncid, int varid, int endian) nogil | |
310 | 305 | int nc_inq_var_chunking(int ncid, int varid, int *contiguousp, size_t *chunksizesp) nogil |
311 | 306 | int nc_inq_var_deflate(int ncid, int varid, int *shufflep, |
312 | 307 | int *deflatep, int *deflate_levelp) nogil |
313 | 308 | int nc_inq_var_fill(int ncid, int varid, int *no_fill, void *fill_value) nogil |
314 | 309 | int nc_inq_var_endian(int ncid, int varid, int *endianp) nogil |
315 | int nc_set_fill(int ncid, int fillmode, int *old_modep) | |
316 | int nc_set_default_format(int format, int *old_formatp) | |
317 | int nc_redef(int ncid) | |
318 | int nc__enddef(int ncid, size_t h_minfree, size_t v_align, | |
319 | size_t v_minfree, size_t r_align) | |
320 | int nc_enddef(int ncid) | |
321 | int nc_sync(int ncid) | |
322 | int nc_abort(int ncid) | |
323 | int nc_close(int ncid) | |
310 | int nc_set_fill(int ncid, int fillmode, int *old_modep) nogil | |
311 | int nc_set_default_format(int format, int *old_formatp) nogil | |
312 | int nc_redef(int ncid) nogil | |
313 | int nc_enddef(int ncid) nogil | |
314 | int nc_sync(int ncid) nogil | |
315 | int nc_abort(int ncid) nogil | |
316 | int nc_close(int ncid) nogil | |
324 | 317 | int nc_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp) nogil |
325 | int nc_inq_ndims(int ncid, int *ndimsp) nogil | |
318 | int nc_inq_ndims(int ncid, int *ndimsp) nogil | |
326 | 319 | int nc_inq_nvars(int ncid, int *nvarsp) nogil |
327 | int nc_inq_natts(int ncid, int *nattsp) nogil | |
320 | int nc_inq_natts(int ncid, int *nattsp) nogil | |
328 | 321 | int nc_inq_unlimdim(int ncid, int *unlimdimidp) nogil |
329 | 322 | int nc_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp) nogil |
330 | 323 | int nc_inq_format(int ncid, int *formatp) nogil |
331 | int nc_def_dim(int ncid, char *name, size_t len, int *idp) | |
324 | int nc_def_dim(int ncid, char *name, size_t len, int *idp) nogil | |
332 | 325 | int nc_inq_dimid(int ncid, char *name, int *idp) nogil |
333 | 326 | int nc_inq_dim(int ncid, int dimid, char *name, size_t *lenp) nogil |
334 | 327 | int nc_inq_dimname(int ncid, int dimid, char *name) nogil |
335 | 328 | int nc_inq_dimlen(int ncid, int dimid, size_t *lenp) nogil |
336 | int nc_rename_dim(int ncid, int dimid, char *name) | |
329 | int nc_rename_dim(int ncid, int dimid, char *name) nogil | |
337 | 330 | int nc_inq_att(int ncid, int varid, char *name, |
338 | 331 | nc_type *xtypep, size_t *lenp) nogil |
339 | 332 | int nc_inq_attid(int ncid, int varid, char *name, int *idp) nogil |
341 | 334 | int nc_inq_attlen(int ncid, int varid, char *name, size_t *lenp) nogil |
342 | 335 | int nc_inq_attname(int ncid, int varid, int attnum, char *name) nogil |
343 | 336 | int nc_copy_att(int ncid_in, int varid_in, char *name, int ncid_out, int varid_out) |
344 | int nc_rename_att(int ncid, int varid, char *name, char *newname) | |
345 | int nc_del_att(int ncid, int varid, char *name) | |
337 | int nc_rename_att(int ncid, int varid, char *name, char *newname) nogil | |
338 | int nc_del_att(int ncid, int varid, char *name) nogil | |
346 | 339 | int nc_put_att_text(int ncid, int varid, char *name, |
347 | size_t len, char *op) | |
340 | size_t len, char *op) nogil | |
348 | 341 | int nc_get_att_text(int ncid, int varid, char *name, char *ip) nogil |
349 | int nc_put_att_uchar(int ncid, int varid, char *name, nc_type xtype, | |
350 | size_t len, unsigned char *op) | |
351 | int nc_get_att_uchar(int ncid, int varid, char *name, unsigned char *ip) | |
352 | int nc_put_att_schar(int ncid, int varid, char *name, nc_type xtype, | |
353 | size_t len, signed char *op) | |
354 | int nc_get_att_schar(int ncid, int varid, char *name, signed char *ip) | |
355 | int nc_put_att_short(int ncid, int varid, char *name, nc_type xtype, | |
356 | size_t len, short *op) | |
357 | int nc_get_att_short(int ncid, int varid, char *name, short *ip) | |
358 | int nc_put_att_int(int ncid, int varid, char *name, nc_type xtype, | |
359 | size_t len, int *op) | |
360 | int nc_get_att_int(int ncid, int varid, char *name, int *ip) | |
361 | int nc_put_att_long(int ncid, int varid, char *name, nc_type xtype, | |
362 | size_t len, long *op) | |
363 | int nc_get_att_long(int ncid, int varid, char *name, long *ip) | |
364 | int nc_put_att_float(int ncid, int varid, char *name, nc_type xtype, | |
365 | size_t len, float *op) | |
366 | int nc_get_att_float(int ncid, int varid, char *name, float *ip) | |
367 | int nc_put_att_double(int ncid, int varid, char *name, nc_type xtype, | |
368 | size_t len, double *op) | |
369 | int nc_get_att_double(int ncid, int varid, char *name, double *ip) | |
370 | int nc_put_att_ushort(int ncid, int varid, char *name, nc_type xtype, | |
371 | size_t len, unsigned short *op) | |
372 | int nc_get_att_ushort(int ncid, int varid, char *name, unsigned short *ip) | |
373 | int nc_put_att_uint(int ncid, int varid, char *name, nc_type xtype, | |
374 | size_t len, unsigned int *op) | |
375 | int nc_get_att_uint(int ncid, int varid, char *name, unsigned int *ip) | |
376 | int nc_put_att_longlong(int ncid, int varid, char *name, nc_type xtype, | |
377 | size_t len, long long *op) | |
378 | int nc_get_att_longlong(int ncid, int varid, char *name, long long *ip) | |
379 | int nc_put_att_ulonglong(int ncid, int varid, char *name, nc_type xtype, | |
380 | size_t len, unsigned long long *op) | |
381 | int nc_get_att_ulonglong(int ncid, int varid, char *name, | |
382 | unsigned long long *ip) | |
383 | 342 | int nc_def_var(int ncid, char *name, nc_type xtype, int ndims, |
384 | int *dimidsp, int *varidp) | |
343 | int *dimidsp, int *varidp) nogil | |
385 | 344 | int nc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, |
386 | 345 | int *ndimsp, int *dimidsp, int *nattsp) nogil |
387 | 346 | int nc_inq_varid(int ncid, char *name, int *varidp) nogil |
390 | 349 | int nc_inq_varndims(int ncid, int varid, int *ndimsp) nogil |
391 | 350 | int nc_inq_vardimid(int ncid, int varid, int *dimidsp) nogil |
392 | 351 | int nc_inq_varnatts(int ncid, int varid, int *nattsp) nogil |
393 | int nc_rename_var(int ncid, int varid, char *name) | |
394 | int nc_copy_var(int ncid_in, int varid, int ncid_out) | |
395 | int nc_put_var1_text(int ncid, int varid, size_t *indexp, char *op) | |
396 | int nc_get_var1_text(int ncid, int varid, size_t *indexp, char *ip) | |
397 | int nc_put_var1_uchar(int ncid, int varid, size_t *indexp, | |
398 | unsigned char *op) | |
399 | int nc_get_var1_uchar(int ncid, int varid, size_t *indexp, | |
400 | unsigned char *ip) | |
401 | int nc_put_var1_schar(int ncid, int varid, size_t *indexp, | |
402 | signed char *op) | |
403 | int nc_get_var1_schar(int ncid, int varid, size_t *indexp, | |
404 | signed char *ip) | |
405 | int nc_put_var1_short(int ncid, int varid, size_t *indexp, | |
406 | short *op) | |
407 | int nc_get_var1_short(int ncid, int varid, size_t *indexp, | |
408 | short *ip) | |
409 | int nc_put_var1_int(int ncid, int varid, size_t *indexp, int *op) | |
410 | int nc_get_var1_int(int ncid, int varid, size_t *indexp, int *ip) | |
411 | int nc_put_var1_long(int ncid, int varid, size_t *indexp, long *op) | |
412 | int nc_get_var1_long(int ncid, int varid, size_t *indexp, long *ip) | |
413 | int nc_put_var1_float(int ncid, int varid, size_t *indexp, float *op) | |
414 | int nc_get_var1_float(int ncid, int varid, size_t *indexp, float *ip) | |
415 | int nc_put_var1_double(int ncid, int varid, size_t *indexp, double *op) | |
416 | int nc_get_var1_double(int ncid, int varid, size_t *indexp, double *ip) | |
417 | int nc_put_var1_ubyte(int ncid, int varid, size_t *indexp, | |
418 | unsigned char *op) | |
419 | int nc_get_var1_ubyte(int ncid, int varid, size_t *indexp, | |
420 | unsigned char *ip) | |
421 | int nc_put_var1_ushort(int ncid, int varid, size_t *indexp, | |
422 | unsigned short *op) | |
423 | int nc_get_var1_ushort(int ncid, int varid, size_t *indexp, | |
424 | unsigned short *ip) | |
425 | int nc_put_var1_uint(int ncid, int varid, size_t *indexp, | |
426 | unsigned int *op) | |
427 | int nc_get_var1_uint(int ncid, int varid, size_t *indexp, | |
428 | unsigned int *ip) | |
429 | int nc_put_var1_longlong(int ncid, int varid, size_t *indexp, | |
430 | long long *op) | |
431 | int nc_get_var1_longlong(int ncid, int varid, size_t *indexp, | |
432 | long long *ip) | |
433 | int nc_put_var1_ulonglong(int ncid, int varid, size_t *indexp, | |
434 | unsigned long long *op) | |
435 | int nc_get_var1_ulonglong(int ncid, int varid, size_t *indexp, | |
436 | unsigned long long *ip) | |
437 | int nc_put_vara_text(int ncid, int varid, | |
438 | size_t *startp, size_t *countp, char *op) | |
439 | int nc_get_vara_text(int ncid, int varid, | |
440 | size_t *startp, size_t *countp, char *ip) | |
441 | int nc_put_vara_uchar(int ncid, int varid, | |
442 | size_t *startp, size_t *countp, unsigned char *op) | |
443 | int nc_get_vara_uchar(int ncid, int varid, size_t *startp, | |
444 | size_t *countp, unsigned char *ip) | |
445 | int nc_put_vara_schar(int ncid, int varid, size_t *startp, | |
446 | size_t *countp, signed char *op) | |
447 | int nc_get_vara_schar(int ncid, int varid, size_t *startp, | |
448 | size_t *countp, signed char *ip) | |
449 | int nc_put_vara_short(int ncid, int varid, size_t *startp, | |
450 | size_t *countp, short *op) | |
451 | int nc_get_vara_short(int ncid, int varid, size_t *startp, | |
452 | size_t *countp, short *ip) | |
453 | int nc_put_vara_int(int ncid, int varid, size_t *startp, | |
454 | size_t *countp, int *op) | |
455 | int nc_get_vara_int(int ncid, int varid, size_t *startp, | |
456 | size_t *countp, int *ip) | |
457 | int nc_put_vara_long(int ncid, int varid, size_t *startp, | |
458 | size_t *countp, long *op) | |
459 | int nc_get_vara_long(int ncid, int varid, | |
460 | size_t *startp, size_t *countp, long *ip) | |
461 | int nc_put_vara_float(int ncid, int varid, | |
462 | size_t *startp, size_t *countp, float *op) | |
463 | int nc_get_vara_float(int ncid, int varid, | |
464 | size_t *startp, size_t *countp, float *ip) | |
465 | int nc_put_vara_double(int ncid, int varid, size_t *startp, | |
466 | size_t *countp, double *op) | |
467 | int nc_get_vara_double(int ncid, int varid, size_t *startp, | |
468 | size_t *countp, double *ip) | |
469 | int nc_put_vara_ubyte(int ncid, int varid, size_t *startp, | |
470 | size_t *countp, unsigned char *op) | |
471 | int nc_get_vara_ubyte(int ncid, int varid, size_t *startp, | |
472 | size_t *countp, unsigned char *ip) | |
473 | int nc_put_vara_ushort(int ncid, int varid, size_t *startp, | |
474 | size_t *countp, unsigned short *op) | |
475 | int nc_get_vara_ushort(int ncid, int varid, size_t *startp, | |
476 | size_t *countp, unsigned short *ip) | |
477 | int nc_put_vara_uint(int ncid, int varid, size_t *startp, | |
478 | size_t *countp, unsigned int *op) | |
479 | int nc_get_vara_uint(int ncid, int varid, size_t *startp, | |
480 | size_t *countp, unsigned int *ip) | |
481 | int nc_put_vara_longlong(int ncid, int varid, size_t *startp, | |
482 | size_t *countp, long long *op) | |
483 | int nc_get_vara_longlong(int ncid, int varid, size_t *startp, | |
484 | size_t *countp, long long *ip) | |
485 | int nc_put_vara_ulonglong(int ncid, int varid, size_t *startp, | |
486 | size_t *countp, unsigned long long *op) | |
487 | int nc_get_vara_ulonglong(int ncid, int varid, size_t *startp, | |
488 | size_t *countp, unsigned long long *ip) | |
489 | int nc_put_vars_text(int ncid, int varid, | |
490 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
491 | char *op) | |
492 | int nc_get_vars_text(int ncid, int varid, | |
493 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
494 | char *ip) | |
495 | int nc_put_vars_uchar(int ncid, int varid, | |
496 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
497 | unsigned char *op) | |
498 | int nc_get_vars_uchar(int ncid, int varid, | |
499 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
500 | unsigned char *ip) | |
501 | int nc_put_vars_schar(int ncid, int varid, | |
502 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
503 | signed char *op) | |
504 | int nc_get_vars_schar(int ncid, int varid, | |
505 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
506 | signed char *ip) | |
507 | int nc_put_vars_short(int ncid, int varid, | |
508 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
509 | short *op) | |
510 | int nc_get_vars_short(int ncid, int varid, size_t *startp, | |
511 | size_t *countp, ptrdiff_t *stridep, | |
512 | short *ip) | |
513 | int nc_put_vars_int(int ncid, int varid, | |
514 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
515 | int *op) | |
516 | int nc_get_vars_int(int ncid, int varid, | |
517 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
518 | int *ip) | |
519 | int nc_put_vars_long(int ncid, int varid, | |
520 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
521 | long *op) | |
522 | int nc_get_vars_long(int ncid, int varid, | |
523 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
524 | long *ip) | |
525 | int nc_put_vars_float(int ncid, int varid, | |
526 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
527 | float *op) | |
528 | int nc_get_vars_float(int ncid, int varid, | |
529 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
530 | float *ip) | |
531 | int nc_put_vars_double(int ncid, int varid, | |
532 | size_t *startp, size_t *countp, ptrdiff_t *stridep, | |
533 | double *op) | |
534 | int nc_get_vars_double(int ncid, int varid, size_t *startp, | |
535 | size_t *countp, ptrdiff_t *stridep, | |
536 | double *ip) | |
537 | int nc_put_vars_ubyte(int ncid, int varid, size_t *startp, | |
538 | size_t *countp, ptrdiff_t *stridep, | |
539 | unsigned char *op) | |
540 | int nc_get_vars_ubyte(int ncid, int varid, size_t *startp, | |
541 | size_t *countp, ptrdiff_t *stridep, | |
542 | unsigned char *ip) | |
543 | int nc_put_vars_ushort(int ncid, int varid, size_t *startp, | |
544 | size_t *countp, ptrdiff_t *stridep, | |
545 | unsigned short *op) | |
546 | int nc_get_vars_ushort(int ncid, int varid, size_t *startp, | |
547 | size_t *countp, ptrdiff_t *stridep, | |
548 | unsigned short *ip) | |
549 | int nc_put_vars_uint(int ncid, int varid, size_t *startp, | |
550 | size_t *countp, ptrdiff_t *stridep, | |
551 | unsigned int *op) | |
552 | int nc_get_vars_uint(int ncid, int varid, size_t *startp, | |
553 | size_t *countp, ptrdiff_t *stridep, | |
554 | unsigned int *ip) | |
555 | int nc_put_vars_longlong(int ncid, int varid, size_t *startp, | |
556 | size_t *countp, ptrdiff_t *stridep, | |
557 | long long *op) | |
558 | int nc_get_vars_longlong(int ncid, int varid, size_t *startp, | |
559 | size_t *countp, ptrdiff_t *stridep, | |
560 | long long *ip) | |
561 | int nc_put_vars_ulonglong(int ncid, int varid, size_t *startp, | |
562 | size_t *countp, ptrdiff_t *stridep, | |
563 | unsigned long long *op) | |
564 | int nc_get_vars_ulonglong(int ncid, int varid, size_t *startp, | |
565 | size_t *countp, ptrdiff_t *stridep, | |
566 | unsigned long long *ip) | |
567 | int nc_put_varm_text(int ncid, int varid, size_t *startp, | |
568 | size_t *countp, ptrdiff_t *stridep, | |
569 | ptrdiff_t *imapp, char *op) | |
570 | int nc_get_varm_text(int ncid, int varid, size_t *startp, | |
571 | size_t *countp, ptrdiff_t *stridep, | |
572 | ptrdiff_t *imapp, char *ip) | |
573 | int nc_put_varm_uchar(int ncid, int varid, size_t *startp, | |
574 | size_t *countp, ptrdiff_t *stridep, | |
575 | ptrdiff_t *imapp, unsigned char *op) | |
576 | int nc_get_varm_uchar(int ncid, int varid, size_t *startp, | |
577 | size_t *countp, ptrdiff_t *stridep, | |
578 | ptrdiff_t *imapp, unsigned char *ip) | |
579 | int nc_put_varm_schar(int ncid, int varid, size_t *startp, | |
580 | size_t *countp, ptrdiff_t *stridep, | |
581 | ptrdiff_t *imapp, signed char *op) | |
582 | int nc_get_varm_schar(int ncid, int varid, size_t *startp, | |
583 | size_t *countp, ptrdiff_t *stridep, | |
584 | ptrdiff_t *imapp, signed char *ip) | |
585 | int nc_put_varm_short(int ncid, int varid, size_t *startp, | |
586 | size_t *countp, ptrdiff_t *stridep, | |
587 | ptrdiff_t *imapp, short *op) | |
588 | int nc_get_varm_short(int ncid, int varid, size_t *startp, | |
589 | size_t *countp, ptrdiff_t *stridep, | |
590 | ptrdiff_t *imapp, short *ip) | |
591 | int nc_put_varm_int(int ncid, int varid, size_t *startp, | |
592 | size_t *countp, ptrdiff_t *stridep, | |
593 | ptrdiff_t *imapp, int *op) | |
594 | int nc_get_varm_int(int ncid, int varid, size_t *startp, | |
595 | size_t *countp, ptrdiff_t *stridep, | |
596 | ptrdiff_t *imapp, int *ip) | |
597 | int nc_put_varm_long(int ncid, int varid, size_t *startp, | |
598 | size_t *countp, ptrdiff_t *stridep, | |
599 | ptrdiff_t *imapp, long *op) | |
600 | int nc_get_varm_long(int ncid, int varid, size_t *startp, | |
601 | size_t *countp, ptrdiff_t *stridep, | |
602 | ptrdiff_t *imapp, long *ip) | |
603 | int nc_put_varm_float(int ncid, int varid,size_t *startp, | |
604 | size_t *countp, ptrdiff_t *stridep, | |
605 | ptrdiff_t *imapp, float *op) | |
606 | int nc_get_varm_float(int ncid, int varid,size_t *startp, | |
607 | size_t *countp, ptrdiff_t *stridep, | |
608 | ptrdiff_t *imapp, float *ip) | |
609 | int nc_put_varm_double(int ncid, int varid, size_t *startp, | |
610 | size_t *countp, ptrdiff_t *stridep, | |
611 | ptrdiff_t *imapp, double *op) | |
612 | int nc_get_varm_double(int ncid, int varid, size_t *startp, | |
613 | size_t *countp, ptrdiff_t *stridep, | |
614 | ptrdiff_t * imapp, double *ip) | |
615 | int nc_put_varm_ubyte(int ncid, int varid, size_t *startp, | |
616 | size_t *countp, ptrdiff_t *stridep, | |
617 | ptrdiff_t * imapp, unsigned char *op) | |
618 | int nc_get_varm_ubyte(int ncid, int varid, size_t *startp, | |
619 | size_t *countp, ptrdiff_t *stridep, | |
620 | ptrdiff_t * imapp, unsigned char *ip) | |
621 | int nc_put_varm_ushort(int ncid, int varid, size_t *startp, | |
622 | size_t *countp, ptrdiff_t *stridep, | |
623 | ptrdiff_t * imapp, unsigned short *op) | |
624 | int nc_get_varm_ushort(int ncid, int varid, size_t *startp, | |
625 | size_t *countp, ptrdiff_t *stridep, | |
626 | ptrdiff_t * imapp, unsigned short *ip) | |
627 | int nc_put_varm_uint(int ncid, int varid, size_t *startp, | |
628 | size_t *countp, ptrdiff_t *stridep, | |
629 | ptrdiff_t * imapp, unsigned int *op) | |
630 | int nc_get_varm_uint(int ncid, int varid, size_t *startp, | |
631 | size_t *countp, ptrdiff_t *stridep, | |
632 | ptrdiff_t * imapp, unsigned int *ip) | |
633 | int nc_put_varm_longlong(int ncid, int varid, size_t *startp, | |
634 | size_t *countp, ptrdiff_t *stridep, | |
635 | ptrdiff_t * imapp, long long *op) | |
636 | int nc_get_varm_longlong(int ncid, int varid, size_t *startp, | |
637 | size_t *countp, ptrdiff_t *stridep, | |
638 | ptrdiff_t * imapp, long long *ip) | |
639 | int nc_put_varm_ulonglong(int ncid, int varid, size_t *startp, | |
640 | size_t *countp, ptrdiff_t *stridep, | |
641 | ptrdiff_t * imapp, unsigned long long *op) | |
642 | int nc_get_varm_ulonglong(int ncid, int varid, size_t *startp, | |
643 | size_t *countp, ptrdiff_t *stridep, | |
644 | ptrdiff_t * imapp, unsigned long long *ip) | |
645 | int nc_put_var_text(int ncid, int varid, char *op) | |
646 | int nc_get_var_text(int ncid, int varid, char *ip) | |
647 | int nc_put_var_uchar(int ncid, int varid, unsigned char *op) | |
648 | int nc_get_var_uchar(int ncid, int varid, unsigned char *ip) | |
649 | int nc_put_var_schar(int ncid, int varid, signed char *op) | |
650 | int nc_get_var_schar(int ncid, int varid, signed char *ip) | |
651 | int nc_put_var_short(int ncid, int varid, short *op) | |
652 | int nc_get_var_short(int ncid, int varid, short *ip) | |
653 | int nc_put_var_int(int ncid, int varid, int *op) | |
654 | int nc_get_var_int(int ncid, int varid, int *ip) | |
655 | int nc_put_var_long(int ncid, int varid, long *op) | |
656 | int nc_get_var_long(int ncid, int varid, long *ip) | |
657 | int nc_put_var_float(int ncid, int varid, float *op) | |
658 | int nc_get_var_float(int ncid, int varid, float *ip) | |
659 | int nc_put_var_double(int ncid, int varid, double *op) | |
660 | int nc_get_var_double(int ncid, int varid, double *ip) | |
661 | int nc_put_var_ubyte(int ncid, int varid, unsigned char *op) | |
662 | int nc_get_var_ubyte(int ncid, int varid, unsigned char *ip) | |
663 | int nc_put_var_ushort(int ncid, int varid, unsigned short *op) | |
664 | int nc_get_var_ushort(int ncid, int varid, unsigned short *ip) | |
665 | int nc_put_var_uint(int ncid, int varid, unsigned int *op) | |
666 | int nc_get_var_uint(int ncid, int varid, unsigned int *ip) | |
667 | int nc_put_var_longlong(int ncid, int varid, long long *op) | |
668 | int nc_get_var_longlong(int ncid, int varid, long long *ip) | |
669 | int nc_put_var_ulonglong(int ncid, int varid, unsigned long long *op) | |
670 | int nc_get_var_ulonglong(int ncid, int varid, unsigned long long *ip) | |
671 | # set logging verbosity level. | |
672 | void nc_set_log_level(int new_level) | |
673 | int nc_show_metadata(int ncid) | |
674 | int nc_free_vlen(nc_vlen_t *vl) | |
675 | int nc_free_vlens(size_t len, nc_vlen_t *vl) | |
676 | int nc_free_string(size_t len, char **data) | |
677 | int nc_set_chunk_cache(size_t size, size_t nelems, float preemption) | |
678 | int nc_get_chunk_cache(size_t *sizep, size_t *nelemsp, float *preemptionp) | |
679 | int nc_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems, float preemption) | |
352 | int nc_rename_var(int ncid, int varid, char *name) nogil | |
353 | int nc_free_vlen(nc_vlen_t *vl) nogil | |
354 | int nc_free_vlens(size_t len, nc_vlen_t *vl) nogil | |
355 | int nc_free_string(size_t len, char **data) nogil | |
356 | int nc_get_chunk_cache(size_t *sizep, size_t *nelemsp, float *preemptionp) nogil | |
357 | int nc_set_chunk_cache(size_t size, size_t nelems, float preemption) nogil | |
358 | int nc_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems, float preemption) nogil | |
680 | 359 | int nc_get_var_chunk_cache(int ncid, int varid, size_t *sizep, size_t *nelemsp, float *preemptionp) nogil |
681 | int nc_rename_grp(int grpid, char *name) | |
682 | int nc_def_enum(int ncid, nc_type base_typeid, char *name, nc_type *typeidp) | |
683 | int nc_insert_enum(int ncid, nc_type xtype, char *name, void *value) | |
360 | int nc_rename_grp(int grpid, char *name) nogil | |
361 | int nc_def_enum(int ncid, nc_type base_typeid, char *name, nc_type *typeidp) nogil | |
362 | int nc_insert_enum(int ncid, nc_type xtype, char *name, void *value) nogil | |
684 | 363 | int nc_inq_enum(int ncid, nc_type xtype, char *name, nc_type *base_nc_typep,\ |
685 | 364 | size_t *base_sizep, size_t *num_membersp) nogil |
686 | 365 | int nc_inq_enum_member(int ncid, nc_type xtype, int idx, char *name, void *value) nogil |
695 | 374 | NC_QUANTIZE_BITGROOM |
696 | 375 | NC_QUANTIZE_GRANULARBR |
697 | 376 | NC_QUANTIZE_BITROUND |
698 | int nc_def_var_quantize(int ncid, int varid, int quantize_mode, int nsd) | |
377 | int nc_def_var_quantize(int ncid, int varid, int quantize_mode, int nsd) nogil | |
699 | 378 | int nc_inq_var_quantize(int ncid, int varid, int *quantize_modep, int *nsdp) nogil |
379 | cdef extern from "netcdf_filter.h": | |
380 | int nc_inq_filter_avail(int ncid, unsigned filterid) nogil | |
700 | 381 | |
701 | 382 | IF HAS_SZIP_SUPPORT: |
702 | 383 | cdef extern from "netcdf.h": |
703 | int nc_def_var_quantize(int ncid, int varid, int quantize_mode, int nsd) | |
384 | cdef enum: | |
385 | H5Z_FILTER_SZIP | |
386 | int nc_def_var_quantize(int ncid, int varid, int quantize_mode, int nsd) nogil | |
704 | 387 | int nc_inq_var_quantize(int ncid, int varid, int *quantize_modep, int *nsdp) nogil |
705 | int nc_def_var_szip(int ncid, int varid, int options_mask, int pixels_per_bloc) | |
706 | int nc_inq_var_szip(int ncid, int varid, int *options_maskp, int *pixels_per_blockp) | |
388 | int nc_def_var_szip(int ncid, int varid, int options_mask, int pixels_per_bloc) nogil | |
389 | int nc_inq_var_szip(int ncid, int varid, int *options_maskp, int *pixels_per_blockp) nogil | |
707 | 390 | |
708 | 391 | IF HAS_ZSTANDARD_SUPPORT: |
709 | 392 | cdef extern from "netcdf_filter.h": |
710 | 393 | cdef enum: |
711 | H5Z_FILTER_ZSTANDARD | |
712 | int nc_def_var_zstandard(int ncid, int varid, int level) | |
713 | int nc_inq_var_zstandard(int ncid, int varid, int* hasfilterp, int *levelp) | |
714 | int nc_inq_filter_avail(int ncid, unsigned id) | |
394 | H5Z_FILTER_ZSTD | |
395 | int nc_def_var_zstandard(int ncid, int varid, int level) nogil | |
396 | int nc_inq_var_zstandard(int ncid, int varid, int* hasfilterp, int *levelp) nogil | |
397 | int nc_inq_filter_avail(int ncid, unsigned id) nogil | |
715 | 398 | |
716 | 399 | IF HAS_BZIP2_SUPPORT: |
717 | 400 | cdef extern from "netcdf_filter.h": |
718 | 401 | cdef enum: |
719 | 402 | H5Z_FILTER_BZIP2 |
720 | int nc_def_var_bzip2(int ncid, int varid, int level) | |
721 | int nc_inq_var_bzip2(int ncid, int varid, int* hasfilterp, int *levelp) | |
403 | int nc_def_var_bzip2(int ncid, int varid, int level) nogil | |
404 | int nc_inq_var_bzip2(int ncid, int varid, int* hasfilterp, int *levelp) nogil | |
722 | 405 | |
723 | 406 | IF HAS_BLOSC_SUPPORT: |
724 | 407 | cdef extern from "netcdf_filter.h": |
725 | int nc_def_var_blosc(int ncid, int varid, unsigned subcompressor, unsigned level, unsigned blocksize, unsigned addshuffle) | |
726 | int nc_inq_var_blosc(int ncid, int varid, int* hasfilterp, unsigned* subcompressorp, unsigned* levelp, unsigned* blocksizep, unsigned* addshufflep) | |
408 | cdef enum: | |
409 | H5Z_FILTER_BLOSC | |
410 | int nc_def_var_blosc(int ncid, int varid, unsigned subcompressor, unsigned level, unsigned blocksize, unsigned addshuffle) nogil | |
411 | int nc_inq_var_blosc(int ncid, int varid, int* hasfilterp, unsigned* subcompressorp, unsigned* levelp, unsigned* blocksizep, unsigned* addshufflep) nogil | |
727 | 412 | |
728 | 413 | IF HAS_NC_OPEN_MEM: |
729 | 414 | cdef extern from "netcdf_mem.h": |
730 | int nc_open_mem(const char *path, int mode, size_t size, void* memory, int *ncidp) | |
415 | int nc_open_mem(const char *path, int mode, size_t size, void* memory, int *ncidp) nogil | |
731 | 416 | |
732 | 417 | IF HAS_NC_CREATE_MEM: |
733 | 418 | cdef extern from "netcdf_mem.h": |
734 | int nc_create_mem(const char *path, int mode, size_t initialize, int *ncidp); | |
419 | int nc_create_mem(const char *path, int mode, size_t initialize, int *ncidp) nogil | |
735 | 420 | ctypedef struct NC_memio: |
736 | 421 | size_t size |
737 | 422 | void* memory |
738 | 423 | int flags |
739 | int nc_close_memio(int ncid, NC_memio* info); | |
424 | int nc_close_memio(int ncid, NC_memio* info) nogil | |
740 | 425 | |
741 | 426 | IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT: |
742 | 427 | cdef extern from "mpi-compat.h": pass |
743 | 428 | cdef extern from "netcdf_par.h": |
744 | 429 | ctypedef int MPI_Comm |
745 | 430 | ctypedef int MPI_Info |
746 | int nc_create_par(char *path, int cmode, MPI_Comm comm, MPI_Info info, int *ncidp); | |
747 | int nc_open_par(char *path, int mode, MPI_Comm comm, MPI_Info info, int *ncidp); | |
748 | int nc_var_par_access(int ncid, int varid, int par_access); | |
431 | int nc_create_par(char *path, int cmode, MPI_Comm comm, MPI_Info info, int *ncidp) nogil | |
432 | int nc_open_par(char *path, int mode, MPI_Comm comm, MPI_Info info, int *ncidp) nogil | |
433 | int nc_var_par_access(int ncid, int varid, int par_access) nogil | |
749 | 434 | cdef enum: |
750 | 435 | NC_COLLECTIVE |
751 | 436 | NC_INDEPENDENT |
754 | 439 | NC_MPIIO |
755 | 440 | NC_MPIPOSIX |
756 | 441 | NC_PNETCDF |
442 | ||
443 | IF HAS_SET_ALIGNMENT: | |
444 | cdef extern from "netcdf.h": | |
445 | int nc_set_alignment(int threshold, int alignment) | |
446 | int nc_get_alignment(int *threshold, int *alignment) | |
757 | 447 | |
758 | 448 | # taken from numpy.pxi in numpy 1.0rc2. |
759 | 449 | cdef extern from "numpy/arrayobject.h": |
760 | 450 | ctypedef int npy_intp |
761 | 451 | ctypedef extern class numpy.ndarray [object PyArrayObject]: |
762 | 452 | pass |
763 | npy_intp PyArray_SIZE(ndarray arr) | |
764 | npy_intp PyArray_ISCONTIGUOUS(ndarray arr) | |
765 | npy_intp PyArray_ISALIGNED(ndarray arr) | |
453 | npy_intp PyArray_SIZE(ndarray arr) nogil | |
454 | npy_intp PyArray_ISCONTIGUOUS(ndarray arr) nogil | |
455 | npy_intp PyArray_ISALIGNED(ndarray arr) nogil | |
766 | 456 | void* PyArray_DATA(ndarray) nogil |
767 | 457 | char* PyArray_BYTES(ndarray) nogil |
768 | 458 | npy_intp* PyArray_STRIDES(ndarray) nogil |
70 | 70 | has_zstandard = False |
71 | 71 | has_bzip2 = False |
72 | 72 | has_blosc = False |
73 | has_set_alignment = False | |
73 | 74 | |
74 | 75 | for d in inc_dirs: |
75 | 76 | try: |
91 | 92 | has_cdf5_format = True |
92 | 93 | if line.startswith('nc_def_var_quantize'): |
93 | 94 | has_quantize = True |
95 | if line.startswith('nc_set_alignment'): | |
96 | has_set_alignment = True | |
94 | 97 | |
95 | 98 | if has_nc_open_mem: |
96 | 99 | try: |
140 | 143 | return has_rename_grp, has_nc_inq_path, has_nc_inq_format_extended, \ |
141 | 144 | has_cdf5_format, has_nc_open_mem, has_nc_create_mem, \ |
142 | 145 | has_parallel4_support, has_pnetcdf_support, has_szip_support, has_quantize, \ |
143 | has_zstandard, has_bzip2, has_blosc | |
146 | has_zstandard, has_bzip2, has_blosc, has_set_alignment | |
144 | 147 | |
145 | 148 | |
146 | 149 | def getnetcdfvers(libdirs): |
227 | 230 | |
228 | 231 | setup_cfg = 'setup.cfg' |
229 | 232 | # contents of setup.cfg will override env vars, unless |
230 | # USE_SETUPCFG evaluates to False. | |
233 | # USE_SETUPCFG evaluates to False. | |
231 | 234 | ncconfig = None |
232 | 235 | use_ncconfig = None |
233 | 236 | if USE_SETUPCFG and os.path.exists(setup_cfg): |
337 | 340 | elif USE_NCCONFIG is None: |
338 | 341 | # if nc-config exists, and USE_NCCONFIG not set, try to use it. |
339 | 342 | if HAS_NCCONFIG: USE_NCCONFIG=True |
340 | #elif USE_NCCONFIG is None: | |
343 | #elif USE_NCCONFIG is None: | |
341 | 344 | # USE_NCCONFIG = False # don't try to use nc-config if USE_NCCONFIG not set |
342 | 345 | |
343 | 346 | try: |
554 | 557 | has_rename_grp, has_nc_inq_path, has_nc_inq_format_extended, \ |
555 | 558 | has_cdf5_format, has_nc_open_mem, has_nc_create_mem, \ |
556 | 559 | has_parallel4_support, has_pnetcdf_support, has_szip_support, has_quantize, \ |
557 | has_zstandard, has_bzip2, has_blosc = \ | |
560 | has_zstandard, has_bzip2, has_blosc, has_set_alignment = \ | |
558 | 561 | check_api(inc_dirs,netcdf_lib_version) |
559 | 562 | # for netcdf 4.4.x CDF5 format is always enabled. |
560 | 563 | if netcdf_lib_version is not None and\ |
660 | 663 | else: |
661 | 664 | sys.stdout.write('netcdf lib does not have szip compression functions\n') |
662 | 665 | f.write('DEF HAS_SZIP_SUPPORT = 0\n') |
666 | ||
667 | if has_set_alignment: | |
668 | sys.stdout.write('netcdf lib has nc_set_alignment function\n') | |
669 | f.write('DEF HAS_SET_ALIGNMENT = 1\n') | |
670 | else: | |
671 | sys.stdout.write('netcdf lib does not have nc_set_alignment function\n') | |
672 | f.write('DEF HAS_SET_ALIGNMENT = 0\n') | |
663 | 673 | |
664 | 674 | f.close() |
665 | 675 |
11 | 11 | __has_bzip2_support__, __has_blosc_support__, __has_szip_support__) |
12 | 12 | import os |
13 | 13 | __all__ =\ |
14 | ['Dataset','Variable','Dimension','Group','MFDataset','MFTime','CompoundType','VLType','date2num','num2date','date2index','stringtochar','chartostring','stringtoarr','getlibversion','EnumType','get_chunk_cache','set_chunk_cache'] | |
14 | ['Dataset','Variable','Dimension','Group','MFDataset','MFTime','CompoundType','VLType','date2num','num2date','date2index','stringtochar','chartostring','stringtoarr','getlibversion','EnumType','get_chunk_cache','set_chunk_cache','set_alignment','get_alignment'] | |
15 | 15 | # if HDF5_PLUGIN_PATH not set, point to package path if plugins live there |
16 | 16 | pluginpath = os.path.join(__path__[0],'plugins') |
17 | 17 | if 'HDF5_PLUGIN_PATH' not in os.environ and\ |
0 | 0 | """ |
1 | Version 1.6.0 | |
1 | Version 1.6.1 | |
2 | 2 | ------------- |
3 | 3 | |
4 | 4 | # Introduction |
1229 | 1229 | # Python 3.7+ guarantees order; older versions need OrderedDict |
1230 | 1230 | from collections import OrderedDict |
1231 | 1231 | |
1232 | __version__ = "1.6.0" | |
1232 | __version__ = "1.6.1" | |
1233 | 1233 | |
1234 | 1234 | # Initialize numpy |
1235 | 1235 | import posixpath |
1264 | 1264 | def _gethdf5libversion(): |
1265 | 1265 | cdef unsigned int majorvers, minorvers, releasevers |
1266 | 1266 | cdef herr_t ierr |
1267 | ierr = H5get_libversion( &majorvers, &minorvers, &releasevers) | |
1267 | with nogil: | |
1268 | ierr = H5get_libversion( &majorvers, &minorvers, &releasevers) | |
1268 | 1269 | if ierr < 0: |
1269 | 1270 | raise RuntimeError('error getting HDF5 library version info') |
1270 | 1271 | return '%d.%d.%d' % (majorvers,minorvers,releasevers) |
1288 | 1289 | cdef int ierr |
1289 | 1290 | cdef size_t sizep, nelemsp |
1290 | 1291 | cdef float preemptionp |
1291 | ierr = nc_get_chunk_cache(&sizep, &nelemsp, &preemptionp) | |
1292 | with nogil: | |
1293 | ierr = nc_get_chunk_cache(&sizep, &nelemsp, &preemptionp) | |
1292 | 1294 | _ensure_nc_success(ierr) |
1293 | 1295 | size = sizep; nelems = nelemsp; preemption = preemptionp |
1294 | 1296 | return (size,nelems,preemption) |
1317 | 1319 | preemptionp = preemption |
1318 | 1320 | else: |
1319 | 1321 | preemptionp = preemption_orig |
1320 | ierr = nc_set_chunk_cache(sizep,nelemsp, preemptionp) | |
1322 | with nogil: | |
1323 | ierr = nc_set_chunk_cache(sizep,nelemsp, preemptionp) | |
1321 | 1324 | _ensure_nc_success(ierr) |
1325 | ||
1326 | IF HAS_SET_ALIGNMENT: | |
1327 | def get_alignment(): | |
1328 | """ | |
1329 | **`get_alignment()`** | |
1330 | ||
1331 | return current netCDF alignment within HDF5 files in a tuple | |
1332 | (threshold,alignment). See netcdf C library documentation for | |
1333 | `nc_get_alignment` for details. Values can be reset with | |
1334 | `set_alignment`. | |
1335 | ||
1336 | This function was added in netcdf 4.9.0.""" | |
1337 | cdef int ierr | |
1338 | cdef int thresholdp, alignmentp | |
1339 | ierr = nc_get_alignment(&thresholdp, &alignmentp) | |
1340 | _ensure_nc_success(ierr) | |
1341 | threshold = thresholdp | |
1342 | alignment = alignmentp | |
1343 | return (threshold,alignment) | |
1344 | ||
1345 | def set_alignment(threshold, alignment): | |
1346 | """ | |
1347 | **`set_alignment(threshold,alignment)`** | |
1348 | ||
1349 | Change the HDF5 file alignment. | |
1350 | See netcdf C library documentation for `nc_set_alignment` for | |
1351 | details. | |
1352 | ||
1353 | This function was added in netcdf 4.9.0.""" | |
1354 | cdef int ierr | |
1355 | cdef int thresholdp, alignmentp | |
1356 | thresholdp = threshold | |
1357 | alignmentp = alignment | |
1358 | ||
1359 | ierr = nc_set_alignment(thresholdp, alignmentp) | |
1360 | _ensure_nc_success(ierr) | |
1361 | ELSE: | |
1362 | def get_alignment(): | |
1363 | raise RuntimeError( | |
1364 | "This function requires netcdf4 4.9.0+ to be used at compile time" | |
1365 | ) | |
1366 | ||
1367 | def set_alignment(threshold, alignment): | |
1368 | raise RuntimeError( | |
1369 | "This function requires netcdf4 4.9.0+ to be used at compile time" | |
1370 | ) | |
1322 | 1371 | |
1323 | 1372 | __netcdf4libversion__ = getlibversion().split()[0] |
1324 | 1373 | __hdf5libversion__ = _gethdf5libversion() |
1335 | 1384 | __has_bzip2_support__ = HAS_BZIP2_SUPPORT |
1336 | 1385 | __has_blosc_support__ = HAS_BLOSC_SUPPORT |
1337 | 1386 | __has_szip_support__ = HAS_SZIP_SUPPORT |
1387 | __has_set_alignment__ = HAS_SET_ALIGNMENT | |
1338 | 1388 | _needsworkaround_issue485 = __netcdf4libversion__ < "4.4.0" or \ |
1339 | 1389 | (__netcdf4libversion__.startswith("4.4.0") and \ |
1340 | 1390 | "-development" in __netcdf4libversion__) |
1506 | 1556 | result = [values[j].decode(encoding,errors='replace').replace('\x00','') |
1507 | 1557 | if values[j] else "" for j in range(att_len)] |
1508 | 1558 | finally: |
1509 | ierr = nc_free_string(att_len, values) # free memory in netcdf C lib | |
1559 | with nogil: | |
1560 | ierr = nc_free_string(att_len, values) # free memory in netcdf C lib | |
1510 | 1561 | finally: |
1511 | 1562 | PyMem_Free(values) |
1512 | 1563 | |
1547 | 1598 | |
1548 | 1599 | def _set_default_format(object format='NETCDF4'): |
1549 | 1600 | # Private function to set the netCDF file format |
1601 | cdef int ierr, formatid | |
1550 | 1602 | if format not in _format_dict: |
1551 | 1603 | raise ValueError("unrecognized format requested") |
1552 | nc_set_default_format(_format_dict[format], NULL) | |
1604 | formatid = _format_dict[format] | |
1605 | with nogil: | |
1606 | ierr = nc_set_default_format(formatid, NULL) | |
1607 | _ensure_nc_success(ierr) | |
1553 | 1608 | |
1554 | 1609 | cdef _get_format(int grpid): |
1555 | 1610 | # Private function to get the netCDF file format |
1596 | 1651 | |
1597 | 1652 | if not _needsworkaround_issue485: |
1598 | 1653 | return |
1599 | ierr = nc_inq_att(grpid, varid, attname, &att_type, &att_len) | |
1654 | with nogil: | |
1655 | ierr = nc_inq_att(grpid, varid, attname, &att_type, &att_len) | |
1600 | 1656 | if ierr == NC_NOERR and att_type == NC_CHAR: |
1601 | ierr = nc_del_att(grpid, varid, attname) | |
1657 | with nogil: | |
1658 | ierr = nc_del_att(grpid, varid, attname) | |
1602 | 1659 | _ensure_nc_success(ierr) |
1603 | 1660 | |
1604 | 1661 | |
1605 | 1662 | cdef _set_att(grp, int varid, name, value,\ |
1606 | 1663 | nc_type xtype=-99, force_ncstring=False): |
1607 | 1664 | # Private function to set an attribute name/value pair |
1608 | cdef int ierr, lenarr | |
1665 | cdef int ierr, lenarr, N, grpid | |
1609 | 1666 | cdef char *attname |
1610 | 1667 | cdef char *datstring |
1611 | 1668 | cdef char **string_ptrs |
1612 | 1669 | cdef ndarray value_arr |
1613 | 1670 | bytestr = _strencode(name) |
1614 | 1671 | attname = bytestr |
1672 | grpid = grp._grpid | |
1615 | 1673 | # put attribute value into a numpy array. |
1616 | 1674 | value_arr = numpy.array(value) |
1617 | 1675 | if value_arr.ndim > 1: # issue #841 |
1625 | 1683 | warnings.warn(msg,FutureWarning) |
1626 | 1684 | # if array is 64 bit integers or |
1627 | 1685 | # if 64-bit datatype not supported, cast to 32 bit integers. |
1628 | fmt = _get_format(grp._grpid) | |
1686 | fmt = _get_format(grpid) | |
1629 | 1687 | is_netcdf3 = fmt.startswith('NETCDF3') or fmt == 'NETCDF4_CLASSIC' |
1630 | 1688 | if value_arr.dtype.str[1:] == 'i8' and ('i8' not in _supportedtypes or\ |
1631 | 1689 | (is_netcdf3 and fmt != 'NETCDF3_64BIT_DATA')): |
1647 | 1705 | if len(strings[j]) == 0: |
1648 | 1706 | strings[j] = _strencode('\x00') |
1649 | 1707 | string_ptrs[j] = strings[j] |
1650 | issue485_workaround(grp._grpid, varid, attname) | |
1651 | ierr = nc_put_att_string(grp._grpid, varid, attname, N, string_ptrs) | |
1708 | issue485_workaround(grpid, varid, attname) | |
1709 | with nogil: | |
1710 | ierr = nc_put_att_string(grpid, varid, attname, N, string_ptrs) | |
1652 | 1711 | finally: |
1653 | 1712 | PyMem_Free(string_ptrs) |
1654 | 1713 | else: |
1672 | 1731 | try: |
1673 | 1732 | if force_ncstring: raise UnicodeError |
1674 | 1733 | dats_ascii = _to_ascii(dats) # try to encode bytes as ascii string |
1675 | ierr = nc_put_att_text(grp._grpid, varid, attname, lenarr, datstring) | |
1734 | with nogil: | |
1735 | ierr = nc_put_att_text(grpid, varid, attname, lenarr, datstring) | |
1676 | 1736 | except UnicodeError: |
1677 | issue485_workaround(grp._grpid, varid, attname) | |
1678 | ierr = nc_put_att_string(grp._grpid, varid, attname, 1, &datstring) | |
1737 | issue485_workaround(grpid, varid, attname) | |
1738 | with nogil: | |
1739 | ierr = nc_put_att_string(grpid, varid, attname, 1, &datstring) | |
1679 | 1740 | else: |
1680 | ierr = nc_put_att_text(grp._grpid, varid, attname, lenarr, datstring) | |
1741 | with nogil: | |
1742 | ierr = nc_put_att_text(grpid, varid, attname, lenarr, datstring) | |
1681 | 1743 | _ensure_nc_success(ierr, err_cls=AttributeError) |
1682 | 1744 | # a 'regular' array type ('f4','i4','f8' etc) |
1683 | 1745 | else: |
1688 | 1750 | elif xtype == -99: # if xtype is not passed in as kwarg. |
1689 | 1751 | xtype = _nptonctype[value_arr.dtype.str[1:]] |
1690 | 1752 | lenarr = PyArray_SIZE(value_arr) |
1691 | ierr = nc_put_att(grp._grpid, varid, attname, xtype, lenarr, | |
1753 | with nogil: | |
1754 | ierr = nc_put_att(grpid, varid, attname, xtype, lenarr, | |
1692 | 1755 | PyArray_DATA(value_arr)) |
1693 | 1756 | _ensure_nc_success(ierr, err_cls=AttributeError) |
1694 | 1757 | |
2150 | 2213 | **`info`**: MPI_Info object for parallel access. Default `None`, which |
2151 | 2214 | means MPI_INFO_NULL will be used. Ignored if `parallel=False`. |
2152 | 2215 | """ |
2153 | cdef int grpid, ierr, numgrps, numdims, numvars | |
2216 | cdef int grpid, ierr, numgrps, numdims, numvars, | |
2154 | 2217 | cdef size_t initialsize |
2155 | 2218 | cdef char *path |
2156 | 2219 | cdef char namstring[NC_MAX_NAME+1] |
2157 | cdef int cmode | |
2220 | cdef int cmode, parmode | |
2158 | 2221 | IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT: |
2159 | 2222 | cdef MPI_Comm mpicomm |
2160 | 2223 | cdef MPI_Info mpiinfo |
2201 | 2264 | mpiinfo = info.ob_mpi |
2202 | 2265 | else: |
2203 | 2266 | mpiinfo = MPI_INFO_NULL |
2204 | cmode = NC_MPIIO | _cmode_dict[format] | |
2267 | parmode = NC_MPIIO | _cmode_dict[format] | |
2205 | 2268 | |
2206 | 2269 | self._inmemory = False |
2207 | 2270 | |
2216 | 2279 | # kwarg is interpreted as advisory size. |
2217 | 2280 | IF HAS_NC_CREATE_MEM: |
2218 | 2281 | initialsize = <size_t>memory |
2219 | ierr = nc_create_mem(path, 0, initialsize, &grpid) | |
2282 | with nogil: | |
2283 | ierr = nc_create_mem(path, 0, initialsize, &grpid) | |
2220 | 2284 | self._inmemory = True # checked in close method |
2221 | 2285 | ELSE: |
2222 | 2286 | msg = """ |
2227 | 2291 | if clobber: |
2228 | 2292 | if parallel: |
2229 | 2293 | IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT: |
2230 | ierr = nc_create_par(path, NC_CLOBBER | cmode, \ | |
2231 | mpicomm, mpiinfo, &grpid) | |
2294 | cmode = NC_CLOBBER | parmode | |
2295 | with nogil: | |
2296 | ierr = nc_create_par(path, cmode, \ | |
2297 | mpicomm, mpiinfo, &grpid) | |
2232 | 2298 | ELSE: |
2233 | 2299 | pass |
2234 | 2300 | elif diskless: |
2235 | 2301 | if persist: |
2236 | ierr = nc_create(path, NC_WRITE | NC_CLOBBER | | |
2237 | NC_DISKLESS | NC_PERSIST, &grpid) | |
2302 | cmode = NC_WRITE | NC_CLOBBER | NC_DISKLESS | NC_PERSIST | |
2303 | with nogil: | |
2304 | ierr = nc_create(path, cmode, &grpid) | |
2238 | 2305 | else: |
2239 | ierr = nc_create(path, NC_CLOBBER | NC_DISKLESS , &grpid) | |
2306 | cmode = NC_CLOBBER | NC_DISKLESS | |
2307 | with nogil: | |
2308 | ierr = nc_create(path, cmode , &grpid) | |
2240 | 2309 | else: |
2241 | ierr = nc_create(path, NC_CLOBBER, &grpid) | |
2310 | with nogil: | |
2311 | ierr = nc_create(path, NC_CLOBBER, &grpid) | |
2242 | 2312 | else: |
2243 | 2313 | if parallel: |
2244 | 2314 | IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT: |
2245 | ierr = nc_create_par(path, NC_NOCLOBBER | cmode, \ | |
2246 | mpicomm, mpiinfo, &grpid) | |
2315 | cmode = NC_NOCLOBBER | parmode | |
2316 | with nogil: | |
2317 | ierr = nc_create_par(path, cmode, \ | |
2318 | mpicomm, mpiinfo, &grpid) | |
2247 | 2319 | ELSE: |
2248 | 2320 | pass |
2249 | 2321 | elif diskless: |
2250 | 2322 | if persist: |
2251 | ierr = nc_create(path, NC_WRITE | NC_NOCLOBBER | | |
2252 | NC_DISKLESS | NC_PERSIST , &grpid) | |
2323 | cmode = NC_WRITE | NC_NOCLOBBER | NC_DISKLESS | NC_PERSIST | |
2324 | with nogil: | |
2325 | ierr = nc_create(path, cmode, &grpid) | |
2253 | 2326 | else: |
2254 | ierr = nc_create(path, NC_NOCLOBBER | NC_DISKLESS , &grpid) | |
2327 | cmode = NC_NOCLOBBER | NC_DISKLESS | |
2328 | with nogil: | |
2329 | ierr = nc_create(path, cmode , &grpid) | |
2255 | 2330 | else: |
2256 | ierr = nc_create(path, NC_NOCLOBBER, &grpid) | |
2331 | with nogil: | |
2332 | ierr = nc_create(path, NC_NOCLOBBER, &grpid) | |
2257 | 2333 | # reset default format to netcdf3 - this is a workaround |
2258 | 2334 | # for issue 170 (nc_open'ing a DAP dataset after switching |
2259 | 2335 | # format to NETCDF4). This bug should be fixed in version |
2269 | 2345 | if result != 0: |
2270 | 2346 | raise ValueError("Unable to retrieve Buffer from %s" % (memory,)) |
2271 | 2347 | |
2272 | ierr = nc_open_mem(<char *>path, 0, self._buffer.len, <void *>self._buffer.buf, &grpid) | |
2348 | with nogil: | |
2349 | ierr = nc_open_mem(<char *>path, 0, self._buffer.len, <void *>self._buffer.buf, &grpid) | |
2273 | 2350 | ELSE: |
2274 | 2351 | msg = """ |
2275 | 2352 | nc_open_mem functionality not enabled. To enable, install Cython, make sure you have |
2277 | 2354 | raise ValueError(msg) |
2278 | 2355 | elif parallel: |
2279 | 2356 | IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT: |
2280 | ierr = nc_open_par(path, NC_NOWRITE | NC_MPIIO, \ | |
2281 | mpicomm, mpiinfo, &grpid) | |
2357 | cmode = NC_NOWRITE | NC_MPIIO | |
2358 | with nogil: | |
2359 | ierr = nc_open_par(path, cmode, \ | |
2360 | mpicomm, mpiinfo, &grpid) | |
2282 | 2361 | ELSE: |
2283 | 2362 | pass |
2284 | 2363 | elif diskless: |
2285 | ierr = nc_open(path, NC_NOWRITE | NC_DISKLESS, &grpid) | |
2364 | cmode = NC_NOWRITE | NC_DISKLESS | |
2365 | with nogil: | |
2366 | ierr = nc_open(path, cmode, &grpid) | |
2286 | 2367 | else: |
2287 | 2368 | if mode == 'rs': |
2288 | 2369 | # NC_SHARE is very important for speed reading |
2289 | 2370 | # large netcdf3 files with a record dimension |
2290 | 2371 | # (pull request #902). |
2291 | ierr = nc_open(path, NC_NOWRITE | NC_SHARE, &grpid) | |
2372 | cmode = NC_NOWRITE | NC_SHARE | |
2373 | with nogil: | |
2374 | ierr = nc_open(path, cmode, &grpid) | |
2292 | 2375 | else: |
2293 | ierr = nc_open(path, NC_NOWRITE, &grpid) | |
2376 | with nogil: | |
2377 | ierr = nc_open(path, NC_NOWRITE, &grpid) | |
2294 | 2378 | elif mode in ['a','r+'] and os.path.exists(filename): |
2295 | 2379 | if parallel: |
2296 | 2380 | IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT: |
2297 | ierr = nc_open_par(path, NC_WRITE | NC_MPIIO, \ | |
2298 | mpicomm, mpiinfo, &grpid) | |
2381 | cmode = NC_WRITE | NC_MPIIO | |
2382 | with nogil: | |
2383 | ierr = nc_open_par(path, cmode, \ | |
2384 | mpicomm, mpiinfo, &grpid) | |
2299 | 2385 | ELSE: |
2300 | 2386 | pass |
2301 | 2387 | elif diskless: |
2302 | ierr = nc_open(path, NC_WRITE | NC_DISKLESS, &grpid) | |
2388 | cmode = NC_WRITE | NC_DISKLESS | |
2389 | with nogil: | |
2390 | ierr = nc_open(path, cmode, &grpid) | |
2303 | 2391 | else: |
2304 | ierr = nc_open(path, NC_WRITE, &grpid) | |
2392 | with nogil: | |
2393 | ierr = nc_open(path, NC_WRITE, &grpid) | |
2305 | 2394 | elif mode in ['as','r+s'] and os.path.exists(filename): |
2306 | 2395 | if parallel: |
2307 | 2396 | # NC_SHARE ignored |
2308 | 2397 | IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT: |
2309 | ierr = nc_open_par(path, NC_WRITE | NC_MPIIO, \ | |
2310 | mpicomm, mpiinfo, &grpid) | |
2398 | cmode = NC_WRITE | NC_MPIIO | |
2399 | with nogil: | |
2400 | ierr = nc_open_par(path, cmode, \ | |
2401 | mpicomm, mpiinfo, &grpid) | |
2311 | 2402 | ELSE: |
2312 | 2403 | pass |
2313 | 2404 | elif diskless: |
2314 | ierr = nc_open(path, NC_SHARE | NC_DISKLESS, &grpid) | |
2405 | cmode = NC_SHARE | NC_DISKLESS | |
2406 | with nogil: | |
2407 | ierr = nc_open(path, cmode, &grpid) | |
2315 | 2408 | else: |
2316 | ierr = nc_open(path, NC_SHARE, &grpid) | |
2409 | with nogil: | |
2410 | ierr = nc_open(path, NC_SHARE, &grpid) | |
2317 | 2411 | elif mode == 'ws' or (mode in ['as','r+s'] and not os.path.exists(filename)): |
2318 | 2412 | _set_default_format(format=format) |
2319 | 2413 | if clobber: |
2320 | 2414 | if parallel: |
2321 | 2415 | # NC_SHARE ignored |
2322 | 2416 | IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT: |
2323 | ierr = nc_create_par(path, NC_CLOBBER | cmode, \ | |
2324 | mpicomm, mpiinfo, &grpid) | |
2417 | cmode = NC_CLOBBER | parmode | |
2418 | with nogil: | |
2419 | ierr = nc_create_par(path, NC_CLOBBER | cmode, \ | |
2420 | mpicomm, mpiinfo, &grpid) | |
2325 | 2421 | ELSE: |
2326 | 2422 | pass |
2327 | 2423 | elif diskless: |
2328 | 2424 | if persist: |
2329 | ierr = nc_create(path, NC_WRITE | NC_SHARE | NC_CLOBBER | NC_DISKLESS , &grpid) | |
2425 | cmode = NC_WRITE | NC_SHARE | NC_CLOBBER | NC_DISKLESS | |
2426 | with nogil: | |
2427 | ierr = nc_create(path, cmode, &grpid) | |
2330 | 2428 | else: |
2331 | ierr = nc_create(path, NC_SHARE | NC_CLOBBER | NC_DISKLESS , &grpid) | |
2429 | cmode = NC_SHARE | NC_CLOBBER | NC_DISKLESS | |
2430 | with nogil: | |
2431 | ierr = nc_create(path, cmode , &grpid) | |
2332 | 2432 | else: |
2333 | ierr = nc_create(path, NC_SHARE | NC_CLOBBER, &grpid) | |
2433 | cmode = NC_SHARE | NC_CLOBBER | |
2434 | with nogil: | |
2435 | ierr = nc_create(path, cmode, &grpid) | |
2334 | 2436 | else: |
2335 | 2437 | if parallel: |
2336 | 2438 | # NC_SHARE ignored |
2337 | 2439 | IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT: |
2338 | ierr = nc_create_par(path, NC_NOCLOBBER | cmode, \ | |
2339 | mpicomm, mpiinfo, &grpid) | |
2440 | cmode = NC_NOCLOBBER | parmode | |
2441 | with nogil: | |
2442 | ierr = nc_create_par(path, cmode, \ | |
2443 | mpicomm, mpiinfo, &grpid) | |
2340 | 2444 | ELSE: |
2341 | 2445 | pass |
2342 | 2446 | elif diskless: |
2343 | 2447 | if persist: |
2344 | ierr = nc_create(path, NC_WRITE | NC_SHARE | NC_NOCLOBBER | NC_DISKLESS , &grpid) | |
2448 | cmode = NC_WRITE | NC_SHARE | NC_NOCLOBBER | NC_DISKLESS | |
2449 | with nogil: | |
2450 | ierr = nc_create(path, cmode , &grpid) | |
2345 | 2451 | else: |
2346 | ierr = nc_create(path, NC_SHARE | NC_NOCLOBBER | NC_DISKLESS , &grpid) | |
2452 | cmode = NC_SHARE | NC_NOCLOBBER | NC_DISKLESS | |
2453 | with nogil: | |
2454 | ierr = nc_create(path, cmode , &grpid) | |
2347 | 2455 | else: |
2348 | ierr = nc_create(path, NC_SHARE | NC_NOCLOBBER, &grpid) | |
2456 | cmode = NC_SHARE | NC_NOCLOBBER | |
2457 | with nogil: | |
2458 | ierr = nc_create(path, cmode, &grpid) | |
2349 | 2459 | else: |
2350 | 2460 | raise ValueError("mode must be 'w', 'x', 'r', 'a' or 'r+', got '%s'" % mode) |
2351 | 2461 | |
2468 | 2578 | return '\n'.join(ncdump) |
2469 | 2579 | |
2470 | 2580 | def _close(self, check_err): |
2471 | cdef int ierr = nc_close(self._grpid) | |
2581 | cdef int ierr | |
2582 | with nogil: | |
2583 | ierr = nc_close(self._grpid) | |
2472 | 2584 | |
2473 | 2585 | if check_err: |
2474 | 2586 | _ensure_nc_success(ierr) |
2484 | 2596 | def _close_mem(self, check_err): |
2485 | 2597 | cdef int ierr |
2486 | 2598 | cdef NC_memio memio |
2487 | ierr = nc_close_memio(self._grpid, &memio) | |
2599 | with nogil: | |
2600 | ierr = nc_close_memio(self._grpid, &memio) | |
2488 | 2601 | |
2489 | 2602 | if check_err: |
2490 | 2603 | _ensure_nc_success(ierr) |
2533 | 2646 | **`sync(self)`** |
2534 | 2647 | |
2535 | 2648 | Writes all buffered data in the `Dataset` to the disk file.""" |
2536 | _ensure_nc_success(nc_sync(self._grpid)) | |
2649 | cdef int ierr | |
2650 | with nogil: | |
2651 | ierr = nc_sync(self._grpid) | |
2652 | _ensure_nc_success(ierr) | |
2537 | 2653 | |
2538 | 2654 | def _redef(self): |
2539 | 2655 | cdef int ierr |
2540 | ierr = nc_redef(self._grpid) | |
2656 | with nogil: | |
2657 | ierr = nc_redef(self._grpid) | |
2541 | 2658 | |
2542 | 2659 | def _enddef(self): |
2543 | 2660 | cdef int ierr |
2544 | ierr = nc_enddef(self._grpid) | |
2661 | with nogil: | |
2662 | ierr = nc_enddef(self._grpid) | |
2545 | 2663 | |
2546 | 2664 | def set_fill_on(self): |
2547 | 2665 | """ |
2556 | 2674 | library corresponds to `set_fill_on`. Data which are equal to the |
2557 | 2675 | `_Fill_Value` indicate that the variable was created, but never written |
2558 | 2676 | to.""" |
2559 | cdef int oldmode | |
2560 | _ensure_nc_success(nc_set_fill(self._grpid, NC_FILL, &oldmode)) | |
2677 | cdef int oldmode, ierr | |
2678 | with nogil: | |
2679 | ierr = nc_set_fill(self._grpid, NC_FILL, &oldmode) | |
2680 | _ensure_nc_success(ierr) | |
2561 | 2681 | |
2562 | 2682 | def set_fill_off(self): |
2563 | 2683 | """ |
2568 | 2688 | This will prevent the data from being pre-filled with fill values, which |
2569 | 2689 | may result in some performance improvements. However, you must then make |
2570 | 2690 | sure the data is actually written before being read.""" |
2571 | cdef int oldmode | |
2572 | _ensure_nc_success(nc_set_fill(self._grpid, NC_NOFILL, &oldmode)) | |
2691 | cdef int oldmode, ierr | |
2692 | with nogil: | |
2693 | ierr = nc_set_fill(self._grpid, NC_NOFILL, &oldmode) | |
2694 | _ensure_nc_success(ierr) | |
2573 | 2695 | |
2574 | 2696 | def createDimension(self, dimname, size=None): |
2575 | 2697 | """ |
2593 | 2715 | |
2594 | 2716 | rename a `Dimension` named `oldname` to `newname`.""" |
2595 | 2717 | cdef char *namstring |
2718 | cdef Dimension dim | |
2596 | 2719 | bytestr = _strencode(newname) |
2597 | 2720 | namstring = bytestr |
2598 | 2721 | if self.data_model != 'NETCDF4': self._redef() |
2600 | 2723 | dim = self.dimensions[oldname] |
2601 | 2724 | except KeyError: |
2602 | 2725 | raise KeyError('%s not a valid dimension name' % oldname) |
2603 | ierr = nc_rename_dim(self._grpid, dim._dimid, namstring) | |
2726 | with nogil: | |
2727 | ierr = nc_rename_dim(self._grpid, dim._dimid, namstring) | |
2604 | 2728 | if self.data_model != 'NETCDF4': self._enddef() |
2605 | 2729 | |
2606 | 2730 | _ensure_nc_success(ierr) |
2849 | 2973 | |
2850 | 2974 | rename a `Variable` named `oldname` to `newname`""" |
2851 | 2975 | cdef char *namstring |
2976 | cdef Variable var | |
2852 | 2977 | try: |
2853 | 2978 | var = self.variables[oldname] |
2854 | 2979 | except KeyError: |
2856 | 2981 | bytestr = _strencode(newname) |
2857 | 2982 | namstring = bytestr |
2858 | 2983 | if self.data_model != 'NETCDF4': self._redef() |
2859 | ierr = nc_rename_var(self._grpid, var._varid, namstring) | |
2984 | with nogil: | |
2985 | ierr = nc_rename_var(self._grpid, var._varid, namstring) | |
2860 | 2986 | if self.data_model != 'NETCDF4': self._enddef() |
2861 | 2987 | |
2862 | 2988 | _ensure_nc_success(ierr) |
2974 | 3100 | bytestr = _strencode(name) |
2975 | 3101 | attname = bytestr |
2976 | 3102 | if self.data_model != 'NETCDF4': self._redef() |
2977 | ierr = nc_del_att(self._grpid, NC_GLOBAL, attname) | |
3103 | with nogil: | |
3104 | ierr = nc_del_att(self._grpid, NC_GLOBAL, attname) | |
2978 | 3105 | if self.data_model != 'NETCDF4': self._enddef() |
2979 | 3106 | _ensure_nc_success(ierr) |
2980 | 3107 | |
3019 | 3146 | rename a `Dataset` or `Group` attribute named `oldname` to `newname`.""" |
3020 | 3147 | cdef char *oldnamec |
3021 | 3148 | cdef char *newnamec |
3149 | cdef int ierr | |
3022 | 3150 | bytestr = _strencode(oldname) |
3023 | 3151 | oldnamec = bytestr |
3024 | 3152 | bytestr = _strencode(newname) |
3025 | 3153 | newnamec = bytestr |
3026 | _ensure_nc_success(nc_rename_att(self._grpid, NC_GLOBAL, oldnamec, newnamec)) | |
3154 | with nogil: | |
3155 | ierr = nc_rename_att(self._grpid, NC_GLOBAL, oldnamec, newnamec) | |
3156 | _ensure_nc_success(ierr) | |
3027 | 3157 | |
3028 | 3158 | def renameGroup(self, oldname, newname): |
3029 | 3159 | """ |
3031 | 3161 | |
3032 | 3162 | rename a `Group` named `oldname` to `newname` (requires netcdf >= 4.3.1).""" |
3033 | 3163 | cdef char *newnamec |
3164 | cdef int grpid | |
3034 | 3165 | IF HAS_RENAME_GRP: |
3166 | cdef int ierr | |
3035 | 3167 | bytestr = _strencode(newname) |
3036 | 3168 | newnamec = bytestr |
3037 | 3169 | try: |
3038 | 3170 | grp = self.groups[oldname] |
3171 | grpid = grp._grpid | |
3039 | 3172 | except KeyError: |
3040 | 3173 | raise KeyError('%s not a valid group name' % oldname) |
3041 | _ensure_nc_success(nc_rename_grp(grp._grpid, newnamec)) | |
3174 | with nogil: | |
3175 | ierr = nc_rename_grp(grpid, newnamec) | |
3176 | _ensure_nc_success(ierr) | |
3042 | 3177 | # remove old key from groups dict. |
3043 | 3178 | self.groups.pop(oldname) |
3044 | 3179 | # add new key. |
3360 | 3495 | f = open(outfile,'w') |
3361 | 3496 | f.write(result.stdout) |
3362 | 3497 | f.close() |
3498 | def has_blosc_filter(self): | |
3499 | """ | |
3500 | **`has_blosc_filter(self)`** | |
3501 | returns True if blosc compression filter is available""" | |
3502 | cdef int ierr | |
3503 | IF HAS_BLOSC_SUPPORT: | |
3504 | with nogil: | |
3505 | ierr = nc_inq_filter_avail(self._grpid, H5Z_FILTER_BLOSC) | |
3506 | if ierr: | |
3507 | return False | |
3508 | else: | |
3509 | return True | |
3510 | ELSE: | |
3511 | return False | |
3512 | def has_zstd_filter(self): | |
3513 | """ | |
3514 | **`has_zstd_filter(self)`** | |
3515 | returns True if zstd compression filter is available""" | |
3516 | cdef int ierr | |
3517 | IF HAS_ZSTANDARD_SUPPORT: | |
3518 | with nogil: | |
3519 | ierr = nc_inq_filter_avail(self._grpid, H5Z_FILTER_ZSTD) | |
3520 | if ierr: | |
3521 | return False | |
3522 | else: | |
3523 | return True | |
3524 | ELSE: | |
3525 | return False | |
3526 | def has_bzip2_filter(self): | |
3527 | """ | |
3528 | **`has_bzip2_filter(self)`** | |
3529 | returns True if bzip2 compression filter is available""" | |
3530 | cdef int ierr | |
3531 | IF HAS_BZIP2_SUPPORT: | |
3532 | with nogil: | |
3533 | ierr = nc_inq_filter_avail(self._grpid, H5Z_FILTER_BZIP2) | |
3534 | if ierr: | |
3535 | return False | |
3536 | else: | |
3537 | return True | |
3538 | ELSE: | |
3539 | return False | |
3540 | def has_szip_filter(self): | |
3541 | """ | |
3542 | **`has_szip_filter(self)`** | |
3543 | returns True if szip compression filter is available""" | |
3544 | cdef int ierr | |
3545 | IF HAS_SZIP_SUPPORT: | |
3546 | with nogil: | |
3547 | ierr = nc_inq_filter_avail(self._grpid, H5Z_FILTER_SZIP) | |
3548 | if ierr: | |
3549 | return False | |
3550 | else: | |
3551 | return True | |
3552 | ELSE: | |
3553 | return False | |
3363 | 3554 | |
3364 | 3555 | cdef class Group(Dataset): |
3365 | 3556 | """ |
3392 | 3583 | another `Group` instance, not using this class directly. |
3393 | 3584 | """ |
3394 | 3585 | cdef char *groupname |
3586 | cdef int ierr, grpid | |
3395 | 3587 | # flag to indicate that Variables in this Group support orthogonal indexing. |
3396 | 3588 | self.__orthogonal_indexing__ = True |
3397 | 3589 | # set data_model and file_format attributes. |
3418 | 3610 | else: |
3419 | 3611 | bytestr = _strencode(name) |
3420 | 3612 | groupname = bytestr |
3421 | _ensure_nc_success(nc_def_grp(parent._grpid, groupname, &self._grpid)) | |
3613 | grpid = parent._grpid | |
3614 | with nogil: | |
3615 | ierr = nc_def_grp(grpid, groupname, &self._grpid) | |
3616 | _ensure_nc_success(ierr) | |
3422 | 3617 | if sys.version_info[0:2] < (3, 7): |
3423 | 3618 | self.cmptypes = OrderedDict() |
3424 | 3619 | self.vltypes = OrderedDict() |
3503 | 3698 | else: |
3504 | 3699 | lendim = NC_UNLIMITED |
3505 | 3700 | if grp.data_model != 'NETCDF4': grp._redef() |
3506 | ierr = nc_def_dim(self._grpid, dimname, lendim, &self._dimid) | |
3701 | with nogil: | |
3702 | ierr = nc_def_dim(self._grpid, dimname, lendim, &self._dimid) | |
3507 | 3703 | if grp.data_model != 'NETCDF4': grp._enddef() |
3508 | 3704 | _ensure_nc_success(ierr) |
3509 | 3705 | |
3568 | 3764 | cdef int ierr, n, numunlimdims, ndims, nvars, ngatts, xdimid |
3569 | 3765 | cdef int *unlimdimids |
3570 | 3766 | if self._data_model == 'NETCDF4': |
3571 | ierr = nc_inq_unlimdims(self._grpid, &numunlimdims, NULL) | |
3767 | with nogil: | |
3768 | ierr = nc_inq_unlimdims(self._grpid, &numunlimdims, NULL) | |
3572 | 3769 | _ensure_nc_success(ierr) |
3573 | 3770 | if numunlimdims == 0: |
3574 | 3771 | return False |
3930 | 4127 | self._vltype = datatype |
3931 | 4128 | xtype = datatype._nc_type |
3932 | 4129 | # make sure this a valid user defined datatype defined in this Group |
3933 | ierr = nc_inq_type(self._grpid, xtype, namstring, NULL) | |
4130 | with nogil: | |
4131 | ierr = nc_inq_type(self._grpid, xtype, namstring, NULL) | |
3934 | 4132 | _ensure_nc_success(ierr) |
3935 | 4133 | # dtype variable attribute is a numpy datatype object. |
3936 | 4134 | self.dtype = datatype.dtype |
3960 | 4158 | if grp.data_model != 'NETCDF4': grp._redef() |
3961 | 4159 | # define variable. |
3962 | 4160 | if ndims: |
3963 | ierr = nc_def_var(self._grpid, varname, xtype, ndims, | |
3964 | dimids, &self._varid) | |
4161 | with nogil: | |
4162 | ierr = nc_def_var(self._grpid, varname, xtype, ndims, | |
4163 | dimids, &self._varid) | |
3965 | 4164 | free(dimids) |
3966 | 4165 | else: # a scalar variable. |
3967 | ierr = nc_def_var(self._grpid, varname, xtype, ndims, | |
3968 | NULL, &self._varid) | |
4166 | with nogil: | |
4167 | ierr = nc_def_var(self._grpid, varname, xtype, ndims, | |
4168 | NULL, &self._varid) | |
3969 | 4169 | # set chunk cache size if desired |
3970 | 4170 | # default is 1mb per var, can cause problems when many (1000's) |
3971 | 4171 | # of vars are created. This change only lasts as long as file is |
3972 | 4172 | # open. |
3973 | 4173 | if grp.data_model.startswith('NETCDF4') and chunk_cache is not None: |
3974 | ierr = nc_get_var_chunk_cache(self._grpid, self._varid, &sizep, | |
3975 | &nelemsp, &preemptionp) | |
4174 | with nogil: | |
4175 | ierr = nc_get_var_chunk_cache(self._grpid, self._varid, &sizep, | |
4176 | &nelemsp, &preemptionp) | |
3976 | 4177 | _ensure_nc_success(ierr) |
3977 | 4178 | # reset chunk cache size, leave other parameters unchanged. |
3978 | 4179 | sizep = chunk_cache |
3979 | ierr = nc_set_var_chunk_cache(self._grpid, self._varid, sizep, | |
3980 | nelemsp, preemptionp) | |
4180 | with nogil: | |
4181 | ierr = nc_set_var_chunk_cache(self._grpid, self._varid, sizep, | |
4182 | nelemsp, preemptionp) | |
3981 | 4183 | _ensure_nc_success(ierr) |
3982 | 4184 | if ierr != NC_NOERR: |
3983 | 4185 | if grp.data_model != 'NETCDF4': grp._enddef() |
3994 | 4196 | if zlib: |
3995 | 4197 | icomplevel = complevel |
3996 | 4198 | if shuffle: |
3997 | ierr = nc_def_var_deflate(self._grpid, self._varid, 1, 1, icomplevel) | |
4199 | with nogil: | |
4200 | ierr = nc_def_var_deflate(self._grpid, self._varid, 1, 1, icomplevel) | |
3998 | 4201 | else: |
3999 | ierr = nc_def_var_deflate(self._grpid, self._varid, 0, 1, icomplevel) | |
4202 | with nogil: | |
4203 | ierr = nc_def_var_deflate(self._grpid, self._varid, 0, 1, icomplevel) | |
4000 | 4204 | if ierr != NC_NOERR: |
4001 | 4205 | if grp.data_model != 'NETCDF4': grp._enddef() |
4002 | 4206 | _ensure_nc_success(ierr) |
4008 | 4212 | msg="unknown szip coding ('ec' or 'nn' supported)" |
4009 | 4213 | raise ValueError(msg) |
4010 | 4214 | iszip_pixels_per_block = szip_pixels_per_block |
4011 | ierr = nc_def_var_szip(self._grpid, self._varid, iszip_coding, iszip_pixels_per_block) | |
4215 | with nogil: | |
4216 | ierr = nc_def_var_szip(self._grpid, self._varid, iszip_coding, iszip_pixels_per_block) | |
4012 | 4217 | if ierr != NC_NOERR: |
4013 | 4218 | if grp.data_model != 'NETCDF4': grp._enddef() |
4014 | 4219 | _ensure_nc_success(ierr) |
4019 | 4224 | if zstd: |
4020 | 4225 | IF HAS_ZSTANDARD_SUPPORT: |
4021 | 4226 | icomplevel = complevel |
4022 | ierr = nc_def_var_zstandard(self._grpid, self._varid, icomplevel) | |
4227 | with nogil: | |
4228 | ierr = nc_def_var_zstandard(self._grpid, self._varid, icomplevel) | |
4023 | 4229 | if ierr != NC_NOERR: |
4024 | 4230 | if grp.data_model != 'NETCDF4': grp._enddef() |
4025 | 4231 | _ensure_nc_success(ierr) |
4031 | 4237 | if bzip2: |
4032 | 4238 | IF HAS_BZIP2_SUPPORT: |
4033 | 4239 | icomplevel = complevel |
4034 | ierr = nc_def_var_bzip2(self._grpid, self._varid, icomplevel) | |
4240 | with nogil: | |
4241 | ierr = nc_def_var_bzip2(self._grpid, self._varid, icomplevel) | |
4035 | 4242 | if ierr != NC_NOERR: |
4036 | 4243 | if grp.data_model != 'NETCDF4': grp._enddef() |
4037 | 4244 | _ensure_nc_success(ierr) |
4046 | 4253 | iblosc_shuffle = blosc_shuffle |
4047 | 4254 | iblosc_blocksize = 0 # not currently used by c lib |
4048 | 4255 | iblosc_complevel = complevel |
4049 | ierr = nc_def_var_blosc(self._grpid, self._varid,\ | |
4256 | with nogil: | |
4257 | ierr = nc_def_var_blosc(self._grpid, self._varid,\ | |
4050 | 4258 | iblosc_compressor,\ |
4051 | 4259 | iblosc_complevel,iblosc_blocksize,\ |
4052 | 4260 | iblosc_shuffle) |
4060 | 4268 | raise ValueError(msg) |
4061 | 4269 | # set checksum. |
4062 | 4270 | if fletcher32 and ndims: # don't bother for scalar variable |
4063 | ierr = nc_def_var_fletcher32(self._grpid, self._varid, 1) | |
4271 | with nogil: | |
4272 | ierr = nc_def_var_fletcher32(self._grpid, self._varid, 1) | |
4064 | 4273 | if ierr != NC_NOERR: |
4065 | 4274 | if grp.data_model != 'NETCDF4': grp._enddef() |
4066 | 4275 | _ensure_nc_success(ierr) |
4086 | 4295 | raise ValueError(msg) |
4087 | 4296 | chunksizesp[n] = chunksizes[n] |
4088 | 4297 | if chunksizes is not None or contiguous: |
4089 | ierr = nc_def_var_chunking(self._grpid, self._varid, icontiguous, chunksizesp) | |
4298 | with nogil: | |
4299 | ierr = nc_def_var_chunking(self._grpid, self._varid, icontiguous, chunksizesp) | |
4090 | 4300 | free(chunksizesp) |
4091 | 4301 | if ierr != NC_NOERR: |
4092 | 4302 | if grp.data_model != 'NETCDF4': grp._enddef() |
4093 | 4303 | _ensure_nc_success(ierr) |
4094 | 4304 | # set endian-ness of variable |
4095 | 4305 | if endian == 'little': |
4096 | ierr = nc_def_var_endian(self._grpid, self._varid, NC_ENDIAN_LITTLE) | |
4306 | with nogil: | |
4307 | ierr = nc_def_var_endian(self._grpid, self._varid, NC_ENDIAN_LITTLE) | |
4097 | 4308 | elif endian == 'big': |
4098 | ierr = nc_def_var_endian(self._grpid, self._varid, NC_ENDIAN_BIG) | |
4309 | with nogil: | |
4310 | ierr = nc_def_var_endian(self._grpid, self._varid, NC_ENDIAN_BIG) | |
4099 | 4311 | elif endian == 'native': |
4100 | 4312 | pass # this is the default format. |
4101 | 4313 | else: |
4105 | 4317 | if significant_digits is not None: |
4106 | 4318 | nsd = significant_digits |
4107 | 4319 | if quantize_mode == 'BitGroom': |
4108 | ierr = nc_def_var_quantize(self._grpid, | |
4109 | self._varid, NC_QUANTIZE_BITGROOM, nsd) | |
4320 | with nogil: | |
4321 | ierr = nc_def_var_quantize(self._grpid, | |
4322 | self._varid, NC_QUANTIZE_BITGROOM, nsd) | |
4110 | 4323 | elif quantize_mode == 'GranularBitRound': |
4111 | ierr = nc_def_var_quantize(self._grpid, | |
4112 | self._varid, NC_QUANTIZE_GRANULARBR, nsd) | |
4324 | with nogil: | |
4325 | ierr = nc_def_var_quantize(self._grpid, | |
4326 | self._varid, NC_QUANTIZE_GRANULARBR, nsd) | |
4113 | 4327 | elif quantize_mode == 'BitRound': |
4114 | 4328 | ierr = nc_def_var_quantize(self._grpid, |
4115 | self._varid, NC_QUANTIZE_BITROUND, nsd) | |
4329 | self._varid, NC_QUANTIZE_BITROUND, nsd) | |
4116 | 4330 | else: |
4117 | 4331 | raise ValueError("'quantize_mode' keyword argument must be 'BitGroom','GranularBitRound' or 'BitRound', got '%s'" % quantize_mode) |
4118 | 4332 | |
4141 | 4355 | # anyway. |
4142 | 4356 | ierr = 0 |
4143 | 4357 | else: |
4144 | ierr = nc_def_var_fill(self._grpid, self._varid, 1, NULL) | |
4358 | with nogil: | |
4359 | ierr = nc_def_var_fill(self._grpid, self._varid, 1, NULL) | |
4145 | 4360 | if ierr != NC_NOERR: |
4146 | 4361 | if grp.data_model != 'NETCDF4': grp._enddef() |
4147 | 4362 | _ensure_nc_success(ierr) |
4430 | 4645 | bytestr = _strencode(name) |
4431 | 4646 | attname = bytestr |
4432 | 4647 | if self._grp.data_model != 'NETCDF4': self._grp._redef() |
4433 | ierr = nc_del_att(self._grpid, self._varid, attname) | |
4648 | with nogil: | |
4649 | ierr = nc_del_att(self._grpid, self._varid, attname) | |
4434 | 4650 | if self._grp.data_model != 'NETCDF4': self._grp._enddef() |
4435 | 4651 | _ensure_nc_success(ierr) |
4436 | 4652 | |
4439 | 4655 | **`filters(self)`** |
4440 | 4656 | |
4441 | 4657 | return dictionary containing HDF5 filter parameters.""" |
4442 | cdef int ierr,ideflate,ishuffle,icomplevel,icomplevel_zstd,icomplevel_bzip2,ifletcher32 | |
4658 | cdef int ierr,ideflate,ishuffle,icomplevel,ifletcher32 | |
4443 | 4659 | cdef int izstd=0 |
4444 | 4660 | cdef int ibzip2=0 |
4445 | 4661 | cdef int iblosc=0 |
4446 | 4662 | cdef int iszip=0 |
4447 | cdef unsigned int iblosc_complevel,iblosc_blocksize,iblosc_compressor,iblosc_shuffle | |
4448 | cdef int iszip_coding, iszip_pixels_per_block | |
4663 | cdef int iszip_coding=0 | |
4664 | cdef int iszip_pixels_per_block=0 | |
4665 | cdef int icomplevel_zstd=0 | |
4666 | cdef int icomplevel_bzip2=0 | |
4667 | cdef unsigned int iblosc_shuffle=0 | |
4668 | cdef unsigned int iblosc_compressor=0 | |
4669 | cdef unsigned int iblosc_blocksize=0 | |
4670 | cdef unsigned int iblosc_complevel=0 | |
4449 | 4671 | filtdict = {'zlib':False,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':False,'complevel':0,'fletcher32':False} |
4450 | 4672 | if self._grp.data_model not in ['NETCDF4_CLASSIC','NETCDF4']: return |
4451 | 4673 | with nogil: |
4455 | 4677 | ierr = nc_inq_var_fletcher32(self._grpid, self._varid, &ifletcher32) |
4456 | 4678 | _ensure_nc_success(ierr) |
4457 | 4679 | IF HAS_ZSTANDARD_SUPPORT: |
4458 | ierr = nc_inq_var_zstandard(self._grpid, self._varid, &izstd,\ | |
4459 | &icomplevel_zstd) | |
4680 | with nogil: | |
4681 | ierr = nc_inq_var_zstandard(self._grpid, self._varid, &izstd,\ | |
4682 | &icomplevel_zstd) | |
4460 | 4683 | if ierr != 0: izstd=0 |
4461 | 4684 | # _ensure_nc_success(ierr) |
4462 | 4685 | IF HAS_BZIP2_SUPPORT: |
4463 | ierr = nc_inq_var_bzip2(self._grpid, self._varid, &ibzip2,\ | |
4464 | &icomplevel_bzip2) | |
4686 | with nogil: | |
4687 | ierr = nc_inq_var_bzip2(self._grpid, self._varid, &ibzip2,\ | |
4688 | &icomplevel_bzip2) | |
4465 | 4689 | if ierr != 0: ibzip2=0 |
4466 | 4690 | #_ensure_nc_success(ierr) |
4467 | 4691 | IF HAS_BLOSC_SUPPORT: |
4468 | ierr = nc_inq_var_blosc(self._grpid, self._varid, &iblosc,\ | |
4469 | &iblosc_compressor,&iblosc_complevel,&iblosc_blocksize,&iblosc_shuffle) | |
4692 | with nogil: | |
4693 | ierr = nc_inq_var_blosc(self._grpid, self._varid, &iblosc,\ | |
4694 | &iblosc_compressor,&iblosc_complevel,&iblosc_blocksize,&iblosc_shuffle) | |
4470 | 4695 | if ierr != 0: iblosc=0 |
4471 | 4696 | #_ensure_nc_success(ierr) |
4472 | 4697 | IF HAS_SZIP_SUPPORT: |
4473 | ierr = nc_inq_var_szip(self._grpid, self._varid, &iszip_coding,\ | |
4474 | &iszip_pixels_per_block) | |
4698 | with nogil: | |
4699 | ierr = nc_inq_var_szip(self._grpid, self._varid, &iszip_coding,\ | |
4700 | &iszip_pixels_per_block) | |
4475 | 4701 | if ierr != 0: |
4476 | 4702 | iszip=0 |
4477 | 4703 | else: |
4617 | 4843 | preemptionp = preemption |
4618 | 4844 | else: |
4619 | 4845 | preemptionp = preemption_orig |
4620 | ierr = nc_set_var_chunk_cache(self._grpid, self._varid, sizep, | |
4621 | nelemsp, preemptionp) | |
4846 | with nogil: | |
4847 | ierr = nc_set_var_chunk_cache(self._grpid, self._varid, sizep, | |
4848 | nelemsp, preemptionp) | |
4622 | 4849 | _ensure_nc_success(ierr) |
4623 | 4850 | |
4624 | 4851 | def __delattr__(self,name): |
4701 | 4928 | oldnamec = bytestr |
4702 | 4929 | bytestr = _strencode(newname) |
4703 | 4930 | newnamec = bytestr |
4704 | ierr = nc_rename_att(self._grpid, self._varid, oldnamec, newnamec) | |
4931 | with nogil: | |
4932 | ierr = nc_rename_att(self._grpid, self._varid, oldnamec, newnamec) | |
4705 | 4933 | _ensure_nc_success(ierr) |
4706 | 4934 | |
4707 | 4935 | def __getitem__(self, elem): |
5105 | 5333 | encoding = getattr(self,'_Encoding','utf-8') |
5106 | 5334 | bytestr = _strencode(data,encoding=encoding) |
5107 | 5335 | strdata[0] = bytestr |
5108 | ierr = nc_put_vara(self._grpid, self._varid, | |
5109 | startp, countp, strdata) | |
5336 | with nogil: | |
5337 | ierr = nc_put_vara(self._grpid, self._varid, | |
5338 | startp, countp, strdata) | |
5110 | 5339 | _ensure_nc_success(ierr) |
5111 | 5340 | free(strdata) |
5112 | 5341 | else: # regular VLEN |
5116 | 5345 | vldata = <nc_vlen_t *>malloc(sizeof(nc_vlen_t)) |
5117 | 5346 | vldata[0].len = PyArray_SIZE(data2) |
5118 | 5347 | vldata[0].p = PyArray_DATA(data2) |
5119 | ierr = nc_put_vara(self._grpid, self._varid, | |
5120 | startp, countp, vldata) | |
5348 | with nogil: | |
5349 | ierr = nc_put_vara(self._grpid, self._varid, | |
5350 | startp, countp, vldata) | |
5121 | 5351 | _ensure_nc_success(ierr) |
5122 | 5352 | free(vldata) |
5123 | 5353 | free(startp) |
5555 | 5785 | data = data.byteswap() |
5556 | 5786 | # strides all 1 or scalar variable, use put_vara (faster) |
5557 | 5787 | if sum(stride) == ndims or ndims == 0: |
5558 | ierr = nc_put_vara(self._grpid, self._varid, | |
5559 | startp, countp, PyArray_DATA(data)) | |
5788 | with nogil: | |
5789 | ierr = nc_put_vara(self._grpid, self._varid, | |
5790 | startp, countp, PyArray_DATA(data)) | |
5560 | 5791 | else: |
5561 | ierr = nc_put_vars(self._grpid, self._varid, | |
5562 | startp, countp, stridep, PyArray_DATA(data)) | |
5792 | with nogil: | |
5793 | ierr = nc_put_vars(self._grpid, self._varid, | |
5794 | startp, countp, stridep, PyArray_DATA(data)) | |
5563 | 5795 | _ensure_nc_success(ierr) |
5564 | 5796 | elif self._isvlen: |
5565 | 5797 | if data.dtype.char !='O': |
5582 | 5814 | strdata[i] = data[i] |
5583 | 5815 | # strides all 1 or scalar variable, use put_vara (faster) |
5584 | 5816 | if sum(stride) == ndims or ndims == 0: |
5585 | ierr = nc_put_vara(self._grpid, self._varid, | |
5586 | startp, countp, strdata) | |
5817 | with nogil: | |
5818 | ierr = nc_put_vara(self._grpid, self._varid, | |
5819 | startp, countp, strdata) | |
5587 | 5820 | else: |
5588 | 5821 | raise IndexError('strides must all be 1 for string variables') |
5589 | #ierr = nc_put_vars(self._grpid, self._varid, | |
5590 | # startp, countp, stridep, strdata) | |
5822 | #with nogil: | |
5823 | # ierr = nc_put_vars(self._grpid, self._varid, | |
5824 | # startp, countp, stridep, strdata) | |
5591 | 5825 | _ensure_nc_success(ierr) |
5592 | 5826 | free(strdata) |
5593 | 5827 | else: |
5609 | 5843 | databuff = databuff + PyArray_STRIDES(data)[0] |
5610 | 5844 | # strides all 1 or scalar variable, use put_vara (faster) |
5611 | 5845 | if sum(stride) == ndims or ndims == 0: |
5612 | ierr = nc_put_vara(self._grpid, self._varid, | |
5613 | startp, countp, vldata) | |
5846 | with nogil: | |
5847 | ierr = nc_put_vara(self._grpid, self._varid, | |
5848 | startp, countp, vldata) | |
5614 | 5849 | else: |
5615 | 5850 | raise IndexError('strides must all be 1 for vlen variables') |
5616 | #ierr = nc_put_vars(self._grpid, self._varid, | |
5617 | # startp, countp, stridep, vldata) | |
5851 | #with nogil: | |
5852 | # ierr = nc_put_vars(self._grpid, self._varid, | |
5853 | # startp, countp, stridep, vldata) | |
5618 | 5854 | _ensure_nc_success(ierr) |
5619 | 5855 | # free the pointer array. |
5620 | 5856 | free(vldata) |
5624 | 5860 | |
5625 | 5861 | def _get(self,start,count,stride): |
5626 | 5862 | """Private method to retrieve data from a netCDF variable""" |
5627 | cdef int ierr, ndims | |
5863 | cdef int ierr, ndims, totelem | |
5628 | 5864 | cdef size_t *startp |
5629 | 5865 | cdef size_t *countp |
5630 | 5866 | cdef ptrdiff_t *stridep |
5703 | 5939 | else: |
5704 | 5940 | # FIXME: is this a bug in netCDF4? |
5705 | 5941 | raise IndexError('strides must all be 1 for string variables') |
5706 | #ierr = nc_get_vars(self._grpid, self._varid, | |
5707 | # startp, countp, stridep, strdata) | |
5942 | #with nogil: | |
5943 | # ierr = nc_get_vars(self._grpid, self._varid, | |
5944 | # startp, countp, stridep, strdata) | |
5708 | 5945 | if ierr == NC_EINVALCOORDS: |
5709 | 5946 | raise IndexError |
5710 | 5947 | elif ierr != NC_NOERR: |
5722 | 5959 | # reshape the output array |
5723 | 5960 | data = numpy.reshape(data, shapeout) |
5724 | 5961 | # free string data internally allocated in netcdf C lib |
5725 | ierr = nc_free_string(totelem, strdata) | |
5962 | with nogil: | |
5963 | ierr = nc_free_string(totelem, strdata) | |
5726 | 5964 | # free the pointer array |
5727 | 5965 | free(strdata) |
5728 | 5966 | else: |
5739 | 5977 | startp, countp, vldata) |
5740 | 5978 | else: |
5741 | 5979 | raise IndexError('strides must all be 1 for vlen variables') |
5742 | #ierr = nc_get_vars(self._grpid, self._varid, | |
5743 | # startp, countp, stridep, vldata) | |
5980 | #with nogil: | |
5981 | # ierr = nc_get_vars(self._grpid, self._varid, | |
5982 | # startp, countp, stridep, vldata) | |
5744 | 5983 | if ierr == NC_EINVALCOORDS: |
5745 | 5984 | raise IndexError |
5746 | 5985 | elif ierr != NC_NOERR: |
5756 | 5995 | # reshape the output array |
5757 | 5996 | data = numpy.reshape(data, shapeout) |
5758 | 5997 | # free vlen data internally allocated in netcdf C lib |
5759 | ierr = nc_free_vlens(totelem, vldata) | |
5998 | with nogil: | |
5999 | ierr = nc_free_vlens(totelem, vldata) | |
5760 | 6000 | # free the pointer array |
5761 | 6001 | free(vldata) |
5762 | 6002 | free(startp) |
5789 | 6029 | IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT: |
5790 | 6030 | # set collective MPI IO mode on or off |
5791 | 6031 | if value: |
5792 | ierr = nc_var_par_access(self._grpid, self._varid, | |
5793 | NC_COLLECTIVE) | |
6032 | with nogil: | |
6033 | ierr = nc_var_par_access(self._grpid, self._varid, | |
6034 | NC_COLLECTIVE) | |
5794 | 6035 | else: |
5795 | ierr = nc_var_par_access(self._grpid, self._varid, | |
5796 | NC_INDEPENDENT) | |
6036 | with nogil: | |
6037 | ierr = nc_var_par_access(self._grpid, self._varid, | |
6038 | NC_INDEPENDENT) | |
5797 | 6039 | _ensure_nc_success(ierr) |
5798 | 6040 | ELSE: |
5799 | 6041 | pass # does nothing |
5941 | 6183 | # private function used to construct a netcdf compound data type |
5942 | 6184 | # from a numpy dtype object by CompoundType.__init__. |
5943 | 6185 | cdef nc_type xtype, xtype_tmp |
5944 | cdef int ierr, ndims | |
6186 | cdef int ierr, ndims, grpid | |
5945 | 6187 | cdef size_t offset, size |
5946 | 6188 | cdef char *namstring |
5947 | 6189 | cdef char *nested_namstring |
5949 | 6191 | bytestr = _strencode(dtype_name) |
5950 | 6192 | namstring = bytestr |
5951 | 6193 | size = dt.itemsize |
5952 | ierr = nc_def_compound(grp._grpid, size, namstring, &xtype) | |
6194 | grpid = grp._grpid | |
6195 | with nogil: | |
6196 | ierr = nc_def_compound(grpid, size, namstring, &xtype) | |
5953 | 6197 | _ensure_nc_success(ierr) |
5954 | 6198 | names = list(dt.fields.keys()) |
5955 | 6199 | formats = [v[0] for v in dt.fields.values()] |
5967 | 6211 | xtype_tmp = _nptonctype[format.str[1:]] |
5968 | 6212 | except KeyError: |
5969 | 6213 | raise ValueError('Unsupported compound type element') |
5970 | ierr = nc_insert_compound(grp._grpid, xtype, namstring, | |
5971 | offset, xtype_tmp) | |
6214 | with nogil: | |
6215 | ierr = nc_insert_compound(grpid, xtype, namstring, | |
6216 | offset, xtype_tmp) | |
5972 | 6217 | _ensure_nc_success(ierr) |
5973 | 6218 | else: |
5974 | 6219 | if format.shape == (): # nested scalar compound type |
5976 | 6221 | xtype_tmp = _find_cmptype(grp, format) |
5977 | 6222 | bytestr = _strencode(name) |
5978 | 6223 | nested_namstring = bytestr |
5979 | ierr = nc_insert_compound(grp._grpid, xtype,\ | |
5980 | nested_namstring,\ | |
5981 | offset, xtype_tmp) | |
6224 | with nogil: | |
6225 | ierr = nc_insert_compound(grpid, xtype,\ | |
6226 | nested_namstring,\ | |
6227 | offset, xtype_tmp) | |
5982 | 6228 | _ensure_nc_success(ierr) |
5983 | 6229 | else: # nested array compound element |
5984 | 6230 | ndims = len(format.shape) |
5990 | 6236 | xtype_tmp = _nptonctype[format.subdtype[0].str[1:]] |
5991 | 6237 | except KeyError: |
5992 | 6238 | raise ValueError('Unsupported compound type element') |
5993 | ierr = nc_insert_array_compound(grp._grpid,xtype,namstring, | |
6239 | with nogil: | |
6240 | ierr = nc_insert_array_compound(grpid,xtype,namstring, | |
5994 | 6241 | offset,xtype_tmp,ndims,dim_sizes) |
5995 | 6242 | _ensure_nc_success(ierr) |
5996 | 6243 | else: # nested array compound type. |
6001 | 6248 | # xtype_tmp = _find_cmptype(grp, format.subdtype[0]) |
6002 | 6249 | # bytestr = _strencode(name) |
6003 | 6250 | # nested_namstring = bytestr |
6004 | # ierr = nc_insert_array_compound(grp._grpid,xtype,\ | |
6005 | # nested_namstring,\ | |
6006 | # offset,xtype_tmp,\ | |
6007 | # ndims,dim_sizes) | |
6251 | # with nogil: | |
6252 | # ierr = nc_insert_array_compound(grpid,xtype,\ | |
6253 | # nested_namstring,\ | |
6254 | # offset,xtype_tmp,\ | |
6255 | # ndims,dim_sizes) | |
6008 | 6256 | # _ensure_nc_success(ierr) |
6009 | 6257 | free(dim_sizes) |
6010 | 6258 | return xtype |
6178 | 6426 | # private function used to construct a netcdf VLEN data type |
6179 | 6427 | # from a numpy dtype object or python str object by VLType.__init__. |
6180 | 6428 | cdef nc_type xtype, xtype_tmp |
6181 | cdef int ierr, ndims | |
6429 | cdef int ierr, ndims, grpid | |
6182 | 6430 | cdef size_t offset, size |
6183 | 6431 | cdef char *namstring |
6184 | 6432 | cdef char *nested_namstring |
6433 | grpid = grp._grpid | |
6185 | 6434 | if dt == str: # python string, use NC_STRING |
6186 | 6435 | xtype = NC_STRING |
6187 | 6436 | # dtype_name ignored |
6193 | 6442 | # find netCDF primitive data type corresponding to |
6194 | 6443 | # specified numpy data type. |
6195 | 6444 | xtype_tmp = _nptonctype[dt.str[1:]] |
6196 | ierr = nc_def_vlen(grp._grpid, namstring, xtype_tmp, &xtype); | |
6445 | with nogil: | |
6446 | ierr = nc_def_vlen(grpid, namstring, xtype_tmp, &xtype); | |
6197 | 6447 | _ensure_nc_success(ierr) |
6198 | 6448 | else: |
6199 | 6449 | raise KeyError("unsupported datatype specified for VLEN") |
6204 | 6454 | # construct a corresponding numpy dtype instance, |
6205 | 6455 | # then use that to create a VLType instance. |
6206 | 6456 | # called by _get_types, _get_vars. |
6207 | cdef int ierr, _grpid | |
6457 | cdef int ierr, grpid | |
6208 | 6458 | cdef size_t vlsize |
6209 | 6459 | cdef nc_type base_xtype |
6210 | 6460 | cdef char vl_namstring[NC_MAX_NAME+1] |
6211 | _grpid = group._grpid | |
6461 | grpid = group._grpid | |
6212 | 6462 | if xtype == NC_STRING: |
6213 | 6463 | dt = str |
6214 | 6464 | name = None |
6215 | 6465 | else: |
6216 | 6466 | with nogil: |
6217 | ierr = nc_inq_vlen(_grpid, xtype, vl_namstring, &vlsize, &base_xtype) | |
6467 | ierr = nc_inq_vlen(grpid, xtype, vl_namstring, &vlsize, &base_xtype) | |
6218 | 6468 | _ensure_nc_success(ierr) |
6219 | 6469 | name = vl_namstring.decode('utf-8') |
6220 | 6470 | try: |
6285 | 6535 | # private function used to construct a netCDF Enum data type |
6286 | 6536 | # from a numpy dtype object or python str object by EnumType.__init__. |
6287 | 6537 | cdef nc_type xtype, xtype_tmp |
6288 | cdef int ierr | |
6538 | cdef int ierr, grpid | |
6289 | 6539 | cdef char *namstring |
6290 | 6540 | cdef ndarray value_arr |
6291 | 6541 | bytestr = _strencode(dtype_name) |
6292 | 6542 | namstring = bytestr |
6543 | grpid = grp._grpid | |
6293 | 6544 | dt = numpy.dtype(dt) # convert to numpy datatype. |
6294 | 6545 | if dt.str[1:] in _intnptonctype.keys(): |
6295 | 6546 | # find netCDF primitive data type corresponding to |
6296 | 6547 | # specified numpy data type. |
6297 | 6548 | xtype_tmp = _intnptonctype[dt.str[1:]] |
6298 | ierr = nc_def_enum(grp._grpid, xtype_tmp, namstring, &xtype); | |
6549 | with nogil: | |
6550 | ierr = nc_def_enum(grpid, xtype_tmp, namstring, &xtype) | |
6299 | 6551 | _ensure_nc_success(ierr) |
6300 | 6552 | else: |
6301 | 6553 | msg="unsupported datatype specified for ENUM (must be integer)" |
6305 | 6557 | value_arr = numpy.array(enum_dict[field],dt) |
6306 | 6558 | bytestr = _strencode(field) |
6307 | 6559 | namstring = bytestr |
6308 | ierr = nc_insert_enum(grp._grpid, xtype, namstring, | |
6309 | PyArray_DATA(value_arr)) | |
6560 | with nogil: | |
6561 | ierr = nc_insert_enum(grpid, xtype, namstring, | |
6562 | PyArray_DATA(value_arr)) | |
6310 | 6563 | _ensure_nc_success(ierr) |
6311 | 6564 | return xtype, dt |
6312 | 6565 | |
6315 | 6568 | # construct a corresponding numpy dtype instance, |
6316 | 6569 | # then use that to create a EnumType instance. |
6317 | 6570 | # called by _get_types, _get_vars. |
6318 | cdef int ierr, _grpid, nmem | |
6571 | cdef int ierr, grpid, nmem | |
6319 | 6572 | cdef ndarray enum_val |
6320 | 6573 | cdef nc_type base_xtype |
6321 | 6574 | cdef char enum_namstring[NC_MAX_NAME+1] |
6322 | 6575 | cdef size_t nmembers |
6323 | _grpid = group._grpid | |
6576 | grpid = group._grpid | |
6324 | 6577 | # get name, datatype, and number of members. |
6325 | 6578 | with nogil: |
6326 | ierr = nc_inq_enum(_grpid, xtype, enum_namstring, &base_xtype, NULL,\ | |
6579 | ierr = nc_inq_enum(grpid, xtype, enum_namstring, &base_xtype, NULL,\ | |
6327 | 6580 | &nmembers) |
6328 | 6581 | _ensure_nc_success(ierr) |
6329 | 6582 | enum_name = enum_namstring.decode('utf-8') |
6338 | 6591 | enum_val = numpy.empty(1,dt) |
6339 | 6592 | for nmem from 0 <= nmem < nmembers: |
6340 | 6593 | with nogil: |
6341 | ierr = nc_inq_enum_member(_grpid, xtype, nmem, \ | |
6594 | ierr = nc_inq_enum_member(grpid, xtype, nmem, \ | |
6342 | 6595 | enum_namstring,PyArray_DATA(enum_val)) |
6343 | 6596 | _ensure_nc_success(ierr) |
6344 | 6597 | name = enum_namstring.decode('utf-8') |
0 | import glob, os, sys, unittest, struct | |
1 | from netCDF4 import getlibversion,__hdf5libversion__,__netcdf4libversion__,__version__ | |
0 | import glob, os, sys, unittest, struct, tempfile | |
1 | from netCDF4 import getlibversion,__hdf5libversion__,__netcdf4libversion__,__version__, Dataset | |
2 | 2 | from netCDF4 import __has_cdf5_format__, __has_nc_inq_path__, __has_nc_create_mem__, \ |
3 | 3 | __has_parallel4_support__, __has_pnetcdf_support__, \ |
4 | 4 | __has_zstandard_support__, __has_bzip2_support__, \ |
25 | 25 | if not __has_quantization_support__: |
26 | 26 | test_files.remove('tst_compression_quant.py') |
27 | 27 | sys.stdout.write('not running tst_compression_quant.py ...\n') |
28 | if not __has_zstandard_support__ or os.getenv('NO_PLUGINS'): | |
28 | filename = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name | |
29 | nc = Dataset(filename,'w') | |
30 | if not __has_zstandard_support__ or os.getenv('NO_PLUGINS') or not nc.has_zstd_filter(): | |
29 | 31 | test_files.remove('tst_compression_zstd.py') |
30 | 32 | sys.stdout.write('not running tst_compression_zstd.py ...\n') |
31 | if not __has_bzip2_support__ or os.getenv('NO_PLUGINS'): | |
33 | if not __has_bzip2_support__ or os.getenv('NO_PLUGINS') or not nc.has_bzip2_filter(): | |
32 | 34 | test_files.remove('tst_compression_bzip2.py') |
33 | 35 | sys.stdout.write('not running tst_compression_bzip2.py ...\n') |
34 | if not __has_blosc_support__ or os.getenv('NO_PLUGINS'): | |
36 | if not __has_blosc_support__ or os.getenv('NO_PLUGINS') or not nc.has_blosc_filter(): | |
35 | 37 | test_files.remove('tst_compression_blosc.py') |
36 | 38 | sys.stdout.write('not running tst_compression_blosc.py ...\n') |
37 | if not __has_szip_support__: | |
39 | if not __has_szip_support__ or not nc.has_szip_filter(): | |
38 | 40 | test_files.remove('tst_compression_szip.py') |
39 | 41 | sys.stdout.write('not running tst_compression_szip.py ...\n') |
42 | nc.close() | |
43 | os.remove(filename) | |
40 | 44 | |
41 | 45 | # Don't run tests that require network connectivity |
42 | 46 | if os.getenv('NO_NET'): |
0 | import numpy as np | |
1 | from netCDF4 import set_alignment, get_alignment, Dataset | |
2 | import netCDF4 | |
3 | import os | |
4 | import subprocess | |
5 | import tempfile | |
6 | import unittest | |
7 | ||
8 | # During testing, sometimes development versions are used. | |
9 | # They may be written as 4.9.1-development | |
10 | libversion_no_development = netCDF4.__netcdf4libversion__.split('-')[0] | |
11 | libversion = tuple(int(v) for v in libversion_no_development.split('.')) | |
12 | has_alignment = (libversion[0] > 4) or ( | |
13 | libversion[0] == 4 and (libversion[1] >= 9) | |
14 | ) | |
15 | try: | |
16 | has_h5ls = subprocess.check_call(['h5ls', '--version'], stdout=subprocess.PIPE) == 0 | |
17 | except Exception: | |
18 | has_h5ls = False | |
19 | ||
20 | file_name = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name | |
21 | ||
22 | ||
23 | class AlignmentTestCase(unittest.TestCase): | |
24 | def setUp(self): | |
25 | self.file = file_name | |
26 | ||
27 | # This is a global variable in netcdf4, it must be set before File | |
28 | # creation | |
29 | if has_alignment: | |
30 | set_alignment(1024, 4096) | |
31 | assert get_alignment() == (1024, 4096) | |
32 | ||
33 | f = Dataset(self.file, 'w') | |
34 | f.createDimension('x', 4096) | |
35 | # Create many datasets so that we decrease the chance of | |
36 | # the dataset being randomly aligned | |
37 | for i in range(10): | |
38 | f.createVariable(f'data{i:02d}', np.float64, ('x',)) | |
39 | v = f.variables[f'data{i:02d}'] | |
40 | v[...] = 0 | |
41 | f.close() | |
42 | if has_alignment: | |
43 | # ensure to reset the alignment to 1 (default values) so as not to | |
44 | # disrupt other tests | |
45 | set_alignment(1, 1) | |
46 | assert get_alignment() == (1, 1) | |
47 | ||
48 | def test_version_settings(self): | |
49 | if has_alignment: | |
50 | # One should always be able to set the alignment to 1, 1 | |
51 | set_alignment(1, 1) | |
52 | assert get_alignment() == (1, 1) | |
53 | else: | |
54 | with self.assertRaises(RuntimeError): | |
55 | set_alignment(1, 1) | |
56 | with self.assertRaises(RuntimeError): | |
57 | get_alignment() | |
58 | ||
59 | # if we have no support for alignment, we have no guarantees on | |
60 | # how the data can be aligned | |
61 | @unittest.skipIf( | |
62 | not has_h5ls, | |
63 | "h5ls not found." | |
64 | ) | |
65 | @unittest.skipIf( | |
66 | not has_alignment, | |
67 | "No support for set_alignment in libnetcdf." | |
68 | ) | |
69 | def test_setting_alignment(self): | |
70 | # We choose to use h5ls instead of h5py since h5ls is very likely | |
71 | # to be installed alongside the rest of the tooling required to build | |
72 | # netcdf4-python | |
73 | # Output from h5ls is expected to look like: | |
74 | """ | |
75 | Opened "/tmp/tmpqexgozg1.nc" with sec2 driver. | |
76 | data00 Dataset {4096/4096} | |
77 | Attribute: DIMENSION_LIST {1} | |
78 | Type: variable length of | |
79 | object reference | |
80 | Attribute: _Netcdf4Coordinates {1} | |
81 | Type: 32-bit little-endian integer | |
82 | Location: 1:563 | |
83 | Links: 1 | |
84 | Storage: 32768 logical bytes, 32768 allocated bytes, 100.00% utilization | |
85 | Type: IEEE 64-bit little-endian float | |
86 | Address: 8192 | |
87 | data01 Dataset {4096/4096} | |
88 | Attribute: DIMENSION_LIST {1} | |
89 | Type: variable length of | |
90 | object reference | |
91 | Attribute: _Netcdf4Coordinates {1} | |
92 | Type: 32-bit little-endian integer | |
93 | Location: 1:1087 | |
94 | Links: 1 | |
95 | Storage: 32768 logical bytes, 32768 allocated bytes, 100.00% utilization | |
96 | Type: IEEE 64-bit little-endian float | |
97 | Address: 40960 | |
98 | [...] | |
99 | x Dataset {4096/4096} | |
100 | Attribute: CLASS scalar | |
101 | Type: 16-byte null-terminated ASCII string | |
102 | Attribute: NAME scalar | |
103 | Type: 64-byte null-terminated ASCII string | |
104 | Attribute: REFERENCE_LIST {10} | |
105 | Type: struct { | |
106 | "dataset" +0 object reference | |
107 | "dimension" +8 32-bit little-endian unsigned integer | |
108 | } 16 bytes | |
109 | Attribute: _Netcdf4Dimid scalar | |
110 | Type: 32-bit little-endian integer | |
111 | Location: 1:239 | |
112 | Links: 1 | |
113 | Storage: 16384 logical bytes, 0 allocated bytes | |
114 | Type: IEEE 32-bit big-endian float | |
115 | Address: 18446744073709551615 | |
116 | """ | |
117 | h5ls_results = subprocess.check_output( | |
118 | ["h5ls", "--verbose", "--address", "--simple", self.file] | |
119 | ).decode() | |
120 | ||
121 | addresses = { | |
122 | f'data{i:02d}': -1 | |
123 | for i in range(10) | |
124 | } | |
125 | ||
126 | data_variable = None | |
127 | for line in h5ls_results.split('\n'): | |
128 | if not line.startswith(' '): | |
129 | data_variable = line.split(' ')[0] | |
130 | # only process the data variables we care to inpsect | |
131 | if data_variable not in addresses: | |
132 | continue | |
133 | line = line.strip() | |
134 | if line.startswith('Address:'): | |
135 | address = int(line.split(':')[1].strip()) | |
136 | addresses[data_variable] = address | |
137 | ||
138 | for key, address in addresses.items(): | |
139 | is_aligned = (address % 4096) == 0 | |
140 | assert is_aligned, f"{key} is not aligned. Address = 0x{address:x}" | |
141 | ||
142 | # Alternative implementation in h5py | |
143 | # import h5py | |
144 | # with h5py.File(self.file, 'r') as h5file: | |
145 | # for i in range(10): | |
146 | # v = h5file[f'data{i:02d}'] | |
147 | # assert (dataset.id.get_offset() % 4096) == 0 | |
148 | ||
149 | def tearDown(self): | |
150 | # Remove the temporary files | |
151 | os.remove(self.file) | |
152 | ||
153 | ||
154 | if __name__ == '__main__': | |
155 | unittest.main() |
0 | 0 | from numpy.random.mtrand import uniform |
1 | 1 | from netCDF4 import Dataset |
2 | 2 | from numpy.testing import assert_almost_equal |
3 | import os, tempfile, unittest | |
3 | import os, tempfile, unittest, sys | |
4 | 4 | |
5 | 5 | ndim = 100000 |
6 | 6 | iblosc_shuffle=2 |
73 | 73 | f.close() |
74 | 74 | |
75 | 75 | if __name__ == '__main__': |
76 | unittest.main() | |
76 | nc = Dataset(filename,'w') | |
77 | if not nc.has_blosc_filter(): | |
78 | sys.stdout.write('blosc filter not available, skipping tests ...\n') | |
79 | else: | |
80 | nc.close() | |
81 | unittest.main() |
0 | 0 | from numpy.random.mtrand import uniform |
1 | 1 | from netCDF4 import Dataset |
2 | 2 | from numpy.testing import assert_almost_equal |
3 | import os, tempfile, unittest | |
3 | import os, tempfile, unittest, sys | |
4 | 4 | |
5 | 5 | ndim = 100000 |
6 | 6 | filename1 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name |
48 | 48 | f.close() |
49 | 49 | |
50 | 50 | if __name__ == '__main__': |
51 | unittest.main() | |
51 | nc = Dataset(filename1,'w') | |
52 | if not nc.has_bzip2_filter(): | |
53 | sys.stdout.write('bzip2 filter not available, skipping tests ...\n') | |
54 | else: | |
55 | nc.close() | |
56 | unittest.main() |
0 | 0 | from numpy.random.mtrand import uniform |
1 | 1 | from netCDF4 import Dataset |
2 | 2 | from numpy.testing import assert_almost_equal |
3 | import os, tempfile, unittest | |
3 | import os, tempfile, unittest, sys | |
4 | 4 | |
5 | 5 | ndim = 100000 |
6 | 6 | filename = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name |
38 | 38 | f.close() |
39 | 39 | |
40 | 40 | if __name__ == '__main__': |
41 | unittest.main() | |
41 | nc = Dataset(filename,'w') | |
42 | if not nc.has_szip_filter(): | |
43 | sys.stdout.write('szip filter not available, skipping tests ...\n') | |
44 | else: | |
45 | nc.close() | |
46 | unittest.main() |
0 | 0 | from numpy.random.mtrand import uniform |
1 | 1 | from netCDF4 import Dataset |
2 | 2 | from numpy.testing import assert_almost_equal |
3 | import os, tempfile, unittest | |
3 | import os, tempfile, unittest, sys | |
4 | 4 | |
5 | 5 | ndim = 100000 |
6 | 6 | filename1 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name |
48 | 48 | f.close() |
49 | 49 | |
50 | 50 | if __name__ == '__main__': |
51 | unittest.main() | |
51 | nc = Dataset(filename1,'w') | |
52 | if not nc.has_zstd_filter(): | |
53 | sys.stdout.write('zstd filter not available, skipping tests ...\n') | |
54 | else: | |
55 | nc.close() | |
56 | unittest.main() |