Debian Codegraph @

docs/index.html

raw
1 <!doctype html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
6 <meta name="generator" content="pdoc3 0.11.6">
7 <title>netCDF4 API documentation</title>
8 <meta name="description" content="Version 1.7.4
9 …">
10 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
11 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
12 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
13 <style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source > summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible;min-width:max-content}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin:1em 0}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
14 <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
15 <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
16 <script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
17 <script>window.addEventListener('DOMContentLoaded', () => {
18 hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
19 hljs.highlightAll();
20 /* Collapse source docstrings */
21 setTimeout(() => {
22 [...document.querySelectorAll('.hljs.language-python > .hljs-string')]
23 .filter(el => el.innerHTML.length > 200 && ['"""', "'''"].includes(el.innerHTML.substring(0, 3)))
24 .forEach(el => {
25 let d = document.createElement('details');
26 d.classList.add('hljs-string');
27 d.innerHTML = '<summary>"""</summary>' + el.innerHTML.substring(3);
28 el.replaceWith(d);
29 });
30 }, 100);
31 })</script>
32 </head>
33 <body>
34 <main>
35 <article id="content">
36 <header>
37 <h1 class="title">Package <code>netCDF4</code></h1>
38 </header>
39 <section id="section-intro">
40 <h2 id="version-174">Version 1.7.4</h2>
41 <h1 id="introduction">Introduction</h1>
42 <p>netcdf4-python is a Python interface to the netCDF C library.</p>
43 <p><a href="http://www.unidata.ucar.edu/software/netcdf/">netCDF</a> version 4 has many features
44 not found in earlier versions of the library and is implemented on top of
45 <a href="http://www.hdfgroup.org/HDF5">HDF5</a>. This module can read and write
46 files in both the new netCDF 4 and the old netCDF 3 format, and can create
47 files that are readable by HDF5 clients. The API modelled after
48 <a href="http://dirac.cnrs-orleans.fr/ScientificPython/">Scientific.IO.NetCDF</a>,
49 and should be familiar to users of that module.</p>
50 <p>Most new features of netCDF 4 are implemented, such as multiple
51 unlimited dimensions, groups and data compression.
52 All the new
53 numeric data types (such as 64 bit and unsigned integer types) are
54 implemented. Compound (struct), variable length (vlen) and
55 enumerated (enum) data types are supported, but not the opaque data type.
56 Mixtures of compound, vlen and enum data types (such as
57 compound types containing enums, or vlens containing compound
58 types) are not supported.</p>
59 <h2 id="quick-install">Quick Install</h2>
60 <ul>
61 <li>the easiest way to get going is to install via <code>pip install <a title="netCDF4" href="#netCDF4">netCDF4</a></code>.
62 (or if you use the <a href="http://conda.io">conda</a> package manager <code>conda install -c conda-forge netCDF4</code>).</li>
63 </ul>
64 <h2 id="developer-install">Developer Install</h2>
65 <ul>
66 <li>Clone the <a href="http://github.com/Unidata/netcdf4-python">github repository</a>. Make
67 sure you either clone recursively, or run <code>git submodule update --init</code> to
68 ensure all the submodules are also checked out.</li>
69 <li>Make sure the dependencies are satisfied (Python 3.8 or later,
70 <a href="http://numpy.scipy.org">numpy</a>,
71 <a href="http://cython.org">Cython</a>,
72 <a href="https://github.com/Unidata/cftime">cftime</a>,
73 <a href="https://pypi.python.org/pypi/setuptools">setuptools</a>,
74 the <a href="https://www.hdfgroup.org/solutions/hdf5/">HDF5 C library</a>,
75 and the <a href="https://www.unidata.ucar.edu/software/netcdf/">netCDF C library</a>).
76 For MPI parallel IO support, an MPI-enabled versions of the netcdf library
77 is required, as is <a href="http://mpi4py.scipy.org">mpi4py</a>.
78 Parallel IO further depends on the existence of MPI-enabled HDF5 or the
79 <a href="https://parallel-netcdf.github.io/">PnetCDF</a> library.</li>
80 <li>By default, the utility <code>nc-config</code> (installed with netcdf-c)
81 will be run used to determine where all the dependencies live.</li>
82 <li>If <code>nc-config</code> is not in your default <code>PATH</code>, you can set the <code>NETCDF4_DIR</code>
83 environment variable and <code>setup.py</code> will look in <code>$NETCDF4_DIR/bin</code>.
84 You can also use the file <code>setup.cfg</code> to set the path to <code>nc-config</code>, or
85 enter the paths to the libraries and include files manually. Just
86 edit the <code>setup.cfg</code> file
87 in a text editor and follow the instructions in the comments.
88 To disable the use of <code>nc-config</code>, set the env var <code>USE_NCCONFIG</code> to 0.
89 To disable the use of <code>setup.cfg</code>, set <code>USE_SETUPCFG</code> to 0.
90 As a last resort, the library and include paths can be set via environment variables.
91 If you go this route, set <code>USE_NCCONFIG</code> and <code>USE_SETUPCFG</code> to 0, and specify
92 <code>NETCDF4_LIBDIR</code>, <code>NETCDF4_INCDIR</code>, <code>HDF5_LIBDIR</code> and <code>HDF5_INCDIR</code>.
93 If the dependencies are not found
94 in any of the paths specified by environment variables, then standard locations
95 (such as <code>/usr</code> and <code>/usr/local</code>) are searched.</li>
96 <li>if the env var <code>NETCDF_PLUGIN_DIR</code> is set to point to the location of the netcdf-c compression
97 plugins built by netcdf &gt;= 4.9.0, they will be installed inside the package.
98 In this
99 case <code>HDF5_PLUGIN_PATH</code> will be set to the package installation path on import,
100 so the extra compression algorithms available in netcdf-c &gt;= 4.9.0 will automatically
101 be available.
102 Otherwise, the user will have to set <code>HDF5_PLUGIN_PATH</code> explicitly
103 to have access to the extra compression plugins.</li>
104 <li>run <code>pip install -v .</code> (as root if necessary)</li>
105 <li>run the tests in the 'test' directory by running <code>python run_all.py</code>.</li>
106 </ul>
107 <h1 id="tutorial">Tutorial</h1>
108 <ul>
109 <li><a href="#creatingopeningclosing-a-netcdf-file">Creating/Opening/Closing a netCDF file</a></li>
110 <li><a href="#groups-in-a-netcdf-file">Groups in a netCDF file</a></li>
111 <li><a href="#dimensions-in-a-netcdf-file">Dimensions in a netCDF file</a></li>
112 <li><a href="#variables-in-a-netcdf-file">Variables in a netCDF file</a></li>
113 <li><a href="#attributes-in-a-netcdf-file">Attributes in a netCDF file</a></li>
114 <li><a href="#dealing-with-time-coordinates">Dealing with time coordinates</a></li>
115 <li><a href="#writing-data-to-and-retrieving-data-from-a-netcdf-variable">Writing data to and retrieving data from a netCDF variable</a></li>
116 <li><a href="#reading-data-from-a-multi-file-netcdf-dataset">Reading data from a multi-file netCDF dataset</a></li>
117 <li><a href="#efficient-compression-of-netcdf-variables">Efficient compression of netCDF variables</a></li>
118 <li><a href="#beyond-homogeneous-arrays-of-a-fixed-type-compound-data-types">Beyond homogeneous arrays of a fixed type - compound data types</a></li>
119 <li><a href="#variable-length-vlen-data-types">Variable-length (vlen) data types</a></li>
120 <li><a href="#enum-data-type">Enum data type</a></li>
121 <li><a href="#parallel-io">Parallel IO</a></li>
122 <li><a href="#dealing-with-strings">Dealing with strings</a></li>
123 <li><a href="#in-memory-diskless-datasets">In-memory (diskless) Datasets</a></li>
124 </ul>
125 <p>All of the code in this tutorial is available in <code>examples/tutorial.py</code>, except
126 the parallel IO example, which is in <code>examples/mpi_example.py</code>.
127 Unit tests are in the <code>test</code> directory.</p>
128 <h2 id="creatingopeningclosing-a-netcdf-file">Creating/Opening/Closing a netCDF file</h2>
129 <p>To create a netCDF file from python, you simply call the <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code>
130 constructor. This is also the method used to open an existing netCDF
131 file.
132 If the file is open for write access (<code>mode='w', 'r+'</code> or <code>'a'</code>), you may
133 write any type of data including new dimensions, groups, variables and
134 attributes.
135 netCDF files come in five flavors (<code>NETCDF3_CLASSIC</code>,
136 <code>NETCDF3_64BIT_OFFSET</code>, <code>NETCDF3_64BIT_DATA</code>, <code>NETCDF4_CLASSIC</code>, and <code>NETCDF4</code>).
137 <code>NETCDF3_CLASSIC</code> was the original netcdf binary format, and was limited
138 to file sizes less than 2 Gb. <code>NETCDF3_64BIT_OFFSET</code> was introduced
139 in version 3.6.0 of the library, and extended the original binary format
140 to allow for file sizes greater than 2 Gb.
141 <code>NETCDF3_64BIT_DATA</code> is a new format that requires version 4.4.0 of
142 the C library - it extends the <code>NETCDF3_64BIT_OFFSET</code> binary format to
143 allow for unsigned/64 bit integer data types and 64-bit dimension sizes.
144 <code>NETCDF3_64BIT</code> is an alias for <code>NETCDF3_64BIT_OFFSET</code>.
145 <code>NETCDF4_CLASSIC</code> files use the version 4 disk format (HDF5), but omits features
146 not found in the version 3 API. They can be read by netCDF 3 clients
147 only if they have been relinked against the netCDF 4 library. They can
148 also be read by HDF5 clients. <code>NETCDF4</code> files use the version 4 disk
149 format (HDF5) and use the new features of the version 4 API.
150 The
151 netCDF4 module can read and write files in any of these formats. When
152 creating a new file, the format may be specified using the <code>format</code>
153 keyword in the <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> constructor.
154 The default format is
155 <code>NETCDF4</code>. To see how a given file is formatted, you can examine the
156 <code>data_model</code> attribute.
157 Closing the netCDF file is
158 accomplished via the <code><a title="netCDF4.Dataset.close" href="#netCDF4.Dataset.close">Dataset.close()</a></code> method of the <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code>
159 instance.</p>
160 <p>Here's an example:</p>
161 <pre><code class="language-python">&gt;&gt;&gt; from netCDF4 import Dataset
162 &gt;&gt;&gt; rootgrp = Dataset(&quot;test.nc&quot;, &quot;w&quot;, format=&quot;NETCDF4&quot;)
163 &gt;&gt;&gt; print(rootgrp.data_model)
164 NETCDF4
165 &gt;&gt;&gt; rootgrp.close()
166 </code></pre>
167 <p>Remote <a href="http://opendap.org">OPeNDAP</a>-hosted datasets can be accessed for
168 reading over http if a URL is provided to the <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> constructor instead of a
169 filename.
170 However, this requires that the netCDF library be built with
171 OPenDAP support, via the <code>--enable-dap</code> configure option (added in
172 version 4.0.1).</p>
173 <h2 id="groups-in-a-netcdf-file">Groups in a netCDF file</h2>
174 <p>netCDF version 4 added support for organizing data in hierarchical
175 groups, which are analogous to directories in a filesystem. Groups serve
176 as containers for variables, dimensions and attributes, as well as other
177 groups.
178 A <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> creates a special group, called
179 the 'root group', which is similar to the root directory in a unix
180 filesystem.
181 To create <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instances, use the
182 <code><a title="netCDF4.Dataset.createGroup" href="#netCDF4.Dataset.createGroup">Dataset.createGroup()</a></code> method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code>
183 instance. <code><a title="netCDF4.Dataset.createGroup" href="#netCDF4.Dataset.createGroup">Dataset.createGroup()</a></code> takes a single argument, a
184 python string containing the name of the new group. The new <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code>
185 instances contained within the root group can be accessed by name using
186 the <code>groups</code> dictionary attribute of the <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> instance.
187 Only
188 <code>NETCDF4</code> formatted files support Groups, if you try to create a Group
189 in a netCDF 3 file you will get an error message.</p>
190 <pre><code class="language-python">&gt;&gt;&gt; rootgrp = Dataset(&quot;test.nc&quot;, &quot;a&quot;)
191 &gt;&gt;&gt; fcstgrp = rootgrp.createGroup(&quot;forecasts&quot;)
192 &gt;&gt;&gt; analgrp = rootgrp.createGroup(&quot;analyses&quot;)
193 &gt;&gt;&gt; print(rootgrp.groups)
194 {'forecasts': &lt;class 'netCDF4._netCDF4.Group'&gt;
195 group /forecasts:
196 dimensions(sizes):
197 variables(dimensions):
198 groups: , 'analyses': &lt;class 'netCDF4._netCDF4.Group'&gt;
199 group /analyses:
200 dimensions(sizes):
201 variables(dimensions):
202 groups: }
203 &gt;&gt;&gt;
204 </code></pre>
205 <p>Groups can exist within groups in a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code>, just as directories
206 exist within directories in a unix filesystem. Each <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance
207 has a <code>groups</code> attribute dictionary containing all of the group
208 instances contained within that group. Each <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance also has a
209 <code>path</code> attribute that contains a simulated unix directory path to
210 that group.
211 To simplify the creation of nested groups, you can
212 use a unix-like path as an argument to <code><a title="netCDF4.Dataset.createGroup" href="#netCDF4.Dataset.createGroup">Dataset.createGroup()</a></code>.</p>
213 <pre><code class="language-python">&gt;&gt;&gt; fcstgrp1 = rootgrp.createGroup(&quot;/forecasts/model1&quot;)
214 &gt;&gt;&gt; fcstgrp2 = rootgrp.createGroup(&quot;/forecasts/model2&quot;)
215 </code></pre>
216 <p>If any of the intermediate elements of the path do not exist, they are created,
217 just as with the unix command <code>'mkdir -p'</code>. If you try to create a group
218 that already exists, no error will be raised, and the existing group will be
219 returned.</p>
220 <p>Here's an example that shows how to navigate all the groups in a
221 <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code>. The function <code>walktree</code> is a Python generator that is used
222 to walk the directory tree. Note that printing the <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code>
223 object yields summary information about it's contents.</p>
224 <pre><code class="language-python">&gt;&gt;&gt; def walktree(top):
225 ... yield top.groups.values()
226 ... for value in top.groups.values():
227 ... yield from walktree(value)
228 &gt;&gt;&gt; print(rootgrp)
229 &lt;class 'netCDF4._netCDF4.Dataset'&gt;
230 root group (NETCDF4 data model, file format HDF5):
231 dimensions(sizes):
232 variables(dimensions):
233 groups: forecasts, analyses
234 &gt;&gt;&gt; for children in walktree(rootgrp):
235 ... for child in children:
236 ... print(child)
237 &lt;class 'netCDF4._netCDF4.Group'&gt;
238 group /forecasts:
239 dimensions(sizes):
240 variables(dimensions):
241 groups: model1, model2
242 &lt;class 'netCDF4._netCDF4.Group'&gt;
243 group /analyses:
244 dimensions(sizes):
245 variables(dimensions):
246 groups:
247 &lt;class 'netCDF4._netCDF4.Group'&gt;
248 group /forecasts/model1:
249 dimensions(sizes):
250 variables(dimensions):
251 groups:
252 &lt;class 'netCDF4._netCDF4.Group'&gt;
253 group /forecasts/model2:
254 dimensions(sizes):
255 variables(dimensions):
256 groups:
257 </code></pre>
258 <h2 id="dimensions-in-a-netcdf-file">Dimensions in a netCDF file</h2>
259 <p>netCDF defines the sizes of all variables in terms of dimensions, so
260 before any variables can be created the dimensions they use must be
261 created first. A special case, not often used in practice, is that of a
262 scalar variable, which has no dimensions. A dimension is created using
263 the <code><a title="netCDF4.Dataset.createDimension" href="#netCDF4.Dataset.createDimension">Dataset.createDimension()</a></code> method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code>
264 or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance. A Python string is used to set the name of the
265 dimension, and an integer value is used to set the size. To create an
266 unlimited dimension (a dimension that can be appended to), the size
267 value is set to <code>None</code> or 0. In this example, there both the <code>time</code> and
268 <code>level</code> dimensions are unlimited.
269 Having more than one unlimited
270 dimension is a new netCDF 4 feature, in netCDF 3 files there may be only
271 one, and it must be the first (leftmost) dimension of the variable.</p>
272 <pre><code class="language-python">&gt;&gt;&gt; level = rootgrp.createDimension(&quot;level&quot;, None)
273 &gt;&gt;&gt; time = rootgrp.createDimension(&quot;time&quot;, None)
274 &gt;&gt;&gt; lat = rootgrp.createDimension(&quot;lat&quot;, 73)
275 &gt;&gt;&gt; lon = rootgrp.createDimension(&quot;lon&quot;, 144)
276 </code></pre>
277 <p>All of the <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> instances are stored in a python dictionary.</p>
278 <pre><code class="language-python">&gt;&gt;&gt; print(rootgrp.dimensions)
279 {'level': &lt;class 'netCDF4._netCDF4.Dimension'&gt; (unlimited): name = 'level', size = 0, 'time': &lt;class 'netCDF4._netCDF4.Dimension'&gt; (unlimited): name = 'time', size = 0, 'lat': &lt;class 'netCDF4._netCDF4.Dimension'&gt;: name = 'lat', size = 73, 'lon': &lt;class 'netCDF4._netCDF4.Dimension'&gt;: name = 'lon', size = 144}
280 </code></pre>
281 <p>Using the python <code>len</code> function with a <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> instance returns
282 current size of that dimension.
283 <code><a title="netCDF4.Dimension.isunlimited" href="#netCDF4.Dimension.isunlimited">Dimension.isunlimited()</a></code> method of a <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> instance
284 be used to determine if the dimensions is unlimited, or appendable.</p>
285 <pre><code class="language-python">&gt;&gt;&gt; print(len(lon))
286 144
287 &gt;&gt;&gt; print(lon.isunlimited())
288 False
289 &gt;&gt;&gt; print(time.isunlimited())
290 True
291 </code></pre>
292 <p>Printing the <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> object
293 provides useful summary info, including the name and length of the dimension,
294 and whether it is unlimited.</p>
295 <pre><code class="language-python">&gt;&gt;&gt; for dimobj in rootgrp.dimensions.values():
296 ... print(dimobj)
297 &lt;class 'netCDF4._netCDF4.Dimension'&gt; (unlimited): name = 'level', size = 0
298 &lt;class 'netCDF4._netCDF4.Dimension'&gt; (unlimited): name = 'time', size = 0
299 &lt;class 'netCDF4._netCDF4.Dimension'&gt;: name = 'lat', size = 73
300 &lt;class 'netCDF4._netCDF4.Dimension'&gt;: name = 'lon', size = 144
301 </code></pre>
302 <p><code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> names can be changed using the
303 <code><a title="netCDF4.Dataset.renameDimension" href="#netCDF4.Dataset.renameDimension">Dataset.renameDimension()</a></code> method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or
304 <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance.</p>
305 <h2 id="variables-in-a-netcdf-file">Variables in a netCDF file</h2>
306 <p>netCDF variables behave much like python multidimensional array objects
307 supplied by the <a href="http://numpy.scipy.org">numpy module</a>. However,
308 unlike numpy arrays, netCDF4 variables can be appended to along one or
309 more 'unlimited' dimensions. To create a netCDF variable, use the
310 <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code> method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or
311 <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance. The <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code> method
312 has two mandatory arguments, the variable name (a Python string), and
313 the variable datatype. The variable's dimensions are given by a tuple
314 containing the dimension names (defined previously with
315 <code><a title="netCDF4.Dataset.createDimension" href="#netCDF4.Dataset.createDimension">Dataset.createDimension()</a></code>). To create a scalar
316 variable, simply leave out the dimensions keyword. The variable
317 primitive datatypes correspond to the dtype attribute of a numpy array.
318 You can specify the datatype as a numpy dtype object, or anything that
319 can be converted to a numpy dtype object. Valid datatype specifiers
320 include:</p>
321 <table>
322 <thead>
323 <tr>
324 <th>Specifier</th>
325 <th>Datatype</th>
326 <th>Old typecodes</th>
327 </tr>
328 </thead>
329 <tbody>
330 <tr>
331 <td><code>'f4'</code></td>
332 <td>32-bit floating point</td>
333 <td><code>'f'</code></td>
334 </tr>
335 <tr>
336 <td><code>'f8'</code></td>
337 <td>64-bit floating point</td>
338 <td><code>'d'</code></td>
339 </tr>
340 <tr>
341 <td><code>'i4'</code></td>
342 <td>32-bit signed integer</td>
343 <td><code>'i'</code> <code>'l'</code></td>
344 </tr>
345 <tr>
346 <td><code>'i2'</code></td>
347 <td>16-bit signed integer</td>
348 <td><code>'h'</code> <code>'s'</code></td>
349 </tr>
350 <tr>
351 <td><code>'i8'</code></td>
352 <td>64-bit signed integer</td>
353 <td></td>
354 </tr>
355 <tr>
356 <td><code>'i1'</code></td>
357 <td>8-bit signed integer</td>
358 <td><code>'b'</code> <code>'B'</code></td>
359 </tr>
360 <tr>
361 <td><code>'u1'</code></td>
362 <td>8-bit unsigned integer</td>
363 <td></td>
364 </tr>
365 <tr>
366 <td><code>'u2'</code></td>
367 <td>16-bit unsigned integer</td>
368 <td></td>
369 </tr>
370 <tr>
371 <td><code>'u4'</code></td>
372 <td>32-bit unsigned integer</td>
373 <td></td>
374 </tr>
375 <tr>
376 <td><code>'u8'</code></td>
377 <td>64-bit unsigned integer</td>
378 <td></td>
379 </tr>
380 <tr>
381 <td><code>'S1'</code></td>
382 <td>single-character string</td>
383 <td><code>'c'</code></td>
384 </tr>
385 </tbody>
386 </table>
387 <p>The unsigned integer types and the 64-bit integer type
388 can only be used if the file format is <code>NETCDF4</code>.</p>
389 <p>The dimensions themselves are usually also defined as variables, called
390 coordinate variables. The <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code>
391 method returns an instance of the <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> class whose methods can be
392 used later to access and set variable data and attributes.</p>
393 <pre><code class="language-python">&gt;&gt;&gt; times = rootgrp.createVariable(&quot;time&quot;,&quot;f8&quot;,(&quot;time&quot;,))
394 &gt;&gt;&gt; levels = rootgrp.createVariable(&quot;level&quot;,&quot;i4&quot;,(&quot;level&quot;,))
395 &gt;&gt;&gt; latitudes = rootgrp.createVariable(&quot;lat&quot;,&quot;f4&quot;,(&quot;lat&quot;,))
396 &gt;&gt;&gt; longitudes = rootgrp.createVariable(&quot;lon&quot;,&quot;f4&quot;,(&quot;lon&quot;,))
397 &gt;&gt;&gt; # two dimensions unlimited
398 &gt;&gt;&gt; temp = rootgrp.createVariable(&quot;temp&quot;,&quot;f4&quot;,(&quot;time&quot;,&quot;level&quot;,&quot;lat&quot;,&quot;lon&quot;,))
399 &gt;&gt;&gt; temp.units = &quot;K&quot;
400 </code></pre>
401 <p>To get summary info on a <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instance in an interactive session,
402 just print it.</p>
403 <pre><code class="language-python">&gt;&gt;&gt; print(temp)
404 &lt;class 'netCDF4._netCDF4.Variable'&gt;
405 float32 temp(time, level, lat, lon)
406 units: K
407 unlimited dimensions: time, level
408 current shape = (0, 0, 73, 144)
409 filling on, default _FillValue of 9.969209968386869e+36 used
410 </code></pre>
411 <p>You can use a path to create a Variable inside a hierarchy of groups.</p>
412 <pre><code class="language-python">&gt;&gt;&gt; ftemp = rootgrp.createVariable(&quot;/forecasts/model1/temp&quot;,&quot;f4&quot;,(&quot;time&quot;,&quot;level&quot;,&quot;lat&quot;,&quot;lon&quot;,))
413 </code></pre>
414 <p>If the intermediate groups do not yet exist, they will be created.</p>
415 <p>You can also query a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance directly to obtain <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> or
416 <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instances using paths.</p>
417 <pre><code class="language-python">&gt;&gt;&gt; print(rootgrp[&quot;/forecasts/model1&quot;]) # a Group instance
418 &lt;class 'netCDF4._netCDF4.Group'&gt;
419 group /forecasts/model1:
420 dimensions(sizes):
421 variables(dimensions): float32 temp(time,level,lat,lon)
422 groups:
423 &gt;&gt;&gt; print(rootgrp[&quot;/forecasts/model1/temp&quot;]) # a Variable instance
424 &lt;class 'netCDF4._netCDF4.Variable'&gt;
425 float32 temp(time, level, lat, lon)
426 path = /forecasts/model1
427 unlimited dimensions: time, level
428 current shape = (0, 0, 73, 144)
429 filling on, default _FillValue of 9.969209968386869e+36 used
430 </code></pre>
431 <p>All of the variables in the <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> are stored in a
432 Python dictionary, in the same way as the dimensions:</p>
433 <pre><code class="language-python">&gt;&gt;&gt; print(rootgrp.variables)
434 {'time': &lt;class 'netCDF4._netCDF4.Variable'&gt;
435 float64 time(time)
436 unlimited dimensions: time
437 current shape = (0,)
438 filling on, default _FillValue of 9.969209968386869e+36 used, 'level': &lt;class 'netCDF4._netCDF4.Variable'&gt;
439 int32 level(level)
440 unlimited dimensions: level
441 current shape = (0,)
442 filling on, default _FillValue of -2147483647 used, 'lat': &lt;class 'netCDF4._netCDF4.Variable'&gt;
443 float32 lat(lat)
444 unlimited dimensions:
445 current shape = (73,)
446 filling on, default _FillValue of 9.969209968386869e+36 used, 'lon': &lt;class 'netCDF4._netCDF4.Variable'&gt;
447 float32 lon(lon)
448 unlimited dimensions:
449 current shape = (144,)
450 filling on, default _FillValue of 9.969209968386869e+36 used, 'temp': &lt;class 'netCDF4._netCDF4.Variable'&gt;
451 float32 temp(time, level, lat, lon)
452 units: K
453 unlimited dimensions: time, level
454 current shape = (0, 0, 73, 144)
455 filling on, default _FillValue of 9.969209968386869e+36 used}
456 </code></pre>
457 <p><code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> names can be changed using the
458 <code><a title="netCDF4.Dataset.renameVariable" href="#netCDF4.Dataset.renameVariable">Dataset.renameVariable()</a></code> method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code>
459 instance.</p>
460 <p>Variables can be sliced similar to numpy arrays, but there are some differences.
461 See
462 <a href="#writing-data-to-and-retrieving-data-from-a-netcdf-variable">Writing data to and retrieving data from a netCDF variable</a> for more details.</p>
463 <h2 id="attributes-in-a-netcdf-file">Attributes in a netCDF file</h2>
464 <p>There are two types of attributes in a netCDF file, global and variable.
465 Global attributes provide information about a group, or the entire
466 dataset, as a whole. <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> attributes provide information about
467 one of the variables in a group. Global attributes are set by assigning
468 values to <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance variables. <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code>
469 attributes are set by assigning values to <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instances
470 variables. Attributes can be strings, numbers or sequences. Returning to
471 our example,</p>
472 <pre><code class="language-python">&gt;&gt;&gt; import time
473 &gt;&gt;&gt; rootgrp.description = &quot;bogus example script&quot;
474 &gt;&gt;&gt; rootgrp.history = &quot;Created &quot; + time.ctime(time.time())
475 &gt;&gt;&gt; rootgrp.source = &quot;netCDF4 python module tutorial&quot;
476 &gt;&gt;&gt; latitudes.units = &quot;degrees north&quot;
477 &gt;&gt;&gt; longitudes.units = &quot;degrees east&quot;
478 &gt;&gt;&gt; levels.units = &quot;hPa&quot;
479 &gt;&gt;&gt; temp.units = &quot;K&quot;
480 &gt;&gt;&gt; times.units = &quot;hours since 0001-01-01 00:00:00.0&quot;
481 &gt;&gt;&gt; times.calendar = &quot;gregorian&quot;
482 </code></pre>
483 <p>The <code><a title="netCDF4.Dataset.ncattrs" href="#netCDF4.Dataset.ncattrs">Dataset.ncattrs()</a></code> method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code>, <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> or
484 <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instance can be used to retrieve the names of all the netCDF
485 attributes. This method is provided as a convenience, since using the
486 built-in <code>dir</code> Python function will return a bunch of private methods
487 and attributes that cannot (or should not) be modified by the user.</p>
488 <pre><code class="language-python">&gt;&gt;&gt; for name in rootgrp.ncattrs():
489 ... print(&quot;Global attr {} = {}&quot;.format(name, getattr(rootgrp, name)))
490 Global attr description = bogus example script
491 Global attr history = Created Mon Jul 8 14:19:41 2019
492 Global attr source = netCDF4 python module tutorial
493 </code></pre>
494 <p>The <code>__dict__</code> attribute of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code>, <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> or <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code>
495 instance provides all the netCDF attribute name/value pairs in a python
496 dictionary:</p>
497 <pre><code class="language-python">&gt;&gt;&gt; print(rootgrp.__dict__)
498 {'description': 'bogus example script', 'history': 'Created Mon Jul 8 14:19:41 2019', 'source': 'netCDF4 python module tutorial'}
499 </code></pre>
500 <p>Attributes can be deleted from a netCDF <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code>, <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> or
501 <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> using the python <code>del</code> statement (i.e. <code>del grp.foo</code>
502 removes the attribute <code>foo</code> the the group <code>grp</code>).</p>
503 <h2 id="writing-data-to-and-retrieving-data-from-a-netcdf-variable">Writing data to and retrieving data from a netCDF variable</h2>
504 <p>Now that you have a netCDF <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instance, how do you put data
505 into it? You can just treat it like an array and assign data to a slice.</p>
506 <pre><code class="language-python">&gt;&gt;&gt; import numpy as np
507 &gt;&gt;&gt; lats = np.arange(-90,91,2.5)
508 &gt;&gt;&gt; lons = np.arange(-180,180,2.5)
509 &gt;&gt;&gt; latitudes[:] = lats
510 &gt;&gt;&gt; longitudes[:] = lons
511 &gt;&gt;&gt; print(&quot;latitudes =\n{}&quot;.format(latitudes[:]))
512 latitudes =
513 [-90. -87.5 -85. -82.5 -80. -77.5 -75. -72.5 -70. -67.5 -65. -62.5
514 -60. -57.5 -55. -52.5 -50. -47.5 -45. -42.5 -40. -37.5 -35. -32.5
515 -30. -27.5 -25. -22.5 -20. -17.5 -15. -12.5 -10. -7.5 -5. -2.5
516 0. 2.5 5. 7.5 10. 12.5 15. 17.5 20. 22.5 25. 27.5
517 30. 32.5 35. 37.5 40. 42.5 45. 47.5 50. 52.5 55. 57.5
518 60. 62.5 65. 67.5 70. 72.5 75. 77.5 80. 82.5 85. 87.5
519 90. ]
520 </code></pre>
521 <p>Unlike NumPy's array objects, netCDF <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code>
522 objects with unlimited dimensions will grow along those dimensions if you
523 assign data outside the currently defined range of indices.</p>
524 <pre><code class="language-python">&gt;&gt;&gt; # append along two unlimited dimensions by assigning to slice.
525 &gt;&gt;&gt; nlats = len(rootgrp.dimensions[&quot;lat&quot;])
526 &gt;&gt;&gt; nlons = len(rootgrp.dimensions[&quot;lon&quot;])
527 &gt;&gt;&gt; print(&quot;temp shape before adding data = {}&quot;.format(temp.shape))
528 temp shape before adding data = (0, 0, 73, 144)
529 &gt;&gt;&gt;
530 &gt;&gt;&gt; from numpy.random import uniform
531 &gt;&gt;&gt; temp[0:5, 0:10, :, :] = uniform(size=(5, 10, nlats, nlons))
532 &gt;&gt;&gt; print(&quot;temp shape after adding data = {}&quot;.format(temp.shape))
533 temp shape after adding data = (5, 10, 73, 144)
534 &gt;&gt;&gt;
535 &gt;&gt;&gt; # levels have grown, but no values yet assigned.
536 &gt;&gt;&gt; print(&quot;levels shape after adding pressure data = {}&quot;.format(levels.shape))
537 levels shape after adding pressure data = (10,)
538 </code></pre>
539 <p>Note that the size of the levels variable grows when data is appended
540 along the <code>level</code> dimension of the variable <code>temp</code>, even though no
541 data has yet been assigned to levels.</p>
542 <pre><code class="language-python">&gt;&gt;&gt; # now, assign data to levels dimension variable.
543 &gt;&gt;&gt; levels[:] = [1000.,850.,700.,500.,300.,250.,200.,150.,100.,50.]
544 </code></pre>
545 <p>However, that there are some differences between NumPy and netCDF
546 variable slicing rules. Slices behave as usual, being specified as a
547 <code>start:stop:step</code> triplet. Using a scalar integer index <code>i</code> takes the ith
548 element and reduces the rank of the output array by one. Boolean array and
549 integer sequence indexing behaves differently for netCDF variables
550 than for numpy arrays.
551 Only 1-d boolean arrays and integer sequences are
552 allowed, and these indices work independently along each dimension (similar
553 to the way vector subscripts work in fortran).
554 This means that</p>
555 <pre><code class="language-python">&gt;&gt;&gt; temp[0, 0, [0,1,2,3], [0,1,2,3]].shape
556 (4, 4)
557 </code></pre>
558 <p>returns an array of shape (4,4) when slicing a netCDF variable, but for a
559 numpy array it returns an array of shape (4,).
560 Similarly, a netCDF variable of shape <code>(2,3,4,5)</code> indexed
561 with <code>[0, array([True, False, True]), array([False, True, True, True]), :]</code>
562 would return a <code>(2, 3, 5)</code> array. In NumPy, this would raise an error since
563 it would be equivalent to <code>[0, [0,1], [1,2,3], :]</code>. When slicing with integer
564 sequences, the indices <strong><em>need not be sorted</em></strong> and <strong><em>may contain
565 duplicates</em></strong> (both of these are new features in version 1.2.1).
566 While this behaviour may cause some confusion for those used to NumPy's 'fancy indexing' rules,
567 it provides a very powerful way to extract data from multidimensional netCDF
568 variables by using logical operations on the dimension arrays to create slices.</p>
569 <p>For example,</p>
570 <pre><code class="language-python">&gt;&gt;&gt; tempdat = temp[::2, [1,3,6], lats&gt;0, lons&gt;0]
571 </code></pre>
572 <p>will extract time indices 0,2 and 4, pressure levels
573 850, 500 and 200 hPa, all Northern Hemisphere latitudes and Eastern
574 Hemisphere longitudes, resulting in a numpy array of shape
575 (3, 3, 36, 71).</p>
576 <pre><code class="language-python">&gt;&gt;&gt; print(&quot;shape of fancy temp slice = {}&quot;.format(tempdat.shape))
577 shape of fancy temp slice = (3, 3, 36, 71)
578 </code></pre>
579 <p><strong><em>Special note for scalar variables</em></strong>: To extract data from a scalar variable
580 <code>v</code> with no associated dimensions, use <code>numpy.asarray(v)</code> or <code>v[&hellip;]</code>.
581 The result will be a numpy scalar array.</p>
582 <p>By default, netcdf4-python returns numpy masked arrays with values equal to the
583 <code>missing_value</code> or <code>_FillValue</code> variable attributes masked for primitive and
584 enum data types.
585 The <code><a title="netCDF4.Dataset.set_auto_mask" href="#netCDF4.Dataset.set_auto_mask">Dataset.set_auto_mask()</a></code> <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> and <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> methods
586 can be used to disable this feature so that
587 numpy arrays are always returned, with the missing values included. Prior to
588 version 1.4.0 the default behavior was to only return masked arrays when the
589 requested slice contained missing values.
590 This behavior can be recovered
591 using the <code><a title="netCDF4.Dataset.set_always_mask" href="#netCDF4.Dataset.set_always_mask">Dataset.set_always_mask()</a></code> method. If a masked array is
592 written to a netCDF variable, the masked elements are filled with the
593 value specified by the <code>missing_value</code> attribute.
594 If the variable has
595 no <code>missing_value</code>, the <code>_FillValue</code> is used instead.</p>
596 <h2 id="dealing-with-time-coordinates">Dealing with time coordinates</h2>
597 <p>Time coordinate values pose a special challenge to netCDF users.
598 Most
599 metadata standards (such as CF) specify that time should be
600 measure relative to a fixed date using a certain calendar, with units
601 specified like <code>hours since YY-MM-DD hh:mm:ss</code>.
602 These units can be
603 awkward to deal with, without a utility to convert the values to and
604 from calendar dates.
605 The functions <a href="https://unidata.github.io/cftime/api.html">num2date</a>
606 and <a href="https://unidata.github.io/cftime/api.html">date2num</a> are
607 provided by <a href="https://unidata.github.io/cftime">cftime</a> to do just that.
608 Here's an example of how they can be used:</p>
609 <pre><code class="language-python">&gt;&gt;&gt; # fill in times.
610 &gt;&gt;&gt; from datetime import datetime, timedelta
611 &gt;&gt;&gt; from cftime import num2date, date2num
612 &gt;&gt;&gt; dates = [datetime(2001,3,1)+n*timedelta(hours=12) for n in range(temp.shape[0])]
613 &gt;&gt;&gt; times[:] = date2num(dates,units=times.units,calendar=times.calendar)
614 &gt;&gt;&gt; print(&quot;time values (in units {}):\n{}&quot;.format(times.units, times[:]))
615 time values (in units hours since 0001-01-01 00:00:00.0):
616 [17533104. 17533116. 17533128. 17533140. 17533152.]
617 &gt;&gt;&gt; dates = num2date(times[:],units=times.units,calendar=times.calendar)
618 &gt;&gt;&gt; print(&quot;dates corresponding to time values:\n{}&quot;.format(dates))
619 [cftime.DatetimeGregorian(2001, 3, 1, 0, 0, 0, 0, has_year_zero=False)
620 cftime.DatetimeGregorian(2001, 3, 1, 12, 0, 0, 0, has_year_zero=False)
621 cftime.DatetimeGregorian(2001, 3, 2, 0, 0, 0, 0, has_year_zero=False)
622 cftime.DatetimeGregorian(2001, 3, 2, 12, 0, 0, 0, has_year_zero=False)
623 cftime.DatetimeGregorian(2001, 3, 3, 0, 0, 0, 0, has_year_zero=False)]
624 </code></pre>
625 <p><code><a title="netCDF4.num2date" href="#netCDF4.num2date">num2date()</a></code> converts numeric values of time in the specified <code>units</code>
626 and <code>calendar</code> to datetime objects, and <code><a title="netCDF4.date2num" href="#netCDF4.date2num">date2num()</a></code> does the reverse.
627 All the calendars currently defined in the
628 <a href="http://cfconventions.org">CF metadata convention</a> are supported.
629 A function called <code><a title="netCDF4.date2index" href="#netCDF4.date2index">date2index()</a></code> is also provided which returns the indices
630 of a netCDF time variable corresponding to a sequence of datetime instances.</p>
631 <h2 id="reading-data-from-a-multi-file-netcdf-dataset">Reading data from a multi-file netCDF dataset</h2>
632 <p>If you want to read data from a variable that spans multiple netCDF files,
633 you can use the <code><a title="netCDF4.MFDataset" href="#netCDF4.MFDataset">MFDataset</a></code> class to read the data as if it were
634 contained in a single file. Instead of using a single filename to create
635 a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> instance, create a <code><a title="netCDF4.MFDataset" href="#netCDF4.MFDataset">MFDataset</a></code> instance with either a list
636 of filenames, or a string with a wildcard (which is then converted to
637 a sorted list of files using the python glob module).
638 Variables in the list of files that share the same unlimited
639 dimension are aggregated together, and can be sliced across multiple
640 files.
641 To illustrate this, let's first create a bunch of netCDF files with
642 the same variable (with the same unlimited dimension).
643 The files
644 must in be in <code>NETCDF3_64BIT_OFFSET</code>, <code>NETCDF3_64BIT_DATA</code>, <code>NETCDF3_CLASSIC</code> or
645 <code>NETCDF4_CLASSIC</code> format (<code>NETCDF4</code> formatted multi-file
646 datasets are not supported).</p>
647 <pre><code class="language-python">&gt;&gt;&gt; for nf in range(10):
648 ... with Dataset(&quot;mftest%s.nc&quot; % nf, &quot;w&quot;, format=&quot;NETCDF4_CLASSIC&quot;) as f:
649 ... _ = f.createDimension(&quot;x&quot;,None)
650 ... x = f.createVariable(&quot;x&quot;,&quot;i&quot;,(&quot;x&quot;,))
651 ... x[0:10] = np.arange(nf*10,10*(nf+1))
652 </code></pre>
653 <p>Now read all the files back in at once with <code><a title="netCDF4.MFDataset" href="#netCDF4.MFDataset">MFDataset</a></code></p>
654 <pre><code class="language-python">&gt;&gt;&gt; from netCDF4 import MFDataset
655 &gt;&gt;&gt; f = MFDataset(&quot;mftest*nc&quot;)
656 &gt;&gt;&gt; print(f.variables[&quot;x&quot;][:])
657 [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
658 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
659 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
660 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
661 96 97 98 99]
662 </code></pre>
663 <p>Note that <code><a title="netCDF4.MFDataset" href="#netCDF4.MFDataset">MFDataset</a></code> can only be used to read, not write, multi-file
664 datasets.</p>
665 <h2 id="efficient-compression-of-netcdf-variables">Efficient compression of netCDF variables</h2>
666 <p>Data stored in netCDF <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> objects can be compressed and
667 decompressed on the fly. The compression algorithm used is determined
668 by the <code>compression</code> keyword argument to the <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code> method.
669 <code>zlib</code> compression is always available, <code>szip</code> is available if the linked HDF5
670 library supports it, and <code>zstd</code>, <code>bzip2</code>, <code>blosc_lz</code>,<code>blosc_lz4</code>,<code>blosc_lz4hc</code>,
671 <code>blosc_zlib</code> and <code>blosc_zstd</code> are available via optional external plugins.
672 The <code>complevel</code> keyword regulates the
673 speed and efficiency of the compression for <code>zlib</code>, <code>bzip</code> and <code>zstd</code> (1 being fastest, but lowest
674 compression ratio, 9 being slowest but best compression ratio). The
675 default value of <code>complevel</code> is 4. Setting <code>shuffle=False</code> will turn
676 off the HDF5 shuffle filter, which de-interlaces a block of data before
677 <code>zlib</code> compression by reordering the bytes.
678 The shuffle filter can
679 significantly improve compression ratios, and is on by default if <code>compression=zlib</code>.
680 Setting
681 <code>fletcher32</code> keyword argument to
682 <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code> to <code>True</code> (it's <code>False</code> by
683 default) enables the Fletcher32 checksum algorithm for error detection.
684 It's also possible to set the HDF5 chunking parameters and endian-ness
685 of the binary data stored in the HDF5 file with the <code>chunksizes</code>
686 and <code>endian</code> keyword arguments to
687 <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code>.
688 These keyword arguments only
689 are relevant for <code>NETCDF4</code> and <code>NETCDF4_CLASSIC</code> files (where the
690 underlying file format is HDF5) and are silently ignored if the file
691 format is <code>NETCDF3_CLASSIC</code>, <code>NETCDF3_64BIT_OFFSET</code> or <code>NETCDF3_64BIT_DATA</code>.
692 If the HDF5 library is built with szip support, compression=<code>szip</code> can also
693 be used (in conjunction with the <code>szip_coding</code> and <code>szip_pixels_per_block</code> keyword
694 arguments).</p>
695 <p>If your data only has a certain number of digits of precision (say for
696 example, it is temperature data that was measured with a precision of
697 0.1 degrees), you can dramatically improve compression by
698 quantizing (or truncating) the data. There are two methods supplied for
699 doing this.
700 You can use the <code>least_significant_digit</code>
701 keyword argument to <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code> to specify
702 the power of ten of the smallest decimal place in
703 the data that is a reliable value. For example if the data has a
704 precision of 0.1, then setting <code>least_significant_digit=1</code> will cause
705 data the data to be quantized using <code>numpy.around(scale*data)/scale</code>, where
706 scale = 2**bits, and bits is determined so that a precision of 0.1 is
707 retained (in this case bits=4).
708 This is done at the python level and is
709 not a part of the underlying C library.
710 Starting with netcdf-c version 4.9.0,
711 a quantization capability is provided in the library.
712 This can be
713 used via the <code>significant_digits</code> <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code> kwarg (new in
714 version 1.6.0).
715 The interpretation of <code>significant_digits</code> is different than <code>least_signficant_digit</code>
716 in that it specifies the absolute number of significant digits independent
717 of the magnitude of the variable (the floating point exponent).
718 Either of these approaches makes the compression
719 'lossy' instead of 'lossless', that is some precision in the data is
720 sacrificed for the sake of disk space.</p>
721 <p>In our example, try replacing the line</p>
722 <pre><code class="language-python">&gt;&gt;&gt; temp = rootgrp.createVariable(&quot;temp&quot;,&quot;f4&quot;,(&quot;time&quot;,&quot;level&quot;,&quot;lat&quot;,&quot;lon&quot;,))
723 </code></pre>
724 <p>with</p>
725 <pre><code class="language-python">&gt;&gt;&gt; temp = rootgrp.createVariable(&quot;temp&quot;,&quot;f4&quot;,(&quot;time&quot;,&quot;level&quot;,&quot;lat&quot;,&quot;lon&quot;,),compression='zlib')
726 </code></pre>
727 <p>and then</p>
728 <pre><code class="language-python">&gt;&gt;&gt; temp = rootgrp.createVariable(&quot;temp&quot;,&quot;f4&quot;,(&quot;time&quot;,&quot;level&quot;,&quot;lat&quot;,&quot;lon&quot;,),compression='zlib',least_significant_digit=3)
729 </code></pre>
730 <p>or with netcdf-c &gt;= 4.9.0</p>
731 <pre><code class="language-python">&gt;&gt;&gt; temp = rootgrp.createVariable(&quot;temp&quot;,&quot;f4&quot;,(&quot;time&quot;,&quot;level&quot;,&quot;lat&quot;,&quot;lon&quot;,),compression='zlib',significant_digits=4)
732 </code></pre>
733 <p>and see how much smaller the resulting files are.</p>
734 <h2 id="beyond-homogeneous-arrays-of-a-fixed-type-compound-data-types">Beyond homogeneous arrays of a fixed type - compound data types</h2>
735 <p>Compound data types map directly to numpy structured (a.k.a 'record')
736 arrays.
737 Structured arrays are akin to C structs, or derived types
738 in Fortran. They allow for the construction of table-like structures
739 composed of combinations of other data types, including other
740 compound types. Compound types might be useful for representing multiple
741 parameter values at each point on a grid, or at each time and space
742 location for scattered (point) data. You can then access all the
743 information for a point by reading one variable, instead of reading
744 different parameters from different variables.
745 Compound data types
746 are created from the corresponding numpy data type using the
747 <code><a title="netCDF4.Dataset.createCompoundType" href="#netCDF4.Dataset.createCompoundType">Dataset.createCompoundType()</a></code> method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance.
748 Since there is no native complex data type in netcdf (but see
749 <a href="#support-for-complex-numbers">Support for complex numbers</a>), compound
750 types are handy for storing numpy complex arrays. Here's an example:</p>
751 <pre><code class="language-python">&gt;&gt;&gt; f = Dataset(&quot;complex.nc&quot;,&quot;w&quot;)
752 &gt;&gt;&gt; size = 3 # length of 1-d complex array
753 &gt;&gt;&gt; # create sample complex data.
754 &gt;&gt;&gt; datac = np.exp(1j*(1.+np.linspace(0, np.pi, size)))
755 &gt;&gt;&gt; # create complex128 compound data type.
756 &gt;&gt;&gt; complex128 = np.dtype([(&quot;real&quot;,np.float64),(&quot;imag&quot;,np.float64)])
757 &gt;&gt;&gt; complex128_t = f.createCompoundType(complex128,&quot;complex128&quot;)
758 &gt;&gt;&gt; # create a variable with this data type, write some data to it.
759 &gt;&gt;&gt; x_dim = f.createDimension(&quot;x_dim&quot;,None)
760 &gt;&gt;&gt; v = f.createVariable(&quot;cmplx_var&quot;,complex128_t,&quot;x_dim&quot;)
761 &gt;&gt;&gt; data = np.empty(size,complex128) # numpy structured array
762 &gt;&gt;&gt; data[&quot;real&quot;] = datac.real; data[&quot;imag&quot;] = datac.imag
763 &gt;&gt;&gt; v[:] = data # write numpy structured array to netcdf compound var
764 &gt;&gt;&gt; # close and reopen the file, check the contents.
765 &gt;&gt;&gt; f.close(); f = Dataset(&quot;complex.nc&quot;)
766 &gt;&gt;&gt; v = f.variables[&quot;cmplx_var&quot;]
767 &gt;&gt;&gt; datain = v[:] # read in all the data into a numpy structured array
768 &gt;&gt;&gt; # create an empty numpy complex array
769 &gt;&gt;&gt; datac2 = np.empty(datain.shape,np.complex128)
770 &gt;&gt;&gt; # .. fill it with contents of structured array.
771 &gt;&gt;&gt; datac2.real = datain[&quot;real&quot;]; datac2.imag = datain[&quot;imag&quot;]
772 &gt;&gt;&gt; print('{}: {}'.format(datac.dtype, datac)) # original data
773 complex128: [ 0.54030231+0.84147098j -0.84147098+0.54030231j -0.54030231-0.84147098j]
774 &gt;&gt;&gt;
775 &gt;&gt;&gt; print('{}: {}'.format(datac2.dtype, datac2)) # data from file
776 complex128: [ 0.54030231+0.84147098j -0.84147098+0.54030231j -0.54030231-0.84147098j]
777 </code></pre>
778 <p>Compound types can be nested, but you must create the 'inner'
779 ones first. All possible numpy structured arrays cannot be
780 represented as Compound variables - an error message will be
781 raise if you try to create one that is not supported.
782 All of the compound types defined for a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> are stored
783 in a Python dictionary, just like variables and dimensions. As always, printing
784 objects gives useful summary information in an interactive session:</p>
785 <pre><code class="language-python">&gt;&gt;&gt; print(f)
786 &lt;class 'netCDF4._netCDF4.Dataset'&gt;
787 root group (NETCDF4 data model, file format HDF5):
788 dimensions(sizes): x_dim(3)
789 variables(dimensions): {'names':['real','imag'], 'formats':['&lt;f8','&lt;f8'], 'offsets':[0,8], 'itemsize':16, 'aligned':True} cmplx_var(x_dim)
790 groups:
791 &gt;&gt;&gt; print(f.variables[&quot;cmplx_var&quot;])
792 &lt;class 'netCDF4._netCDF4.Variable'&gt;
793 compound cmplx_var(x_dim)
794 compound data type: {'names':['real','imag'], 'formats':['&lt;f8','&lt;f8'], 'offsets':[0,8], 'itemsize':16, 'aligned':True}
795 unlimited dimensions: x_dim
796 current shape = (3,)
797 &gt;&gt;&gt; print(f.cmptypes)
798 {'complex128': &lt;class 'netCDF4._netCDF4.CompoundType'&gt;: name = 'complex128', numpy dtype = {'names':['real','imag'], 'formats':['&lt;f8','&lt;f8'], 'offsets':[0,8], 'itemsize':16, 'aligned':True}}
799 &gt;&gt;&gt; print(f.cmptypes[&quot;complex128&quot;])
800 &lt;class 'netCDF4._netCDF4.CompoundType'&gt;: name = 'complex128', numpy dtype = {'names':['real','imag'], 'formats':['&lt;f8','&lt;f8'], 'offsets':[0,8], 'itemsize':16, 'aligned':True}
801 </code></pre>
802 <h2 id="variable-length-vlen-data-types">Variable-length (vlen) data types</h2>
803 <p>NetCDF 4 has support for variable-length or "ragged" arrays.
804 These are arrays
805 of variable length sequences having the same type. To create a variable-length
806 data type, use the <code><a title="netCDF4.Dataset.createVLType" href="#netCDF4.Dataset.createVLType">Dataset.createVLType()</a></code> method
807 method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance.</p>
808 <pre><code class="language-python">&gt;&gt;&gt; f = Dataset(&quot;tst_vlen.nc&quot;,&quot;w&quot;)
809 &gt;&gt;&gt; vlen_t = f.createVLType(np.int32, &quot;phony_vlen&quot;)
810 </code></pre>
811 <p>The numpy datatype of the variable-length sequences and the name of the
812 new datatype must be specified. Any of the primitive datatypes can be
813 used (signed and unsigned integers, 32 and 64 bit floats, and characters),
814 but compound data types cannot.
815 A new variable can then be created using this datatype.</p>
816 <pre><code class="language-python">&gt;&gt;&gt; x = f.createDimension(&quot;x&quot;,3)
817 &gt;&gt;&gt; y = f.createDimension(&quot;y&quot;,4)
818 &gt;&gt;&gt; vlvar = f.createVariable(&quot;phony_vlen_var&quot;, vlen_t, (&quot;y&quot;,&quot;x&quot;))
819 </code></pre>
820 <p>Since there is no native vlen datatype in numpy, vlen arrays are represented
821 in python as object arrays (arrays of dtype <code>object</code>). These are arrays whose
822 elements are Python object pointers, and can contain any type of python object.
823 For this application, they must contain 1-D numpy arrays all of the same type
824 but of varying length.
825 In this case, they contain 1-D numpy <code>int32</code> arrays of random length between
826 1 and 10.</p>
827 <pre><code class="language-python">&gt;&gt;&gt; import random
828 &gt;&gt;&gt; random.seed(54321)
829 &gt;&gt;&gt; data = np.empty(len(y)*len(x),object)
830 &gt;&gt;&gt; for n in range(len(y)*len(x)):
831 ... data[n] = np.arange(random.randint(1,10),dtype=&quot;int32&quot;)+1
832 &gt;&gt;&gt; data = np.reshape(data,(len(y),len(x)))
833 &gt;&gt;&gt; vlvar[:] = data
834 &gt;&gt;&gt; print(&quot;vlen variable =\n{}&quot;.format(vlvar[:]))
835 vlen variable =
836 [[array([1, 2, 3, 4, 5, 6, 7, 8], dtype=int32) array([1, 2], dtype=int32)
837 array([1, 2, 3, 4], dtype=int32)]
838 [array([1, 2, 3], dtype=int32)
839 array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int32)
840 array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int32)]
841 [array([1, 2, 3, 4, 5, 6, 7], dtype=int32) array([1, 2, 3], dtype=int32)
842 array([1, 2, 3, 4, 5, 6], dtype=int32)]
843 [array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int32)
844 array([1, 2, 3, 4, 5], dtype=int32) array([1, 2], dtype=int32)]]
845 &gt;&gt;&gt; print(f)
846 &lt;class 'netCDF4._netCDF4.Dataset'&gt;
847 root group (NETCDF4 data model, file format HDF5):
848 dimensions(sizes): x(3), y(4)
849 variables(dimensions): int32 phony_vlen_var(y,x)
850 groups:
851 &gt;&gt;&gt; print(f.variables[&quot;phony_vlen_var&quot;])
852 &lt;class 'netCDF4._netCDF4.Variable'&gt;
853 vlen phony_vlen_var(y, x)
854 vlen data type: int32
855 unlimited dimensions:
856 current shape = (4, 3)
857 &gt;&gt;&gt; print(f.vltypes[&quot;phony_vlen&quot;])
858 &lt;class 'netCDF4._netCDF4.VLType'&gt;: name = 'phony_vlen', numpy dtype = int32
859 </code></pre>
860 <p>Numpy object arrays containing python strings can also be written as vlen
861 variables,
862 For vlen strings, you don't need to create a vlen data type.
863 Instead, simply use the python <code>str</code> builtin (or a numpy string datatype
864 with fixed length greater than 1) when calling the
865 <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code> method.</p>
866 <pre><code class="language-python">&gt;&gt;&gt; z = f.createDimension(&quot;z&quot;,10)
867 &gt;&gt;&gt; strvar = f.createVariable(&quot;strvar&quot;, str, &quot;z&quot;)
868 </code></pre>
869 <p>In this example, an object array is filled with random python strings with
870 random lengths between 2 and 12 characters, and the data in the object
871 array is assigned to the vlen string variable.</p>
872 <pre><code class="language-python">&gt;&gt;&gt; chars = &quot;1234567890aabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;
873 &gt;&gt;&gt; data = np.empty(10,&quot;O&quot;)
874 &gt;&gt;&gt; for n in range(10):
875 ... stringlen = random.randint(2,12)
876 ... data[n] = &quot;&quot;.join([random.choice(chars) for i in range(stringlen)])
877 &gt;&gt;&gt; strvar[:] = data
878 &gt;&gt;&gt; print(&quot;variable-length string variable:\n{}&quot;.format(strvar[:]))
879 variable-length string variable:
880 ['Lh' '25F8wBbMI' '53rmM' 'vvjnb3t63ao' 'qjRBQk6w' 'aJh' 'QF'
881 'jtIJbJACaQk4' '3Z5' 'bftIIq']
882 &gt;&gt;&gt; print(f)
883 &lt;class 'netCDF4._netCDF4.Dataset'&gt;
884 root group (NETCDF4 data model, file format HDF5):
885 dimensions(sizes): x(3), y(4), z(10)
886 variables(dimensions): int32 phony_vlen_var(y,x), &lt;class 'str'&gt; strvar(z)
887 groups:
888 &gt;&gt;&gt; print(f.variables[&quot;strvar&quot;])
889 &lt;class 'netCDF4._netCDF4.Variable'&gt;
890 vlen strvar(z)
891 vlen data type: &lt;class 'str'&gt;
892 unlimited dimensions:
893 current shape = (10,)
894 </code></pre>
895 <p>It is also possible to set contents of vlen string variables with numpy arrays
896 of any string or unicode data type. Note, however, that accessing the contents
897 of such variables will always return numpy arrays with dtype <code>object</code>.</p>
898 <h2 id="enum-data-type">Enum data type</h2>
899 <p>netCDF4 has an enumerated data type, which is an integer datatype that is
900 restricted to certain named values. Since Enums don't map directly to
901 a numpy data type, they are read and written as integer arrays.</p>
902 <p>Here's an example of using an Enum type to hold cloud type data.
903 The base integer data type and a python dictionary describing the allowed
904 values and their names are used to define an Enum data type using
905 <code><a title="netCDF4.Dataset.createEnumType" href="#netCDF4.Dataset.createEnumType">Dataset.createEnumType()</a></code>.</p>
906 <pre><code class="language-python">&gt;&gt;&gt; nc = Dataset('clouds.nc','w')
907 &gt;&gt;&gt; # python dict with allowed values and their names.
908 &gt;&gt;&gt; enum_dict = {'Altocumulus': 7, 'Missing': 255,
909 ... 'Stratus': 2, 'Clear': 0,
910 ... 'Nimbostratus': 6, 'Cumulus': 4, 'Altostratus': 5,
911 ... 'Cumulonimbus': 1, 'Stratocumulus': 3}
912 &gt;&gt;&gt; # create the Enum type called 'cloud_t'.
913 &gt;&gt;&gt; cloud_type = nc.createEnumType(np.uint8,'cloud_t',enum_dict)
914 &gt;&gt;&gt; print(cloud_type)
915 &lt;class 'netCDF4._netCDF4.EnumType'&gt;: name = 'cloud_t', numpy dtype = uint8, fields/values ={'Altocumulus': 7, 'Missing': 255, 'Stratus': 2, 'Clear': 0, 'Nimbostratus': 6, 'Cumulus': 4, 'Altostratus': 5, 'Cumulonimbus': 1, 'Stratocumulus': 3}
916 </code></pre>
917 <p>A new variable can be created in the usual way using this data type.
918 Integer data is written to the variable that represents the named
919 cloud types in enum_dict. A <code>ValueError</code> will be raised if an attempt
920 is made to write an integer value not associated with one of the
921 specified names.</p>
922 <pre><code class="language-python">&gt;&gt;&gt; time = nc.createDimension('time',None)
923 &gt;&gt;&gt; # create a 1d variable of type 'cloud_type'.
924 &gt;&gt;&gt; # The fill_value is set to the 'Missing' named value.
925 &gt;&gt;&gt; cloud_var = nc.createVariable('primary_cloud',cloud_type,'time',
926 ... fill_value=enum_dict['Missing'])
927 &gt;&gt;&gt; # write some data to the variable.
928 &gt;&gt;&gt; cloud_var[:] = [enum_dict[k] for k in ['Clear', 'Stratus', 'Cumulus',
929 ... 'Missing', 'Cumulonimbus']]
930 &gt;&gt;&gt; nc.close()
931 &gt;&gt;&gt; # reopen the file, read the data.
932 &gt;&gt;&gt; nc = Dataset('clouds.nc')
933 &gt;&gt;&gt; cloud_var = nc.variables['primary_cloud']
934 &gt;&gt;&gt; print(cloud_var)
935 &lt;class 'netCDF4._netCDF4.Variable'&gt;
936 enum primary_cloud(time)
937 _FillValue: 255
938 enum data type: uint8
939 unlimited dimensions: time
940 current shape = (5,)
941 &gt;&gt;&gt; print(cloud_var.datatype.enum_dict)
942 {'Altocumulus': 7, 'Missing': 255, 'Stratus': 2, 'Clear': 0, 'Nimbostratus': 6, 'Cumulus': 4, 'Altostratus': 5, 'Cumulonimbus': 1, 'Stratocumulus': 3}
943 &gt;&gt;&gt; print(cloud_var[:])
944 [0 2 4 -- 1]
945 &gt;&gt;&gt; nc.close()
946 </code></pre>
947 <h2 id="parallel-io">Parallel IO</h2>
948 <p>If MPI parallel enabled versions of netcdf and hdf5 or pnetcdf are detected,
949 and <a href="https://mpi4py.scipy.org">mpi4py</a> is installed, netcdf4-python will
950 be built with parallel IO capabilities enabled. Parallel IO of NETCDF4 or
951 NETCDF4_CLASSIC formatted files is only available if the MPI parallel HDF5
952 library is available. Parallel IO of classic netcdf-3 file formats is only
953 available if the <a href="https://parallel-netcdf.github.io/">PnetCDF</a> library is
954 available. To use parallel IO, your program must be running in an MPI
955 environment using <a href="https://mpi4py.scipy.org">mpi4py</a>.</p>
956 <pre><code class="language-python">&gt;&gt;&gt; from mpi4py import MPI
957 &gt;&gt;&gt; import numpy as np
958 &gt;&gt;&gt; from netCDF4 import Dataset
959 &gt;&gt;&gt; rank = MPI.COMM_WORLD.rank # The process ID (integer 0-3 for 4-process run)
960 </code></pre>
961 <p>To run an MPI-based parallel program like this, you must use <code>mpiexec</code> to launch several
962 parallel instances of Python (for example, using <code>mpiexec -np 4 python mpi_example.py</code>).
963 The parallel features of netcdf4-python are mostly transparent -
964 when a new dataset is created or an existing dataset is opened,
965 use the <code>parallel</code> keyword to enable parallel access.</p>
966 <pre><code class="language-python">&gt;&gt;&gt; nc = Dataset('parallel_test.nc','w',parallel=True)
967 </code></pre>
968 <p>The optional <code>comm</code> keyword may be used to specify a particular
969 MPI communicator (<code>MPI_COMM_WORLD</code> is used by default).
970 Each process (or rank)
971 can now write to the file independently.
972 In this example the process rank is
973 written to a different variable index on each task</p>
974 <pre><code class="language-python">&gt;&gt;&gt; d = nc.createDimension('dim',4)
975 &gt;&gt;&gt; v = nc.createVariable('var', np.int64, 'dim')
976 &gt;&gt;&gt; v[rank] = rank
977 &gt;&gt;&gt; nc.close()
978
979 % ncdump parallel_test.nc
980 netcdf parallel_test {
981 dimensions:
982 dim = 4 ;
983 variables:
984 int64 var(dim) ;
985 data:
986
987 var = 0, 1, 2, 3 ;
988 }
989 </code></pre>
990 <p>There are two types of parallel IO, independent (the default) and collective.
991 Independent IO means that each process can do IO independently. It should not
992 depend on or be affected by other processes. Collective IO is a way of doing
993 IO defined in the MPI-IO standard; unlike independent IO, all processes must
994 participate in doing IO. To toggle back and forth between
995 the two types of IO, use the <code><a title="netCDF4.Variable.set_collective" href="#netCDF4.Variable.set_collective">Variable.set_collective()</a></code>
996 <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> method. All metadata
997 operations (such as creation of groups, types, variables, dimensions, or attributes)
998 are collective.
999 There are a couple of important limitations of parallel IO:</p>
1000 <ul>
1001 <li>parallel IO for NETCDF4 or NETCDF4_CLASSIC formatted files is only available
1002 if the netcdf library was compiled with MPI enabled HDF5.</li>
1003 <li>parallel IO for all classic netcdf-3 file formats is only available if the
1004 netcdf library was compiled with <a href="https://parallel-netcdf.github.io">PnetCDF</a>.</li>
1005 <li>If a variable has an unlimited dimension, appending data must be done in collective mode.
1006 If the write is done in independent mode, the operation will fail with a
1007 a generic "HDF Error".</li>
1008 <li>You can write compressed data in parallel only with netcdf-c &gt;= 4.7.4
1009 and hdf5 &gt;= 1.10.3 (although you can read in parallel with earlier versions). To write
1010 compressed data in parallel, the variable must be in 'collective IO mode'.
1011 This is done
1012 automatically on variable creation if compression is turned on, but if you are appending
1013 to a variable in an existing file, you must use <code><a title="netCDF4.Variable.set_collective" href="#netCDF4.Variable.set_collective">Variable.set_collective()</a>(True)</code> before attempting
1014 to write to it.</li>
1015 <li>You cannot use variable-length (VLEN) data types.</li>
1016 </ul>
1017 <p><strong><em>Import warning regarding threads:</em></strong>
1018 The underlying netcdf-c library is not thread-safe, so netcdf4-python cannot perform parallel
1019 IO in a multi-threaded environment.
1020 Users should expect segfaults if a netcdf file is opened on multiple threads - care should
1021 be taken to restrict netcdf4-python usage to a single thread, even when using free-threaded python.</p>
1022 <h2 id="dealing-with-strings">Dealing with strings</h2>
1023 <p>The most flexible way to store arrays of strings is with the
1024 <a href="#variable-length-vlen-data-type">Variable-length (vlen) string data type</a>. However, this requires
1025 the use of the NETCDF4 data model, and the vlen type does not map very well
1026 numpy arrays (you have to use numpy arrays of dtype=<code>object</code>, which are arrays of
1027 arbitrary python objects). numpy does have a fixed-width string array
1028 data type, but unfortunately the netCDF data model does not.
1029 Instead fixed-width byte strings are typically stored as <a href="https://www.unidata.ucar.edu/software/netcdf/docs/BestPractices.html#bp_Strings-and-Variables-of-type-char">arrays of 8-bit
1030 characters</a>.
1031 To perform the conversion to and from character arrays to fixed-width numpy string arrays, the
1032 following convention is followed by the python interface.
1033 If the <code>_Encoding</code> special attribute is set for a character array
1034 (dtype <code>S1</code>) variable, the <code><a title="netCDF4.chartostring" href="#netCDF4.chartostring">chartostring()</a></code> utility function is used to convert the array of
1035 characters to an array of strings with one less dimension (the last dimension is
1036 interpreted as the length of each string) when reading the data. The character
1037 set is specified by the <code>_Encoding</code> attribute. If <code>_Encoding</code>
1038 is 'none' or 'bytes', then the character array is converted to a numpy
1039 fixed-width byte string array (dtype <code>S#</code>), otherwise a numpy unicode (dtype
1040 <code>U#</code>) array is created.
1041 When writing the data,
1042 <code><a title="netCDF4.stringtochar" href="#netCDF4.stringtochar">stringtochar()</a></code> is used to convert the numpy string array to an array of
1043 characters with one more dimension. For example,</p>
1044 <pre><code class="language-python">&gt;&gt;&gt; from netCDF4 import stringtochar
1045 &gt;&gt;&gt; nc = Dataset('stringtest.nc','w',format='NETCDF4_CLASSIC')
1046 &gt;&gt;&gt; _ = nc.createDimension('nchars',3)
1047 &gt;&gt;&gt; _ = nc.createDimension('nstrings',None)
1048 &gt;&gt;&gt; v = nc.createVariable('strings','S1',('nstrings','nchars'))
1049 &gt;&gt;&gt; datain = np.array(['foo','bar'],dtype='S3')
1050 &gt;&gt;&gt; v[:] = stringtochar(datain) # manual conversion to char array
1051 &gt;&gt;&gt; print(v[:]) # data returned as char array
1052 [[b'f' b'o' b'o']
1053 [b'b' b'a' b'r']]
1054 &gt;&gt;&gt; v._Encoding = 'ascii' # this enables automatic conversion
1055 &gt;&gt;&gt; v[:] = datain # conversion to char array done internally
1056 &gt;&gt;&gt; print(v[:]) # data returned in numpy string array
1057 ['foo' 'bar']
1058 &gt;&gt;&gt; nc.close()
1059 </code></pre>
1060 <p>Even if the <code>_Encoding</code> attribute is set, the automatic conversion of char
1061 arrays to/from string arrays can be disabled with
1062 <code><a title="netCDF4.Variable.set_auto_chartostring" href="#netCDF4.Variable.set_auto_chartostring">Variable.set_auto_chartostring()</a></code>.</p>
1063 <p>A similar situation is often encountered with numpy structured arrays with subdtypes
1064 containing fixed-wdith byte strings (dtype=<code>S#</code>). Since there is no native fixed-length string
1065 netCDF datatype, these numpy structure arrays are mapped onto netCDF compound
1066 types with character array elements.
1067 In this case the string &lt;-&gt; char array
1068 conversion is handled automatically (without the need to set the <code>_Encoding</code>
1069 attribute) using <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.view.html">numpy
1070 views</a>.
1071 The structured array dtype (including the string elements) can even be used to
1072 define the compound data type - the string dtype will be converted to
1073 character array dtype under the hood when creating the netcdf compound type.
1074 Here's an example:</p>
1075 <pre><code class="language-python">&gt;&gt;&gt; nc = Dataset('compoundstring_example.nc','w')
1076 &gt;&gt;&gt; dtype = np.dtype([('observation', 'f4'),
1077 ... ('station_name','S10')])
1078 &gt;&gt;&gt; station_data_t = nc.createCompoundType(dtype,'station_data')
1079 &gt;&gt;&gt; _ = nc.createDimension('station',None)
1080 &gt;&gt;&gt; statdat = nc.createVariable('station_obs', station_data_t, ('station',))
1081 &gt;&gt;&gt; data = np.empty(2,dtype)
1082 &gt;&gt;&gt; data['observation'][:] = (123.,3.14)
1083 &gt;&gt;&gt; data['station_name'][:] = ('Boulder','New York')
1084 &gt;&gt;&gt; print(statdat.dtype) # strings actually stored as character arrays
1085 {'names':['observation','station_name'], 'formats':['&lt;f4',('S1', (10,))], 'offsets':[0,4], 'itemsize':16, 'aligned':True}
1086 &gt;&gt;&gt; statdat[:] = data # strings converted to character arrays internally
1087 &gt;&gt;&gt; print(statdat[:]) # character arrays converted back to strings
1088 [(123. , b'Boulder') ( 3.14, b'New York')]
1089 &gt;&gt;&gt; print(statdat[:].dtype)
1090 {'names':['observation','station_name'], 'formats':['&lt;f4','S10'], 'offsets':[0,4], 'itemsize':16, 'aligned':True}
1091 &gt;&gt;&gt; statdat.set_auto_chartostring(False) # turn off auto-conversion
1092 &gt;&gt;&gt; statdat[:] = data.view(dtype=[('observation', 'f4'),('station_name','S1',10)])
1093 &gt;&gt;&gt; print(statdat[:]) # now structured array with char array subtype is returned
1094 [(123. , [b'B', b'o', b'u', b'l', b'd', b'e', b'r', b'', b'', b''])
1095 ( 3.14, [b'N', b'e', b'w', b' ', b'Y', b'o', b'r', b'k', b'', b''])]
1096 &gt;&gt;&gt; nc.close()
1097 </code></pre>
1098 <p>Note that there is currently no support for mapping numpy structured arrays with
1099 unicode elements (dtype <code>U#</code>) onto netCDF compound types, nor is there support
1100 for netCDF compound types with vlen string components.</p>
1101 <h2 id="in-memory-diskless-datasets">In-memory (diskless) Datasets</h2>
1102 <p>You can create netCDF Datasets whose content is held in memory
1103 instead of in a disk file.
1104 There are two ways to do this.
1105 If you
1106 don't need access to the memory buffer containing the Dataset from
1107 within python, the best way is to use the <code>diskless=True</code> keyword
1108 argument when creating the Dataset.
1109 If you want to save the Dataset
1110 to disk when you close it, also set <code>persist=True</code>.
1111 If you want to
1112 create a new read-only Dataset from an existing python memory buffer, use the
1113 <code>memory</code> keyword argument to pass the memory buffer when creating the Dataset.
1114 If you want to create a new in-memory Dataset, and then access the memory buffer
1115 directly from Python, use the <code>memory</code> keyword argument to specify the
1116 estimated size of the Dataset in bytes when creating the Dataset with
1117 <code>mode='w'</code>.
1118 Then, the <code><a title="netCDF4.Dataset.close" href="#netCDF4.Dataset.close">Dataset.close()</a></code> method will return a python memoryview
1119 object representing the Dataset. Below are examples illustrating both
1120 approaches.</p>
1121 <pre><code class="language-python">&gt;&gt;&gt; # create a diskless (in-memory) Dataset,
1122 &gt;&gt;&gt; # and persist the file to disk when it is closed.
1123 &gt;&gt;&gt; nc = Dataset('diskless_example.nc','w',diskless=True,persist=True)
1124 &gt;&gt;&gt; d = nc.createDimension('x',None)
1125 &gt;&gt;&gt; v = nc.createVariable('v',np.int32,'x')
1126 &gt;&gt;&gt; v[0:5] = np.arange(5)
1127 &gt;&gt;&gt; print(nc)
1128 &lt;class 'netCDF4._netCDF4.Dataset'&gt;
1129 root group (NETCDF4 data model, file format HDF5):
1130 dimensions(sizes): x(5)
1131 variables(dimensions): int32 v(x)
1132 groups:
1133 &gt;&gt;&gt; print(nc['v'][:])
1134 [0 1 2 3 4]
1135 &gt;&gt;&gt; nc.close() # file saved to disk
1136 &gt;&gt;&gt; # create an in-memory dataset from an existing python
1137 &gt;&gt;&gt; # python memory buffer.
1138 &gt;&gt;&gt; # read the newly created netcdf file into a python
1139 &gt;&gt;&gt; # bytes object.
1140 &gt;&gt;&gt; with open('diskless_example.nc', 'rb') as f:
1141 ... nc_bytes = f.read()
1142 &gt;&gt;&gt; # create a netCDF in-memory dataset from the bytes object.
1143 &gt;&gt;&gt; nc = Dataset('inmemory.nc', memory=nc_bytes)
1144 &gt;&gt;&gt; print(nc)
1145 &lt;class 'netCDF4._netCDF4.Dataset'&gt;
1146 root group (NETCDF4 data model, file format HDF5):
1147 dimensions(sizes): x(5)
1148 variables(dimensions): int32 v(x)
1149 groups:
1150 &gt;&gt;&gt; print(nc['v'][:])
1151 [0 1 2 3 4]
1152 &gt;&gt;&gt; nc.close()
1153 &gt;&gt;&gt; # create an in-memory Dataset and retrieve memory buffer
1154 &gt;&gt;&gt; # estimated size is 1028 bytes - this is actually only
1155 &gt;&gt;&gt; # used if format is NETCDF3
1156 &gt;&gt;&gt; # (ignored for NETCDF4/HDF5 files).
1157 &gt;&gt;&gt; nc = Dataset('inmemory.nc', mode='w',memory=1028)
1158 &gt;&gt;&gt; d = nc.createDimension('x',None)
1159 &gt;&gt;&gt; v = nc.createVariable('v',np.int32,'x')
1160 &gt;&gt;&gt; v[0:5] = np.arange(5)
1161 &gt;&gt;&gt; nc_buf = nc.close() # close returns memoryview
1162 &gt;&gt;&gt; print(type(nc_buf))
1163 &lt;class 'memoryview'&gt;
1164 &gt;&gt;&gt; # save nc_buf to disk, read it back in and check.
1165 &gt;&gt;&gt; with open('inmemory.nc', 'wb') as f:
1166 ... f.write(nc_buf)
1167 &gt;&gt;&gt; nc = Dataset('inmemory.nc')
1168 &gt;&gt;&gt; print(nc)
1169 &lt;class 'netCDF4._netCDF4.Dataset'&gt;
1170 root group (NETCDF4 data model, file format HDF5):
1171 dimensions(sizes): x(5)
1172 variables(dimensions): int32 v(x)
1173 groups:
1174 &gt;&gt;&gt; print(nc['v'][:])
1175 [0 1 2 3 4]
1176 &gt;&gt;&gt; nc.close()
1177 </code></pre>
1178 <h2 id="support-for-complex-numbers">Support for complex numbers</h2>
1179 <p>Although there is no native support for complex numbers in netCDF, there are
1180 some common conventions for storing them. Two of the most common are to either
1181 use a compound datatype for the real and imaginary components, or a separate
1182 dimension. <code><a title="netCDF4" href="#netCDF4">netCDF4</a></code> supports reading several of these conventions, as well as
1183 writing using one of two conventions (depending on file format). This support
1184 for complex numbers is enabled by setting <code>auto_complex=True</code> when opening a
1185 <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code>:</p>
1186 <pre><code class="language-python">&gt;&gt;&gt; complex_array = np.array([0 + 0j, 1 + 0j, 0 + 1j, 1 + 1j, 0.25 + 0.75j])
1187 &gt;&gt;&gt; with netCDF4.Dataset(&quot;complex.nc&quot;, &quot;w&quot;, auto_complex=True) as nc:
1188 ... nc.createDimension(&quot;x&quot;, size=len(complex_array))
1189 ... var = nc.createVariable(&quot;data&quot;, &quot;c16&quot;, (&quot;x&quot;,))
1190 ... var[:] = complex_array
1191 ... print(var)
1192 &lt;class 'netCDF4._netCDF4.Variable'&gt;
1193 compound data(x)
1194 compound data type: complex128
1195 unlimited dimensions:
1196 current shape = (5,)
1197 </code></pre>
1198 <p>When reading files using <code>auto_complex=True</code>, <code><a title="netCDF4" href="#netCDF4">netCDF4</a></code> will interpret variables
1199 stored using the following conventions as complex numbers:</p>
1200 <ul>
1201 <li>compound datatypes with two <code>float</code> or <code>double</code> members who names begin with
1202 <code>r</code> and <code>i</code> (case insensitive)</li>
1203 <li>a dimension of length 2 named <code>complex</code> or <code>ri</code></li>
1204 </ul>
1205 <p>When writing files using <code>auto_complex=True</code>, <code><a title="netCDF4" href="#netCDF4">netCDF4</a></code> will use:</p>
1206 <ul>
1207 <li>a compound datatype named <code>_PFNC_DOUBLE_COMPLEX_TYPE</code> (or <code>*FLOAT*</code> as
1208 appropriate) with members <code>r</code> and <code>i</code> for netCDF4 formats;</li>
1209 <li>or a dimension of length 2 named <code>_pfnc_complex</code> for netCDF3 or classic
1210 formats.</li>
1211 </ul>
1212 <p>Support for complex numbers is handled via the
1213 <a href="https://github.com/PlasmaFAIR/nc-complex"><code>nc-complex</code></a> library. See there for
1214 further details.</p>
1215 <p><strong>contact</strong>: Jeffrey Whitaker <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#119;&#104;&#105;&#116;&#97;&#107;&#101;&#114;&#46;&#106;&#101;&#102;&#102;&#114;&#101;&#121;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;">&#119;&#104;&#105;&#116;&#97;&#107;&#101;&#114;&#46;&#106;&#101;&#102;&#102;&#114;&#101;&#121;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;</a></p>
1216 <p><strong>copyright</strong>: 2008 by Jeffrey Whitaker.</p>
1217 <p><strong>license</strong>: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
1218 <p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
1219 <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
1220 </section>
1221 <section>
1222 </section>
1223 <section>
1224 </section>
1225 <section>
1226 <h2 class="section-title" id="header-functions">Functions</h2>
1227 <dl>
1228 <dt id="netCDF4.chartostring"><code class="name flex">
1229 <span>def <span class="ident">chartostring</span></span>(<span>b, encoding='utf-8')</span>
1230 </code></dt>
1231 <dd>
1232 <div class="desc"><p><strong><code>chartostring(b,encoding='utf-8')</code></strong></p>
1233 <p>convert a character array to a string array with one less dimension.</p>
1234 <p><strong><code>b</code></strong>:
1235 Input character array (numpy datatype <code>'S1'</code> or <code>'U1'</code>).
1236 Will be converted to a array of strings, where each string has a fixed
1237 length of <code>b.shape[-1]</code> characters.</p>
1238 <p>optional kwarg <code>encoding</code> can be used to specify character encoding (default
1239 <code>utf-8</code>). If <code>encoding</code> is 'none' or 'bytes', a <code>numpy.string_</code> byte array is
1240 returned.</p>
1241 <p>returns a numpy string array with datatype <code>'UN'</code> (or <code>'SN'</code>) and shape
1242 <code>b.shape[:-1]</code> where where <code>N=b.shape[-1]</code>.</p></div>
1243 </dd>
1244 <dt id="netCDF4.date2index"><code class="name flex">
1245 <span>def <span class="ident">date2index</span></span>(<span>dates, nctime, calendar=None, select='exact', has_year_zero=None)</span>
1246 </code></dt>
1247 <dd>
1248 <div class="desc"><p>date2index(dates, nctime, calendar=None, select='exact', has_year_zero=None)</p>
1249 <p>Return indices of a netCDF time variable corresponding to the given dates.</p>
1250 <p><strong>dates</strong>: A datetime object or a sequence of datetime objects.
1251 The datetime objects should not include a time-zone offset.</p>
1252 <p><strong>nctime</strong>: A netCDF time variable object. The nctime object must have a
1253 <strong>units</strong> attribute.</p>
1254 <p><strong>calendar</strong>: describes the calendar to be used in the time calculations.
1255 All the values currently defined in the
1256 <code>CF metadata convention &lt;http://cfconventions.org/cf-conventions/cf-conventions#calendar&gt;</code>__ are supported.
1257 Valid calendars <strong>'standard', 'gregorian', 'proleptic_gregorian'
1258 'noleap', '365_day', '360_day', 'julian', 'all_leap', '366_day'</strong>.
1259 Default is <code>None</code> which means the calendar associated with the first
1260 input datetime instance will be used.</p>
1261 <p><strong>select</strong>: <strong>'exact', 'before', 'after', 'nearest'</strong>
1262 The index selection method. <strong>exact</strong> will return the indices perfectly
1263 matching the dates given. <strong>before</strong> and <strong>after</strong> will return the indices
1264 corresponding to the dates just before or just after the given dates if
1265 an exact match cannot be found. <strong>nearest</strong> will return the indices that
1266 correspond to the closest dates.</p>
1267 <p><strong>has_year_zero</strong>: if set to True, astronomical year numbering
1268 is used and the year zero exists.
1269 If set to False for real-world
1270 calendars, then historical year numbering is used and the year 1 is
1271 preceded by year -1 and no year zero exists.
1272 The defaults are set to conform with
1273 CF version 1.9 conventions (False for 'julian', 'gregorian'/'standard', True
1274 for 'proleptic_gregorian' (ISO 8601) and True for the idealized
1275 calendars 'noleap'/'365_day', '360_day', 366_day'/'all_leap')
1276 The defaults can only be over-ridden for the real-world calendars,
1277 for the the idealized calendars the year zero
1278 always exists and the has_year_zero kwarg is ignored.
1279 This kwarg is not needed to define calendar systems allowed by CF
1280 (the calendar-specific defaults do this).</p>
1281 <p>returns an index (indices) of the netCDF time variable corresponding
1282 to the given datetime object(s).</p></div>
1283 </dd>
1284 <dt id="netCDF4.date2num"><code class="name flex">
1285 <span>def <span class="ident">date2num</span></span>(<span>dates, units, calendar=None, has_year_zero=None, longdouble=False)</span>
1286 </code></dt>
1287 <dd>
1288 <div class="desc"><p>date2num(dates, units, calendar=None, has_year_zero=None, longdouble=False)</p>
1289 <p>Return numeric time values given datetime objects. The units
1290 of the numeric time values are described by the <strong>units</strong> argument
1291 and the <strong>calendar</strong> keyword. The datetime objects must
1292 be in UTC with no time-zone offset.
1293 If there is a
1294 time-zone offset in <strong>units</strong>, it will be applied to the
1295 returned numeric values.</p>
1296 <p><strong>dates</strong>: A datetime object or a sequence of datetime objects.
1297 The datetime objects should not include a time-zone offset. They
1298 can be either native python datetime instances (which use
1299 the proleptic gregorian calendar) or cftime.datetime instances.</p>
1300 <p><strong>units</strong>: a string of the form <strong><time units> since <reference time></strong>
1301 describing the time units. <strong><time units></strong> can be days, hours, minutes,
1302 seconds, milliseconds or microseconds. <strong><reference time></strong> is the time
1303 origin. <strong>months since</strong> is allowed <em>only</em> for the <strong>360_day</strong> calendar
1304 and <strong>common_years since</strong> is allowed <em>only</em> for the <strong>365_day</strong> calendar.</p>
1305 <p><strong>calendar</strong>: describes the calendar to be used in the time calculations.
1306 All the values currently defined in the
1307 <code>CF metadata convention &lt;http://cfconventions.org/cf-conventions/cf-conventions#calendar&gt;</code>__ are supported.
1308 Valid calendars <strong>'standard', 'gregorian', 'proleptic_gregorian'
1309 'noleap', '365_day', '360_day', 'julian', 'all_leap', '366_day'</strong>.
1310 Default is <code>None</code> which means the calendar associated with the first
1311 input datetime instance will be used.</p>
1312 <p><strong>has_year_zero</strong>: If set to True, astronomical year numbering
1313 is used and the year zero exists.
1314 If set to False for real-world
1315 calendars, then historical year numbering is used and the year 1 is
1316 preceded by year -1 and no year zero exists.
1317 The defaults are set to conform with
1318 CF version 1.9 conventions (False for 'julian', 'gregorian'/'standard', True
1319 for 'proleptic_gregorian' (ISO 8601) and True for the idealized
1320 calendars 'noleap'/'365_day', '360_day', 366_day'/'all_leap')
1321 Note that CF v1.9 does not specifically mention whether year zero
1322 is allowed in the proleptic_gregorian calendar, but ISO-8601 has
1323 a year zero so we have adopted this as the default.
1324 The defaults can only be over-ridden for the real-world calendars,
1325 for the the idealized calendars the year zero
1326 always exists and the has_year_zero kwarg is ignored.
1327 This kwarg is not needed to define calendar systems allowed by CF
1328 (the calendar-specific defaults do this).</p>
1329 <p><strong>longdouble</strong>: If set True, output is in the long double float type
1330 (numpy.float128) instead of float (numpy.float64), allowing microsecond
1331 accuracy when converting a time value to a date and back again. Otherwise
1332 this is only possible if the discretization of the time variable is an
1333 integer multiple of the units.</p>
1334 <p>returns a numeric time value, or an array of numeric time values
1335 with approximately 1 microsecond accuracy.</p></div>
1336 </dd>
1337 <dt id="netCDF4.get_alignment"><code class="name flex">
1338 <span>def <span class="ident">get_alignment</span></span>(<span>)</span>
1339 </code></dt>
1340 <dd>
1341 <div class="desc"><p><strong><code>get_alignment()</code></strong></p>
1342 <p>return current netCDF alignment within HDF5 files in a tuple
1343 (threshold,alignment). See netcdf C library documentation for
1344 <code>nc_get_alignment</code> for details. Values can be reset with
1345 <code><a title="netCDF4.set_alignment" href="#netCDF4.set_alignment">set_alignment()</a></code>.</p>
1346 <p>This function was added in netcdf 4.9.0.</p></div>
1347 </dd>
1348 <dt id="netCDF4.get_chunk_cache"><code class="name flex">
1349 <span>def <span class="ident">get_chunk_cache</span></span>(<span>)</span>
1350 </code></dt>
1351 <dd>
1352 <div class="desc"><p><strong><code>get_chunk_cache()</code></strong></p>
1353 <p>return current netCDF chunk cache information in a tuple (size,nelems,preemption).
1354 See netcdf C library documentation for <code>nc_get_chunk_cache</code> for
1355 details. Values can be reset with <code><a title="netCDF4.set_chunk_cache" href="#netCDF4.set_chunk_cache">set_chunk_cache()</a></code>.</p></div>
1356 </dd>
1357 <dt id="netCDF4.getlibversion"><code class="name flex">
1358 <span>def <span class="ident">getlibversion</span></span>(<span>)</span>
1359 </code></dt>
1360 <dd>
1361 <div class="desc"><p><strong><code>getlibversion()</code></strong></p>
1362 <p>returns a string describing the version of the netcdf library
1363 used to build the module, and when it was built.</p></div>
1364 </dd>
1365 <dt id="netCDF4.num2date"><code class="name flex">
1366 <span>def <span class="ident">num2date</span></span>(<span>times,<br>units,<br>calendar='standard',<br>only_use_cftime_datetimes=True,<br>only_use_python_datetimes=False,<br>has_year_zero=None)</span>
1367 </code></dt>
1368 <dd>
1369 <div class="desc"><p>num2date(times, units, calendar='standard', only_use_cftime_datetimes=True, only_use_python_datetimes=False, has_year_zero=None)</p>
1370 <p>Return datetime objects given numeric time values. The units
1371 of the numeric time values are described by the <strong>units</strong> argument
1372 and the <strong>calendar</strong> keyword. The returned datetime objects represent
1373 UTC with no time-zone offset, even if the specified
1374 <strong>units</strong> contain a time-zone offset.</p>
1375 <p><strong>times</strong>: numeric time values.</p>
1376 <p><strong>units</strong>: a string of the form <strong><time units> since <reference time></strong>
1377 describing the time units. <strong><time units></strong> can be days, hours, minutes,
1378 seconds, milliseconds or microseconds. <strong><reference time></strong> is the time
1379 origin. <strong>months since</strong> is allowed <em>only</em> for the <strong>360_day</strong> calendar
1380 and <strong>common_years since</strong> is allowed <em>only</em> for the <strong>365_day</strong> calendar.</p>
1381 <p><strong>calendar</strong>: describes the calendar used in the time calculations.
1382 All the values currently defined in the
1383 <code>CF metadata convention &lt;http://cfconventions.org/cf-conventions/cf-conventions#calendar&gt;</code>__ are supported.
1384 Valid calendars <strong>'standard', 'gregorian', 'proleptic_gregorian'
1385 'noleap', '365_day', '360_day', 'julian', 'all_leap', '366_day'</strong>.
1386 Default is <strong>'standard'</strong>, which is a mixed Julian/Gregorian calendar.</p>
1387 <p><strong>only_use_cftime_datetimes</strong>: if False, python datetime.datetime
1388 objects are returned from num2date where possible; if True dates which
1389 subclass cftime.datetime are returned for all calendars. Default <strong>True</strong>.</p>
1390 <p><strong>only_use_python_datetimes</strong>: always return python datetime.datetime
1391 objects and raise an error if this is not possible. Ignored unless
1392 <strong>only_use_cftime_datetimes=False</strong>. Default <strong>False</strong>.</p>
1393 <p><strong>has_year_zero</strong>: if set to True, astronomical year numbering
1394 is used and the year zero exists.
1395 If set to False for real-world
1396 calendars, then historical year numbering is used and the year 1 is
1397 preceded by year -1 and no year zero exists.
1398 The defaults are set to conform with
1399 CF version 1.9 conventions (False for 'julian', 'gregorian'/'standard', True
1400 for 'proleptic_gregorian' (ISO 8601) and True for the idealized
1401 calendars 'noleap'/'365_day', '360_day', 366_day'/'all_leap')
1402 The defaults can only be over-ridden for the real-world calendars,
1403 for the the idealized calendars the year zero
1404 always exists and the has_year_zero kwarg is ignored.
1405 This kwarg is not needed to define calendar systems allowed by CF
1406 (the calendar-specific defaults do this).</p>
1407 <p>returns a datetime instance, or an array of datetime instances with
1408 microsecond accuracy, if possible.</p>
1409 <p><strong><em>Note</em></strong>: If only_use_cftime_datetimes=False and
1410 use_only_python_datetimes=False, the datetime instances
1411 returned are 'real' python datetime
1412 objects if <strong>calendar='proleptic_gregorian'</strong>, or
1413 <strong>calendar='standard'</strong> or <strong>'gregorian'</strong>
1414 and the date is after the breakpoint between the Julian and
1415 Gregorian calendars (1582-10-15). Otherwise, they are ctime.datetime
1416 objects which support some but not all the methods of native python
1417 datetime objects. The datetime instances
1418 do not contain a time-zone offset, even if the specified <strong>units</strong>
1419 contains one.</p></div>
1420 </dd>
1421 <dt id="netCDF4.rc_get"><code class="name flex">
1422 <span>def <span class="ident">rc_get</span></span>(<span>key)</span>
1423 </code></dt>
1424 <dd>
1425 <div class="desc"><p><strong><code>rc_get(key)</code></strong></p>
1426 <p>Returns the internal netcdf-c rc table value corresponding to key.
1427 See <a href="https://docs.unidata.ucar.edu/netcdf-c/current/md_auth.html">https://docs.unidata.ucar.edu/netcdf-c/current/md_auth.html</a>
1428 for more information on rc files and values.</p></div>
1429 </dd>
1430 <dt id="netCDF4.rc_set"><code class="name flex">
1431 <span>def <span class="ident">rc_set</span></span>(<span>key, value)</span>
1432 </code></dt>
1433 <dd>
1434 <div class="desc"><p><strong><code>rc_set(key, value)</code></strong></p>
1435 <p>Sets the internal netcdf-c rc table value corresponding to key.
1436 See <a href="https://docs.unidata.ucar.edu/netcdf-c/current/md_auth.html">https://docs.unidata.ucar.edu/netcdf-c/current/md_auth.html</a>
1437 for more information on rc files and values.</p></div>
1438 </dd>
1439 <dt id="netCDF4.set_alignment"><code class="name flex">
1440 <span>def <span class="ident">set_alignment</span></span>(<span>threshold, alignment)</span>
1441 </code></dt>
1442 <dd>
1443 <div class="desc"><p><strong><code>set_alignment(threshold,alignment)</code></strong></p>
1444 <p>Change the HDF5 file alignment.
1445 See netcdf C library documentation for <code>nc_set_alignment</code> for
1446 details.</p>
1447 <p>This function was added in netcdf 4.9.0.</p></div>
1448 </dd>
1449 <dt id="netCDF4.set_chunk_cache"><code class="name flex">
1450 <span>def <span class="ident">set_chunk_cache</span></span>(<span>size=None, nelems=None, preemption=None)</span>
1451 </code></dt>
1452 <dd>
1453 <div class="desc"><p><strong><code>set_chunk_cache(size=None,nelems=None,preemption=None)</code></strong></p>
1454 <p>change netCDF4 chunk cache settings.
1455 See netcdf C library documentation for <code>nc_set_chunk_cache</code> for
1456 details.</p></div>
1457 </dd>
1458 <dt id="netCDF4.stringtoarr"><code class="name flex">
1459 <span>def <span class="ident">stringtoarr</span></span>(<span>string, NUMCHARS, dtype='S')</span>
1460 </code></dt>
1461 <dd>
1462 <div class="desc"><p><strong><code>stringtoarr(a, NUMCHARS,dtype='S')</code></strong></p>
1463 <p>convert a string to a character array of length <code>NUMCHARS</code></p>
1464 <p><strong><code>a</code></strong>:
1465 Input python string.</p>
1466 <p><strong><code>NUMCHARS</code></strong>:
1467 number of characters used to represent string
1468 (if len(a) &lt; <code>NUMCHARS</code>, it will be padded on the right with blanks).</p>
1469 <p><strong><code>dtype</code></strong>:
1470 type of numpy array to return.
1471 Default is <code>'S'</code>, which
1472 means an array of dtype <code>'S1'</code> will be returned.
1473 If dtype=<code>'U'</code>, a
1474 unicode array (dtype = <code>'U1'</code>) will be returned.</p>
1475 <p>returns a rank 1 numpy character array of length NUMCHARS with datatype <code>'S1'</code>
1476 (default) or <code>'U1'</code> (if dtype=<code>'U'</code>)</p></div>
1477 </dd>
1478 <dt id="netCDF4.stringtochar"><code class="name flex">
1479 <span>def <span class="ident">stringtochar</span></span>(<span>a, encoding='utf-8', n_strlen=None)</span>
1480 </code></dt>
1481 <dd>
1482 <div class="desc"><p><strong><code>stringtochar(a,encoding='utf-8',n_strlen=None)</code></strong></p>
1483 <p>convert a string array to a character array with one extra dimension</p>
1484 <p><strong><code>a</code></strong>:
1485 Input numpy string array with numpy datatype <code>'SN'</code> or <code>'UN'</code>, where N
1486 is the number of characters in each string.
1487 Will be converted to
1488 an array of characters (datatype <code>'S1'</code> or <code>'U1'</code>) of shape <code>a.shape + (N,)</code>.</p>
1489 <p>optional kwarg <code>encoding</code> can be used to specify character encoding (default
1490 <code>utf-8</code>). If <code>encoding</code> is 'none' or 'bytes', a <code>numpy.string_</code> the input array
1491 is treated a raw byte strings (<code>numpy.string_</code>).</p>
1492 <p>optional kwarg <code>n_strlen</code> is the number of characters in each string.
1493 Default
1494 is None, which means <code>n_strlen</code> will be set to a.itemsize (the number of bytes
1495 used to represent each string in the input array).</p>
1496 <p>returns a numpy character array with datatype <code>'S1'</code> or <code>'U1'</code>
1497 and shape <code>a.shape + (N,)</code>, where N is the length of each string in a.</p></div>
1498 </dd>
1499 </dl>
1500 </section>
1501 <section>
1502 <h2 class="section-title" id="header-classes">Classes</h2>
1503 <dl>
1504 <dt id="netCDF4.CompoundType"><code class="flex name class">
1505 <span>class <span class="ident">CompoundType</span></span>
1506 <span>(</span><span>...)</span>
1507 </code></dt>
1508 <dd>
1509 <div class="desc"><p>A <code><a title="netCDF4.CompoundType" href="#netCDF4.CompoundType">CompoundType</a></code> instance is used to describe a compound data
1510 type, and can be passed to the the <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code> method of
1511 a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance.
1512 Compound data types map to numpy structured arrays.
1513 See <code><a title="netCDF4.CompoundType" href="#netCDF4.CompoundType">CompoundType</a></code> for more details.</p>
1514 <p>The instance variables <code>dtype</code> and <code>name</code> should not be modified by
1515 the user.</p>
1516 <p><strong><em><code>__init__(group, datatype, datatype_name)</code></em></strong></p>
1517 <p>CompoundType constructor.</p>
1518 <p><strong><code>grp</code></strong>: <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance to associate with the compound datatype.</p>
1519 <p><strong><code>dt</code></strong>: A numpy dtype object describing a structured (a.k.a record)
1520 array.
1521 Can be composed of homogeneous numeric or character data types, or
1522 other structured array data types.</p>
1523 <p><strong><code>dtype_name</code></strong>: a Python string containing a description of the
1524 compound data type.</p>
1525 <p><strong><em>Note 1</em></strong>: When creating nested compound data types,
1526 the inner compound data types must already be associated with CompoundType
1527 instances (so create CompoundType instances for the innermost structures
1528 first).</p>
1529 <p><strong><em>Note 2</em></strong>: <code><a title="netCDF4.CompoundType" href="#netCDF4.CompoundType">CompoundType</a></code> instances should be created using the
1530 <code><a title="netCDF4.Dataset.createCompoundType" href="#netCDF4.Dataset.createCompoundType">Dataset.createCompoundType()</a></code> method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or
1531 <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance, not using this class directly.</p></div>
1532 <h3>Instance variables</h3>
1533 <dl>
1534 <dt id="netCDF4.CompoundType.dtype"><code class="name">var <span class="ident">dtype</span></code></dt>
1535 <dd>
1536 <div class="desc"></div>
1537 </dd>
1538 <dt id="netCDF4.CompoundType.dtype_view"><code class="name">var <span class="ident">dtype_view</span></code></dt>
1539 <dd>
1540 <div class="desc"></div>
1541 </dd>
1542 <dt id="netCDF4.CompoundType.name"><code class="name">var <span class="ident">name</span></code></dt>
1543 <dd>
1544 <div class="desc"></div>
1545 </dd>
1546 </dl>
1547 </dd>
1548 <dt id="netCDF4.Dataset"><code class="flex name class">
1549 <span>class <span class="ident">Dataset</span></span>
1550 <span>(</span><span>...)</span>
1551 </code></dt>
1552 <dd>
1553 <div class="desc"><p>A netCDF <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> is a collection of dimensions, groups, variables and
1554 attributes. Together they describe the meaning of data and relations among
1555 data fields stored in a netCDF file. See <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> for more
1556 details.</p>
1557 <p>A list of attribute names corresponding to global netCDF attributes
1558 defined for the <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> can be obtained with the
1559 <code><a title="netCDF4.Dataset.ncattrs" href="#netCDF4.Dataset.ncattrs">Dataset.ncattrs()</a></code> method.
1560 These attributes can be created by assigning to an attribute of the
1561 <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> instance. A dictionary containing all the netCDF attribute
1562 name/value pairs is provided by the <code>__dict__</code> attribute of a
1563 <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> instance.</p>
1564 <p>The following class variables are read-only and should not be
1565 modified by the user.</p>
1566 <p><strong><code>dimensions</code></strong>: The <code>dimensions</code> dictionary maps the names of
1567 dimensions defined for the <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> or <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> to instances of the
1568 <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> class.</p>
1569 <p><strong><code>variables</code></strong>: The <code>variables</code> dictionary maps the names of variables
1570 defined for this <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> to instances of the
1571 <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> class.</p>
1572 <p><strong><code>groups</code></strong>: The groups dictionary maps the names of groups created for
1573 this <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> to instances of the <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> class (the
1574 <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> class is simply a special case of the <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> class which
1575 describes the root group in the netCDF4 file).</p>
1576 <p><strong><code>cmptypes</code></strong>: The <code>cmptypes</code> dictionary maps the names of
1577 compound types defined for the <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> or <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> to instances of the
1578 <code><a title="netCDF4.CompoundType" href="#netCDF4.CompoundType">CompoundType</a></code> class.</p>
1579 <p><strong><code>vltypes</code></strong>: The <code>vltypes</code> dictionary maps the names of
1580 variable-length types defined for the <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> or <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> to instances
1581 of the <code><a title="netCDF4.VLType" href="#netCDF4.VLType">VLType</a></code> class.</p>
1582 <p><strong><code>enumtypes</code></strong>: The <code>enumtypes</code> dictionary maps the names of
1583 Enum types defined for the <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> or <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> to instances
1584 of the <code><a title="netCDF4.EnumType" href="#netCDF4.EnumType">EnumType</a></code> class.</p>
1585 <p><strong><code>data_model</code></strong>: <code>data_model</code> describes the netCDF
1586 data model version, one of <code>NETCDF3_CLASSIC</code>, <code>NETCDF4</code>,
1587 <code>NETCDF4_CLASSIC</code>, <code>NETCDF3_64BIT_OFFSET</code> or <code>NETCDF3_64BIT_DATA</code>.</p>
1588 <p><strong><code>file_format</code></strong>: same as <code>data_model</code>, retained for backwards compatibility.</p>
1589 <p><strong><code>disk_format</code></strong>: <code>disk_format</code> describes the underlying
1590 file format, one of <code>NETCDF3</code>, <code>HDF5</code>, <code>HDF4</code>,
1591 <code>PNETCDF</code>, <code>DAP2</code>, <code>DAP4</code> or <code>UNDEFINED</code>. Only available if using
1592 netcdf C library version &gt;= 4.3.1, otherwise will always return
1593 <code>UNDEFINED</code>.</p>
1594 <p><strong><code>parent</code></strong>: <code>parent</code> is a reference to the parent
1595 <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance. <code>None</code> for the root group or <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code>
1596 instance.</p>
1597 <p><strong><code>path</code></strong>: <code>path</code> shows the location of the <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> in
1598 the <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> in a unix directory format (the names of groups in the
1599 hierarchy separated by backslashes). A <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> instance is the root
1600 group, so the path is simply <code>'/'</code>.</p>
1601 <p><strong><code>keepweakref</code></strong>: If <code>True</code>, child Dimension and Variables objects only keep weak
1602 references to the parent Dataset or Group.</p>
1603 <p><strong><code>_ncstring_attrs__</code></strong>: If <code>True</code>, all text attributes will be written as variable-length
1604 strings.</p>
1605 <p><strong><code>__init__(self, filename, mode="r", clobber=True, diskless=False,
1606 persist=False, keepweakref=False, memory=None, encoding=None,
1607 parallel=False, comm=None, info=None, format='NETCDF4')</code></strong></p>
1608 <p><code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> constructor.</p>
1609 <p><strong><code>filename</code></strong>: Name of netCDF file to hold dataset. Can also
1610 be a python 3 pathlib instance or the URL of an OpenDAP dataset.
1611 When memory is
1612 set this is just used to set the <code>filepath()</code>.</p>
1613 <p><strong><code>mode</code></strong>: access mode. <code>r</code> means read-only; no data can be
1614 modified. <code>w</code> means write; a new file is created, an existing file with
1615 the same name is deleted. <code>x</code> means write, but fail if an existing
1616 file with the same name already exists. <code>a</code> and <code>r+</code> mean append;
1617 an existing file is opened for reading and writing, if
1618 file does not exist already, one is created.
1619 Appending <code>s</code> to modes <code>r</code>, <code>w</code>, <code>r+</code> or <code>a</code> will enable unbuffered shared
1620 access to <code>NETCDF3_CLASSIC</code>, <code>NETCDF3_64BIT_OFFSET</code> or
1621 <code>NETCDF3_64BIT_DATA</code> formatted files.
1622 Unbuffered access may be useful even if you don't need shared
1623 access, since it may be faster for programs that don't access data
1624 sequentially. This option is ignored for <code>NETCDF4</code> and <code>NETCDF4_CLASSIC</code>
1625 formatted files.</p>
1626 <p><strong><code>clobber</code></strong>: if <code>True</code> (default), opening a file with <code>mode='w'</code>
1627 will clobber an existing file with the same name.
1628 if <code>False</code>, an
1629 exception will be raised if a file with the same name already exists.
1630 mode=<code>x</code> is identical to mode=<code>w</code> with clobber=False.</p>
1631 <p><strong><code>format</code></strong>: underlying file format (one of <code>'NETCDF4'</code>,
1632 <code>'NETCDF4_CLASSIC'</code>, <code>'NETCDF3_CLASSIC'</code>, <code>'NETCDF3_64BIT_OFFSET'</code> or
1633 <code>'NETCDF3_64BIT_DATA'</code>.
1634 Only relevant if <code>mode = 'w'</code> (if <code>mode = 'r','a'</code> or <code>'r+'</code> the file format
1635 is automatically detected). Default <code>'NETCDF4'</code>, which means the data is
1636 stored in an HDF5 file, using netCDF 4 API features.
1637 Setting
1638 <code>format='NETCDF4_CLASSIC'</code> will create an HDF5 file, using only netCDF 3
1639 compatible API features. netCDF 3 clients must be recompiled and linked
1640 against the netCDF 4 library to read files in <code>NETCDF4_CLASSIC</code> format.
1641 <code>'NETCDF3_CLASSIC'</code> is the classic netCDF 3 file format that does not
1642 handle 2+ Gb files. <code>'NETCDF3_64BIT_OFFSET'</code> is the 64-bit offset
1643 version of the netCDF 3 file format, which fully supports 2+ GB files, but
1644 is only compatible with clients linked against netCDF version 3.6.0 or
1645 later. <code>'NETCDF3_64BIT_DATA'</code> is the 64-bit data version of the netCDF 3
1646 file format, which supports 64-bit dimension sizes plus unsigned and
1647 64 bit integer data types, but is only compatible with clients linked against
1648 netCDF version 4.4.0 or later.</p>
1649 <p><strong><code>diskless</code></strong>: If <code>True</code>, create diskless (in-core) file.
1650 This is a feature added to the C library after the
1651 netcdf-4.2 release. If you need to access the memory buffer directly,
1652 use the in-memory feature instead (see <code>memory</code> kwarg).</p>
1653 <p><strong><code>persist</code></strong>: if <code>diskless=True</code>, persist file to disk when closed
1654 (default <code>False</code>).</p>
1655 <p><strong><code>keepweakref</code></strong>: if <code>True</code>, child Dimension and Variable instances will keep weak
1656 references to the parent Dataset or Group object.
1657 Default is <code>False</code>, which
1658 means strong references will be kept.
1659 Having Dimension and Variable instances
1660 keep a strong reference to the parent Dataset instance, which in turn keeps a
1661 reference to child Dimension and Variable instances, creates circular references.
1662 Circular references complicate garbage collection, which may mean increased
1663 memory usage for programs that create may Dataset instances with lots of
1664 Variables. It also will result in the Dataset object never being deleted, which
1665 means it may keep open files alive as well. Setting <code>keepweakref=True</code> allows
1666 Dataset instances to be garbage collected as soon as they go out of scope, potentially
1667 reducing memory usage and open file handles.
1668 However, in many cases this is not
1669 desirable, since the associated Variable instances may still be needed, but are
1670 rendered unusable when the parent Dataset instance is garbage collected.</p>
1671 <p><strong><code>memory</code></strong>: if not <code>None</code>, create or open an in-memory Dataset.
1672 If mode = <code>r</code>, the memory kwarg must contain a memory buffer object
1673 (an object that supports the python buffer interface).
1674 The Dataset will then be created with contents taken from this block of memory.
1675 If mode = <code>w</code>, the memory kwarg should contain the anticipated size
1676 of the Dataset in bytes (used only for NETCDF3 files).
1677 A memory
1678 buffer containing a copy of the Dataset is returned by the
1679 <code><a title="netCDF4.Dataset.close" href="#netCDF4.Dataset.close">Dataset.close()</a></code> method. Requires netcdf-c version 4.4.1 for mode=<code>r</code>
1680 netcdf-c 4.6.2 for mode=<code>w</code>. To persist the file to disk, the raw
1681 bytes from the returned buffer can be written into a binary file.
1682 The Dataset can also be re-opened using this memory buffer.</p>
1683 <p><strong><code>encoding</code></strong>: encoding used to encode filename string into bytes.
1684 Default is None (<code>sys.getdefaultfileencoding()</code> is used).</p>
1685 <p><strong><code>parallel</code></strong>: open for parallel access using MPI (requires mpi4py and
1686 parallel-enabled netcdf-c and hdf5 libraries).
1687 Default is <code>False</code>. If
1688 <code>True</code>, <code>comm</code> and <code>info</code> kwargs may also be specified.</p>
1689 <p><strong><code>comm</code></strong>: MPI_Comm object for parallel access. Default <code>None</code>, which
1690 means MPI_COMM_WORLD will be used.
1691 Ignored if <code>parallel=False</code>.</p>
1692 <p><strong><code>info</code></strong>: MPI_Info object for parallel access. Default <code>None</code>, which
1693 means MPI_INFO_NULL will be used.
1694 Ignored if <code>parallel=False</code>.</p>
1695 <p><strong><code>auto_complex</code></strong>: if <code>True</code>, then automatically convert complex number types</p></div>
1696 <h3>Subclasses</h3>
1697 <ul class="hlist">
1698 <li>netCDF4._netCDF4.Group</li>
1699 <li>netCDF4._netCDF4.MFDataset</li>
1700 </ul>
1701 <h3>Static methods</h3>
1702 <dl>
1703 <dt id="netCDF4.Dataset.fromcdl"><code class="name flex">
1704 <span>def <span class="ident">fromcdl</span></span>(<span>cdlfilename, ncfilename=None, mode='a', format='NETCDF4')</span>
1705 </code></dt>
1706 <dd>
1707 <div class="desc"><p><strong><code>fromcdl(cdlfilename, ncfilename=None, mode='a',format='NETCDF4')</code></strong></p>
1708 <p>call <a href="https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#ncgen_guide">ncgen</a> via subprocess to create Dataset from <a href="https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#cdl_guide">CDL</a>
1709 text representation. Requires <a href="https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#ncgen_guide">ncgen</a> to be installed and in <code>$PATH</code>.</p>
1710 <p><strong><code>cdlfilename</code></strong>:
1711 CDL file.</p>
1712 <p><strong><code>ncfilename</code></strong>: netCDF file to create. If not given, CDL filename with
1713 suffix replaced by <code>.nc</code> is used..</p>
1714 <p><strong><code>mode</code></strong>:
1715 Access mode to open Dataset (Default <code>'a'</code>).</p>
1716 <p><strong><code>format</code></strong>: underlying file format to use (one of <code>'NETCDF4'</code>,
1717 <code>'NETCDF4_CLASSIC'</code>, <code>'NETCDF3_CLASSIC'</code>, <code>'NETCDF3_64BIT_OFFSET'</code> or
1718 <code>'NETCDF3_64BIT_DATA'</code>. Default <code>'NETCDF4'</code>.</p>
1719 <p>Dataset instance for <code>ncfilename</code> is returned.</p></div>
1720 </dd>
1721 </dl>
1722 <h3>Instance variables</h3>
1723 <dl>
1724 <dt id="netCDF4.Dataset.auto_complex"><code class="name">var <span class="ident">auto_complex</span></code></dt>
1725 <dd>
1726 <div class="desc"></div>
1727 </dd>
1728 <dt id="netCDF4.Dataset.cmptypes"><code class="name">var <span class="ident">cmptypes</span></code></dt>
1729 <dd>
1730 <div class="desc"></div>
1731 </dd>
1732 <dt id="netCDF4.Dataset.data_model"><code class="name">var <span class="ident">data_model</span></code></dt>
1733 <dd>
1734 <div class="desc"></div>
1735 </dd>
1736 <dt id="netCDF4.Dataset.dimensions"><code class="name">var <span class="ident">dimensions</span></code></dt>
1737 <dd>
1738 <div class="desc"></div>
1739 </dd>
1740 <dt id="netCDF4.Dataset.disk_format"><code class="name">var <span class="ident">disk_format</span></code></dt>
1741 <dd>
1742 <div class="desc"></div>
1743 </dd>
1744 <dt id="netCDF4.Dataset.enumtypes"><code class="name">var <span class="ident">enumtypes</span></code></dt>
1745 <dd>
1746 <div class="desc"></div>
1747 </dd>
1748 <dt id="netCDF4.Dataset.file_format"><code class="name">var <span class="ident">file_format</span></code></dt>
1749 <dd>
1750 <div class="desc"></div>
1751 </dd>
1752 <dt id="netCDF4.Dataset.groups"><code class="name">var <span class="ident">groups</span></code></dt>
1753 <dd>
1754 <div class="desc"></div>
1755 </dd>
1756 <dt id="netCDF4.Dataset.keepweakref"><code class="name">var <span class="ident">keepweakref</span></code></dt>
1757 <dd>
1758 <div class="desc"></div>
1759 </dd>
1760 <dt id="netCDF4.Dataset.name"><code class="name">var <span class="ident">name</span></code></dt>
1761 <dd>
1762 <div class="desc"><p>string name of Group instance</p></div>
1763 </dd>
1764 <dt id="netCDF4.Dataset.parent"><code class="name">var <span class="ident">parent</span></code></dt>
1765 <dd>
1766 <div class="desc"></div>
1767 </dd>
1768 <dt id="netCDF4.Dataset.path"><code class="name">var <span class="ident">path</span></code></dt>
1769 <dd>
1770 <div class="desc"></div>
1771 </dd>
1772 <dt id="netCDF4.Dataset.variables"><code class="name">var <span class="ident">variables</span></code></dt>
1773 <dd>
1774 <div class="desc"></div>
1775 </dd>
1776 <dt id="netCDF4.Dataset.vltypes"><code class="name">var <span class="ident">vltypes</span></code></dt>
1777 <dd>
1778 <div class="desc"></div>
1779 </dd>
1780 </dl>
1781 <h3>Methods</h3>
1782 <dl>
1783 <dt id="netCDF4.Dataset.close"><code class="name flex">
1784 <span>def <span class="ident">close</span></span>(<span>self)</span>
1785 </code></dt>
1786 <dd>
1787 <div class="desc"><p><strong><code>close(self)</code></strong></p>
1788 <p>Close the Dataset.</p></div>
1789 </dd>
1790 <dt id="netCDF4.Dataset.createCompoundType"><code class="name flex">
1791 <span>def <span class="ident">createCompoundType</span></span>(<span>self, datatype, datatype_name)</span>
1792 </code></dt>
1793 <dd>
1794 <div class="desc"><p><strong><code>createCompoundType(self, datatype, datatype_name)</code></strong></p>
1795 <p>Creates a new compound data type named <code>datatype_name</code> from the numpy
1796 dtype object <code>datatype</code>.</p>
1797 <p><strong><em>Note</em></strong>: If the new compound data type contains other compound data types
1798 (i.e. it is a 'nested' compound type, where not all of the elements
1799 are homogeneous numeric data types), then the 'inner' compound types <strong>must</strong> be
1800 created first.</p>
1801 <p>The return value is the <code><a title="netCDF4.CompoundType" href="#netCDF4.CompoundType">CompoundType</a></code> class instance describing the new
1802 datatype.</p></div>
1803 </dd>
1804 <dt id="netCDF4.Dataset.createDimension"><code class="name flex">
1805 <span>def <span class="ident">createDimension</span></span>(<span>self, dimname, size=None)</span>
1806 </code></dt>
1807 <dd>
1808 <div class="desc"><p><strong><code>createDimension(self, dimname, size=None)</code></strong></p>
1809 <p>Creates a new dimension with the given <code>dimname</code> and <code>size</code>.</p>
1810 <p><code>size</code> must be a positive integer or <code>None</code>, which stands for
1811 "unlimited" (default is <code>None</code>). Specifying a size of 0 also
1812 results in an unlimited dimension. The return value is the <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code>
1813 class instance describing the new dimension.
1814 To determine the current
1815 maximum size of the dimension, use the <code>len</code> function on the <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code>
1816 instance. To determine if a dimension is 'unlimited', use the
1817 <code><a title="netCDF4.Dimension.isunlimited" href="#netCDF4.Dimension.isunlimited">Dimension.isunlimited()</a></code> method of the <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> instance.</p></div>
1818 </dd>
1819 <dt id="netCDF4.Dataset.createEnumType"><code class="name flex">
1820 <span>def <span class="ident">createEnumType</span></span>(<span>self, datatype, datatype_name, enum_dict)</span>
1821 </code></dt>
1822 <dd>
1823 <div class="desc"><p><strong><code>createEnumType(self, datatype, datatype_name, enum_dict)</code></strong></p>
1824 <p>Creates a new Enum data type named <code>datatype_name</code> from a numpy
1825 integer dtype object <code>datatype</code>, and a python dictionary
1826 defining the enum fields and values.</p>
1827 <p>The return value is the <code><a title="netCDF4.EnumType" href="#netCDF4.EnumType">EnumType</a></code> class instance describing the new
1828 datatype.</p></div>
1829 </dd>
1830 <dt id="netCDF4.Dataset.createGroup"><code class="name flex">
1831 <span>def <span class="ident">createGroup</span></span>(<span>self, groupname)</span>
1832 </code></dt>
1833 <dd>
1834 <div class="desc"><p><strong><code>createGroup(self, groupname)</code></strong></p>
1835 <p>Creates a new <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> with the given <code>groupname</code>.</p>
1836 <p>If <code>groupname</code> is specified as a path, using forward slashes as in unix to
1837 separate components, then intermediate groups will be created as necessary
1838 (analogous to <code>mkdir -p</code> in unix).
1839 For example,
1840 <code>createGroup('/GroupA/GroupB/GroupC')</code> will create <code>GroupA</code>,
1841 <code>GroupA/GroupB</code>, and <code>GroupA/GroupB/GroupC</code>, if they don't already exist.
1842 If the specified path describes a group that already exists, no error is
1843 raised.</p>
1844 <p>The return value is a <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> class instance.</p></div>
1845 </dd>
1846 <dt id="netCDF4.Dataset.createVLType"><code class="name flex">
1847 <span>def <span class="ident">createVLType</span></span>(<span>self, datatype, datatype_name)</span>
1848 </code></dt>
1849 <dd>
1850 <div class="desc"><p><strong><code>createVLType(self, datatype, datatype_name)</code></strong></p>
1851 <p>Creates a new VLEN data type named <code>datatype_name</code> from a numpy
1852 dtype object <code>datatype</code>.</p>
1853 <p>The return value is the <code><a title="netCDF4.VLType" href="#netCDF4.VLType">VLType</a></code> class instance describing the new
1854 datatype.</p></div>
1855 </dd>
1856 <dt id="netCDF4.Dataset.createVariable"><code class="name flex">
1857 <span>def <span class="ident">createVariable</span></span>(<span>self,<br>varname,<br>datatype,<br>dimensions=(),<br>compression=None,<br>zlib=False,<br>complevel=4,<br>shuffle=True,<br>szip_coding='nn',<br>szip_pixels_per_block=8,<br>blosc_shuffle=1,<br>fletcher32=False,<br>contiguous=False,<br>chunksizes=None,<br>endian='native',<br>least_significant_digit=None,<br>significant_digits=None,<br>quantize_mode='BitGroom',<br>fill_value=None,<br>chunk_cache=None)</span>
1858 </code></dt>
1859 <dd>
1860 <div class="desc"><p><strong><code>createVariable(self, varname, datatype, dimensions=(), compression=None, zlib=False,
1861 complevel=4, shuffle=True, fletcher32=False, contiguous=False, chunksizes=None,
1862 szip_coding='nn', szip_pixels_per_block=8, blosc_shuffle=1,
1863 endian='native', least_significant_digit=None, significant_digits=None, quantize_mode='BitGroom',
1864 fill_value=None, chunk_cache=None)</code></strong></p>
1865 <p>Creates a new variable with the given <code>varname</code>, <code>datatype</code>, and
1866 <code>dimensions</code>. If dimensions are not given, the variable is assumed to be
1867 a scalar.</p>
1868 <p>If <code>varname</code> is specified as a path, using forward slashes as in unix to
1869 separate components, then intermediate groups will be created as necessary
1870 For example, <code>createVariable('/GroupA/GroupB/VarC', float, ('x','y'))</code> will create groups <code>GroupA</code>
1871 and <code>GroupA/GroupB</code>, plus the variable <code>GroupA/GroupB/VarC</code>, if the preceding
1872 groups don't already exist.</p>
1873 <p>The <code>datatype</code> can be a numpy datatype object, or a string that describes
1874 a numpy dtype object (like the <code>dtype.str</code> attribute of a numpy array).
1875 Supported specifiers include: <code>'S1' or 'c' (NC_CHAR), 'i1' or 'b' or 'B'
1876 (NC_BYTE), 'u1' (NC_UBYTE), 'i2' or 'h' or 's' (NC_SHORT), 'u2'
1877 (NC_USHORT), 'i4' or 'i' or 'l' (NC_INT), 'u4' (NC_UINT), 'i8' (NC_INT64),
1878 'u8' (NC_UINT64), 'f4' or 'f' (NC_FLOAT), 'f8' or 'd' (NC_DOUBLE)</code>.
1879 <code>datatype</code> can also be a <code><a title="netCDF4.CompoundType" href="#netCDF4.CompoundType">CompoundType</a></code> instance
1880 (for a structured, or compound array), a <code><a title="netCDF4.VLType" href="#netCDF4.VLType">VLType</a></code> instance
1881 (for a variable-length array), or the python <code>str</code> builtin
1882 (for a variable-length string array). Numpy string and unicode datatypes with
1883 length greater than one are aliases for <code>str</code>.</p>
1884 <p>Data from netCDF variables is presented to python as numpy arrays with
1885 the corresponding data type.</p>
1886 <p><code>dimensions</code> must be a tuple containing <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> instances and/or
1887 dimension names (strings) that have been defined
1888 previously using <code><a title="netCDF4.Dataset.createDimension" href="#netCDF4.Dataset.createDimension">Dataset.createDimension()</a></code>. The default value
1889 is an empty tuple, which means the variable is a scalar.</p>
1890 <p>If the optional keyword argument <code>compression</code> is set, the data will be
1891 compressed in the netCDF file using the specified compression algorithm.
1892 Currently <code>zlib</code>,<code>szip</code>,<code>zstd</code>,<code>bzip2</code>,<code>blosc_lz</code>,<code>blosc_lz4</code>,<code>blosc_lz4hc</code>,
1893 <code>blosc_zlib</code> and <code>blosc_zstd</code> are supported.
1894 Default is <code>None</code> (no compression).
1895 All of the compressors except
1896 <code>zlib</code> and <code>szip</code> use the HDF5 plugin architecture.</p>
1897 <p>If the optional keyword <code>zlib</code> is <code>True</code>, the data will be compressed in
1898 the netCDF file using zlib compression (default <code>False</code>).
1899 The use of this option is
1900 deprecated in favor of <code>compression='zlib'</code>.</p>
1901 <p>The optional keyword <code>complevel</code> is an integer between 0 and 9 describing
1902 the level of compression desired (default 4). Ignored if <code>compression=None</code>.
1903 A value of zero disables compression.</p>
1904 <p>If the optional keyword <code>shuffle</code> is <code>True</code>, the HDF5 shuffle filter
1905 will be applied before compressing the data with zlib (default <code>True</code>).
1906 This
1907 significantly improves compression. Default is <code>True</code>. Ignored if
1908 <code>zlib=False</code>.</p>
1909 <p>The optional kwarg <code>blosc_shuffle</code>is
1910 ignored
1911 unless the blosc compressor is used. <code>blosc_shuffle</code> can be 0 (no shuffle),
1912 1 (byte-wise shuffle) or 2 (bit-wise shuffle). Default is 1.</p>
1913 <p>The optional kwargs <code>szip_coding</code> and <code>szip_pixels_per_block</code> are ignored
1914 unless the szip compressor is used. <code>szip_coding</code> can be <code>ec</code> (entropy coding)
1915 or <code>nn</code> (nearest neighbor coding). Default is <code>nn</code>. <code>szip_pixels_per_block</code>
1916 can be 4, 8, 16 or 32 (default 8).</p>
1917 <p>If the optional keyword <code>fletcher32</code> is <code>True</code>, the Fletcher32 HDF5
1918 checksum algorithm is activated to detect errors. Default <code>False</code>.</p>
1919 <p>If the optional keyword <code>contiguous</code> is <code>True</code>, the variable data is
1920 stored contiguously on disk.
1921 Default <code>False</code>. Setting to <code>True</code> for
1922 a variable with an unlimited dimension will trigger an error.
1923 Fixed size variables (with no unlimited dimension) with no compression filters
1924 are contiguous by default.</p>
1925 <p>The optional keyword <code>chunksizes</code> can be used to manually specify the
1926 HDF5 chunksizes for each dimension of the variable.
1927 A detailed discussion of HDF chunking and I/O performance is available
1928 <a href="https://support.hdfgroup.org/HDF5/doc/Advanced/Chunking">here</a>.
1929 The default chunking scheme in the netcdf-c library is discussed
1930 <a href="https://www.unidata.ucar.edu/software/netcdf/documentation/NUG/netcdf_perf_chunking.html">here</a>.
1931 Basically, you want the chunk size for each dimension to match as
1932 closely as possible the size of the data block that users will read
1933 from the file. <code>chunksizes</code> cannot be set if <code>contiguous=True</code>.</p>
1934 <p>The optional keyword <code>endian</code> can be used to control whether the
1935 data is stored in little or big endian format on disk. Possible
1936 values are <code>little, big</code> or <code>native</code> (default). The library
1937 will automatically handle endian conversions when the data is read,
1938 but if the data is always going to be read on a computer with the
1939 opposite format as the one used to create the file, there may be
1940 some performance advantage to be gained by setting the endian-ness.</p>
1941 <p>The optional keyword <code>fill_value</code> can be used to override the default
1942 netCDF <code>_FillValue</code> (the value that the variable gets filled with before
1943 any data is written to it, defaults given in the dict <code>netCDF4.default_fillvals</code>).
1944 If fill_value is set to <code>False</code>, then the variable is not pre-filled.</p>
1945 <p>If the optional keyword parameters <code>least_significant_digit</code> or <code>significant_digits</code> are
1946 specified, variable data will be truncated (quantized). In conjunction
1947 with <code>compression='zlib'</code> this produces 'lossy', but significantly more
1948 efficient compression. For example, if <code>least_significant_digit=1</code>,
1949 data will be quantized using <code>numpy.around(scale*data)/scale</code>, where
1950 scale = 2**bits, and bits is determined so that a precision of 0.1 is
1951 retained (in this case bits=4). From the
1952 <a href="http://www.esrl.noaa.gov/psl/data/gridded/conventions/cdc_netcdf_standard.shtml">PSL metadata conventions</a>:
1953 "least_significant_digit &ndash; power of ten of the smallest decimal place
1954 in unpacked data that is a reliable value." Default is <code>None</code>, or no
1955 quantization, or 'lossless' compression.
1956 If <code>significant_digits=3</code>
1957 then the data will be quantized so that three significant digits are retained, independent
1958 of the floating point exponent. The keyword argument <code>quantize_mode</code> controls
1959 the quantization algorithm (default 'BitGroom', 'BitRound' and
1960 'GranularBitRound' also available).
1961 The 'GranularBitRound'
1962 algorithm may result in better compression for typical geophysical datasets.
1963 This <code>significant_digits</code> kwarg is only available
1964 with netcdf-c &gt;= 4.9.0, and
1965 only works with <code>NETCDF4</code> or <code>NETCDF4_CLASSIC</code> formatted files.</p>
1966 <p>When creating variables in a <code>NETCDF4</code> or <code>NETCDF4_CLASSIC</code> formatted file,
1967 HDF5 creates something called a 'chunk cache' for each variable.
1968 The
1969 default size of the chunk cache may be large enough to completely fill
1970 available memory when creating thousands of variables.
1971 The optional
1972 keyword <code>chunk_cache</code> allows you to reduce (or increase) the size of
1973 the default chunk cache when creating a variable.
1974 The setting only
1975 persists as long as the Dataset is open - you can use the set_var_chunk_cache
1976 method to change it the next time the Dataset is opened.
1977 Warning - messing with this parameter can seriously degrade performance.</p>
1978 <p>The return value is the <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> class instance describing the new
1979 variable.</p>
1980 <p>A list of names corresponding to netCDF variable attributes can be
1981 obtained with the <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> method <code><a title="netCDF4.Variable.ncattrs" href="#netCDF4.Variable.ncattrs">Variable.ncattrs()</a></code>. A dictionary
1982 containing all the netCDF attribute name/value pairs is provided by
1983 the <code>__dict__</code> attribute of a <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instance.</p>
1984 <p><code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instances behave much like array objects. Data can be
1985 assigned to or retrieved from a variable with indexing and slicing
1986 operations on the <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instance. A <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instance has six
1987 Dataset standard attributes: <code>dimensions, dtype, shape, ndim, name</code> and
1988 <code>least_significant_digit</code>. Application programs should never modify
1989 these attributes. The <code>dimensions</code> attribute is a tuple containing the
1990 names of the dimensions associated with this variable. The <code>dtype</code>
1991 attribute is a string describing the variable's data type (<code>i4</code>, <code>f8</code>,
1992 <code>S1</code>, etc). The <code>shape</code> attribute is a tuple describing the current
1993 sizes of all the variable's dimensions. The <code>name</code> attribute is a
1994 string containing the name of the Variable instance.
1995 The <code>least_significant_digit</code>
1996 attributes describes the power of ten of the smallest decimal place in
1997 the data the contains a reliable value.
1998 assigned to the <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code>
1999 instance. The <code>ndim</code> attribute
2000 is the number of variable dimensions.</p></div>
2001 </dd>
2002 <dt id="netCDF4.Dataset.delncattr"><code class="name flex">
2003 <span>def <span class="ident">delncattr</span></span>(<span>self, name)</span>
2004 </code></dt>
2005 <dd>
2006 <div class="desc"><p><strong><code>delncattr(self,name,value)</code></strong></p>
2007 <p>delete a netCDF dataset or group attribute.
2008 Use if you need to delete a
2009 netCDF attribute with the same name as one of the reserved python
2010 attributes.</p></div>
2011 </dd>
2012 <dt id="netCDF4.Dataset.filepath"><code class="name flex">
2013 <span>def <span class="ident">filepath</span></span>(<span>self, encoding=None)</span>
2014 </code></dt>
2015 <dd>
2016 <div class="desc"><p><strong><code>filepath(self,encoding=None)</code></strong></p>
2017 <p>Get the file system path (or the opendap URL) which was used to
2018 open/create the Dataset. Requires netcdf &gt;= 4.1.2.
2019 The path
2020 is decoded into a string using <code>sys.getfilesystemencoding()</code> by default, this can be
2021 changed using the <code>encoding</code> kwarg.</p></div>
2022 </dd>
2023 <dt id="netCDF4.Dataset.get_variables_by_attributes"><code class="name flex">
2024 <span>def <span class="ident">get_variables_by_attributes</span></span>(<span>self, **kwargs)</span>
2025 </code></dt>
2026 <dd>
2027 <div class="desc"><p><strong><code>get_variables_by_attributes(self, **kwargs)</code></strong></p>
2028 <p>Returns a list of variables that match specific conditions.</p>
2029 <p>Can pass in key=value parameters and variables are returned that
2030 contain all of the matches. For example,</p>
2031 <pre><code class="language-python">&gt;&gt;&gt; # Get variables with x-axis attribute.
2032 &gt;&gt;&gt; vs = nc.get_variables_by_attributes(axis='X')
2033 &gt;&gt;&gt; # Get variables with matching &quot;standard_name&quot; attribute
2034 &gt;&gt;&gt; vs = nc.get_variables_by_attributes(standard_name='northward_sea_water_velocity')
2035 </code></pre>
2036 <p>Can pass in key=callable parameter and variables are returned if the
2037 callable returns True.
2038 The callable should accept a single parameter,
2039 the attribute value.
2040 None is given as the attribute value when the
2041 attribute does not exist on the variable. For example,</p>
2042 <pre><code class="language-python">&gt;&gt;&gt; # Get Axis variables
2043 &gt;&gt;&gt; vs = nc.get_variables_by_attributes(axis=lambda v: v in ['X', 'Y', 'Z', 'T'])
2044 &gt;&gt;&gt; # Get variables that don't have an &quot;axis&quot; attribute
2045 &gt;&gt;&gt; vs = nc.get_variables_by_attributes(axis=lambda v: v is None)
2046 &gt;&gt;&gt; # Get variables that have a &quot;grid_mapping&quot; attribute
2047 &gt;&gt;&gt; vs = nc.get_variables_by_attributes(grid_mapping=lambda v: v is not None)
2048 </code></pre></div>
2049 </dd>
2050 <dt id="netCDF4.Dataset.getncattr"><code class="name flex">
2051 <span>def <span class="ident">getncattr</span></span>(<span>self, name, encoding='utf-8')</span>
2052 </code></dt>
2053 <dd>
2054 <div class="desc"><p><strong><code>getncattr(self,name)</code></strong></p>
2055 <p>retrieve a netCDF dataset or group attribute.
2056 Use if you need to get a netCDF attribute with the same
2057 name as one of the reserved python attributes.</p>
2058 <p>option kwarg <code>encoding</code> can be used to specify the
2059 character encoding of a string attribute (default is <code>utf-8</code>).</p></div>
2060 </dd>
2061 <dt id="netCDF4.Dataset.has_blosc_filter"><code class="name flex">
2062 <span>def <span class="ident">has_blosc_filter</span></span>(<span>self)</span>
2063 </code></dt>
2064 <dd>
2065 <div class="desc"><p><strong><code>has_blosc_filter(self)</code></strong>
2066 returns True if blosc compression filter is available</p></div>
2067 </dd>
2068 <dt id="netCDF4.Dataset.has_bzip2_filter"><code class="name flex">
2069 <span>def <span class="ident">has_bzip2_filter</span></span>(<span>self)</span>
2070 </code></dt>
2071 <dd>
2072 <div class="desc"><p><strong><code>has_bzip2_filter(self)</code></strong>
2073 returns True if bzip2 compression filter is available</p></div>
2074 </dd>
2075 <dt id="netCDF4.Dataset.has_szip_filter"><code class="name flex">
2076 <span>def <span class="ident">has_szip_filter</span></span>(<span>self)</span>
2077 </code></dt>
2078 <dd>
2079 <div class="desc"><p><strong><code>has_szip_filter(self)</code></strong>
2080 returns True if szip compression filter is available</p></div>
2081 </dd>
2082 <dt id="netCDF4.Dataset.has_zstd_filter"><code class="name flex">
2083 <span>def <span class="ident">has_zstd_filter</span></span>(<span>self)</span>
2084 </code></dt>
2085 <dd>
2086 <div class="desc"><p><strong><code>has_zstd_filter(self)</code></strong>
2087 returns True if zstd compression filter is available</p></div>
2088 </dd>
2089 <dt id="netCDF4.Dataset.isopen"><code class="name flex">
2090 <span>def <span class="ident">isopen</span></span>(<span>self)</span>
2091 </code></dt>
2092 <dd>
2093 <div class="desc"><p><strong><code>isopen(self)</code></strong></p>
2094 <p>Is the Dataset open or closed?</p></div>
2095 </dd>
2096 <dt id="netCDF4.Dataset.ncattrs"><code class="name flex">
2097 <span>def <span class="ident">ncattrs</span></span>(<span>self)</span>
2098 </code></dt>
2099 <dd>
2100 <div class="desc"><p><strong><code>ncattrs(self)</code></strong></p>
2101 <p>return netCDF global attribute names for this <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> in a list.</p></div>
2102 </dd>
2103 <dt id="netCDF4.Dataset.renameAttribute"><code class="name flex">
2104 <span>def <span class="ident">renameAttribute</span></span>(<span>self, oldname, newname)</span>
2105 </code></dt>
2106 <dd>
2107 <div class="desc"><p><strong><code>renameAttribute(self, oldname, newname)</code></strong></p>
2108 <p>rename a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> attribute named <code>oldname</code> to <code>newname</code>.</p></div>
2109 </dd>
2110 <dt id="netCDF4.Dataset.renameDimension"><code class="name flex">
2111 <span>def <span class="ident">renameDimension</span></span>(<span>self, oldname, newname)</span>
2112 </code></dt>
2113 <dd>
2114 <div class="desc"><p><strong><code>renameDimension(self, oldname, newname)</code></strong></p>
2115 <p>rename a <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> named <code>oldname</code> to <code>newname</code>.</p></div>
2116 </dd>
2117 <dt id="netCDF4.Dataset.renameGroup"><code class="name flex">
2118 <span>def <span class="ident">renameGroup</span></span>(<span>self, oldname, newname)</span>
2119 </code></dt>
2120 <dd>
2121 <div class="desc"><p><strong><code>renameGroup(self, oldname, newname)</code></strong></p>
2122 <p>rename a <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> named <code>oldname</code> to <code>newname</code> (requires netcdf &gt;= 4.3.1).</p></div>
2123 </dd>
2124 <dt id="netCDF4.Dataset.renameVariable"><code class="name flex">
2125 <span>def <span class="ident">renameVariable</span></span>(<span>self, oldname, newname)</span>
2126 </code></dt>
2127 <dd>
2128 <div class="desc"><p><strong><code>renameVariable(self, oldname, newname)</code></strong></p>
2129 <p>rename a <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> named <code>oldname</code> to <code>newname</code></p></div>
2130 </dd>
2131 <dt id="netCDF4.Dataset.set_always_mask"><code class="name flex">
2132 <span>def <span class="ident">set_always_mask</span></span>(<span>self, value)</span>
2133 </code></dt>
2134 <dd>
2135 <div class="desc"><p><strong><code>set_always_mask(self, True_or_False)</code></strong></p>
2136 <p>Call <code><a title="netCDF4.Variable.set_always_mask" href="#netCDF4.Variable.set_always_mask">Variable.set_always_mask()</a></code> for all variables contained in
2137 this <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code>, as well as for all
2138 variables in all its subgroups.</p>
2139 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic conversion of
2140 masked arrays with no missing values to regular numpy arrays shall be
2141 applied for all variables. Default True. Set to False to restore the default behaviour
2142 in versions prior to 1.4.1 (numpy array returned unless missing values are present,
2143 otherwise masked array returned).</p>
2144 <p><strong><em>Note</em></strong>: Calling this function only affects existing
2145 variables. Variables created after calling this function will follow
2146 the default behaviour.</p></div>
2147 </dd>
2148 <dt id="netCDF4.Dataset.set_auto_chartostring"><code class="name flex">
2149 <span>def <span class="ident">set_auto_chartostring</span></span>(<span>self, value)</span>
2150 </code></dt>
2151 <dd>
2152 <div class="desc"><p><strong><code>set_auto_chartostring(self, True_or_False)</code></strong></p>
2153 <p>Call <code><a title="netCDF4.Variable.set_auto_chartostring" href="#netCDF4.Variable.set_auto_chartostring">Variable.set_auto_chartostring()</a></code> for all variables contained in this <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or
2154 <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code>, as well as for all variables in all its subgroups.</p>
2155 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic conversion of
2156 all character arrays &lt;&ndash;&gt; string arrays should be performed for
2157 character variables (variables of type <code>NC_CHAR</code> or <code>S1</code>) with the
2158 <code>_Encoding</code> attribute set.</p>
2159 <p><strong><em>Note</em></strong>: Calling this function only affects existing variables. Variables created
2160 after calling this function will follow the default behaviour.</p></div>
2161 </dd>
2162 <dt id="netCDF4.Dataset.set_auto_mask"><code class="name flex">
2163 <span>def <span class="ident">set_auto_mask</span></span>(<span>self, value)</span>
2164 </code></dt>
2165 <dd>
2166 <div class="desc"><p><strong><code>set_auto_mask(self, True_or_False)</code></strong></p>
2167 <p>Call <code><a title="netCDF4.Variable.set_auto_mask" href="#netCDF4.Variable.set_auto_mask">Variable.set_auto_mask()</a></code> for all variables contained in this <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or
2168 <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code>, as well as for all variables in all its subgroups. Only affects
2169 Variables with primitive or enum types (not compound or vlen Variables).</p>
2170 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic conversion to masked arrays
2171 shall be applied for all variables.</p>
2172 <p><strong><em>Note</em></strong>: Calling this function only affects existing variables. Variables created
2173 after calling this function will follow the default behaviour.</p></div>
2174 </dd>
2175 <dt id="netCDF4.Dataset.set_auto_maskandscale"><code class="name flex">
2176 <span>def <span class="ident">set_auto_maskandscale</span></span>(<span>self, value)</span>
2177 </code></dt>
2178 <dd>
2179 <div class="desc"><p><strong><code>set_auto_maskandscale(self, True_or_False)</code></strong></p>
2180 <p>Call <code><a title="netCDF4.Variable.set_auto_maskandscale" href="#netCDF4.Variable.set_auto_maskandscale">Variable.set_auto_maskandscale()</a></code> for all variables contained in this <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or
2181 <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code>, as well as for all variables in all its subgroups.</p>
2182 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic conversion to masked arrays
2183 and variable scaling shall be applied for all variables.</p>
2184 <p><strong><em>Note</em></strong>: Calling this function only affects existing variables. Variables created
2185 after calling this function will follow the default behaviour.</p></div>
2186 </dd>
2187 <dt id="netCDF4.Dataset.set_auto_scale"><code class="name flex">
2188 <span>def <span class="ident">set_auto_scale</span></span>(<span>self, value)</span>
2189 </code></dt>
2190 <dd>
2191 <div class="desc"><p><strong><code>set_auto_scale(self, True_or_False)</code></strong></p>
2192 <p>Call <code><a title="netCDF4.Variable.set_auto_scale" href="#netCDF4.Variable.set_auto_scale">Variable.set_auto_scale()</a></code> for all variables contained in this <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or
2193 <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code>, as well as for all variables in all its subgroups.</p>
2194 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic variable scaling
2195 shall be applied for all variables.</p>
2196 <p><strong><em>Note</em></strong>: Calling this function only affects existing variables. Variables created
2197 after calling this function will follow the default behaviour.</p></div>
2198 </dd>
2199 <dt id="netCDF4.Dataset.set_fill_off"><code class="name flex">
2200 <span>def <span class="ident">set_fill_off</span></span>(<span>self)</span>
2201 </code></dt>
2202 <dd>
2203 <div class="desc"><p><strong><code>set_fill_off(self)</code></strong></p>
2204 <p>Sets the fill mode for a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> open for writing to <code>off</code>.</p>
2205 <p>This will prevent the data from being pre-filled with fill values, which
2206 may result in some performance improvements. However, you must then make
2207 sure the data is actually written before being read.</p></div>
2208 </dd>
2209 <dt id="netCDF4.Dataset.set_fill_on"><code class="name flex">
2210 <span>def <span class="ident">set_fill_on</span></span>(<span>self)</span>
2211 </code></dt>
2212 <dd>
2213 <div class="desc"><p><strong><code>set_fill_on(self)</code></strong></p>
2214 <p>Sets the fill mode for a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> open for writing to <code>on</code>.</p>
2215 <p>This causes data to be pre-filled with fill values. The fill values can be
2216 controlled by the variable's <code>_Fill_Value</code> attribute, but is usually
2217 sufficient to the use the netCDF default <code>_Fill_Value</code> (defined
2218 separately for each variable type). The default behavior of the netCDF
2219 library corresponds to <code>set_fill_on</code>.
2220 Data which are equal to the
2221 <code>_Fill_Value</code> indicate that the variable was created, but never written
2222 to.</p></div>
2223 </dd>
2224 <dt id="netCDF4.Dataset.set_ncstring_attrs"><code class="name flex">
2225 <span>def <span class="ident">set_ncstring_attrs</span></span>(<span>self, value)</span>
2226 </code></dt>
2227 <dd>
2228 <div class="desc"><p><strong><code>set_ncstring_attrs(self, True_or_False)</code></strong></p>
2229 <p>Call <code><a title="netCDF4.Variable.set_ncstring_attrs" href="#netCDF4.Variable.set_ncstring_attrs">Variable.set_ncstring_attrs()</a></code> for all variables contained in
2230 this <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code>, as well as for all its
2231 subgroups and their variables.</p>
2232 <p><strong><code>True_or_False</code></strong>: Boolean determining if all string attributes are
2233 created as variable-length NC_STRINGs, (if True), or if ascii text
2234 attributes are stored as NC_CHARs (if False; default)</p>
2235 <p><strong><em>Note</em></strong>: Calling this function only affects newly created attributes
2236 of existing (sub-) groups and their variables.</p></div>
2237 </dd>
2238 <dt id="netCDF4.Dataset.setncattr"><code class="name flex">
2239 <span>def <span class="ident">setncattr</span></span>(<span>self, name, value)</span>
2240 </code></dt>
2241 <dd>
2242 <div class="desc"><p><strong><code>setncattr(self,name,value)</code></strong></p>
2243 <p>set a netCDF dataset or group attribute using name,value pair.
2244 Use if you need to set a netCDF attribute with the
2245 with the same name as one of the reserved python attributes.</p></div>
2246 </dd>
2247 <dt id="netCDF4.Dataset.setncattr_string"><code class="name flex">
2248 <span>def <span class="ident">setncattr_string</span></span>(<span>self, name, value)</span>
2249 </code></dt>
2250 <dd>
2251 <div class="desc"><p><strong><code>setncattr_string(self,name,value)</code></strong></p>
2252 <p>set a netCDF dataset or group string attribute using name,value pair.
2253 Use if you need to ensure that a netCDF attribute is created with type
2254 <code>NC_STRING</code> if the file format is <code>NETCDF4</code>.</p></div>
2255 </dd>
2256 <dt id="netCDF4.Dataset.setncatts"><code class="name flex">
2257 <span>def <span class="ident">setncatts</span></span>(<span>self, attdict)</span>
2258 </code></dt>
2259 <dd>
2260 <div class="desc"><p><strong><code>setncatts(self,attdict)</code></strong></p>
2261 <p>set a bunch of netCDF dataset or group attributes at once using a python dictionary.
2262 This may be faster when setting a lot of attributes for a <code>NETCDF3</code>
2263 formatted file, since nc_redef/nc_enddef is not called in between setting
2264 each attribute</p></div>
2265 </dd>
2266 <dt id="netCDF4.Dataset.sync"><code class="name flex">
2267 <span>def <span class="ident">sync</span></span>(<span>self)</span>
2268 </code></dt>
2269 <dd>
2270 <div class="desc"><p><strong><code>sync(self)</code></strong></p>
2271 <p>Writes all buffered data in the <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> to the disk file.</p></div>
2272 </dd>
2273 <dt id="netCDF4.Dataset.tocdl"><code class="name flex">
2274 <span>def <span class="ident">tocdl</span></span>(<span>self, coordvars=False, data=False, outfile=None)</span>
2275 </code></dt>
2276 <dd>
2277 <div class="desc"><p><strong><code>tocdl(self, coordvars=False, data=False, outfile=None)</code></strong></p>
2278 <p>call <a href="https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#ncdump_guide">ncdump</a> via subprocess to create <a href="https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#cdl_guide">CDL</a>
2279 text representation of Dataset. Requires <a href="https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#ncdump_guide">ncdump</a>
2280 to be installed and in <code>$PATH</code>.</p>
2281 <p><strong><code>coordvars</code></strong>: include coordinate variable data (via <code>ncdump -c</code>). Default False</p>
2282 <p><strong><code>data</code></strong>: if True, write out variable data (Default False).</p>
2283 <p><strong><code>outfile</code></strong>: If not None, file to output ncdump to. Default is to return a string.</p></div>
2284 </dd>
2285 </dl>
2286 </dd>
2287 <dt id="netCDF4.Dimension"><code class="flex name class">
2288 <span>class <span class="ident">Dimension</span></span>
2289 <span>(</span><span>...)</span>
2290 </code></dt>
2291 <dd>
2292 <div class="desc"><p>A netCDF <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> is used to describe the coordinates of a <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code>.
2293 See <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> for more details.</p>
2294 <p>The current maximum size of a <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> instance can be obtained by
2295 calling the python <code>len</code> function on the <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> instance. The
2296 <code><a title="netCDF4.Dimension.isunlimited" href="#netCDF4.Dimension.isunlimited">Dimension.isunlimited()</a></code> method of a <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> instance can be used to
2297 determine if the dimension is unlimited.</p>
2298 <p>Read-only class variables:</p>
2299 <p><strong><code>name</code></strong>: String name, used when creating a <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> with
2300 <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code>.</p>
2301 <p><strong><code>size</code></strong>: Current <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> size (same as <code>len(d)</code>, where <code>d</code> is a
2302 <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> instance).</p>
2303 <p><strong><code>__init__(self, group, name, size=None)</code></strong></p>
2304 <p><code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> constructor.</p>
2305 <p><strong><code>group</code></strong>: <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance to associate with dimension.</p>
2306 <p><strong><code>name</code></strong>: Name of the dimension.</p>
2307 <p><strong><code>size</code></strong>: Size of the dimension. <code>None</code> or 0 means unlimited. (Default <code>None</code>).</p>
2308 <p><strong><em>Note</em></strong>: <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> instances should be created using the
2309 <code><a title="netCDF4.Dataset.createDimension" href="#netCDF4.Dataset.createDimension">Dataset.createDimension()</a></code> method of a <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> or
2310 <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> instance, not using <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> directly.</p></div>
2311 <h3>Instance variables</h3>
2312 <dl>
2313 <dt id="netCDF4.Dimension.name"><code class="name">var <span class="ident">name</span></code></dt>
2314 <dd>
2315 <div class="desc"><p>string name of Dimension instance</p></div>
2316 </dd>
2317 <dt id="netCDF4.Dimension.size"><code class="name">var <span class="ident">size</span></code></dt>
2318 <dd>
2319 <div class="desc"><p>current size of Dimension (calls <code>len</code> on Dimension instance)</p></div>
2320 </dd>
2321 </dl>
2322 <h3>Methods</h3>
2323 <dl>
2324 <dt id="netCDF4.Dimension.group"><code class="name flex">
2325 <span>def <span class="ident">group</span></span>(<span>self)</span>
2326 </code></dt>
2327 <dd>
2328 <div class="desc"><p><strong><code>group(self)</code></strong></p>
2329 <p>return the group that this <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> is a member of.</p></div>
2330 </dd>
2331 <dt id="netCDF4.Dimension.isunlimited"><code class="name flex">
2332 <span>def <span class="ident">isunlimited</span></span>(<span>self)</span>
2333 </code></dt>
2334 <dd>
2335 <div class="desc"><p><strong><code>isunlimited(self)</code></strong></p>
2336 <p>returns <code>True</code> if the <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> instance is unlimited, <code>False</code> otherwise.</p></div>
2337 </dd>
2338 </dl>
2339 </dd>
2340 <dt id="netCDF4.EnumType"><code class="flex name class">
2341 <span>class <span class="ident">EnumType</span></span>
2342 <span>(</span><span>...)</span>
2343 </code></dt>
2344 <dd>
2345 <div class="desc"><p>A <code><a title="netCDF4.EnumType" href="#netCDF4.EnumType">EnumType</a></code> instance is used to describe an Enum data
2346 type, and can be passed to the the <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code> method of
2347 a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance. See
2348 <code><a title="netCDF4.EnumType" href="#netCDF4.EnumType">EnumType</a></code> for more details.</p>
2349 <p>The instance variables <code>dtype</code>, <code>name</code> and <code>enum_dict</code> should not be modified by
2350 the user.</p>
2351 <p><strong><code>__init__(group, datatype, datatype_name, enum_dict)</code></strong></p>
2352 <p>EnumType constructor.</p>
2353 <p><strong><code>group</code></strong>: <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance to associate with the VLEN datatype.</p>
2354 <p><strong><code>datatype</code></strong>: An numpy integer dtype object describing the base type
2355 for the Enum.</p>
2356 <p><strong><code>datatype_name</code></strong>: a Python string containing a description of the
2357 Enum data type.</p>
2358 <p><strong><code>enum_dict</code></strong>: a Python dictionary containing the Enum field/value
2359 pairs.</p>
2360 <p><strong><em><code>Note</code></em></strong>: <code><a title="netCDF4.EnumType" href="#netCDF4.EnumType">EnumType</a></code> instances should be created using the
2361 <code><a title="netCDF4.Dataset.createEnumType" href="#netCDF4.Dataset.createEnumType">Dataset.createEnumType()</a></code> method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or
2362 <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance, not using this class directly.</p></div>
2363 <h3>Instance variables</h3>
2364 <dl>
2365 <dt id="netCDF4.EnumType.dtype"><code class="name">var <span class="ident">dtype</span></code></dt>
2366 <dd>
2367 <div class="desc"></div>
2368 </dd>
2369 <dt id="netCDF4.EnumType.enum_dict"><code class="name">var <span class="ident">enum_dict</span></code></dt>
2370 <dd>
2371 <div class="desc"></div>
2372 </dd>
2373 <dt id="netCDF4.EnumType.name"><code class="name">var <span class="ident">name</span></code></dt>
2374 <dd>
2375 <div class="desc"></div>
2376 </dd>
2377 </dl>
2378 </dd>
2379 <dt id="netCDF4.Group"><code class="flex name class">
2380 <span>class <span class="ident">Group</span></span>
2381 <span>(</span><span>...)</span>
2382 </code></dt>
2383 <dd>
2384 <div class="desc"><p>Groups define a hierarchical namespace within a netCDF file. They are
2385 analogous to directories in a unix filesystem. Each <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> behaves like
2386 a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> within a Dataset, and can contain it's own variables,
2387 dimensions and attributes (and other Groups). See <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code>
2388 for more details.</p>
2389 <p><code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> inherits from <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code>, so all the
2390 <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> class methods and variables are available
2391 to a <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance (except the <code>close</code> method).</p>
2392 <p>Additional read-only class variables:</p>
2393 <p><strong><code>name</code></strong>: String describing the group name.</p>
2394 <p><strong><code>__init__(self, parent, name)</code></strong>
2395 <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> constructor.</p>
2396 <p><strong><code>parent</code></strong>: <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance for the parent group.
2397 If being created
2398 in the root group, use a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> instance.</p>
2399 <p><strong><code>name</code></strong>: - Name of the group.</p>
2400 <p><strong><em>Note</em></strong>: <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instances should be created using the
2401 <code><a title="netCDF4.Dataset.createGroup" href="#netCDF4.Dataset.createGroup">Dataset.createGroup()</a></code> method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> instance, or
2402 another <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance, not using this class directly.</p></div>
2403 <h3>Ancestors</h3>
2404 <ul class="hlist">
2405 <li>netCDF4._netCDF4.Dataset</li>
2406 </ul>
2407 <h3>Methods</h3>
2408 <dl>
2409 <dt id="netCDF4.Group.close"><code class="name flex">
2410 <span>def <span class="ident">close</span></span>(<span>self)</span>
2411 </code></dt>
2412 <dd>
2413 <div class="desc"><p><strong><code>close(self)</code></strong></p>
2414 <p>overrides <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> close method which does not apply to <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code>
2415 instances, raises OSError.</p></div>
2416 </dd>
2417 </dl>
2418 </dd>
2419 <dt id="netCDF4.MFDataset"><code class="flex name class">
2420 <span>class <span class="ident">MFDataset</span></span>
2421 <span>(</span><span>files, check=False, aggdim=None, exclude=[], master_file=None)</span>
2422 </code></dt>
2423 <dd>
2424 <div class="desc"><p>Class for reading multi-file netCDF Datasets, making variables
2425 spanning multiple files appear as if they were in one file.
2426 Datasets must be in <code>NETCDF4_CLASSIC</code>, <code>NETCDF3_CLASSIC</code>, <code>NETCDF3_64BIT_OFFSET</code>
2427 or <code>NETCDF3_64BIT_DATA</code> format (<code>NETCDF4</code> Datasets won't work).</p>
2428 <p>Adapted from <a href="http://pysclint.sourceforge.net/pycdf">pycdf</a> by Andre Gosselin.</p>
2429 <p>Example usage (See <code><a title="netCDF4.MFDataset" href="#netCDF4.MFDataset">MFDataset</a></code> for more details):</p>
2430 <pre><code class="language-python">&gt;&gt;&gt; import numpy as np
2431 &gt;&gt;&gt; # create a series of netCDF files with a variable sharing
2432 &gt;&gt;&gt; # the same unlimited dimension.
2433 &gt;&gt;&gt; for nf in range(10):
2434 ... with Dataset(&quot;mftest%s.nc&quot; % nf, &quot;w&quot;, format='NETCDF4_CLASSIC') as f:
2435 ... f.createDimension(&quot;x&quot;,None)
2436 ... x = f.createVariable(&quot;x&quot;,&quot;i&quot;,(&quot;x&quot;,))
2437 ... x[0:10] = np.arange(nf*10,10*(nf+1))
2438 &gt;&gt;&gt; # now read all those files in at once, in one Dataset.
2439 &gt;&gt;&gt; f = MFDataset(&quot;mftest*nc&quot;)
2440 &gt;&gt;&gt; print(f.variables[&quot;x&quot;][:])
2441 [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
2442 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
2443 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
2444 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
2445 96 97 98 99]
2446 </code></pre>
2447 <p><strong><code>__init__(self, files, check=False, aggdim=None, exclude=[],
2448 master_file=None)</code></strong></p>
2449 <p>Open a Dataset spanning multiple files, making it look as if it was a
2450 single file. Variables in the list of files that share the same
2451 dimension (specified with the keyword <code>aggdim</code>) are aggregated. If
2452 <code>aggdim</code> is not specified, the unlimited is aggregated.
2453 Currently,
2454 <code>aggdim</code> must be the leftmost (slowest varying) dimension of each
2455 of the variables to be aggregated.</p>
2456 <p><strong><code>files</code></strong>: either a sequence of netCDF files or a string with a
2457 wildcard (converted to a sorted list of files using glob)
2458 If
2459 the <code>master_file</code> kwarg is not specified, the first file
2460 in the list will become the "master" file, defining all the
2461 variables with an aggregation dimension which may span
2462 subsequent files. Attribute access returns attributes only from "master"
2463 file. The files are always opened in read-only mode.</p>
2464 <p><strong><code>check</code></strong>: True if you want to do consistency checking to ensure the
2465 correct variables structure for all of the netcdf files.
2466 Checking makes
2467 the initialization of the MFDataset instance much slower. Default is
2468 False.</p>
2469 <p><strong><code>aggdim</code></strong>: The name of the dimension to aggregate over (must
2470 be the leftmost dimension of each of the variables to be aggregated).
2471 If None (default), aggregate over the unlimited dimension.</p>
2472 <p><strong><code>exclude</code></strong>: A list of variable names to exclude from aggregation.
2473 Default is an empty list.</p>
2474 <p><strong><code>master_file</code></strong>: file to use as "master file", defining all the
2475 variables with an aggregation dimension and all global attributes.</p></div>
2476 <h3>Ancestors</h3>
2477 <ul class="hlist">
2478 <li>netCDF4._netCDF4.Dataset</li>
2479 </ul>
2480 <h3>Methods</h3>
2481 <dl>
2482 <dt id="netCDF4.MFDataset.close"><code class="name flex">
2483 <span>def <span class="ident">close</span></span>(<span>self)</span>
2484 </code></dt>
2485 <dd>
2486 <div class="desc"><p><strong><code>close(self)</code></strong></p>
2487 <p>close all the open files.</p></div>
2488 </dd>
2489 <dt id="netCDF4.MFDataset.isopen"><code class="name flex">
2490 <span>def <span class="ident">isopen</span></span>(<span>self)</span>
2491 </code></dt>
2492 <dd>
2493 <div class="desc"><p><strong><code>isopen(self)</code></strong></p>
2494 <p>True if all files are open, False otherwise.</p></div>
2495 </dd>
2496 <dt id="netCDF4.MFDataset.ncattrs"><code class="name flex">
2497 <span>def <span class="ident">ncattrs</span></span>(<span>self)</span>
2498 </code></dt>
2499 <dd>
2500 <div class="desc"><p><strong><code>ncattrs(self)</code></strong></p>
2501 <p>return the netcdf attribute names from the master file.</p></div>
2502 </dd>
2503 </dl>
2504 </dd>
2505 <dt id="netCDF4.MFTime"><code class="flex name class">
2506 <span>class <span class="ident">MFTime</span></span>
2507 <span>(</span><span>time, units=None, calendar=None)</span>
2508 </code></dt>
2509 <dd>
2510 <div class="desc"><p>Class providing an interface to a MFDataset time Variable by imposing a unique common
2511 time unit and/or calendar to all files.</p>
2512 <p>Example usage (See <code><a title="netCDF4.MFTime" href="#netCDF4.MFTime">MFTime</a></code> for more details):</p>
2513 <pre><code class="language-python">&gt;&gt;&gt; import numpy as np
2514 &gt;&gt;&gt; f1 = Dataset(&quot;mftest_1.nc&quot;,&quot;w&quot;, format=&quot;NETCDF4_CLASSIC&quot;)
2515 &gt;&gt;&gt; f2 = Dataset(&quot;mftest_2.nc&quot;,&quot;w&quot;, format=&quot;NETCDF4_CLASSIC&quot;)
2516 &gt;&gt;&gt; f1.createDimension(&quot;time&quot;,None)
2517 &gt;&gt;&gt; f2.createDimension(&quot;time&quot;,None)
2518 &gt;&gt;&gt; t1 = f1.createVariable(&quot;time&quot;,&quot;i&quot;,(&quot;time&quot;,))
2519 &gt;&gt;&gt; t2 = f2.createVariable(&quot;time&quot;,&quot;i&quot;,(&quot;time&quot;,))
2520 &gt;&gt;&gt; t1.units = &quot;days since 2000-01-01&quot;
2521 &gt;&gt;&gt; t2.units = &quot;days since 2000-02-01&quot;
2522 &gt;&gt;&gt; t1.calendar = &quot;standard&quot;
2523 &gt;&gt;&gt; t2.calendar = &quot;standard&quot;
2524 &gt;&gt;&gt; t1[:] = np.arange(31)
2525 &gt;&gt;&gt; t2[:] = np.arange(30)
2526 &gt;&gt;&gt; f1.close()
2527 &gt;&gt;&gt; f2.close()
2528 &gt;&gt;&gt; # Read the two files in at once, in one Dataset.
2529 &gt;&gt;&gt; f = MFDataset(&quot;mftest_*nc&quot;)
2530 &gt;&gt;&gt; t = f.variables[&quot;time&quot;]
2531 &gt;&gt;&gt; print(t.units)
2532 days since 2000-01-01
2533 &gt;&gt;&gt; print(t[32]) # The value written in the file, inconsistent with the MF time units.
2534 1
2535 &gt;&gt;&gt; T = MFTime(t)
2536 &gt;&gt;&gt; print(T[32])
2537 32
2538 </code></pre>
2539 <p><strong><code>__init__(self, time, units=None, calendar=None)</code></strong></p>
2540 <p>Create a time Variable with units consistent across a multifile
2541 dataset.</p>
2542 <p><strong><code>time</code></strong>: Time variable from a <code><a title="netCDF4.MFDataset" href="#netCDF4.MFDataset">MFDataset</a></code>.</p>
2543 <p><strong><code>units</code></strong>: Time units, for example, <code>'days since 1979-01-01'</code>. If <code>None</code>,
2544 use the units from the master variable.</p>
2545 <p><strong><code>calendar</code></strong>: Calendar overload to use across all files, for example,
2546 <code>'standard'</code> or <code>'gregorian'</code>. If <code>None</code>, check that the calendar attribute
2547 is present on each variable and values are unique across files raising a
2548 <code>ValueError</code> otherwise.</p></div>
2549 <h3>Ancestors</h3>
2550 <ul class="hlist">
2551 <li>netCDF4._netCDF4._Variable</li>
2552 </ul>
2553 </dd>
2554 <dt id="netCDF4.VLType"><code class="flex name class">
2555 <span>class <span class="ident">VLType</span></span>
2556 <span>(</span><span>...)</span>
2557 </code></dt>
2558 <dd>
2559 <div class="desc"><p>A <code><a title="netCDF4.VLType" href="#netCDF4.VLType">VLType</a></code> instance is used to describe a variable length (VLEN) data
2560 type, and can be passed to the the <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code> method of
2561 a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance. See
2562 <code><a title="netCDF4.VLType" href="#netCDF4.VLType">VLType</a></code> for more details.</p>
2563 <p>The instance variables <code>dtype</code> and <code>name</code> should not be modified by
2564 the user.</p>
2565 <p><strong><code>__init__(group, datatype, datatype_name)</code></strong></p>
2566 <p>VLType constructor.</p>
2567 <p><strong><code>group</code></strong>: <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance to associate with the VLEN datatype.</p>
2568 <p><strong><code>datatype</code></strong>: An numpy dtype object describing the component type for the
2569 variable length array.</p>
2570 <p><strong><code>datatype_name</code></strong>: a Python string containing a description of the
2571 VLEN data type.</p>
2572 <p><strong><em><code>Note</code></em></strong>: <code><a title="netCDF4.VLType" href="#netCDF4.VLType">VLType</a></code> instances should be created using the
2573 <code><a title="netCDF4.Dataset.createVLType" href="#netCDF4.Dataset.createVLType">Dataset.createVLType()</a></code> method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or
2574 <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance, not using this class directly.</p></div>
2575 <h3>Instance variables</h3>
2576 <dl>
2577 <dt id="netCDF4.VLType.dtype"><code class="name">var <span class="ident">dtype</span></code></dt>
2578 <dd>
2579 <div class="desc"></div>
2580 </dd>
2581 <dt id="netCDF4.VLType.name"><code class="name">var <span class="ident">name</span></code></dt>
2582 <dd>
2583 <div class="desc"></div>
2584 </dd>
2585 </dl>
2586 </dd>
2587 <dt id="netCDF4.Variable"><code class="flex name class">
2588 <span>class <span class="ident">Variable</span></span>
2589 <span>(</span><span>...)</span>
2590 </code></dt>
2591 <dd>
2592 <div class="desc"><p>A netCDF <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> is used to read and write netCDF data.
2593 They are
2594 analogous to numpy array objects. See <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> for more
2595 details.</p>
2596 <p>A list of attribute names corresponding to netCDF attributes defined for
2597 the variable can be obtained with the <code><a title="netCDF4.Variable.ncattrs" href="#netCDF4.Variable.ncattrs">Variable.ncattrs()</a></code> method. These
2598 attributes can be created by assigning to an attribute of the
2599 <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instance. A dictionary containing all the netCDF attribute
2600 name/value pairs is provided by the <code>__dict__</code> attribute of a
2601 <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instance.</p>
2602 <p>The following class variables are read-only:</p>
2603 <p><strong><code>dimensions</code></strong>: A tuple containing the names of the
2604 dimensions associated with this variable.</p>
2605 <p><strong><code>dtype</code></strong>: A numpy dtype object describing the
2606 variable's data type.</p>
2607 <p><strong><code>ndim</code></strong>: The number of variable dimensions.</p>
2608 <p><strong><code>shape</code></strong>: A tuple with the current shape (length of all dimensions).</p>
2609 <p><strong><code>scale</code></strong>: If True, <code>scale_factor</code> and <code>add_offset</code> are
2610 applied, and signed integer data is automatically converted to
2611 unsigned integer data if the <code>_Unsigned</code> attribute is set to "true" or "True".
2612 Default is <code>True</code>, can be reset using <code><a title="netCDF4.Variable.set_auto_scale" href="#netCDF4.Variable.set_auto_scale">Variable.set_auto_scale()</a></code> and
2613 <code><a title="netCDF4.Variable.set_auto_maskandscale" href="#netCDF4.Variable.set_auto_maskandscale">Variable.set_auto_maskandscale()</a></code> methods.</p>
2614 <p><strong><code>mask</code></strong>: If True, data is automatically converted to/from masked
2615 arrays when missing values or fill values are present. Default is <code>True</code>, can be
2616 reset using <code><a title="netCDF4.Variable.set_auto_mask" href="#netCDF4.Variable.set_auto_mask">Variable.set_auto_mask()</a></code> and <code><a title="netCDF4.Variable.set_auto_maskandscale" href="#netCDF4.Variable.set_auto_maskandscale">Variable.set_auto_maskandscale()</a></code>
2617 methods. Only relevant for Variables with primitive or enum types (ignored
2618 for compound and vlen Variables).</p>
2619 <p><strong><code><a title="netCDF4.chartostring" href="#netCDF4.chartostring">chartostring()</a></code></strong>: If True, data is automatically converted to/from character
2620 arrays to string arrays when the <code>_Encoding</code> variable attribute is set.
2621 Default is <code>True</code>, can be reset using
2622 <code><a title="netCDF4.Variable.set_auto_chartostring" href="#netCDF4.Variable.set_auto_chartostring">Variable.set_auto_chartostring()</a></code> method.</p>
2623 <p><strong><code>least_significant_digit</code></strong>: Describes the power of ten of the
2624 smallest decimal place in the data the contains a reliable value.
2625 Data is
2626 truncated to this decimal place when it is assigned to the <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code>
2627 instance. If <code>None</code>, the data is not truncated.</p>
2628 <p><strong><code>significant_digits</code></strong>: New in version 1.6.0. Describes the number of significant
2629 digits in the data the contains a reliable value.
2630 Data is
2631 truncated to retain this number of significant digits when it is assigned to the
2632 <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instance. If <code>None</code>, the data is not truncated.
2633 Only available with netcdf-c &gt;= 4.9.0,
2634 and only works with <code>NETCDF4</code> or <code>NETCDF4_CLASSIC</code> formatted files.
2635 The number of significant digits used in the quantization of variable data can be
2636 obtained using the <code>Variable.significant_digits</code> method. Default <code>None</code> -
2637 no quantization done.</p>
2638 <p><strong><code>quantize_mode</code></strong>: New in version 1.6.0. Controls
2639 the quantization algorithm (default 'BitGroom', 'BitRound' and
2640 'GranularBitRound' also available).
2641 The 'GranularBitRound'
2642 algorithm may result in better compression for typical geophysical datasets.
2643 Ignored if <code>significant_digits</code> not specified. If 'BitRound' is used, then
2644 <code>significant_digits</code> is interpreted as binary (not decimal) digits.</p>
2645 <p><strong><code>__orthogonal_indexing__</code></strong>: Always <code>True</code>.
2646 Indicates to client code
2647 that the object supports 'orthogonal indexing', which means that slices
2648 that are 1d arrays or lists slice along each dimension independently.
2649 This
2650 behavior is similar to Fortran or Matlab, but different than numpy.</p>
2651 <p><strong><code>datatype</code></strong>: numpy data type (for primitive data types) or VLType/CompoundType
2652 instance (for compound or vlen data types).</p>
2653 <p><strong><code>name</code></strong>: String name.</p>
2654 <p><strong><code>size</code></strong>: The number of stored elements.</p>
2655 <p><strong><code>__init__(self, group, name, datatype, dimensions=(), compression=None, zlib=False,
2656 complevel=4, shuffle=True, szip_coding='nn', szip_pixels_per_block=8,
2657 blosc_shuffle=1, fletcher32=False, contiguous=False,
2658 chunksizes=None, endian='native',
2659 least_significant_digit=None,fill_value=None,chunk_cache=None)</code></strong></p>
2660 <p><code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> constructor.</p>
2661 <p><strong><code>group</code></strong>: <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> or <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> instance to associate with variable.</p>
2662 <p><strong><code>name</code></strong>: Name of the variable.</p>
2663 <p><strong><code>datatype</code></strong>: <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> data type. Can be specified by providing a
2664 numpy dtype object, or a string that describes a numpy dtype object.
2665 Supported values, corresponding to <code>str</code> attribute of numpy dtype
2666 objects, include <code>'f4'</code> (32-bit floating point), <code>'f8'</code> (64-bit floating
2667 point), <code>'i4'</code> (32-bit signed integer), <code>'i2'</code> (16-bit signed integer),
2668 <code>'i8'</code> (64-bit signed integer), <code>'i4'</code> (8-bit signed integer), <code>'i1'</code>
2669 (8-bit signed integer), <code>'u1'</code> (8-bit unsigned integer), <code>'u2'</code> (16-bit
2670 unsigned integer), <code>'u4'</code> (32-bit unsigned integer), <code>'u8'</code> (64-bit
2671 unsigned integer), or <code>'S1'</code> (single-character string).
2672 From
2673 compatibility with Scientific.IO.NetCDF, the old Numeric single character
2674 typecodes can also be used (<code>'f'</code> instead of <code>'f4'</code>, <code>'d'</code> instead of
2675 <code>'f8'</code>, <code>'h'</code> or <code>'s'</code> instead of <code>'i2'</code>, <code>'b'</code> or <code>'B'</code> instead of
2676 <code>'i1'</code>, <code>'c'</code> instead of <code>'S1'</code>, and <code>'i'</code> or <code>'l'</code> instead of
2677 <code>'i4'</code>). <code>datatype</code> can also be a <code><a title="netCDF4.CompoundType" href="#netCDF4.CompoundType">CompoundType</a></code> instance
2678 (for a structured, or compound array), a <code><a title="netCDF4.VLType" href="#netCDF4.VLType">VLType</a></code> instance
2679 (for a variable-length array), or the python <code>str</code> builtin
2680 (for a variable-length string array). Numpy string and unicode datatypes with
2681 length greater than one are aliases for <code>str</code>.</p>
2682 <p><strong><code>dimensions</code></strong>: a tuple containing the variable's Dimension instances
2683 (defined previously with <code>createDimension</code>). Default is an empty tuple
2684 which means the variable is a scalar (and therefore has no dimensions).</p>
2685 <p><strong><code>compression</code></strong>: compression algorithm to use.
2686 Currently <code>zlib</code>,<code>szip</code>,<code>zstd</code>,<code>bzip2</code>,<code>blosc_lz</code>,<code>blosc_lz4</code>,<code>blosc_lz4hc</code>,
2687 <code>blosc_zlib</code> and <code>blosc_zstd</code> are supported.
2688 Default is <code>None</code> (no compression).
2689 All of the compressors except
2690 <code>zlib</code> and <code>szip</code> use the HDF5 plugin architecture.</p>
2691 <p><strong><code>zlib</code></strong>: if <code>True</code>, data assigned to the <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code>
2692 instance is compressed on disk. Default <code>False</code>. Deprecated - use
2693 <code>compression='zlib'</code> instead.</p>
2694 <p><strong><code>complevel</code></strong>: the level of compression to use (1 is the fastest,
2695 but poorest compression, 9 is the slowest but best compression). Default 4.
2696 Ignored if <code>compression=None</code> or <code>szip</code>. A value of 0 disables compression.</p>
2697 <p><strong><code>shuffle</code></strong>: if <code>True</code>, the HDF5 shuffle filter is applied
2698 to improve zlib compression. Default <code>True</code>. Ignored unless <code>compression = 'zlib'</code>.</p>
2699 <p><strong><code>blosc_shuffle</code></strong>: shuffle filter inside blosc compressor (only
2700 relevant if compression kwarg set to one of the blosc compressors).
2701 Can be 0 (no blosc shuffle), 1 (bytewise shuffle) or 2 (bitwise
2702 shuffle)). Default is 1. Ignored if blosc compressor not used.</p>
2703 <p><strong><code>szip_coding</code></strong>: szip coding method. Can be <code>ec</code> (entropy coding)
2704 or <code>nn</code> (nearest neighbor coding). Default is <code>nn</code>.
2705 Ignored if szip compressor not used.</p>
2706 <p><strong><code>szip_pixels_per_block</code></strong>: Can be 4,8,16 or 32 (Default 8).
2707 Ignored if szip compressor not used.</p>
2708 <p><strong><code>fletcher32</code></strong>: if <code>True</code> (default <code>False</code>), the Fletcher32 checksum
2709 algorithm is used for error detection.</p>
2710 <p><strong><code>contiguous</code></strong>: if <code>True</code> (default <code>False</code>), the variable data is
2711 stored contiguously on disk.
2712 Default <code>False</code>. Setting to <code>True</code> for
2713 a variable with an unlimited dimension will trigger an error. Fixed
2714 size variables (with no unlimited dimension) with no compression
2715 filters are contiguous by default.</p>
2716 <p><strong><code>chunksizes</code></strong>: Can be used to specify the HDF5 chunksizes for each
2717 dimension of the variable. A detailed discussion of HDF chunking and I/O
2718 performance is available
2719 <a href="https://support.hdfgroup.org/HDF5/doc/Advanced/Chunking">here</a>.
2720 The default chunking scheme in the netcdf-c library is discussed
2721 <a href="https://www.unidata.ucar.edu/software/netcdf/documentation/NUG/netcdf_perf_chunking.html">here</a>.
2722 Basically, you want the chunk size for each dimension to match as
2723 closely as possible the size of the data block that users will read
2724 from the file. <code>chunksizes</code> cannot be set if <code>contiguous=True</code>.</p>
2725 <p><strong><code>endian</code></strong>: Can be used to control whether the
2726 data is stored in little or big endian format on disk. Possible
2727 values are <code>little, big</code> or <code>native</code> (default). The library
2728 will automatically handle endian conversions when the data is read,
2729 but if the data is always going to be read on a computer with the
2730 opposite format as the one used to create the file, there may be
2731 some performance advantage to be gained by setting the endian-ness.
2732 For netCDF 3 files (that don't use HDF5), only <code>endian='native'</code> is allowed.</p>
2733 <p>The <code>compression, zlib, complevel, shuffle, fletcher32, contiguous</code> and <code>chunksizes</code>
2734 keywords are silently ignored for netCDF 3 files that do not use HDF5.</p>
2735 <p><strong><code>least_significant_digit</code></strong>: If this or <code>significant_digits</code> are specified,
2736 variable data will be truncated (quantized).
2737 In conjunction with <code>compression='zlib'</code> this produces
2738 'lossy', but significantly more efficient compression. For example, if
2739 <code>least_significant_digit=1</code>, data will be quantized using
2740 around(scale<em>data)/scale, where scale = 2</em>*bits, and bits is determined
2741 so that a precision of 0.1 is retained (in this case bits=4). Default is
2742 <code>None</code>, or no quantization.</p>
2743 <p><strong><code>significant_digits</code></strong>: New in version 1.6.0.
2744 As described for <code>least_significant_digit</code>
2745 except the number of significant digits retained is prescribed independent
2746 of the floating point exponent. Default <code>None</code> - no quantization done.</p>
2747 <p><strong><code>quantize_mode</code></strong>: New in version 1.6.0. Controls
2748 the quantization algorithm (default 'BitGroom', 'BitRound' and
2749 'GranularBitRound' also available).
2750 The 'GranularBitRound'
2751 algorithm may result in better compression for typical geophysical datasets.
2752 Ignored if <code>significant_digts</code> not specified. If 'BitRound' is used, then
2753 <code>significant_digits</code> is interpreted as binary (not decimal) digits.</p>
2754 <p><strong><code>fill_value</code></strong>:
2755 If specified, the default netCDF fill value (the
2756 value that the variable gets filled with before any data is written to it)
2757 is replaced with this value, and the <code>_FillValue</code> attribute is set.
2758 If fill_value is set to <code>False</code>, then the variable is not pre-filled.
2759 The default netCDF fill values can be found in the dictionary <code>netCDF4.default_fillvals</code>.
2760 If not set, the default fill value will be used but no <code>_FillValue</code> attribute will be created
2761 (this is the default behavior of the netcdf-c library). If you want to use the
2762 default fill value, but have the <code>_FillValue</code> attribute set, use
2763 <code>fill_value='default'</code> (note - this only works for primitive data types). <code><a title="netCDF4.Variable.get_fill_value" href="#netCDF4.Variable.get_fill_value">Variable.get_fill_value()</a></code>
2764 can be used to retrieve the fill value, even if the <code>_FillValue</code> attribute is not set.</p>
2765 <p><strong><code>chunk_cache</code></strong>: If specified, sets the chunk cache size for this variable.
2766 Persists as long as Dataset is open. Use <code>set_var_chunk_cache</code> to
2767 change it when Dataset is re-opened.</p>
2768 <p><strong><em>Note</em></strong>: <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> instances should be created using the
2769 <code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">Dataset.createVariable()</a></code> method of a <code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code> or
2770 <code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code> instance, not using this class directly.</p></div>
2771 <h3>Instance variables</h3>
2772 <dl>
2773 <dt id="netCDF4.Variable.always_mask"><code class="name">var <span class="ident">always_mask</span></code></dt>
2774 <dd>
2775 <div class="desc"></div>
2776 </dd>
2777 <dt id="netCDF4.Variable.auto_complex"><code class="name">var <span class="ident">auto_complex</span></code></dt>
2778 <dd>
2779 <div class="desc"></div>
2780 </dd>
2781 <dt id="netCDF4.Variable.chartostring"><code class="name">var <span class="ident">chartostring</span></code></dt>
2782 <dd>
2783 <div class="desc"></div>
2784 </dd>
2785 <dt id="netCDF4.Variable.datatype"><code class="name">var <span class="ident">datatype</span></code></dt>
2786 <dd>
2787 <div class="desc"><p>numpy data type (for primitive data types) or
2788 VLType/CompoundType/EnumType instance
2789 (for compound, vlen
2790 or enum data types)</p></div>
2791 </dd>
2792 <dt id="netCDF4.Variable.dimensions"><code class="name">var <span class="ident">dimensions</span></code></dt>
2793 <dd>
2794 <div class="desc"><p>get variables's dimension names</p></div>
2795 </dd>
2796 <dt id="netCDF4.Variable.dtype"><code class="name">var <span class="ident">dtype</span></code></dt>
2797 <dd>
2798 <div class="desc"></div>
2799 </dd>
2800 <dt id="netCDF4.Variable.mask"><code class="name">var <span class="ident">mask</span></code></dt>
2801 <dd>
2802 <div class="desc"></div>
2803 </dd>
2804 <dt id="netCDF4.Variable.name"><code class="name">var <span class="ident">name</span></code></dt>
2805 <dd>
2806 <div class="desc"><p>string name of Variable instance</p></div>
2807 </dd>
2808 <dt id="netCDF4.Variable.ndim"><code class="name">var <span class="ident">ndim</span></code></dt>
2809 <dd>
2810 <div class="desc"></div>
2811 </dd>
2812 <dt id="netCDF4.Variable.scale"><code class="name">var <span class="ident">scale</span></code></dt>
2813 <dd>
2814 <div class="desc"></div>
2815 </dd>
2816 <dt id="netCDF4.Variable.shape"><code class="name">var <span class="ident">shape</span></code></dt>
2817 <dd>
2818 <div class="desc"><p>find current sizes of all variable dimensions</p></div>
2819 </dd>
2820 <dt id="netCDF4.Variable.size"><code class="name">var <span class="ident">size</span></code></dt>
2821 <dd>
2822 <div class="desc"><p>Return the number of stored elements.</p></div>
2823 </dd>
2824 </dl>
2825 <h3>Methods</h3>
2826 <dl>
2827 <dt id="netCDF4.Variable.assignValue"><code class="name flex">
2828 <span>def <span class="ident">assignValue</span></span>(<span>self, val)</span>
2829 </code></dt>
2830 <dd>
2831 <div class="desc"><p><strong><code>assignValue(self, val)</code></strong></p>
2832 <p>assign a value to a scalar variable.
2833 Provided for compatibility with
2834 Scientific.IO.NetCDF, can also be done by assigning to an Ellipsis slice ([&hellip;]).</p></div>
2835 </dd>
2836 <dt id="netCDF4.Variable.chunking"><code class="name flex">
2837 <span>def <span class="ident">chunking</span></span>(<span>self)</span>
2838 </code></dt>
2839 <dd>
2840 <div class="desc"><p><strong><code>chunking(self)</code></strong></p>
2841 <p>return variable chunking information.
2842 If the dataset is
2843 defined to be contiguous (and hence there is no chunking) the word 'contiguous'
2844 is returned.
2845 Otherwise, a sequence with the chunksize for
2846 each dimension is returned.</p></div>
2847 </dd>
2848 <dt id="netCDF4.Variable.delncattr"><code class="name flex">
2849 <span>def <span class="ident">delncattr</span></span>(<span>self, name)</span>
2850 </code></dt>
2851 <dd>
2852 <div class="desc"><p><strong><code>delncattr(self,name,value)</code></strong></p>
2853 <p>delete a netCDF variable attribute.
2854 Use if you need to delete a
2855 netCDF attribute with the same name as one of the reserved python
2856 attributes.</p></div>
2857 </dd>
2858 <dt id="netCDF4.Variable.endian"><code class="name flex">
2859 <span>def <span class="ident">endian</span></span>(<span>self)</span>
2860 </code></dt>
2861 <dd>
2862 <div class="desc"><p><strong><code>endian(self)</code></strong></p>
2863 <p>return endian-ness (<code>little,big,native</code>) of variable (as stored in HDF5 file).</p></div>
2864 </dd>
2865 <dt id="netCDF4.Variable.filters"><code class="name flex">
2866 <span>def <span class="ident">filters</span></span>(<span>self)</span>
2867 </code></dt>
2868 <dd>
2869 <div class="desc"><p><strong><code>filters(self)</code></strong></p>
2870 <p>return dictionary containing HDF5 filter parameters.</p></div>
2871 </dd>
2872 <dt id="netCDF4.Variable.getValue"><code class="name flex">
2873 <span>def <span class="ident">getValue</span></span>(<span>self)</span>
2874 </code></dt>
2875 <dd>
2876 <div class="desc"><p><strong><code>getValue(self)</code></strong></p>
2877 <p>get the value of a scalar variable.
2878 Provided for compatibility with
2879 Scientific.IO.NetCDF, can also be done by slicing with an Ellipsis ([&hellip;]).</p></div>
2880 </dd>
2881 <dt id="netCDF4.Variable.get_dims"><code class="name flex">
2882 <span>def <span class="ident">get_dims</span></span>(<span>self)</span>
2883 </code></dt>
2884 <dd>
2885 <div class="desc"><p><strong><code>get_dims(self)</code></strong></p>
2886 <p>return a tuple of <code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code> instances associated with this
2887 <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code>.</p></div>
2888 </dd>
2889 <dt id="netCDF4.Variable.get_fill_value"><code class="name flex">
2890 <span>def <span class="ident">get_fill_value</span></span>(<span>self)</span>
2891 </code></dt>
2892 <dd>
2893 <div class="desc"><p><strong><code>get_fill_value(self)</code></strong></p>
2894 <p>return the fill value associated with this <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> (returns <code>None</code> if data is not
2895 pre-filled). Works even if default fill value was used, and <code>_FillValue</code> attribute
2896 does not exist.</p></div>
2897 </dd>
2898 <dt id="netCDF4.Variable.get_var_chunk_cache"><code class="name flex">
2899 <span>def <span class="ident">get_var_chunk_cache</span></span>(<span>self)</span>
2900 </code></dt>
2901 <dd>
2902 <div class="desc"><p><strong><code>get_var_chunk_cache(self)</code></strong></p>
2903 <p>return variable chunk cache information in a tuple (size,nelems,preemption).
2904 See netcdf C library documentation for <code>nc_get_var_chunk_cache</code> for
2905 details.</p></div>
2906 </dd>
2907 <dt id="netCDF4.Variable.getncattr"><code class="name flex">
2908 <span>def <span class="ident">getncattr</span></span>(<span>self, name, encoding='utf-8')</span>
2909 </code></dt>
2910 <dd>
2911 <div class="desc"><p><strong><code>getncattr(self,name)</code></strong></p>
2912 <p>retrieve a netCDF variable attribute.
2913 Use if you need to set a
2914 netCDF attribute with the same name as one of the reserved python
2915 attributes.</p>
2916 <p>option kwarg <code>encoding</code> can be used to specify the
2917 character encoding of a string attribute (default is <code>utf-8</code>).</p></div>
2918 </dd>
2919 <dt id="netCDF4.Variable.group"><code class="name flex">
2920 <span>def <span class="ident">group</span></span>(<span>self)</span>
2921 </code></dt>
2922 <dd>
2923 <div class="desc"><p><strong><code>group(self)</code></strong></p>
2924 <p>return the group that this <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> is a member of.</p></div>
2925 </dd>
2926 <dt id="netCDF4.Variable.ncattrs"><code class="name flex">
2927 <span>def <span class="ident">ncattrs</span></span>(<span>self)</span>
2928 </code></dt>
2929 <dd>
2930 <div class="desc"><p><strong><code>ncattrs(self)</code></strong></p>
2931 <p>return netCDF attribute names for this <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> in a list.</p></div>
2932 </dd>
2933 <dt id="netCDF4.Variable.quantization"><code class="name flex">
2934 <span>def <span class="ident">quantization</span></span>(<span>self)</span>
2935 </code></dt>
2936 <dd>
2937 <div class="desc"><p><strong><code>quantization(self)</code></strong></p>
2938 <p>return number of significant digits and the algorithm used in quantization.
2939 Returns None if quantization not active.</p></div>
2940 </dd>
2941 <dt id="netCDF4.Variable.renameAttribute"><code class="name flex">
2942 <span>def <span class="ident">renameAttribute</span></span>(<span>self, oldname, newname)</span>
2943 </code></dt>
2944 <dd>
2945 <div class="desc"><p><strong><code>renameAttribute(self, oldname, newname)</code></strong></p>
2946 <p>rename a <code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code> attribute named <code>oldname</code> to <code>newname</code>.</p></div>
2947 </dd>
2948 <dt id="netCDF4.Variable.set_always_mask"><code class="name flex">
2949 <span>def <span class="ident">set_always_mask</span></span>(<span>self, always_mask)</span>
2950 </code></dt>
2951 <dd>
2952 <div class="desc"><p><strong><code>set_always_mask(self,always_mask)</code></strong></p>
2953 <p>turn on or off conversion of data without missing values to regular
2954 numpy arrays.</p>
2955 <p><code>always_mask</code> is a Boolean determining if automatic conversion of
2956 masked arrays with no missing values to regular numpy arrays shall be
2957 applied. Default is True. Set to False to restore the default behaviour
2958 in versions prior to 1.4.1 (numpy array returned unless missing values are present,
2959 otherwise masked array returned).</p></div>
2960 </dd>
2961 <dt id="netCDF4.Variable.set_auto_chartostring"><code class="name flex">
2962 <span>def <span class="ident">set_auto_chartostring</span></span>(<span>self, chartostring)</span>
2963 </code></dt>
2964 <dd>
2965 <div class="desc"><p><strong><code>set_auto_chartostring(self,<a title="netCDF4.chartostring" href="#netCDF4.chartostring">chartostring()</a>)</code></strong></p>
2966 <p>turn on or off automatic conversion of character variable data to and
2967 from numpy fixed length string arrays when the <code>_Encoding</code> variable attribute
2968 is set.</p>
2969 <p>If <code><a title="netCDF4.chartostring" href="#netCDF4.chartostring">chartostring()</a></code> is set to <code>True</code>, when data is read from a character variable
2970 (dtype = <code>S1</code>) that has an <code>_Encoding</code> attribute, it is converted to a numpy
2971 fixed length unicode string array (dtype = <code>UN</code>, where <code>N</code> is the length
2972 of the the rightmost dimension of the variable).
2973 The value of <code>_Encoding</code>
2974 is the unicode encoding that is used to decode the bytes into strings.</p>
2975 <p>When numpy string data is written to a variable it is converted back to
2976 individual bytes, with the number of bytes in each string equalling the
2977 rightmost dimension of the variable.</p>
2978 <p>The default value of <code><a title="netCDF4.chartostring" href="#netCDF4.chartostring">chartostring()</a></code> is <code>True</code>
2979 (automatic conversions are performed).</p></div>
2980 </dd>
2981 <dt id="netCDF4.Variable.set_auto_mask"><code class="name flex">
2982 <span>def <span class="ident">set_auto_mask</span></span>(<span>self, mask)</span>
2983 </code></dt>
2984 <dd>
2985 <div class="desc"><p><strong><code>set_auto_mask(self,mask)</code></strong></p>
2986 <p>turn on or off automatic conversion of variable data to and
2987 from masked arrays .</p>
2988 <p>If <code>mask</code> is set to <code>True</code>, when data is read from a variable
2989 it is converted to a masked array if any of the values are exactly
2990 equal to the either the netCDF _FillValue or the value specified by the
2991 missing_value variable attribute. The fill_value of the masked array
2992 is set to the missing_value attribute (if it exists), otherwise
2993 the netCDF _FillValue attribute (which has a default value
2994 for each data type). If the variable has no missing_value attribute, the
2995 _FillValue is used instead. If the variable has valid_min/valid_max and
2996 missing_value attributes, data outside the specified range will be masked.
2997 When data is written to a variable, the masked
2998 array is converted back to a regular numpy array by replacing all the
2999 masked values by the missing_value attribute of the variable (if it
3000 exists).
3001 If the variable has no missing_value attribute, the _FillValue
3002 is used instead.</p>
3003 <p>The default value of <code>mask</code> is <code>True</code>
3004 (automatic conversions are performed).</p></div>
3005 </dd>
3006 <dt id="netCDF4.Variable.set_auto_maskandscale"><code class="name flex">
3007 <span>def <span class="ident">set_auto_maskandscale</span></span>(<span>self, maskandscale)</span>
3008 </code></dt>
3009 <dd>
3010 <div class="desc"><p><strong><code>set_auto_maskandscale(self,maskandscale)</code></strong></p>
3011 <p>turn on or off automatic conversion of variable data to and
3012 from masked arrays, automatic packing/unpacking of variable
3013 data using <code>scale_factor</code> and <code>add_offset</code> attributes and
3014 automatic conversion of signed integer data to unsigned integer
3015 data if the <code>_Unsigned</code> attribute exists and is set to "true" (or "True").</p>
3016 <p>If <code>maskandscale</code> is set to <code>True</code>, when data is read from a variable
3017 it is converted to a masked array if any of the values are exactly
3018 equal to the either the netCDF _FillValue or the value specified by the
3019 missing_value variable attribute. The fill_value of the masked array
3020 is set to the missing_value attribute (if it exists), otherwise
3021 the netCDF _FillValue attribute (which has a default value
3022 for each data type). If the variable has no missing_value attribute, the
3023 _FillValue is used instead. If the variable has valid_min/valid_max and
3024 missing_value attributes, data outside the specified range will be masked.
3025 When data is written to a variable, the masked
3026 array is converted back to a regular numpy array by replacing all the
3027 masked values by the missing_value attribute of the variable (if it
3028 exists).
3029 If the variable has no missing_value attribute, the _FillValue
3030 is used instead.</p>
3031 <p>If <code>maskandscale</code> is set to <code>True</code>, and the variable has a
3032 <code>scale_factor</code> or an <code>add_offset</code> attribute, then data read
3033 from that variable is unpacked using::</p>
3034 <pre><code>data = self.scale_factor*data + self.add_offset
3035 </code></pre>
3036 <p>When data is written to a variable it is packed using::</p>
3037 <pre><code>data = (data - self.add_offset)/self.scale_factor
3038 </code></pre>
3039 <p>If either scale_factor is present, but add_offset is missing, add_offset
3040 is assumed zero.
3041 If add_offset is present, but scale_factor is missing,
3042 scale_factor is assumed to be one.
3043 For more information on how <code>scale_factor</code> and <code>add_offset</code> can be
3044 used to provide simple compression, see the
3045 <a href="http://www.esrl.noaa.gov/psl/data/gridded/conventions/cdc_netcdf_standard.shtml">PSL metadata conventions</a>.</p>
3046 <p>In addition, if <code>maskandscale</code> is set to <code>True</code>, and if the variable has an
3047 attribute <code>_Unsigned</code> set to "true", and the variable has a signed integer data type,
3048 a view to the data is returned with the corresponding unsigned integer data type.
3049 This convention is used by the netcdf-java library to save unsigned integer
3050 data in <code>NETCDF3</code> or <code>NETCDF4_CLASSIC</code> files (since the <code>NETCDF3</code>
3051 data model does not have unsigned integer data types).</p>
3052 <p>The default value of <code>maskandscale</code> is <code>True</code>
3053 (automatic conversions are performed).</p></div>
3054 </dd>
3055 <dt id="netCDF4.Variable.set_auto_scale"><code class="name flex">
3056 <span>def <span class="ident">set_auto_scale</span></span>(<span>self, scale)</span>
3057 </code></dt>
3058 <dd>
3059 <div class="desc"><p><strong><code>set_auto_scale(self,scale)</code></strong></p>
3060 <p>turn on or off automatic packing/unpacking of variable
3061 data using <code>scale_factor</code> and <code>add_offset</code> attributes.
3062 Also turns on and off automatic conversion of signed integer data
3063 to unsigned integer data if the variable has an <code>_Unsigned</code>
3064 attribute set to "true" or "True".</p>
3065 <p>If <code>scale</code> is set to <code>True</code>, and the variable has a
3066 <code>scale_factor</code> or an <code>add_offset</code> attribute, then data read
3067 from that variable is unpacked using::</p>
3068 <pre><code>data = self.scale_factor*data + self.add_offset
3069 </code></pre>
3070 <p>When data is written to a variable it is packed using::</p>
3071 <pre><code>data = (data - self.add_offset)/self.scale_factor
3072 </code></pre>
3073 <p>If either scale_factor is present, but add_offset is missing, add_offset
3074 is assumed zero.
3075 If add_offset is present, but scale_factor is missing,
3076 scale_factor is assumed to be one.
3077 For more information on how <code>scale_factor</code> and <code>add_offset</code> can be
3078 used to provide simple compression, see the
3079 <a href="http://www.esrl.noaa.gov/psl/data/gridded/conventions/cdc_netcdf_standard.shtml">PSL metadata conventions</a>.</p>
3080 <p>In addition, if <code>scale</code> is set to <code>True</code>, and if the variable has an
3081 attribute <code>_Unsigned</code> set to "true", and the variable has a signed integer data type,
3082 a view to the data is returned with the corresponding unsigned integer datatype.
3083 This convention is used by the netcdf-java library to save unsigned integer
3084 data in <code>NETCDF3</code> or <code>NETCDF4_CLASSIC</code> files (since the <code>NETCDF3</code>
3085 data model does not have unsigned integer data types).</p>
3086 <p>The default value of <code>scale</code> is <code>True</code>
3087 (automatic conversions are performed).</p></div>
3088 </dd>
3089 <dt id="netCDF4.Variable.set_collective"><code class="name flex">
3090 <span>def <span class="ident">set_collective</span></span>(<span>self, value)</span>
3091 </code></dt>
3092 <dd>
3093 <div class="desc"><p><strong><code>set_collective(self,True_or_False)</code></strong></p>
3094 <p>turn on or off collective parallel IO access. Ignored if file is not
3095 open for parallel access.</p></div>
3096 </dd>
3097 <dt id="netCDF4.Variable.set_ncstring_attrs"><code class="name flex">
3098 <span>def <span class="ident">set_ncstring_attrs</span></span>(<span>self, ncstring_attrs)</span>
3099 </code></dt>
3100 <dd>
3101 <div class="desc"><p><strong><code>set_always_mask(self,ncstring_attrs)</code></strong></p>
3102 <p>turn on or off creating NC_STRING string attributes.</p>
3103 <p>If <code>ncstring_attrs</code> is set to <code>True</code> then text attributes will be variable-length
3104 NC_STRINGs.</p>
3105 <p>The default value of <code>ncstring_attrs</code> is <code>False</code> (writing ascii text attributes as
3106 NC_CHAR).</p></div>
3107 </dd>
3108 <dt id="netCDF4.Variable.set_var_chunk_cache"><code class="name flex">
3109 <span>def <span class="ident">set_var_chunk_cache</span></span>(<span>self, size=None, nelems=None, preemption=None)</span>
3110 </code></dt>
3111 <dd>
3112 <div class="desc"><p><strong><code>set_var_chunk_cache(self,size=None,nelems=None,preemption=None)</code></strong></p>
3113 <p>change variable chunk cache settings.
3114 See netcdf C library documentation for <code>nc_set_var_chunk_cache</code> for
3115 details.</p></div>
3116 </dd>
3117 <dt id="netCDF4.Variable.setncattr"><code class="name flex">
3118 <span>def <span class="ident">setncattr</span></span>(<span>self, name, value)</span>
3119 </code></dt>
3120 <dd>
3121 <div class="desc"><p><strong><code>setncattr(self,name,value)</code></strong></p>
3122 <p>set a netCDF variable attribute using name,value pair.
3123 Use if you need to set a
3124 netCDF attribute with the same name as one of the reserved python
3125 attributes.</p></div>
3126 </dd>
3127 <dt id="netCDF4.Variable.setncattr_string"><code class="name flex">
3128 <span>def <span class="ident">setncattr_string</span></span>(<span>self, name, value)</span>
3129 </code></dt>
3130 <dd>
3131 <div class="desc"><p><strong><code>setncattr_string(self,name,value)</code></strong></p>
3132 <p>set a netCDF variable string attribute using name,value pair.
3133 Use if you need to ensure that a netCDF attribute is created with type
3134 <code>NC_STRING</code> if the file format is <code>NETCDF4</code>.
3135 Use if you need to set an attribute to an array of variable-length strings.</p></div>
3136 </dd>
3137 <dt id="netCDF4.Variable.setncatts"><code class="name flex">
3138 <span>def <span class="ident">setncatts</span></span>(<span>self, attdict)</span>
3139 </code></dt>
3140 <dd>
3141 <div class="desc"><p><strong><code>setncatts(self,attdict)</code></strong></p>
3142 <p>set a bunch of netCDF variable attributes at once using a python dictionary.
3143 This may be faster when setting a lot of attributes for a <code>NETCDF3</code>
3144 formatted file, since nc_redef/nc_enddef is not called in between setting
3145 each attribute</p></div>
3146 </dd>
3147 <dt id="netCDF4.Variable.use_nc_get_vars"><code class="name flex">
3148 <span>def <span class="ident">use_nc_get_vars</span></span>(<span>self, use_nc_get_vars)</span>
3149 </code></dt>
3150 <dd>
3151 <div class="desc"><p><strong><code>use_nc_get_vars(self,_use_get_vars)</code></strong></p>
3152 <p>enable the use of netcdf library routine <code>nc_get_vars</code>
3153 to retrieve strided variable slices.
3154 By default,
3155 <code>nc_get_vars</code> may not used by default (depending on the
3156 version of the netcdf-c library being used) since it may be
3157 slower than multiple calls to the unstrided read routine <code>nc_get_vara</code>.</p></div>
3158 </dd>
3159 </dl>
3160 </dd>
3161 </dl>
3162 </section>
3163 </article>
3164 <nav id="sidebar">
3165 <div class="toc">
3166 <ul>
3167 <li><a href="#version-174">Version 1.7.4</a></li>
3168 <li><a href="#introduction">Introduction</a><ul>
3169 <li><a href="#quick-install">Quick Install</a></li>
3170 <li><a href="#developer-install">Developer Install</a></li>
3171 </ul>
3172 </li>
3173 <li><a href="#tutorial">Tutorial</a><ul>
3174 <li><a href="#creatingopeningclosing-a-netcdf-file">Creating/Opening/Closing a netCDF file</a></li>
3175 <li><a href="#groups-in-a-netcdf-file">Groups in a netCDF file</a></li>
3176 <li><a href="#dimensions-in-a-netcdf-file">Dimensions in a netCDF file</a></li>
3177 <li><a href="#variables-in-a-netcdf-file">Variables in a netCDF file</a></li>
3178 <li><a href="#attributes-in-a-netcdf-file">Attributes in a netCDF file</a></li>
3179 <li><a href="#writing-data-to-and-retrieving-data-from-a-netcdf-variable">Writing data to and retrieving data from a netCDF variable</a></li>
3180 <li><a href="#dealing-with-time-coordinates">Dealing with time coordinates</a></li>
3181 <li><a href="#reading-data-from-a-multi-file-netcdf-dataset">Reading data from a multi-file netCDF dataset</a></li>
3182 <li><a href="#efficient-compression-of-netcdf-variables">Efficient compression of netCDF variables</a></li>
3183 <li><a href="#beyond-homogeneous-arrays-of-a-fixed-type-compound-data-types">Beyond homogeneous arrays of a fixed type - compound data types</a></li>
3184 <li><a href="#variable-length-vlen-data-types">Variable-length (vlen) data types</a></li>
3185 <li><a href="#enum-data-type">Enum data type</a></li>
3186 <li><a href="#parallel-io">Parallel IO</a></li>
3187 <li><a href="#dealing-with-strings">Dealing with strings</a></li>
3188 <li><a href="#in-memory-diskless-datasets">In-memory (diskless) Datasets</a></li>
3189 <li><a href="#support-for-complex-numbers">Support for complex numbers</a></li>
3190 </ul>
3191 </li>
3192 </ul>
3193 </div>
3194 <ul id="index">
3195 <li><h3><a href="#header-functions">Functions</a></h3>
3196 <ul class="two-column">
3197 <li><code><a title="netCDF4.chartostring" href="#netCDF4.chartostring">chartostring</a></code></li>
3198 <li><code><a title="netCDF4.date2index" href="#netCDF4.date2index">date2index</a></code></li>
3199 <li><code><a title="netCDF4.date2num" href="#netCDF4.date2num">date2num</a></code></li>
3200 <li><code><a title="netCDF4.get_alignment" href="#netCDF4.get_alignment">get_alignment</a></code></li>
3201 <li><code><a title="netCDF4.get_chunk_cache" href="#netCDF4.get_chunk_cache">get_chunk_cache</a></code></li>
3202 <li><code><a title="netCDF4.getlibversion" href="#netCDF4.getlibversion">getlibversion</a></code></li>
3203 <li><code><a title="netCDF4.num2date" href="#netCDF4.num2date">num2date</a></code></li>
3204 <li><code><a title="netCDF4.rc_get" href="#netCDF4.rc_get">rc_get</a></code></li>
3205 <li><code><a title="netCDF4.rc_set" href="#netCDF4.rc_set">rc_set</a></code></li>
3206 <li><code><a title="netCDF4.set_alignment" href="#netCDF4.set_alignment">set_alignment</a></code></li>
3207 <li><code><a title="netCDF4.set_chunk_cache" href="#netCDF4.set_chunk_cache">set_chunk_cache</a></code></li>
3208 <li><code><a title="netCDF4.stringtoarr" href="#netCDF4.stringtoarr">stringtoarr</a></code></li>
3209 <li><code><a title="netCDF4.stringtochar" href="#netCDF4.stringtochar">stringtochar</a></code></li>
3210 </ul>
3211 </li>
3212 <li><h3><a href="#header-classes">Classes</a></h3>
3213 <ul>
3214 <li>
3215 <h4><code><a title="netCDF4.CompoundType" href="#netCDF4.CompoundType">CompoundType</a></code></h4>
3216 <ul class="">
3217 <li><code><a title="netCDF4.CompoundType.dtype" href="#netCDF4.CompoundType.dtype">dtype</a></code></li>
3218 <li><code><a title="netCDF4.CompoundType.dtype_view" href="#netCDF4.CompoundType.dtype_view">dtype_view</a></code></li>
3219 <li><code><a title="netCDF4.CompoundType.name" href="#netCDF4.CompoundType.name">name</a></code></li>
3220 </ul>
3221 </li>
3222 <li>
3223 <h4><code><a title="netCDF4.Dataset" href="#netCDF4.Dataset">Dataset</a></code></h4>
3224 <ul class="">
3225 <li><code><a title="netCDF4.Dataset.auto_complex" href="#netCDF4.Dataset.auto_complex">auto_complex</a></code></li>
3226 <li><code><a title="netCDF4.Dataset.close" href="#netCDF4.Dataset.close">close</a></code></li>
3227 <li><code><a title="netCDF4.Dataset.cmptypes" href="#netCDF4.Dataset.cmptypes">cmptypes</a></code></li>
3228 <li><code><a title="netCDF4.Dataset.createCompoundType" href="#netCDF4.Dataset.createCompoundType">createCompoundType</a></code></li>
3229 <li><code><a title="netCDF4.Dataset.createDimension" href="#netCDF4.Dataset.createDimension">createDimension</a></code></li>
3230 <li><code><a title="netCDF4.Dataset.createEnumType" href="#netCDF4.Dataset.createEnumType">createEnumType</a></code></li>
3231 <li><code><a title="netCDF4.Dataset.createGroup" href="#netCDF4.Dataset.createGroup">createGroup</a></code></li>
3232 <li><code><a title="netCDF4.Dataset.createVLType" href="#netCDF4.Dataset.createVLType">createVLType</a></code></li>
3233 <li><code><a title="netCDF4.Dataset.createVariable" href="#netCDF4.Dataset.createVariable">createVariable</a></code></li>
3234 <li><code><a title="netCDF4.Dataset.data_model" href="#netCDF4.Dataset.data_model">data_model</a></code></li>
3235 <li><code><a title="netCDF4.Dataset.delncattr" href="#netCDF4.Dataset.delncattr">delncattr</a></code></li>
3236 <li><code><a title="netCDF4.Dataset.dimensions" href="#netCDF4.Dataset.dimensions">dimensions</a></code></li>
3237 <li><code><a title="netCDF4.Dataset.disk_format" href="#netCDF4.Dataset.disk_format">disk_format</a></code></li>
3238 <li><code><a title="netCDF4.Dataset.enumtypes" href="#netCDF4.Dataset.enumtypes">enumtypes</a></code></li>
3239 <li><code><a title="netCDF4.Dataset.file_format" href="#netCDF4.Dataset.file_format">file_format</a></code></li>
3240 <li><code><a title="netCDF4.Dataset.filepath" href="#netCDF4.Dataset.filepath">filepath</a></code></li>
3241 <li><code><a title="netCDF4.Dataset.fromcdl" href="#netCDF4.Dataset.fromcdl">fromcdl</a></code></li>
3242 <li><code><a title="netCDF4.Dataset.get_variables_by_attributes" href="#netCDF4.Dataset.get_variables_by_attributes">get_variables_by_attributes</a></code></li>
3243 <li><code><a title="netCDF4.Dataset.getncattr" href="#netCDF4.Dataset.getncattr">getncattr</a></code></li>
3244 <li><code><a title="netCDF4.Dataset.groups" href="#netCDF4.Dataset.groups">groups</a></code></li>
3245 <li><code><a title="netCDF4.Dataset.has_blosc_filter" href="#netCDF4.Dataset.has_blosc_filter">has_blosc_filter</a></code></li>
3246 <li><code><a title="netCDF4.Dataset.has_bzip2_filter" href="#netCDF4.Dataset.has_bzip2_filter">has_bzip2_filter</a></code></li>
3247 <li><code><a title="netCDF4.Dataset.has_szip_filter" href="#netCDF4.Dataset.has_szip_filter">has_szip_filter</a></code></li>
3248 <li><code><a title="netCDF4.Dataset.has_zstd_filter" href="#netCDF4.Dataset.has_zstd_filter">has_zstd_filter</a></code></li>
3249 <li><code><a title="netCDF4.Dataset.isopen" href="#netCDF4.Dataset.isopen">isopen</a></code></li>
3250 <li><code><a title="netCDF4.Dataset.keepweakref" href="#netCDF4.Dataset.keepweakref">keepweakref</a></code></li>
3251 <li><code><a title="netCDF4.Dataset.name" href="#netCDF4.Dataset.name">name</a></code></li>
3252 <li><code><a title="netCDF4.Dataset.ncattrs" href="#netCDF4.Dataset.ncattrs">ncattrs</a></code></li>
3253 <li><code><a title="netCDF4.Dataset.parent" href="#netCDF4.Dataset.parent">parent</a></code></li>
3254 <li><code><a title="netCDF4.Dataset.path" href="#netCDF4.Dataset.path">path</a></code></li>
3255 <li><code><a title="netCDF4.Dataset.renameAttribute" href="#netCDF4.Dataset.renameAttribute">renameAttribute</a></code></li>
3256 <li><code><a title="netCDF4.Dataset.renameDimension" href="#netCDF4.Dataset.renameDimension">renameDimension</a></code></li>
3257 <li><code><a title="netCDF4.Dataset.renameGroup" href="#netCDF4.Dataset.renameGroup">renameGroup</a></code></li>
3258 <li><code><a title="netCDF4.Dataset.renameVariable" href="#netCDF4.Dataset.renameVariable">renameVariable</a></code></li>
3259 <li><code><a title="netCDF4.Dataset.set_always_mask" href="#netCDF4.Dataset.set_always_mask">set_always_mask</a></code></li>
3260 <li><code><a title="netCDF4.Dataset.set_auto_chartostring" href="#netCDF4.Dataset.set_auto_chartostring">set_auto_chartostring</a></code></li>
3261 <li><code><a title="netCDF4.Dataset.set_auto_mask" href="#netCDF4.Dataset.set_auto_mask">set_auto_mask</a></code></li>
3262 <li><code><a title="netCDF4.Dataset.set_auto_maskandscale" href="#netCDF4.Dataset.set_auto_maskandscale">set_auto_maskandscale</a></code></li>
3263 <li><code><a title="netCDF4.Dataset.set_auto_scale" href="#netCDF4.Dataset.set_auto_scale">set_auto_scale</a></code></li>
3264 <li><code><a title="netCDF4.Dataset.set_fill_off" href="#netCDF4.Dataset.set_fill_off">set_fill_off</a></code></li>
3265 <li><code><a title="netCDF4.Dataset.set_fill_on" href="#netCDF4.Dataset.set_fill_on">set_fill_on</a></code></li>
3266 <li><code><a title="netCDF4.Dataset.set_ncstring_attrs" href="#netCDF4.Dataset.set_ncstring_attrs">set_ncstring_attrs</a></code></li>
3267 <li><code><a title="netCDF4.Dataset.setncattr" href="#netCDF4.Dataset.setncattr">setncattr</a></code></li>
3268 <li><code><a title="netCDF4.Dataset.setncattr_string" href="#netCDF4.Dataset.setncattr_string">setncattr_string</a></code></li>
3269 <li><code><a title="netCDF4.Dataset.setncatts" href="#netCDF4.Dataset.setncatts">setncatts</a></code></li>
3270 <li><code><a title="netCDF4.Dataset.sync" href="#netCDF4.Dataset.sync">sync</a></code></li>
3271 <li><code><a title="netCDF4.Dataset.tocdl" href="#netCDF4.Dataset.tocdl">tocdl</a></code></li>
3272 <li><code><a title="netCDF4.Dataset.variables" href="#netCDF4.Dataset.variables">variables</a></code></li>
3273 <li><code><a title="netCDF4.Dataset.vltypes" href="#netCDF4.Dataset.vltypes">vltypes</a></code></li>
3274 </ul>
3275 </li>
3276 <li>
3277 <h4><code><a title="netCDF4.Dimension" href="#netCDF4.Dimension">Dimension</a></code></h4>
3278 <ul class="">
3279 <li><code><a title="netCDF4.Dimension.group" href="#netCDF4.Dimension.group">group</a></code></li>
3280 <li><code><a title="netCDF4.Dimension.isunlimited" href="#netCDF4.Dimension.isunlimited">isunlimited</a></code></li>
3281 <li><code><a title="netCDF4.Dimension.name" href="#netCDF4.Dimension.name">name</a></code></li>
3282 <li><code><a title="netCDF4.Dimension.size" href="#netCDF4.Dimension.size">size</a></code></li>
3283 </ul>
3284 </li>
3285 <li>
3286 <h4><code><a title="netCDF4.EnumType" href="#netCDF4.EnumType">EnumType</a></code></h4>
3287 <ul class="">
3288 <li><code><a title="netCDF4.EnumType.dtype" href="#netCDF4.EnumType.dtype">dtype</a></code></li>
3289 <li><code><a title="netCDF4.EnumType.enum_dict" href="#netCDF4.EnumType.enum_dict">enum_dict</a></code></li>
3290 <li><code><a title="netCDF4.EnumType.name" href="#netCDF4.EnumType.name">name</a></code></li>
3291 </ul>
3292 </li>
3293 <li>
3294 <h4><code><a title="netCDF4.Group" href="#netCDF4.Group">Group</a></code></h4>
3295 <ul class="">
3296 <li><code><a title="netCDF4.Group.close" href="#netCDF4.Group.close">close</a></code></li>
3297 </ul>
3298 </li>
3299 <li>
3300 <h4><code><a title="netCDF4.MFDataset" href="#netCDF4.MFDataset">MFDataset</a></code></h4>
3301 <ul class="">
3302 <li><code><a title="netCDF4.MFDataset.close" href="#netCDF4.MFDataset.close">close</a></code></li>
3303 <li><code><a title="netCDF4.MFDataset.isopen" href="#netCDF4.MFDataset.isopen">isopen</a></code></li>
3304 <li><code><a title="netCDF4.MFDataset.ncattrs" href="#netCDF4.MFDataset.ncattrs">ncattrs</a></code></li>
3305 </ul>
3306 </li>
3307 <li>
3308 <h4><code><a title="netCDF4.MFTime" href="#netCDF4.MFTime">MFTime</a></code></h4>
3309 </li>
3310 <li>
3311 <h4><code><a title="netCDF4.VLType" href="#netCDF4.VLType">VLType</a></code></h4>
3312 <ul class="">
3313 <li><code><a title="netCDF4.VLType.dtype" href="#netCDF4.VLType.dtype">dtype</a></code></li>
3314 <li><code><a title="netCDF4.VLType.name" href="#netCDF4.VLType.name">name</a></code></li>
3315 </ul>
3316 </li>
3317 <li>
3318 <h4><code><a title="netCDF4.Variable" href="#netCDF4.Variable">Variable</a></code></h4>
3319 <ul class="">
3320 <li><code><a title="netCDF4.Variable.always_mask" href="#netCDF4.Variable.always_mask">always_mask</a></code></li>
3321 <li><code><a title="netCDF4.Variable.assignValue" href="#netCDF4.Variable.assignValue">assignValue</a></code></li>
3322 <li><code><a title="netCDF4.Variable.auto_complex" href="#netCDF4.Variable.auto_complex">auto_complex</a></code></li>
3323 <li><code><a title="netCDF4.Variable.chartostring" href="#netCDF4.Variable.chartostring">chartostring</a></code></li>
3324 <li><code><a title="netCDF4.Variable.chunking" href="#netCDF4.Variable.chunking">chunking</a></code></li>
3325 <li><code><a title="netCDF4.Variable.datatype" href="#netCDF4.Variable.datatype">datatype</a></code></li>
3326 <li><code><a title="netCDF4.Variable.delncattr" href="#netCDF4.Variable.delncattr">delncattr</a></code></li>
3327 <li><code><a title="netCDF4.Variable.dimensions" href="#netCDF4.Variable.dimensions">dimensions</a></code></li>
3328 <li><code><a title="netCDF4.Variable.dtype" href="#netCDF4.Variable.dtype">dtype</a></code></li>
3329 <li><code><a title="netCDF4.Variable.endian" href="#netCDF4.Variable.endian">endian</a></code></li>
3330 <li><code><a title="netCDF4.Variable.filters" href="#netCDF4.Variable.filters">filters</a></code></li>
3331 <li><code><a title="netCDF4.Variable.getValue" href="#netCDF4.Variable.getValue">getValue</a></code></li>
3332 <li><code><a title="netCDF4.Variable.get_dims" href="#netCDF4.Variable.get_dims">get_dims</a></code></li>
3333 <li><code><a title="netCDF4.Variable.get_fill_value" href="#netCDF4.Variable.get_fill_value">get_fill_value</a></code></li>
3334 <li><code><a title="netCDF4.Variable.get_var_chunk_cache" href="#netCDF4.Variable.get_var_chunk_cache">get_var_chunk_cache</a></code></li>
3335 <li><code><a title="netCDF4.Variable.getncattr" href="#netCDF4.Variable.getncattr">getncattr</a></code></li>
3336 <li><code><a title="netCDF4.Variable.group" href="#netCDF4.Variable.group">group</a></code></li>
3337 <li><code><a title="netCDF4.Variable.mask" href="#netCDF4.Variable.mask">mask</a></code></li>
3338 <li><code><a title="netCDF4.Variable.name" href="#netCDF4.Variable.name">name</a></code></li>
3339 <li><code><a title="netCDF4.Variable.ncattrs" href="#netCDF4.Variable.ncattrs">ncattrs</a></code></li>
3340 <li><code><a title="netCDF4.Variable.ndim" href="#netCDF4.Variable.ndim">ndim</a></code></li>
3341 <li><code><a title="netCDF4.Variable.quantization" href="#netCDF4.Variable.quantization">quantization</a></code></li>
3342 <li><code><a title="netCDF4.Variable.renameAttribute" href="#netCDF4.Variable.renameAttribute">renameAttribute</a></code></li>
3343 <li><code><a title="netCDF4.Variable.scale" href="#netCDF4.Variable.scale">scale</a></code></li>
3344 <li><code><a title="netCDF4.Variable.set_always_mask" href="#netCDF4.Variable.set_always_mask">set_always_mask</a></code></li>
3345 <li><code><a title="netCDF4.Variable.set_auto_chartostring" href="#netCDF4.Variable.set_auto_chartostring">set_auto_chartostring</a></code></li>
3346 <li><code><a title="netCDF4.Variable.set_auto_mask" href="#netCDF4.Variable.set_auto_mask">set_auto_mask</a></code></li>
3347 <li><code><a title="netCDF4.Variable.set_auto_maskandscale" href="#netCDF4.Variable.set_auto_maskandscale">set_auto_maskandscale</a></code></li>
3348 <li><code><a title="netCDF4.Variable.set_auto_scale" href="#netCDF4.Variable.set_auto_scale">set_auto_scale</a></code></li>
3349 <li><code><a title="netCDF4.Variable.set_collective" href="#netCDF4.Variable.set_collective">set_collective</a></code></li>
3350 <li><code><a title="netCDF4.Variable.set_ncstring_attrs" href="#netCDF4.Variable.set_ncstring_attrs">set_ncstring_attrs</a></code></li>
3351 <li><code><a title="netCDF4.Variable.set_var_chunk_cache" href="#netCDF4.Variable.set_var_chunk_cache">set_var_chunk_cache</a></code></li>
3352 <li><code><a title="netCDF4.Variable.setncattr" href="#netCDF4.Variable.setncattr">setncattr</a></code></li>
3353 <li><code><a title="netCDF4.Variable.setncattr_string" href="#netCDF4.Variable.setncattr_string">setncattr_string</a></code></li>
3354 <li><code><a title="netCDF4.Variable.setncatts" href="#netCDF4.Variable.setncatts">setncatts</a></code></li>
3355 <li><code><a title="netCDF4.Variable.shape" href="#netCDF4.Variable.shape">shape</a></code></li>
3356 <li><code><a title="netCDF4.Variable.size" href="#netCDF4.Variable.size">size</a></code></li>
3357 <li><code><a title="netCDF4.Variable.use_nc_get_vars" href="#netCDF4.Variable.use_nc_get_vars">use_nc_get_vars</a></code></li>
3358 </ul>
3359 </li>
3360 </ul>
3361 </li>
3362 </ul>
3363 </nav>
3364 </main>
3365 <footer id="footer">
3366 <p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.6</a>.</p>
3367 </footer>
3368 </body>
3369 </html>