Codebase list netcdf4-python / 91a2224
New upstream version 1.6.1 Bas Couwenberg 1 year, 7 months ago
14 changed file(s) with 904 addition(s) and 612 deletion(s). Raw diff Collapse all Expand all
1717 exclude:
1818 - os: macos-latest
1919 platform: x32
20 fail-fast: false
21
2022 steps:
21 - uses: actions/checkout@v2
23 - uses: actions/checkout@v3
2224
23 - name: Setup Conda
24 uses: s-weigand/setup-conda@v1
25 - name: Setup Micromamba
26 uses: mamba-org/provision-with-micromamba@v13
2527 with:
26 activate-conda: false
27 conda-channels: conda-forge
28 environment-file: false
2829
2930 - name: Python ${{ matrix.python-version }}
3031 shell: bash -l {0}
3132 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
3435 export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH" # so setup.py finds nc-config
3536 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
3844
3945 - name: Tests
4046 shell: bash -l {0}
4147 run: |
42 source activate TEST
48 micromamba activate TEST
4349 cd test && python run_all.py
4450
4551 run-mpi:
5258 steps:
5359 - uses: actions/checkout@v2
5460
55 - name: Setup Conda
56 uses: s-weigand/setup-conda@v1
61 - name: Setup Micromamba
62 uses: mamba-org/provision-with-micromamba@main
5763 with:
58 activate-conda: false
59 conda-channels: conda-forge
64 environment-file: false
6065
6166 - name: Python ${{ matrix.python-version }}
6267 shell: bash -l {0}
6368 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
6671 export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH" # so setup.py finds nc-config
6772 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
7080
7181 - name: Tests
7282 shell: bash -l {0}
7383 run: |
74 source activate TEST
84 micromamba activate TEST
7585 cd test && python run_all.py
7686 cd ../examples
7787 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
08 version 1.6.0 (tag v1.6.0rel)
19 ==============================
210 * add support for new quantization functionality in netcdf-c 4.9.0 via "signficant_digits"
99 ## News
1010 For details on the latest updates, see the [Changelog](https://github.com/Unidata/netcdf4-python/blob/master/Changelog).
1111
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
1318 for quantization (bit-grooming and bit-rounding) functionality in netcdf-c 4.9.0 which can
1419 dramatically improve compression. Dataset.createVariable now accepts dimension instances (instead
1520 of just dimension names). 'compression' kwarg added to Dataset.createVariable to support szip as
2020
2121 <h2>Contents</h2>
2222 <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>
2424 </ul></li>
2525 <li><a href="#introduction">Introduction</a>
2626 <ul>
148148 </li>
149149 <li>
150150 <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>
151163 </li>
152164 <li>
153165 <a class="variable" href="#Dataset.name">name</a>
443455 <li>
444456 <a class="function" href="#set_chunk_cache">set_chunk_cache</a>
445457 </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>
446464 </ul>
447465
448466
459477 <h1 class="modulename">
460478 netCDF4 </h1>
461479
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>
463481
464482 <h1 id="introduction">Introduction</h1>
465483
520538 If the dependencies are not found
521539 in any of the paths specified by environment variables, then standard locations
522540 (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 &gt;= 4.9.0, they will be installed inside the package. In this
525543 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 &gt;= 4.9.0 will automatically
527545 be available. Otherwise, the user will have to set <code>HDF5_PLUGIN_PATH</code> explicitly
528546 to have access to the extra compression plugins.</li>
529547 <li>run <code>python setup.py build</code>, then <code>python setup.py install</code> (as root if
16231641 the parallel IO example, which is in <code>examples/mpi_example.py</code>.
16241642 Unit tests are in the <code>test</code> directory.</p>
16251643
1626 <p><strong>contact</strong>: Jeffrey Whitaker <a href="&#x6d;&#x61;&#105;&#108;&#x74;&#x6f;&#x3a;&#x6a;&#x65;&#102;&#102;&#114;e&#x79;&#46;&#x73;&#46;&#119;&#x68;&#x69;&#116;&#x61;&#x6b;&#101;&#x72;&#64;&#x6e;&#x6f;&#x61;&#x61;&#46;&#x67;o&#x76;">&#x6a;&#x65;&#102;&#102;&#114;e&#x79;&#46;&#x73;&#46;&#119;&#x68;&#x69;&#116;&#x61;&#x6b;&#101;&#x72;&#64;&#x6e;&#x6f;&#x61;&#x61;&#46;&#x67;o&#x76;</a></p>
1644 <p><strong>contact</strong>: Jeffrey Whitaker <a href="m&#97;&#105;&#108;&#x74;&#x6f;&#x3a;&#106;&#101;&#x66;&#102;r&#101;y&#x2e;&#x73;&#x2e;&#x77;&#x68;&#105;&#x74;&#x61;&#107;&#101;&#x72;&#64;&#x6e;&#111;&#x61;&#x61;&#46;&#x67;o&#x76;">&#106;&#101;&#x66;&#102;r&#101;y&#x2e;&#x73;&#x2e;&#x77;&#x68;&#105;&#x74;&#x61;&#107;&#101;&#x72;&#64;&#x6e;&#111;&#x61;&#x61;&#46;&#x67;o&#x76;</a></p>
16271645
16281646 <p><strong>copyright</strong>: 2008 by Jeffrey Whitaker.</p>
16291647
16501668 <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>
16511669 <span class="kn">import</span> <span class="nn">os</span>
16521670 <span class="n">__all__</span> <span class="o">=</span>\
1653 <span class="p">[</span><span class="s1">&#39;Dataset&#39;</span><span class="p">,</span><span class="s1">&#39;Variable&#39;</span><span class="p">,</span><span class="s1">&#39;Dimension&#39;</span><span class="p">,</span><span class="s1">&#39;Group&#39;</span><span class="p">,</span><span class="s1">&#39;MFDataset&#39;</span><span class="p">,</span><span class="s1">&#39;MFTime&#39;</span><span class="p">,</span><span class="s1">&#39;CompoundType&#39;</span><span class="p">,</span><span class="s1">&#39;VLType&#39;</span><span class="p">,</span><span class="s1">&#39;date2num&#39;</span><span class="p">,</span><span class="s1">&#39;num2date&#39;</span><span class="p">,</span><span class="s1">&#39;date2index&#39;</span><span class="p">,</span><span class="s1">&#39;stringtochar&#39;</span><span class="p">,</span><span class="s1">&#39;chartostring&#39;</span><span class="p">,</span><span class="s1">&#39;stringtoarr&#39;</span><span class="p">,</span><span class="s1">&#39;getlibversion&#39;</span><span class="p">,</span><span class="s1">&#39;EnumType&#39;</span><span class="p">,</span><span class="s1">&#39;get_chunk_cache&#39;</span><span class="p">,</span><span class="s1">&#39;set_chunk_cache&#39;</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">&#39;HDF5_PLUGIN_PATH&#39;</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">&#39;libh5noop.so&#39;</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">&#39;HDF5_PLUGIN_PATH&#39;</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">&#39;Dataset&#39;</span><span class="p">,</span><span class="s1">&#39;Variable&#39;</span><span class="p">,</span><span class="s1">&#39;Dimension&#39;</span><span class="p">,</span><span class="s1">&#39;Group&#39;</span><span class="p">,</span><span class="s1">&#39;MFDataset&#39;</span><span class="p">,</span><span class="s1">&#39;MFTime&#39;</span><span class="p">,</span><span class="s1">&#39;CompoundType&#39;</span><span class="p">,</span><span class="s1">&#39;VLType&#39;</span><span class="p">,</span><span class="s1">&#39;date2num&#39;</span><span class="p">,</span><span class="s1">&#39;num2date&#39;</span><span class="p">,</span><span class="s1">&#39;date2index&#39;</span><span class="p">,</span><span class="s1">&#39;stringtochar&#39;</span><span class="p">,</span><span class="s1">&#39;chartostring&#39;</span><span class="p">,</span><span class="s1">&#39;stringtoarr&#39;</span><span class="p">,</span><span class="s1">&#39;getlibversion&#39;</span><span class="p">,</span><span class="s1">&#39;EnumType&#39;</span><span class="p">,</span><span class="s1">&#39;get_chunk_cache&#39;</span><span class="p">,</span><span class="s1">&#39;set_chunk_cache&#39;</span><span class="p">,</span><span class="s1">&#39;set_alignment&#39;</span><span class="p">,</span><span class="s1">&#39;get_alignment&#39;</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">&#39;plugins&#39;</span><span class="p">)</span>
1674 <span class="k">if</span> <span class="s1">&#39;HDF5_PLUGIN_PATH&#39;</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">&#39;lib__nczhdf5filters.so&#39;</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">&#39;lib__nczhdf5filters.dylib&#39;</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">&#39;HDF5_PLUGIN_PATH&#39;</span><span class="p">]</span><span class="o">=</span><span class="n">pluginpath</span>
16571678 </pre></div>
16581679
16591680 </details>
26442665 <p><strong><code>data</code></strong>: if True, write out variable data (Default False).</p>
26452666
26462667 <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">#&nbsp;&nbsp</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">#&nbsp;&nbsp</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">#&nbsp;&nbsp</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">#&nbsp;&nbsp</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>
26472728 </div>
26482729
26492730
39003981 <dd id="Group.get_variables_by_attributes" class="function"><a href="#Dataset.get_variables_by_attributes">get_variables_by_attributes</a></dd>
39013982 <dd id="Group.fromcdl" class="function"><a href="#Dataset.fromcdl">fromcdl</a></dd>
39023983 <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>
39033988 <dd id="Group.name" class="variable"><a href="#Dataset.name">name</a></dd>
39043989 <dd id="Group.groups" class="variable"><a href="#Dataset.groups">groups</a></dd>
39053990 <dd id="Group.dimensions" class="variable"><a href="#Dataset.dimensions">dimensions</a></dd>
40664151 <dd id="MFDataset.get_variables_by_attributes" class="function"><a href="#Dataset.get_variables_by_attributes">get_variables_by_attributes</a></dd>
40674152 <dd id="MFDataset.fromcdl" class="function"><a href="#Dataset.fromcdl">fromcdl</a></dd>
40684153 <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>
40694158 <dd id="MFDataset.name" class="variable"><a href="#Dataset.name">name</a></dd>
40704159 <dd id="MFDataset.groups" class="variable"><a href="#Dataset.groups">groups</a></dd>
40714160 <dd id="MFDataset.dimensions" class="variable"><a href="#Dataset.dimensions">dimensions</a></dd>
43324421 </div>
43334422
43344423
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>
43364425
43374426 <p>Return numeric time values given datetime objects. The units
43384427 of the numeric time values are described by the <strong>units</strong> argument
43774466 This kwarg is not needed to define calendar systems allowed by CF
43784467 (the calendar-specific defaults do this).</p>
43794468
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
43804475 <p>returns a numeric time value, or an array of numeric time values
43814476 with approximately 1 microsecond accuracy.</p>
43824477 </div>
47254820
47264821
47274822 </section>
4823 <section id="set_alignment">
4824 <div class="attr function"><a class="headerlink" href="#set_alignment">#&nbsp;&nbsp</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">#&nbsp;&nbsp</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>
47284864 </main>
47294865 </body>
47304866 </html>
55 # hdf5 version info.
66 cdef extern from "H5public.h":
77 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
99
1010 cdef extern from *:
1111 ctypedef char* const_char_ptr "const char*"
125125 NC_FORMAT_DAP4
126126 NC_FORMAT_PNETCDF
127127 NC_FORMAT_UNDEFINED
128 # Let nc__create() or nc__open() figure out
129 # as suitable chunk size.
130128 NC_SIZEHINT_DEFAULT
131 # In nc__enddef(), align to the chunk size.
132129 NC_ALIGN_CHUNK
133130 # 'size' argument to ncdimdef for an unlimited dimension
134131 NC_UNLIMITED
217214 NC_ENDIAN_BIG
218215 const_char_ptr *nc_inq_libvers() nogil
219216 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
224219 int nc_inq_path(int ncid, size_t *pathlen, char *path) nogil
225220 int nc_inq_format_extended(int ncid, int *formatp, int* modep) nogil
226221 int nc_inq_ncid(int ncid, char *name, int *grp_ncid) nogil
229224 int nc_inq_grp_parent(int ncid, int *parent_ncid) nogil
230225 int nc_inq_varids(int ncid, int *nvars, int *varids) nogil
231226 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
234229 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
236231 int nc_insert_array_compound(int ncid, nc_type xtype, char *name,
237232 size_t offset, nc_type field_typeid,
238 int ndims, int *dim_sizes)
233 int ndims, int *dim_sizes) nogil
239234 int nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size) nogil
240235 int nc_inq_compound(int ncid, nc_type xtype, char *name, size_t *size,
241236 size_t *nfieldsp) nogil
257252 int *ndimsp) nogil
258253 int nc_inq_compound_fielddim_sizes(int ncid, nc_type xtype, int fieldid,
259254 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
261256 int nc_inq_vlen(int ncid, nc_type xtype, char *name, size_t *datum_sizep,
262257 nc_type *base_nc_typep) nogil
263258 int nc_inq_user_type(int ncid, nc_type xtype, char *name, size_t *size,
264259 nc_type *base_nc_typep, size_t *nfieldsp, int *classp) nogil
265260 int nc_inq_typeids(int ncid, int *ntypes, int *typeids) nogil
266261 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
268263 int nc_get_att(int ncid, int varid, char *name, void *ip) nogil
269264 int nc_get_att_string(int ncid, int varid, char *name, char **ip) nogil
270265 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
273268 int nc_put_att_opaque(int ncid, int varid, char *name,
274 size_t len, void *op)
269 size_t len, void *op) nogil
275270 int nc_get_att_opaque(int ncid, int varid, char *name,
276 void *ip)
271 void *ip) nogil
277272 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
279274 int nc_get_cmp_att_opaque(int ncid, nc_type xtype, int fieldid,
280 char *name, void *ip)
275 char *name, void *ip) nogil
281276 int nc_put_var1(int ncid, int varid, size_t *indexp,
282 void *op)
277 void *op) nogil
283278 int nc_get_var1(int ncid, int varid, size_t *indexp,
284 void *ip)
279 void *ip) nogil
285280 int nc_put_vara(int ncid, int varid, size_t *startp,
286 size_t *countp, void *op)
281 size_t *countp, void *op) nogil
287282 int nc_get_vara(int ncid, int varid, size_t *startp,
288283 size_t *countp, void *ip) nogil
289284 int nc_put_vars(int ncid, int varid, size_t *startp,
290285 size_t *countp, ptrdiff_t *stridep,
291 void *op)
286 void *op) nogil
292287 int nc_get_vars(int ncid, int varid, size_t *startp,
293288 size_t *countp, ptrdiff_t *stridep,
294289 void *ip) nogil
295290 int nc_put_varm(int ncid, int varid, size_t *startp,
296291 size_t *countp, ptrdiff_t *stridep,
297 ptrdiff_t *imapp, void *op)
292 ptrdiff_t *imapp, void *op) nogil
298293 int nc_get_varm(int ncid, int varid, size_t *startp,
299294 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
303298 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
306301 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
310305 int nc_inq_var_chunking(int ncid, int varid, int *contiguousp, size_t *chunksizesp) nogil
311306 int nc_inq_var_deflate(int ncid, int varid, int *shufflep,
312307 int *deflatep, int *deflate_levelp) nogil
313308 int nc_inq_var_fill(int ncid, int varid, int *no_fill, void *fill_value) nogil
314309 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
324317 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
326319 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
328321 int nc_inq_unlimdim(int ncid, int *unlimdimidp) nogil
329322 int nc_inq_unlimdims(int ncid, int *nunlimdimsp, int *unlimdimidsp) nogil
330323 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
332325 int nc_inq_dimid(int ncid, char *name, int *idp) nogil
333326 int nc_inq_dim(int ncid, int dimid, char *name, size_t *lenp) nogil
334327 int nc_inq_dimname(int ncid, int dimid, char *name) nogil
335328 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
337330 int nc_inq_att(int ncid, int varid, char *name,
338331 nc_type *xtypep, size_t *lenp) nogil
339332 int nc_inq_attid(int ncid, int varid, char *name, int *idp) nogil
341334 int nc_inq_attlen(int ncid, int varid, char *name, size_t *lenp) nogil
342335 int nc_inq_attname(int ncid, int varid, int attnum, char *name) nogil
343336 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
346339 int nc_put_att_text(int ncid, int varid, char *name,
347 size_t len, char *op)
340 size_t len, char *op) nogil
348341 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)
383342 int nc_def_var(int ncid, char *name, nc_type xtype, int ndims,
384 int *dimidsp, int *varidp)
343 int *dimidsp, int *varidp) nogil
385344 int nc_inq_var(int ncid, int varid, char *name, nc_type *xtypep,
386345 int *ndimsp, int *dimidsp, int *nattsp) nogil
387346 int nc_inq_varid(int ncid, char *name, int *varidp) nogil
390349 int nc_inq_varndims(int ncid, int varid, int *ndimsp) nogil
391350 int nc_inq_vardimid(int ncid, int varid, int *dimidsp) nogil
392351 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
680359 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
684363 int nc_inq_enum(int ncid, nc_type xtype, char *name, nc_type *base_nc_typep,\
685364 size_t *base_sizep, size_t *num_membersp) nogil
686365 int nc_inq_enum_member(int ncid, nc_type xtype, int idx, char *name, void *value) nogil
695374 NC_QUANTIZE_BITGROOM
696375 NC_QUANTIZE_GRANULARBR
697376 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
699378 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
700381
701382 IF HAS_SZIP_SUPPORT:
702383 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
704387 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
707390
708391 IF HAS_ZSTANDARD_SUPPORT:
709392 cdef extern from "netcdf_filter.h":
710393 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
715398
716399 IF HAS_BZIP2_SUPPORT:
717400 cdef extern from "netcdf_filter.h":
718401 cdef enum:
719402 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
722405
723406 IF HAS_BLOSC_SUPPORT:
724407 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
727412
728413 IF HAS_NC_OPEN_MEM:
729414 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
731416
732417 IF HAS_NC_CREATE_MEM:
733418 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
735420 ctypedef struct NC_memio:
736421 size_t size
737422 void* memory
738423 int flags
739 int nc_close_memio(int ncid, NC_memio* info);
424 int nc_close_memio(int ncid, NC_memio* info) nogil
740425
741426 IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT:
742427 cdef extern from "mpi-compat.h": pass
743428 cdef extern from "netcdf_par.h":
744429 ctypedef int MPI_Comm
745430 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
749434 cdef enum:
750435 NC_COLLECTIVE
751436 NC_INDEPENDENT
754439 NC_MPIIO
755440 NC_MPIPOSIX
756441 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)
757447
758448 # taken from numpy.pxi in numpy 1.0rc2.
759449 cdef extern from "numpy/arrayobject.h":
760450 ctypedef int npy_intp
761451 ctypedef extern class numpy.ndarray [object PyArrayObject]:
762452 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
766456 void* PyArray_DATA(ndarray) nogil
767457 char* PyArray_BYTES(ndarray) nogil
768458 npy_intp* PyArray_STRIDES(ndarray) nogil
7070 has_zstandard = False
7171 has_bzip2 = False
7272 has_blosc = False
73 has_set_alignment = False
7374
7475 for d in inc_dirs:
7576 try:
9192 has_cdf5_format = True
9293 if line.startswith('nc_def_var_quantize'):
9394 has_quantize = True
95 if line.startswith('nc_set_alignment'):
96 has_set_alignment = True
9497
9598 if has_nc_open_mem:
9699 try:
140143 return has_rename_grp, has_nc_inq_path, has_nc_inq_format_extended, \
141144 has_cdf5_format, has_nc_open_mem, has_nc_create_mem, \
142145 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
144147
145148
146149 def getnetcdfvers(libdirs):
227230
228231 setup_cfg = 'setup.cfg'
229232 # contents of setup.cfg will override env vars, unless
230 # USE_SETUPCFG evaluates to False.
233 # USE_SETUPCFG evaluates to False.
231234 ncconfig = None
232235 use_ncconfig = None
233236 if USE_SETUPCFG and os.path.exists(setup_cfg):
337340 elif USE_NCCONFIG is None:
338341 # if nc-config exists, and USE_NCCONFIG not set, try to use it.
339342 if HAS_NCCONFIG: USE_NCCONFIG=True
340 #elif USE_NCCONFIG is None:
343 #elif USE_NCCONFIG is None:
341344 # USE_NCCONFIG = False # don't try to use nc-config if USE_NCCONFIG not set
342345
343346 try:
554557 has_rename_grp, has_nc_inq_path, has_nc_inq_format_extended, \
555558 has_cdf5_format, has_nc_open_mem, has_nc_create_mem, \
556559 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 = \
558561 check_api(inc_dirs,netcdf_lib_version)
559562 # for netcdf 4.4.x CDF5 format is always enabled.
560563 if netcdf_lib_version is not None and\
660663 else:
661664 sys.stdout.write('netcdf lib does not have szip compression functions\n')
662665 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')
663673
664674 f.close()
665675
1111 __has_bzip2_support__, __has_blosc_support__, __has_szip_support__)
1212 import os
1313 __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']
1515 # if HDF5_PLUGIN_PATH not set, point to package path if plugins live there
1616 pluginpath = os.path.join(__path__[0],'plugins')
1717 if 'HDF5_PLUGIN_PATH' not in os.environ and\
00 """
1 Version 1.6.0
1 Version 1.6.1
22 -------------
33
44 # Introduction
12291229 # Python 3.7+ guarantees order; older versions need OrderedDict
12301230 from collections import OrderedDict
12311231
1232 __version__ = "1.6.0"
1232 __version__ = "1.6.1"
12331233
12341234 # Initialize numpy
12351235 import posixpath
12641264 def _gethdf5libversion():
12651265 cdef unsigned int majorvers, minorvers, releasevers
12661266 cdef herr_t ierr
1267 ierr = H5get_libversion( &majorvers, &minorvers, &releasevers)
1267 with nogil:
1268 ierr = H5get_libversion( &majorvers, &minorvers, &releasevers)
12681269 if ierr < 0:
12691270 raise RuntimeError('error getting HDF5 library version info')
12701271 return '%d.%d.%d' % (majorvers,minorvers,releasevers)
12881289 cdef int ierr
12891290 cdef size_t sizep, nelemsp
12901291 cdef float preemptionp
1291 ierr = nc_get_chunk_cache(&sizep, &nelemsp, &preemptionp)
1292 with nogil:
1293 ierr = nc_get_chunk_cache(&sizep, &nelemsp, &preemptionp)
12921294 _ensure_nc_success(ierr)
12931295 size = sizep; nelems = nelemsp; preemption = preemptionp
12941296 return (size,nelems,preemption)
13171319 preemptionp = preemption
13181320 else:
13191321 preemptionp = preemption_orig
1320 ierr = nc_set_chunk_cache(sizep,nelemsp, preemptionp)
1322 with nogil:
1323 ierr = nc_set_chunk_cache(sizep,nelemsp, preemptionp)
13211324 _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 )
13221371
13231372 __netcdf4libversion__ = getlibversion().split()[0]
13241373 __hdf5libversion__ = _gethdf5libversion()
13351384 __has_bzip2_support__ = HAS_BZIP2_SUPPORT
13361385 __has_blosc_support__ = HAS_BLOSC_SUPPORT
13371386 __has_szip_support__ = HAS_SZIP_SUPPORT
1387 __has_set_alignment__ = HAS_SET_ALIGNMENT
13381388 _needsworkaround_issue485 = __netcdf4libversion__ < "4.4.0" or \
13391389 (__netcdf4libversion__.startswith("4.4.0") and \
13401390 "-development" in __netcdf4libversion__)
15061556 result = [values[j].decode(encoding,errors='replace').replace('\x00','')
15071557 if values[j] else "" for j in range(att_len)]
15081558 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
15101561 finally:
15111562 PyMem_Free(values)
15121563
15471598
15481599 def _set_default_format(object format='NETCDF4'):
15491600 # Private function to set the netCDF file format
1601 cdef int ierr, formatid
15501602 if format not in _format_dict:
15511603 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)
15531608
15541609 cdef _get_format(int grpid):
15551610 # Private function to get the netCDF file format
15961651
15971652 if not _needsworkaround_issue485:
15981653 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)
16001656 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)
16021659 _ensure_nc_success(ierr)
16031660
16041661
16051662 cdef _set_att(grp, int varid, name, value,\
16061663 nc_type xtype=-99, force_ncstring=False):
16071664 # Private function to set an attribute name/value pair
1608 cdef int ierr, lenarr
1665 cdef int ierr, lenarr, N, grpid
16091666 cdef char *attname
16101667 cdef char *datstring
16111668 cdef char **string_ptrs
16121669 cdef ndarray value_arr
16131670 bytestr = _strencode(name)
16141671 attname = bytestr
1672 grpid = grp._grpid
16151673 # put attribute value into a numpy array.
16161674 value_arr = numpy.array(value)
16171675 if value_arr.ndim > 1: # issue #841
16251683 warnings.warn(msg,FutureWarning)
16261684 # if array is 64 bit integers or
16271685 # if 64-bit datatype not supported, cast to 32 bit integers.
1628 fmt = _get_format(grp._grpid)
1686 fmt = _get_format(grpid)
16291687 is_netcdf3 = fmt.startswith('NETCDF3') or fmt == 'NETCDF4_CLASSIC'
16301688 if value_arr.dtype.str[1:] == 'i8' and ('i8' not in _supportedtypes or\
16311689 (is_netcdf3 and fmt != 'NETCDF3_64BIT_DATA')):
16471705 if len(strings[j]) == 0:
16481706 strings[j] = _strencode('\x00')
16491707 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)
16521711 finally:
16531712 PyMem_Free(string_ptrs)
16541713 else:
16721731 try:
16731732 if force_ncstring: raise UnicodeError
16741733 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)
16761736 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)
16791740 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)
16811743 _ensure_nc_success(ierr, err_cls=AttributeError)
16821744 # a 'regular' array type ('f4','i4','f8' etc)
16831745 else:
16881750 elif xtype == -99: # if xtype is not passed in as kwarg.
16891751 xtype = _nptonctype[value_arr.dtype.str[1:]]
16901752 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,
16921755 PyArray_DATA(value_arr))
16931756 _ensure_nc_success(ierr, err_cls=AttributeError)
16941757
21502213 **`info`**: MPI_Info object for parallel access. Default `None`, which
21512214 means MPI_INFO_NULL will be used. Ignored if `parallel=False`.
21522215 """
2153 cdef int grpid, ierr, numgrps, numdims, numvars
2216 cdef int grpid, ierr, numgrps, numdims, numvars,
21542217 cdef size_t initialsize
21552218 cdef char *path
21562219 cdef char namstring[NC_MAX_NAME+1]
2157 cdef int cmode
2220 cdef int cmode, parmode
21582221 IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT:
21592222 cdef MPI_Comm mpicomm
21602223 cdef MPI_Info mpiinfo
22012264 mpiinfo = info.ob_mpi
22022265 else:
22032266 mpiinfo = MPI_INFO_NULL
2204 cmode = NC_MPIIO | _cmode_dict[format]
2267 parmode = NC_MPIIO | _cmode_dict[format]
22052268
22062269 self._inmemory = False
22072270
22162279 # kwarg is interpreted as advisory size.
22172280 IF HAS_NC_CREATE_MEM:
22182281 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)
22202284 self._inmemory = True # checked in close method
22212285 ELSE:
22222286 msg = """
22272291 if clobber:
22282292 if parallel:
22292293 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)
22322298 ELSE:
22332299 pass
22342300 elif diskless:
22352301 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)
22382305 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)
22402309 else:
2241 ierr = nc_create(path, NC_CLOBBER, &grpid)
2310 with nogil:
2311 ierr = nc_create(path, NC_CLOBBER, &grpid)
22422312 else:
22432313 if parallel:
22442314 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)
22472319 ELSE:
22482320 pass
22492321 elif diskless:
22502322 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)
22532326 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)
22552330 else:
2256 ierr = nc_create(path, NC_NOCLOBBER, &grpid)
2331 with nogil:
2332 ierr = nc_create(path, NC_NOCLOBBER, &grpid)
22572333 # reset default format to netcdf3 - this is a workaround
22582334 # for issue 170 (nc_open'ing a DAP dataset after switching
22592335 # format to NETCDF4). This bug should be fixed in version
22692345 if result != 0:
22702346 raise ValueError("Unable to retrieve Buffer from %s" % (memory,))
22712347
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)
22732350 ELSE:
22742351 msg = """
22752352 nc_open_mem functionality not enabled. To enable, install Cython, make sure you have
22772354 raise ValueError(msg)
22782355 elif parallel:
22792356 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)
22822361 ELSE:
22832362 pass
22842363 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)
22862367 else:
22872368 if mode == 'rs':
22882369 # NC_SHARE is very important for speed reading
22892370 # large netcdf3 files with a record dimension
22902371 # (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)
22922375 else:
2293 ierr = nc_open(path, NC_NOWRITE, &grpid)
2376 with nogil:
2377 ierr = nc_open(path, NC_NOWRITE, &grpid)
22942378 elif mode in ['a','r+'] and os.path.exists(filename):
22952379 if parallel:
22962380 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)
22992385 ELSE:
23002386 pass
23012387 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)
23032391 else:
2304 ierr = nc_open(path, NC_WRITE, &grpid)
2392 with nogil:
2393 ierr = nc_open(path, NC_WRITE, &grpid)
23052394 elif mode in ['as','r+s'] and os.path.exists(filename):
23062395 if parallel:
23072396 # NC_SHARE ignored
23082397 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)
23112402 ELSE:
23122403 pass
23132404 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)
23152408 else:
2316 ierr = nc_open(path, NC_SHARE, &grpid)
2409 with nogil:
2410 ierr = nc_open(path, NC_SHARE, &grpid)
23172411 elif mode == 'ws' or (mode in ['as','r+s'] and not os.path.exists(filename)):
23182412 _set_default_format(format=format)
23192413 if clobber:
23202414 if parallel:
23212415 # NC_SHARE ignored
23222416 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)
23252421 ELSE:
23262422 pass
23272423 elif diskless:
23282424 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)
23302428 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)
23322432 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)
23342436 else:
23352437 if parallel:
23362438 # NC_SHARE ignored
23372439 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)
23402444 ELSE:
23412445 pass
23422446 elif diskless:
23432447 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)
23452451 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)
23472455 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)
23492459 else:
23502460 raise ValueError("mode must be 'w', 'x', 'r', 'a' or 'r+', got '%s'" % mode)
23512461
24682578 return '\n'.join(ncdump)
24692579
24702580 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)
24722584
24732585 if check_err:
24742586 _ensure_nc_success(ierr)
24842596 def _close_mem(self, check_err):
24852597 cdef int ierr
24862598 cdef NC_memio memio
2487 ierr = nc_close_memio(self._grpid, &memio)
2599 with nogil:
2600 ierr = nc_close_memio(self._grpid, &memio)
24882601
24892602 if check_err:
24902603 _ensure_nc_success(ierr)
25332646 **`sync(self)`**
25342647
25352648 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)
25372653
25382654 def _redef(self):
25392655 cdef int ierr
2540 ierr = nc_redef(self._grpid)
2656 with nogil:
2657 ierr = nc_redef(self._grpid)
25412658
25422659 def _enddef(self):
25432660 cdef int ierr
2544 ierr = nc_enddef(self._grpid)
2661 with nogil:
2662 ierr = nc_enddef(self._grpid)
25452663
25462664 def set_fill_on(self):
25472665 """
25562674 library corresponds to `set_fill_on`. Data which are equal to the
25572675 `_Fill_Value` indicate that the variable was created, but never written
25582676 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)
25612681
25622682 def set_fill_off(self):
25632683 """
25682688 This will prevent the data from being pre-filled with fill values, which
25692689 may result in some performance improvements. However, you must then make
25702690 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)
25732695
25742696 def createDimension(self, dimname, size=None):
25752697 """
25932715
25942716 rename a `Dimension` named `oldname` to `newname`."""
25952717 cdef char *namstring
2718 cdef Dimension dim
25962719 bytestr = _strencode(newname)
25972720 namstring = bytestr
25982721 if self.data_model != 'NETCDF4': self._redef()
26002723 dim = self.dimensions[oldname]
26012724 except KeyError:
26022725 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)
26042728 if self.data_model != 'NETCDF4': self._enddef()
26052729
26062730 _ensure_nc_success(ierr)
28492973
28502974 rename a `Variable` named `oldname` to `newname`"""
28512975 cdef char *namstring
2976 cdef Variable var
28522977 try:
28532978 var = self.variables[oldname]
28542979 except KeyError:
28562981 bytestr = _strencode(newname)
28572982 namstring = bytestr
28582983 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)
28602986 if self.data_model != 'NETCDF4': self._enddef()
28612987
28622988 _ensure_nc_success(ierr)
29743100 bytestr = _strencode(name)
29753101 attname = bytestr
29763102 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)
29783105 if self.data_model != 'NETCDF4': self._enddef()
29793106 _ensure_nc_success(ierr)
29803107
30193146 rename a `Dataset` or `Group` attribute named `oldname` to `newname`."""
30203147 cdef char *oldnamec
30213148 cdef char *newnamec
3149 cdef int ierr
30223150 bytestr = _strencode(oldname)
30233151 oldnamec = bytestr
30243152 bytestr = _strencode(newname)
30253153 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)
30273157
30283158 def renameGroup(self, oldname, newname):
30293159 """
30313161
30323162 rename a `Group` named `oldname` to `newname` (requires netcdf >= 4.3.1)."""
30333163 cdef char *newnamec
3164 cdef int grpid
30343165 IF HAS_RENAME_GRP:
3166 cdef int ierr
30353167 bytestr = _strencode(newname)
30363168 newnamec = bytestr
30373169 try:
30383170 grp = self.groups[oldname]
3171 grpid = grp._grpid
30393172 except KeyError:
30403173 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)
30423177 # remove old key from groups dict.
30433178 self.groups.pop(oldname)
30443179 # add new key.
33603495 f = open(outfile,'w')
33613496 f.write(result.stdout)
33623497 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
33633554
33643555 cdef class Group(Dataset):
33653556 """
33923583 another `Group` instance, not using this class directly.
33933584 """
33943585 cdef char *groupname
3586 cdef int ierr, grpid
33953587 # flag to indicate that Variables in this Group support orthogonal indexing.
33963588 self.__orthogonal_indexing__ = True
33973589 # set data_model and file_format attributes.
34183610 else:
34193611 bytestr = _strencode(name)
34203612 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)
34223617 if sys.version_info[0:2] < (3, 7):
34233618 self.cmptypes = OrderedDict()
34243619 self.vltypes = OrderedDict()
35033698 else:
35043699 lendim = NC_UNLIMITED
35053700 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)
35073703 if grp.data_model != 'NETCDF4': grp._enddef()
35083704 _ensure_nc_success(ierr)
35093705
35683764 cdef int ierr, n, numunlimdims, ndims, nvars, ngatts, xdimid
35693765 cdef int *unlimdimids
35703766 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)
35723769 _ensure_nc_success(ierr)
35733770 if numunlimdims == 0:
35743771 return False
39304127 self._vltype = datatype
39314128 xtype = datatype._nc_type
39324129 # 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)
39344132 _ensure_nc_success(ierr)
39354133 # dtype variable attribute is a numpy datatype object.
39364134 self.dtype = datatype.dtype
39604158 if grp.data_model != 'NETCDF4': grp._redef()
39614159 # define variable.
39624160 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)
39654164 free(dimids)
39664165 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)
39694169 # set chunk cache size if desired
39704170 # default is 1mb per var, can cause problems when many (1000's)
39714171 # of vars are created. This change only lasts as long as file is
39724172 # open.
39734173 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)
39764177 _ensure_nc_success(ierr)
39774178 # reset chunk cache size, leave other parameters unchanged.
39784179 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)
39814183 _ensure_nc_success(ierr)
39824184 if ierr != NC_NOERR:
39834185 if grp.data_model != 'NETCDF4': grp._enddef()
39944196 if zlib:
39954197 icomplevel = complevel
39964198 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)
39984201 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)
40004204 if ierr != NC_NOERR:
40014205 if grp.data_model != 'NETCDF4': grp._enddef()
40024206 _ensure_nc_success(ierr)
40084212 msg="unknown szip coding ('ec' or 'nn' supported)"
40094213 raise ValueError(msg)
40104214 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)
40124217 if ierr != NC_NOERR:
40134218 if grp.data_model != 'NETCDF4': grp._enddef()
40144219 _ensure_nc_success(ierr)
40194224 if zstd:
40204225 IF HAS_ZSTANDARD_SUPPORT:
40214226 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)
40234229 if ierr != NC_NOERR:
40244230 if grp.data_model != 'NETCDF4': grp._enddef()
40254231 _ensure_nc_success(ierr)
40314237 if bzip2:
40324238 IF HAS_BZIP2_SUPPORT:
40334239 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)
40354242 if ierr != NC_NOERR:
40364243 if grp.data_model != 'NETCDF4': grp._enddef()
40374244 _ensure_nc_success(ierr)
40464253 iblosc_shuffle = blosc_shuffle
40474254 iblosc_blocksize = 0 # not currently used by c lib
40484255 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,\
40504258 iblosc_compressor,\
40514259 iblosc_complevel,iblosc_blocksize,\
40524260 iblosc_shuffle)
40604268 raise ValueError(msg)
40614269 # set checksum.
40624270 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)
40644273 if ierr != NC_NOERR:
40654274 if grp.data_model != 'NETCDF4': grp._enddef()
40664275 _ensure_nc_success(ierr)
40864295 raise ValueError(msg)
40874296 chunksizesp[n] = chunksizes[n]
40884297 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)
40904300 free(chunksizesp)
40914301 if ierr != NC_NOERR:
40924302 if grp.data_model != 'NETCDF4': grp._enddef()
40934303 _ensure_nc_success(ierr)
40944304 # set endian-ness of variable
40954305 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)
40974308 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)
40994311 elif endian == 'native':
41004312 pass # this is the default format.
41014313 else:
41054317 if significant_digits is not None:
41064318 nsd = significant_digits
41074319 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)
41104323 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)
41134327 elif quantize_mode == 'BitRound':
41144328 ierr = nc_def_var_quantize(self._grpid,
4115 self._varid, NC_QUANTIZE_BITROUND, nsd)
4329 self._varid, NC_QUANTIZE_BITROUND, nsd)
41164330 else:
41174331 raise ValueError("'quantize_mode' keyword argument must be 'BitGroom','GranularBitRound' or 'BitRound', got '%s'" % quantize_mode)
41184332
41414355 # anyway.
41424356 ierr = 0
41434357 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)
41454360 if ierr != NC_NOERR:
41464361 if grp.data_model != 'NETCDF4': grp._enddef()
41474362 _ensure_nc_success(ierr)
44304645 bytestr = _strencode(name)
44314646 attname = bytestr
44324647 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)
44344650 if self._grp.data_model != 'NETCDF4': self._grp._enddef()
44354651 _ensure_nc_success(ierr)
44364652
44394655 **`filters(self)`**
44404656
44414657 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
44434659 cdef int izstd=0
44444660 cdef int ibzip2=0
44454661 cdef int iblosc=0
44464662 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
44494671 filtdict = {'zlib':False,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':False,'complevel':0,'fletcher32':False}
44504672 if self._grp.data_model not in ['NETCDF4_CLASSIC','NETCDF4']: return
44514673 with nogil:
44554677 ierr = nc_inq_var_fletcher32(self._grpid, self._varid, &ifletcher32)
44564678 _ensure_nc_success(ierr)
44574679 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)
44604683 if ierr != 0: izstd=0
44614684 # _ensure_nc_success(ierr)
44624685 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)
44654689 if ierr != 0: ibzip2=0
44664690 #_ensure_nc_success(ierr)
44674691 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)
44704695 if ierr != 0: iblosc=0
44714696 #_ensure_nc_success(ierr)
44724697 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)
44754701 if ierr != 0:
44764702 iszip=0
44774703 else:
46174843 preemptionp = preemption
46184844 else:
46194845 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)
46224849 _ensure_nc_success(ierr)
46234850
46244851 def __delattr__(self,name):
47014928 oldnamec = bytestr
47024929 bytestr = _strencode(newname)
47034930 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)
47054933 _ensure_nc_success(ierr)
47064934
47074935 def __getitem__(self, elem):
51055333 encoding = getattr(self,'_Encoding','utf-8')
51065334 bytestr = _strencode(data,encoding=encoding)
51075335 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)
51105339 _ensure_nc_success(ierr)
51115340 free(strdata)
51125341 else: # regular VLEN
51165345 vldata = <nc_vlen_t *>malloc(sizeof(nc_vlen_t))
51175346 vldata[0].len = PyArray_SIZE(data2)
51185347 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)
51215351 _ensure_nc_success(ierr)
51225352 free(vldata)
51235353 free(startp)
55555785 data = data.byteswap()
55565786 # strides all 1 or scalar variable, use put_vara (faster)
55575787 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))
55605791 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))
55635795 _ensure_nc_success(ierr)
55645796 elif self._isvlen:
55655797 if data.dtype.char !='O':
55825814 strdata[i] = data[i]
55835815 # strides all 1 or scalar variable, use put_vara (faster)
55845816 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)
55875820 else:
55885821 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)
55915825 _ensure_nc_success(ierr)
55925826 free(strdata)
55935827 else:
56095843 databuff = databuff + PyArray_STRIDES(data)[0]
56105844 # strides all 1 or scalar variable, use put_vara (faster)
56115845 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)
56145849 else:
56155850 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)
56185854 _ensure_nc_success(ierr)
56195855 # free the pointer array.
56205856 free(vldata)
56245860
56255861 def _get(self,start,count,stride):
56265862 """Private method to retrieve data from a netCDF variable"""
5627 cdef int ierr, ndims
5863 cdef int ierr, ndims, totelem
56285864 cdef size_t *startp
56295865 cdef size_t *countp
56305866 cdef ptrdiff_t *stridep
57035939 else:
57045940 # FIXME: is this a bug in netCDF4?
57055941 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)
57085945 if ierr == NC_EINVALCOORDS:
57095946 raise IndexError
57105947 elif ierr != NC_NOERR:
57225959 # reshape the output array
57235960 data = numpy.reshape(data, shapeout)
57245961 # 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)
57265964 # free the pointer array
57275965 free(strdata)
57285966 else:
57395977 startp, countp, vldata)
57405978 else:
57415979 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)
57445983 if ierr == NC_EINVALCOORDS:
57455984 raise IndexError
57465985 elif ierr != NC_NOERR:
57565995 # reshape the output array
57575996 data = numpy.reshape(data, shapeout)
57585997 # 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)
57606000 # free the pointer array
57616001 free(vldata)
57626002 free(startp)
57896029 IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT:
57906030 # set collective MPI IO mode on or off
57916031 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)
57946035 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)
57976039 _ensure_nc_success(ierr)
57986040 ELSE:
57996041 pass # does nothing
59416183 # private function used to construct a netcdf compound data type
59426184 # from a numpy dtype object by CompoundType.__init__.
59436185 cdef nc_type xtype, xtype_tmp
5944 cdef int ierr, ndims
6186 cdef int ierr, ndims, grpid
59456187 cdef size_t offset, size
59466188 cdef char *namstring
59476189 cdef char *nested_namstring
59496191 bytestr = _strencode(dtype_name)
59506192 namstring = bytestr
59516193 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)
59536197 _ensure_nc_success(ierr)
59546198 names = list(dt.fields.keys())
59556199 formats = [v[0] for v in dt.fields.values()]
59676211 xtype_tmp = _nptonctype[format.str[1:]]
59686212 except KeyError:
59696213 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)
59726217 _ensure_nc_success(ierr)
59736218 else:
59746219 if format.shape == (): # nested scalar compound type
59766221 xtype_tmp = _find_cmptype(grp, format)
59776222 bytestr = _strencode(name)
59786223 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)
59826228 _ensure_nc_success(ierr)
59836229 else: # nested array compound element
59846230 ndims = len(format.shape)
59906236 xtype_tmp = _nptonctype[format.subdtype[0].str[1:]]
59916237 except KeyError:
59926238 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,
59946241 offset,xtype_tmp,ndims,dim_sizes)
59956242 _ensure_nc_success(ierr)
59966243 else: # nested array compound type.
60016248 # xtype_tmp = _find_cmptype(grp, format.subdtype[0])
60026249 # bytestr = _strencode(name)
60036250 # 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)
60086256 # _ensure_nc_success(ierr)
60096257 free(dim_sizes)
60106258 return xtype
61786426 # private function used to construct a netcdf VLEN data type
61796427 # from a numpy dtype object or python str object by VLType.__init__.
61806428 cdef nc_type xtype, xtype_tmp
6181 cdef int ierr, ndims
6429 cdef int ierr, ndims, grpid
61826430 cdef size_t offset, size
61836431 cdef char *namstring
61846432 cdef char *nested_namstring
6433 grpid = grp._grpid
61856434 if dt == str: # python string, use NC_STRING
61866435 xtype = NC_STRING
61876436 # dtype_name ignored
61936442 # find netCDF primitive data type corresponding to
61946443 # specified numpy data type.
61956444 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);
61976447 _ensure_nc_success(ierr)
61986448 else:
61996449 raise KeyError("unsupported datatype specified for VLEN")
62046454 # construct a corresponding numpy dtype instance,
62056455 # then use that to create a VLType instance.
62066456 # called by _get_types, _get_vars.
6207 cdef int ierr, _grpid
6457 cdef int ierr, grpid
62086458 cdef size_t vlsize
62096459 cdef nc_type base_xtype
62106460 cdef char vl_namstring[NC_MAX_NAME+1]
6211 _grpid = group._grpid
6461 grpid = group._grpid
62126462 if xtype == NC_STRING:
62136463 dt = str
62146464 name = None
62156465 else:
62166466 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)
62186468 _ensure_nc_success(ierr)
62196469 name = vl_namstring.decode('utf-8')
62206470 try:
62856535 # private function used to construct a netCDF Enum data type
62866536 # from a numpy dtype object or python str object by EnumType.__init__.
62876537 cdef nc_type xtype, xtype_tmp
6288 cdef int ierr
6538 cdef int ierr, grpid
62896539 cdef char *namstring
62906540 cdef ndarray value_arr
62916541 bytestr = _strencode(dtype_name)
62926542 namstring = bytestr
6543 grpid = grp._grpid
62936544 dt = numpy.dtype(dt) # convert to numpy datatype.
62946545 if dt.str[1:] in _intnptonctype.keys():
62956546 # find netCDF primitive data type corresponding to
62966547 # specified numpy data type.
62976548 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)
62996551 _ensure_nc_success(ierr)
63006552 else:
63016553 msg="unsupported datatype specified for ENUM (must be integer)"
63056557 value_arr = numpy.array(enum_dict[field],dt)
63066558 bytestr = _strencode(field)
63076559 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))
63106563 _ensure_nc_success(ierr)
63116564 return xtype, dt
63126565
63156568 # construct a corresponding numpy dtype instance,
63166569 # then use that to create a EnumType instance.
63176570 # called by _get_types, _get_vars.
6318 cdef int ierr, _grpid, nmem
6571 cdef int ierr, grpid, nmem
63196572 cdef ndarray enum_val
63206573 cdef nc_type base_xtype
63216574 cdef char enum_namstring[NC_MAX_NAME+1]
63226575 cdef size_t nmembers
6323 _grpid = group._grpid
6576 grpid = group._grpid
63246577 # get name, datatype, and number of members.
63256578 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,\
63276580 &nmembers)
63286581 _ensure_nc_success(ierr)
63296582 enum_name = enum_namstring.decode('utf-8')
63386591 enum_val = numpy.empty(1,dt)
63396592 for nmem from 0 <= nmem < nmembers:
63406593 with nogil:
6341 ierr = nc_inq_enum_member(_grpid, xtype, nmem, \
6594 ierr = nc_inq_enum_member(grpid, xtype, nmem, \
63426595 enum_namstring,PyArray_DATA(enum_val))
63436596 _ensure_nc_success(ierr)
63446597 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
22 from netCDF4 import __has_cdf5_format__, __has_nc_inq_path__, __has_nc_create_mem__, \
33 __has_parallel4_support__, __has_pnetcdf_support__, \
44 __has_zstandard_support__, __has_bzip2_support__, \
2525 if not __has_quantization_support__:
2626 test_files.remove('tst_compression_quant.py')
2727 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():
2931 test_files.remove('tst_compression_zstd.py')
3032 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():
3234 test_files.remove('tst_compression_bzip2.py')
3335 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():
3537 test_files.remove('tst_compression_blosc.py')
3638 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():
3840 test_files.remove('tst_compression_szip.py')
3941 sys.stdout.write('not running tst_compression_szip.py ...\n')
42 nc.close()
43 os.remove(filename)
4044
4145 # Don't run tests that require network connectivity
4246 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()
00 from numpy.random.mtrand import uniform
11 from netCDF4 import Dataset
22 from numpy.testing import assert_almost_equal
3 import os, tempfile, unittest
3 import os, tempfile, unittest, sys
44
55 ndim = 100000
66 iblosc_shuffle=2
7373 f.close()
7474
7575 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()
00 from numpy.random.mtrand import uniform
11 from netCDF4 import Dataset
22 from numpy.testing import assert_almost_equal
3 import os, tempfile, unittest
3 import os, tempfile, unittest, sys
44
55 ndim = 100000
66 filename1 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
4848 f.close()
4949
5050 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()
00 from numpy.random.mtrand import uniform
11 from netCDF4 import Dataset
22 from numpy.testing import assert_almost_equal
3 import os, tempfile, unittest
3 import os, tempfile, unittest, sys
44
55 ndim = 100000
66 filename = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
3838 f.close()
3939
4040 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()
00 from numpy.random.mtrand import uniform
11 from netCDF4 import Dataset
22 from numpy.testing import assert_almost_equal
3 import os, tempfile, unittest
3 import os, tempfile, unittest, sys
44
55 ndim = 100000
66 filename1 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
4848 f.close()
4949
5050 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()