Codebase list netcdf4-python / e5f84b5
New upstream version 1.5.7 Bas Couwenberg 2 years ago
32 changed file(s) with 2502 addition(s) and 2346 deletion(s). Raw diff Collapse all Expand all
55 runs-on: ubuntu-latest
66 env:
77 PNETCDF_VERSION: 1.12.1
8 NETCDF_VERSION: 4.7.4
8 NETCDF_VERSION: 4.8.0
99 NETCDF_DIR: ${{ github.workspace }}/..
1010 NETCDF_EXTRA_CONFIG: --enable-pnetcdf
1111 CC: mpicc.mpich
7777 else
7878 echo "hdf5 mpi test passed!"
7979 fi
80 mpirun.mpich -np 4 python mpi_example_compressed.py
81 if [ $? -ne 0 ] ; then
82 echo "hdf5 compressed mpi test failed!"
83 exit 1
84 else
85 echo "hdf5 compressed mpi test passed!"
86 fi
8087 mpirun.mpich -np 4 python mpi_example.py NETCDF3_64BIT_DATA
8188 if [ $? -ne 0 ] ; then
8289 echo "pnetcdf mpi test failed!"
7575 export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH"
7676 which mpirun
7777 mpirun --version
78 mpirun -np 4 python mpi_example.py
78 mpirun --oversubscribe -np 4 python mpi_example.py
7979 if [ $? -ne 0 ] ; then
8080 echo "hdf5 mpi test failed!"
8181 exit 1
0 version 1.5.7 (tag v1.5.7rel)
1 ==============================
2 * don't try to mask vlens with default _FillValue, since vlens don't have a default _FillValue.
3 This gets rid of numpy DeprecationWarning (issue #1099).
4 * update docs to reflect the fact that a variable must be in collective mode before writing
5 compressed data to it in parallel. Added a test for this (examples/mpi_example_compressed.py).
6 Issue #1108.
7 * Fix OverflowError when dimension sizes become greater than 2**32-1 elements on Windows (Issue #1112).
8 * Don't return masked arrays for vlens (only for primitive and enum types - issue #1115).
9
010 version 1.5.6 (tag v1.5.6rel)
111 ==============================
212 * move CI/CD tests from travis/appveyor to Github Actions (PR #1061).
55 [![Anaconda-Server Badge](https://anaconda.org/conda-forge/netCDF4/badges/version.svg)](https://anaconda.org/conda-forge/netCDF4)
66 [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.2592291.svg)](https://doi.org/10.5281/zenodo.2592290)
77
8
89 ## News
910 For details on the latest updates, see the [Changelog](https://github.com/Unidata/netcdf4-python/blob/master/Changelog).
1011
11 2/15/2020: Version [1.5.6](https://pypi.python.org/pypi/netCDF4/1.5.6) released. Added `Dataset.fromcdl` and `Dataset.tocdl`, which require `ncdump` and `ncgen` utilities to be in `$PATH`. Removed python 2.7 support.
12 6/22/2021: Version [1.5.7](https://pypi.python.org/pypi/netCDF4/1.5.7) released.
13 Fixed OverflowError on Windows when reading data with dimension sizes greater than 2**32-1.
14 Masked arrays no longer returned for vlens.
15
16 2/15/2021: Version [1.5.6](https://pypi.python.org/pypi/netCDF4/1.5.6) released. Added `Dataset.fromcdl` and `Dataset.tocdl`, which require `ncdump` and `ncgen` utilities to be in `$PATH`. Removed python 2.7 support.
1217
1318 12/20/2020: Version [1.5.5.1](https://pypi.python.org/pypi/netCDF4/1.5.5.1) released.
1419 Updated binary wheels for OSX and linux that link latest netcdf-c and hdf5 libs.
205210 with `export USE_NCCONFIG=0` will use environment variables to find paths to libraries and include files,
206211 instead of relying exclusively on the nc-config utility.
207212
208 ## Quick Start
209 * Clone GitHub repository (`git clone https://github.com/Unidata/netcdf4-python.git`), or get source tarball from [PyPI](https://pypi.python.org/pypi/netCDF4). Links to Windows and OS X precompiled binary packages are also available on [PyPI](https://pypi.python.org/pypi/netCDF4).
213 ## Installation
214 The easiest way to install is through pip:
215
216 ```shell
217 pip install netCDF4
218 ```
219
220 or, if you are a user of the Conda package manager,
221
222 ```shell
223 conda install -c conda-forge netCDF4
224 ```
225
226 ## Development installation
227 * Clone GitHub repository (`git clone https://github.com/Unidata/netcdf4-python.git`)
210228
211229 * Make sure [numpy](http://www.numpy.org/) and [Cython](http://cython.org/) are
212 installed and you have [Python](https://www.python.org) 2.7 or newer.
213
214 * Make sure [HDF5](http://www.h5py.org/) and netcdf-4 are installed, and the `nc-config` utility
215 is in your Unix PATH.
216
217 * Run `python setup.py build`, then `python setup.py install` (with `sudo` if necessary).
230 installed and you have [Python](https://www.python.org) 3.6 or newer.
231
232 * Make sure [HDF5](http://www.h5py.org/) and netcdf-4 are installed,
233 and the `nc-config` utility is in your Unix PATH.
234
235 * Run `python setup.py build`, then `pip install -e .`.
218236
219237 * To run all the tests, execute `cd test && python run_all.py`.
220238
00 # Uses pdoc (https://github.com/mitmproxy/pdoc)
11 # to create html docs from docstrings in Cython source.
2 /Users/jwhitaker/.local/bin/pdoc -o 'docs' netCDF4
2 pdoc -o 'docs' netCDF4
33 # use resulting docs/netCDF4/_netCDF4.html
4 cp docs/netCDF4/_netCDF4.html docs/index.html
4 cp docs/netCDF4.html docs/index.html
55 sed -i -e 's!href="../netCDF4.html!href="./index.html!g' docs/index.html
66 sed -i -e 's!/../netCDF4.html!/index.html!g' docs/index.html
77 sed -i -e 's!._netCDF4 API! API!g' docs/index.html
22 <head>
33 <meta charset="utf-8">
44 <meta name="viewport" content="width=device-width, initial-scale=1">
5 <meta name="generator" content="pdoc" />
5 <meta name="generator" content="pdoc 7.1.0" />
66 <title>netCDF4 API documentation</title>
77 <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2264%22%20height%3D%2264%22%20viewBox%3D%2244.5%202.5%2015%2015%22%3E%3Cpath%20d%3D%22M49.351%2021.041c-.233-.721-.546-2.408-.772-4.076-.042-.09-.067-.187-.046-.288-.166-1.347-.277-2.625-.241-3.351-1.378-1.008-2.271-2.586-2.271-4.362%200-.976.272-1.935.788-2.774.057-.094.122-.18.184-.268-.033-.167-.052-.339-.052-.516%200-1.477%201.202-2.679%202.679-2.679.791%200%201.496.352%201.987.9a6.3%206.3%200%200%201%201.001.029c.492-.564%201.207-.929%202.012-.929%201.477%200%202.679%201.202%202.679%202.679a2.65%202.65%200%200%201-.269%201.148c.383.747.595%201.572.595%202.41%200%202.311-1.507%204.29-3.635%205.107.037.699.147%202.27.423%203.294l.137.461c.156%202.136-4.612%205.166-5.199%203.215zm.127-4.919a4.78%204.78%200%200%200%20.775-.584c-.172-.115-.505-.254-.88-.378zm.331%202.302l.828-.502c-.202-.143-.576-.328-.984-.49zm.45%202.157l.701-.403c-.214-.115-.536-.249-.891-.376l.19.779zM49.13%204.141c0%20.152.123.276.276.276s.275-.124.275-.276-.123-.276-.276-.276-.275.124-.275.276zm.735-.389a1.15%201.15%200%200%201%20.314.783%201.16%201.16%200%200%201-1.162%201.162c-.457%200-.842-.27-1.032-.653-.026.117-.042.238-.042.362a1.68%201.68%200%200%200%201.679%201.679%201.68%201.68%200%200%200%201.679-1.679c0-.843-.626-1.535-1.436-1.654zm3.076%201.654a1.68%201.68%200%200%200%201.679%201.679%201.68%201.68%200%200%200%201.679-1.679c0-.037-.009-.072-.011-.109-.21.3-.541.508-.935.508a1.16%201.16%200%200%201-1.162-1.162%201.14%201.14%200%200%201%20.474-.912c-.015%200-.03-.005-.045-.005-.926.001-1.679.754-1.679%201.68zm1.861-1.265c0%20.152.123.276.276.276s.275-.124.275-.276-.123-.276-.276-.276-.275.124-.275.276zm1.823%204.823c0-.52-.103-1.035-.288-1.52-.466.394-1.06.64-1.717.64-1.144%200-2.116-.725-2.499-1.738-.383%201.012-1.355%201.738-2.499%201.738-.867%200-1.631-.421-2.121-1.062-.307.605-.478%201.267-.478%201.942%200%202.486%202.153%204.51%204.801%204.51s4.801-2.023%204.801-4.51zm-3.032%209.156l-.146-.492c-.276-1.02-.395-2.457-.444-3.268a6.11%206.11%200%200%201-1.18.115%206.01%206.01%200%200%201-2.536-.562l.006.175c.802.215%201.848.612%202.021%201.25.079.295-.021.601-.274.837l-.598.501c.667.304%201.243.698%201.311%201.179.02.144.022.507-.393.787l-.564.365c1.285.521%201.361.96%201.381%201.126.018.142.011.496-.427.746l-.854.489c.064-1.19%201.985-2.585%202.697-3.248zM49.34%209.925c0-.667%201-.667%201%200%200%20.653.818%201.205%201.787%201.205s1.787-.552%201.787-1.205c0-.667%201-.667%201%200%200%201.216-1.25%202.205-2.787%202.205s-2.787-.989-2.787-2.205zm-.887-7.633c-.093.077-.205.114-.317.114a.5.5%200%200%201-.318-.886L49.183.397a.5.5%200%200%201%20.703.068.5.5%200%200%201-.069.703zm7.661-.065c-.086%200-.173-.022-.253-.068l-1.523-.893c-.575-.337-.069-1.2.506-.863l1.523.892a.5.5%200%200%201%20.179.685c-.094.158-.261.247-.432.247z%22%20fill%3D%22%233bb300%22/%3E%3C/svg%3E"/>
88
99
10 <style type="text/css">/*! * Bootstrap Reboot v5.0.0-beta1 (https://getbootstrap.com/) * Copyright 2011-2020 The Bootstrap Authors * Copyright 2011-2020 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;background-color:#fff;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}[tabindex="-1"]:focus:not(:focus-visible){outline:0!important}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{text-decoration:underline;-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus{outline:dotted 1px;outline:-webkit-focus-ring-color auto 5px}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important}</style>
11 <style type="text/css">/*! pygments syntax highlighting */pre{line-height:125%;}td.linenos pre{color:#000000; background-color:#f0f0f0; padding-left:5px; padding-right:5px;}span.linenos{color:#000000; background-color:#f0f0f0; padding-left:5px; padding-right:5px;}td.linenos pre.special{color:#000000; background-color:#ffffc0; padding-left:5px; padding-right:5px;}span.linenos.special{color:#000000; background-color:#ffffc0; padding-left:5px; padding-right:5px;}.pdoc .hll{background-color:#ffffcc}.pdoc{background:#f8f8f8;}.pdoc .c{color:#408080; font-style:italic}.pdoc .err{border:1px solid #FF0000}.pdoc .k{color:#008000; font-weight:bold}.pdoc .o{color:#666666}.pdoc .ch{color:#408080; font-style:italic}.pdoc .cm{color:#408080; font-style:italic}.pdoc .cp{color:#BC7A00}.pdoc .cpf{color:#408080; font-style:italic}.pdoc .c1{color:#408080; font-style:italic}.pdoc .cs{color:#408080; font-style:italic}.pdoc .gd{color:#A00000}.pdoc .ge{font-style:italic}.pdoc .gr{color:#FF0000}.pdoc .gh{color:#000080; font-weight:bold}.pdoc .gi{color:#00A000}.pdoc .go{color:#888888}.pdoc .gp{color:#000080; font-weight:bold}.pdoc .gs{font-weight:bold}.pdoc .gu{color:#800080; font-weight:bold}.pdoc .gt{color:#0044DD}.pdoc .kc{color:#008000; font-weight:bold}.pdoc .kd{color:#008000; font-weight:bold}.pdoc .kn{color:#008000; font-weight:bold}.pdoc .kp{color:#008000}.pdoc .kr{color:#008000; font-weight:bold}.pdoc .kt{color:#B00040}.pdoc .m{color:#666666}.pdoc .s{color:#BA2121}.pdoc .na{color:#7D9029}.pdoc .nb{color:#008000}.pdoc .nc{color:#0000FF; font-weight:bold}.pdoc .no{color:#880000}.pdoc .nd{color:#AA22FF}.pdoc .ni{color:#999999; font-weight:bold}.pdoc .ne{color:#D2413A; font-weight:bold}.pdoc .nf{color:#0000FF}.pdoc .nl{color:#A0A000}.pdoc .nn{color:#0000FF; font-weight:bold}.pdoc .nt{color:#008000; font-weight:bold}.pdoc .nv{color:#19177C}.pdoc .ow{color:#AA22FF; font-weight:bold}.pdoc .w{color:#bbbbbb}.pdoc .mb{color:#666666}.pdoc .mf{color:#666666}.pdoc .mh{color:#666666}.pdoc .mi{color:#666666}.pdoc .mo{color:#666666}.pdoc .sa{color:#BA2121}.pdoc .sb{color:#BA2121}.pdoc .sc{color:#BA2121}.pdoc .dl{color:#BA2121}.pdoc .sd{color:#BA2121; font-style:italic}.pdoc .s2{color:#BA2121}.pdoc .se{color:#BB6622; font-weight:bold}.pdoc .sh{color:#BA2121}.pdoc .si{color:#BB6688; font-weight:bold}.pdoc .sx{color:#008000}.pdoc .sr{color:#BB6688}.pdoc .s1{color:#BA2121}.pdoc .ss{color:#19177C}.pdoc .bp{color:#008000}.pdoc .fm{color:#0000FF}.pdoc .vc{color:#19177C}.pdoc .vg{color:#19177C}.pdoc .vi{color:#19177C}.pdoc .vm{color:#19177C}.pdoc .il{color:#666666}</style>
12 <style type="text/css">/*! pdoc */:root{--pdoc-background:#fff;}.pdoc{--text:#212529;--muted:#6c757d;--link:#3660a5;--link-hover:#1659c5;--code:#f7f7f7;--active:#fff598;--accent:#eee;--accent2:#c1c1c1;--nav-hover:rgba(255, 255, 255, 0.5);--name:#0066BB;--def:#008800;--annotation:#007020;}body{background-color:var(--pdoc-background);}html, body{width:100%;height:100%;}@media (max-width:769px){#navtoggle{cursor:pointer;position:absolute;width:50px;height:40px;top:1rem;right:1rem;border-color:var(--text);color:var(--text);display:flex;opacity:0.8;}#navtoggle:hover{opacity:1;}#togglestate + div{display:none;}#togglestate:checked + div{display:inherit;}main{padding:2rem 3vw;}.git-button{display:none !important;}}@media (min-width:770px){:root{--sidebar-width:clamp(12.5rem, 28vw, 22rem);}nav{position:fixed;overflow:auto;height:100vh;width:var(--sidebar-width);}main{padding:3rem 2rem 3rem calc(var(--sidebar-width) + 3rem);width:calc(54rem + var(--sidebar-width));max-width:100%;}#navtoggle{display:none;}}#togglestate{display:none;}nav.pdoc{--pad:1.75rem;--indent:1.5rem;background-color:var(--accent);border-right:1px solid var(--accent2);box-shadow:0 0 20px rgba(50, 50, 50, .2) inset;padding:0 0 0 var(--pad);overflow-wrap:anywhere;scrollbar-width:thin; scrollbar-color:var(--accent2) transparent }nav.pdoc::-webkit-scrollbar{width:.4rem; }nav.pdoc::-webkit-scrollbar-thumb{background-color:var(--accent2); }nav.pdoc > div{padding:var(--pad) 0;}nav.pdoc .module-list-button{display:inline-flex;align-items:center;color:var(--text);border-color:var(--muted);margin-bottom:1rem;}nav.pdoc .module-list-button:hover{border-color:var(--text);}nav.pdoc ul{list-style:none;padding-left:0;}nav.pdoc li{display:block;margin:0;padding:.2rem 0 .2rem var(--indent);transition:all 100ms;}nav.pdoc > div > ul > li{padding-left:0;}nav.pdoc li:hover{background-color:var(--nav-hover);}nav.pdoc a, nav.pdoc a:hover{color:var(--text);}nav.pdoc a{display:block;}nav.pdoc > h2:first-of-type{margin-top:1.5rem;}nav.pdoc .class:before{content:"class ";color:var(--muted);}nav.pdoc .function:after{content:"()";color:var(--muted);}html, main{scroll-behavior:smooth;}.pdoc{color:var(--text);box-sizing:border-box;line-height:1.5;background:none;}.pdoc .pdoc-button{display:inline-block;border:solid black 1px;border-radius:2px;font-size:.75rem;padding:calc(0.5em - 1px) 1em;transition:100ms all;}.pdoc h1, .pdoc h2, .pdoc h3, .pdoc h4{font-weight:300;margin:.3em 0;padding:.2em 0;}.pdoc a{text-decoration:none;color:var(--link);}.pdoc a:hover{color:var(--link-hover);}.pdoc blockquote{margin-left:2rem;}.pdoc pre{background-color:var(--code);border-top:1px solid var(--accent2);border-bottom:1px solid var(--accent2);margin-bottom:1em;padding:.5rem 0 .5rem .5rem;overflow-x:auto;}.pdoc code{color:var(--text);padding:.2em .4em;margin:0;font-size:85%;background-color:var(--code);border-radius:6px;}.pdoc a > code{color:inherit;}.pdoc pre > code{display:inline-block;font-size:inherit;background:none;border:none;padding:0;}.pdoc .modulename{margin-top:0;font-weight:bold;}.pdoc .modulename a{color:var(--link);transition:100ms all;}.pdoc .git-button{float:right;border:solid var(--link) 1px;}.pdoc .git-button:hover{background-color:var(--link);color:var(--pdoc-background);}.pdoc details{--shift:-40px;text-align:right;margin-top:var(--shift);margin-bottom:calc(0px - var(--shift));clear:both;filter:opacity(1);}.pdoc details:not([open]){height:0;overflow:visible;}.pdoc details > summary{font-size:.75rem;cursor:pointer;color:var(--muted);border-width:0;padding:0 .7em;display:inline-block;display:inline list-item;user-select:none;}.pdoc details > summary:focus{outline:0;}.pdoc details > div{margin-top:calc(0px - var(--shift) / 2);text-align:left;}.pdoc .docstring{margin-bottom:1.5rem;}.pdoc > section:first-of-type > .docstring{margin-bottom:3rem;}.pdoc .docstring pre{margin-left:1em;margin-right:1em;}.pdoc h1:target,.pdoc h2:target,.pdoc h3:target,.pdoc h4:target,.pdoc h5:target,.pdoc h6:target{background-color:var(--active);box-shadow:-1rem 0 0 0 var(--active);}.pdoc div:target > .attr,.pdoc section:target > .attr,.pdoc dd:target > a{background-color:var(--active);}.pdoc .attr:hover{filter:contrast(0.95);}.pdoc .headerlink{position:absolute;width:0;margin-left:-1.5rem;line-height:1.4rem;font-size:1.5rem;font-weight:normal;transition:all 100ms ease-in-out;opacity:0;}.pdoc .attr > .headerlink{margin-left:-2.5rem;}.pdoc *:hover > .headerlink,.pdoc *:target > .attr > .headerlink{opacity:1;}.pdoc .attr{color:var(--text);margin:1rem 0 .5rem;padding:.4rem 5rem .4rem 1rem;background-color:var(--accent);}.pdoc .classattr{margin-left:2rem;}.pdoc .name{color:var(--name);font-weight:bold;}.pdoc .def{color:var(--def);font-weight:bold;}.pdoc .signature{white-space:pre-wrap;}.pdoc .annotation{color:var(--annotation);}.pdoc .inherited{margin-left:2rem;}.pdoc .inherited dt{font-weight:700;}.pdoc .inherited dt, .pdoc .inherited dd{display:inline;margin-left:0;margin-bottom:.5rem;}.pdoc .inherited dd:not(:last-child):after{content:", ";}.pdoc .inherited .class:before{content:"class ";}.pdoc .inherited .function a:after{content:"()";}.pdoc .attribution{margin-top:2rem;display:block;opacity:0.5;transition:all 200ms;filter:grayscale(100%);}.pdoc .attribution:hover{opacity:1;filter:grayscale(0%);}.pdoc .attribution img{margin-left:5px;height:35px;vertical-align:middle;width:70px;transition:all 200ms;}</style>
10 <style type="text/css">/*! * Bootstrap Reboot v5.0.0 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors * Copyright 2011-2021 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;background-color:#fff;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important}</style>
11 <style>/*! pygments syntax highlighting */pre{line-height:125%;}td.linenos pre{color:#000000; background-color:#f0f0f0; padding-left:5px; padding-right:5px;}span.linenos{color:#000000; background-color:#f0f0f0; padding-left:5px; padding-right:5px;}td.linenos pre.special{color:#000000; background-color:#ffffc0; padding-left:5px; padding-right:5px;}span.linenos.special{color:#000000; background-color:#ffffc0; padding-left:5px; padding-right:5px;}.pdoc .hll{background-color:#ffffcc}.pdoc{background:#f8f8f8;}.pdoc .c{color:#408080; font-style:italic}.pdoc .err{border:1px solid #FF0000}.pdoc .k{color:#008000; font-weight:bold}.pdoc .o{color:#666666}.pdoc .ch{color:#408080; font-style:italic}.pdoc .cm{color:#408080; font-style:italic}.pdoc .cp{color:#BC7A00}.pdoc .cpf{color:#408080; font-style:italic}.pdoc .c1{color:#408080; font-style:italic}.pdoc .cs{color:#408080; font-style:italic}.pdoc .gd{color:#A00000}.pdoc .ge{font-style:italic}.pdoc .gr{color:#FF0000}.pdoc .gh{color:#000080; font-weight:bold}.pdoc .gi{color:#00A000}.pdoc .go{color:#888888}.pdoc .gp{color:#000080; font-weight:bold}.pdoc .gs{font-weight:bold}.pdoc .gu{color:#800080; font-weight:bold}.pdoc .gt{color:#0044DD}.pdoc .kc{color:#008000; font-weight:bold}.pdoc .kd{color:#008000; font-weight:bold}.pdoc .kn{color:#008000; font-weight:bold}.pdoc .kp{color:#008000}.pdoc .kr{color:#008000; font-weight:bold}.pdoc .kt{color:#B00040}.pdoc .m{color:#666666}.pdoc .s{color:#BA2121}.pdoc .na{color:#7D9029}.pdoc .nb{color:#008000}.pdoc .nc{color:#0000FF; font-weight:bold}.pdoc .no{color:#880000}.pdoc .nd{color:#AA22FF}.pdoc .ni{color:#999999; font-weight:bold}.pdoc .ne{color:#D2413A; font-weight:bold}.pdoc .nf{color:#0000FF}.pdoc .nl{color:#A0A000}.pdoc .nn{color:#0000FF; font-weight:bold}.pdoc .nt{color:#008000; font-weight:bold}.pdoc .nv{color:#19177C}.pdoc .ow{color:#AA22FF; font-weight:bold}.pdoc .w{color:#bbbbbb}.pdoc .mb{color:#666666}.pdoc .mf{color:#666666}.pdoc .mh{color:#666666}.pdoc .mi{color:#666666}.pdoc .mo{color:#666666}.pdoc .sa{color:#BA2121}.pdoc .sb{color:#BA2121}.pdoc .sc{color:#BA2121}.pdoc .dl{color:#BA2121}.pdoc .sd{color:#BA2121; font-style:italic}.pdoc .s2{color:#BA2121}.pdoc .se{color:#BB6622; font-weight:bold}.pdoc .sh{color:#BA2121}.pdoc .si{color:#BB6688; font-weight:bold}.pdoc .sx{color:#008000}.pdoc .sr{color:#BB6688}.pdoc .s1{color:#BA2121}.pdoc .ss{color:#19177C}.pdoc .bp{color:#008000}.pdoc .fm{color:#0000FF}.pdoc .vc{color:#19177C}.pdoc .vg{color:#19177C}.pdoc .vi{color:#19177C}.pdoc .vm{color:#19177C}.pdoc .il{color:#666666}</style>
12 <style>/*! pdoc */:root{--pdoc-background:#fff;}.pdoc{--text:#212529;--muted:#6c757d;--link:#3660a5;--link-hover:#1659c5;--code:#f7f7f7;--active:#fff598;--accent:#eee;--accent2:#c1c1c1;--nav-hover:rgba(255, 255, 255, 0.5);--name:#0066BB;--def:#008800;--annotation:#007020;}body{background-color:var(--pdoc-background);}html, body{width:100%;height:100%;}@media (max-width:769px){#navtoggle{cursor:pointer;position:absolute;width:50px;height:40px;top:1rem;right:1rem;border-color:var(--text);color:var(--text);display:flex;opacity:0.8;}#navtoggle:hover{opacity:1;}#togglestate + div{display:none;}#togglestate:checked + div{display:inherit;}main, header{padding:2rem 3vw;}.git-button{display:none !important;}nav input[type="search"]:valid ~ *{display:none !important;}}@media (min-width:770px){:root{--sidebar-width:clamp(12.5rem, 28vw, 22rem);}nav{position:fixed;overflow:auto;height:100vh;width:var(--sidebar-width);}main, header{padding:3rem 2rem 3rem calc(var(--sidebar-width) + 3rem);width:calc(54rem + var(--sidebar-width));max-width:100%;}#navtoggle{display:none;}}#togglestate{display:none;}nav.pdoc{--pad:1.75rem;--indent:1.5rem;background-color:var(--accent);border-right:1px solid var(--accent2);box-shadow:0 0 20px rgba(50, 50, 50, .2) inset;padding:0 0 0 var(--pad);overflow-wrap:anywhere;scrollbar-width:thin; scrollbar-color:var(--accent2) transparent }nav.pdoc::-webkit-scrollbar{width:.4rem; }nav.pdoc::-webkit-scrollbar-thumb{background-color:var(--accent2); }nav.pdoc > div{padding:var(--pad) 0;}nav.pdoc .module-list-button{display:inline-flex;align-items:center;color:var(--text);border-color:var(--muted);margin-bottom:1rem;}nav.pdoc .module-list-button:hover{border-color:var(--text);}nav.pdoc input[type=search]{display:block;outline-offset:0;width:calc(100% - var(--pad));}nav.pdoc ul{list-style:none;padding-left:0;}nav.pdoc li{display:block;margin:0;padding:.2rem 0 .2rem var(--indent);transition:all 100ms;}nav.pdoc > div > ul > li{padding-left:0;}nav.pdoc li:hover{background-color:var(--nav-hover);}nav.pdoc a, nav.pdoc a:hover{color:var(--text);}nav.pdoc a{display:block;}nav.pdoc > h2:first-of-type{margin-top:1.5rem;}nav.pdoc .class:before{content:"class ";color:var(--muted);}nav.pdoc .function:after{content:"()";color:var(--muted);}html, main{scroll-behavior:smooth;}.pdoc{color:var(--text);box-sizing:border-box;line-height:1.5;background:none;}.pdoc .pdoc-button{display:inline-block;border:solid black 1px;border-radius:2px;font-size:.75rem;padding:calc(0.5em - 1px) 1em;transition:100ms all;}.pdoc .visually-hidden{position:absolute !important;width:1px !important;height:1px !important;padding:0 !important;margin:-1px !important;overflow:hidden !important;clip:rect(0, 0, 0, 0) !important;white-space:nowrap !important;border:0 !important;}.pdoc h1, .pdoc h2, .pdoc h3{font-weight:300;margin:.3em 0;padding:.2em 0;}.pdoc a{text-decoration:none;color:var(--link);}.pdoc a:hover{color:var(--link-hover);}.pdoc blockquote{margin-left:2rem;}.pdoc pre{background-color:var(--code);border-top:1px solid var(--accent2);border-bottom:1px solid var(--accent2);margin-bottom:1em;padding:.5rem 0 .5rem .5rem;overflow-x:auto;}.pdoc code{color:var(--text);padding:.2em .4em;margin:0;font-size:85%;background-color:var(--code);border-radius:6px;}.pdoc a > code{color:inherit;}.pdoc pre > code{display:inline-block;font-size:inherit;background:none;border:none;padding:0;}.pdoc .modulename{margin-top:0;font-weight:bold;}.pdoc .modulename a{color:var(--link);transition:100ms all;}.pdoc .git-button{float:right;border:solid var(--link) 1px;}.pdoc .git-button:hover{background-color:var(--link);color:var(--pdoc-background);}.pdoc details{--shift:-40px;text-align:right;margin-top:var(--shift);margin-bottom:calc(0px - var(--shift));clear:both;filter:opacity(1);}.pdoc details:not([open]){height:0;overflow:visible;}.pdoc details > summary{font-size:.75rem;cursor:pointer;color:var(--muted);border-width:0;padding:0 .7em;display:inline-block;display:inline list-item;user-select:none;}.pdoc details > summary:focus{outline:0;}.pdoc details > div{margin-top:calc(0px - var(--shift) / 2);text-align:left;}.pdoc .docstring{margin-bottom:1.5rem;}.pdoc > section:first-of-type > .docstring{margin-bottom:3rem;}.pdoc .docstring pre{margin-left:1em;margin-right:1em;}.pdoc h1:target,.pdoc h2:target,.pdoc h3:target,.pdoc h4:target,.pdoc h5:target,.pdoc h6:target{background-color:var(--active);box-shadow:-1rem 0 0 0 var(--active);}.pdoc div:target > .attr,.pdoc section:target > .attr,.pdoc dd:target > a{background-color:var(--active);}.pdoc .attr:hover{filter:contrast(0.95);}.pdoc .headerlink{position:absolute;width:0;margin-left:-1.5rem;line-height:1.4rem;font-size:1.5rem;font-weight:normal;transition:all 100ms ease-in-out;opacity:0;}.pdoc .attr > .headerlink{margin-left:-2.5rem;}.pdoc *:hover > .headerlink,.pdoc *:target > .attr > .headerlink{opacity:1;}.pdoc .attr{display:block;color:var(--text);margin:1rem 0 .5rem;padding:.4rem 5rem .4rem 1rem;background-color:var(--accent);}.pdoc .classattr{margin-left:2rem;}.pdoc .name{color:var(--name);font-weight:bold;}.pdoc .def{color:var(--def);font-weight:bold;}.pdoc .signature{white-space:pre-wrap;}.pdoc .annotation{color:var(--annotation);}.pdoc .inherited{margin-left:2rem;}.pdoc .inherited dt{font-weight:700;}.pdoc .inherited dt, .pdoc .inherited dd{display:inline;margin-left:0;margin-bottom:.5rem;}.pdoc .inherited dd:not(:last-child):after{content:", ";}.pdoc .inherited .class:before{content:"class ";}.pdoc .inherited .function a:after{content:"()";}.pdoc .search-result .docstring{overflow:auto;max-height:25vh;}.pdoc .search-result.focused > .attr{background-color:var(--active);}.pdoc .attribution{margin-top:2rem;display:block;opacity:0.5;transition:all 200ms;filter:grayscale(100%);}.pdoc .attribution:hover{opacity:1;filter:grayscale(0%);}.pdoc .attribution img{margin-left:5px;height:35px;vertical-align:middle;width:70px;transition:all 200ms;}</style>
1313 </head>
1414 <body> <nav class="pdoc">
1515 <label id="navtoggle" for="togglestate" class="pdoc-button"><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke-linecap='round' stroke="currentColor" stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg></label>
1616 <input id="togglestate" type="checkbox">
1717 <div>
18 <a class="pdoc-button module-list-button" href="./index.html">
19 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-box-arrow-in-left" viewBox="0 0 16 16">
20 <path fill-rule="evenodd" d="M10 3.5a.5.5 0 0 0-.5-.5h-8a.5.5 0 0 0-.5.5v9a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-2a.5.5 0 0 1 1 0v2A1.5 1.5 0 0 1 9.5 14h-8A1.5 1.5 0 0 1 0 12.5v-9A1.5 1.5 0 0 1 1.5 2h8A1.5 1.5 0 0 1 11 3.5v2a.5.5 0 0 1-1 0v-2z"/>
21 <path fill-rule="evenodd" d="M4.146 8.354a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L5.707 7.5H14.5a.5.5 0 0 1 0 1H5.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3z"/>
22 </svg> &nbsp;netCDF4</a>
18
2319
2420
2521 <h2>Contents</h2>
2622 <ul>
27 <li><a href="#version-156">Version 1.5.6</a></li>
23 <li><a href="#version-157">Version 1.5.7</a></li>
2824 </ul></li>
2925 <li><a href="#introduction">Introduction</a>
3026 <ul>
31 <li><a href="#download">Download</a></li>
32 <li><a href="#requires">Requires</a></li>
33 <li><a href="#install">Install</a></li>
27 <li><a href="#quick-install">Quick Install</a></li>
28 <li><a href="#developer-install">Developer Install</a></li>
3429 </ul></li>
3530 <li><a href="#tutorial">Tutorial</a>
3631 <ul>
197192
198193 </li>
199194 <li>
200 <a class="class" href="#Group">Group</a>
195 <a class="class" href="#Variable">Variable</a>
201196 <ul class="memberlist">
202197 <li>
203 <a class="function" href="#Group.__init__">Group</a>
204 </li>
205 <li>
206 <a class="function" href="#Group.close">close</a>
198 <a class="function" href="#Variable.__init__">Variable</a>
199 </li>
200 <li>
201 <a class="function" href="#Variable.group">group</a>
202 </li>
203 <li>
204 <a class="function" href="#Variable.ncattrs">ncattrs</a>
205 </li>
206 <li>
207 <a class="function" href="#Variable.setncattr">setncattr</a>
208 </li>
209 <li>
210 <a class="function" href="#Variable.setncattr_string">setncattr_string</a>
211 </li>
212 <li>
213 <a class="function" href="#Variable.setncatts">setncatts</a>
214 </li>
215 <li>
216 <a class="function" href="#Variable.getncattr">getncattr</a>
217 </li>
218 <li>
219 <a class="function" href="#Variable.delncattr">delncattr</a>
220 </li>
221 <li>
222 <a class="function" href="#Variable.filters">filters</a>
223 </li>
224 <li>
225 <a class="function" href="#Variable.endian">endian</a>
226 </li>
227 <li>
228 <a class="function" href="#Variable.chunking">chunking</a>
229 </li>
230 <li>
231 <a class="function" href="#Variable.get_var_chunk_cache">get_var_chunk_cache</a>
232 </li>
233 <li>
234 <a class="function" href="#Variable.set_var_chunk_cache">set_var_chunk_cache</a>
235 </li>
236 <li>
237 <a class="function" href="#Variable.renameAttribute">renameAttribute</a>
238 </li>
239 <li>
240 <a class="function" href="#Variable.assignValue">assignValue</a>
241 </li>
242 <li>
243 <a class="function" href="#Variable.getValue">getValue</a>
244 </li>
245 <li>
246 <a class="function" href="#Variable.set_auto_chartostring">set_auto_chartostring</a>
247 </li>
248 <li>
249 <a class="function" href="#Variable.use_nc_get_vars">use_nc_get_vars</a>
250 </li>
251 <li>
252 <a class="function" href="#Variable.set_auto_maskandscale">set_auto_maskandscale</a>
253 </li>
254 <li>
255 <a class="function" href="#Variable.set_auto_scale">set_auto_scale</a>
256 </li>
257 <li>
258 <a class="function" href="#Variable.set_auto_mask">set_auto_mask</a>
259 </li>
260 <li>
261 <a class="function" href="#Variable.set_always_mask">set_always_mask</a>
262 </li>
263 <li>
264 <a class="function" href="#Variable.set_ncstring_attrs">set_ncstring_attrs</a>
265 </li>
266 <li>
267 <a class="function" href="#Variable.set_collective">set_collective</a>
268 </li>
269 <li>
270 <a class="function" href="#Variable.get_dims">get_dims</a>
271 </li>
272 <li>
273 <a class="variable" href="#Variable.name">name</a>
274 </li>
275 <li>
276 <a class="variable" href="#Variable.datatype">datatype</a>
277 </li>
278 <li>
279 <a class="variable" href="#Variable.shape">shape</a>
280 </li>
281 <li>
282 <a class="variable" href="#Variable.size">size</a>
283 </li>
284 <li>
285 <a class="variable" href="#Variable.dimensions">dimensions</a>
286 </li>
287 <li>
288 <a class="variable" href="#Variable.ndim">ndim</a>
289 </li>
290 <li>
291 <a class="variable" href="#Variable.dtype">dtype</a>
292 </li>
293 <li>
294 <a class="variable" href="#Variable.mask">mask</a>
295 </li>
296 <li>
297 <a class="variable" href="#Variable.scale">scale</a>
298 </li>
299 <li>
300 <a class="variable" href="#Variable.always_mask">always_mask</a>
301 </li>
302 <li>
303 <a class="variable" href="#Variable.chartostring">chartostring</a>
207304 </li>
208305 </ul>
209306
230327
231328 </li>
232329 <li>
233 <a class="class" href="#Variable">Variable</a>
330 <a class="class" href="#Group">Group</a>
234331 <ul class="memberlist">
235332 <li>
236 <a class="function" href="#Variable.__init__">Variable</a>
237 </li>
238 <li>
239 <a class="function" href="#Variable.group">group</a>
240 </li>
241 <li>
242 <a class="function" href="#Variable.ncattrs">ncattrs</a>
243 </li>
244 <li>
245 <a class="function" href="#Variable.setncattr">setncattr</a>
246 </li>
247 <li>
248 <a class="function" href="#Variable.setncattr_string">setncattr_string</a>
249 </li>
250 <li>
251 <a class="function" href="#Variable.setncatts">setncatts</a>
252 </li>
253 <li>
254 <a class="function" href="#Variable.getncattr">getncattr</a>
255 </li>
256 <li>
257 <a class="function" href="#Variable.delncattr">delncattr</a>
258 </li>
259 <li>
260 <a class="function" href="#Variable.filters">filters</a>
261 </li>
262 <li>
263 <a class="function" href="#Variable.endian">endian</a>
264 </li>
265 <li>
266 <a class="function" href="#Variable.chunking">chunking</a>
267 </li>
268 <li>
269 <a class="function" href="#Variable.get_var_chunk_cache">get_var_chunk_cache</a>
270 </li>
271 <li>
272 <a class="function" href="#Variable.set_var_chunk_cache">set_var_chunk_cache</a>
273 </li>
274 <li>
275 <a class="function" href="#Variable.renameAttribute">renameAttribute</a>
276 </li>
277 <li>
278 <a class="function" href="#Variable.assignValue">assignValue</a>
279 </li>
280 <li>
281 <a class="function" href="#Variable.getValue">getValue</a>
282 </li>
283 <li>
284 <a class="function" href="#Variable.set_auto_chartostring">set_auto_chartostring</a>
285 </li>
286 <li>
287 <a class="function" href="#Variable.use_nc_get_vars">use_nc_get_vars</a>
288 </li>
289 <li>
290 <a class="function" href="#Variable.set_auto_maskandscale">set_auto_maskandscale</a>
291 </li>
292 <li>
293 <a class="function" href="#Variable.set_auto_scale">set_auto_scale</a>
294 </li>
295 <li>
296 <a class="function" href="#Variable.set_auto_mask">set_auto_mask</a>
297 </li>
298 <li>
299 <a class="function" href="#Variable.set_always_mask">set_always_mask</a>
300 </li>
301 <li>
302 <a class="function" href="#Variable.set_ncstring_attrs">set_ncstring_attrs</a>
303 </li>
304 <li>
305 <a class="function" href="#Variable.set_collective">set_collective</a>
306 </li>
307 <li>
308 <a class="function" href="#Variable.get_dims">get_dims</a>
309 </li>
310 <li>
311 <a class="variable" href="#Variable.name">name</a>
312 </li>
313 <li>
314 <a class="variable" href="#Variable.datatype">datatype</a>
315 </li>
316 <li>
317 <a class="variable" href="#Variable.shape">shape</a>
318 </li>
319 <li>
320 <a class="variable" href="#Variable.size">size</a>
321 </li>
322 <li>
323 <a class="variable" href="#Variable.dimensions">dimensions</a>
324 </li>
325 <li>
326 <a class="variable" href="#Variable.ndim">ndim</a>
327 </li>
328 <li>
329 <a class="variable" href="#Variable.dtype">dtype</a>
330 </li>
331 <li>
332 <a class="variable" href="#Variable.mask">mask</a>
333 </li>
334 <li>
335 <a class="variable" href="#Variable.scale">scale</a>
336 </li>
337 <li>
338 <a class="variable" href="#Variable.always_mask">always_mask</a>
339 </li>
340 <li>
341 <a class="variable" href="#Variable.chartostring">chartostring</a>
333 <a class="function" href="#Group.__init__">Group</a>
334 </li>
335 <li>
336 <a class="function" href="#Group.close">close</a>
337 </li>
338 </ul>
339
340 </li>
341 <li>
342 <a class="class" href="#MFDataset">MFDataset</a>
343 <ul class="memberlist">
344 <li>
345 <a class="function" href="#MFDataset.__init__">MFDataset</a>
346 </li>
347 <li>
348 <a class="function" href="#MFDataset.ncattrs">ncattrs</a>
349 </li>
350 <li>
351 <a class="function" href="#MFDataset.close">close</a>
352 </li>
353 </ul>
354
355 </li>
356 <li>
357 <a class="class" href="#MFTime">MFTime</a>
358 <ul class="memberlist">
359 <li>
360 <a class="function" href="#MFTime.__init__">MFTime</a>
342361 </li>
343362 </ul>
344363
377396
378397 </li>
379398 <li>
380 <a class="class" href="#EnumType">EnumType</a>
381 <ul class="memberlist">
382 <li>
383 <a class="function" href="#EnumType.__init__">EnumType</a>
384 </li>
385 <li>
386 <a class="variable" href="#EnumType.dtype">dtype</a>
387 </li>
388 <li>
389 <a class="variable" href="#EnumType.name">name</a>
390 </li>
391 <li>
392 <a class="variable" href="#EnumType.enum_dict">enum_dict</a>
393 </li>
394 </ul>
395
399 <a class="function" href="#date2num">date2num</a>
396400 </li>
397401 <li>
398 <a class="function" href="#getlibversion">getlibversion</a>
402 <a class="function" href="#num2date">num2date</a>
399403 </li>
400404 <li>
401 <a class="function" href="#get_chunk_cache">get_chunk_cache</a>
402 </li>
403 <li>
404 <a class="function" href="#set_chunk_cache">set_chunk_cache</a>
405 </li>
406 <li>
407 <a class="function" href="#stringtoarr">stringtoarr</a>
405 <a class="function" href="#date2index">date2index</a>
408406 </li>
409407 <li>
410408 <a class="function" href="#stringtochar">stringtochar</a>
413411 <a class="function" href="#chartostring">chartostring</a>
414412 </li>
415413 <li>
416 <a class="class" href="#MFDataset">MFDataset</a>
417 <ul class="memberlist">
418 <li>
419 <a class="function" href="#MFDataset.__init__">MFDataset</a>
420 </li>
421 <li>
422 <a class="function" href="#MFDataset.ncattrs">ncattrs</a>
423 </li>
424 <li>
425 <a class="function" href="#MFDataset.close">close</a>
426 </li>
427 </ul>
428
414 <a class="function" href="#stringtoarr">stringtoarr</a>
429415 </li>
430416 <li>
431 <a class="class" href="#MFTime">MFTime</a>
417 <a class="function" href="#getlibversion">getlibversion</a>
418 </li>
419 <li>
420 <a class="class" href="#EnumType">EnumType</a>
432421 <ul class="memberlist">
433422 <li>
434 <a class="function" href="#MFTime.__init__">MFTime</a>
423 <a class="function" href="#EnumType.__init__">EnumType</a>
424 </li>
425 <li>
426 <a class="variable" href="#EnumType.dtype">dtype</a>
427 </li>
428 <li>
429 <a class="variable" href="#EnumType.name">name</a>
430 </li>
431 <li>
432 <a class="variable" href="#EnumType.enum_dict">enum_dict</a>
435433 </li>
436434 </ul>
437435
436 </li>
437 <li>
438 <a class="function" href="#get_chunk_cache">get_chunk_cache</a>
439 </li>
440 <li>
441 <a class="function" href="#set_chunk_cache">set_chunk_cache</a>
438442 </li>
439443 </ul>
440444
441445
442446 <a class="attribution" title="pdoc: Python API documentation generator" href="https://pdoc.dev">
443 built with <img
444 alt="pdoc"
447 built with <span class="visually-hidden">pdoc</span><img
448 alt="pdoc logo"
445449 src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20role%3D%22img%22%20aria-label%3D%22pdoc%20logo%22%20width%3D%22300%22%20height%3D%22150%22%20viewBox%3D%22-1%200%2060%2030%22%3E%3Ctitle%3Epdoc%3C/title%3E%3Cpath%20d%3D%22M29.621%2021.293c-.011-.273-.214-.475-.511-.481a.5.5%200%200%200-.489.503l-.044%201.393c-.097.551-.695%201.215-1.566%201.704-.577.428-1.306.486-2.193.182-1.426-.617-2.467-1.654-3.304-2.487l-.173-.172a3.43%203.43%200%200%200-.365-.306.49.49%200%200%200-.286-.196c-1.718-1.06-4.931-1.47-7.353.191l-.219.15c-1.707%201.187-3.413%202.131-4.328%201.03-.02-.027-.49-.685-.141-1.763.233-.721.546-2.408.772-4.076.042-.09.067-.187.046-.288.166-1.347.277-2.625.241-3.351%201.378-1.008%202.271-2.586%202.271-4.362%200-.976-.272-1.935-.788-2.774-.057-.094-.122-.18-.184-.268.033-.167.052-.339.052-.516%200-1.477-1.202-2.679-2.679-2.679-.791%200-1.496.352-1.987.9a6.3%206.3%200%200%200-1.001.029c-.492-.564-1.207-.929-2.012-.929-1.477%200-2.679%201.202-2.679%202.679A2.65%202.65%200%200%200%20.97%206.554c-.383.747-.595%201.572-.595%202.41%200%202.311%201.507%204.29%203.635%205.107-.037.699-.147%202.27-.423%203.294l-.137.461c-.622%202.042-2.515%208.257%201.727%2010.643%201.614.908%203.06%201.248%204.317%201.248%202.665%200%204.492-1.524%205.322-2.401%201.476-1.559%202.886-1.854%206.491.82%201.877%201.393%203.514%201.753%204.861%201.068%202.223-1.713%202.811-3.867%203.399-6.374.077-.846.056-1.469.054-1.537zm-4.835%204.313c-.054.305-.156.586-.242.629-.034-.007-.131-.022-.307-.157-.145-.111-.314-.478-.456-.908.221.121.432.25.675.355.115.039.219.051.33.081zm-2.251-1.238c-.05.33-.158.648-.252.694-.022.001-.125-.018-.307-.157-.217-.166-.488-.906-.639-1.573.358.344.754.693%201.198%201.036zm-3.887-2.337c-.006-.116-.018-.231-.041-.342.635.145%201.189.368%201.599.625.097.231.166.481.174.642-.03.049-.055.101-.067.158-.046.013-.128.026-.298.004-.278-.037-.901-.57-1.367-1.087zm-1.127-.497c.116.306.176.625.12.71-.019.014-.117.045-.345.016-.206-.027-.604-.332-.986-.695.41-.051.816-.056%201.211-.031zm-4.535%201.535c.209.22.379.47.358.598-.006.041-.088.138-.351.234-.144.055-.539-.063-.979-.259a11.66%2011.66%200%200%200%20.972-.573zm.983-.664c.359-.237.738-.418%201.126-.554.25.237.479.548.457.694-.006.042-.087.138-.351.235-.174.064-.694-.105-1.232-.375zm-3.381%201.794c-.022.145-.061.29-.149.401-.133.166-.358.248-.69.251h-.002c-.133%200-.306-.26-.45-.621.417.091.854.07%201.291-.031zm-2.066-8.077a4.78%204.78%200%200%201-.775-.584c.172-.115.505-.254.88-.378l-.105.962zm-.331%202.302a10.32%2010.32%200%200%201-.828-.502c.202-.143.576-.328.984-.49l-.156.992zm-.45%202.157l-.701-.403c.214-.115.536-.249.891-.376a11.57%2011.57%200%200%201-.19.779zm-.181%201.716c.064.398.194.702.298.893-.194-.051-.435-.162-.736-.398.061-.119.224-.3.438-.495zM8.87%204.141c0%20.152-.123.276-.276.276s-.275-.124-.275-.276.123-.276.276-.276.275.124.275.276zm-.735-.389a1.15%201.15%200%200%200-.314.783%201.16%201.16%200%200%200%201.162%201.162c.457%200%20.842-.27%201.032-.653.026.117.042.238.042.362a1.68%201.68%200%200%201-1.679%201.679%201.68%201.68%200%200%201-1.679-1.679c0-.843.626-1.535%201.436-1.654zM5.059%205.406A1.68%201.68%200%200%201%203.38%207.085a1.68%201.68%200%200%201-1.679-1.679c0-.037.009-.072.011-.109.21.3.541.508.935.508a1.16%201.16%200%200%200%201.162-1.162%201.14%201.14%200%200%200-.474-.912c.015%200%20.03-.005.045-.005.926.001%201.679.754%201.679%201.68zM3.198%204.141c0%20.152-.123.276-.276.276s-.275-.124-.275-.276.123-.276.276-.276.275.124.275.276zM1.375%208.964c0-.52.103-1.035.288-1.52.466.394%201.06.64%201.717.64%201.144%200%202.116-.725%202.499-1.738.383%201.012%201.355%201.738%202.499%201.738.867%200%201.631-.421%202.121-1.062.307.605.478%201.267.478%201.942%200%202.486-2.153%204.51-4.801%204.51s-4.801-2.023-4.801-4.51zm24.342%2019.349c-.985.498-2.267.168-3.813-.979-3.073-2.281-5.453-3.199-7.813-.705-1.315%201.391-4.163%203.365-8.423.97-3.174-1.786-2.239-6.266-1.261-9.479l.146-.492c.276-1.02.395-2.457.444-3.268a6.11%206.11%200%200%200%201.18.115%206.01%206.01%200%200%200%202.536-.562l-.006.175c-.802.215-1.848.612-2.021%201.25-.079.295.021.601.274.837.219.203.415.364.598.501-.667.304-1.243.698-1.311%201.179-.02.144-.022.507.393.787.213.144.395.26.564.365-1.285.521-1.361.96-1.381%201.126-.018.142-.011.496.427.746l.854.489c-.473.389-.971.914-.999%201.429-.018.278.095.532.316.713.675.556%201.231.721%201.653.721.059%200%20.104-.014.158-.02.207.707.641%201.64%201.513%201.64h.013c.8-.008%201.236-.345%201.462-.626.173-.216.268-.457.325-.692.424.195.93.374%201.372.374.151%200%20.294-.021.423-.068.732-.27.944-.704.993-1.021.009-.061.003-.119.002-.179.266.086.538.147.789.147.15%200%20.294-.021.423-.069.542-.2.797-.489.914-.754.237.147.478.258.704.288.106.014.205.021.296.021.356%200%20.595-.101.767-.229.438.435%201.094.992%201.656%201.067.106.014.205.021.296.021a1.56%201.56%200%200%200%20.323-.035c.17.575.453%201.289.866%201.605.358.273.665.362.914.362a.99.99%200%200%200%20.421-.093%201.03%201.03%200%200%200%20.245-.164c.168.428.39.846.68%201.068.358.273.665.362.913.362a.99.99%200%200%200%20.421-.093c.317-.148.512-.448.639-.762.251.157.495.257.726.257.127%200%20.25-.024.37-.071.427-.17.706-.617.841-1.314.022-.015.047-.022.068-.038.067-.051.133-.104.196-.159-.443%201.486-1.107%202.761-2.086%203.257zM8.66%209.925a.5.5%200%201%200-1%200c0%20.653-.818%201.205-1.787%201.205s-1.787-.552-1.787-1.205a.5.5%200%201%200-1%200c0%201.216%201.25%202.205%202.787%202.205s2.787-.989%202.787-2.205zm4.4%2015.965l-.208.097c-2.661%201.258-4.708%201.436-6.086.527-1.542-1.017-1.88-3.19-1.844-4.198a.4.4%200%200%200-.385-.414c-.242-.029-.406.164-.414.385-.046%201.249.367%203.686%202.202%204.896.708.467%201.547.7%202.51.7%201.248%200%202.706-.392%204.362-1.174l.185-.086a.4.4%200%200%200%20.205-.527c-.089-.204-.326-.291-.527-.206zM9.547%202.292c.093.077.205.114.317.114a.5.5%200%200%200%20.318-.886L8.817.397a.5.5%200%200%200-.703.068.5.5%200%200%200%20.069.703l1.364%201.124zm-7.661-.065c.086%200%20.173-.022.253-.068l1.523-.893a.5.5%200%200%200-.506-.863l-1.523.892a.5.5%200%200%200-.179.685c.094.158.261.247.432.247z%22%20transform%3D%22matrix%28-1%200%200%201%2058%200%29%22%20fill%3D%22%233bb300%22/%3E%3Cpath%20d%3D%22M.3%2021.86V10.18q0-.46.02-.68.04-.22.18-.5.28-.54%201.34-.54%201.06%200%201.42.28.38.26.44.78.76-1.04%202.38-1.04%201.64%200%203.1%201.54%201.46%201.54%201.46%203.58%200%202.04-1.46%203.58-1.44%201.54-3.08%201.54-1.64%200-2.38-.92v4.04q0%20.46-.04.68-.02.22-.18.5-.14.3-.5.42-.36.12-.98.12-.62%200-1-.12-.36-.12-.52-.4-.14-.28-.18-.5-.02-.22-.02-.68zm3.96-9.42q-.46.54-.46%201.18%200%20.64.46%201.18.48.52%201.2.52.74%200%201.24-.52.52-.52.52-1.18%200-.66-.48-1.18-.48-.54-1.26-.54-.76%200-1.22.54zm14.741-8.36q.16-.3.54-.42.38-.12%201-.12.64%200%201.02.12.38.12.52.42.16.3.18.54.04.22.04.68v11.94q0%20.46-.04.7-.02.22-.18.5-.3.54-1.7.54-1.38%200-1.54-.98-.84.96-2.34.96-1.8%200-3.28-1.56-1.48-1.58-1.48-3.66%200-2.1%201.48-3.68%201.5-1.58%203.28-1.58%201.48%200%202.3%201v-4.2q0-.46.02-.68.04-.24.18-.52zm-3.24%2010.86q.52.54%201.26.54.74%200%201.22-.54.5-.54.5-1.18%200-.66-.48-1.22-.46-.56-1.26-.56-.8%200-1.28.56-.48.54-.48%201.2%200%20.66.52%201.2zm7.833-1.2q0-2.4%201.68-3.96%201.68-1.56%203.84-1.56%202.16%200%203.82%201.56%201.66%201.54%201.66%203.94%200%201.66-.86%202.96-.86%201.28-2.1%201.9-1.22.6-2.54.6-1.32%200-2.56-.64-1.24-.66-2.1-1.92-.84-1.28-.84-2.88zm4.18%201.44q.64.48%201.3.48.66%200%201.32-.5.66-.5.66-1.48%200-.98-.62-1.46-.62-.48-1.34-.48-.72%200-1.34.5-.62.5-.62%201.48%200%20.96.64%201.46zm11.412-1.44q0%20.84.56%201.32.56.46%201.18.46.64%200%201.18-.36.56-.38.9-.38.6%200%201.46%201.06.46.58.46%201.04%200%20.76-1.1%201.42-1.14.8-2.8.8-1.86%200-3.58-1.34-.82-.64-1.34-1.7-.52-1.08-.52-2.36%200-1.3.52-2.34.52-1.06%201.34-1.7%201.66-1.32%203.54-1.32.76%200%201.48.22.72.2%201.06.4l.32.2q.36.24.56.38.52.4.52.92%200%20.5-.42%201.14-.72%201.1-1.38%201.1-.38%200-1.08-.44-.36-.34-1.04-.34-.66%200-1.24.48-.58.48-.58%201.34z%22%20fill%3D%22green%22/%3E%3C/svg%3E"/>
446450 </a>
447451 </div>
449453 <main class="pdoc">
450454 <section>
451455 <h1 class="modulename">
452 <a href="./index.html">netCDF4</a>._netCDF4 </h1>
453
454 <div class="docstring"><h2 id="version-156">Version 1.5.6</h2>
456 netCDF4 </h1>
457
458 <div class="docstring"><h2 id="version-157">Version 1.5.7</h2>
455459
456460 <h1 id="introduction">Introduction</h1>
457461
474478 compound types containing enums, or vlens containing compound
475479 types) are not supported.</p>
476480
477 <h2 id="download">Download</h2>
481 <h2 id="quick-install">Quick Install</h2>
478482
479483 <ul>
480 <li>Latest bleeding-edge code from the
484 <li>the easiest way to get going is to install via <code>pip install netCDF4</code>.
485 (or if you use the <a href="http://conda.io">conda</a> package manager <code>conda install -c conda-forge netCDF4</code>).</li>
486 </ul>
487
488 <h2 id="developer-install">Developer Install</h2>
489
490 <ul>
491 <li>Clone the
481492 <a href="http://github.com/Unidata/netcdf4-python">github repository</a>.</li>
482 <li>Latest <a href="https://pypi.python.org/pypi/netCDF4">releases</a>
483 (source code and binary installers).</li>
484 </ul>
485
486 <h2 id="requires">Requires</h2>
487
488 <ul>
489 <li>Python 3.6 or later.</li>
490 <li><a href="http://numpy.scipy.org">numpy array module</a>, version 1.10.0 or later.</li>
491 <li><a href="http://cython.org">Cython</a>, version 0.21 or later.</li>
492 <li><a href="https://pypi.python.org/pypi/setuptools">setuptools</a>, version 18.0 or
493 later.</li>
494 <li>The HDF5 C library version 1.8.4-patch1 or higher
495 from <a href="ftp://ftp.hdfgroup.org/HDF5/current/src"></a>.
496 <strong><em>netCDF version 4.4.1 or higher is recommended if using HDF5 1.10.x -
497 otherwise resulting files may be unreadable by clients using earlier
498 versions of HDF5. For netCDF &lt; 4.4.1, HDF5 version 1.8.x is recommended.</em></strong>
499 Be sure to build with <code>--enable-hl --enable-shared</code>.</li>
500 <li><a href="http://curl.haxx.se/libcurl">Libcurl</a>, if you want
501 <a href="http://opendap.org">OPeNDAP</a> support.</li>
502 <li><a href="http://www.hdfgroup.org/products/hdf4">HDF4</a>, if you want
503 to be able to read HDF4 "Scientific Dataset" (SD) files.</li>
504 <li>The netCDF-4 C library from the <a href="https://github.com/Unidata/netcdf-c/releases">github releases
505 page</a>.
506 Version 4.1.1 or higher is required (4.2 or higher recommended).
507 Be sure to build with <code>--enable-netcdf-4 --enable-shared</code>, and set
508 <code>CPPFLAGS="-I $HDF5_DIR/include"</code> and <code>LDFLAGS="-L $HDF5_DIR/lib"</code>,
509 where <code>$HDF5_DIR</code> is the directory where HDF5 was installed.
510 If you want <a href="http://opendap.org">OPeNDAP</a> support, add <code>--enable-dap</code>.
511 If you want HDF4 SD support, add <code>--enable-hdf4</code> and add
512 the location of the HDF4 headers and library to <code>$CPPFLAGS</code> and <code>$LDFLAGS</code>.</li>
513 <li>for MPI parallel IO support, an MPI-enabled versions of the netcdf library
514 is required, as is the <a href="http://mpi4py.scipy.org">mpi4py</a> python module.
493 <li>Make sure the dependencies are satisfied (Python 3.6 or later,
494 <a href="http://numpy.scipy.org">numpy</a>,
495 <a href="http://cython.org">Cython</a>,
496 <a href="https://github.com/Unidata/cftime">cftime</a>,
497 <a href="https://pypi.python.org/pypi/setuptools">setuptools</a>,
498 the <a href="https://www.hdfgroup.org/solutions/hdf5/">HDF5 C library</a>,
499 and the <a href="https://www.unidata.ucar.edu/software/netcdf/">netCDF C library</a>).
500 For MPI parallel IO support, an MPI-enabled versions of the netcdf library
501 is required, as is <a href="http://mpi4py.scipy.org">mpi4py</a>.
515502 Parallel IO further depends on the existence of MPI-enabled HDF5 or the
516503 <a href="https://parallel-netcdf.github.io/">PnetCDF</a> library.</li>
517 <li><a href="https://github.com/Unidata/cftime">cftime</a> for
518 time and date handling utility functions.</li>
519 </ul>
520
521 <h2 id="install">Install</h2>
522
523 <ul>
524 <li>install the requisite python modules and C libraries (see above). It's
525 easiest if all the C libs are built as shared libraries.</li>
526 <li>By default, the utility <code>nc-config</code>, installed with netcdf 4.1.2 or higher,
504 <li>By default, the utility <code>nc-config</code> (installed with netcdf-c)
527505 will be run used to determine where all the dependencies live.</li>
528506 <li>If <code>nc-config</code> is not in your default <code>PATH</code>, you can set the <code>NETCDF4_DIR</code>
529507 environment variable and <code>setup.py</code> will look in <code>$NETCDF4_DIR/bin</code>.
535513 As a last resort, the library and include paths can be set via environment variables.
536514 If you go this route, set <code>USE_NCCONFIG</code> and <code>USE_SETUPCFG</code> to 0, and specify
537515 <code>NETCDF4_LIBDIR</code>, <code>NETCDF4_INCDIR</code>, <code>HDF5_LIBDIR</code> and <code>HDF5_INCDIR</code>.
538 Similarly, environment variables
539 (all capitalized) can be used to set the include and library paths for
540 <code>hdf4</code>, <code>szip</code>, <code>jpeg</code>, <code>curl</code> and <code>zlib</code>. If the dependencies are not found
516 If the dependencies are not found
541517 in any of the paths specified by environment variables, then standard locations
542518 (such as <code>/usr</code> and <code>/usr/local</code>) are searched.</li>
543519 <li>run <code>python setup.py build</code>, then <code>python setup.py install</code> (as root if
544 necessary). <code>pip install</code> can be used to install pre-compiled binary wheels from
545 <a href="https://pypi.org/project/netCDF4">pypi</a>.</li>
520 necessary).</li>
546521 <li>run the tests in the 'test' directory by running <code>python run_all.py</code>.</li>
547522 </ul>
548523
568543
569544 <h2 id="creatingopeningclosing-a-netcdf-file">Creating/Opening/Closing a netCDF file</h2>
570545
571 <p>To create a netCDF file from python, you simply call the <a href="#Dataset">Dataset</a>
546 <p>To create a netCDF file from python, you simply call the <code><a href="#Dataset">Dataset</a></code>
572547 constructor. This is also the method used to open an existing netCDF
573548 file. If the file is open for write access (<code>mode='w', 'r+'</code> or <code>'a'</code>), you may
574549 write any type of data including new dimensions, groups, variables and
592567 keyword in the <code><a href="#Dataset">Dataset</a></code> constructor. The default format is
593568 <code>NETCDF4</code>. To see how a given file is formatted, you can examine the
594569 <code>data_model</code> attribute. Closing the netCDF file is
595 accomplished via the <a href="#<a href="#Dataset.close">Dataset.close</a>"><a href="#Dataset.close">Dataset.close</a></a> method of the <a href="#Dataset">Dataset</a>
570 accomplished via the <code><a href="#Dataset.close">Dataset.close</a></code> method of the <code><a href="#Dataset">Dataset</a></code>
596571 instance.</p>
597572
598573 <p>Here's an example:</p>
605580 </code></pre></div>
606581
607582 <p>Remote <a href="http://opendap.org">OPeNDAP</a>-hosted datasets can be accessed for
608 reading over http if a URL is provided to the <a href="#Dataset">Dataset</a> constructor instead of a
583 reading over http if a URL is provided to the <code><a href="#Dataset">Dataset</a></code> constructor instead of a
609584 filename. However, this requires that the netCDF library be built with
610585 OPenDAP support, via the <code>--enable-dap</code> configure option (added in
611586 version 4.0.1).</p>
615590 <p>netCDF version 4 added support for organizing data in hierarchical
616591 groups, which are analogous to directories in a filesystem. Groups serve
617592 as containers for variables, dimensions and attributes, as well as other
618 groups. A <a href="#Dataset">Dataset</a> creates a special group, called
593 groups. A <code><a href="#Dataset">Dataset</a></code> creates a special group, called
619594 the 'root group', which is similar to the root directory in a unix
620 filesystem. To create <a href="#Group">Group</a> instances, use the
621 <a href="#<a href="#Dataset.createGroup">Dataset.createGroup</a>"><a href="#Dataset.createGroup">Dataset.createGroup</a></a> method of a <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a>
622 instance. <a href="#<a href="#Dataset.createGroup">Dataset.createGroup</a>"><a href="#Dataset.createGroup">Dataset.createGroup</a></a> takes a single argument, a
623 python string containing the name of the new group. The new <a href="#Group">Group</a>
595 filesystem. To create <code><a href="#Group">Group</a></code> instances, use the
596 <code><a href="#Dataset.createGroup">Dataset.createGroup</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code>
597 instance. <code><a href="#Dataset.createGroup">Dataset.createGroup</a></code> takes a single argument, a
598 python string containing the name of the new group. The new <code><a href="#Group">Group</a></code>
624599 instances contained within the root group can be accessed by name using
625 the <code>groups</code> dictionary attribute of the <a href="#Dataset">Dataset</a> instance. Only
600 the <code>groups</code> dictionary attribute of the <code><a href="#Dataset">Dataset</a></code> instance. Only
626601 <code>NETCDF4</code> formatted files support Groups, if you try to create a Group
627602 in a netCDF 3 file you will get an error message.</p>
628603
642617 <span class="o">&gt;&gt;&gt;</span>
643618 </code></pre></div>
644619
645 <p>Groups can exist within groups in a <a href="#Dataset">Dataset</a>, just as directories
646 exist within directories in a unix filesystem. Each <a href="#Group">Group</a> instance
620 <p>Groups can exist within groups in a <code><a href="#Dataset">Dataset</a></code>, just as directories
621 exist within directories in a unix filesystem. Each <code><a href="#Group">Group</a></code> instance
647622 has a <code>groups</code> attribute dictionary containing all of the group
648 instances contained within that group. Each <a href="#Group">Group</a> instance also has a
623 instances contained within that group. Each <code><a href="#Group">Group</a></code> instance also has a
649624 <code>path</code> attribute that contains a simulated unix directory path to
650625 that group. To simplify the creation of nested groups, you can
651 use a unix-like path as an argument to <a href="#<a href="#Dataset.createGroup">Dataset.createGroup</a>"><a href="#Dataset.createGroup">Dataset.createGroup</a></a>.</p>
626 use a unix-like path as an argument to <code><a href="#Dataset.createGroup">Dataset.createGroup</a></code>.</p>
652627
653628 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">fcstgrp1</span> <span class="o">=</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">createGroup</span><span class="p">(</span><span class="s2">&quot;/forecasts/model1&quot;</span><span class="p">)</span>
654629 <span class="o">&gt;&gt;&gt;</span> <span class="n">fcstgrp2</span> <span class="o">=</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">createGroup</span><span class="p">(</span><span class="s2">&quot;/forecasts/model2&quot;</span><span class="p">)</span>
660635 returned.</p>
661636
662637 <p>Here's an example that shows how to navigate all the groups in a
663 <a href="#Dataset">Dataset</a>. The function <code>walktree</code> is a Python generator that is used
664 to walk the directory tree. Note that printing the <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a>
638 <code><a href="#Dataset">Dataset</a></code>. The function <code>walktree</code> is a Python generator that is used
639 to walk the directory tree. Note that printing the <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code>
665640 object yields summary information about it's contents.</p>
666641
667642 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="k">def</span> <span class="nf">walktree</span><span class="p">(</span><span class="n">top</span><span class="p">):</span>
668 <span class="o">...</span> <span class="n">values</span> <span class="o">=</span> <span class="n">top</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">values</span><span class="p">()</span>
669 <span class="o">...</span> <span class="k">yield</span> <span class="n">values</span>
643 <span class="o">...</span> <span class="k">yield</span> <span class="n">top</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">values</span><span class="p">()</span>
670644 <span class="o">...</span> <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">top</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
671 <span class="o">...</span> <span class="k">for</span> <span class="n">children</span> <span class="ow">in</span> <span class="n">walktree</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
672 <span class="o">...</span> <span class="k">yield</span> <span class="n">children</span>
645 <span class="o">...</span> <span class="k">yield from</span> <span class="n">walktree</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
673646 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">rootgrp</span><span class="p">)</span>
674647 <span class="o">&lt;</span><span class="k">class</span> <span class="err">&#39;</span><span class="nc">netCDF4</span><span class="o">.</span><span class="n">_netCDF4</span><span class="o">.</span><span class="n">Dataset</span><span class="s1">&#39;&gt;</span>
675648 <span class="n">root</span> <span class="n">group</span> <span class="p">(</span><span class="n">NETCDF4</span> <span class="n">data</span> <span class="n">model</span><span class="p">,</span> <span class="n">file</span> <span class="nb">format</span> <span class="n">HDF5</span><span class="p">):</span>
707680 before any variables can be created the dimensions they use must be
708681 created first. A special case, not often used in practice, is that of a
709682 scalar variable, which has no dimensions. A dimension is created using
710 the <a href="#<a href="#Dataset.createDimension">Dataset.createDimension</a>"><a href="#Dataset.createDimension">Dataset.createDimension</a></a> method of a <a href="#Dataset">Dataset</a>
711 or <a href="#Group">Group</a> instance. A Python string is used to set the name of the
683 the <code><a href="#Dataset.createDimension">Dataset.createDimension</a></code> method of a <code><a href="#Dataset">Dataset</a></code>
684 or <code><a href="#Group">Group</a></code> instance. A Python string is used to set the name of the
712685 dimension, and an integer value is used to set the size. To create an
713686 unlimited dimension (a dimension that can be appended to), the size
714687 value is set to <code>None</code> or 0. In this example, there both the <code>time</code> and
722695 <span class="o">&gt;&gt;&gt;</span> <span class="n">lon</span> <span class="o">=</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s2">&quot;lon&quot;</span><span class="p">,</span> <span class="mi">144</span><span class="p">)</span>
723696 </code></pre></div>
724697
725 <p>All of the <a href="#Dimension">Dimension</a> instances are stored in a python dictionary.</p>
698 <p>All of the <code><a href="#Dimension">Dimension</a></code> instances are stored in a python dictionary.</p>
726699
727700 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">rootgrp</span><span class="o">.</span><span class="n">dimensions</span><span class="p">)</span>
728701 <span class="p">{</span><span class="s1">&#39;level&#39;</span><span class="p">:</span> <span class="o">&lt;</span><span class="k">class</span> <span class="err">&#39;</span><span class="nc">netCDF4</span><span class="o">.</span><span class="n">_netCDF4</span><span class="o">.</span><span class="n">Dimension</span><span class="s1">&#39;&gt; (unlimited): name = &#39;</span><span class="n">level</span><span class="s1">&#39;, size = 0, &#39;</span><span class="n">time</span><span class="s1">&#39;: &lt;class &#39;</span><span class="n">netCDF4</span><span class="o">.</span><span class="n">_netCDF4</span><span class="o">.</span><span class="n">Dimension</span><span class="s1">&#39;&gt; (unlimited): name = &#39;</span><span class="n">time</span><span class="s1">&#39;, size = 0, &#39;</span><span class="n">lat</span><span class="s1">&#39;: &lt;class &#39;</span><span class="n">netCDF4</span><span class="o">.</span><span class="n">_netCDF4</span><span class="o">.</span><span class="n">Dimension</span><span class="s1">&#39;&gt;: name = &#39;</span><span class="n">lat</span><span class="s1">&#39;, size = 73, &#39;</span><span class="n">lon</span><span class="s1">&#39;: &lt;class &#39;</span><span class="n">netCDF4</span><span class="o">.</span><span class="n">_netCDF4</span><span class="o">.</span><span class="n">Dimension</span><span class="s1">&#39;&gt;: name = &#39;</span><span class="n">lon</span><span class="s1">&#39;, size = 144}</span>
729702 </code></pre></div>
730703
731 <p>Using the python <code>len</code> function with a <a href="#Dimension">Dimension</a> instance returns
704 <p>Using the python <code>len</code> function with a <code><a href="#Dimension">Dimension</a></code> instance returns
732705 current size of that dimension.
733 <a href="#<a href="#Dimension.isunlimited">Dimension.isunlimited</a>"><a href="#Dimension.isunlimited">Dimension.isunlimited</a></a> method of a <a href="#Dimension">Dimension</a> instance
706 <code><a href="#Dimension.isunlimited">Dimension.isunlimited</a></code> method of a <code><a href="#Dimension">Dimension</a></code> instance
734707 be used to determine if the dimensions is unlimited, or appendable.</p>
735708
736709 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">lon</span><span class="p">))</span>
741714 <span class="kc">True</span>
742715 </code></pre></div>
743716
744 <p>Printing the <a href="#Dimension">Dimension</a> object
717 <p>Printing the <code><a href="#Dimension">Dimension</a></code> object
745718 provides useful summary info, including the name and length of the dimension,
746719 and whether it is unlimited.</p>
747720
753726 <span class="o">&lt;</span><span class="k">class</span> <span class="err">&#39;</span><span class="nc">netCDF4</span><span class="o">.</span><span class="n">_netCDF4</span><span class="o">.</span><span class="n">Dimension</span><span class="s1">&#39;&gt;: name = &#39;</span><span class="n">lon</span><span class="s1">&#39;, size = 144</span>
754727 </code></pre></div>
755728
756 <p><a href="#Dimension">Dimension</a> names can be changed using the
757 <a href="#Datatset.renameDimension">Datatset.renameDimension</a> method of a <a href="#Dataset">Dataset</a> or
758 <a href="#Group">Group</a> instance.</p>
729 <p><code><a href="#Dimension">Dimension</a></code> names can be changed using the
730 <code>Datatset.renameDimension</code> method of a <code><a href="#Dataset">Dataset</a></code> or
731 <code><a href="#Group">Group</a></code> instance.</p>
759732
760733 <h2 id="variables-in-a-netcdf-file">Variables in a netCDF file</h2>
761734
763736 supplied by the <a href="http://numpy.scipy.org">numpy module</a>. However,
764737 unlike numpy arrays, netCDF4 variables can be appended to along one or
765738 more 'unlimited' dimensions. To create a netCDF variable, use the
766 <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a> method of a <a href="#Dataset">Dataset</a> or
767 <a href="#Group">Group</a> instance. The <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a> method
739 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or
740 <code><a href="#Group">Group</a></code> instance. The <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code>j method
768741 has two mandatory arguments, the variable name (a Python string), and
769742 the variable datatype. The variable's dimensions are given by a tuple
770743 containing the dimension names (defined previously with
771 <a href="#<a href="#Dataset.createDimension">Dataset.createDimension</a>"><a href="#Dataset.createDimension">Dataset.createDimension</a></a>). To create a scalar
744 <code><a href="#Dataset.createDimension">Dataset.createDimension</a></code>). To create a scalar
772745 variable, simply leave out the dimensions keyword. The variable
773746 primitive datatypes correspond to the dtype attribute of a numpy array.
774747 You can specify the datatype as a numpy dtype object, or anything that
786759 can only be used if the file format is <code>NETCDF4</code>.</p>
787760
788761 <p>The dimensions themselves are usually also defined as variables, called
789 coordinate variables. The <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a>
790 method returns an instance of the <a href="#Variable">Variable</a> class whose methods can be
762 coordinate variables. The <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code>
763 method returns an instance of the <code><a href="#Variable">Variable</a></code> class whose methods can be
791764 used later to access and set variable data and attributes.</p>
792765
793766 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">times</span> <span class="o">=</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s2">&quot;time&quot;</span><span class="p">,</span><span class="s2">&quot;f8&quot;</span><span class="p">,(</span><span class="s2">&quot;time&quot;</span><span class="p">,))</span>
799772 <span class="o">&gt;&gt;&gt;</span> <span class="n">temp</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s2">&quot;K&quot;</span>
800773 </code></pre></div>
801774
802 <p>To get summary info on a <a href="#Variable">Variable</a> instance in an interactive session,
775 <p>To get summary info on a <code><a href="#Variable">Variable</a></code> instance in an interactive session,
803776 just print it.</p>
804777
805778 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">temp</span><span class="p">)</span>
818791
819792 <p>If the intermediate groups do not yet exist, they will be created.</p>
820793
821 <p>You can also query a <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> instance directly to obtain <a href="#Group">Group</a> or
822 <a href="#Variable">Variable</a> instances using paths.</p>
794 <p>You can also query a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance directly to obtain <code><a href="#Group">Group</a></code> or
795 <code><a href="#Variable">Variable</a></code> instances using paths.</p>
823796
824797 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">rootgrp</span><span class="p">[</span><span class="s2">&quot;/forecasts/model1&quot;</span><span class="p">])</span> <span class="c1"># a Group instance</span>
825798 <span class="o">&lt;</span><span class="k">class</span> <span class="err">&#39;</span><span class="nc">netCDF4</span><span class="o">.</span><span class="n">_netCDF4</span><span class="o">.</span><span class="n">Group</span><span class="s1">&#39;&gt;</span>
836809 <span class="n">filling</span> <span class="n">on</span><span class="p">,</span> <span class="n">default</span> <span class="n">_FillValue</span> <span class="n">of</span> <span class="mf">9.969209968386869e+36</span> <span class="n">used</span>
837810 </code></pre></div>
838811
839 <p>All of the variables in the <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> are stored in a
812 <p>All of the variables in the <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> are stored in a
840813 Python dictionary, in the same way as the dimensions:</p>
841814
842815 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">rootgrp</span><span class="o">.</span><span class="n">variables</span><span class="p">)</span>
864837 <span class="n">filling</span> <span class="n">on</span><span class="p">,</span> <span class="n">default</span> <span class="n">_FillValue</span> <span class="n">of</span> <span class="mf">9.969209968386869e+36</span> <span class="n">used</span><span class="p">}</span>
865838 </code></pre></div>
866839
867 <p><a href="#Variable">Variable</a> names can be changed using the
868 <a href="#<a href="#Dataset.renameVariable">Dataset.renameVariable</a>"><a href="#Dataset.renameVariable">Dataset.renameVariable</a></a> method of a <a href="#Dataset">Dataset</a>
840 <p><code><a href="#Variable">Variable</a></code> names can be changed using the
841 <code><a href="#Dataset.renameVariable">Dataset.renameVariable</a></code> method of a <code><a href="#Dataset">Dataset</a></code>
869842 instance.</p>
870843
871844 <p>Variables can be sliced similar to numpy arrays, but there are some differences. See
875848
876849 <p>There are two types of attributes in a netCDF file, global and variable.
877850 Global attributes provide information about a group, or the entire
878 dataset, as a whole. <a href="#Variable">Variable</a> attributes provide information about
851 dataset, as a whole. <code><a href="#Variable">Variable</a></code> attributes provide information about
879852 one of the variables in a group. Global attributes are set by assigning
880 values to <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> instance variables. <a href="#Variable">Variable</a>
881 attributes are set by assigning values to <a href="#Variable">Variable</a> instances
853 values to <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance variables. <code><a href="#Variable">Variable</a></code>
854 attributes are set by assigning values to <code><a href="#Variable">Variable</a></code> instances
882855 variables. Attributes can be strings, numbers or sequences. Returning to
883856 our example,</p>
884857
894867 <span class="o">&gt;&gt;&gt;</span> <span class="n">times</span><span class="o">.</span><span class="n">calendar</span> <span class="o">=</span> <span class="s2">&quot;gregorian&quot;</span>
895868 </code></pre></div>
896869
897 <p>The <a href="#<a href="#Dataset.ncattrs">Dataset.ncattrs</a>"><a href="#Dataset.ncattrs">Dataset.ncattrs</a></a> method of a <a href="#Dataset">Dataset</a>, <a href="#Group">Group</a> or
898 <a href="#Variable">Variable</a> instance can be used to retrieve the names of all the netCDF
870 <p>The <code><a href="#Dataset.ncattrs">Dataset.ncattrs</a></code> method of a <code><a href="#Dataset">Dataset</a></code>, <code><a href="#Group">Group</a></code> or
871 <code><a href="#Variable">Variable</a></code> instance can be used to retrieve the names of all the netCDF
899872 attributes. This method is provided as a convenience, since using the
900873 built-in <code>dir</code> Python function will return a bunch of private methods
901874 and attributes that cannot (or should not) be modified by the user.</p>
907880 <span class="n">Global</span> <span class="n">attr</span> <span class="n">source</span> <span class="o">=</span> <span class="n">netCDF4</span> <span class="n">python</span> <span class="n">module</span> <span class="n">tutorial</span>
908881 </code></pre></div>
909882
910 <p>The <code>__dict__</code> attribute of a <a href="#Dataset">Dataset</a>, <a href="#Group">Group</a> or <a href="#Variable">Variable</a>
883 <p>The <code>__dict__</code> attribute of a <code><a href="#Dataset">Dataset</a></code>, <code><a href="#Group">Group</a></code> or <code><a href="#Variable">Variable</a></code>
911884 instance provides all the netCDF attribute name/value pairs in a python
912885 dictionary:</p>
913886
915888 <span class="p">{</span><span class="s1">&#39;description&#39;</span><span class="p">:</span> <span class="s1">&#39;bogus example script&#39;</span><span class="p">,</span> <span class="s1">&#39;history&#39;</span><span class="p">:</span> <span class="s1">&#39;Created Mon Jul 8 14:19:41 2019&#39;</span><span class="p">,</span> <span class="s1">&#39;source&#39;</span><span class="p">:</span> <span class="s1">&#39;netCDF4 python module tutorial&#39;</span><span class="p">}</span>
916889 </code></pre></div>
917890
918 <p>Attributes can be deleted from a netCDF <a href="#Dataset">Dataset</a>, <a href="#Group">Group</a> or
919 <a href="#Variable">Variable</a> using the python <code>del</code> statement (i.e. <code>del grp.foo</code>
891 <p>Attributes can be deleted from a netCDF <code><a href="#Dataset">Dataset</a></code>, <code><a href="#Group">Group</a></code> or
892 <code><a href="#Variable">Variable</a></code> using the python <code>del</code> statement (i.e. <code>del grp.foo</code>
920893 removes the attribute <code>foo</code> the the group <code>grp</code>).</p>
921894
922895 <h2 id="writing-data-to-and-retrieving-data-from-a-netcdf-variable">Writing data to and retrieving data from a netCDF variable</h2>
923896
924 <p>Now that you have a netCDF <a href="#Variable">Variable</a> instance, how do you put data
897 <p>Now that you have a netCDF <code><a href="#Variable">Variable</a></code> instance, how do you put data
925898 into it? You can just treat it like an array and assign data to a slice.</p>
926899
927 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">numpy</span>
928 <span class="o">&gt;&gt;&gt;</span> <span class="n">lats</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="o">-</span><span class="mi">90</span><span class="p">,</span><span class="mi">91</span><span class="p">,</span><span class="mf">2.5</span><span class="p">)</span>
929 <span class="o">&gt;&gt;&gt;</span> <span class="n">lons</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="o">-</span><span class="mi">180</span><span class="p">,</span><span class="mi">180</span><span class="p">,</span><span class="mf">2.5</span><span class="p">)</span>
900 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
901 <span class="o">&gt;&gt;&gt;</span> <span class="n">lats</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="o">-</span><span class="mi">90</span><span class="p">,</span><span class="mi">91</span><span class="p">,</span><span class="mf">2.5</span><span class="p">)</span>
902 <span class="o">&gt;&gt;&gt;</span> <span class="n">lons</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="o">-</span><span class="mi">180</span><span class="p">,</span><span class="mi">180</span><span class="p">,</span><span class="mf">2.5</span><span class="p">)</span>
930903 <span class="o">&gt;&gt;&gt;</span> <span class="n">latitudes</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">lats</span>
931904 <span class="o">&gt;&gt;&gt;</span> <span class="n">longitudes</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">lons</span>
932905 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;latitudes =</span><span class="se">\n</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">latitudes</span><span class="p">[:]))</span>
940913 <span class="mf">90.</span> <span class="p">]</span>
941914 </code></pre></div>
942915
943 <p>Unlike NumPy's array objects, netCDF <a href="#Variable">Variable</a>
916 <p>Unlike NumPy's array objects, netCDF <code><a href="#Variable">Variable</a></code>
944917 objects with unlimited dimensions will grow along those dimensions if you
945918 assign data outside the currently defined range of indices.</p>
946919
1011984 The result will be a numpy scalar array.</p>
1012985
1013986 <p>By default, netcdf4-python returns numpy masked arrays with values equal to the
1014 <code>missing_value</code> or <code>_FillValue</code> variable attributes masked. The
1015 <a href="#<a href="#Dataset.set_auto_mask">Dataset.set_auto_mask</a>"><a href="#Dataset.set_auto_mask">Dataset.set_auto_mask</a></a> <a href="#Dataset">Dataset</a> and <a href="#Variable">Variable</a> methods
987 <code>missing_value</code> or <code>_FillValue</code> variable attributes masked for primitive and
988 enum data types.
989 The <code><a href="#Dataset.set_auto_mask">Dataset.set_auto_mask</a></code> <code><a href="#Dataset">Dataset</a></code> and <code><a href="#Variable">Variable</a></code> methods
1016990 can be used to disable this feature so that
1017991 numpy arrays are always returned, with the missing values included. Prior to
1018992 version 1.4.0 the default behavior was to only return masked arrays when the
1019993 requested slice contained missing values. This behavior can be recovered
1020 using the <a href="#<a href="#Dataset.set_always_mask">Dataset.set_always_mask</a>"><a href="#Dataset.set_always_mask">Dataset.set_always_mask</a></a> method. If a masked array is
994 using the <code><a href="#Dataset.set_always_mask">Dataset.set_always_mask</a></code> method. If a masked array is
1021995 written to a netCDF variable, the masked elements are filled with the
1022996 value specified by the <code>missing_value</code> attribute. If the variable has
1023997 no <code>missing_value</code>, the <code>_FillValue</code> is used instead.</p>
10441018 <span class="p">[</span><span class="mf">17533104.</span> <span class="mf">17533116.</span> <span class="mf">17533128.</span> <span class="mf">17533140.</span> <span class="mf">17533152.</span><span class="p">]</span>
10451019 <span class="o">&gt;&gt;&gt;</span> <span class="n">dates</span> <span class="o">=</span> <span class="n">num2date</span><span class="p">(</span><span class="n">times</span><span class="p">[:],</span><span class="n">units</span><span class="o">=</span><span class="n">times</span><span class="o">.</span><span class="n">units</span><span class="p">,</span><span class="n">calendar</span><span class="o">=</span><span class="n">times</span><span class="o">.</span><span class="n">calendar</span><span class="p">)</span>
10461020 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;dates corresponding to time values:</span><span class="se">\n</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">dates</span><span class="p">))</span>
1047 <span class="n">dates</span> <span class="n">corresponding</span> <span class="n">to</span> <span class="n">time</span> <span class="n">values</span><span class="p">:</span>
1048 <span class="p">[</span><span class="n">real_datetime</span><span class="p">(</span><span class="mi">2001</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="n">real_datetime</span><span class="p">(</span><span class="mi">2001</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
1049 <span class="n">real_datetime</span><span class="p">(</span><span class="mi">2001</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="n">real_datetime</span><span class="p">(</span><span class="mi">2001</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
1050 <span class="n">real_datetime</span><span class="p">(</span><span class="mi">2001</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)]</span>
1051 </code></pre></div>
1052
1053 <p><code>num2date</code> converts numeric values of time in the specified <code>units</code>
1054 and <code>calendar</code> to datetime objects, and <code>date2num</code> does the reverse.
1021 <span class="p">[</span><span class="n">cftime</span><span class="o">.</span><span class="n">DatetimeGregorian</span><span class="p">(</span><span class="mi">2001</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">has_year_zero</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
1022 <span class="n">cftime</span><span class="o">.</span><span class="n">DatetimeGregorian</span><span class="p">(</span><span class="mi">2001</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">has_year_zero</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
1023 <span class="n">cftime</span><span class="o">.</span><span class="n">DatetimeGregorian</span><span class="p">(</span><span class="mi">2001</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">has_year_zero</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
1024 <span class="n">cftime</span><span class="o">.</span><span class="n">DatetimeGregorian</span><span class="p">(</span><span class="mi">2001</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">has_year_zero</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
1025 <span class="n">cftime</span><span class="o">.</span><span class="n">DatetimeGregorian</span><span class="p">(</span><span class="mi">2001</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">has_year_zero</span><span class="o">=</span><span class="kc">False</span><span class="p">)]</span>
1026 </code></pre></div>
1027
1028 <p><code><a href="#num2date">num2date</a></code> converts numeric values of time in the specified <code>units</code>
1029 and <code>calendar</code> to datetime objects, and <code><a href="#date2num">date2num</a></code> does the reverse.
10551030 All the calendars currently defined in the
10561031 <a href="http://cfconventions.org">CF metadata convention</a> are supported.
1057 A function called <code>date2index</code> is also provided which returns the indices
1032 A function called <code><a href="#date2index">date2index</a></code> is also provided which returns the indices
10581033 of a netCDF time variable corresponding to a sequence of datetime instances.</p>
10591034
10601035 <h2 id="reading-data-from-a-multi-file-netcdf-dataset">Reading data from a multi-file netCDF dataset</h2>
10611036
10621037 <p>If you want to read data from a variable that spans multiple netCDF files,
1063 you can use the <a href="#MFDataset">MFDataset</a> class to read the data as if it were
1038 you can use the <code><a href="#MFDataset">MFDataset</a></code> class to read the data as if it were
10641039 contained in a single file. Instead of using a single filename to create
1065 a <a href="#Dataset">Dataset</a> instance, create a <a href="#MFDataset">MFDataset</a> instance with either a list
1040 a <code><a href="#Dataset">Dataset</a></code> instance, create a <code><a href="#MFDataset">MFDataset</a></code> instance with either a list
10661041 of filenames, or a string with a wildcard (which is then converted to
10671042 a sorted list of files using the python glob module).
10681043 Variables in the list of files that share the same unlimited
10771052 <span class="o">...</span> <span class="k">with</span> <span class="n">Dataset</span><span class="p">(</span><span class="s2">&quot;mftest</span><span class="si">%s</span><span class="s2">.nc&quot;</span> <span class="o">%</span> <span class="n">nf</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s2">&quot;NETCDF4_CLASSIC&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
10781053 <span class="o">...</span> <span class="n">_</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
10791054 <span class="o">...</span> <span class="n">x</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span><span class="s2">&quot;i&quot;</span><span class="p">,(</span><span class="s2">&quot;x&quot;</span><span class="p">,))</span>
1080 <span class="o">...</span> <span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">nf</span><span class="o">*</span><span class="mi">10</span><span class="p">,</span><span class="mi">10</span><span class="o">*</span><span class="p">(</span><span class="n">nf</span><span class="o">+</span><span class="mi">1</span><span class="p">))</span>
1081 </code></pre></div>
1082
1083 <p>Now read all the files back in at once with <a href="#MFDataset">MFDataset</a></p>
1055 <span class="o">...</span> <span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">nf</span><span class="o">*</span><span class="mi">10</span><span class="p">,</span><span class="mi">10</span><span class="o">*</span><span class="p">(</span><span class="n">nf</span><span class="o">+</span><span class="mi">1</span><span class="p">))</span>
1056 </code></pre></div>
1057
1058 <p>Now read all the files back in at once with <code><a href="#MFDataset">MFDataset</a></code></p>
10841059
10851060 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">from</span> <span class="nn">netCDF4</span> <span class="kn">import</span> <span class="n">MFDataset</span>
10861061 <span class="o">&gt;&gt;&gt;</span> <span class="n">f</span> <span class="o">=</span> <span class="n">MFDataset</span><span class="p">(</span><span class="s2">&quot;mftest*nc&quot;</span><span class="p">)</span>
10921067 <span class="mi">96</span> <span class="mi">97</span> <span class="mi">98</span> <span class="mi">99</span><span class="p">]</span>
10931068 </code></pre></div>
10941069
1095 <p>Note that <a href="#MFDataset">MFDataset</a> can only be used to read, not write, multi-file
1070 <p>Note that <code><a href="#MFDataset">MFDataset</a></code> can only be used to read, not write, multi-file
10961071 datasets.</p>
10971072
10981073 <h2 id="efficient-compression-of-netcdf-variables">Efficient compression of netCDF variables</h2>
10991074
1100 <p>Data stored in netCDF 4 <a href="#Variable">Variable</a> objects can be compressed and
1075 <p>Data stored in netCDF 4 <code><a href="#Variable">Variable</a></code> objects can be compressed and
11011076 decompressed on the fly. The parameters for the compression are
11021077 determined by the <code>zlib</code>, <code>complevel</code> and <code>shuffle</code> keyword arguments
1103 to the <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a> method. To turn on
1078 to the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method. To turn on
11041079 compression, set <code>zlib=True</code>. The <code>complevel</code> keyword regulates the
11051080 speed and efficiency of the compression (1 being fastest, but lowest
11061081 compression ratio, 9 being slowest but best compression ratio). The
11091084 compression by reordering the bytes. The shuffle filter can
11101085 significantly improve compression ratios, and is on by default. Setting
11111086 <code>fletcher32</code> keyword argument to
1112 <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a> to <code>True</code> (it's <code>False</code> by
1087 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> to <code>True</code> (it's <code>False</code> by
11131088 default) enables the Fletcher32 checksum algorithm for error detection.
11141089 It's also possible to set the HDF5 chunking parameters and endian-ness
11151090 of the binary data stored in the HDF5 file with the <code>chunksizes</code>
11161091 and <code>endian</code> keyword arguments to
1117 <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a>. These keyword arguments only
1092 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code>. These keyword arguments only
11181093 are relevant for <code>NETCDF4</code> and <code>NETCDF4_CLASSIC</code> files (where the
11191094 underlying file format is HDF5) and are silently ignored if the file
11201095 format is <code>NETCDF3_CLASSIC</code>, <code>NETCDF3_64BIT_OFFSET</code> or <code>NETCDF3_64BIT_DATA</code>.</p>
11231098 example, it is temperature data that was measured with a precision of
11241099 0.1 degrees), you can dramatically improve zlib compression by
11251100 quantizing (or truncating) the data using the <code>least_significant_digit</code>
1126 keyword argument to <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a>. The least
1101 keyword argument to <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code>. The least
11271102 significant digit is the power of ten of the smallest decimal place in
11281103 the data that is a reliable value. For example if the data has a
11291104 precision of 0.1, then setting <code>least_significant_digit=1</code> will cause
11351110
11361111 <p>In our example, try replacing the line</p>
11371112
1138 <pre><code>```python
1139 &gt;&gt;&gt; temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",))
1140 </code></pre>
1113 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">temp</span> <span class="o">=</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s2">&quot;temp&quot;</span><span class="p">,</span><span class="s2">&quot;f4&quot;</span><span class="p">,(</span><span class="s2">&quot;time&quot;</span><span class="p">,</span><span class="s2">&quot;level&quot;</span><span class="p">,</span><span class="s2">&quot;lat&quot;</span><span class="p">,</span><span class="s2">&quot;lon&quot;</span><span class="p">,))</span>
1114 </code></pre></div>
11411115
11421116 <p>with</p>
11431117
11631137 information for a point by reading one variable, instead of reading
11641138 different parameters from different variables. Compound data types
11651139 are created from the corresponding numpy data type using the
1166 <a href="#<a href="#Dataset.createCompoundType">Dataset.createCompoundType</a>"><a href="#Dataset.createCompoundType">Dataset.createCompoundType</a></a> method of a <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> instance.
1140 <code><a href="#Dataset.createCompoundType">Dataset.createCompoundType</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance.
11671141 Since there is no native complex data type in netcdf, compound types are handy
11681142 for storing numpy complex arrays. Here's an example:</p>
11691143
11701144 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">f</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="s2">&quot;complex.nc&quot;</span><span class="p">,</span><span class="s2">&quot;w&quot;</span><span class="p">)</span>
11711145 <span class="o">&gt;&gt;&gt;</span> <span class="n">size</span> <span class="o">=</span> <span class="mi">3</span> <span class="c1"># length of 1-d complex array</span>
11721146 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># create sample complex data.</span>
1173 <span class="o">&gt;&gt;&gt;</span> <span class="n">datac</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="mi">1</span><span class="n">j</span><span class="o">*</span><span class="p">(</span><span class="mf">1.</span><span class="o">+</span><span class="n">numpy</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">numpy</span><span class="o">.</span><span class="n">pi</span><span class="p">,</span> <span class="n">size</span><span class="p">)))</span>
1147 <span class="o">&gt;&gt;&gt;</span> <span class="n">datac</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="mi">1</span><span class="n">j</span><span class="o">*</span><span class="p">(</span><span class="mf">1.</span><span class="o">+</span><span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">,</span> <span class="n">size</span><span class="p">)))</span>
11741148 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># create complex128 compound data type.</span>
1175 <span class="o">&gt;&gt;&gt;</span> <span class="n">complex128</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">dtype</span><span class="p">([(</span><span class="s2">&quot;real&quot;</span><span class="p">,</span><span class="n">numpy</span><span class="o">.</span><span class="n">float_64</span><span class="p">),(</span><span class="s2">&quot;imag&quot;</span><span class="p">,</span><span class="n">numpy</span><span class="o">.</span><span class="n">float_64</span><span class="p">)])</span>
1149 <span class="o">&gt;&gt;&gt;</span> <span class="n">complex128</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">([(</span><span class="s2">&quot;real&quot;</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">),(</span><span class="s2">&quot;imag&quot;</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">)])</span>
11761150 <span class="o">&gt;&gt;&gt;</span> <span class="n">complex128_t</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">createCompoundType</span><span class="p">(</span><span class="n">complex128</span><span class="p">,</span><span class="s2">&quot;complex128&quot;</span><span class="p">)</span>
11771151 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># create a variable with this data type, write some data to it.</span>
11781152 <span class="o">&gt;&gt;&gt;</span> <span class="n">x_dim</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s2">&quot;x_dim&quot;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
11791153 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s2">&quot;cmplx_var&quot;</span><span class="p">,</span><span class="n">complex128_t</span><span class="p">,</span><span class="s2">&quot;x_dim&quot;</span><span class="p">)</span>
1180 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="n">size</span><span class="p">,</span><span class="n">complex128</span><span class="p">)</span> <span class="c1"># numpy structured array</span>
1154 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="n">size</span><span class="p">,</span><span class="n">complex128</span><span class="p">)</span> <span class="c1"># numpy structured array</span>
11811155 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;real&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">datac</span><span class="o">.</span><span class="n">real</span><span class="p">;</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;imag&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">datac</span><span class="o">.</span><span class="n">imag</span>
11821156 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">data</span> <span class="c1"># write numpy structured array to netcdf compound var</span>
11831157 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># close and reopen the file, check the contents.</span>
11851159 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s2">&quot;cmplx_var&quot;</span><span class="p">]</span>
11861160 <span class="o">&gt;&gt;&gt;</span> <span class="n">datain</span> <span class="o">=</span> <span class="n">v</span><span class="p">[:]</span> <span class="c1"># read in all the data into a numpy structured array</span>
11871161 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># create an empty numpy complex array</span>
1188 <span class="o">&gt;&gt;&gt;</span> <span class="n">datac2</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="n">datain</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span><span class="n">numpy</span><span class="o">.</span><span class="n">complex128</span><span class="p">)</span>
1162 <span class="o">&gt;&gt;&gt;</span> <span class="n">datac2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="n">datain</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">complex128</span><span class="p">)</span>
11891163 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># .. fill it with contents of structured array.</span>
11901164 <span class="o">&gt;&gt;&gt;</span> <span class="n">datac2</span><span class="o">.</span><span class="n">real</span> <span class="o">=</span> <span class="n">datain</span><span class="p">[</span><span class="s2">&quot;real&quot;</span><span class="p">];</span> <span class="n">datac2</span><span class="o">.</span><span class="n">imag</span> <span class="o">=</span> <span class="n">datain</span><span class="p">[</span><span class="s2">&quot;imag&quot;</span><span class="p">]</span>
11911165 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{}</span><span class="s1">: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">datac</span><span class="o">.</span><span class="n">dtype</span><span class="p">,</span> <span class="n">datac</span><span class="p">))</span> <span class="c1"># original data</span>
11991173 ones first. All possible numpy structured arrays cannot be
12001174 represented as Compound variables - an error message will be
12011175 raise if you try to create one that is not supported.
1202 All of the compound types defined for a <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> are stored
1176 All of the compound types defined for a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> are stored
12031177 in a Python dictionary, just like variables and dimensions. As always, printing
12041178 objects gives useful summary information in an interactive session:</p>
12051179
12251199
12261200 <p>NetCDF 4 has support for variable-length or "ragged" arrays. These are arrays
12271201 of variable length sequences having the same type. To create a variable-length
1228 data type, use the <a href="#<a href="#Dataset.createVLType">Dataset.createVLType</a>"><a href="#Dataset.createVLType">Dataset.createVLType</a></a> method
1229 method of a <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> instance.</p>
1202 data type, use the <code><a href="#Dataset.createVLType">Dataset.createVLType</a></code> method
1203 method of a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance.</p>
12301204
12311205 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">f</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="s2">&quot;tst_vlen.nc&quot;</span><span class="p">,</span><span class="s2">&quot;w&quot;</span><span class="p">)</span>
1232 <span class="o">&gt;&gt;&gt;</span> <span class="n">vlen_t</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">createVLType</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">int32</span><span class="p">,</span> <span class="s2">&quot;phony_vlen&quot;</span><span class="p">)</span>
1206 <span class="o">&gt;&gt;&gt;</span> <span class="n">vlen_t</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">createVLType</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">,</span> <span class="s2">&quot;phony_vlen&quot;</span><span class="p">)</span>
12331207 </code></pre></div>
12341208
12351209 <p>The numpy datatype of the variable-length sequences and the name of the
12531227
12541228 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">random</span>
12551229 <span class="o">&gt;&gt;&gt;</span> <span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">54321</span><span class="p">)</span>
1256 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">),</span><span class="nb">object</span><span class="p">)</span>
1230 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">),</span><span class="nb">object</span><span class="p">)</span>
12571231 <span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)):</span>
1258 <span class="o">...</span> <span class="n">data</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">10</span><span class="p">),</span><span class="n">dtype</span><span class="o">=</span><span class="s2">&quot;int32&quot;</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span>
1259 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">data</span><span class="p">,(</span><span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)))</span>
1232 <span class="o">...</span> <span class="n">data</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">10</span><span class="p">),</span><span class="n">dtype</span><span class="o">=</span><span class="s2">&quot;int32&quot;</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span>
1233 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">data</span><span class="p">,(</span><span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)))</span>
12601234 <span class="o">&gt;&gt;&gt;</span> <span class="n">vlvar</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">data</span>
12611235 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;vlen variable =</span><span class="se">\n</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">vlvar</span><span class="p">[:]))</span>
12621236 <span class="n">vlen</span> <span class="n">variable</span> <span class="o">=</span>
12891263 variables, For vlen strings, you don't need to create a vlen data type.
12901264 Instead, simply use the python <code>str</code> builtin (or a numpy string datatype
12911265 with fixed length greater than 1) when calling the
1292 <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a> method.</p>
1266 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method.</p>
12931267
12941268 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">z</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">,</span><span class="mi">10</span><span class="p">)</span>
12951269 <span class="o">&gt;&gt;&gt;</span> <span class="n">strvar</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s2">&quot;strvar&quot;</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">)</span>
13001274 array is assigned to the vlen string variable.</p>
13011275
13021276 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">chars</span> <span class="o">=</span> <span class="s2">&quot;1234567890aabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;</span>
1303 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="s2">&quot;O&quot;</span><span class="p">)</span>
1277 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="s2">&quot;O&quot;</span><span class="p">)</span>
13041278 <span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>
13051279 <span class="o">...</span> <span class="n">stringlen</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">12</span><span class="p">)</span>
13061280 <span class="o">...</span> <span class="n">data</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">random</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">chars</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">stringlen</span><span class="p">)])</span>
13361310 <p>Here's an example of using an Enum type to hold cloud type data.
13371311 The base integer data type and a python dictionary describing the allowed
13381312 values and their names are used to define an Enum data type using
1339 <a href="#<a href="#Dataset.createEnumType">Dataset.createEnumType</a>"><a href="#Dataset.createEnumType">Dataset.createEnumType</a></a>.</p>
1313 <code><a href="#Dataset.createEnumType">Dataset.createEnumType</a></code>.</p>
13401314
13411315 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">nc</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="s1">&#39;clouds.nc&#39;</span><span class="p">,</span><span class="s1">&#39;w&#39;</span><span class="p">)</span>
13421316 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># python dict with allowed values and their names.</span>
13451319 <span class="o">...</span> <span class="s1">&#39;Nimbostratus&#39;</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span> <span class="s1">&#39;Cumulus&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="s1">&#39;Altostratus&#39;</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span>
13461320 <span class="o">...</span> <span class="s1">&#39;Cumulonimbus&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;Stratocumulus&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">}</span>
13471321 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># create the Enum type called &#39;cloud_t&#39;.</span>
1348 <span class="o">&gt;&gt;&gt;</span> <span class="n">cloud_type</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createEnumType</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">uint8</span><span class="p">,</span><span class="s1">&#39;cloud_t&#39;</span><span class="p">,</span><span class="n">enum_dict</span><span class="p">)</span>
1322 <span class="o">&gt;&gt;&gt;</span> <span class="n">cloud_type</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createEnumType</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">,</span><span class="s1">&#39;cloud_t&#39;</span><span class="p">,</span><span class="n">enum_dict</span><span class="p">)</span>
13491323 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">cloud_type</span><span class="p">)</span>
13501324 <span class="o">&lt;</span><span class="k">class</span> <span class="err">&#39;</span><span class="nc">netCDF4</span><span class="o">.</span><span class="n">_netCDF4</span><span class="o">.</span><span class="n">EnumType</span><span class="s1">&#39;&gt;: name = &#39;</span><span class="n">cloud_t</span><span class="s1">&#39;, numpy dtype = uint8, fields/values ={&#39;</span><span class="n">Altocumulus</span><span class="s1">&#39;: 7, &#39;</span><span class="n">Missing</span><span class="s1">&#39;: 255, &#39;</span><span class="n">Stratus</span><span class="s1">&#39;: 2, &#39;</span><span class="n">Clear</span><span class="s1">&#39;: 0, &#39;</span><span class="n">Nimbostratus</span><span class="s1">&#39;: 6, &#39;</span><span class="n">Cumulus</span><span class="s1">&#39;: 4, &#39;</span><span class="n">Altostratus</span><span class="s1">&#39;: 5, &#39;</span><span class="n">Cumulonimbus</span><span class="s1">&#39;: 1, &#39;</span><span class="n">Stratocumulus</span><span class="s1">&#39;: 3}</span>
13511325 </code></pre></div>
14141388 written to a different variable index on each task</p>
14151389
14161390 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">d</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;dim&#39;</span><span class="p">,</span><span class="mi">4</span><span class="p">)</span>
1417 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;var&#39;</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">,</span> <span class="s1">&#39;dim&#39;</span><span class="p">)</span>
1391 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;var&#39;</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">int64</span><span class="p">,</span> <span class="s1">&#39;dim&#39;</span><span class="p">)</span>
14181392 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span><span class="p">[</span><span class="n">rank</span><span class="p">]</span> <span class="o">=</span> <span class="n">rank</span>
14191393 <span class="o">&gt;&gt;&gt;</span> <span class="n">nc</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
14201394
14351409 depend on or be affected by other processes. Collective IO is a way of doing
14361410 IO defined in the MPI-IO standard; unlike independent IO, all processes must
14371411 participate in doing IO. To toggle back and forth between
1438 the two types of IO, use the <a href="#<a href="#Variable.set_collective">Variable.set_collective</a>"><a href="#Variable.set_collective">Variable.set_collective</a></a>
1439 <a href="#Variable">Variable</a> method. All metadata
1412 the two types of IO, use the <code><a href="#Variable.set_collective">Variable.set_collective</a></code>
1413 <code><a href="#Variable">Variable</a></code> method. All metadata
14401414 operations (such as creation of groups, types, variables, dimensions, or attributes)
14411415 are collective. There are a couple of important limitations of parallel IO:</p>
14421416
14491423 If the write is done in independent mode, the operation will fail with a
14501424 a generic "HDF Error".</li>
14511425 <li>You can write compressed data in parallel only with netcdf-c &gt;= 4.7.4
1452 and hdf5 &gt;= 1.10.3 (although you can read in parallel with earlier versions).</li>
1426 and hdf5 &gt;= 1.10.3 (although you can read in parallel with earlier versions). To write
1427 compressed data in parallel, the variable must be in 'collective IO mode'. This is done
1428 automatically on variable creation if compression is turned on, but if you are appending
1429 to a variable in an existing file, you must use <code><a href="#Variable.set_collective">Variable.set_collective</a>(True)</code> before attempting
1430 to write to it.</li>
14531431 <li>You cannot use variable-length (VLEN) data types.</li>
14541432 </ul>
14551433
14661444 To perform the conversion to and from character arrays to fixed-width numpy string arrays, the
14671445 following convention is followed by the python interface.
14681446 If the <code>_Encoding</code> special attribute is set for a character array
1469 (dtype <code>S1</code>) variable, the <a href="#chartostring">chartostring</a> utility function is used to convert the array of
1447 (dtype <code>S1</code>) variable, the <code><a href="#chartostring">chartostring</a></code> utility function is used to convert the array of
14701448 characters to an array of strings with one less dimension (the last dimension is
14711449 interpreted as the length of each string) when reading the data. The character
14721450 set (usually ascii) is specified by the <code>_Encoding</code> attribute. If <code>_Encoding</code>
14731451 is 'none' or 'bytes', then the character array is converted to a numpy
14741452 fixed-width byte string array (dtype <code>S#</code>), otherwise a numpy unicode (dtype
14751453 <code>U#</code>) array is created. When writing the data,
1476 <a href="#stringtochar">stringtochar</a> is used to convert the numpy string array to an array of
1454 <code><a href="#stringtochar">stringtochar</a></code> is used to convert the numpy string array to an array of
14771455 characters with one more dimension. For example,</p>
14781456
14791457 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">from</span> <span class="nn">netCDF4</span> <span class="kn">import</span> <span class="n">stringtochar</span>
14811459 <span class="o">&gt;&gt;&gt;</span> <span class="n">_</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;nchars&#39;</span><span class="p">,</span><span class="mi">3</span><span class="p">)</span>
14821460 <span class="o">&gt;&gt;&gt;</span> <span class="n">_</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;nstrings&#39;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
14831461 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;strings&#39;</span><span class="p">,</span><span class="s1">&#39;S1&#39;</span><span class="p">,(</span><span class="s1">&#39;nstrings&#39;</span><span class="p">,</span><span class="s1">&#39;nchars&#39;</span><span class="p">))</span>
1484 <span class="o">&gt;&gt;&gt;</span> <span class="n">datain</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span><span class="s1">&#39;bar&#39;</span><span class="p">],</span><span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;S3&#39;</span><span class="p">)</span>
1462 <span class="o">&gt;&gt;&gt;</span> <span class="n">datain</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span><span class="s1">&#39;bar&#39;</span><span class="p">],</span><span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;S3&#39;</span><span class="p">)</span>
14851463 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">stringtochar</span><span class="p">(</span><span class="n">datain</span><span class="p">)</span> <span class="c1"># manual conversion to char array</span>
14861464 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">v</span><span class="p">[:])</span> <span class="c1"># data returned as char array</span>
14871465 <span class="p">[[</span><span class="sa">b</span><span class="s1">&#39;f&#39;</span> <span class="sa">b</span><span class="s1">&#39;o&#39;</span> <span class="sa">b</span><span class="s1">&#39;o&#39;</span><span class="p">]</span>
14951473
14961474 <p>Even if the <code>_Encoding</code> attribute is set, the automatic conversion of char
14971475 arrays to/from string arrays can be disabled with
1498 <a href="#<a href="#Variable.set_auto_chartostring">Variable.set_auto_chartostring</a>"><a href="#Variable.set_auto_chartostring">Variable.set_auto_chartostring</a></a>.</p>
1476 <code><a href="#Variable.set_auto_chartostring">Variable.set_auto_chartostring</a></code>.</p>
14991477
15001478 <p>A similar situation is often encountered with numpy structured arrays with subdtypes
15011479 containing fixed-wdith byte strings (dtype=<code>S#</code>). Since there is no native fixed-length string
15101488 Here's an example:</p>
15111489
15121490 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">nc</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="s1">&#39;compoundstring_example.nc&#39;</span><span class="p">,</span><span class="s1">&#39;w&#39;</span><span class="p">)</span>
1513 <span class="o">&gt;&gt;&gt;</span> <span class="n">dtype</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">dtype</span><span class="p">([(</span><span class="s1">&#39;observation&#39;</span><span class="p">,</span> <span class="s1">&#39;f4&#39;</span><span class="p">),</span>
1491 <span class="o">&gt;&gt;&gt;</span> <span class="n">dtype</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">([(</span><span class="s1">&#39;observation&#39;</span><span class="p">,</span> <span class="s1">&#39;f4&#39;</span><span class="p">),</span>
15141492 <span class="o">...</span> <span class="p">(</span><span class="s1">&#39;station_name&#39;</span><span class="p">,</span><span class="s1">&#39;S10&#39;</span><span class="p">)])</span>
15151493 <span class="o">&gt;&gt;&gt;</span> <span class="n">station_data_t</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createCompoundType</span><span class="p">(</span><span class="n">dtype</span><span class="p">,</span><span class="s1">&#39;station_data&#39;</span><span class="p">)</span>
15161494 <span class="o">&gt;&gt;&gt;</span> <span class="n">_</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;station&#39;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
15171495 <span class="o">&gt;&gt;&gt;</span> <span class="n">statdat</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;station_obs&#39;</span><span class="p">,</span> <span class="n">station_data_t</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;station&#39;</span><span class="p">,))</span>
1518 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="n">dtype</span><span class="p">)</span>
1496 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="n">dtype</span><span class="p">)</span>
15191497 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;observation&#39;</span><span class="p">][:]</span> <span class="o">=</span> <span class="p">(</span><span class="mf">123.</span><span class="p">,</span><span class="mf">3.14</span><span class="p">)</span>
15201498 <span class="o">&gt;&gt;&gt;</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;station_name&#39;</span><span class="p">][:]</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;Boulder&#39;</span><span class="p">,</span><span class="s1">&#39;New York&#39;</span><span class="p">)</span>
15211499 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">statdat</span><span class="o">.</span><span class="n">dtype</span><span class="p">)</span> <span class="c1"># strings actually stored as character arrays</span>
15581536 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># and persist the file to disk when it is closed.</span>
15591537 <span class="o">&gt;&gt;&gt;</span> <span class="n">nc</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="s1">&#39;diskless_example.nc&#39;</span><span class="p">,</span><span class="s1">&#39;w&#39;</span><span class="p">,</span><span class="n">diskless</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span><span class="n">persist</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
15601538 <span class="o">&gt;&gt;&gt;</span> <span class="n">d</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
1561 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;v&#39;</span><span class="p">,</span><span class="n">numpy</span><span class="o">.</span><span class="n">int32</span><span class="p">,</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
1562 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
1539 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;v&#39;</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">,</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
1540 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
15631541 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">nc</span><span class="p">)</span>
15641542 <span class="o">&lt;</span><span class="k">class</span> <span class="err">&#39;</span><span class="nc">netCDF4</span><span class="o">.</span><span class="n">_netCDF4</span><span class="o">.</span><span class="n">Dataset</span><span class="s1">&#39;&gt;</span>
15651543 <span class="n">root</span> <span class="n">group</span> <span class="p">(</span><span class="n">NETCDF4</span> <span class="n">data</span> <span class="n">model</span><span class="p">,</span> <span class="n">file</span> <span class="nb">format</span> <span class="n">HDF5</span><span class="p">):</span>
15921570 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># (ignored for NETCDF4/HDF5 files).</span>
15931571 <span class="o">&gt;&gt;&gt;</span> <span class="n">nc</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="s1">&#39;inmemory.nc&#39;</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;w&#39;</span><span class="p">,</span><span class="n">memory</span><span class="o">=</span><span class="mi">1028</span><span class="p">)</span>
15941572 <span class="o">&gt;&gt;&gt;</span> <span class="n">d</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
1595 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;v&#39;</span><span class="p">,</span><span class="n">numpy</span><span class="o">.</span><span class="n">int32</span><span class="p">,</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
1596 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
1573 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;v&#39;</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">,</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
1574 <span class="o">&gt;&gt;&gt;</span> <span class="n">v</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
15971575 <span class="o">&gt;&gt;&gt;</span> <span class="n">nc_buf</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> <span class="c1"># close returns memoryview</span>
15981576 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">nc_buf</span><span class="p">))</span>
15991577 <span class="o">&lt;</span><span class="k">class</span> <span class="err">&#39;</span><span class="nc">memoryview</span><span class="s1">&#39;&gt;</span>
16161594 the parallel IO example, which is in <code>examples/mpi_example.py</code>.
16171595 Unit tests are in the <code>test</code> directory.</p>
16181596
1619 <p><strong>contact</strong>: Jeffrey Whitaker <a href="&#109;&#97;&#105;&#x6c;&#116;&#x6f;&#x3a;&#x6a;&#101;ff&#114;&#x65;&#121;&#x2e;&#x73;&#x2e;&#119;&#x68;&#105;&#116;&#x61;&#107;&#101;&#114;&#64;n&#x6f;&#x61;a.&#x67;&#111;v">&#x6a;&#101;ff&#114;&#x65;&#121;&#x2e;&#x73;&#x2e;&#119;&#x68;&#105;&#116;&#x61;&#107;&#101;&#114;&#64;n&#x6f;&#x61;a.&#x67;&#111;v</a></p>
1597 <p><strong>contact</strong>: Jeffrey Whitaker <a href="&#x6d;&#x61;&#105;&#x6c;&#116;&#111;&#58;&#106;&#101;&#x66;&#x66;&#114;&#x65;&#x79;&#x2e;&#115;&#46;&#x77;&#x68;&#x69;t&#x61;&#107;&#x65;&#x72;&#64;&#110;oa&#97;&#46;&#103;&#x6f;&#x76;">&#106;&#101;&#x66;&#x66;&#114;&#x65;&#x79;&#x2e;&#115;&#46;&#x77;&#x68;&#x69;t&#x61;&#107;&#x65;&#x72;&#64;&#110;oa&#97;&#46;&#103;&#x6f;&#x76;</a></p>
16201598
16211599 <p><strong>copyright</strong>: 2008 by Jeffrey Whitaker.</p>
16221600
16271605 <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>
16281606 </div>
16291607
1630
1608 <details>
1609 <summary>View Source</summary>
1610 <div class="codehilite"><pre><span></span><span class="c1"># init for netCDF4. package</span>
1611 <span class="c1"># Docstring comes from extension module _netCDF4.</span>
1612 <span class="kn">from</span> <span class="nn">._netCDF4</span> <span class="kn">import</span> <span class="o">*</span>
1613 <span class="c1"># Need explicit imports for names beginning with underscores</span>
1614 <span class="kn">from</span> <span class="nn">._netCDF4</span> <span class="kn">import</span> <span class="vm">__doc__</span>
1615 <span class="kn">from</span> <span class="nn">._netCDF4</span> <span class="kn">import</span> <span class="p">(</span><span class="n">__version__</span><span class="p">,</span> <span class="n">__netcdf4libversion__</span><span class="p">,</span> <span class="n">__hdf5libversion__</span><span class="p">,</span>
1616 <span class="n">__has_rename_grp__</span><span class="p">,</span> <span class="n">__has_nc_inq_path__</span><span class="p">,</span>
1617 <span class="n">__has_nc_inq_format_extended__</span><span class="p">,</span> <span class="n">__has_nc_open_mem__</span><span class="p">,</span>
1618 <span class="n">__has_nc_create_mem__</span><span class="p">,</span> <span class="n">__has_cdf5_format__</span><span class="p">,</span>
1619 <span class="n">__has_parallel4_support__</span><span class="p">,</span> <span class="n">__has_pnetcdf_support__</span><span class="p">)</span>
1620 <span class="n">__all__</span> <span class="o">=</span>\
1621 <span class="p">[</span><span class="s1">&#39;Dataset&#39;</span><span class="p">,</span><span class="s1">&#39;Variable&#39;</span><span class="p">,</span><span class="s1">&#39;Dimension&#39;</span><span class="p">,</span><span class="s1">&#39;Group&#39;</span><span class="p">,</span><span class="s1">&#39;MFDataset&#39;</span><span class="p">,</span><span class="s1">&#39;MFTime&#39;</span><span class="p">,</span><span class="s1">&#39;CompoundType&#39;</span><span class="p">,</span><span class="s1">&#39;VLType&#39;</span><span class="p">,</span><span class="s1">&#39;date2num&#39;</span><span class="p">,</span><span class="s1">&#39;num2date&#39;</span><span class="p">,</span><span class="s1">&#39;date2index&#39;</span><span class="p">,</span><span class="s1">&#39;stringtochar&#39;</span><span class="p">,</span><span class="s1">&#39;chartostring&#39;</span><span class="p">,</span><span class="s1">&#39;stringtoarr&#39;</span><span class="p">,</span><span class="s1">&#39;getlibversion&#39;</span><span class="p">,</span><span class="s1">&#39;EnumType&#39;</span><span class="p">,</span><span class="s1">&#39;get_chunk_cache&#39;</span><span class="p">,</span><span class="s1">&#39;set_chunk_cache&#39;</span><span class="p">]</span>
1622 </pre></div>
1623
1624 </details>
1625
16311626 </section>
16321627 <section id="Dataset">
16331628 <div class="attr class">
16391634 </div>
16401635
16411636
1642 <div class="docstring"><p>A netCDF <a href="#Dataset">Dataset</a> is a collection of dimensions, groups, variables and
1637 <div class="docstring"><p>A netCDF <code><a href="#Dataset">Dataset</a></code> is a collection of dimensions, groups, variables and
16431638 attributes. Together they describe the meaning of data and relations among
1644 data fields stored in a netCDF file. See <a href="#<a href="#Dataset.__init__">Dataset.__init__</a>"><a href="#Dataset.__init__">Dataset.__init__</a></a> for more
1639 data fields stored in a netCDF file. See <code><a href="#Dataset.__init__">Dataset.__init__</a></code> for more
16451640 details.</p>
16461641
16471642 <p>A list of attribute names corresponding to global netCDF attributes
1648 defined for the <a href="#Dataset">Dataset</a> can be obtained with the
1649 <a href="#<a href="#Dataset.ncattrs">Dataset.ncattrs</a>"><a href="#Dataset.ncattrs">Dataset.ncattrs</a></a> method.
1643 defined for the <code><a href="#Dataset">Dataset</a></code> can be obtained with the
1644 <code><a href="#Dataset.ncattrs">Dataset.ncattrs</a></code> method.
16501645 These attributes can be created by assigning to an attribute of the
1651 <a href="#Dataset">Dataset</a> instance. A dictionary containing all the netCDF attribute
1646 <code><a href="#Dataset">Dataset</a></code> instance. A dictionary containing all the netCDF attribute
16521647 name/value pairs is provided by the <code>__dict__</code> attribute of a
1653 <a href="#Dataset">Dataset</a> instance.</p>
1648 <code><a href="#Dataset">Dataset</a></code> instance.</p>
16541649
16551650 <p>The following class variables are read-only and should not be
16561651 modified by the user.</p>
16571652
1658 <p><strong><code>dimensions</code></strong>: The <code>dimensions</code> dictionary maps the names of
1659 dimensions defined for the <a href="#Group">Group</a> or <a href="#Dataset">Dataset</a> to instances of the
1660 <a href="#Dimension">Dimension</a> class.</p>
1661
1662 <p><strong><code>variables</code></strong>: The <code>variables</code> dictionary maps the names of variables
1663 defined for this <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> to instances of the
1664 <a href="#Variable">Variable</a> class.</p>
1665
1666 <p><strong><code>groups</code></strong>: The groups dictionary maps the names of groups created for
1667 this <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> to instances of the <a href="#Group">Group</a> class (the
1668 <a href="#Dataset">Dataset</a> class is simply a special case of the <a href="#Group">Group</a> class which
1653 <p><strong><code><a href="#Dataset.dimensions">dimensions</a></code></strong>: The <code><a href="#Dataset.dimensions">dimensions</a></code> dictionary maps the names of
1654 dimensions defined for the <code><a href="#Group">Group</a></code> or <code><a href="#Dataset">Dataset</a></code> to instances of the
1655 <code><a href="#Dimension">Dimension</a></code> class.</p>
1656
1657 <p><strong><code><a href="#Dataset.variables">variables</a></code></strong>: The <code><a href="#Dataset.variables">variables</a></code> dictionary maps the names of variables
1658 defined for this <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> to instances of the
1659 <code><a href="#Variable">Variable</a></code> class.</p>
1660
1661 <p><strong><code><a href="#Dataset.groups">groups</a></code></strong>: The groups dictionary maps the names of groups created for
1662 this <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> to instances of the <code><a href="#Group">Group</a></code> class (the
1663 <code><a href="#Dataset">Dataset</a></code> class is simply a special case of the <code><a href="#Group">Group</a></code> class which
16691664 describes the root group in the netCDF4 file).</p>
16701665
1671 <p><strong><code>cmptypes</code></strong>: The <code>cmptypes</code> dictionary maps the names of
1672 compound types defined for the <a href="#Group">Group</a> or <a href="#Dataset">Dataset</a> to instances of the
1673 <a href="#CompoundType">CompoundType</a> class.</p>
1674
1675 <p><strong><code>vltypes</code></strong>: The <code>vltypes</code> dictionary maps the names of
1676 variable-length types defined for the <a href="#Group">Group</a> or <a href="#Dataset">Dataset</a> to instances
1677 of the <a href="#VLType">VLType</a> class.</p>
1678
1679 <p><strong><code>enumtypes</code></strong>: The <code>enumtypes</code> dictionary maps the names of
1680 Enum types defined for the <a href="#Group">Group</a> or <a href="#Dataset">Dataset</a> to instances
1681 of the <a href="#EnumType">EnumType</a> class.</p>
1682
1683 <p><strong><code>data_model</code></strong>: <code>data_model</code> describes the netCDF
1666 <p><strong><code><a href="#Dataset.cmptypes">cmptypes</a></code></strong>: The <code><a href="#Dataset.cmptypes">cmptypes</a></code> dictionary maps the names of
1667 compound types defined for the <code><a href="#Group">Group</a></code> or <code><a href="#Dataset">Dataset</a></code> to instances of the
1668 <code><a href="#CompoundType">CompoundType</a></code> class.</p>
1669
1670 <p><strong><code><a href="#Dataset.vltypes">vltypes</a></code></strong>: The <code><a href="#Dataset.vltypes">vltypes</a></code> dictionary maps the names of
1671 variable-length types defined for the <code><a href="#Group">Group</a></code> or <code><a href="#Dataset">Dataset</a></code> to instances
1672 of the <code><a href="#VLType">VLType</a></code> class.</p>
1673
1674 <p><strong><code><a href="#Dataset.enumtypes">enumtypes</a></code></strong>: The <code><a href="#Dataset.enumtypes">enumtypes</a></code> dictionary maps the names of
1675 Enum types defined for the <code><a href="#Group">Group</a></code> or <code><a href="#Dataset">Dataset</a></code> to instances
1676 of the <code><a href="#EnumType">EnumType</a></code> class.</p>
1677
1678 <p><strong><code><a href="#Dataset.data_model">data_model</a></code></strong>: <code><a href="#Dataset.data_model">data_model</a></code> describes the netCDF
16841679 data model version, one of <code>NETCDF3_CLASSIC</code>, <code>NETCDF4</code>,
16851680 <code>NETCDF4_CLASSIC</code>, <code>NETCDF3_64BIT_OFFSET</code> or <code>NETCDF3_64BIT_DATA</code>.</p>
16861681
1687 <p><strong><code>file_format</code></strong>: same as <code>data_model</code>, retained for backwards compatibility.</p>
1688
1689 <p><strong><code>disk_format</code></strong>: <code>disk_format</code> describes the underlying
1682 <p><strong><code><a href="#Dataset.file_format">file_format</a></code></strong>: same as <code><a href="#Dataset.data_model">data_model</a></code>, retained for backwards compatibility.</p>
1683
1684 <p><strong><code><a href="#Dataset.disk_format">disk_format</a></code></strong>: <code><a href="#Dataset.disk_format">disk_format</a></code> describes the underlying
16901685 file format, one of <code>NETCDF3</code>, <code>HDF5</code>, <code>HDF4</code>,
16911686 <code>PNETCDF</code>, <code>DAP2</code>, <code>DAP4</code> or <code>UNDEFINED</code>. Only available if using
16921687 netcdf C library version &gt;= 4.3.1, otherwise will always return
16931688 <code>UNDEFINED</code>.</p>
16941689
1695 <p><strong><code>parent</code></strong>: <code>parent</code> is a reference to the parent
1696 <a href="#Group">Group</a> instance. <code>None</code> for the root group or <a href="#Dataset">Dataset</a>
1690 <p><strong><code><a href="#Dataset.parent">parent</a></code></strong>: <code><a href="#Dataset.parent">parent</a></code> is a reference to the parent
1691 <code><a href="#Group">Group</a></code> instance. <code>None</code> for the root group or <code><a href="#Dataset">Dataset</a></code>
16971692 instance.</p>
16981693
1699 <p><strong><code>path</code></strong>: <code>path</code> shows the location of the <a href="#Group">Group</a> in
1700 the <a href="#Dataset">Dataset</a> in a unix directory format (the names of groups in the
1701 hierarchy separated by backslashes). A <a href="#Dataset">Dataset</a> instance is the root
1694 <p><strong><code><a href="#Dataset.path">path</a></code></strong>: <code><a href="#Dataset.path">path</a></code> shows the location of the <code><a href="#Group">Group</a></code> in
1695 the <code><a href="#Dataset">Dataset</a></code> in a unix directory format (the names of groups in the
1696 hierarchy separated by backslashes). A <code><a href="#Dataset">Dataset</a></code> instance is the root
17021697 group, so the path is simply <code>'/'</code>.</p>
17031698
1704 <p><strong><code>keepweakref</code></strong>: If <code>True</code>, child Dimension and Variables objects only keep weak
1699 <p><strong><code><a href="#Dataset.keepweakref">keepweakref</a></code></strong>: If <code>True</code>, child Dimension and Variables objects only keep weak
17051700 references to the parent Dataset or Group.</p>
17061701
17071702 <p><strong><code>_ncstring_attrs__</code></strong>: If <code>True</code>, all text attributes will be written as variable-length
17131708 <div class="attr function"><a class="headerlink" href="#Dataset.__init__">#&nbsp;&nbsp</a>
17141709
17151710
1716 <span class="name">Dataset</span><span class="signature">(unknown)</span> </div>
1711 <span class="name">Dataset</span><span class="signature">()</span>
1712 </div>
17171713
17181714
17191715 <div class="docstring"><p><strong><code>__init__(self, filename, mode="r", clobber=True, diskless=False,
17201716 persist=False, keepweakref=False, memory=None, encoding=None,
17211717 parallel=False, comm=None, info=None, format='NETCDF4')</code></strong></p>
17221718
1723 <p><a href="#Dataset">Dataset</a> constructor.</p>
1719 <p><code><a href="#Dataset">Dataset</a></code> constructor.</p>
17241720
17251721 <p><strong><code>filename</code></strong>: Name of netCDF file to hold dataset. Can also
17261722 be a python 3 pathlib instance or the URL of an OpenDAP dataset. When memory is
1727 set this is just used to set the <code>filepath()</code>.</p>
1723 set this is just used to set the <code><a href="#Dataset.filepath">filepath()</a></code>.</p>
17281724
17291725 <p><strong><code>mode</code></strong>: access mode. <code>r</code> means read-only; no data can be
17301726 modified. <code>w</code> means write; a new file is created, an existing file with
17681764 <p><strong><code>persist</code></strong>: if <code>diskless=True</code>, persist file to disk when closed
17691765 (default <code>False</code>).</p>
17701766
1771 <p><strong><code>keepweakref</code></strong>: if <code>True</code>, child Dimension and Variable instances will keep weak
1767 <p><strong><code><a href="#Dataset.keepweakref">keepweakref</a></code></strong>: if <code>True</code>, child Dimension and Variable instances will keep weak
17721768 references to the parent Dataset or Group object. Default is <code>False</code>, which
17731769 means strong references will be kept. Having Dimension and Variable instances
17741770 keep a strong reference to the parent Dataset instance, which in turn keeps a
18721868
18731869 <div class="docstring"><p><strong><code>sync(self)</code></strong></p>
18741870
1875 <p>Writes all buffered data in the <a href="#Dataset">Dataset</a> to the disk file.</p>
1871 <p>Writes all buffered data in the <code><a href="#Dataset">Dataset</a></code> to the disk file.</p>
18761872 </div>
18771873
18781874
18881884
18891885 <div class="docstring"><p><strong><code>set_fill_on(self)</code></strong></p>
18901886
1891 <p>Sets the fill mode for a <a href="#Dataset">Dataset</a> open for writing to <code>on</code>.</p>
1887 <p>Sets the fill mode for a <code><a href="#Dataset">Dataset</a></code> open for writing to <code>on</code>.</p>
18921888
18931889 <p>This causes data to be pre-filled with fill values. The fill values can be
18941890 controlled by the variable's <code>_Fill_Value</code> attribute, but is usually
18951891 sufficient to the use the netCDF default <code>_Fill_Value</code> (defined
18961892 separately for each variable type). The default behavior of the netCDF
1897 library corresponds to <code>set_fill_on</code>. Data which are equal to the
1893 library corresponds to <code><a href="#Dataset.set_fill_on">set_fill_on</a></code>. Data which are equal to the
18981894 <code>_Fill_Value</code> indicate that the variable was created, but never written
18991895 to.</p>
19001896 </div>
19121908
19131909 <div class="docstring"><p><strong><code>set_fill_off(self)</code></strong></p>
19141910
1915 <p>Sets the fill mode for a <a href="#Dataset">Dataset</a> open for writing to <code>off</code>.</p>
1911 <p>Sets the fill mode for a <code><a href="#Dataset">Dataset</a></code> open for writing to <code>off</code>.</p>
19161912
19171913 <p>This will prevent the data from being pre-filled with fill values, which
19181914 may result in some performance improvements. However, you must then make
19361932
19371933 <p><code>size</code> must be a positive integer or <code>None</code>, which stands for
19381934 "unlimited" (default is <code>None</code>). Specifying a size of 0 also
1939 results in an unlimited dimension. The return value is the <a href="#Dimension">Dimension</a>
1935 results in an unlimited dimension. The return value is the <code><a href="#Dimension">Dimension</a></code>
19401936 class instance describing the new dimension. To determine the current
1941 maximum size of the dimension, use the <code>len</code> function on the <a href="#Dimension">Dimension</a>
1937 maximum size of the dimension, use the <code>len</code> function on the <code><a href="#Dimension">Dimension</a></code>
19421938 instance. To determine if a dimension is 'unlimited', use the
1943 <a href="#<a href="#Dimension.isunlimited">Dimension.isunlimited</a>"><a href="#Dimension.isunlimited">Dimension.isunlimited</a></a> method of the <a href="#Dimension">Dimension</a> instance.</p>
1939 <code><a href="#Dimension.isunlimited">Dimension.isunlimited</a></code> method of the <code><a href="#Dimension">Dimension</a></code> instance.</p>
19441940 </div>
19451941
19461942
19561952
19571953 <div class="docstring"><p><strong><code>renameDimension(self, oldname, newname)</code></strong></p>
19581954
1959 <p>rename a <a href="#Dimension">Dimension</a> named <code>oldname</code> to <code>newname</code>.</p>
1955 <p>rename a <code><a href="#Dimension">Dimension</a></code> named <code>oldname</code> to <code>newname</code>.</p>
19601956 </div>
19611957
19621958
19801976 are homogeneous numeric data types), then the 'inner' compound types <strong>must</strong> be
19811977 created first.</p>
19821978
1983 <p>The return value is the <a href="#CompoundType">CompoundType</a> class instance describing the new
1979 <p>The return value is the <code><a href="#CompoundType">CompoundType</a></code> class instance describing the new
19841980 datatype.</p>
19851981 </div>
19861982
20001996 <p>Creates a new VLEN data type named <code>datatype_name</code> from a numpy
20011997 dtype object <code>datatype</code>.</p>
20021998
2003 <p>The return value is the <a href="#VLType">VLType</a> class instance describing the new
1999 <p>The return value is the <code><a href="#VLType">VLType</a></code> class instance describing the new
20042000 datatype.</p>
20052001 </div>
20062002
20212017 integer dtype object <code>datatype</code>, and a python dictionary
20222018 defining the enum fields and values.</p>
20232019
2024 <p>The return value is the <a href="#EnumType">EnumType</a> class instance describing the new
2020 <p>The return value is the <code><a href="#EnumType">EnumType</a></code> class instance describing the new
20252021 datatype.</p>
20262022 </div>
20272023
20412037 endian='native', least_significant_digit=None, fill_value=None, chunk_cache=None)</code></strong></p>
20422038
20432039 <p>Creates a new variable with the given <code>varname</code>, <code>datatype</code>, and
2044 <code>dimensions</code>. If dimensions are not given, the variable is assumed to be
2040 <code><a href="#Dataset.dimensions">dimensions</a></code>. If dimensions are not given, the variable is assumed to be
20452041 a scalar.</p>
20462042
20472043 <p>If <code>varname</code> is specified as a path, using forward slashes as in unix to
20562052 (NC_BYTE), 'u1' (NC_UBYTE), 'i2' or 'h' or 's' (NC_SHORT), 'u2'
20572053 (NC_USHORT), 'i4' or 'i' or 'l' (NC_INT), 'u4' (NC_UINT), 'i8' (NC_INT64),
20582054 'u8' (NC_UINT64), 'f4' or 'f' (NC_FLOAT), 'f8' or 'd' (NC_DOUBLE)</code>.
2059 <code>datatype</code> can also be a <a href="#CompoundType">CompoundType</a> instance
2060 (for a structured, or compound array), a <a href="#VLType">VLType</a> instance
2055 <code>datatype</code> can also be a <code><a href="#CompoundType">CompoundType</a></code> instance
2056 (for a structured, or compound array), a <code><a href="#VLType">VLType</a></code> instance
20612057 (for a variable-length array), or the python <code>str</code> builtin
20622058 (for a variable-length string array). Numpy string and unicode datatypes with
20632059 length greater than one are aliases for <code>str</code>.</p>
20652061 <p>Data from netCDF variables is presented to python as numpy arrays with
20662062 the corresponding data type.</p>
20672063
2068 <p><code>dimensions</code> must be a tuple containing dimension names (strings) that
2069 have been defined previously using <a href="#<a href="#Dataset.createDimension">Dataset.createDimension</a>"><a href="#Dataset.createDimension">Dataset.createDimension</a></a>. The default value
2064 <p><code><a href="#Dataset.dimensions">dimensions</a></code> must be a tuple containing dimension names (strings) that
2065 have been defined previously using <code><a href="#Dataset.createDimension">Dataset.createDimension</a></code>. The default value
20702066 is an empty tuple, which means the variable is a scalar.</p>
20712067
20722068 <p>If the optional keyword <code>zlib</code> is <code>True</code>, the data will be compressed in
21082104
21092105 <p>The optional keyword <code>fill_value</code> can be used to override the default
21102106 netCDF <code>_FillValue</code> (the value that the variable gets filled with before
2111 any data is written to it, defaults given in <a href="#default_fillvals">default_fillvals</a>).
2107 any data is written to it, defaults given in the dict <code><a href="#default_fillvals">netCDF4.default_fillvals</a></code>).
21122108 If fill_value is set to <code>False</code>, then the variable is not pre-filled.</p>
21132109
21142110 <p>If the optional keyword parameter <code>least_significant_digit</code> is
21332129 method to change it the next time the Dataset is opened.
21342130 Warning - messing with this parameter can seriously degrade performance.</p>
21352131
2136 <p>The return value is the <a href="#Variable">Variable</a> class instance describing the new
2132 <p>The return value is the <code><a href="#Variable">Variable</a></code> class instance describing the new
21372133 variable.</p>
21382134
21392135 <p>A list of names corresponding to netCDF variable attributes can be
2140 obtained with the <a href="#Variable">Variable</a> method <a href="#<a href="#Variable.ncattrs">Variable.ncattrs</a>"><a href="#Variable.ncattrs">Variable.ncattrs</a></a>. A dictionary
2136 obtained with the <code><a href="#Variable">Variable</a></code> method <code><a href="#Variable.ncattrs">Variable.ncattrs</a></code>. A dictionary
21412137 containing all the netCDF attribute name/value pairs is provided by
2142 the <code>__dict__</code> attribute of a <a href="#Variable">Variable</a> instance.</p>
2143
2144 <p><a href="#Variable">Variable</a> instances behave much like array objects. Data can be
2138 the <code>__dict__</code> attribute of a <code><a href="#Variable">Variable</a></code> instance.</p>
2139
2140 <p><code><a href="#Variable">Variable</a></code> instances behave much like array objects. Data can be
21452141 assigned to or retrieved from a variable with indexing and slicing
2146 operations on the <a href="#Variable">Variable</a> instance. A <a href="#Variable">Variable</a> instance has six
2142 operations on the <code><a href="#Variable">Variable</a></code> instance. A <code><a href="#Variable">Variable</a></code> instance has six
21472143 Dataset standard attributes: <code>dimensions, dtype, shape, ndim, name</code> and
21482144 <code>least_significant_digit</code>. Application programs should never modify
2149 these attributes. The <code>dimensions</code> attribute is a tuple containing the
2145 these attributes. The <code><a href="#Dataset.dimensions">dimensions</a></code> attribute is a tuple containing the
21502146 names of the dimensions associated with this variable. The <code>dtype</code>
21512147 attribute is a string describing the variable's data type (<code>i4, f8,
21522148 S1,</code> etc). The <code>shape</code> attribute is a tuple describing the current
2153 sizes of all the variable's dimensions. The <code>name</code> attribute is a
2149 sizes of all the variable's dimensions. The <code><a href="#Dataset.name">name</a></code> attribute is a
21542150 string containing the name of the Variable instance.
21552151 The <code>least_significant_digit</code>
21562152 attributes describes the power of ten of the smallest decimal place in
2157 the data the contains a reliable value. assigned to the <a href="#Variable">Variable</a>
2153 the data the contains a reliable value. assigned to the <code><a href="#Variable">Variable</a></code>
21582154 instance. If <code>None</code>, the data is not truncated. The <code>ndim</code> attribute
21592155 is the number of variable dimensions.</p>
21602156 </div>
21722168
21732169 <div class="docstring"><p><strong><code>renameVariable(self, oldname, newname)</code></strong></p>
21742170
2175 <p>rename a <a href="#Variable">Variable</a> named <code>oldname</code> to <code>newname</code></p>
2171 <p>rename a <code><a href="#Variable">Variable</a></code> named <code>oldname</code> to <code>newname</code></p>
21762172 </div>
21772173
21782174
21882184
21892185 <div class="docstring"><p><strong><code>createGroup(self, groupname)</code></strong></p>
21902186
2191 <p>Creates a new <a href="#Group">Group</a> with the given <code>groupname</code>.</p>
2187 <p>Creates a new <code><a href="#Group">Group</a></code> with the given <code>groupname</code>.</p>
21922188
21932189 <p>If <code>groupname</code> is specified as a path, using forward slashes as in unix to
21942190 separate components, then intermediate groups will be created as necessary
21982194 If the specified path describes a group that already exists, no error is
21992195 raised.</p>
22002196
2201 <p>The return value is a <a href="#Group">Group</a> class instance.</p>
2197 <p>The return value is a <code><a href="#Group">Group</a></code> class instance.</p>
22022198 </div>
22032199
22042200
22142210
22152211 <div class="docstring"><p><strong><code>ncattrs(self)</code></strong></p>
22162212
2217 <p>return netCDF global attribute names for this <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> in a list.</p>
2213 <p>return netCDF global attribute names for this <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> in a list.</p>
22182214 </div>
22192215
22202216
23242320
23252321 <div class="docstring"><p><strong><code>renameAttribute(self, oldname, newname)</code></strong></p>
23262322
2327 <p>rename a <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> attribute named <code>oldname</code> to <code>newname</code>.</p>
2323 <p>rename a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> attribute named <code>oldname</code> to <code>newname</code>.</p>
23282324 </div>
23292325
23302326
23402336
23412337 <div class="docstring"><p><strong><code>renameGroup(self, oldname, newname)</code></strong></p>
23422338
2343 <p>rename a <a href="#Group">Group</a> named <code>oldname</code> to <code>newname</code> (requires netcdf &gt;= 4.3.1).</p>
2339 <p>rename a <code><a href="#Group">Group</a></code> named <code>oldname</code> to <code>newname</code> (requires netcdf &gt;= 4.3.1).</p>
23442340 </div>
23452341
23462342
23562352
23572353 <div class="docstring"><p><strong><code>set_auto_chartostring(self, True_or_False)</code></strong></p>
23582354
2359 <p>Call <a href="#<a href="#Variable.set_auto_chartostring">Variable.set_auto_chartostring</a>"><a href="#Variable.set_auto_chartostring">Variable.set_auto_chartostring</a></a> for all variables contained in this <a href="#Dataset">Dataset</a> or
2360 <a href="#Group">Group</a>, as well as for all variables in all its subgroups.</p>
2355 <p>Call <code><a href="#Variable.set_auto_chartostring">Variable.set_auto_chartostring</a></code> for all variables contained in this <code><a href="#Dataset">Dataset</a></code> or
2356 <code><a href="#Group">Group</a></code>, as well as for all variables in all its subgroups.</p>
23612357
23622358 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic conversion of
23632359 all character arrays &lt;--> string arrays should be performed for
23812377
23822378 <div class="docstring"><p><strong><code>set_auto_maskandscale(self, True_or_False)</code></strong></p>
23832379
2384 <p>Call <a href="#<a href="#Variable.set_auto_maskandscale">Variable.set_auto_maskandscale</a>"><a href="#Variable.set_auto_maskandscale">Variable.set_auto_maskandscale</a></a> for all variables contained in this <a href="#Dataset">Dataset</a> or
2385 <a href="#Group">Group</a>, as well as for all variables in all its subgroups.</p>
2380 <p>Call <code><a href="#Variable.set_auto_maskandscale">Variable.set_auto_maskandscale</a></code> for all variables contained in this <code><a href="#Dataset">Dataset</a></code> or
2381 <code><a href="#Group">Group</a></code>, as well as for all variables in all its subgroups.</p>
23862382
23872383 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic conversion to masked arrays
23882384 and variable scaling shall be applied for all variables.</p>
24042400
24052401 <div class="docstring"><p><strong><code>set_auto_mask(self, True_or_False)</code></strong></p>
24062402
2407 <p>Call <a href="#<a href="#Variable.set_auto_mask">Variable.set_auto_mask</a>"><a href="#Variable.set_auto_mask">Variable.set_auto_mask</a></a> for all variables contained in this <a href="#Dataset">Dataset</a> or
2408 <a href="#Group">Group</a>, as well as for all variables in all its subgroups.</p>
2403 <p>Call <code><a href="#Variable.set_auto_mask">Variable.set_auto_mask</a></code> for all variables contained in this <code><a href="#Dataset">Dataset</a></code> or
2404 <code><a href="#Group">Group</a></code>, as well as for all variables in all its subgroups. Only affects
2405 Variables with primitive or enum types (not compound or vlen Variables).</p>
24092406
24102407 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic conversion to masked arrays
24112408 shall be applied for all variables.</p>
24272424
24282425 <div class="docstring"><p><strong><code>set_auto_scale(self, True_or_False)</code></strong></p>
24292426
2430 <p>Call <a href="#<a href="#Variable.set_auto_scale">Variable.set_auto_scale</a>"><a href="#Variable.set_auto_scale">Variable.set_auto_scale</a></a> for all variables contained in this <a href="#Dataset">Dataset</a> or
2431 <a href="#Group">Group</a>, as well as for all variables in all its subgroups.</p>
2427 <p>Call <code><a href="#Variable.set_auto_scale">Variable.set_auto_scale</a></code> for all variables contained in this <code><a href="#Dataset">Dataset</a></code> or
2428 <code><a href="#Group">Group</a></code>, as well as for all variables in all its subgroups.</p>
24322429
24332430 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic variable scaling
24342431 shall be applied for all variables.</p>
24502447
24512448 <div class="docstring"><p><strong><code>set_always_mask(self, True_or_False)</code></strong></p>
24522449
2453 <p>Call <a href="#<a href="#Variable.set_always_mask">Variable.set_always_mask</a>"><a href="#Variable.set_always_mask">Variable.set_always_mask</a></a> for all variables contained in
2454 this <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a>, as well as for all
2450 <p>Call <code><a href="#Variable.set_always_mask">Variable.set_always_mask</a></code> for all variables contained in
2451 this <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code>, as well as for all
24552452 variables in all its subgroups.</p>
24562453
24572454 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic conversion of
24782475
24792476 <div class="docstring"><p><strong><code>set_ncstring_attrs(self, True_or_False)</code></strong></p>
24802477
2481 <p>Call <a href="#<a href="#Variable.set_ncstring_attrs">Variable.set_ncstring_attrs</a>"><a href="#Variable.set_ncstring_attrs">Variable.set_ncstring_attrs</a></a> for all variables contained in
2482 this <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a>, as well as for all its
2478 <p>Call <code><a href="#Variable.set_ncstring_attrs">Variable.set_ncstring_attrs</a></code> for all variables contained in
2479 this <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code>, as well as for all its
24832480 subgroups and their variables.</p>
24842481
24852482 <p><strong><code>True_or_False</code></strong>: Boolean determining if all string attributes are
25412538
25422539 <div class="docstring"><p><strong><code>fromcdl(cdlfilename, ncfilename=None, mode='a',format='NETCDF4')</code></strong></p>
25432540
2544 <p>call <code>ncgen</code> via subprocess to create Dataset from <a href="https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#cdl_guide">CDL</a>
2545 text representation. Requires <code>ncgen</code> to be installed and in <code>$PATH</code>.</p>
2541 <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>
2542 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>
25462543
25472544 <p><strong><code>cdlfilename</code></strong>: CDL file.</p>
25482545
25712568
25722569 <div class="docstring"><p><strong><code>tocdl(self, coordvars=False, data=False, outfile=None)</code></strong></p>
25732570
2574 <p>call <code>ncdump</code> via subprocess to create <a href="https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#cdl_guide">CDL</a>
2575 text representation of Dataset. Requires <code>ncdump</code> to be installed and in <code>$PATH</code>.</p>
2571 <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>
2572 text representation of Dataset. Requires <a href="https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#ncdump_guide">ncdump</a>
2573 to be installed and in <code>$PATH</code>.</p>
25762574
25772575 <p><strong><code>coordvars</code></strong>: include coordinate variable data (via <code>ncdump -c</code>). Default False</p>
25782576
25862584 <div id="Dataset.name" class="classattr">
25872585 <div class="attr variable"><a class="headerlink" href="#Dataset.name">#&nbsp;&nbsp</a>
25882586
2589 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2590 </div>
2591
2592
2587 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2588 </div>
2589
2590 <div class="docstring"><p>string name of Group instance</p>
2591 </div>
2592
25932593
25942594 </div>
25952595 <div id="Dataset.groups" class="classattr">
25962596 <div class="attr variable"><a class="headerlink" href="#Dataset.groups">#&nbsp;&nbsp</a>
25972597
2598 <span class="name">groups</span><span class="default_value"> = &lt;attribute &#39;groups&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2598 <span class="name">groups</span><span class="default_value"> = &lt;attribute &#39;groups&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
25992599 </div>
26002600
26012601
26042604 <div id="Dataset.dimensions" class="classattr">
26052605 <div class="attr variable"><a class="headerlink" href="#Dataset.dimensions">#&nbsp;&nbsp</a>
26062606
2607 <span class="name">dimensions</span><span class="default_value"> = &lt;attribute &#39;dimensions&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2607 <span class="name">dimensions</span><span class="default_value"> = &lt;attribute &#39;dimensions&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
26082608 </div>
26092609
26102610
26132613 <div id="Dataset.variables" class="classattr">
26142614 <div class="attr variable"><a class="headerlink" href="#Dataset.variables">#&nbsp;&nbsp</a>
26152615
2616 <span class="name">variables</span><span class="default_value"> = &lt;attribute &#39;variables&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2616 <span class="name">variables</span><span class="default_value"> = &lt;attribute &#39;variables&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
26172617 </div>
26182618
26192619
26222622 <div id="Dataset.disk_format" class="classattr">
26232623 <div class="attr variable"><a class="headerlink" href="#Dataset.disk_format">#&nbsp;&nbsp</a>
26242624
2625 <span class="name">disk_format</span><span class="default_value"> = &lt;attribute &#39;disk_format&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2625 <span class="name">disk_format</span><span class="default_value"> = &lt;attribute &#39;disk_format&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
26262626 </div>
26272627
26282628
26312631 <div id="Dataset.path" class="classattr">
26322632 <div class="attr variable"><a class="headerlink" href="#Dataset.path">#&nbsp;&nbsp</a>
26332633
2634 <span class="name">path</span><span class="default_value"> = &lt;attribute &#39;path&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2634 <span class="name">path</span><span class="default_value"> = &lt;attribute &#39;path&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
26352635 </div>
26362636
26372637
26402640 <div id="Dataset.parent" class="classattr">
26412641 <div class="attr variable"><a class="headerlink" href="#Dataset.parent">#&nbsp;&nbsp</a>
26422642
2643 <span class="name">parent</span><span class="default_value"> = &lt;attribute &#39;parent&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2643 <span class="name">parent</span><span class="default_value"> = &lt;attribute &#39;parent&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
26442644 </div>
26452645
26462646
26492649 <div id="Dataset.file_format" class="classattr">
26502650 <div class="attr variable"><a class="headerlink" href="#Dataset.file_format">#&nbsp;&nbsp</a>
26512651
2652 <span class="name">file_format</span><span class="default_value"> = &lt;attribute &#39;file_format&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2652 <span class="name">file_format</span><span class="default_value"> = &lt;attribute &#39;file_format&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
26532653 </div>
26542654
26552655
26582658 <div id="Dataset.data_model" class="classattr">
26592659 <div class="attr variable"><a class="headerlink" href="#Dataset.data_model">#&nbsp;&nbsp</a>
26602660
2661 <span class="name">data_model</span><span class="default_value"> = &lt;attribute &#39;data_model&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2661 <span class="name">data_model</span><span class="default_value"> = &lt;attribute &#39;data_model&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
26622662 </div>
26632663
26642664
26672667 <div id="Dataset.cmptypes" class="classattr">
26682668 <div class="attr variable"><a class="headerlink" href="#Dataset.cmptypes">#&nbsp;&nbsp</a>
26692669
2670 <span class="name">cmptypes</span><span class="default_value"> = &lt;attribute &#39;cmptypes&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2670 <span class="name">cmptypes</span><span class="default_value"> = &lt;attribute &#39;cmptypes&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
26712671 </div>
26722672
26732673
26762676 <div id="Dataset.vltypes" class="classattr">
26772677 <div class="attr variable"><a class="headerlink" href="#Dataset.vltypes">#&nbsp;&nbsp</a>
26782678
2679 <span class="name">vltypes</span><span class="default_value"> = &lt;attribute &#39;vltypes&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2679 <span class="name">vltypes</span><span class="default_value"> = &lt;attribute &#39;vltypes&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
26802680 </div>
26812681
26822682
26852685 <div id="Dataset.enumtypes" class="classattr">
26862686 <div class="attr variable"><a class="headerlink" href="#Dataset.enumtypes">#&nbsp;&nbsp</a>
26872687
2688 <span class="name">enumtypes</span><span class="default_value"> = &lt;attribute &#39;enumtypes&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2688 <span class="name">enumtypes</span><span class="default_value"> = &lt;attribute &#39;enumtypes&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
26892689 </div>
26902690
26912691
26942694 <div id="Dataset.keepweakref" class="classattr">
26952695 <div class="attr variable"><a class="headerlink" href="#Dataset.keepweakref">#&nbsp;&nbsp</a>
26962696
2697 <span class="name">keepweakref</span><span class="default_value"> = &lt;attribute &#39;keepweakref&#39; of &#39;<a href="#Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2697 <span class="name">keepweakref</span><span class="default_value"> = &lt;attribute &#39;keepweakref&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
26982698 </div>
26992699
27002700
2701
2702 </div>
2703 </section>
2704 <section id="Variable">
2705 <div class="attr class">
2706 <a class="headerlink" href="#Variable">#&nbsp;&nbsp</a>
2707
2708
2709 <span class="def">class</span>
2710 <span class="name">Variable</span>:
2711 </div>
2712
2713
2714 <div class="docstring"><p>A netCDF <code><a href="#Variable">Variable</a></code> is used to read and write netCDF data. They are
2715 analogous to numpy array objects. See <code><a href="#Variable.__init__">Variable.__init__</a></code> for more
2716 details.</p>
2717
2718 <p>A list of attribute names corresponding to netCDF attributes defined for
2719 the variable can be obtained with the <code><a href="#Variable.ncattrs">Variable.ncattrs</a></code> method. These
2720 attributes can be created by assigning to an attribute of the
2721 <code><a href="#Variable">Variable</a></code> instance. A dictionary containing all the netCDF attribute
2722 name/value pairs is provided by the <code>__dict__</code> attribute of a
2723 <code><a href="#Variable">Variable</a></code> instance.</p>
2724
2725 <p>The following class variables are read-only:</p>
2726
2727 <p><strong><code><a href="#Variable.dimensions">dimensions</a></code></strong>: A tuple containing the names of the
2728 dimensions associated with this variable.</p>
2729
2730 <p><strong><code><a href="#Variable.dtype">dtype</a></code></strong>: A numpy dtype object describing the
2731 variable's data type.</p>
2732
2733 <p><strong><code><a href="#Variable.ndim">ndim</a></code></strong>: The number of variable dimensions.</p>
2734
2735 <p><strong><code><a href="#Variable.shape">shape</a></code></strong>: A tuple with the current shape (length of all dimensions).</p>
2736
2737 <p><strong><code><a href="#Variable.scale">scale</a></code></strong>: If True, <code>scale_factor</code> and <code>add_offset</code> are
2738 applied, and signed integer data is automatically converted to
2739 unsigned integer data if the <code>_Unsigned</code> attribute is set.
2740 Default is <code>True</code>, can be reset using <code><a href="#Variable.set_auto_scale">Variable.set_auto_scale</a></code> and
2741 <code><a href="#Variable.set_auto_maskandscale">Variable.set_auto_maskandscale</a></code> methods.</p>
2742
2743 <p><strong><code><a href="#Variable.mask">mask</a></code></strong>: If True, data is automatically converted to/from masked
2744 arrays when missing values or fill values are present. Default is <code>True</code>, can be
2745 reset using <code><a href="#Variable.set_auto_mask">Variable.set_auto_mask</a></code> and <code><a href="#Variable.set_auto_maskandscale">Variable.set_auto_maskandscale</a></code>
2746 methods. Only relevant for Variables with primitive or enum types (ignored
2747 for compound and vlen Variables).</p>
2748
2749 <p><strong><code><a href="#Variable.chartostring">chartostring</a></code></strong>: If True, data is automatically converted to/from character
2750 arrays to string arrays when the <code>_Encoding</code> variable attribute is set.
2751 Default is <code>True</code>, can be reset using
2752 <code><a href="#Variable.set_auto_chartostring">Variable.set_auto_chartostring</a></code> method.</p>
2753
2754 <p><strong><code>least_significant_digit</code></strong>: Describes the power of ten of the
2755 smallest decimal place in the data the contains a reliable value. Data is
2756 truncated to this decimal place when it is assigned to the <code><a href="#Variable">Variable</a></code>
2757 instance. If <code>None</code>, the data is not truncated.</p>
2758
2759 <p><strong><code>__orthogonal_indexing__</code></strong>: Always <code>True</code>. Indicates to client code
2760 that the object supports 'orthogonal indexing', which means that slices
2761 that are 1d arrays or lists slice along each dimension independently. This
2762 behavior is similar to Fortran or Matlab, but different than numpy.</p>
2763
2764 <p><strong><code><a href="#Variable.datatype">datatype</a></code></strong>: numpy data type (for primitive data types) or VLType/CompoundType
2765 instance (for compound or vlen data types).</p>
2766
2767 <p><strong><code><a href="#Variable.name">name</a></code></strong>: String name.</p>
2768
2769 <p><strong><code><a href="#Variable.size">size</a></code></strong>: The number of stored elements.</p>
2770 </div>
2771
2772
2773 <div id="Variable.__init__" class="classattr">
2774 <div class="attr function"><a class="headerlink" href="#Variable.__init__">#&nbsp;&nbsp</a>
2775
2776
2777 <span class="name">Variable</span><span class="signature">()</span>
2778 </div>
2779
2780
2781 <div class="docstring"><p><strong><code>__init__(self, group, name, datatype, dimensions=(), zlib=False,
2782 complevel=4, shuffle=True, fletcher32=False, contiguous=False,
2783 chunksizes=None, endian='native',
2784 least_significant_digit=None,fill_value=None,chunk_cache=None)</code></strong></p>
2785
2786 <p><code><a href="#Variable">Variable</a></code> constructor.</p>
2787
2788 <p><strong><code><a href="#Variable.group">group</a></code></strong>: <code><a href="#Group">Group</a></code> or <code><a href="#Dataset">Dataset</a></code> instance to associate with variable.</p>
2789
2790 <p><strong><code><a href="#Variable.name">name</a></code></strong>: Name of the variable.</p>
2791
2792 <p><strong><code><a href="#Variable.datatype">datatype</a></code></strong>: <code><a href="#Variable">Variable</a></code> data type. Can be specified by providing a
2793 numpy dtype object, or a string that describes a numpy dtype object.
2794 Supported values, corresponding to <code>str</code> attribute of numpy dtype
2795 objects, include <code>'f4'</code> (32-bit floating point), <code>'f8'</code> (64-bit floating
2796 point), <code>'i4'</code> (32-bit signed integer), <code>'i2'</code> (16-bit signed integer),
2797 <code>'i8'</code> (64-bit signed integer), <code>'i4'</code> (8-bit signed integer), <code>'i1'</code>
2798 (8-bit signed integer), <code>'u1'</code> (8-bit unsigned integer), <code>'u2'</code> (16-bit
2799 unsigned integer), <code>'u4'</code> (32-bit unsigned integer), <code>'u8'</code> (64-bit
2800 unsigned integer), or <code>'S1'</code> (single-character string). From
2801 compatibility with Scientific.IO.NetCDF, the old Numeric single character
2802 typecodes can also be used (<code>'f'</code> instead of <code>'f4'</code>, <code>'d'</code> instead of
2803 <code>'f8'</code>, <code>'h'</code> or <code>'s'</code> instead of <code>'i2'</code>, <code>'b'</code> or <code>'B'</code> instead of
2804 <code>'i1'</code>, <code>'c'</code> instead of <code>'S1'</code>, and <code>'i'</code> or <code>'l'</code> instead of
2805 <code>'i4'</code>). <code><a href="#Variable.datatype">datatype</a></code> can also be a <code><a href="#CompoundType">CompoundType</a></code> instance
2806 (for a structured, or compound array), a <code><a href="#VLType">VLType</a></code> instance
2807 (for a variable-length array), or the python <code>str</code> builtin
2808 (for a variable-length string array). Numpy string and unicode datatypes with
2809 length greater than one are aliases for <code>str</code>.</p>
2810
2811 <p><strong><code><a href="#Variable.dimensions">dimensions</a></code></strong>: a tuple containing the variable's dimension names
2812 (defined previously with <code>createDimension</code>). Default is an empty tuple
2813 which means the variable is a scalar (and therefore has no dimensions).</p>
2814
2815 <p><strong><code>zlib</code></strong>: if <code>True</code>, data assigned to the <code><a href="#Variable">Variable</a></code>
2816 instance is compressed on disk. Default <code>False</code>.</p>
2817
2818 <p><strong><code>complevel</code></strong>: the level of zlib compression to use (1 is the fastest,
2819 but poorest compression, 9 is the slowest but best compression). Default 4.
2820 Ignored if <code>zlib=False</code>.</p>
2821
2822 <p><strong><code>shuffle</code></strong>: if <code>True</code>, the HDF5 shuffle filter is applied
2823 to improve compression. Default <code>True</code>. Ignored if <code>zlib=False</code>.</p>
2824
2825 <p><strong><code>fletcher32</code></strong>: if <code>True</code> (default <code>False</code>), the Fletcher32 checksum
2826 algorithm is used for error detection.</p>
2827
2828 <p><strong><code>contiguous</code></strong>: if <code>True</code> (default <code>False</code>), the variable data is
2829 stored contiguously on disk. Default <code>False</code>. Setting to <code>True</code> for
2830 a variable with an unlimited dimension will trigger an error.</p>
2831
2832 <p><strong><code>chunksizes</code></strong>: Can be used to specify the HDF5 chunksizes for each
2833 dimension of the variable. A detailed discussion of HDF chunking and I/O
2834 performance is available
2835 <a href="http://www.hdfgroup.org/HDF5/doc/H5.user/Chunking.html">here</a>.
2836 Basically, you want the chunk size for each dimension to match as
2837 closely as possible the size of the data block that users will read
2838 from the file. <code>chunksizes</code> cannot be set if <code>contiguous=True</code>.</p>
2839
2840 <p><strong><code><a href="#Variable.endian">endian</a></code></strong>: Can be used to control whether the
2841 data is stored in little or big endian format on disk. Possible
2842 values are <code>little, big</code> or <code>native</code> (default). The library
2843 will automatically handle endian conversions when the data is read,
2844 but if the data is always going to be read on a computer with the
2845 opposite format as the one used to create the file, there may be
2846 some performance advantage to be gained by setting the endian-ness.
2847 For netCDF 3 files (that don't use HDF5), only <code>endian='native'</code> is allowed.</p>
2848
2849 <p>The <code>zlib, complevel, shuffle, fletcher32, contiguous</code> and <code>chunksizes</code>
2850 keywords are silently ignored for netCDF 3 files that do not use HDF5.</p>
2851
2852 <p><strong><code>least_significant_digit</code></strong>: If specified, variable data will be
2853 truncated (quantized). In conjunction with <code>zlib=True</code> this produces
2854 'lossy', but significantly more efficient compression. For example, if
2855 <code>least_significant_digit=1</code>, data will be quantized using
2856 around(scale<em>data)/scale, where scale = 2</em>*bits, and bits is determined
2857 so that a precision of 0.1 is retained (in this case bits=4). Default is
2858 <code>None</code>, or no quantization.</p>
2859
2860 <p><strong><code>fill_value</code></strong>: If specified, the default netCDF <code>_FillValue</code> (the
2861 value that the variable gets filled with before any data is written to it)
2862 is replaced with this value. If fill_value is set to <code>False</code>, then
2863 the variable is not pre-filled. The default netCDF fill values can be found
2864 in the dictionary <code><a href="#default_fillvals">netCDF4.default_fillvals</a></code>.</p>
2865
2866 <p><strong><code>chunk_cache</code></strong>: If specified, sets the chunk cache size for this variable.
2867 Persists as long as Dataset is open. Use <code><a href="#Variable.set_var_chunk_cache">set_var_chunk_cache</a></code> to
2868 change it when Dataset is re-opened. </p>
2869
2870 <p><strong><em>Note</em></strong>: <code><a href="#Variable">Variable</a></code> instances should be created using the
2871 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or
2872 <code><a href="#Group">Group</a></code> instance, not using this class directly.</p>
2873 </div>
2874
2875
2876 </div>
2877 <div id="Variable.group" class="classattr">
2878 <div class="attr function"><a class="headerlink" href="#Variable.group">#&nbsp;&nbsp</a>
2879
2880
2881 <span class="def">def</span>
2882 <span class="name">group</span><span class="signature">(unknown)</span>:
2883 </div>
2884
2885
2886 <div class="docstring"><p><strong><code>group(self)</code></strong></p>
2887
2888 <p>return the group that this <code><a href="#Variable">Variable</a></code> is a member of.</p>
2889 </div>
2890
2891
2892 </div>
2893 <div id="Variable.ncattrs" class="classattr">
2894 <div class="attr function"><a class="headerlink" href="#Variable.ncattrs">#&nbsp;&nbsp</a>
2895
2896
2897 <span class="def">def</span>
2898 <span class="name">ncattrs</span><span class="signature">(unknown)</span>:
2899 </div>
2900
2901
2902 <div class="docstring"><p><strong><code>ncattrs(self)</code></strong></p>
2903
2904 <p>return netCDF attribute names for this <code><a href="#Variable">Variable</a></code> in a list.</p>
2905 </div>
2906
2907
2908 </div>
2909 <div id="Variable.setncattr" class="classattr">
2910 <div class="attr function"><a class="headerlink" href="#Variable.setncattr">#&nbsp;&nbsp</a>
2911
2912
2913 <span class="def">def</span>
2914 <span class="name">setncattr</span><span class="signature">(unknown)</span>:
2915 </div>
2916
2917
2918 <div class="docstring"><p><strong><code>setncattr(self,name,value)</code></strong></p>
2919
2920 <p>set a netCDF variable attribute using name,value pair. Use if you need to set a
2921 netCDF attribute with the same name as one of the reserved python
2922 attributes.</p>
2923 </div>
2924
2925
2926 </div>
2927 <div id="Variable.setncattr_string" class="classattr">
2928 <div class="attr function"><a class="headerlink" href="#Variable.setncattr_string">#&nbsp;&nbsp</a>
2929
2930
2931 <span class="def">def</span>
2932 <span class="name">setncattr_string</span><span class="signature">(unknown)</span>:
2933 </div>
2934
2935
2936 <div class="docstring"><p><strong><code>setncattr_string(self,name,value)</code></strong></p>
2937
2938 <p>set a netCDF variable string attribute using name,value pair.
2939 Use if you need to ensure that a netCDF attribute is created with type
2940 <code>NC_STRING</code> if the file format is <code>NETCDF4</code>.
2941 Use if you need to set an attribute to an array of variable-length strings.</p>
2942 </div>
2943
2944
2945 </div>
2946 <div id="Variable.setncatts" class="classattr">
2947 <div class="attr function"><a class="headerlink" href="#Variable.setncatts">#&nbsp;&nbsp</a>
2948
2949
2950 <span class="def">def</span>
2951 <span class="name">setncatts</span><span class="signature">(unknown)</span>:
2952 </div>
2953
2954
2955 <div class="docstring"><p><strong><code>setncatts(self,attdict)</code></strong></p>
2956
2957 <p>set a bunch of netCDF variable attributes at once using a python dictionary.
2958 This may be faster when setting a lot of attributes for a <code>NETCDF3</code>
2959 formatted file, since nc_redef/nc_enddef is not called in between setting
2960 each attribute</p>
2961 </div>
2962
2963
2964 </div>
2965 <div id="Variable.getncattr" class="classattr">
2966 <div class="attr function"><a class="headerlink" href="#Variable.getncattr">#&nbsp;&nbsp</a>
2967
2968
2969 <span class="def">def</span>
2970 <span class="name">getncattr</span><span class="signature">(unknown)</span>:
2971 </div>
2972
2973
2974 <div class="docstring"><p><strong><code>getncattr(self,name)</code></strong></p>
2975
2976 <p>retrieve a netCDF variable attribute. Use if you need to set a
2977 netCDF attribute with the same name as one of the reserved python
2978 attributes.</p>
2979
2980 <p>option kwarg <code>encoding</code> can be used to specify the
2981 character encoding of a string attribute (default is <code>utf-8</code>).</p>
2982 </div>
2983
2984
2985 </div>
2986 <div id="Variable.delncattr" class="classattr">
2987 <div class="attr function"><a class="headerlink" href="#Variable.delncattr">#&nbsp;&nbsp</a>
2988
2989
2990 <span class="def">def</span>
2991 <span class="name">delncattr</span><span class="signature">(unknown)</span>:
2992 </div>
2993
2994
2995 <div class="docstring"><p><strong><code>delncattr(self,name,value)</code></strong></p>
2996
2997 <p>delete a netCDF variable attribute. Use if you need to delete a
2998 netCDF attribute with the same name as one of the reserved python
2999 attributes.</p>
3000 </div>
3001
3002
3003 </div>
3004 <div id="Variable.filters" class="classattr">
3005 <div class="attr function"><a class="headerlink" href="#Variable.filters">#&nbsp;&nbsp</a>
3006
3007
3008 <span class="def">def</span>
3009 <span class="name">filters</span><span class="signature">(unknown)</span>:
3010 </div>
3011
3012
3013 <div class="docstring"><p><strong><code>filters(self)</code></strong></p>
3014
3015 <p>return dictionary containing HDF5 filter parameters.</p>
3016 </div>
3017
3018
3019 </div>
3020 <div id="Variable.endian" class="classattr">
3021 <div class="attr function"><a class="headerlink" href="#Variable.endian">#&nbsp;&nbsp</a>
3022
3023
3024 <span class="def">def</span>
3025 <span class="name">endian</span><span class="signature">(unknown)</span>:
3026 </div>
3027
3028
3029 <div class="docstring"><p><strong><code>endian(self)</code></strong></p>
3030
3031 <p>return endian-ness (<code>little,big,native</code>) of variable (as stored in HDF5 file).</p>
3032 </div>
3033
3034
3035 </div>
3036 <div id="Variable.chunking" class="classattr">
3037 <div class="attr function"><a class="headerlink" href="#Variable.chunking">#&nbsp;&nbsp</a>
3038
3039
3040 <span class="def">def</span>
3041 <span class="name">chunking</span><span class="signature">(unknown)</span>:
3042 </div>
3043
3044
3045 <div class="docstring"><p><strong><code>chunking(self)</code></strong></p>
3046
3047 <p>return variable chunking information. If the dataset is
3048 defined to be contiguous (and hence there is no chunking) the word 'contiguous'
3049 is returned. Otherwise, a sequence with the chunksize for
3050 each dimension is returned.</p>
3051 </div>
3052
3053
3054 </div>
3055 <div id="Variable.get_var_chunk_cache" class="classattr">
3056 <div class="attr function"><a class="headerlink" href="#Variable.get_var_chunk_cache">#&nbsp;&nbsp</a>
3057
3058
3059 <span class="def">def</span>
3060 <span class="name">get_var_chunk_cache</span><span class="signature">(unknown)</span>:
3061 </div>
3062
3063
3064 <div class="docstring"><p><strong><code>get_var_chunk_cache(self)</code></strong></p>
3065
3066 <p>return variable chunk cache information in a tuple (size,nelems,preemption).
3067 See netcdf C library documentation for <code>nc_get_var_chunk_cache</code> for
3068 details.</p>
3069 </div>
3070
3071
3072 </div>
3073 <div id="Variable.set_var_chunk_cache" class="classattr">
3074 <div class="attr function"><a class="headerlink" href="#Variable.set_var_chunk_cache">#&nbsp;&nbsp</a>
3075
3076
3077 <span class="def">def</span>
3078 <span class="name">set_var_chunk_cache</span><span class="signature">(unknown)</span>:
3079 </div>
3080
3081
3082 <div class="docstring"><p><strong><code>set_var_chunk_cache(self,size=None,nelems=None,preemption=None)</code></strong></p>
3083
3084 <p>change variable chunk cache settings.
3085 See netcdf C library documentation for <code>nc_set_var_chunk_cache</code> for
3086 details.</p>
3087 </div>
3088
3089
3090 </div>
3091 <div id="Variable.renameAttribute" class="classattr">
3092 <div class="attr function"><a class="headerlink" href="#Variable.renameAttribute">#&nbsp;&nbsp</a>
3093
3094
3095 <span class="def">def</span>
3096 <span class="name">renameAttribute</span><span class="signature">(unknown)</span>:
3097 </div>
3098
3099
3100 <div class="docstring"><p><strong><code>renameAttribute(self, oldname, newname)</code></strong></p>
3101
3102 <p>rename a <code><a href="#Variable">Variable</a></code> attribute named <code>oldname</code> to <code>newname</code>.</p>
3103 </div>
3104
3105
3106 </div>
3107 <div id="Variable.assignValue" class="classattr">
3108 <div class="attr function"><a class="headerlink" href="#Variable.assignValue">#&nbsp;&nbsp</a>
3109
3110
3111 <span class="def">def</span>
3112 <span class="name">assignValue</span><span class="signature">(unknown)</span>:
3113 </div>
3114
3115
3116 <div class="docstring"><p><strong><code>assignValue(self, val)</code></strong></p>
3117
3118 <p>assign a value to a scalar variable. Provided for compatibility with
3119 Scientific.IO.NetCDF, can also be done by assigning to an Ellipsis slice ([...]).</p>
3120 </div>
3121
3122
3123 </div>
3124 <div id="Variable.getValue" class="classattr">
3125 <div class="attr function"><a class="headerlink" href="#Variable.getValue">#&nbsp;&nbsp</a>
3126
3127
3128 <span class="def">def</span>
3129 <span class="name">getValue</span><span class="signature">(unknown)</span>:
3130 </div>
3131
3132
3133 <div class="docstring"><p><strong><code>getValue(self)</code></strong></p>
3134
3135 <p>get the value of a scalar variable. Provided for compatibility with
3136 Scientific.IO.NetCDF, can also be done by slicing with an Ellipsis ([...]).</p>
3137 </div>
3138
3139
3140 </div>
3141 <div id="Variable.set_auto_chartostring" class="classattr">
3142 <div class="attr function"><a class="headerlink" href="#Variable.set_auto_chartostring">#&nbsp;&nbsp</a>
3143
3144
3145 <span class="def">def</span>
3146 <span class="name">set_auto_chartostring</span><span class="signature">(unknown)</span>:
3147 </div>
3148
3149
3150 <div class="docstring"><p><strong><code>set_auto_chartostring(self,chartostring)</code></strong></p>
3151
3152 <p>turn on or off automatic conversion of character variable data to and
3153 from numpy fixed length string arrays when the <code>_Encoding</code> variable attribute
3154 is set.</p>
3155
3156 <p>If <code><a href="#Variable.chartostring">chartostring</a></code> is set to <code>True</code>, when data is read from a character variable
3157 (dtype = <code>S1</code>) that has an <code>_Encoding</code> attribute, it is converted to a numpy
3158 fixed length unicode string array (dtype = <code>UN</code>, where <code>N</code> is the length
3159 of the the rightmost dimension of the variable). The value of <code>_Encoding</code>
3160 is the unicode encoding that is used to decode the bytes into strings.</p>
3161
3162 <p>When numpy string data is written to a variable it is converted back to
3163 indiviual bytes, with the number of bytes in each string equalling the
3164 rightmost dimension of the variable.</p>
3165
3166 <p>The default value of <code><a href="#Variable.chartostring">chartostring</a></code> is <code>True</code>
3167 (automatic conversions are performed).</p>
3168 </div>
3169
3170
3171 </div>
3172 <div id="Variable.use_nc_get_vars" class="classattr">
3173 <div class="attr function"><a class="headerlink" href="#Variable.use_nc_get_vars">#&nbsp;&nbsp</a>
3174
3175
3176 <span class="def">def</span>
3177 <span class="name">use_nc_get_vars</span><span class="signature">(unknown)</span>:
3178 </div>
3179
3180
3181 <div class="docstring"><p><strong><code>use_nc_get_vars(self,_use_get_vars)</code></strong></p>
3182
3183 <p>enable the use of netcdf library routine <code>nc_get_vars</code>
3184 to retrieve strided variable slices. By default,
3185 <code>nc_get_vars</code> may not used by default (depending on the
3186 version of the netcdf-c library being used) since it may be
3187 slower than multiple calls to the unstrided read routine <code>nc_get_vara</code>.</p>
3188 </div>
3189
3190
3191 </div>
3192 <div id="Variable.set_auto_maskandscale" class="classattr">
3193 <div class="attr function"><a class="headerlink" href="#Variable.set_auto_maskandscale">#&nbsp;&nbsp</a>
3194
3195
3196 <span class="def">def</span>
3197 <span class="name">set_auto_maskandscale</span><span class="signature">(unknown)</span>:
3198 </div>
3199
3200
3201 <div class="docstring"><p><strong><code>set_auto_maskandscale(self,maskandscale)</code></strong></p>
3202
3203 <p>turn on or off automatic conversion of variable data to and
3204 from masked arrays, automatic packing/unpacking of variable
3205 data using <code>scale_factor</code> and <code>add_offset</code> attributes and
3206 automatic conversion of signed integer data to unsigned integer
3207 data if the <code>_Unsigned</code> attribute exists.</p>
3208
3209 <p>If <code>maskandscale</code> is set to <code>True</code>, when data is read from a variable
3210 it is converted to a masked array if any of the values are exactly
3211 equal to the either the netCDF _FillValue or the value specified by the
3212 missing_value variable attribute. The fill_value of the masked array
3213 is set to the missing_value attribute (if it exists), otherwise
3214 the netCDF _FillValue attribute (which has a default value
3215 for each data type). If the variable has no missing_value attribute, the
3216 _FillValue is used instead. If the variable has valid_min/valid_max and
3217 missing_value attributes, data outside the specified range will be masked.
3218 When data is written to a variable, the masked
3219 array is converted back to a regular numpy array by replacing all the
3220 masked values by the missing_value attribute of the variable (if it
3221 exists). If the variable has no missing_value attribute, the _FillValue
3222 is used instead. </p>
3223
3224 <p>If <code>maskandscale</code> is set to <code>True</code>, and the variable has a
3225 <code>scale_factor</code> or an <code>add_offset</code> attribute, then data read
3226 from that variable is unpacked using::</p>
3227
3228 <pre><code>data = self.scale_factor*data + self.add_offset
3229 </code></pre>
3230
3231 <p>When data is written to a variable it is packed using::</p>
3232
3233 <pre><code>data = (data - self.add_offset)/self.scale_factor
3234 </code></pre>
3235
3236 <p>If either scale_factor is present, but add_offset is missing, add_offset
3237 is assumed zero. If add_offset is present, but scale_factor is missing,
3238 scale_factor is assumed to be one.
3239 For more information on how <code>scale_factor</code> and <code>add_offset</code> can be
3240 used to provide simple compression, see the
3241 <a href="http://www.esrl.noaa.gov/psl/data/gridded/conventions/cdc_netcdf_standard.shtml">PSL metadata conventions</a>.</p>
3242
3243 <p>In addition, if <code>maskandscale</code> is set to <code>True</code>, and if the variable has an
3244 attribute <code>_Unsigned</code> set, and the variable has a signed integer data type,
3245 a view to the data is returned with the corresponding unsigned integer data type.
3246 This convention is used by the netcdf-java library to save unsigned integer
3247 data in <code>NETCDF3</code> or <code>NETCDF4_CLASSIC</code> files (since the <code>NETCDF3</code>
3248 data model does not have unsigned integer data types).</p>
3249
3250 <p>The default value of <code>maskandscale</code> is <code>True</code>
3251 (automatic conversions are performed).</p>
3252 </div>
3253
3254
3255 </div>
3256 <div id="Variable.set_auto_scale" class="classattr">
3257 <div class="attr function"><a class="headerlink" href="#Variable.set_auto_scale">#&nbsp;&nbsp</a>
3258
3259
3260 <span class="def">def</span>
3261 <span class="name">set_auto_scale</span><span class="signature">(unknown)</span>:
3262 </div>
3263
3264
3265 <div class="docstring"><p><strong><code>set_auto_scale(self,scale)</code></strong></p>
3266
3267 <p>turn on or off automatic packing/unpacking of variable
3268 data using <code>scale_factor</code> and <code>add_offset</code> attributes.
3269 Also turns on and off automatic conversion of signed integer data
3270 to unsigned integer data if the variable has an <code>_Unsigned</code>
3271 attribute.</p>
3272
3273 <p>If <code><a href="#Variable.scale">scale</a></code> is set to <code>True</code>, and the variable has a
3274 <code>scale_factor</code> or an <code>add_offset</code> attribute, then data read
3275 from that variable is unpacked using::</p>
3276
3277 <pre><code>data = self.scale_factor*data + self.add_offset
3278 </code></pre>
3279
3280 <p>When data is written to a variable it is packed using::</p>
3281
3282 <pre><code>data = (data - self.add_offset)/self.scale_factor
3283 </code></pre>
3284
3285 <p>If either scale_factor is present, but add_offset is missing, add_offset
3286 is assumed zero. If add_offset is present, but scale_factor is missing,
3287 scale_factor is assumed to be one.
3288 For more information on how <code>scale_factor</code> and <code>add_offset</code> can be
3289 used to provide simple compression, see the
3290 <a href="http://www.esrl.noaa.gov/psl/data/gridded/conventions/cdc_netcdf_standard.shtml">PSL metadata conventions</a>.</p>
3291
3292 <p>In addition, if <code><a href="#Variable.scale">scale</a></code> is set to <code>True</code>, and if the variable has an
3293 attribute <code>_Unsigned</code> set, and the variable has a signed integer data type,
3294 a view to the data is returned with the corresponding unsigned integer datatype.
3295 This convention is used by the netcdf-java library to save unsigned integer
3296 data in <code>NETCDF3</code> or <code>NETCDF4_CLASSIC</code> files (since the <code>NETCDF3</code>
3297 data model does not have unsigned integer data types).</p>
3298
3299 <p>The default value of <code><a href="#Variable.scale">scale</a></code> is <code>True</code>
3300 (automatic conversions are performed).</p>
3301 </div>
3302
3303
3304 </div>
3305 <div id="Variable.set_auto_mask" class="classattr">
3306 <div class="attr function"><a class="headerlink" href="#Variable.set_auto_mask">#&nbsp;&nbsp</a>
3307
3308
3309 <span class="def">def</span>
3310 <span class="name">set_auto_mask</span><span class="signature">(unknown)</span>:
3311 </div>
3312
3313
3314 <div class="docstring"><p><strong><code>set_auto_mask(self,mask)</code></strong></p>
3315
3316 <p>turn on or off automatic conversion of variable data to and
3317 from masked arrays .</p>
3318
3319 <p>If <code><a href="#Variable.mask">mask</a></code> is set to <code>True</code>, when data is read from a variable
3320 it is converted to a masked array if any of the values are exactly
3321 equal to the either the netCDF _FillValue or the value specified by the
3322 missing_value variable attribute. The fill_value of the masked array
3323 is set to the missing_value attribute (if it exists), otherwise
3324 the netCDF _FillValue attribute (which has a default value
3325 for each data type). If the variable has no missing_value attribute, the
3326 _FillValue is used instead. If the variable has valid_min/valid_max and
3327 missing_value attributes, data outside the specified range will be masked.
3328 When data is written to a variable, the masked
3329 array is converted back to a regular numpy array by replacing all the
3330 masked values by the missing_value attribute of the variable (if it
3331 exists). If the variable has no missing_value attribute, the _FillValue
3332 is used instead. </p>
3333
3334 <p>The default value of <code><a href="#Variable.mask">mask</a></code> is <code>True</code>
3335 (automatic conversions are performed).</p>
3336 </div>
3337
3338
3339 </div>
3340 <div id="Variable.set_always_mask" class="classattr">
3341 <div class="attr function"><a class="headerlink" href="#Variable.set_always_mask">#&nbsp;&nbsp</a>
3342
3343
3344 <span class="def">def</span>
3345 <span class="name">set_always_mask</span><span class="signature">(unknown)</span>:
3346 </div>
3347
3348
3349 <div class="docstring"><p><strong><code>set_always_mask(self,always_mask)</code></strong></p>
3350
3351 <p>turn on or off conversion of data without missing values to regular
3352 numpy arrays.</p>
3353
3354 <p><code><a href="#Variable.always_mask">always_mask</a></code> is a Boolean determining if automatic conversion of
3355 masked arrays with no missing values to regular numpy arrays shall be
3356 applied. Default is True. Set to False to restore the default behaviour
3357 in versions prior to 1.4.1 (numpy array returned unless missing values are present,
3358 otherwise masked array returned).</p>
3359 </div>
3360
3361
3362 </div>
3363 <div id="Variable.set_ncstring_attrs" class="classattr">
3364 <div class="attr function"><a class="headerlink" href="#Variable.set_ncstring_attrs">#&nbsp;&nbsp</a>
3365
3366
3367 <span class="def">def</span>
3368 <span class="name">set_ncstring_attrs</span><span class="signature">(unknown)</span>:
3369 </div>
3370
3371
3372 <div class="docstring"><p><strong><code>set_always_mask(self,ncstring_attrs)</code></strong></p>
3373
3374 <p>turn on or off creating NC_STRING string attributes.</p>
3375
3376 <p>If <code>ncstring_attrs</code> is set to <code>True</code> then text attributes will be variable-length
3377 NC_STRINGs.</p>
3378
3379 <p>The default value of <code>ncstring_attrs</code> is <code>False</code> (writing ascii text attributes as
3380 NC_CHAR).</p>
3381 </div>
3382
3383
3384 </div>
3385 <div id="Variable.set_collective" class="classattr">
3386 <div class="attr function"><a class="headerlink" href="#Variable.set_collective">#&nbsp;&nbsp</a>
3387
3388
3389 <span class="def">def</span>
3390 <span class="name">set_collective</span><span class="signature">(unknown)</span>:
3391 </div>
3392
3393
3394 <div class="docstring"><p><strong><code>set_collective(self,True_or_False)</code></strong></p>
3395
3396 <p>turn on or off collective parallel IO access. Ignored if file is not
3397 open for parallel access.</p>
3398 </div>
3399
3400
3401 </div>
3402 <div id="Variable.get_dims" class="classattr">
3403 <div class="attr function"><a class="headerlink" href="#Variable.get_dims">#&nbsp;&nbsp</a>
3404
3405
3406 <span class="def">def</span>
3407 <span class="name">get_dims</span><span class="signature">(unknown)</span>:
3408 </div>
3409
3410
3411 <div class="docstring"><p><strong><code>get_dims(self)</code></strong></p>
3412
3413 <p>return a tuple of <code><a href="#Dimension">Dimension</a></code> instances associated with this
3414 <code><a href="#Variable">Variable</a></code>.</p>
3415 </div>
3416
3417
3418 </div>
3419 <div id="Variable.name" class="classattr">
3420 <div class="attr variable"><a class="headerlink" href="#Variable.name">#&nbsp;&nbsp</a>
3421
3422 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3423 </div>
3424
3425 <div class="docstring"><p>string name of Variable instance</p>
3426 </div>
3427
3428
3429 </div>
3430 <div id="Variable.datatype" class="classattr">
3431 <div class="attr variable"><a class="headerlink" href="#Variable.datatype">#&nbsp;&nbsp</a>
3432
3433 <span class="name">datatype</span><span class="default_value"> = &lt;attribute &#39;datatype&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3434 </div>
3435
3436 <div class="docstring"><p>numpy data type (for primitive data types) or
3437 VLType/CompoundType/EnumType instance
3438 (for compound, vlen or enum data types)</p>
3439 </div>
3440
3441
3442 </div>
3443 <div id="Variable.shape" class="classattr">
3444 <div class="attr variable"><a class="headerlink" href="#Variable.shape">#&nbsp;&nbsp</a>
3445
3446 <span class="name">shape</span><span class="default_value"> = &lt;attribute &#39;shape&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3447 </div>
3448
3449 <div class="docstring"><p>find current sizes of all variable dimensions</p>
3450 </div>
3451
3452
3453 </div>
3454 <div id="Variable.size" class="classattr">
3455 <div class="attr variable"><a class="headerlink" href="#Variable.size">#&nbsp;&nbsp</a>
3456
3457 <span class="name">size</span><span class="default_value"> = &lt;attribute &#39;size&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3458 </div>
3459
3460 <div class="docstring"><p>Return the number of stored elements.</p>
3461 </div>
3462
3463
3464 </div>
3465 <div id="Variable.dimensions" class="classattr">
3466 <div class="attr variable"><a class="headerlink" href="#Variable.dimensions">#&nbsp;&nbsp</a>
3467
3468 <span class="name">dimensions</span><span class="default_value"> = &lt;attribute &#39;dimensions&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3469 </div>
3470
3471 <div class="docstring"><p>get variables's dimension names</p>
3472 </div>
3473
3474
3475 </div>
3476 <div id="Variable.ndim" class="classattr">
3477 <div class="attr variable"><a class="headerlink" href="#Variable.ndim">#&nbsp;&nbsp</a>
3478
3479 <span class="name">ndim</span><span class="default_value"> = &lt;attribute &#39;ndim&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3480 </div>
3481
3482
3483
3484 </div>
3485 <div id="Variable.dtype" class="classattr">
3486 <div class="attr variable"><a class="headerlink" href="#Variable.dtype">#&nbsp;&nbsp</a>
3487
3488 <span class="name">dtype</span><span class="default_value"> = &lt;attribute &#39;dtype&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3489 </div>
3490
3491
3492
3493 </div>
3494 <div id="Variable.mask" class="classattr">
3495 <div class="attr variable"><a class="headerlink" href="#Variable.mask">#&nbsp;&nbsp</a>
3496
3497 <span class="name">mask</span><span class="default_value"> = &lt;attribute &#39;mask&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3498 </div>
3499
3500
3501
3502 </div>
3503 <div id="Variable.scale" class="classattr">
3504 <div class="attr variable"><a class="headerlink" href="#Variable.scale">#&nbsp;&nbsp</a>
3505
3506 <span class="name">scale</span><span class="default_value"> = &lt;attribute &#39;scale&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3507 </div>
3508
3509
3510
3511 </div>
3512 <div id="Variable.always_mask" class="classattr">
3513 <div class="attr variable"><a class="headerlink" href="#Variable.always_mask">#&nbsp;&nbsp</a>
3514
3515 <span class="name">always_mask</span><span class="default_value"> = &lt;attribute &#39;always_mask&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3516 </div>
3517
3518
3519
3520 </div>
3521 <div id="Variable.chartostring" class="classattr">
3522 <div class="attr variable"><a class="headerlink" href="#Variable.chartostring">#&nbsp;&nbsp</a>
3523
3524 <span class="name">chartostring</span><span class="default_value"> = &lt;attribute &#39;chartostring&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3525 </div>
3526
3527
3528
3529 </div>
3530 </section>
3531 <section id="Dimension">
3532 <div class="attr class">
3533 <a class="headerlink" href="#Dimension">#&nbsp;&nbsp</a>
3534
3535
3536 <span class="def">class</span>
3537 <span class="name">Dimension</span>:
3538 </div>
3539
3540
3541 <div class="docstring"><p>A netCDF <code><a href="#Dimension">Dimension</a></code> is used to describe the coordinates of a <code><a href="#Variable">Variable</a></code>.
3542 See <code><a href="#Dimension.__init__">Dimension.__init__</a></code> for more details.</p>
3543
3544 <p>The current maximum size of a <code><a href="#Dimension">Dimension</a></code> instance can be obtained by
3545 calling the python <code>len</code> function on the <code><a href="#Dimension">Dimension</a></code> instance. The
3546 <code><a href="#Dimension.isunlimited">Dimension.isunlimited</a></code> method of a <code><a href="#Dimension">Dimension</a></code> instance can be used to
3547 determine if the dimension is unlimited.</p>
3548
3549 <p>Read-only class variables:</p>
3550
3551 <p><strong><code><a href="#Dimension.name">name</a></code></strong>: String name, used when creating a <code><a href="#Variable">Variable</a></code> with
3552 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code>.</p>
3553
3554 <p><strong><code><a href="#Dimension.size">size</a></code></strong>: Current <code><a href="#Dimension">Dimension</a></code> size (same as <code>len(d)</code>, where <code>d</code> is a
3555 <code><a href="#Dimension">Dimension</a></code> instance).</p>
3556 </div>
3557
3558
3559 <div id="Dimension.__init__" class="classattr">
3560 <div class="attr function"><a class="headerlink" href="#Dimension.__init__">#&nbsp;&nbsp</a>
3561
3562
3563 <span class="name">Dimension</span><span class="signature">()</span>
3564 </div>
3565
3566
3567 <div class="docstring"><p><strong><code>__init__(self, group, name, size=None)</code></strong></p>
3568
3569 <p><code><a href="#Dimension">Dimension</a></code> constructor.</p>
3570
3571 <p><strong><code><a href="#Dimension.group">group</a></code></strong>: <code><a href="#Group">Group</a></code> instance to associate with dimension.</p>
3572
3573 <p><strong><code><a href="#Dimension.name">name</a></code></strong>: Name of the dimension.</p>
3574
3575 <p><strong><code><a href="#Dimension.size">size</a></code></strong>: Size of the dimension. <code>None</code> or 0 means unlimited. (Default <code>None</code>).</p>
3576
3577 <p><strong><em>Note</em></strong>: <code><a href="#Dimension">Dimension</a></code> instances should be created using the
3578 <code><a href="#Dataset.createDimension">Dataset.createDimension</a></code> method of a <code><a href="#Group">Group</a></code> or
3579 <code><a href="#Dataset">Dataset</a></code> instance, not using <code><a href="#Dimension.__init__">Dimension.__init__</a></code> directly.</p>
3580 </div>
3581
3582
3583 </div>
3584 <div id="Dimension.group" class="classattr">
3585 <div class="attr function"><a class="headerlink" href="#Dimension.group">#&nbsp;&nbsp</a>
3586
3587
3588 <span class="def">def</span>
3589 <span class="name">group</span><span class="signature">(unknown)</span>:
3590 </div>
3591
3592
3593 <div class="docstring"><p><strong><code>group(self)</code></strong></p>
3594
3595 <p>return the group that this <code><a href="#Dimension">Dimension</a></code> is a member of.</p>
3596 </div>
3597
3598
3599 </div>
3600 <div id="Dimension.isunlimited" class="classattr">
3601 <div class="attr function"><a class="headerlink" href="#Dimension.isunlimited">#&nbsp;&nbsp</a>
3602
3603
3604 <span class="def">def</span>
3605 <span class="name">isunlimited</span><span class="signature">(unknown)</span>:
3606 </div>
3607
3608
3609 <div class="docstring"><p><strong><code>isunlimited(self)</code></strong></p>
3610
3611 <p>returns <code>True</code> if the <code><a href="#Dimension">Dimension</a></code> instance is unlimited, <code>False</code> otherwise.</p>
3612 </div>
3613
3614
3615 </div>
3616 <div id="Dimension.name" class="classattr">
3617 <div class="attr variable"><a class="headerlink" href="#Dimension.name">#&nbsp;&nbsp</a>
3618
3619 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#_netCDF4.Dimension">netCDF4._netCDF4.Dimension</a>&#39; objects&gt;</span>
3620 </div>
3621
3622 <div class="docstring"><p>string name of Dimension instance</p>
3623 </div>
3624
3625
3626 </div>
3627 <div id="Dimension.size" class="classattr">
3628 <div class="attr variable"><a class="headerlink" href="#Dimension.size">#&nbsp;&nbsp</a>
3629
3630 <span class="name">size</span><span class="default_value"> = &lt;attribute &#39;size&#39; of &#39;<a href="#_netCDF4.Dimension">netCDF4._netCDF4.Dimension</a>&#39; objects&gt;</span>
3631 </div>
3632
3633 <div class="docstring"><p>current size of Dimension (calls <code>len</code> on Dimension instance)</p>
3634 </div>
3635
27013636
27023637 </div>
27033638 </section>
27073642
27083643
27093644 <span class="def">class</span>
2710 <span class="name">Group</span>(<span class="base"><a href="#Dataset">Dataset</a></span>):
3645 <span class="name">Group</span><wbr>(<span class="base"><a href="#Dataset">netCDF4.Dataset</a></span>):
27113646 </div>
27123647
27133648
27143649 <div class="docstring"><p>Groups define a hierarchical namespace within a netCDF file. They are
2715 analogous to directories in a unix filesystem. Each <a href="#Group">Group</a> behaves like
2716 a <a href="#Dataset">Dataset</a> within a Dataset, and can contain it's own variables,
2717 dimensions and attributes (and other Groups). See <a href="#<a href="#Group.__init__">Group.__init__</a>"><a href="#Group.__init__">Group.__init__</a></a>
3650 analogous to directories in a unix filesystem. Each <code><a href="#Group">Group</a></code> behaves like
3651 a <code><a href="#Dataset">Dataset</a></code> within a Dataset, and can contain it's own variables,
3652 dimensions and attributes (and other Groups). See <code><a href="#Group.__init__">Group.__init__</a></code>
27183653 for more details.</p>
27193654
2720 <p><a href="#Group">Group</a> inherits from <a href="#Dataset">Dataset</a>, so all the
2721 <a href="#Dataset">Dataset</a> class methods and variables are available
2722 to a <a href="#Group">Group</a> instance (except the <code>close</code> method).</p>
3655 <p><code><a href="#Group">Group</a></code> inherits from <code><a href="#Dataset">Dataset</a></code>, so all the
3656 <code><a href="#Dataset">Dataset</a></code> class methods and variables are available
3657 to a <code><a href="#Group">Group</a></code> instance (except the <code><a href="#Group.close">close</a></code> method).</p>
27233658
27243659 <p>Additional read-only class variables:</p>
27253660
2726 <p><strong><code>name</code></strong>: String describing the group name.</p>
3661 <p><strong><code><a href="#Group.name">name</a></code></strong>: String describing the group name.</p>
27273662 </div>
27283663
27293664
27313666 <div class="attr function"><a class="headerlink" href="#Group.__init__">#&nbsp;&nbsp</a>
27323667
27333668
2734 <span class="name">Group</span><span class="signature">(unknown)</span> </div>
3669 <span class="name">Group</span><span class="signature">()</span>
3670 </div>
27353671
27363672
27373673 <div class="docstring"><p><strong><code>__init__(self, parent, name)</code></strong>
2738 <a href="#Group">Group</a> constructor.</p>
2739
2740 <p><strong><code>parent</code></strong>: <a href="#Group">Group</a> instance for the parent group. If being created
2741 in the root group, use a <a href="#Dataset">Dataset</a> instance.</p>
2742
2743 <p><strong><code>name</code></strong>: - Name of the group.</p>
2744
2745 <p><strong><em>Note</em></strong>: <a href="#Group">Group</a> instances should be created using the
2746 <a href="#<a href="#Dataset.createGroup">Dataset.createGroup</a>"><a href="#Dataset.createGroup">Dataset.createGroup</a></a> method of a <a href="#Dataset">Dataset</a> instance, or
2747 another <a href="#Group">Group</a> instance, not using this class directly.</p>
3674 <code><a href="#Group">Group</a></code> constructor.</p>
3675
3676 <p><strong><code><a href="#Group.parent">parent</a></code></strong>: <code><a href="#Group">Group</a></code> instance for the parent group. If being created
3677 in the root group, use a <code><a href="#Dataset">Dataset</a></code> instance.</p>
3678
3679 <p><strong><code><a href="#Group.name">name</a></code></strong>: - Name of the group.</p>
3680
3681 <p><strong><em>Note</em></strong>: <code><a href="#Group">Group</a></code> instances should be created using the
3682 <code><a href="#Dataset.createGroup">Dataset.createGroup</a></code> method of a <code><a href="#Dataset">Dataset</a></code> instance, or
3683 another <code><a href="#Group">Group</a></code> instance, not using this class directly.</p>
27483684 </div>
27493685
27503686
27603696
27613697 <div class="docstring"><p><strong><code>close(self)</code></strong></p>
27623698
2763 <p>overrides <a href="#Dataset">Dataset</a> close method which does not apply to <a href="#Group">Group</a>
3699 <p>overrides <code><a href="#Dataset">Dataset</a></code> close method which does not apply to <code><a href="#Group">Group</a></code>
27643700 instances, raises IOError.</p>
27653701 </div>
27663702
27693705 <div class="inherited">
27703706 <h5>Inherited Members</h5>
27713707 <dl>
2772 <div><dt><a href="#Dataset">netCDF4._netCDF4.Dataset</a></dt>
3708 <div><dt><a href="#Dataset">Dataset</a></dt>
27733709 <dd id="Group.filepath" class="function"><a href="#Dataset.filepath">filepath</a></dd>
27743710 <dd id="Group.isopen" class="function"><a href="#Dataset.isopen">isopen</a></dd>
27753711 <dd id="Group.sync" class="function"><a href="#Dataset.sync">sync</a></dd>
28183754 </dl>
28193755 </div>
28203756 </section>
2821 <section id="Dimension">
2822 <div class="attr class">
2823 <a class="headerlink" href="#Dimension">#&nbsp;&nbsp</a>
2824
2825
2826 <span class="def">class</span>
2827 <span class="name">Dimension</span>:
2828 </div>
2829
2830
2831 <div class="docstring"><p>A netCDF <a href="#Dimension">Dimension</a> is used to describe the coordinates of a <a href="#Variable">Variable</a>.
2832 See <a href="#<a href="#Dimension.__init__">Dimension.__init__</a>"><a href="#Dimension.__init__">Dimension.__init__</a></a> for more details.</p>
2833
2834 <p>The current maximum size of a <a href="#Dimension">Dimension</a> instance can be obtained by
2835 calling the python <code>len</code> function on the <a href="#Dimension">Dimension</a> instance. The
2836 <a href="#<a href="#Dimension.isunlimited">Dimension.isunlimited</a>"><a href="#Dimension.isunlimited">Dimension.isunlimited</a></a> method of a <a href="#Dimension">Dimension</a> instance can be used to
2837 determine if the dimension is unlimited.</p>
2838
2839 <p>Read-only class variables:</p>
2840
2841 <p><strong><code>name</code></strong>: String name, used when creating a <a href="#Variable">Variable</a> with
2842 <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a>.</p>
2843
2844 <p><strong><code>size</code></strong>: Current <a href="#Dimension">Dimension</a> size (same as <code>len(d)</code>, where <code>d</code> is a
2845 <a href="#Dimension">Dimension</a> instance).</p>
2846 </div>
2847
2848
2849 <div id="Dimension.__init__" class="classattr">
2850 <div class="attr function"><a class="headerlink" href="#Dimension.__init__">#&nbsp;&nbsp</a>
2851
2852
2853 <span class="name">Dimension</span><span class="signature">(unknown)</span> </div>
2854
2855
2856 <div class="docstring"><p><strong><code>__init__(self, group, name, size=None)</code></strong></p>
2857
2858 <p><a href="#Dimension">Dimension</a> constructor.</p>
2859
2860 <p><strong><code>group</code></strong>: <a href="#Group">Group</a> instance to associate with dimension.</p>
2861
2862 <p><strong><code>name</code></strong>: Name of the dimension.</p>
2863
2864 <p><strong><code>size</code></strong>: Size of the dimension. <code>None</code> or 0 means unlimited. (Default <code>None</code>).</p>
2865
2866 <p><strong><em>Note</em></strong>: <a href="#Dimension">Dimension</a> instances should be created using the
2867 <a href="#<a href="#Dataset.createDimension">Dataset.createDimension</a>"><a href="#Dataset.createDimension">Dataset.createDimension</a></a> method of a <a href="#Group">Group</a> or
2868 <a href="#Dataset">Dataset</a> instance, not using <a href="#<a href="#Dimension.__init__">Dimension.__init__</a>"><a href="#Dimension.__init__">Dimension.__init__</a></a> directly.</p>
2869 </div>
2870
2871
2872 </div>
2873 <div id="Dimension.group" class="classattr">
2874 <div class="attr function"><a class="headerlink" href="#Dimension.group">#&nbsp;&nbsp</a>
2875
2876
2877 <span class="def">def</span>
2878 <span class="name">group</span><span class="signature">(unknown)</span>:
2879 </div>
2880
2881
2882 <div class="docstring"><p><strong><code>group(self)</code></strong></p>
2883
2884 <p>return the group that this <a href="#Dimension">Dimension</a> is a member of.</p>
2885 </div>
2886
2887
2888 </div>
2889 <div id="Dimension.isunlimited" class="classattr">
2890 <div class="attr function"><a class="headerlink" href="#Dimension.isunlimited">#&nbsp;&nbsp</a>
2891
2892
2893 <span class="def">def</span>
2894 <span class="name">isunlimited</span><span class="signature">(unknown)</span>:
2895 </div>
2896
2897
2898 <div class="docstring"><p><strong><code>isunlimited(self)</code></strong></p>
2899
2900 <p>returns <code>True</code> if the <a href="#Dimension">Dimension</a> instance is unlimited, <code>False</code> otherwise.</p>
2901 </div>
2902
2903
2904 </div>
2905 <div id="Dimension.name" class="classattr">
2906 <div class="attr variable"><a class="headerlink" href="#Dimension.name">#&nbsp;&nbsp</a>
2907
2908 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#Dimension">netCDF4._netCDF4.Dimension</a>&#39; objects&gt;</span>
2909 </div>
2910
2911
2912
2913 </div>
2914 <div id="Dimension.size" class="classattr">
2915 <div class="attr variable"><a class="headerlink" href="#Dimension.size">#&nbsp;&nbsp</a>
2916
2917 <span class="name">size</span><span class="default_value"> = &lt;attribute &#39;size&#39; of &#39;<a href="#Dimension">netCDF4._netCDF4.Dimension</a>&#39; objects&gt;</span>
2918 </div>
2919
2920
2921
2922 </div>
2923 </section>
2924 <section id="Variable">
2925 <div class="attr class">
2926 <a class="headerlink" href="#Variable">#&nbsp;&nbsp</a>
2927
2928
2929 <span class="def">class</span>
2930 <span class="name">Variable</span>:
2931 </div>
2932
2933
2934 <div class="docstring"><p>A netCDF <a href="#Variable">Variable</a> is used to read and write netCDF data. They are
2935 analogous to numpy array objects. See <a href="#<a href="#Variable.__init__">Variable.__init__</a>"><a href="#Variable.__init__">Variable.__init__</a></a> for more
2936 details.</p>
2937
2938 <p>A list of attribute names corresponding to netCDF attributes defined for
2939 the variable can be obtained with the <a href="#<a href="#Variable.ncattrs">Variable.ncattrs</a>"><a href="#Variable.ncattrs">Variable.ncattrs</a></a> method. These
2940 attributes can be created by assigning to an attribute of the
2941 <a href="#Variable">Variable</a> instance. A dictionary containing all the netCDF attribute
2942 name/value pairs is provided by the <code>__dict__</code> attribute of a
2943 <a href="#Variable">Variable</a> instance.</p>
2944
2945 <p>The following class variables are read-only:</p>
2946
2947 <p><strong><code>dimensions</code></strong>: A tuple containing the names of the
2948 dimensions associated with this variable.</p>
2949
2950 <p><strong><code>dtype</code></strong>: A numpy dtype object describing the
2951 variable's data type.</p>
2952
2953 <p><strong><code>ndim</code></strong>: The number of variable dimensions.</p>
2954
2955 <p><strong><code>shape</code></strong>: A tuple with the current shape (length of all dimensions).</p>
2956
2957 <p><strong><code>scale</code></strong>: If True, <code>scale_factor</code> and <code>add_offset</code> are
2958 applied, and signed integer data is automatically converted to
2959 unsigned integer data if the <code>_Unsigned</code> attribute is set.
2960 Default is <code>True</code>, can be reset using <a href="#<a href="#Variable.set_auto_scale">Variable.set_auto_scale</a>"><a href="#Variable.set_auto_scale">Variable.set_auto_scale</a></a> and
2961 <a href="#<a href="#Variable.set_auto_maskandscale">Variable.set_auto_maskandscale</a>"><a href="#Variable.set_auto_maskandscale">Variable.set_auto_maskandscale</a></a> methods.</p>
2962
2963 <p><strong><code>mask</code></strong>: If True, data is automatically converted to/from masked
2964 arrays when missing values or fill values are present. Default is <code>True</code>, can be
2965 reset using <a href="#<a href="#Variable.set_auto_mask">Variable.set_auto_mask</a>"><a href="#Variable.set_auto_mask">Variable.set_auto_mask</a></a> and <a href="#<a href="#Variable.set_auto_maskandscale">Variable.set_auto_maskandscale</a>"><a href="#Variable.set_auto_maskandscale">Variable.set_auto_maskandscale</a></a>
2966 methods.</p>
2967
2968 <p><strong><code><a href="#chartostring">chartostring</a></code></strong>: If True, data is automatically converted to/from character
2969 arrays to string arrays when the <code>_Encoding</code> variable attribute is set.
2970 Default is <code>True</code>, can be reset using
2971 <a href="#<a href="#Variable.set_auto_chartostring">Variable.set_auto_chartostring</a>"><a href="#Variable.set_auto_chartostring">Variable.set_auto_chartostring</a></a> method.</p>
2972
2973 <p><strong><code>least_significant_digit</code></strong>: Describes the power of ten of the
2974 smallest decimal place in the data the contains a reliable value. Data is
2975 truncated to this decimal place when it is assigned to the <a href="#Variable">Variable</a>
2976 instance. If <code>None</code>, the data is not truncated.</p>
2977
2978 <p><strong><code>__orthogonal_indexing__</code></strong>: Always <code>True</code>. Indicates to client code
2979 that the object supports 'orthogonal indexing', which means that slices
2980 that are 1d arrays or lists slice along each dimension independently. This
2981 behavior is similar to Fortran or Matlab, but different than numpy.</p>
2982
2983 <p><strong><code>datatype</code></strong>: numpy data type (for primitive data types) or VLType/CompoundType
2984 instance (for compound or vlen data types).</p>
2985
2986 <p><strong><code>name</code></strong>: String name.</p>
2987
2988 <p><strong><code>size</code></strong>: The number of stored elements.</p>
2989 </div>
2990
2991
2992 <div id="Variable.__init__" class="classattr">
2993 <div class="attr function"><a class="headerlink" href="#Variable.__init__">#&nbsp;&nbsp</a>
2994
2995
2996 <span class="name">Variable</span><span class="signature">(unknown)</span> </div>
2997
2998
2999 <div class="docstring"><p><strong><code>__init__(self, group, name, datatype, dimensions=(), zlib=False,
3000 complevel=4, shuffle=True, fletcher32=False, contiguous=False,
3001 chunksizes=None, endian='native',
3002 least_significant_digit=None,fill_value=None,chunk_cache=None)</code></strong></p>
3003
3004 <p><a href="#Variable">Variable</a> constructor.</p>
3005
3006 <p><strong><code>group</code></strong>: <a href="#Group">Group</a> or <a href="#Dataset">Dataset</a> instance to associate with variable.</p>
3007
3008 <p><strong><code>name</code></strong>: Name of the variable.</p>
3009
3010 <p><strong><code>datatype</code></strong>: <a href="#Variable">Variable</a> data type. Can be specified by providing a
3011 numpy dtype object, or a string that describes a numpy dtype object.
3012 Supported values, corresponding to <code>str</code> attribute of numpy dtype
3013 objects, include <code>'f4'</code> (32-bit floating point), <code>'f8'</code> (64-bit floating
3014 point), <code>'i4'</code> (32-bit signed integer), <code>'i2'</code> (16-bit signed integer),
3015 <code>'i8'</code> (64-bit signed integer), <code>'i4'</code> (8-bit signed integer), <code>'i1'</code>
3016 (8-bit signed integer), <code>'u1'</code> (8-bit unsigned integer), <code>'u2'</code> (16-bit
3017 unsigned integer), <code>'u4'</code> (32-bit unsigned integer), <code>'u8'</code> (64-bit
3018 unsigned integer), or <code>'S1'</code> (single-character string). From
3019 compatibility with Scientific.IO.NetCDF, the old Numeric single character
3020 typecodes can also be used (<code>'f'</code> instead of <code>'f4'</code>, <code>'d'</code> instead of
3021 <code>'f8'</code>, <code>'h'</code> or <code>'s'</code> instead of <code>'i2'</code>, <code>'b'</code> or <code>'B'</code> instead of
3022 <code>'i1'</code>, <code>'c'</code> instead of <code>'S1'</code>, and <code>'i'</code> or <code>'l'</code> instead of
3023 <code>'i4'</code>). <code>datatype</code> can also be a <a href="#CompoundType">CompoundType</a> instance
3024 (for a structured, or compound array), a <a href="#VLType">VLType</a> instance
3025 (for a variable-length array), or the python <code>str</code> builtin
3026 (for a variable-length string array). Numpy string and unicode datatypes with
3027 length greater than one are aliases for <code>str</code>.</p>
3028
3029 <p><strong><code>dimensions</code></strong>: a tuple containing the variable's dimension names
3030 (defined previously with <code>createDimension</code>). Default is an empty tuple
3031 which means the variable is a scalar (and therefore has no dimensions).</p>
3032
3033 <p><strong><code>zlib</code></strong>: if <code>True</code>, data assigned to the <a href="#Variable">Variable</a>
3034 instance is compressed on disk. Default <code>False</code>.</p>
3035
3036 <p><strong><code>complevel</code></strong>: the level of zlib compression to use (1 is the fastest,
3037 but poorest compression, 9 is the slowest but best compression). Default 4.
3038 Ignored if <code>zlib=False</code>.</p>
3039
3040 <p><strong><code>shuffle</code></strong>: if <code>True</code>, the HDF5 shuffle filter is applied
3041 to improve compression. Default <code>True</code>. Ignored if <code>zlib=False</code>.</p>
3042
3043 <p><strong><code>fletcher32</code></strong>: if <code>True</code> (default <code>False</code>), the Fletcher32 checksum
3044 algorithm is used for error detection.</p>
3045
3046 <p><strong><code>contiguous</code></strong>: if <code>True</code> (default <code>False</code>), the variable data is
3047 stored contiguously on disk. Default <code>False</code>. Setting to <code>True</code> for
3048 a variable with an unlimited dimension will trigger an error.</p>
3049
3050 <p><strong><code>chunksizes</code></strong>: Can be used to specify the HDF5 chunksizes for each
3051 dimension of the variable. A detailed discussion of HDF chunking and I/O
3052 performance is available
3053 <a href="http://www.hdfgroup.org/HDF5/doc/H5.user/Chunking.html">here</a>.
3054 Basically, you want the chunk size for each dimension to match as
3055 closely as possible the size of the data block that users will read
3056 from the file. <code>chunksizes</code> cannot be set if <code>contiguous=True</code>.</p>
3057
3058 <p><strong><code>endian</code></strong>: Can be used to control whether the
3059 data is stored in little or big endian format on disk. Possible
3060 values are <code>little, big</code> or <code>native</code> (default). The library
3061 will automatically handle endian conversions when the data is read,
3062 but if the data is always going to be read on a computer with the
3063 opposite format as the one used to create the file, there may be
3064 some performance advantage to be gained by setting the endian-ness.
3065 For netCDF 3 files (that don't use HDF5), only <code>endian='native'</code> is allowed.</p>
3066
3067 <p>The <code>zlib, complevel, shuffle, fletcher32, contiguous</code> and <code>chunksizes</code>
3068 keywords are silently ignored for netCDF 3 files that do not use HDF5.</p>
3069
3070 <p><strong><code>least_significant_digit</code></strong>: If specified, variable data will be
3071 truncated (quantized). In conjunction with <code>zlib=True</code> this produces
3072 'lossy', but significantly more efficient compression. For example, if
3073 <code>least_significant_digit=1</code>, data will be quantized using
3074 around(scale<em>data)/scale, where scale = 2</em>*bits, and bits is determined
3075 so that a precision of 0.1 is retained (in this case bits=4). Default is
3076 <code>None</code>, or no quantization.</p>
3077
3078 <p><strong><code>fill_value</code></strong>: If specified, the default netCDF <code>_FillValue</code> (the
3079 value that the variable gets filled with before any data is written to it)
3080 is replaced with this value. If fill_value is set to <code>False</code>, then
3081 the variable is not pre-filled. The default netCDF fill values can be found
3082 in <a href="#default_fillvals">default_fillvals</a>.</p>
3083
3084 <p><strong><code>chunk_cache</code></strong>: If specified, sets the chunk cache size for this variable.
3085 Persists as long as Dataset is open. Use <a href="#set_var_chunk_cache">set_var_chunk_cache</a> to
3086 change it when Dataset is re-opened. </p>
3087
3088 <p><strong><em>Note</em></strong>: <a href="#Variable">Variable</a> instances should be created using the
3089 <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a> method of a <a href="#Dataset">Dataset</a> or
3090 <a href="#Group">Group</a> instance, not using this class directly.</p>
3091 </div>
3092
3093
3094 </div>
3095 <div id="Variable.group" class="classattr">
3096 <div class="attr function"><a class="headerlink" href="#Variable.group">#&nbsp;&nbsp</a>
3097
3098
3099 <span class="def">def</span>
3100 <span class="name">group</span><span class="signature">(unknown)</span>:
3101 </div>
3102
3103
3104 <div class="docstring"><p><strong><code>group(self)</code></strong></p>
3105
3106 <p>return the group that this <a href="#Variable">Variable</a> is a member of.</p>
3107 </div>
3108
3109
3110 </div>
3111 <div id="Variable.ncattrs" class="classattr">
3112 <div class="attr function"><a class="headerlink" href="#Variable.ncattrs">#&nbsp;&nbsp</a>
3113
3114
3115 <span class="def">def</span>
3116 <span class="name">ncattrs</span><span class="signature">(unknown)</span>:
3117 </div>
3118
3119
3120 <div class="docstring"><p><strong><code>ncattrs(self)</code></strong></p>
3121
3122 <p>return netCDF attribute names for this <a href="#Variable">Variable</a> in a list.</p>
3123 </div>
3124
3125
3126 </div>
3127 <div id="Variable.setncattr" class="classattr">
3128 <div class="attr function"><a class="headerlink" href="#Variable.setncattr">#&nbsp;&nbsp</a>
3129
3130
3131 <span class="def">def</span>
3132 <span class="name">setncattr</span><span class="signature">(unknown)</span>:
3133 </div>
3134
3135
3136 <div class="docstring"><p><strong><code>setncattr(self,name,value)</code></strong></p>
3137
3138 <p>set a netCDF variable attribute using name,value pair. Use if you need to set a
3139 netCDF attribute with the same name as one of the reserved python
3140 attributes.</p>
3141 </div>
3142
3143
3144 </div>
3145 <div id="Variable.setncattr_string" class="classattr">
3146 <div class="attr function"><a class="headerlink" href="#Variable.setncattr_string">#&nbsp;&nbsp</a>
3147
3148
3149 <span class="def">def</span>
3150 <span class="name">setncattr_string</span><span class="signature">(unknown)</span>:
3151 </div>
3152
3153
3154 <div class="docstring"><p><strong><code>setncattr_string(self,name,value)</code></strong></p>
3155
3156 <p>set a netCDF variable string attribute using name,value pair.
3157 Use if you need to ensure that a netCDF attribute is created with type
3158 <code>NC_STRING</code> if the file format is <code>NETCDF4</code>.
3159 Use if you need to set an attribute to an array of variable-length strings.</p>
3160 </div>
3161
3162
3163 </div>
3164 <div id="Variable.setncatts" class="classattr">
3165 <div class="attr function"><a class="headerlink" href="#Variable.setncatts">#&nbsp;&nbsp</a>
3166
3167
3168 <span class="def">def</span>
3169 <span class="name">setncatts</span><span class="signature">(unknown)</span>:
3170 </div>
3171
3172
3173 <div class="docstring"><p><strong><code>setncatts(self,attdict)</code></strong></p>
3174
3175 <p>set a bunch of netCDF variable attributes at once using a python dictionary.
3176 This may be faster when setting a lot of attributes for a <code>NETCDF3</code>
3177 formatted file, since nc_redef/nc_enddef is not called in between setting
3178 each attribute</p>
3179 </div>
3180
3181
3182 </div>
3183 <div id="Variable.getncattr" class="classattr">
3184 <div class="attr function"><a class="headerlink" href="#Variable.getncattr">#&nbsp;&nbsp</a>
3185
3186
3187 <span class="def">def</span>
3188 <span class="name">getncattr</span><span class="signature">(unknown)</span>:
3189 </div>
3190
3191
3192 <div class="docstring"><p><strong><code>getncattr(self,name)</code></strong></p>
3193
3194 <p>retrieve a netCDF variable attribute. Use if you need to set a
3195 netCDF attribute with the same name as one of the reserved python
3196 attributes.</p>
3197
3198 <p>option kwarg <code>encoding</code> can be used to specify the
3199 character encoding of a string attribute (default is <code>utf-8</code>).</p>
3200 </div>
3201
3202
3203 </div>
3204 <div id="Variable.delncattr" class="classattr">
3205 <div class="attr function"><a class="headerlink" href="#Variable.delncattr">#&nbsp;&nbsp</a>
3206
3207
3208 <span class="def">def</span>
3209 <span class="name">delncattr</span><span class="signature">(unknown)</span>:
3210 </div>
3211
3212
3213 <div class="docstring"><p><strong><code>delncattr(self,name,value)</code></strong></p>
3214
3215 <p>delete a netCDF variable attribute. Use if you need to delete a
3216 netCDF attribute with the same name as one of the reserved python
3217 attributes.</p>
3218 </div>
3219
3220
3221 </div>
3222 <div id="Variable.filters" class="classattr">
3223 <div class="attr function"><a class="headerlink" href="#Variable.filters">#&nbsp;&nbsp</a>
3224
3225
3226 <span class="def">def</span>
3227 <span class="name">filters</span><span class="signature">(unknown)</span>:
3228 </div>
3229
3230
3231 <div class="docstring"><p><strong><code>filters(self)</code></strong></p>
3232
3233 <p>return dictionary containing HDF5 filter parameters.</p>
3234 </div>
3235
3236
3237 </div>
3238 <div id="Variable.endian" class="classattr">
3239 <div class="attr function"><a class="headerlink" href="#Variable.endian">#&nbsp;&nbsp</a>
3240
3241
3242 <span class="def">def</span>
3243 <span class="name">endian</span><span class="signature">(unknown)</span>:
3244 </div>
3245
3246
3247 <div class="docstring"><p><strong><code>endian(self)</code></strong></p>
3248
3249 <p>return endian-ness (<code>little,big,native</code>) of variable (as stored in HDF5 file).</p>
3250 </div>
3251
3252
3253 </div>
3254 <div id="Variable.chunking" class="classattr">
3255 <div class="attr function"><a class="headerlink" href="#Variable.chunking">#&nbsp;&nbsp</a>
3256
3257
3258 <span class="def">def</span>
3259 <span class="name">chunking</span><span class="signature">(unknown)</span>:
3260 </div>
3261
3262
3263 <div class="docstring"><p><strong><code>chunking(self)</code></strong></p>
3264
3265 <p>return variable chunking information. If the dataset is
3266 defined to be contiguous (and hence there is no chunking) the word 'contiguous'
3267 is returned. Otherwise, a sequence with the chunksize for
3268 each dimension is returned.</p>
3269 </div>
3270
3271
3272 </div>
3273 <div id="Variable.get_var_chunk_cache" class="classattr">
3274 <div class="attr function"><a class="headerlink" href="#Variable.get_var_chunk_cache">#&nbsp;&nbsp</a>
3275
3276
3277 <span class="def">def</span>
3278 <span class="name">get_var_chunk_cache</span><span class="signature">(unknown)</span>:
3279 </div>
3280
3281
3282 <div class="docstring"><p><strong><code>get_var_chunk_cache(self)</code></strong></p>
3283
3284 <p>return variable chunk cache information in a tuple (size,nelems,preemption).
3285 See netcdf C library documentation for <code>nc_get_var_chunk_cache</code> for
3286 details.</p>
3287 </div>
3288
3289
3290 </div>
3291 <div id="Variable.set_var_chunk_cache" class="classattr">
3292 <div class="attr function"><a class="headerlink" href="#Variable.set_var_chunk_cache">#&nbsp;&nbsp</a>
3293
3294
3295 <span class="def">def</span>
3296 <span class="name">set_var_chunk_cache</span><span class="signature">(unknown)</span>:
3297 </div>
3298
3299
3300 <div class="docstring"><p><strong><code>set_var_chunk_cache(self,size=None,nelems=None,preemption=None)</code></strong></p>
3301
3302 <p>change variable chunk cache settings.
3303 See netcdf C library documentation for <code>nc_set_var_chunk_cache</code> for
3304 details.</p>
3305 </div>
3306
3307
3308 </div>
3309 <div id="Variable.renameAttribute" class="classattr">
3310 <div class="attr function"><a class="headerlink" href="#Variable.renameAttribute">#&nbsp;&nbsp</a>
3311
3312
3313 <span class="def">def</span>
3314 <span class="name">renameAttribute</span><span class="signature">(unknown)</span>:
3315 </div>
3316
3317
3318 <div class="docstring"><p><strong><code>renameAttribute(self, oldname, newname)</code></strong></p>
3319
3320 <p>rename a <a href="#Variable">Variable</a> attribute named <code>oldname</code> to <code>newname</code>.</p>
3321 </div>
3322
3323
3324 </div>
3325 <div id="Variable.assignValue" class="classattr">
3326 <div class="attr function"><a class="headerlink" href="#Variable.assignValue">#&nbsp;&nbsp</a>
3327
3328
3329 <span class="def">def</span>
3330 <span class="name">assignValue</span><span class="signature">(unknown)</span>:
3331 </div>
3332
3333
3334 <div class="docstring"><p><strong><code>assignValue(self, val)</code></strong></p>
3335
3336 <p>assign a value to a scalar variable. Provided for compatibility with
3337 Scientific.IO.NetCDF, can also be done by assigning to an Ellipsis slice ([...]).</p>
3338 </div>
3339
3340
3341 </div>
3342 <div id="Variable.getValue" class="classattr">
3343 <div class="attr function"><a class="headerlink" href="#Variable.getValue">#&nbsp;&nbsp</a>
3344
3345
3346 <span class="def">def</span>
3347 <span class="name">getValue</span><span class="signature">(unknown)</span>:
3348 </div>
3349
3350
3351 <div class="docstring"><p><strong><code>getValue(self)</code></strong></p>
3352
3353 <p>get the value of a scalar variable. Provided for compatibility with
3354 Scientific.IO.NetCDF, can also be done by slicing with an Ellipsis ([...]).</p>
3355 </div>
3356
3357
3358 </div>
3359 <div id="Variable.set_auto_chartostring" class="classattr">
3360 <div class="attr function"><a class="headerlink" href="#Variable.set_auto_chartostring">#&nbsp;&nbsp</a>
3361
3362
3363 <span class="def">def</span>
3364 <span class="name">set_auto_chartostring</span><span class="signature">(unknown)</span>:
3365 </div>
3366
3367
3368 <div class="docstring"><p><strong><code>set_auto_chartostring(self,chartostring)</code></strong></p>
3369
3370 <p>turn on or off automatic conversion of character variable data to and
3371 from numpy fixed length string arrays when the <code>_Encoding</code> variable attribute
3372 is set.</p>
3373
3374 <p>If <code><a href="#chartostring">chartostring</a></code> is set to <code>True</code>, when data is read from a character variable
3375 (dtype = <code>S1</code>) that has an <code>_Encoding</code> attribute, it is converted to a numpy
3376 fixed length unicode string array (dtype = <code>UN</code>, where <code>N</code> is the length
3377 of the the rightmost dimension of the variable). The value of <code>_Encoding</code>
3378 is the unicode encoding that is used to decode the bytes into strings.</p>
3379
3380 <p>When numpy string data is written to a variable it is converted back to
3381 indiviual bytes, with the number of bytes in each string equalling the
3382 rightmost dimension of the variable.</p>
3383
3384 <p>The default value of <code><a href="#chartostring">chartostring</a></code> is <code>True</code>
3385 (automatic conversions are performed).</p>
3386 </div>
3387
3388
3389 </div>
3390 <div id="Variable.use_nc_get_vars" class="classattr">
3391 <div class="attr function"><a class="headerlink" href="#Variable.use_nc_get_vars">#&nbsp;&nbsp</a>
3392
3393
3394 <span class="def">def</span>
3395 <span class="name">use_nc_get_vars</span><span class="signature">(unknown)</span>:
3396 </div>
3397
3398
3399 <div class="docstring"><p><strong><code>use_nc_get_vars(self,_use_get_vars)</code></strong></p>
3400
3401 <p>enable the use of netcdf library routine <code>nc_get_vars</code>
3402 to retrieve strided variable slices. By default,
3403 <code>nc_get_vars</code> may not used by default (depending on the
3404 version of the netcdf-c library being used) since it may be
3405 slower than multiple calls to the unstrided read routine <code>nc_get_vara</code>.</p>
3406 </div>
3407
3408
3409 </div>
3410 <div id="Variable.set_auto_maskandscale" class="classattr">
3411 <div class="attr function"><a class="headerlink" href="#Variable.set_auto_maskandscale">#&nbsp;&nbsp</a>
3412
3413
3414 <span class="def">def</span>
3415 <span class="name">set_auto_maskandscale</span><span class="signature">(unknown)</span>:
3416 </div>
3417
3418
3419 <div class="docstring"><p><strong><code>set_auto_maskandscale(self,maskandscale)</code></strong></p>
3420
3421 <p>turn on or off automatic conversion of variable data to and
3422 from masked arrays, automatic packing/unpacking of variable
3423 data using <code>scale_factor</code> and <code>add_offset</code> attributes and
3424 automatic conversion of signed integer data to unsigned integer
3425 data if the <code>_Unsigned</code> attribute exists.</p>
3426
3427 <p>If <code>maskandscale</code> is set to <code>True</code>, when data is read from a variable
3428 it is converted to a masked array if any of the values are exactly
3429 equal to the either the netCDF _FillValue or the value specified by the
3430 missing_value variable attribute. The fill_value of the masked array
3431 is set to the missing_value attribute (if it exists), otherwise
3432 the netCDF _FillValue attribute (which has a default value
3433 for each data type). When data is written to a variable, the masked
3434 array is converted back to a regular numpy array by replacing all the
3435 masked values by the missing_value attribute of the variable (if it
3436 exists). If the variable has no missing_value attribute, the _FillValue
3437 is used instead. If the variable has valid_min/valid_max and
3438 missing_value attributes, data outside the specified range will be
3439 set to missing_value.</p>
3440
3441 <p>If <code>maskandscale</code> is set to <code>True</code>, and the variable has a
3442 <code>scale_factor</code> or an <code>add_offset</code> attribute, then data read
3443 from that variable is unpacked using::</p>
3444
3445 <pre><code>data = self.scale_factor*data + self.add_offset
3446 </code></pre>
3447
3448 <p>When data is written to a variable it is packed using::</p>
3449
3450 <pre><code>data = (data - self.add_offset)/self.scale_factor
3451 </code></pre>
3452
3453 <p>If either scale_factor is present, but add_offset is missing, add_offset
3454 is assumed zero. If add_offset is present, but scale_factor is missing,
3455 scale_factor is assumed to be one.
3456 For more information on how <code>scale_factor</code> and <code>add_offset</code> can be
3457 used to provide simple compression, see the
3458 <a href="http://www.esrl.noaa.gov/psl/data/gridded/conventions/cdc_netcdf_standard.shtml">PSL metadata conventions</a>.</p>
3459
3460 <p>In addition, if <code>maskandscale</code> is set to <code>True</code>, and if the variable has an
3461 attribute <code>_Unsigned</code> set, and the variable has a signed integer data type,
3462 a view to the data is returned with the corresponding unsigned integer data type.
3463 This convention is used by the netcdf-java library to save unsigned integer
3464 data in <code>NETCDF3</code> or <code>NETCDF4_CLASSIC</code> files (since the <code>NETCDF3</code>
3465 data model does not have unsigned integer data types).</p>
3466
3467 <p>The default value of <code>maskandscale</code> is <code>True</code>
3468 (automatic conversions are performed).</p>
3469 </div>
3470
3471
3472 </div>
3473 <div id="Variable.set_auto_scale" class="classattr">
3474 <div class="attr function"><a class="headerlink" href="#Variable.set_auto_scale">#&nbsp;&nbsp</a>
3475
3476
3477 <span class="def">def</span>
3478 <span class="name">set_auto_scale</span><span class="signature">(unknown)</span>:
3479 </div>
3480
3481
3482 <div class="docstring"><p><strong><code>set_auto_scale(self,scale)</code></strong></p>
3483
3484 <p>turn on or off automatic packing/unpacking of variable
3485 data using <code>scale_factor</code> and <code>add_offset</code> attributes.
3486 Also turns on and off automatic conversion of signed integer data
3487 to unsigned integer data if the variable has an <code>_Unsigned</code>
3488 attribute.</p>
3489
3490 <p>If <code>scale</code> is set to <code>True</code>, and the variable has a
3491 <code>scale_factor</code> or an <code>add_offset</code> attribute, then data read
3492 from that variable is unpacked using::</p>
3493
3494 <pre><code>data = self.scale_factor*data + self.add_offset
3495 </code></pre>
3496
3497 <p>When data is written to a variable it is packed using::</p>
3498
3499 <pre><code>data = (data - self.add_offset)/self.scale_factor
3500 </code></pre>
3501
3502 <p>If either scale_factor is present, but add_offset is missing, add_offset
3503 is assumed zero. If add_offset is present, but scale_factor is missing,
3504 scale_factor is assumed to be one.
3505 For more information on how <code>scale_factor</code> and <code>add_offset</code> can be
3506 used to provide simple compression, see the
3507 <a href="http://www.esrl.noaa.gov/psl/data/gridded/conventions/cdc_netcdf_standard.shtml">PSL metadata conventions</a>.</p>
3508
3509 <p>In addition, if <code>scale</code> is set to <code>True</code>, and if the variable has an
3510 attribute <code>_Unsigned</code> set, and the variable has a signed integer data type,
3511 a view to the data is returned with the corresponding unsigned integer datatype.
3512 This convention is used by the netcdf-java library to save unsigned integer
3513 data in <code>NETCDF3</code> or <code>NETCDF4_CLASSIC</code> files (since the <code>NETCDF3</code>
3514 data model does not have unsigned integer data types).</p>
3515
3516 <p>The default value of <code>scale</code> is <code>True</code>
3517 (automatic conversions are performed).</p>
3518 </div>
3519
3520
3521 </div>
3522 <div id="Variable.set_auto_mask" class="classattr">
3523 <div class="attr function"><a class="headerlink" href="#Variable.set_auto_mask">#&nbsp;&nbsp</a>
3524
3525
3526 <span class="def">def</span>
3527 <span class="name">set_auto_mask</span><span class="signature">(unknown)</span>:
3528 </div>
3529
3530
3531 <div class="docstring"><p><strong><code>set_auto_mask(self,mask)</code></strong></p>
3532
3533 <p>turn on or off automatic conversion of variable data to and
3534 from masked arrays .</p>
3535
3536 <p>If <code>mask</code> is set to <code>True</code>, when data is read from a variable
3537 it is converted to a masked array if any of the values are exactly
3538 equal to the either the netCDF _FillValue or the value specified by the
3539 missing_value variable attribute. The fill_value of the masked array
3540 is set to the missing_value attribute (if it exists), otherwise
3541 the netCDF _FillValue attribute (which has a default value
3542 for each data type). When data is written to a variable, the masked
3543 array is converted back to a regular numpy array by replacing all the
3544 masked values by the missing_value attribute of the variable (if it
3545 exists). If the variable has no missing_value attribute, the _FillValue
3546 is used instead. If the variable has valid_min/valid_max and
3547 missing_value attributes, data outside the specified range will be
3548 set to missing_value.</p>
3549
3550 <p>The default value of <code>mask</code> is <code>True</code>
3551 (automatic conversions are performed).</p>
3552 </div>
3553
3554
3555 </div>
3556 <div id="Variable.set_always_mask" class="classattr">
3557 <div class="attr function"><a class="headerlink" href="#Variable.set_always_mask">#&nbsp;&nbsp</a>
3558
3559
3560 <span class="def">def</span>
3561 <span class="name">set_always_mask</span><span class="signature">(unknown)</span>:
3562 </div>
3563
3564
3565 <div class="docstring"><p><strong><code>set_always_mask(self,always_mask)</code></strong></p>
3566
3567 <p>turn on or off conversion of data without missing values to regular
3568 numpy arrays.</p>
3569
3570 <p><code>always_mask</code> is a Boolean determining if automatic conversion of
3571 masked arrays with no missing values to regular numpy arrays shall be
3572 applied. Default is True. Set to False to restore the default behaviour
3573 in versions prior to 1.4.1 (numpy array returned unless missing values are present,
3574 otherwise masked array returned).</p>
3575 </div>
3576
3577
3578 </div>
3579 <div id="Variable.set_ncstring_attrs" class="classattr">
3580 <div class="attr function"><a class="headerlink" href="#Variable.set_ncstring_attrs">#&nbsp;&nbsp</a>
3581
3582
3583 <span class="def">def</span>
3584 <span class="name">set_ncstring_attrs</span><span class="signature">(unknown)</span>:
3585 </div>
3586
3587
3588 <div class="docstring"><p><strong><code>set_always_mask(self,ncstring_attrs)</code></strong></p>
3589
3590 <p>turn on or off creating NC_STRING string attributes.</p>
3591
3592 <p>If <code>ncstring_attrs</code> is set to <code>True</code> then text attributes will be variable-length
3593 NC_STRINGs.</p>
3594
3595 <p>The default value of <code>ncstring_attrs</code> is <code>False</code> (writing ascii text attributes as
3596 NC_CHAR).</p>
3597 </div>
3598
3599
3600 </div>
3601 <div id="Variable.set_collective" class="classattr">
3602 <div class="attr function"><a class="headerlink" href="#Variable.set_collective">#&nbsp;&nbsp</a>
3603
3604
3605 <span class="def">def</span>
3606 <span class="name">set_collective</span><span class="signature">(unknown)</span>:
3607 </div>
3608
3609
3610 <div class="docstring"><p><strong><code>set_collective(self,True_or_False)</code></strong></p>
3611
3612 <p>turn on or off collective parallel IO access. Ignored if file is not
3613 open for parallel access.</p>
3614 </div>
3615
3616
3617 </div>
3618 <div id="Variable.get_dims" class="classattr">
3619 <div class="attr function"><a class="headerlink" href="#Variable.get_dims">#&nbsp;&nbsp</a>
3620
3621
3622 <span class="def">def</span>
3623 <span class="name">get_dims</span><span class="signature">(unknown)</span>:
3624 </div>
3625
3626
3627 <div class="docstring"><p><strong><code>get_dims(self)</code></strong></p>
3628
3629 <p>return a tuple of <a href="#Dimension">Dimension</a> instances associated with this
3630 <a href="#Variable">Variable</a>.</p>
3631 </div>
3632
3633
3634 </div>
3635 <div id="Variable.name" class="classattr">
3636 <div class="attr variable"><a class="headerlink" href="#Variable.name">#&nbsp;&nbsp</a>
3637
3638 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3639 </div>
3640
3641
3642
3643 </div>
3644 <div id="Variable.datatype" class="classattr">
3645 <div class="attr variable"><a class="headerlink" href="#Variable.datatype">#&nbsp;&nbsp</a>
3646
3647 <span class="name">datatype</span><span class="default_value"> = &lt;attribute &#39;datatype&#39; of &#39;<a href="#Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3648 </div>
3649
3650
3651
3652 </div>
3653 <div id="Variable.shape" class="classattr">
3654 <div class="attr variable"><a class="headerlink" href="#Variable.shape">#&nbsp;&nbsp</a>
3655
3656 <span class="name">shape</span><span class="default_value"> = &lt;attribute &#39;shape&#39; of &#39;<a href="#Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3657 </div>
3658
3659
3660
3661 </div>
3662 <div id="Variable.size" class="classattr">
3663 <div class="attr variable"><a class="headerlink" href="#Variable.size">#&nbsp;&nbsp</a>
3664
3665 <span class="name">size</span><span class="default_value"> = &lt;attribute &#39;size&#39; of &#39;<a href="#Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3666 </div>
3667
3668
3669
3670 </div>
3671 <div id="Variable.dimensions" class="classattr">
3672 <div class="attr variable"><a class="headerlink" href="#Variable.dimensions">#&nbsp;&nbsp</a>
3673
3674 <span class="name">dimensions</span><span class="default_value"> = &lt;attribute &#39;dimensions&#39; of &#39;<a href="#Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3675 </div>
3676
3677
3678
3679 </div>
3680 <div id="Variable.ndim" class="classattr">
3681 <div class="attr variable"><a class="headerlink" href="#Variable.ndim">#&nbsp;&nbsp</a>
3682
3683 <span class="name">ndim</span><span class="default_value"> = &lt;attribute &#39;ndim&#39; of &#39;<a href="#Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3684 </div>
3685
3686
3687
3688 </div>
3689 <div id="Variable.dtype" class="classattr">
3690 <div class="attr variable"><a class="headerlink" href="#Variable.dtype">#&nbsp;&nbsp</a>
3691
3692 <span class="name">dtype</span><span class="default_value"> = &lt;attribute &#39;dtype&#39; of &#39;<a href="#Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3693 </div>
3694
3695
3696
3697 </div>
3698 <div id="Variable.mask" class="classattr">
3699 <div class="attr variable"><a class="headerlink" href="#Variable.mask">#&nbsp;&nbsp</a>
3700
3701 <span class="name">mask</span><span class="default_value"> = &lt;attribute &#39;mask&#39; of &#39;<a href="#Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3702 </div>
3703
3704
3705
3706 </div>
3707 <div id="Variable.scale" class="classattr">
3708 <div class="attr variable"><a class="headerlink" href="#Variable.scale">#&nbsp;&nbsp</a>
3709
3710 <span class="name">scale</span><span class="default_value"> = &lt;attribute &#39;scale&#39; of &#39;<a href="#Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3711 </div>
3712
3713
3714
3715 </div>
3716 <div id="Variable.always_mask" class="classattr">
3717 <div class="attr variable"><a class="headerlink" href="#Variable.always_mask">#&nbsp;&nbsp</a>
3718
3719 <span class="name">always_mask</span><span class="default_value"> = &lt;attribute &#39;always_mask&#39; of &#39;<a href="#Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3720 </div>
3721
3722
3723
3724 </div>
3725 <div id="Variable.chartostring" class="classattr">
3726 <div class="attr variable"><a class="headerlink" href="#Variable.chartostring">#&nbsp;&nbsp</a>
3727
3728 <span class="name">chartostring</span><span class="default_value"> = &lt;attribute &#39;chartostring&#39; of &#39;<a href="#Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3729 </div>
3730
3731
3732
3733 </div>
3734 </section>
3735 <section id="CompoundType">
3736 <div class="attr class">
3737 <a class="headerlink" href="#CompoundType">#&nbsp;&nbsp</a>
3738
3739
3740 <span class="def">class</span>
3741 <span class="name">CompoundType</span>:
3742 </div>
3743
3744
3745 <div class="docstring"><p>A <a href="#CompoundType">CompoundType</a> instance is used to describe a compound data
3746 type, and can be passed to the the <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a> method of
3747 a <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> instance.
3748 Compound data types map to numpy structured arrays.
3749 See <a href="#<a href="#CompoundType.__init__">CompoundType.__init__</a>"><a href="#CompoundType.__init__">CompoundType.__init__</a></a> for more details.</p>
3750
3751 <p>The instance variables <code>dtype</code> and <code>name</code> should not be modified by
3752 the user.</p>
3753 </div>
3754
3755
3756 <div id="CompoundType.__init__" class="classattr">
3757 <div class="attr function"><a class="headerlink" href="#CompoundType.__init__">#&nbsp;&nbsp</a>
3758
3759
3760 <span class="name">CompoundType</span><span class="signature">(unknown)</span> </div>
3761
3762
3763 <div class="docstring"><p><strong><em><code>__init__(group, datatype, datatype_name)</code></em></strong></p>
3764
3765 <p>CompoundType constructor.</p>
3766
3767 <p><strong><code>group</code></strong>: <a href="#Group">Group</a> instance to associate with the compound datatype.</p>
3768
3769 <p><strong><code>datatype</code></strong>: A numpy dtype object describing a structured (a.k.a record)
3770 array. Can be composed of homogeneous numeric or character data types, or
3771 other structured array data types.</p>
3772
3773 <p><strong><code>datatype_name</code></strong>: a Python string containing a description of the
3774 compound data type.</p>
3775
3776 <p><strong><em>Note 1</em></strong>: When creating nested compound data types,
3777 the inner compound data types must already be associated with CompoundType
3778 instances (so create CompoundType instances for the innermost structures
3779 first).</p>
3780
3781 <p><strong><em>Note 2</em></strong>: <a href="#CompoundType">CompoundType</a> instances should be created using the
3782 <a href="#<a href="#Dataset.createCompoundType">Dataset.createCompoundType</a>"><a href="#Dataset.createCompoundType">Dataset.createCompoundType</a></a>
3783 method of a <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> instance, not using this class directly.</p>
3784 </div>
3785
3786
3787 </div>
3788 <div id="CompoundType.dtype" class="classattr">
3789 <div class="attr variable"><a class="headerlink" href="#CompoundType.dtype">#&nbsp;&nbsp</a>
3790
3791 <span class="name">dtype</span><span class="default_value"> = &lt;attribute &#39;dtype&#39; of &#39;<a href="#CompoundType">netCDF4._netCDF4.CompoundType</a>&#39; objects&gt;</span>
3792 </div>
3793
3794
3795
3796 </div>
3797 <div id="CompoundType.dtype_view" class="classattr">
3798 <div class="attr variable"><a class="headerlink" href="#CompoundType.dtype_view">#&nbsp;&nbsp</a>
3799
3800 <span class="name">dtype_view</span><span class="default_value"> = &lt;attribute &#39;dtype_view&#39; of &#39;<a href="#CompoundType">netCDF4._netCDF4.CompoundType</a>&#39; objects&gt;</span>
3801 </div>
3802
3803
3804
3805 </div>
3806 <div id="CompoundType.name" class="classattr">
3807 <div class="attr variable"><a class="headerlink" href="#CompoundType.name">#&nbsp;&nbsp</a>
3808
3809 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#CompoundType">netCDF4._netCDF4.CompoundType</a>&#39; objects&gt;</span>
3810 </div>
3811
3812
3813
3814 </div>
3815 </section>
3816 <section id="VLType">
3817 <div class="attr class">
3818 <a class="headerlink" href="#VLType">#&nbsp;&nbsp</a>
3819
3820
3821 <span class="def">class</span>
3822 <span class="name">VLType</span>:
3823 </div>
3824
3825
3826 <div class="docstring"><p>A <a href="#VLType">VLType</a> instance is used to describe a variable length (VLEN) data
3827 type, and can be passed to the the <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a> method of
3828 a <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> instance. See
3829 <a href="#<a href="#VLType.__init__">VLType.__init__</a>"><a href="#VLType.__init__">VLType.__init__</a></a>for more details.</p>
3830
3831 <p>The instance variables <code>dtype</code> and <code>name</code> should not be modified by
3832 the user.</p>
3833 </div>
3834
3835
3836 <div id="VLType.__init__" class="classattr">
3837 <div class="attr function"><a class="headerlink" href="#VLType.__init__">#&nbsp;&nbsp</a>
3838
3839
3840 <span class="name">VLType</span><span class="signature">(unknown)</span> </div>
3841
3842
3843 <div class="docstring"><p><strong><code>__init__(group, datatype, datatype_name)</code></strong></p>
3844
3845 <p>VLType constructor.</p>
3846
3847 <p><strong><code>group</code></strong>: <a href="#Group">Group</a> instance to associate with the VLEN datatype.</p>
3848
3849 <p><strong><code>datatype</code></strong>: An numpy dtype object describing the component type for the
3850 variable length array.</p>
3851
3852 <p><strong><code>datatype_name</code></strong>: a Python string containing a description of the
3853 VLEN data type.</p>
3854
3855 <p><strong><em><code>Note</code></em></strong>: <a href="#VLType">VLType</a> instances should be created using the
3856 <a href="#<a href="#Dataset.createVLType">Dataset.createVLType</a>"><a href="#Dataset.createVLType">Dataset.createVLType</a></a>
3857 method of a <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> instance, not using this class directly.</p>
3858 </div>
3859
3860
3861 </div>
3862 <div id="VLType.dtype" class="classattr">
3863 <div class="attr variable"><a class="headerlink" href="#VLType.dtype">#&nbsp;&nbsp</a>
3864
3865 <span class="name">dtype</span><span class="default_value"> = &lt;attribute &#39;dtype&#39; of &#39;<a href="#VLType">netCDF4._netCDF4.VLType</a>&#39; objects&gt;</span>
3866 </div>
3867
3868
3869
3870 </div>
3871 <div id="VLType.name" class="classattr">
3872 <div class="attr variable"><a class="headerlink" href="#VLType.name">#&nbsp;&nbsp</a>
3873
3874 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#VLType">netCDF4._netCDF4.VLType</a>&#39; objects&gt;</span>
3875 </div>
3876
3877
3878
3879 </div>
3880 </section>
3881 <section id="EnumType">
3882 <div class="attr class">
3883 <a class="headerlink" href="#EnumType">#&nbsp;&nbsp</a>
3884
3885
3886 <span class="def">class</span>
3887 <span class="name">EnumType</span>:
3888 </div>
3889
3890
3891 <div class="docstring"><p>A <a href="#EnumType">EnumType</a> instance is used to describe an Enum data
3892 type, and can be passed to the the <a href="#<a href="#Dataset.createVariable">Dataset.createVariable</a>"><a href="#Dataset.createVariable">Dataset.createVariable</a></a> method of
3893 a <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> instance. See
3894 <a href="#<a href="#EnumType.__init__">EnumType.__init__</a>"><a href="#EnumType.__init__">EnumType.__init__</a></a> for more details.</p>
3895
3896 <p>The instance variables <code>dtype</code>, <code>name</code> and <code>enum_dict</code> should not be modified by
3897 the user.</p>
3898 </div>
3899
3900
3901 <div id="EnumType.__init__" class="classattr">
3902 <div class="attr function"><a class="headerlink" href="#EnumType.__init__">#&nbsp;&nbsp</a>
3903
3904
3905 <span class="name">EnumType</span><span class="signature">(unknown)</span> </div>
3906
3907
3908 <div class="docstring"><p><strong><code>__init__(group, datatype, datatype_name, enum_dict)</code></strong></p>
3909
3910 <p>EnumType constructor.</p>
3911
3912 <p><strong><code>group</code></strong>: <a href="#Group">Group</a> instance to associate with the VLEN datatype.</p>
3913
3914 <p><strong><code>datatype</code></strong>: An numpy integer dtype object describing the base type
3915 for the Enum.</p>
3916
3917 <p><strong><code>datatype_name</code></strong>: a Python string containing a description of the
3918 Enum data type.</p>
3919
3920 <p><strong><code>enum_dict</code></strong>: a Python dictionary containing the Enum field/value
3921 pairs.</p>
3922
3923 <p><strong><em><code>Note</code></em></strong>: <a href="#EnumType">EnumType</a> instances should be created using the
3924 <a href="#<a href="#Dataset.createEnumType">Dataset.createEnumType</a>"><a href="#Dataset.createEnumType">Dataset.createEnumType</a></a>
3925 method of a <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> instance, not using this class directly.</p>
3926 </div>
3927
3928
3929 </div>
3930 <div id="EnumType.dtype" class="classattr">
3931 <div class="attr variable"><a class="headerlink" href="#EnumType.dtype">#&nbsp;&nbsp</a>
3932
3933 <span class="name">dtype</span><span class="default_value"> = &lt;attribute &#39;dtype&#39; of &#39;<a href="#EnumType">netCDF4._netCDF4.EnumType</a>&#39; objects&gt;</span>
3934 </div>
3935
3936
3937
3938 </div>
3939 <div id="EnumType.name" class="classattr">
3940 <div class="attr variable"><a class="headerlink" href="#EnumType.name">#&nbsp;&nbsp</a>
3941
3942 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#EnumType">netCDF4._netCDF4.EnumType</a>&#39; objects&gt;</span>
3943 </div>
3944
3945
3946
3947 </div>
3948 <div id="EnumType.enum_dict" class="classattr">
3949 <div class="attr variable"><a class="headerlink" href="#EnumType.enum_dict">#&nbsp;&nbsp</a>
3950
3951 <span class="name">enum_dict</span><span class="default_value"> = &lt;attribute &#39;enum_dict&#39; of &#39;<a href="#EnumType">netCDF4._netCDF4.EnumType</a>&#39; objects&gt;</span>
3952 </div>
3953
3954
3955
3956 </div>
3957 </section>
3958 <section id="getlibversion">
3959 <div class="attr function"><a class="headerlink" href="#getlibversion">#&nbsp;&nbsp</a>
3960
3961
3962 <span class="def">def</span>
3963 <span class="name">getlibversion</span><span class="signature">(unknown)</span>:
3964 </div>
3965
3966
3967 <div class="docstring"><p><strong><code><a href="#getlibversion">getlibversion()</a></code></strong></p>
3968
3969 <p>returns a string describing the version of the netcdf library
3970 used to build the module, and when it was built.</p>
3971 </div>
3972
3973
3974 </section>
3975 <section id="get_chunk_cache">
3976 <div class="attr function"><a class="headerlink" href="#get_chunk_cache">#&nbsp;&nbsp</a>
3977
3978
3979 <span class="def">def</span>
3980 <span class="name">get_chunk_cache</span><span class="signature">(unknown)</span>:
3981 </div>
3982
3983
3984 <div class="docstring"><p><strong><code><a href="#get_chunk_cache">get_chunk_cache()</a></code></strong></p>
3985
3986 <p>return current netCDF chunk cache information in a tuple (size,nelems,preemption).
3987 See netcdf C library documentation for <code>nc_get_chunk_cache</code> for
3988 details. Values can be reset with <a href="#set_chunk_cache">set_chunk_cache</a>.</p>
3989 </div>
3990
3991
3992 </section>
3993 <section id="set_chunk_cache">
3994 <div class="attr function"><a class="headerlink" href="#set_chunk_cache">#&nbsp;&nbsp</a>
3995
3996
3997 <span class="def">def</span>
3998 <span class="name">set_chunk_cache</span><span class="signature">(unknown)</span>:
3999 </div>
4000
4001
4002 <div class="docstring"><p><strong><code>set_chunk_cache(self,size=None,nelems=None,preemption=None)</code></strong></p>
4003
4004 <p>change netCDF4 chunk cache settings.
4005 See netcdf C library documentation for <code>nc_set_chunk_cache</code> for
4006 details.</p>
4007 </div>
4008
4009
4010 </section>
4011 <section id="stringtoarr">
4012 <div class="attr function"><a class="headerlink" href="#stringtoarr">#&nbsp;&nbsp</a>
4013
4014
4015 <span class="def">def</span>
4016 <span class="name">stringtoarr</span><span class="signature">(unknown)</span>:
4017 </div>
4018
4019
4020 <div class="docstring"><p><strong><code>stringtoarr(a, NUMCHARS,dtype='S')</code></strong></p>
4021
4022 <p>convert a string to a character array of length <code>NUMCHARS</code></p>
4023
4024 <p><strong><code>a</code></strong>: Input python string.</p>
4025
4026 <p><strong><code>NUMCHARS</code></strong>: number of characters used to represent string
4027 (if len(a) &lt; <code>NUMCHARS</code>, it will be padded on the right with blanks).</p>
4028
4029 <p><strong><code>dtype</code></strong>: type of numpy array to return. Default is <code>'S'</code>, which
4030 means an array of dtype <code>'S1'</code> will be returned. If dtype=<code>'U'</code>, a
4031 unicode array (dtype = <code>'U1'</code>) will be returned.</p>
4032
4033 <p>returns a rank 1 numpy character array of length NUMCHARS with datatype <code>'S1'</code>
4034 (default) or <code>'U1'</code> (if dtype=<code>'U'</code>)</p>
4035 </div>
4036
4037
4038 </section>
4039 <section id="stringtochar">
4040 <div class="attr function"><a class="headerlink" href="#stringtochar">#&nbsp;&nbsp</a>
4041
4042
4043 <span class="def">def</span>
4044 <span class="name">stringtochar</span><span class="signature">(unknown)</span>:
4045 </div>
4046
4047
4048 <div class="docstring"><p><strong><code>stringtochar(a,encoding='utf-8')</code></strong></p>
4049
4050 <p>convert a string array to a character array with one extra dimension</p>
4051
4052 <p><strong><code>a</code></strong>: Input numpy string array with numpy datatype <code>'SN'</code> or <code>'UN'</code>, where N
4053 is the number of characters in each string. Will be converted to
4054 an array of characters (datatype <code>'S1'</code> or <code>'U1'</code>) of shape <code>a.shape + (N,)</code>.</p>
4055
4056 <p>optional kwarg <code>encoding</code> can be used to specify character encoding (default
4057 <code>utf-8</code>). If <code>encoding</code> is 'none' or 'bytes', a <code>numpy.string_</code> the input array
4058 is treated a raw byte strings (<code>numpy.string_</code>).</p>
4059
4060 <p>returns a numpy character array with datatype <code>'S1'</code> or <code>'U1'</code>
4061 and shape <code>a.shape + (N,)</code>, where N is the length of each string in a.</p>
4062 </div>
4063
4064
4065 </section>
4066 <section id="chartostring">
4067 <div class="attr function"><a class="headerlink" href="#chartostring">#&nbsp;&nbsp</a>
4068
4069
4070 <span class="def">def</span>
4071 <span class="name">chartostring</span><span class="signature">(unknown)</span>:
4072 </div>
4073
4074
4075 <div class="docstring"><p><strong><code>chartostring(b,encoding='utf-8')</code></strong></p>
4076
4077 <p>convert a character array to a string array with one less dimension.</p>
4078
4079 <p><strong><code>b</code></strong>: Input character array (numpy datatype <code>'S1'</code> or <code>'U1'</code>).
4080 Will be converted to a array of strings, where each string has a fixed
4081 length of <code>b.shape[-1]</code> characters.</p>
4082
4083 <p>optional kwarg <code>encoding</code> can be used to specify character encoding (default
4084 <code>utf-8</code>). If <code>encoding</code> is 'none' or 'bytes', a <code>numpy.string_</code> btye array is
4085 returned.</p>
4086
4087 <p>returns a numpy string array with datatype <code>'UN'</code> (or <code>'SN'</code>) and shape
4088 <code>b.shape[:-1]</code> where where <code>N=b.shape[-1]</code>.</p>
4089 </div>
4090
4091
4092 </section>
40933757 <section id="MFDataset">
40943758 <div class="attr class">
40953759 <a class="headerlink" href="#MFDataset">#&nbsp;&nbsp</a>
40963760
40973761
40983762 <span class="def">class</span>
4099 <span class="name">MFDataset</span>(<span class="base"><a href="#Dataset">Dataset</a></span>):
3763 <span class="name">MFDataset</span><wbr>(<span class="base"><a href="#Dataset">netCDF4.Dataset</a></span>):
41003764 </div>
41013765
41023766
41073771
41083772 <p>Adapted from <a href="http://pysclint.sourceforge.net/pycdf">pycdf</a> by Andre Gosselin.</p>
41093773
4110 <p>Example usage (See <a href="#<a href="#MFDataset.__init__">MFDataset.__init__</a>"><a href="#MFDataset.__init__">MFDataset.__init__</a></a> for more details):</p>
3774 <p>Example usage (See <code><a href="#MFDataset.__init__">MFDataset.__init__</a></code> for more details):</p>
41113775
41123776 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
41133777 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># create a series of netCDF files with a variable sharing</span>
41333797 <div class="attr function"><a class="headerlink" href="#MFDataset.__init__">#&nbsp;&nbsp</a>
41343798
41353799
4136 <span class="name">MFDataset</span><span class="signature">(files, check=False, aggdim=None, exclude=[], master_file=None)</span> </div>
3800 <span class="name">MFDataset</span><span class="signature">(files, check=False, aggdim=None, exclude=[], master_file=None)</span>
3801 </div>
41373802
41383803
41393804 <div class="docstring"><p><strong><code>__init__(self, files, check=False, aggdim=None, exclude=[],
42073872 <div class="inherited">
42083873 <h5>Inherited Members</h5>
42093874 <dl>
4210 <div><dt><a href="#Dataset">netCDF4._netCDF4.Dataset</a></dt>
3875 <div><dt><a href="#Dataset">Dataset</a></dt>
42113876 <dd id="MFDataset.filepath" class="function"><a href="#Dataset.filepath">filepath</a></dd>
42123877 <dd id="MFDataset.isopen" class="function"><a href="#Dataset.isopen">isopen</a></dd>
42133878 <dd id="MFDataset.sync" class="function"><a href="#Dataset.sync">sync</a></dd>
42613926
42623927
42633928 <span class="def">class</span>
4264 <span class="name">MFTime</span>(<span class="base"><a href="#_Variable">_Variable</a></span>):
3929 <span class="name">MFTime</span><wbr>(<span class="base">netCDF4._netCDF4._Variable</span>):
42653930 </div>
42663931
42673932
42683933 <div class="docstring"><p>Class providing an interface to a MFDataset time Variable by imposing a unique common
42693934 time unit and/or calendar to all files.</p>
42703935
4271 <p>Example usage (See <a href="#<a href="#MFTime.__init__">MFTime.__init__</a>"><a href="#MFTime.__init__">MFTime.__init__</a></a> for more details):</p>
4272
4273 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">numpy</span>
3936 <p>Example usage (See <code><a href="#MFTime.__init__">MFTime.__init__</a></code> for more details):</p>
3937
3938 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
42743939 <span class="o">&gt;&gt;&gt;</span> <span class="n">f1</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="s2">&quot;mftest_1.nc&quot;</span><span class="p">,</span><span class="s2">&quot;w&quot;</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s2">&quot;NETCDF4_CLASSIC&quot;</span><span class="p">)</span>
42753940 <span class="o">&gt;&gt;&gt;</span> <span class="n">f2</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="s2">&quot;mftest_2.nc&quot;</span><span class="p">,</span><span class="s2">&quot;w&quot;</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s2">&quot;NETCDF4_CLASSIC&quot;</span><span class="p">)</span>
42763941 <span class="o">&gt;&gt;&gt;</span> <span class="n">f1</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s2">&quot;time&quot;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
42813946 <span class="o">&gt;&gt;&gt;</span> <span class="n">t2</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s2">&quot;days since 2000-02-01&quot;</span>
42823947 <span class="o">&gt;&gt;&gt;</span> <span class="n">t1</span><span class="o">.</span><span class="n">calendar</span> <span class="o">=</span> <span class="s2">&quot;standard&quot;</span>
42833948 <span class="o">&gt;&gt;&gt;</span> <span class="n">t2</span><span class="o">.</span><span class="n">calendar</span> <span class="o">=</span> <span class="s2">&quot;standard&quot;</span>
4284 <span class="o">&gt;&gt;&gt;</span> <span class="n">t1</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">31</span><span class="p">)</span>
4285 <span class="o">&gt;&gt;&gt;</span> <span class="n">t2</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
3949 <span class="o">&gt;&gt;&gt;</span> <span class="n">t1</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">31</span><span class="p">)</span>
3950 <span class="o">&gt;&gt;&gt;</span> <span class="n">t2</span><span class="p">[:]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
42863951 <span class="o">&gt;&gt;&gt;</span> <span class="n">f1</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
42873952 <span class="o">&gt;&gt;&gt;</span> <span class="n">f2</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
42883953 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># Read the two files in at once, in one Dataset.</span>
43033968 <div class="attr function"><a class="headerlink" href="#MFTime.__init__">#&nbsp;&nbsp</a>
43043969
43053970
4306 <span class="name">MFTime</span><span class="signature">(time, units=None, calendar=None)</span> </div>
3971 <span class="name">MFTime</span><span class="signature">(time, units=None, calendar=None)</span>
3972 </div>
43073973
43083974
43093975 <div class="docstring"><p><strong><code>__init__(self, time, units=None, calendar=None)</code></strong></p>
43113977 <p>Create a time Variable with units consistent across a multifile
43123978 dataset.</p>
43133979
4314 <p><strong><code>time</code></strong>: Time variable from a <a href="#MFDataset">MFDataset</a>.</p>
3980 <p><strong><code>time</code></strong>: Time variable from a <code><a href="#MFDataset">MFDataset</a></code>.</p>
43153981
43163982 <p><strong><code>units</code></strong>: Time units, for example, <code>'days since 1979-01-01'</code>. If <code>None</code>,
43173983 use the units from the master variable.</p>
43273993 <div class="inherited">
43283994 <h5>Inherited Members</h5>
43293995 <dl>
4330 <div><dt><a href="#_Variable">netCDF4._netCDF4._Variable</a></dt>
4331 <dd id="MFTime.typecode" class="function"><a href="#_Variable.typecode">typecode</a></dd>
4332 <dd id="MFTime.ncattrs" class="function"><a href="#_Variable.ncattrs">ncattrs</a></dd>
4333 <dd id="MFTime.set_auto_chartostring" class="function"><a href="#_Variable.set_auto_chartostring">set_auto_chartostring</a></dd>
4334 <dd id="MFTime.set_auto_maskandscale" class="function"><a href="#_Variable.set_auto_maskandscale">set_auto_maskandscale</a></dd>
4335 <dd id="MFTime.set_auto_mask" class="function"><a href="#_Variable.set_auto_mask">set_auto_mask</a></dd>
4336 <dd id="MFTime.set_auto_scale" class="function"><a href="#_Variable.set_auto_scale">set_auto_scale</a></dd>
4337 <dd id="MFTime.set_always_mask" class="function"><a href="#_Variable.set_always_mask">set_always_mask</a></dd>
3996 <div><dt>netCDF4._netCDF4._Variable</dt>
3997 <dd id="MFTime.typecode" class="function">typecode</dd>
3998 <dd id="MFTime.ncattrs" class="function">ncattrs</dd>
3999 <dd id="MFTime.set_auto_chartostring" class="function">set_auto_chartostring</dd>
4000 <dd id="MFTime.set_auto_maskandscale" class="function">set_auto_maskandscale</dd>
4001 <dd id="MFTime.set_auto_mask" class="function">set_auto_mask</dd>
4002 <dd id="MFTime.set_auto_scale" class="function">set_auto_scale</dd>
4003 <dd id="MFTime.set_always_mask" class="function">set_always_mask</dd>
43384004
43394005 </div>
43404006 </dl>
43414007 </div>
4008 </section>
4009 <section id="CompoundType">
4010 <div class="attr class">
4011 <a class="headerlink" href="#CompoundType">#&nbsp;&nbsp</a>
4012
4013
4014 <span class="def">class</span>
4015 <span class="name">CompoundType</span>:
4016 </div>
4017
4018
4019 <div class="docstring"><p>A <code><a href="#CompoundType">CompoundType</a></code> instance is used to describe a compound data
4020 type, and can be passed to the the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of
4021 a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance.
4022 Compound data types map to numpy structured arrays.
4023 See <code><a href="#CompoundType.__init__">CompoundType.__init__</a></code> for more details.</p>
4024
4025 <p>The instance variables <code><a href="#CompoundType.dtype">dtype</a></code> and <code><a href="#CompoundType.name">name</a></code> should not be modified by
4026 the user.</p>
4027 </div>
4028
4029
4030 <div id="CompoundType.__init__" class="classattr">
4031 <div class="attr function"><a class="headerlink" href="#CompoundType.__init__">#&nbsp;&nbsp</a>
4032
4033
4034 <span class="name">CompoundType</span><span class="signature">()</span>
4035 </div>
4036
4037
4038 <div class="docstring"><p><strong><em><code>__init__(group, datatype, datatype_name)</code></em></strong></p>
4039
4040 <p>CompoundType constructor.</p>
4041
4042 <p><strong><code>group</code></strong>: <code><a href="#Group">Group</a></code> instance to associate with the compound datatype.</p>
4043
4044 <p><strong><code>datatype</code></strong>: A numpy dtype object describing a structured (a.k.a record)
4045 array. Can be composed of homogeneous numeric or character data types, or
4046 other structured array data types.</p>
4047
4048 <p><strong><code>datatype_name</code></strong>: a Python string containing a description of the
4049 compound data type.</p>
4050
4051 <p><strong><em>Note 1</em></strong>: When creating nested compound data types,
4052 the inner compound data types must already be associated with CompoundType
4053 instances (so create CompoundType instances for the innermost structures
4054 first).</p>
4055
4056 <p><strong><em>Note 2</em></strong>: <code><a href="#CompoundType">CompoundType</a></code> instances should be created using the
4057 <code><a href="#Dataset.createCompoundType">Dataset.createCompoundType</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or
4058 <code><a href="#Group">Group</a></code> instance, not using this class directly.</p>
4059 </div>
4060
4061
4062 </div>
4063 <div id="CompoundType.dtype" class="classattr">
4064 <div class="attr variable"><a class="headerlink" href="#CompoundType.dtype">#&nbsp;&nbsp</a>
4065
4066 <span class="name">dtype</span><span class="default_value"> = &lt;attribute &#39;dtype&#39; of &#39;<a href="#_netCDF4.CompoundType">netCDF4._netCDF4.CompoundType</a>&#39; objects&gt;</span>
4067 </div>
4068
4069
4070
4071 </div>
4072 <div id="CompoundType.dtype_view" class="classattr">
4073 <div class="attr variable"><a class="headerlink" href="#CompoundType.dtype_view">#&nbsp;&nbsp</a>
4074
4075 <span class="name">dtype_view</span><span class="default_value"> = &lt;attribute &#39;dtype_view&#39; of &#39;<a href="#_netCDF4.CompoundType">netCDF4._netCDF4.CompoundType</a>&#39; objects&gt;</span>
4076 </div>
4077
4078
4079
4080 </div>
4081 <div id="CompoundType.name" class="classattr">
4082 <div class="attr variable"><a class="headerlink" href="#CompoundType.name">#&nbsp;&nbsp</a>
4083
4084 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#_netCDF4.CompoundType">netCDF4._netCDF4.CompoundType</a>&#39; objects&gt;</span>
4085 </div>
4086
4087
4088
4089 </div>
4090 </section>
4091 <section id="VLType">
4092 <div class="attr class">
4093 <a class="headerlink" href="#VLType">#&nbsp;&nbsp</a>
4094
4095
4096 <span class="def">class</span>
4097 <span class="name">VLType</span>:
4098 </div>
4099
4100
4101 <div class="docstring"><p>A <code><a href="#VLType">VLType</a></code> instance is used to describe a variable length (VLEN) data
4102 type, and can be passed to the the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of
4103 a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance. See
4104 <code><a href="#VLType.__init__">VLType.__init__</a></code> for more details.</p>
4105
4106 <p>The instance variables <code><a href="#VLType.dtype">dtype</a></code> and <code><a href="#VLType.name">name</a></code> should not be modified by
4107 the user.</p>
4108 </div>
4109
4110
4111 <div id="VLType.__init__" class="classattr">
4112 <div class="attr function"><a class="headerlink" href="#VLType.__init__">#&nbsp;&nbsp</a>
4113
4114
4115 <span class="name">VLType</span><span class="signature">()</span>
4116 </div>
4117
4118
4119 <div class="docstring"><p><strong><code>__init__(group, datatype, datatype_name)</code></strong></p>
4120
4121 <p>VLType constructor.</p>
4122
4123 <p><strong><code>group</code></strong>: <code><a href="#Group">Group</a></code> instance to associate with the VLEN datatype.</p>
4124
4125 <p><strong><code>datatype</code></strong>: An numpy dtype object describing the component type for the
4126 variable length array.</p>
4127
4128 <p><strong><code>datatype_name</code></strong>: a Python string containing a description of the
4129 VLEN data type.</p>
4130
4131 <p><strong><em><code>Note</code></em></strong>: <code><a href="#VLType">VLType</a></code> instances should be created using the
4132 <code><a href="#Dataset.createVLType">Dataset.createVLType</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or
4133 <code><a href="#Group">Group</a></code> instance, not using this class directly.</p>
4134 </div>
4135
4136
4137 </div>
4138 <div id="VLType.dtype" class="classattr">
4139 <div class="attr variable"><a class="headerlink" href="#VLType.dtype">#&nbsp;&nbsp</a>
4140
4141 <span class="name">dtype</span><span class="default_value"> = &lt;attribute &#39;dtype&#39; of &#39;<a href="#_netCDF4.VLType">netCDF4._netCDF4.VLType</a>&#39; objects&gt;</span>
4142 </div>
4143
4144
4145
4146 </div>
4147 <div id="VLType.name" class="classattr">
4148 <div class="attr variable"><a class="headerlink" href="#VLType.name">#&nbsp;&nbsp</a>
4149
4150 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#_netCDF4.VLType">netCDF4._netCDF4.VLType</a>&#39; objects&gt;</span>
4151 </div>
4152
4153
4154
4155 </div>
4156 </section>
4157 <section id="date2num">
4158 <div class="attr function"><a class="headerlink" href="#date2num">#&nbsp;&nbsp</a>
4159
4160
4161 <span class="def">def</span>
4162 <span class="name">date2num</span><span class="signature">(unknown)</span>:
4163 </div>
4164
4165
4166 <div class="docstring"><p>date2num(dates, units, calendar=None, has_year_zero=None)</p>
4167
4168 <p>Return numeric time values given datetime objects. The units
4169 of the numeric time values are described by the <strong>units</strong> argument
4170 and the <strong>calendar</strong> keyword. The datetime objects must
4171 be in UTC with no time-zone offset. If there is a
4172 time-zone offset in <strong>units</strong>, it will be applied to the
4173 returned numeric values.</p>
4174
4175 <p><strong>dates</strong>: A datetime object or a sequence of datetime objects.
4176 The datetime objects should not include a time-zone offset. They
4177 can be either native python datetime instances (which use
4178 the proleptic gregorian calendar) or cftime.datetime instances.</p>
4179
4180 <p><strong>units</strong>: a string of the form <strong><time units> since <reference time></strong>
4181 describing the time units. <strong><time units></strong> can be days, hours, minutes,
4182 seconds, milliseconds or microseconds. <strong><reference time></strong> is the time
4183 origin. <strong>months_since</strong> is allowed <em>only</em> for the <strong>360_day</strong> calendar.</p>
4184
4185 <p><strong>calendar</strong>: describes the calendar to be used in the time calculations.
4186 All the values currently defined in the
4187 <code>CF metadata convention &lt;http://cfconventions.org&gt;</code>__ are supported.
4188 Valid calendars <strong>'standard', 'gregorian', 'proleptic_gregorian'
4189 'noleap', '365_day', '360_day', 'julian', 'all_leap', '366_day'</strong>.
4190 Default is <code>None</code> which means the calendar associated with the first
4191 input datetime instance will be used.</p>
4192
4193 <p><strong>has_year_zero</strong>: If set to True, astronomical year numbering
4194 is used and the year zero exists. If set to False for real-world
4195 calendars, then historical year numbering is used and the year 1 is
4196 preceded by year -1 and no year zero exists.
4197 The defaults are False for real-world calendars
4198 and True for idealized calendars.
4199 The defaults can only be over-ridden for the real-world calendars,
4200 for the the idealized calendars the year zero
4201 always exists and the has_year_zero kwarg is ignored.
4202 This kwarg is not needed to define calendar systems allowed by CF
4203 (the calendar-specific defaults do this).</p>
4204
4205 <p>returns a numeric time value, or an array of numeric time values
4206 with approximately 1 microsecond accuracy.</p>
4207 </div>
4208
4209
4210 </section>
4211 <section id="num2date">
4212 <div class="attr function"><a class="headerlink" href="#num2date">#&nbsp;&nbsp</a>
4213
4214
4215 <span class="def">def</span>
4216 <span class="name">num2date</span><span class="signature">(unknown)</span>:
4217 </div>
4218
4219
4220 <div class="docstring"><p>num2date(times, units, calendar=u'standard', only_use_cftime_datetimes=True, only_use_python_datetimes=False, has_year_zero=None)</p>
4221
4222 <p>Return datetime objects given numeric time values. The units
4223 of the numeric time values are described by the <strong>units</strong> argument
4224 and the <strong>calendar</strong> keyword. The returned datetime objects represent
4225 UTC with no time-zone offset, even if the specified
4226 <strong>units</strong> contain a time-zone offset.</p>
4227
4228 <p><strong>times</strong>: numeric time values.</p>
4229
4230 <p><strong>units</strong>: a string of the form <strong><time units> since <reference time></strong>
4231 describing the time units. <strong><time units></strong> can be days, hours, minutes,
4232 seconds, milliseconds or microseconds. <strong><reference time></strong> is the time
4233 origin. <strong>months_since</strong> is allowed <em>only</em> for the <strong>360_day</strong> calendar.</p>
4234
4235 <p><strong>calendar</strong>: describes the calendar used in the time calculations.
4236 All the values currently defined in the
4237 <code>CF metadata convention &lt;http://cfconventions.org&gt;</code>__ are supported.
4238 Valid calendars <strong>'standard', 'gregorian', 'proleptic_gregorian'
4239 'noleap', '365_day', '360_day', 'julian', 'all_leap', '366_day'</strong>.
4240 Default is <strong>'standard'</strong>, which is a mixed Julian/Gregorian calendar.</p>
4241
4242 <p><strong>only_use_cftime_datetimes</strong>: if False, python datetime.datetime
4243 objects are returned from num2date where possible; if True dates which
4244 subclass cftime.datetime are returned for all calendars. Default <strong>True</strong>.</p>
4245
4246 <p><strong>only_use_python_datetimes</strong>: always return python datetime.datetime
4247 objects and raise an error if this is not possible. Ignored unless
4248 <strong>only_use_cftime_datetimes=False</strong>. Default <strong>False</strong>.</p>
4249
4250 <p><strong>has_year_zero</strong>: if set to True, astronomical year numbering
4251 is used and the year zero exists. If set to False for real-world
4252 calendars, then historical year numbering is used and the year 1 is
4253 preceded by year -1 and no year zero exists.
4254 The defaults are False for real-world calendars
4255 and True for idealized calendars.
4256 The defaults can only be over-ridden for the real-world calendars,
4257 for the the idealized calendars the year zero
4258 always exists and the has_year_zero kwarg is ignored.
4259 This kwarg is not needed to define calendar systems allowed by CF
4260 (the calendar-specific defaults do this).</p>
4261
4262 <p>returns a datetime instance, or an array of datetime instances with
4263 microsecond accuracy, if possible.</p>
4264
4265 <p><strong><em>Note</em></strong>: If only_use_cftime_datetimes=False and
4266 use_only_python_datetimes=False, the datetime instances
4267 returned are 'real' python datetime
4268 objects if <strong>calendar='proleptic_gregorian'</strong>, or
4269 <strong>calendar='standard'</strong> or <strong>'gregorian'</strong>
4270 and the date is after the breakpoint between the Julian and
4271 Gregorian calendars (1582-10-15). Otherwise, they are ctime.datetime
4272 objects which support some but not all the methods of native python
4273 datetime objects. The datetime instances
4274 do not contain a time-zone offset, even if the specified <strong>units</strong>
4275 contains one.</p>
4276 </div>
4277
4278
4279 </section>
4280 <section id="date2index">
4281 <div class="attr function"><a class="headerlink" href="#date2index">#&nbsp;&nbsp</a>
4282
4283
4284 <span class="def">def</span>
4285 <span class="name">date2index</span><span class="signature">(unknown)</span>:
4286 </div>
4287
4288
4289 <div class="docstring"><p>date2index(dates, nctime, calendar=None, select=u'exact', has_year_zero=None)</p>
4290
4291 <p>Return indices of a netCDF time variable corresponding to the given dates.</p>
4292
4293 <p><strong>dates</strong>: A datetime object or a sequence of datetime objects.
4294 The datetime objects should not include a time-zone offset.</p>
4295
4296 <p><strong>nctime</strong>: A netCDF time variable object. The nctime object must have a
4297 <strong>units</strong> attribute.</p>
4298
4299 <p><strong>calendar</strong>: describes the calendar to be used in the time calculations.
4300 All the values currently defined in the
4301 <code>CF metadata convention &lt;http://cfconventions.org&gt;</code>__ are supported.
4302 Valid calendars <strong>'standard', 'gregorian', 'proleptic_gregorian'
4303 'noleap', '365_day', '360_day', 'julian', 'all_leap', '366_day'</strong>.
4304 Default is <code>None</code> which means the calendar associated with the first
4305 input datetime instance will be used.</p>
4306
4307 <p><strong>select</strong>: <strong>'exact', 'before', 'after', 'nearest'</strong>
4308 The index selection method. <strong>exact</strong> will return the indices perfectly
4309 matching the dates given. <strong>before</strong> and <strong>after</strong> will return the indices
4310 corresponding to the dates just before or just after the given dates if
4311 an exact match cannot be found. <strong>nearest</strong> will return the indices that
4312 correspond to the closest dates.</p>
4313
4314 <p><strong>has_year_zero</strong>: if set to True, astronomical year numbering
4315 is used and the year zero exists. If set to False for real-world
4316 calendars, then historical year numbering is used and the year 1 is
4317 preceded by year -1 and no year zero exists.
4318 The defaults are False for real-world calendars
4319 and True for idealized calendars.
4320 The defaults can only be over-ridden for the real-world calendars,
4321 for the the idealized calendars the year zero
4322 always exists and the has_year_zero kwarg is ignored.
4323 This kwarg is not needed to define calendar systems allowed by CF
4324 (the calendar-specific defaults do this).</p>
4325
4326 <p>returns an index (indices) of the netCDF time variable corresponding
4327 to the given datetime object(s).</p>
4328 </div>
4329
4330
4331 </section>
4332 <section id="stringtochar">
4333 <div class="attr function"><a class="headerlink" href="#stringtochar">#&nbsp;&nbsp</a>
4334
4335
4336 <span class="def">def</span>
4337 <span class="name">stringtochar</span><span class="signature">(unknown)</span>:
4338 </div>
4339
4340
4341 <div class="docstring"><p><strong><code>stringtochar(a,encoding='utf-8')</code></strong></p>
4342
4343 <p>convert a string array to a character array with one extra dimension</p>
4344
4345 <p><strong><code>a</code></strong>: Input numpy string array with numpy datatype <code>'SN'</code> or <code>'UN'</code>, where N
4346 is the number of characters in each string. Will be converted to
4347 an array of characters (datatype <code>'S1'</code> or <code>'U1'</code>) of shape <code>a.shape + (N,)</code>.</p>
4348
4349 <p>optional kwarg <code>encoding</code> can be used to specify character encoding (default
4350 <code>utf-8</code>). If <code>encoding</code> is 'none' or 'bytes', a <code>numpy.string_</code> the input array
4351 is treated a raw byte strings (<code>numpy.string_</code>).</p>
4352
4353 <p>returns a numpy character array with datatype <code>'S1'</code> or <code>'U1'</code>
4354 and shape <code>a.shape + (N,)</code>, where N is the length of each string in a.</p>
4355 </div>
4356
4357
4358 </section>
4359 <section id="chartostring">
4360 <div class="attr function"><a class="headerlink" href="#chartostring">#&nbsp;&nbsp</a>
4361
4362
4363 <span class="def">def</span>
4364 <span class="name">chartostring</span><span class="signature">(unknown)</span>:
4365 </div>
4366
4367
4368 <div class="docstring"><p><strong><code>chartostring(b,encoding='utf-8')</code></strong></p>
4369
4370 <p>convert a character array to a string array with one less dimension.</p>
4371
4372 <p><strong><code>b</code></strong>: Input character array (numpy datatype <code>'S1'</code> or <code>'U1'</code>).
4373 Will be converted to a array of strings, where each string has a fixed
4374 length of <code>b.shape[-1]</code> characters.</p>
4375
4376 <p>optional kwarg <code>encoding</code> can be used to specify character encoding (default
4377 <code>utf-8</code>). If <code>encoding</code> is 'none' or 'bytes', a <code>numpy.string_</code> btye array is
4378 returned.</p>
4379
4380 <p>returns a numpy string array with datatype <code>'UN'</code> (or <code>'SN'</code>) and shape
4381 <code>b.shape[:-1]</code> where where <code>N=b.shape[-1]</code>.</p>
4382 </div>
4383
4384
4385 </section>
4386 <section id="stringtoarr">
4387 <div class="attr function"><a class="headerlink" href="#stringtoarr">#&nbsp;&nbsp</a>
4388
4389
4390 <span class="def">def</span>
4391 <span class="name">stringtoarr</span><span class="signature">(unknown)</span>:
4392 </div>
4393
4394
4395 <div class="docstring"><p><strong><code>stringtoarr(a, NUMCHARS,dtype='S')</code></strong></p>
4396
4397 <p>convert a string to a character array of length <code>NUMCHARS</code></p>
4398
4399 <p><strong><code>a</code></strong>: Input python string.</p>
4400
4401 <p><strong><code>NUMCHARS</code></strong>: number of characters used to represent string
4402 (if len(a) &lt; <code>NUMCHARS</code>, it will be padded on the right with blanks).</p>
4403
4404 <p><strong><code>dtype</code></strong>: type of numpy array to return. Default is <code>'S'</code>, which
4405 means an array of dtype <code>'S1'</code> will be returned. If dtype=<code>'U'</code>, a
4406 unicode array (dtype = <code>'U1'</code>) will be returned.</p>
4407
4408 <p>returns a rank 1 numpy character array of length NUMCHARS with datatype <code>'S1'</code>
4409 (default) or <code>'U1'</code> (if dtype=<code>'U'</code>)</p>
4410 </div>
4411
4412
4413 </section>
4414 <section id="getlibversion">
4415 <div class="attr function"><a class="headerlink" href="#getlibversion">#&nbsp;&nbsp</a>
4416
4417
4418 <span class="def">def</span>
4419 <span class="name">getlibversion</span><span class="signature">(unknown)</span>:
4420 </div>
4421
4422
4423 <div class="docstring"><p><strong><code><a href="#getlibversion">getlibversion()</a></code></strong></p>
4424
4425 <p>returns a string describing the version of the netcdf library
4426 used to build the module, and when it was built.</p>
4427 </div>
4428
4429
4430 </section>
4431 <section id="EnumType">
4432 <div class="attr class">
4433 <a class="headerlink" href="#EnumType">#&nbsp;&nbsp</a>
4434
4435
4436 <span class="def">class</span>
4437 <span class="name">EnumType</span>:
4438 </div>
4439
4440
4441 <div class="docstring"><p>A <code><a href="#EnumType">EnumType</a></code> instance is used to describe an Enum data
4442 type, and can be passed to the the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of
4443 a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance. See
4444 <code><a href="#EnumType.__init__">EnumType.__init__</a></code> for more details.</p>
4445
4446 <p>The instance variables <code><a href="#EnumType.dtype">dtype</a></code>, <code><a href="#EnumType.name">name</a></code> and <code><a href="#EnumType.enum_dict">enum_dict</a></code> should not be modified by
4447 the user.</p>
4448 </div>
4449
4450
4451 <div id="EnumType.__init__" class="classattr">
4452 <div class="attr function"><a class="headerlink" href="#EnumType.__init__">#&nbsp;&nbsp</a>
4453
4454
4455 <span class="name">EnumType</span><span class="signature">()</span>
4456 </div>
4457
4458
4459 <div class="docstring"><p><strong><code>__init__(group, datatype, datatype_name, enum_dict)</code></strong></p>
4460
4461 <p>EnumType constructor.</p>
4462
4463 <p><strong><code>group</code></strong>: <code><a href="#Group">Group</a></code> instance to associate with the VLEN datatype.</p>
4464
4465 <p><strong><code>datatype</code></strong>: An numpy integer dtype object describing the base type
4466 for the Enum.</p>
4467
4468 <p><strong><code>datatype_name</code></strong>: a Python string containing a description of the
4469 Enum data type.</p>
4470
4471 <p><strong><code><a href="#EnumType.enum_dict">enum_dict</a></code></strong>: a Python dictionary containing the Enum field/value
4472 pairs.</p>
4473
4474 <p><strong><em><code>Note</code></em></strong>: <code><a href="#EnumType">EnumType</a></code> instances should be created using the
4475 <code><a href="#Dataset.createEnumType">Dataset.createEnumType</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or
4476 <code><a href="#Group">Group</a></code> instance, not using this class directly.</p>
4477 </div>
4478
4479
4480 </div>
4481 <div id="EnumType.dtype" class="classattr">
4482 <div class="attr variable"><a class="headerlink" href="#EnumType.dtype">#&nbsp;&nbsp</a>
4483
4484 <span class="name">dtype</span><span class="default_value"> = &lt;attribute &#39;dtype&#39; of &#39;<a href="#_netCDF4.EnumType">netCDF4._netCDF4.EnumType</a>&#39; objects&gt;</span>
4485 </div>
4486
4487
4488
4489 </div>
4490 <div id="EnumType.name" class="classattr">
4491 <div class="attr variable"><a class="headerlink" href="#EnumType.name">#&nbsp;&nbsp</a>
4492
4493 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#_netCDF4.EnumType">netCDF4._netCDF4.EnumType</a>&#39; objects&gt;</span>
4494 </div>
4495
4496
4497
4498 </div>
4499 <div id="EnumType.enum_dict" class="classattr">
4500 <div class="attr variable"><a class="headerlink" href="#EnumType.enum_dict">#&nbsp;&nbsp</a>
4501
4502 <span class="name">enum_dict</span><span class="default_value"> = &lt;attribute &#39;enum_dict&#39; of &#39;<a href="#_netCDF4.EnumType">netCDF4._netCDF4.EnumType</a>&#39; objects&gt;</span>
4503 </div>
4504
4505
4506
4507 </div>
4508 </section>
4509 <section id="get_chunk_cache">
4510 <div class="attr function"><a class="headerlink" href="#get_chunk_cache">#&nbsp;&nbsp</a>
4511
4512
4513 <span class="def">def</span>
4514 <span class="name">get_chunk_cache</span><span class="signature">(unknown)</span>:
4515 </div>
4516
4517
4518 <div class="docstring"><p><strong><code><a href="#get_chunk_cache">get_chunk_cache()</a></code></strong></p>
4519
4520 <p>return current netCDF chunk cache information in a tuple (size,nelems,preemption).
4521 See netcdf C library documentation for <code>nc_get_chunk_cache</code> for
4522 details. Values can be reset with <code><a href="#set_chunk_cache">set_chunk_cache</a></code>.</p>
4523 </div>
4524
4525
4526 </section>
4527 <section id="set_chunk_cache">
4528 <div class="attr function"><a class="headerlink" href="#set_chunk_cache">#&nbsp;&nbsp</a>
4529
4530
4531 <span class="def">def</span>
4532 <span class="name">set_chunk_cache</span><span class="signature">(unknown)</span>:
4533 </div>
4534
4535
4536 <div class="docstring"><p><strong><code>set_chunk_cache(self,size=None,nelems=None,preemption=None)</code></strong></p>
4537
4538 <p>change netCDF4 chunk cache settings.
4539 See netcdf C library documentation for <code>nc_set_chunk_cache</code> for
4540 details.</p>
4541 </div>
4542
4543
43424544 </section>
43434545 </main>
43444546 </body>
33 # can be serialized as strings, saved as netCDF attributes,
44 # and then converted back to python objects using json.
55 ds = Dataset('json.nc', 'w')
6 ds.pythonatt1 = json.dumps([u'foo', {u'bar': [u'baz', None, 1.0, 2]}])
6 ds.pythonatt1 = json.dumps(['foo', {'bar': ['baz', None, 1.0, 2]}])
77 ds.pythonatt2 = "true" # converted to bool
88 ds.pythonatt3 = "null" # converted to None
99 print(ds)
0 # to run: mpirun -np 4 python mpi_example_compressed.py
1 import sys
2 from mpi4py import MPI
3 import numpy as np
4 from netCDF4 import Dataset
5 rank = MPI.COMM_WORLD.rank # The process ID (integer 0-3 for 4-process run)
6 nc = Dataset('parallel_test_compressed.nc', 'w', parallel=True)
7 d = nc.createDimension('dim',4)
8 v = nc.createVariable('var', np.int32, 'dim', zlib=True)
9 v[:] = np.arange(4)
10 nc.close()
11 # read compressed files in parallel, check the data, try to rewrite some data
12 nc = Dataset('parallel_test_compressed.nc', 'a', parallel=True)
13 v = nc['var']
14 assert rank==v[rank]
15 v.set_collective(True) # issue #1108 (var must be in collective mode or write will fail)
16 v[rank]=2*rank
17 nc.close()
1515
1616 # walk the group tree using a Python generator.
1717 def walktree(top):
18 values = top.groups.values()
19 yield values
18 yield top.groups.values()
2019 for value in top.groups.values():
21 for children in walktree(value):
22 yield children
20 yield from walktree(value)
21
2322 print(rootgrp)
2423 for children in walktree(rootgrp):
2524 for child in children:
7978
8079 print(rootgrp.variables)
8180
82 import numpy
81 import numpy as np
8382 # no unlimited dimension, just assign to slice.
84 lats = numpy.arange(-90,91,2.5)
85 lons = numpy.arange(-180,180,2.5)
83 lats = np.arange(-90,91,2.5)
84 lons = np.arange(-180,180,2.5)
8685 latitudes[:] = lats
8786 longitudes[:] = lons
8887 print('latitudes =\n',latitudes[:])
110109 from netCDF4 import num2date, date2num, date2index
111110 dates = [datetime(2001,3,1)+n*timedelta(hours=12) for n in range(temp.shape[0])]
112111 times[:] = date2num(dates,units=times.units,calendar=times.calendar)
113 print('time values (in units %s): ' % times.units+'\\n',times[:])
112 print("time values (in units {}):\n{}".format(times.units, times[:]))
114113 dates = num2date(times[:],units=times.units,calendar=times.calendar)
115 print('dates corresponding to time values:\\n',dates)
114 print("dates corresponding to time values:\n{}".format(dates))
116115
117116 rootgrp.close()
118117
122121 f = Dataset('mftest'+repr(nfile)+'.nc','w',format='NETCDF4_CLASSIC')
123122 f.createDimension('x',None)
124123 x = f.createVariable('x','i',('x',))
125 x[0:10] = numpy.arange(nfile*10,10*(nfile+1))
124 x[0:10] = np.arange(nfile*10,10*(nfile+1))
126125 f.close()
127126 # now read all those files in at once, in one Dataset.
128127 from netCDF4 import MFDataset
133132 f = Dataset('complex.nc','w')
134133 size = 3 # length of 1-d complex array
135134 # create sample complex data.
136 datac = numpy.exp(1j*(1.+numpy.linspace(0, numpy.pi, size)))
135 datac = np.exp(1j*(1.+np.linspace(0, np.pi, size)))
137136 print(datac.dtype)
138137 # create complex128 compound data type.
139 complex128 = numpy.dtype([('real',numpy.float64),('imag',numpy.float64)])
138 complex128 = np.dtype([('real',np.float64),('imag',np.float64)])
140139 complex128_t = f.createCompoundType(complex128,'complex128')
141140 # create a variable with this data type, write some data to it.
142141 f.createDimension('x_dim',None)
143142 v = f.createVariable('cmplx_var',complex128_t,'x_dim')
144 data = numpy.empty(size,complex128) # numpy structured array
143 data = np.empty(size,complex128) # numpy structured array
145144 data['real'] = datac.real; data['imag'] = datac.imag
146145 v[:] = data
147146 # close and reopen the file, check the contents.
155154 print(v.shape)
156155 datain = v[:] # read in all the data into a numpy structured array
157156 # create an empty numpy complex array
158 datac2 = numpy.empty(datain.shape,numpy.complex128)
157 datac2 = np.empty(datain.shape,np.complex128)
159158 # .. fill it with contents of structured array.
160159 datac2.real = datain['real']
161160 datac2.imag = datain['imag']
167166 # create an unlimited dimension call 'station'
168167 f.createDimension('station',None)
169168 # define a compound data type (can contain arrays, or nested compound types).
170 winddtype = numpy.dtype([('speed','f4'),('direction','i4')])
171 statdtype = numpy.dtype([('latitude', 'f4'), ('longitude', 'f4'),
172 ('surface_wind',winddtype),
173 ('temp_sounding','f4',10),('press_sounding','i4',10),
174 ('location_name','S12')])
169 winddtype = np.dtype([('speed','f4'),('direction','i4')])
170 statdtype = np.dtype([('latitude', 'f4'), ('longitude', 'f4'),
171 ('surface_wind',winddtype),
172 ('temp_sounding','f4',10),('press_sounding','i4',10),
173 ('location_name','S12')])
175174 # use this data type definitions to create a compound data types
176175 # called using the createCompoundType Dataset method.
177176 # create a compound type for vector wind which will be nested inside
180179 # now that wind_data_t is defined, create the station data type.
181180 station_data_t = f.createCompoundType(statdtype,'station_data')
182181 # create nested compound data types to hold the units variable attribute.
183 winddtype_units = numpy.dtype([('speed','S12'),('direction','S12')])
184 statdtype_units = numpy.dtype([('latitude', 'S12'), ('longitude', 'S12'),
185 ('surface_wind',winddtype_units),
186 ('temp_sounding','S12'),
187 ('location_name','S12'),
188 ('press_sounding','S12')])
182 winddtype_units = np.dtype([('speed','S12'),('direction','S12')])
183 statdtype_units = np.dtype([('latitude', 'S12'), ('longitude', 'S12'),
184 ('surface_wind',winddtype_units),
185 ('temp_sounding','S12'),
186 ('location_name','S12'),
187 ('press_sounding','S12')])
189188 # create the wind_data_units type first, since it will nested inside
190189 # the station_data_units data type.
191190 wind_data_units_t = f.createCompoundType(winddtype_units,'wind_data_units')
194193 # create a variable of of type 'station_data_t'
195194 statdat = f.createVariable('station_obs', station_data_t, ('station',))
196195 # create a numpy structured array, assign data to it.
197 data = numpy.empty(1,statdtype)
196 data = np.empty(1,statdtype)
198197 data['latitude'] = 40.
199198 data['longitude'] = -105.
200199 data['surface_wind']['speed'] = 12.5
206205 statdat[0] = data
207206 # or just assign a tuple of values to variable slice
208207 # (will automatically be converted to a structured array).
209 statdat[1] = numpy.array((40.78,-73.99,(-12.5,90),
208 statdat[1] = np.array((40.78,-73.99,(-12.5,90),
210209 (290.2,282.5,279.,277.9,276.,266.,264.1,260.,255.5,243.),
211210 range(900,400,-50),'New York, NY'),data.dtype)
212211 print(f.cmptypes)
213 windunits = numpy.empty(1,winddtype_units)
214 stationobs_units = numpy.empty(1,statdtype_units)
212 windunits = np.empty(1,winddtype_units)
213 stationobs_units = np.empty(1,statdtype_units)
215214 windunits['speed'] = 'm/s'
216215 windunits['direction'] = 'degrees'
217216 stationobs_units['latitude'] = 'degrees N'
234233 f.close()
235234
236235 f = Dataset('tst_vlen.nc','w')
237 vlen_t = f.createVLType(numpy.int32, 'phony_vlen')
236 vlen_t = f.createVLType(np.int32, 'phony_vlen')
238237 x = f.createDimension('x',3)
239238 y = f.createDimension('y',4)
240239 vlvar = f.createVariable('phony_vlen_var', vlen_t, ('y','x'))
241240 import random
242 data = numpy.empty(len(y)*len(x),object)
241 data = np.empty(len(y)*len(x),object)
243242 for n in range(len(y)*len(x)):
244 data[n] = numpy.arange(random.randint(1,10),dtype='int32')+1
245 data = numpy.reshape(data,(len(y),len(x)))
243 data[n] = np.arange(random.randint(1,10),dtype='int32')+1
244 data = np.reshape(data,(len(y),len(x)))
246245 vlvar[:] = data
247246 print(vlvar)
248247 print('vlen variable =\n',vlvar[:])
252251 z = f.createDimension('z', 10)
253252 strvar = f.createVariable('strvar',str,'z')
254253 chars = '1234567890aabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
255 data = numpy.empty(10,object)
254 data = np.empty(10,object)
256255 for n in range(10):
257256 stringlen = random.randint(2,12)
258257 data[n] = ''.join([random.choice(chars) for i in range(stringlen)])
265264 # Enum type example.
266265 f = Dataset('clouds.nc','w')
267266 # python dict describing the allowed values and their names.
268 enum_dict = {u'Altocumulus': 7, u'Missing': 255, u'Stratus': 2, u'Clear': 0,
269 u'Nimbostratus': 6, u'Cumulus': 4, u'Altostratus': 5, u'Cumulonimbus': 1,
270 u'Stratocumulus': 3}
267 enum_dict = {'Altocumulus': 7, 'Missing': 255, 'Stratus': 2, 'Clear': 0,
268 'Nimbostratus': 6, 'Cumulus': 4, 'Altostratus': 5, 'Cumulonimbus': 1,
269 'Stratocumulus': 3}
271270 # create the Enum type called 'cloud_t'.
272 cloud_type = f.createEnumType(numpy.uint8,'cloud_t',enum_dict)
271 cloud_type = f.createEnumType(np.uint8,'cloud_t',enum_dict)
273272 print(cloud_type)
274273 time = f.createDimension('time',None)
275274 # create a 1d variable of type 'cloud_type' called 'primary_clouds'.
294293 nc.createDimension('nchars',3)
295294 nc.createDimension('nstrings',None)
296295 v = nc.createVariable('strings','S1',('nstrings','nchars'))
297 datain = numpy.array(['foo','bar'],dtype='S3')
296 datain = np.array(['foo','bar'],dtype='S3')
298297 v[:] = stringtochar(datain) # manual conversion to char array
299298 print(v[:]) # data returned as char array
300299 v._Encoding = 'ascii' # this enables automatic conversion
303302 nc.close()
304303 # strings in compound types
305304 nc = Dataset('compoundstring_example.nc','w')
306 dtype = numpy.dtype([('observation', 'f4'),
307 ('station_name','S12')])
305 dtype = np.dtype([('observation', 'f4'),
306 ('station_name','S12')])
308307 station_data_t = nc.createCompoundType(dtype,'station_data')
309308 nc.createDimension('station',None)
310309 statdat = nc.createVariable('station_obs', station_data_t, ('station',))
311 data = numpy.empty(2,station_data_t.dtype_view)
310 data = np.empty(2,station_data_t.dtype_view)
312311 data['observation'][:] = (123.,3.14)
313312 data['station_name'][:] = ('Boulder','New York')
314313 print(statdat.dtype) # strings actually stored as character arrays
324323 # to disk when it is closed.
325324 nc = Dataset('diskless_example.nc','w',diskless=True,persist=True)
326325 d = nc.createDimension('x',None)
327 v = nc.createVariable('v',numpy.int32,'x')
328 v[0:5] = numpy.arange(5)
326 v = nc.createVariable('v',np.int32,'x')
327 v[0:5] = np.arange(5)
329328 print(nc)
330329 print(nc['v'][:])
331330 nc.close() # file saved to disk
344343 # used if format is NETCDF3 (ignored for NETCDF4/HDF5 files).
345344 nc = Dataset('inmemory.nc', mode='w',memory=1028)
346345 d = nc.createDimension('x',None)
347 v = nc.createVariable('v',numpy.int32,'x')
348 v[0:5] = numpy.arange(5)
346 v = nc.createVariable('v',np.int32,'x')
347 v[0:5] = np.arange(5)
349348 nc_buf = nc.close() # close returns memoryview
350349 print(type(nc_buf))
351350 # save nc_buf to disk, read it back in and check.
00 import os, sys, subprocess
11 import os.path as osp
2 import configparser
23 from setuptools import setup, Extension
34 from distutils.dist import Distribution
45
1415 },
1516 }
1617
17 if sys.version_info[0] < 3:
18 import ConfigParser as configparser
19
20 open_kwargs = {}
21 else:
22 import configparser
23
24 open_kwargs = {'encoding': 'utf-8'}
18 open_kwargs = {'encoding': 'utf-8'}
2519
2620
2721 def check_hdf5version(hdf5_includedir):
00 """
1 Version 1.5.6
1 Version 1.5.7
22 -------------
33
44 # Introduction
2222 compound types containing enums, or vlens containing compound
2323 types) are not supported.
2424
25 ## Download
26
27 - Latest bleeding-edge code from the
25 ## Quick Install
26
27 - the easiest way to get going is to install via `pip install netCDF4`.
28 (or if you use the [conda](http://conda.io) package manager `conda install -c conda-forge netCDF4`).
29
30 ## Developer Install
31
32 - Clone the
2833 [github repository](http://github.com/Unidata/netcdf4-python).
29 - Latest [releases](https://pypi.python.org/pypi/netCDF4)
30 (source code and binary installers).
31
32 ## Requires
33
34 - Python 3.6 or later.
35 - [numpy array module](http://numpy.scipy.org), version 1.10.0 or later.
36 - [Cython](http://cython.org), version 0.21 or later.
37 - [setuptools](https://pypi.python.org/pypi/setuptools), version 18.0 or
38 later.
39 - The HDF5 C library version 1.8.4-patch1 or higher
40 from [](ftp://ftp.hdfgroup.org/HDF5/current/src).
41 ***netCDF version 4.4.1 or higher is recommended if using HDF5 1.10.x -
42 otherwise resulting files may be unreadable by clients using earlier
43 versions of HDF5. For netCDF < 4.4.1, HDF5 version 1.8.x is recommended.***
44 Be sure to build with `--enable-hl --enable-shared`.
45 - [Libcurl](http://curl.haxx.se/libcurl), if you want
46 [OPeNDAP](http://opendap.org) support.
47 - [HDF4](http://www.hdfgroup.org/products/hdf4), if you want
48 to be able to read HDF4 "Scientific Dataset" (SD) files.
49 - The netCDF-4 C library from the [github releases
50 page](https://github.com/Unidata/netcdf-c/releases).
51 Version 4.1.1 or higher is required (4.2 or higher recommended).
52 Be sure to build with `--enable-netcdf-4 --enable-shared`, and set
53 `CPPFLAGS="-I $HDF5_DIR/include"` and `LDFLAGS="-L $HDF5_DIR/lib"`,
54 where `$HDF5_DIR` is the directory where HDF5 was installed.
55 If you want [OPeNDAP](http://opendap.org) support, add `--enable-dap`.
56 If you want HDF4 SD support, add `--enable-hdf4` and add
57 the location of the HDF4 headers and library to `$CPPFLAGS` and `$LDFLAGS`.
58 - for MPI parallel IO support, an MPI-enabled versions of the netcdf library
59 is required, as is the [mpi4py](http://mpi4py.scipy.org) python module.
60 Parallel IO further depends on the existence of MPI-enabled HDF5 or the
61 [PnetCDF](https://parallel-netcdf.github.io/) library.
62 - [cftime](https://github.com/Unidata/cftime) for
63 time and date handling utility functions.
64
65
66 ## Install
67
68 - install the requisite python modules and C libraries (see above). It's
69 easiest if all the C libs are built as shared libraries.
70 - By default, the utility `nc-config`, installed with netcdf 4.1.2 or higher,
71 will be run used to determine where all the dependencies live.
34 - Make sure the dependencies are satisfied (Python 3.6 or later,
35 [numpy](http://numpy.scipy.org),
36 [Cython](http://cython.org),
37 [cftime](https://github.com/Unidata/cftime),
38 [setuptools](https://pypi.python.org/pypi/setuptools),
39 the [HDF5 C library](https://www.hdfgroup.org/solutions/hdf5/),
40 and the [netCDF C library](https://www.unidata.ucar.edu/software/netcdf/)).
41 For MPI parallel IO support, an MPI-enabled versions of the netcdf library
42 is required, as is [mpi4py](http://mpi4py.scipy.org).
43 Parallel IO further depends on the existence of MPI-enabled HDF5 or the
44 [PnetCDF](https://parallel-netcdf.github.io/) library.
45 - By default, the utility `nc-config` (installed with netcdf-c)
46 will be run used to determine where all the dependencies live.
7247 - If `nc-config` is not in your default `PATH`, you can set the `NETCDF4_DIR`
73 environment variable and `setup.py` will look in `$NETCDF4_DIR/bin`.
74 You can also use the file `setup.cfg` to set the path to `nc-config`, or
75 enter the paths to the libraries and include files manually. Just edit the `setup.cfg` file
76 in a text editor and follow the instructions in the comments.
77 To disable the use of `nc-config`, set the env var `USE_NCCONFIG` to 0.
78 To disable the use of `setup.cfg`, set `USE_SETUPCFG` to 0.
79 As a last resort, the library and include paths can be set via environment variables.
80 If you go this route, set `USE_NCCONFIG` and `USE_SETUPCFG` to 0, and specify
81 `NETCDF4_LIBDIR`, `NETCDF4_INCDIR`, `HDF5_LIBDIR` and `HDF5_INCDIR`.
82 Similarly, environment variables
83 (all capitalized) can be used to set the include and library paths for
84 `hdf4`, `szip`, `jpeg`, `curl` and `zlib`. If the dependencies are not found
85 in any of the paths specified by environment variables, then standard locations
86 (such as `/usr` and `/usr/local`) are searched.
48 environment variable and `setup.py` will look in `$NETCDF4_DIR/bin`.
49 You can also use the file `setup.cfg` to set the path to `nc-config`, or
50 enter the paths to the libraries and include files manually. Just edit the `setup.cfg` file
51 in a text editor and follow the instructions in the comments.
52 To disable the use of `nc-config`, set the env var `USE_NCCONFIG` to 0.
53 To disable the use of `setup.cfg`, set `USE_SETUPCFG` to 0.
54 As a last resort, the library and include paths can be set via environment variables.
55 If you go this route, set `USE_NCCONFIG` and `USE_SETUPCFG` to 0, and specify
56 `NETCDF4_LIBDIR`, `NETCDF4_INCDIR`, `HDF5_LIBDIR` and `HDF5_INCDIR`.
57 If the dependencies are not found
58 in any of the paths specified by environment variables, then standard locations
59 (such as `/usr` and `/usr/local`) are searched.
8760 - run `python setup.py build`, then `python setup.py install` (as root if
88 necessary). `pip install` can be used to install pre-compiled binary wheels from
89 [pypi](https://pypi.org/project/netCDF4).
61 necessary).
9062 - run the tests in the 'test' directory by running `python run_all.py`.
9163
9264 # Tutorial
10981
11082 ## Creating/Opening/Closing a netCDF file
11183
112 To create a netCDF file from python, you simply call the [Dataset](#Dataset)
84 To create a netCDF file from python, you simply call the `Dataset`
11385 constructor. This is also the method used to open an existing netCDF
11486 file. If the file is open for write access (`mode='w', 'r+'` or `'a'`), you may
11587 write any type of data including new dimensions, groups, variables and
133105 keyword in the `Dataset` constructor. The default format is
134106 `NETCDF4`. To see how a given file is formatted, you can examine the
135107 `data_model` attribute. Closing the netCDF file is
136 accomplished via the [Dataset.close](#Dataset.close) method of the [Dataset](#Dataset)
108 accomplished via the `Dataset.close` method of the `Dataset`
137109 instance.
138110
139111 Here's an example:
147119 ```
148120
149121 Remote [OPeNDAP](http://opendap.org)-hosted datasets can be accessed for
150 reading over http if a URL is provided to the [Dataset](#Dataset) constructor instead of a
122 reading over http if a URL is provided to the `Dataset` constructor instead of a
151123 filename. However, this requires that the netCDF library be built with
152124 OPenDAP support, via the `--enable-dap` configure option (added in
153125 version 4.0.1).
158130 netCDF version 4 added support for organizing data in hierarchical
159131 groups, which are analogous to directories in a filesystem. Groups serve
160132 as containers for variables, dimensions and attributes, as well as other
161 groups. A [Dataset](#Dataset) creates a special group, called
133 groups. A `Dataset` creates a special group, called
162134 the 'root group', which is similar to the root directory in a unix
163 filesystem. To create [Group](#Group) instances, use the
164 [Dataset.createGroup](#Dataset.createGroup) method of a [Dataset](#Dataset) or [Group](#Group)
165 instance. [Dataset.createGroup](#Dataset.createGroup) takes a single argument, a
166 python string containing the name of the new group. The new [Group](#Group)
135 filesystem. To create `Group` instances, use the
136 `Dataset.createGroup` method of a `Dataset` or `Group`
137 instance. `Dataset.createGroup` takes a single argument, a
138 python string containing the name of the new group. The new `Group`
167139 instances contained within the root group can be accessed by name using
168 the `groups` dictionary attribute of the [Dataset](#Dataset) instance. Only
140 the `groups` dictionary attribute of the `Dataset` instance. Only
169141 `NETCDF4` formatted files support Groups, if you try to create a Group
170142 in a netCDF 3 file you will get an error message.
171143
186158 >>>
187159 ```
188160
189 Groups can exist within groups in a [Dataset](#Dataset), just as directories
190 exist within directories in a unix filesystem. Each [Group](#Group) instance
161 Groups can exist within groups in a `Dataset`, just as directories
162 exist within directories in a unix filesystem. Each `Group` instance
191163 has a `groups` attribute dictionary containing all of the group
192 instances contained within that group. Each [Group](#Group) instance also has a
164 instances contained within that group. Each `Group` instance also has a
193165 `path` attribute that contains a simulated unix directory path to
194166 that group. To simplify the creation of nested groups, you can
195 use a unix-like path as an argument to [Dataset.createGroup](#Dataset.createGroup).
167 use a unix-like path as an argument to `Dataset.createGroup`.
196168
197169 ```python
198170 >>> fcstgrp1 = rootgrp.createGroup("/forecasts/model1")
205177 returned.
206178
207179 Here's an example that shows how to navigate all the groups in a
208 [Dataset](#Dataset). The function `walktree` is a Python generator that is used
209 to walk the directory tree. Note that printing the [Dataset](#Dataset) or [Group](#Group)
180 `Dataset`. The function `walktree` is a Python generator that is used
181 to walk the directory tree. Note that printing the `Dataset` or `Group`
210182 object yields summary information about it's contents.
211183
212184 ```python
213185 >>> def walktree(top):
214 ... values = top.groups.values()
215 ... yield values
186 ... yield top.groups.values()
216187 ... for value in top.groups.values():
217 ... for children in walktree(value):
218 ... yield children
188 ... yield from walktree(value)
219189 >>> print(rootgrp)
220190 <class 'netCDF4._netCDF4.Dataset'>
221191 root group (NETCDF4 data model, file format HDF5):
253223 before any variables can be created the dimensions they use must be
254224 created first. A special case, not often used in practice, is that of a
255225 scalar variable, which has no dimensions. A dimension is created using
256 the [Dataset.createDimension](#Dataset.createDimension) method of a [Dataset](#Dataset)
257 or [Group](#Group) instance. A Python string is used to set the name of the
226 the `Dataset.createDimension` method of a `Dataset`
227 or `Group` instance. A Python string is used to set the name of the
258228 dimension, and an integer value is used to set the size. To create an
259229 unlimited dimension (a dimension that can be appended to), the size
260230 value is set to `None` or 0. In this example, there both the `time` and
270240 ```
271241
272242
273 All of the [Dimension](#Dimension) instances are stored in a python dictionary.
243 All of the `Dimension` instances are stored in a python dictionary.
274244
275245 ```python
276246 >>> print(rootgrp.dimensions)
277247 {'level': <class 'netCDF4._netCDF4.Dimension'> (unlimited): name = 'level', size = 0, 'time': <class 'netCDF4._netCDF4.Dimension'> (unlimited): name = 'time', size = 0, 'lat': <class 'netCDF4._netCDF4.Dimension'>: name = 'lat', size = 73, 'lon': <class 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 144}
278248 ```
279249
280 Using the python `len` function with a [Dimension](#Dimension) instance returns
250 Using the python `len` function with a `Dimension` instance returns
281251 current size of that dimension.
282 [Dimension.isunlimited](#Dimension.isunlimited) method of a [Dimension](#Dimension) instance
252 `Dimension.isunlimited` method of a `Dimension` instance
283253 be used to determine if the dimensions is unlimited, or appendable.
284254
285255 ```python
291261 True
292262 ```
293263
294 Printing the [Dimension](#Dimension) object
264 Printing the `Dimension` object
295265 provides useful summary info, including the name and length of the dimension,
296266 and whether it is unlimited.
297267
304274 <class 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 144
305275 ```
306276
307 [Dimension](#Dimension) names can be changed using the
308 [Datatset.renameDimension](#Datatset.renameDimension) method of a [Dataset](#Dataset) or
309 [Group](#Group) instance.
277 `Dimension` names can be changed using the
278 `Datatset.renameDimension` method of a `Dataset` or
279 `Group` instance.
310280
311281 ## Variables in a netCDF file
312282
314284 supplied by the [numpy module](http://numpy.scipy.org). However,
315285 unlike numpy arrays, netCDF4 variables can be appended to along one or
316286 more 'unlimited' dimensions. To create a netCDF variable, use the
317 [Dataset.createVariable](#Dataset.createVariable) method of a [Dataset](#Dataset) or
318 [Group](#Group) instance. The [Dataset.createVariable](#Dataset.createVariable) method
287 `Dataset.createVariable` method of a `Dataset` or
288 `Group` instance. The `Dataset.createVariable`j method
319289 has two mandatory arguments, the variable name (a Python string), and
320290 the variable datatype. The variable's dimensions are given by a tuple
321291 containing the dimension names (defined previously with
322 [Dataset.createDimension](#Dataset.createDimension)). To create a scalar
292 `Dataset.createDimension`). To create a scalar
323293 variable, simply leave out the dimensions keyword. The variable
324294 primitive datatypes correspond to the dtype attribute of a numpy array.
325295 You can specify the datatype as a numpy dtype object, or anything that
337307 can only be used if the file format is `NETCDF4`.
338308
339309 The dimensions themselves are usually also defined as variables, called
340 coordinate variables. The [Dataset.createVariable](#Dataset.createVariable)
341 method returns an instance of the [Variable](#Variable) class whose methods can be
310 coordinate variables. The `Dataset.createVariable`
311 method returns an instance of the `Variable` class whose methods can be
342312 used later to access and set variable data and attributes.
343313
344314 ```python
351321 >>> temp.units = "K"
352322 ```
353323
354 To get summary info on a [Variable](#Variable) instance in an interactive session,
324 To get summary info on a `Variable` instance in an interactive session,
355325 just print it.
356326
357327 ```python
372342
373343 If the intermediate groups do not yet exist, they will be created.
374344
375 You can also query a [Dataset](#Dataset) or [Group](#Group) instance directly to obtain [Group](#Group) or
376 [Variable](#Variable) instances using paths.
345 You can also query a `Dataset` or `Group` instance directly to obtain `Group` or
346 `Variable` instances using paths.
377347
378348 ```python
379349 >>> print(rootgrp["/forecasts/model1"]) # a Group instance
392362 ```
393363
394364
395 All of the variables in the [Dataset](#Dataset) or [Group](#Group) are stored in a
365 All of the variables in the `Dataset` or `Group` are stored in a
396366 Python dictionary, in the same way as the dimensions:
397367
398368 ```python
421391 filling on, default _FillValue of 9.969209968386869e+36 used}
422392 ```
423393
424 [Variable](#Variable) names can be changed using the
425 [Dataset.renameVariable](#Dataset.renameVariable) method of a [Dataset](#Dataset)
394 `Variable` names can be changed using the
395 `Dataset.renameVariable` method of a `Dataset`
426396 instance.
427397
428398 Variables can be sliced similar to numpy arrays, but there are some differences. See
433403
434404 There are two types of attributes in a netCDF file, global and variable.
435405 Global attributes provide information about a group, or the entire
436 dataset, as a whole. [Variable](#Variable) attributes provide information about
406 dataset, as a whole. `Variable` attributes provide information about
437407 one of the variables in a group. Global attributes are set by assigning
438 values to [Dataset](#Dataset) or [Group](#Group) instance variables. [Variable](#Variable)
439 attributes are set by assigning values to [Variable](#Variable) instances
408 values to `Dataset` or `Group` instance variables. `Variable`
409 attributes are set by assigning values to `Variable` instances
440410 variables. Attributes can be strings, numbers or sequences. Returning to
441411 our example,
442412
453423 >>> times.calendar = "gregorian"
454424 ```
455425
456 The [Dataset.ncattrs](#Dataset.ncattrs) method of a [Dataset](#Dataset), [Group](#Group) or
457 [Variable](#Variable) instance can be used to retrieve the names of all the netCDF
426 The `Dataset.ncattrs` method of a `Dataset`, `Group` or
427 `Variable` instance can be used to retrieve the names of all the netCDF
458428 attributes. This method is provided as a convenience, since using the
459429 built-in `dir` Python function will return a bunch of private methods
460430 and attributes that cannot (or should not) be modified by the user.
467437 Global attr source = netCDF4 python module tutorial
468438 ```
469439
470 The `__dict__` attribute of a [Dataset](#Dataset), [Group](#Group) or [Variable](#Variable)
440 The `__dict__` attribute of a `Dataset`, `Group` or `Variable`
471441 instance provides all the netCDF attribute name/value pairs in a python
472442 dictionary:
473443
476446 {'description': 'bogus example script', 'history': 'Created Mon Jul 8 14:19:41 2019', 'source': 'netCDF4 python module tutorial'}
477447 ```
478448
479 Attributes can be deleted from a netCDF [Dataset](#Dataset), [Group](#Group) or
480 [Variable](#Variable) using the python `del` statement (i.e. `del grp.foo`
449 Attributes can be deleted from a netCDF `Dataset`, `Group` or
450 `Variable` using the python `del` statement (i.e. `del grp.foo`
481451 removes the attribute `foo` the the group `grp`).
482452
483453 ## Writing data to and retrieving data from a netCDF variable
484454
485 Now that you have a netCDF [Variable](#Variable) instance, how do you put data
455 Now that you have a netCDF `Variable` instance, how do you put data
486456 into it? You can just treat it like an array and assign data to a slice.
487457
488458 ```python
489 >>> import numpy
490 >>> lats = numpy.arange(-90,91,2.5)
491 >>> lons = numpy.arange(-180,180,2.5)
459 >>> import numpy as np
460 >>> lats = np.arange(-90,91,2.5)
461 >>> lons = np.arange(-180,180,2.5)
492462 >>> latitudes[:] = lats
493463 >>> longitudes[:] = lons
494464 >>> print("latitudes =\\n{}".format(latitudes[:]))
502472 90. ]
503473 ```
504474
505 Unlike NumPy's array objects, netCDF [Variable](#Variable)
475 Unlike NumPy's array objects, netCDF `Variable`
506476 objects with unlimited dimensions will grow along those dimensions if you
507477 assign data outside the currently defined range of indices.
508478
578548 The result will be a numpy scalar array.
579549
580550 By default, netcdf4-python returns numpy masked arrays with values equal to the
581 `missing_value` or `_FillValue` variable attributes masked. The
582 [Dataset.set_auto_mask](#Dataset.set_auto_mask) [Dataset](#Dataset) and [Variable](#Variable) methods
551 `missing_value` or `_FillValue` variable attributes masked for primitive and
552 enum data types.
553 The `Dataset.set_auto_mask` `Dataset` and `Variable` methods
583554 can be used to disable this feature so that
584555 numpy arrays are always returned, with the missing values included. Prior to
585556 version 1.4.0 the default behavior was to only return masked arrays when the
586557 requested slice contained missing values. This behavior can be recovered
587 using the [Dataset.set_always_mask](#Dataset.set_always_mask) method. If a masked array is
558 using the `Dataset.set_always_mask` method. If a masked array is
588559 written to a netCDF variable, the masked elements are filled with the
589560 value specified by the `missing_value` attribute. If the variable has
590561 no `missing_value`, the `_FillValue` is used instead.
612583 [17533104. 17533116. 17533128. 17533140. 17533152.]
613584 >>> dates = num2date(times[:],units=times.units,calendar=times.calendar)
614585 >>> print("dates corresponding to time values:\\n{}".format(dates))
615 dates corresponding to time values:
616 [real_datetime(2001, 3, 1, 0, 0) real_datetime(2001, 3, 1, 12, 0)
617 real_datetime(2001, 3, 2, 0, 0) real_datetime(2001, 3, 2, 12, 0)
618 real_datetime(2001, 3, 3, 0, 0)]
586 [cftime.DatetimeGregorian(2001, 3, 1, 0, 0, 0, 0, has_year_zero=False)
587 cftime.DatetimeGregorian(2001, 3, 1, 12, 0, 0, 0, has_year_zero=False)
588 cftime.DatetimeGregorian(2001, 3, 2, 0, 0, 0, 0, has_year_zero=False)
589 cftime.DatetimeGregorian(2001, 3, 2, 12, 0, 0, 0, has_year_zero=False)
590 cftime.DatetimeGregorian(2001, 3, 3, 0, 0, 0, 0, has_year_zero=False)]
619591 ```
620592
621593 `num2date` converts numeric values of time in the specified `units`
629601 ## Reading data from a multi-file netCDF dataset
630602
631603 If you want to read data from a variable that spans multiple netCDF files,
632 you can use the [MFDataset](#MFDataset) class to read the data as if it were
604 you can use the `MFDataset` class to read the data as if it were
633605 contained in a single file. Instead of using a single filename to create
634 a [Dataset](#Dataset) instance, create a [MFDataset](#MFDataset) instance with either a list
606 a `Dataset` instance, create a `MFDataset` instance with either a list
635607 of filenames, or a string with a wildcard (which is then converted to
636608 a sorted list of files using the python glob module).
637609 Variables in the list of files that share the same unlimited
647619 ... with Dataset("mftest%s.nc" % nf, "w", format="NETCDF4_CLASSIC") as f:
648620 ... _ = f.createDimension("x",None)
649621 ... x = f.createVariable("x","i",("x",))
650 ... x[0:10] = numpy.arange(nf*10,10*(nf+1))
622 ... x[0:10] = np.arange(nf*10,10*(nf+1))
651623 ```
652624
653 Now read all the files back in at once with [MFDataset](#MFDataset)
625 Now read all the files back in at once with `MFDataset`
654626
655627 ```python
656628 >>> from netCDF4 import MFDataset
663635 96 97 98 99]
664636 ```
665637
666 Note that [MFDataset](#MFDataset) can only be used to read, not write, multi-file
638 Note that `MFDataset` can only be used to read, not write, multi-file
667639 datasets.
668640
669641 ## Efficient compression of netCDF variables
670642
671 Data stored in netCDF 4 [Variable](#Variable) objects can be compressed and
643 Data stored in netCDF 4 `Variable` objects can be compressed and
672644 decompressed on the fly. The parameters for the compression are
673645 determined by the `zlib`, `complevel` and `shuffle` keyword arguments
674 to the [Dataset.createVariable](#Dataset.createVariable) method. To turn on
646 to the `Dataset.createVariable` method. To turn on
675647 compression, set `zlib=True`. The `complevel` keyword regulates the
676648 speed and efficiency of the compression (1 being fastest, but lowest
677649 compression ratio, 9 being slowest but best compression ratio). The
680652 compression by reordering the bytes. The shuffle filter can
681653 significantly improve compression ratios, and is on by default. Setting
682654 `fletcher32` keyword argument to
683 [Dataset.createVariable](#Dataset.createVariable) to `True` (it's `False` by
655 `Dataset.createVariable` to `True` (it's `False` by
684656 default) enables the Fletcher32 checksum algorithm for error detection.
685657 It's also possible to set the HDF5 chunking parameters and endian-ness
686658 of the binary data stored in the HDF5 file with the `chunksizes`
687659 and `endian` keyword arguments to
688 [Dataset.createVariable](#Dataset.createVariable). These keyword arguments only
660 `Dataset.createVariable`. These keyword arguments only
689661 are relevant for `NETCDF4` and `NETCDF4_CLASSIC` files (where the
690662 underlying file format is HDF5) and are silently ignored if the file
691663 format is `NETCDF3_CLASSIC`, `NETCDF3_64BIT_OFFSET` or `NETCDF3_64BIT_DATA`.
694666 example, it is temperature data that was measured with a precision of
695667 0.1 degrees), you can dramatically improve zlib compression by
696668 quantizing (or truncating) the data using the `least_significant_digit`
697 keyword argument to [Dataset.createVariable](#Dataset.createVariable). The least
669 keyword argument to `Dataset.createVariable`. The least
698670 significant digit is the power of ten of the smallest decimal place in
699671 the data that is a reliable value. For example if the data has a
700672 precision of 0.1, then setting `least_significant_digit=1` will cause
706678
707679 In our example, try replacing the line
708680
709 ```python
710 >>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",))
681 ```python
682 >>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",))
683 ```
711684
712685 with
713686
735708 information for a point by reading one variable, instead of reading
736709 different parameters from different variables. Compound data types
737710 are created from the corresponding numpy data type using the
738 [Dataset.createCompoundType](#Dataset.createCompoundType) method of a [Dataset](#Dataset) or [Group](#Group) instance.
711 `Dataset.createCompoundType` method of a `Dataset` or `Group` instance.
739712 Since there is no native complex data type in netcdf, compound types are handy
740713 for storing numpy complex arrays. Here's an example:
741714
743716 >>> f = Dataset("complex.nc","w")
744717 >>> size = 3 # length of 1-d complex array
745718 >>> # create sample complex data.
746 >>> datac = numpy.exp(1j*(1.+numpy.linspace(0, numpy.pi, size)))
719 >>> datac = np.exp(1j*(1.+np.linspace(0, np.pi, size)))
747720 >>> # create complex128 compound data type.
748 >>> complex128 = numpy.dtype([("real",numpy.float_64),("imag",numpy.float_64)])
721 >>> complex128 = np.dtype([("real",np.float64),("imag",np.float64)])
749722 >>> complex128_t = f.createCompoundType(complex128,"complex128")
750723 >>> # create a variable with this data type, write some data to it.
751724 >>> x_dim = f.createDimension("x_dim",None)
752725 >>> v = f.createVariable("cmplx_var",complex128_t,"x_dim")
753 >>> data = numpy.empty(size,complex128) # numpy structured array
726 >>> data = np.empty(size,complex128) # numpy structured array
754727 >>> data["real"] = datac.real; data["imag"] = datac.imag
755728 >>> v[:] = data # write numpy structured array to netcdf compound var
756729 >>> # close and reopen the file, check the contents.
758731 >>> v = f.variables["cmplx_var"]
759732 >>> datain = v[:] # read in all the data into a numpy structured array
760733 >>> # create an empty numpy complex array
761 >>> datac2 = numpy.empty(datain.shape,numpy.complex128)
734 >>> datac2 = np.empty(datain.shape,np.complex128)
762735 >>> # .. fill it with contents of structured array.
763736 >>> datac2.real = datain["real"]; datac2.imag = datain["imag"]
764737 >>> print('{}: {}'.format(datac.dtype, datac)) # original data
772745 ones first. All possible numpy structured arrays cannot be
773746 represented as Compound variables - an error message will be
774747 raise if you try to create one that is not supported.
775 All of the compound types defined for a [Dataset](#Dataset) or [Group](#Group) are stored
748 All of the compound types defined for a `Dataset` or `Group` are stored
776749 in a Python dictionary, just like variables and dimensions. As always, printing
777750 objects gives useful summary information in an interactive session:
778751
799772
800773 NetCDF 4 has support for variable-length or "ragged" arrays. These are arrays
801774 of variable length sequences having the same type. To create a variable-length
802 data type, use the [Dataset.createVLType](#Dataset.createVLType) method
803 method of a [Dataset](#Dataset) or [Group](#Group) instance.
775 data type, use the `Dataset.createVLType` method
776 method of a `Dataset` or `Group` instance.
804777
805778 ```python
806779 >>> f = Dataset("tst_vlen.nc","w")
807 >>> vlen_t = f.createVLType(numpy.int32, "phony_vlen")
780 >>> vlen_t = f.createVLType(np.int32, "phony_vlen")
808781 ```
809782
810783 The numpy datatype of the variable-length sequences and the name of the
830803 ```python
831804 >>> import random
832805 >>> random.seed(54321)
833 >>> data = numpy.empty(len(y)*len(x),object)
806 >>> data = np.empty(len(y)*len(x),object)
834807 >>> for n in range(len(y)*len(x)):
835 ... data[n] = numpy.arange(random.randint(1,10),dtype="int32")+1
836 >>> data = numpy.reshape(data,(len(y),len(x)))
808 ... data[n] = np.arange(random.randint(1,10),dtype="int32")+1
809 >>> data = np.reshape(data,(len(y),len(x)))
837810 >>> vlvar[:] = data
838811 >>> print("vlen variable =\\n{}".format(vlvar[:]))
839812 vlen variable =
866839 variables, For vlen strings, you don't need to create a vlen data type.
867840 Instead, simply use the python `str` builtin (or a numpy string datatype
868841 with fixed length greater than 1) when calling the
869 [Dataset.createVariable](#Dataset.createVariable) method.
842 `Dataset.createVariable` method.
870843
871844 ```python
872845 >>> z = f.createDimension("z",10)
879852
880853 ```python
881854 >>> chars = "1234567890aabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
882 >>> data = numpy.empty(10,"O")
855 >>> data = np.empty(10,"O")
883856 >>> for n in range(10):
884857 ... stringlen = random.randint(2,12)
885858 ... data[n] = "".join([random.choice(chars) for i in range(stringlen)])
915888 Here's an example of using an Enum type to hold cloud type data.
916889 The base integer data type and a python dictionary describing the allowed
917890 values and their names are used to define an Enum data type using
918 [Dataset.createEnumType](#Dataset.createEnumType).
891 `Dataset.createEnumType`.
919892
920893 ```python
921894 >>> nc = Dataset('clouds.nc','w')
925898 ... 'Nimbostratus': 6, 'Cumulus': 4, 'Altostratus': 5,
926899 ... 'Cumulonimbus': 1, 'Stratocumulus': 3}
927900 >>> # create the Enum type called 'cloud_t'.
928 >>> cloud_type = nc.createEnumType(numpy.uint8,'cloud_t',enum_dict)
901 >>> cloud_type = nc.createEnumType(np.uint8,'cloud_t',enum_dict)
929902 >>> print(cloud_type)
930903 <class 'netCDF4._netCDF4.EnumType'>: 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}
931904 ```
998971
999972 ```python
1000973 >>> d = nc.createDimension('dim',4)
1001 >>> v = nc.createVariable('var', np.int, 'dim')
974 >>> v = nc.createVariable('var', np.int64, 'dim')
1002975 >>> v[rank] = rank
1003976 >>> nc.close()
1004977
1019992 depend on or be affected by other processes. Collective IO is a way of doing
1020993 IO defined in the MPI-IO standard; unlike independent IO, all processes must
1021994 participate in doing IO. To toggle back and forth between
1022 the two types of IO, use the [Variable.set_collective](#Variable.set_collective)
1023 [Variable](#Variable) method. All metadata
995 the two types of IO, use the `Variable.set_collective`
996 `Variable` method. All metadata
1024997 operations (such as creation of groups, types, variables, dimensions, or attributes)
1025998 are collective. There are a couple of important limitations of parallel IO:
1026999
10321005 If the write is done in independent mode, the operation will fail with a
10331006 a generic "HDF Error".
10341007 - You can write compressed data in parallel only with netcdf-c >= 4.7.4
1035 and hdf5 >= 1.10.3 (although you can read in parallel with earlier versions).
1008 and hdf5 >= 1.10.3 (although you can read in parallel with earlier versions). To write
1009 compressed data in parallel, the variable must be in 'collective IO mode'. This is done
1010 automatically on variable creation if compression is turned on, but if you are appending
1011 to a variable in an existing file, you must use `Variable.set_collective(True)` before attempting
1012 to write to it.
10361013 - You cannot use variable-length (VLEN) data types.
10371014
10381015 ## Dealing with strings
10481025 To perform the conversion to and from character arrays to fixed-width numpy string arrays, the
10491026 following convention is followed by the python interface.
10501027 If the `_Encoding` special attribute is set for a character array
1051 (dtype `S1`) variable, the [chartostring](#chartostring) utility function is used to convert the array of
1028 (dtype `S1`) variable, the `chartostring` utility function is used to convert the array of
10521029 characters to an array of strings with one less dimension (the last dimension is
10531030 interpreted as the length of each string) when reading the data. The character
10541031 set (usually ascii) is specified by the `_Encoding` attribute. If `_Encoding`
10551032 is 'none' or 'bytes', then the character array is converted to a numpy
10561033 fixed-width byte string array (dtype `S#`), otherwise a numpy unicode (dtype
10571034 `U#`) array is created. When writing the data,
1058 [stringtochar](#stringtochar) is used to convert the numpy string array to an array of
1035 `stringtochar` is used to convert the numpy string array to an array of
10591036 characters with one more dimension. For example,
10601037
10611038 ```python
10641041 >>> _ = nc.createDimension('nchars',3)
10651042 >>> _ = nc.createDimension('nstrings',None)
10661043 >>> v = nc.createVariable('strings','S1',('nstrings','nchars'))
1067 >>> datain = numpy.array(['foo','bar'],dtype='S3')
1044 >>> datain = np.array(['foo','bar'],dtype='S3')
10681045 >>> v[:] = stringtochar(datain) # manual conversion to char array
10691046 >>> print(v[:]) # data returned as char array
10701047 [[b'f' b'o' b'o']
10781055
10791056 Even if the `_Encoding` attribute is set, the automatic conversion of char
10801057 arrays to/from string arrays can be disabled with
1081 [Variable.set_auto_chartostring](#Variable.set_auto_chartostring).
1058 `Variable.set_auto_chartostring`.
10821059
10831060 A similar situation is often encountered with numpy structured arrays with subdtypes
10841061 containing fixed-wdith byte strings (dtype=`S#`). Since there is no native fixed-length string
10941071
10951072 ```python
10961073 >>> nc = Dataset('compoundstring_example.nc','w')
1097 >>> dtype = numpy.dtype([('observation', 'f4'),
1074 >>> dtype = np.dtype([('observation', 'f4'),
10981075 ... ('station_name','S10')])
10991076 >>> station_data_t = nc.createCompoundType(dtype,'station_data')
11001077 >>> _ = nc.createDimension('station',None)
11011078 >>> statdat = nc.createVariable('station_obs', station_data_t, ('station',))
1102 >>> data = numpy.empty(2,dtype)
1079 >>> data = np.empty(2,dtype)
11031080 >>> data['observation'][:] = (123.,3.14)
11041081 >>> data['station_name'][:] = ('Boulder','New York')
11051082 >>> print(statdat.dtype) # strings actually stored as character arrays
11431120 >>> # and persist the file to disk when it is closed.
11441121 >>> nc = Dataset('diskless_example.nc','w',diskless=True,persist=True)
11451122 >>> d = nc.createDimension('x',None)
1146 >>> v = nc.createVariable('v',numpy.int32,'x')
1147 >>> v[0:5] = numpy.arange(5)
1123 >>> v = nc.createVariable('v',np.int32,'x')
1124 >>> v[0:5] = np.arange(5)
11481125 >>> print(nc)
11491126 <class 'netCDF4._netCDF4.Dataset'>
11501127 root group (NETCDF4 data model, file format HDF5):
11771154 >>> # (ignored for NETCDF4/HDF5 files).
11781155 >>> nc = Dataset('inmemory.nc', mode='w',memory=1028)
11791156 >>> d = nc.createDimension('x',None)
1180 >>> v = nc.createVariable('v',numpy.int32,'x')
1181 >>> v[0:5] = numpy.arange(5)
1157 >>> v = nc.createVariable('v',np.int32,'x')
1158 >>> v[0:5] = np.arange(5)
11821159 >>> nc_buf = nc.close() # close returns memoryview
11831160 >>> print(type(nc_buf))
11841161 <class 'memoryview'>
12261203 # Python 3.7+ guarantees order; older versions need OrderedDict
12271204 from collections import OrderedDict
12281205
1229 __version__ = "1.5.6"
1206 __version__ = "1.5.7"
12301207
12311208 # Initialize numpy
12321209 import posixpath
12801257
12811258 return current netCDF chunk cache information in a tuple (size,nelems,preemption).
12821259 See netcdf C library documentation for `nc_get_chunk_cache` for
1283 details. Values can be reset with [set_chunk_cache](#set_chunk_cache)."""
1260 details. Values can be reset with `set_chunk_cache`."""
12841261 cdef int ierr
12851262 cdef size_t sizep, nelemsp
12861263 cdef float preemptionp
16791656 _ensure_nc_success(ierr, err_cls=AttributeError)
16801657
16811658 cdef _get_types(group):
1682 # Private function to create [CompoundType](#CompoundType),
1683 # [VLType](#VLType) or [EnumType](#EnumType) instances for all the
1684 # compound, VLEN or Enum types in a [Group](#Group) or [Dataset](#Dataset).
1659 # Private function to create `CompoundType`,
1660 # `VLType` or `EnumType` instances for all the
1661 # compound, VLEN or Enum types in a `Group` or `Dataset`.
16851662 cdef int ierr, ntypes, classp, n, _grpid
16861663 cdef nc_type xtype
16871664 cdef nc_type *typeids
17501727 return cmptypes, vltypes, enumtypes
17511728
17521729 cdef _get_dims(group):
1753 # Private function to create [Dimension](#Dimension) instances for all the
1754 # dimensions in a [Group](#Group) or Dataset
1730 # Private function to create `Dimension` instances for all the
1731 # dimensions in a `Group` or Dataset
17551732 cdef int ierr, numdims, n, _grpid
17561733 cdef int *dimids
17571734 cdef char namstring[NC_MAX_NAME+1]
17841761 return dimensions
17851762
17861763 cdef _get_grps(group):
1787 # Private function to create [Group](#Group) instances for all the
1788 # groups in a [Group](#Group) or Dataset
1764 # Private function to create `Group` instances for all the
1765 # groups in a `Group` or Dataset
17891766 cdef int ierr, numgrps, n, _grpid
17901767 cdef int *grpids
17911768 cdef char namstring[NC_MAX_NAME+1]
17941771 with nogil:
17951772 ierr = nc_inq_grps(_grpid, &numgrps, NULL)
17961773 _ensure_nc_success(ierr)
1797 # create dictionary containing [Group](#Group) instances for groups in this group
1774 # create dictionary containing `Group` instances for groups in this group
17981775 if sys.version_info[0:2] < (3, 7):
17991776 groups = OrderedDict()
18001777 else:
18141791 return groups
18151792
18161793 cdef _get_vars(group):
1817 # Private function to create [Variable](#Variable) instances for all the
1818 # variables in a [Group](#Group) or Dataset
1794 # Private function to create `Variable` instances for all the
1795 # variables in a `Group` or Dataset
18191796 cdef int ierr, numvars, n, nn, numdims, varid, classp, iendian, _grpid
18201797 cdef int *varids
18211798 cdef int *dimids
19601937
19611938 cdef class Dataset:
19621939 """
1963 A netCDF [Dataset](#Dataset) is a collection of dimensions, groups, variables and
1940 A netCDF `Dataset` is a collection of dimensions, groups, variables and
19641941 attributes. Together they describe the meaning of data and relations among
1965 data fields stored in a netCDF file. See [Dataset.__init__](#Dataset.__init__) for more
1942 data fields stored in a netCDF file. See `Dataset.__init__` for more
19661943 details.
19671944
19681945 A list of attribute names corresponding to global netCDF attributes
1969 defined for the [Dataset](#Dataset) can be obtained with the
1970 [Dataset.ncattrs](#Dataset.ncattrs) method.
1946 defined for the `Dataset` can be obtained with the
1947 `Dataset.ncattrs` method.
19711948 These attributes can be created by assigning to an attribute of the
1972 [Dataset](#Dataset) instance. A dictionary containing all the netCDF attribute
1949 `Dataset` instance. A dictionary containing all the netCDF attribute
19731950 name/value pairs is provided by the `__dict__` attribute of a
1974 [Dataset](#Dataset) instance.
1951 `Dataset` instance.
19751952
19761953 The following class variables are read-only and should not be
19771954 modified by the user.
19781955
19791956 **`dimensions`**: The `dimensions` dictionary maps the names of
1980 dimensions defined for the [Group](#Group) or [Dataset](#Dataset) to instances of the
1981 [Dimension](#Dimension) class.
1957 dimensions defined for the `Group` or `Dataset` to instances of the
1958 `Dimension` class.
19821959
19831960 **`variables`**: The `variables` dictionary maps the names of variables
1984 defined for this [Dataset](#Dataset) or [Group](#Group) to instances of the
1985 [Variable](#Variable) class.
1961 defined for this `Dataset` or `Group` to instances of the
1962 `Variable` class.
19861963
19871964 **`groups`**: The groups dictionary maps the names of groups created for
1988 this [Dataset](#Dataset) or [Group](#Group) to instances of the [Group](#Group) class (the
1989 [Dataset](#Dataset) class is simply a special case of the [Group](#Group) class which
1965 this `Dataset` or `Group` to instances of the `Group` class (the
1966 `Dataset` class is simply a special case of the `Group` class which
19901967 describes the root group in the netCDF4 file).
19911968
19921969 **`cmptypes`**: The `cmptypes` dictionary maps the names of
1993 compound types defined for the [Group](#Group) or [Dataset](#Dataset) to instances of the
1994 [CompoundType](#CompoundType) class.
1970 compound types defined for the `Group` or `Dataset` to instances of the
1971 `CompoundType` class.
19951972
19961973 **`vltypes`**: The `vltypes` dictionary maps the names of
1997 variable-length types defined for the [Group](#Group) or [Dataset](#Dataset) to instances
1998 of the [VLType](#VLType) class.
1974 variable-length types defined for the `Group` or `Dataset` to instances
1975 of the `VLType` class.
19991976
20001977 **`enumtypes`**: The `enumtypes` dictionary maps the names of
2001 Enum types defined for the [Group](#Group) or [Dataset](#Dataset) to instances
2002 of the [EnumType](#EnumType) class.
1978 Enum types defined for the `Group` or `Dataset` to instances
1979 of the `EnumType` class.
20031980
20041981 **`data_model`**: `data_model` describes the netCDF
20051982 data model version, one of `NETCDF3_CLASSIC`, `NETCDF4`,
20141991 `UNDEFINED`.
20151992
20161993 **`parent`**: `parent` is a reference to the parent
2017 [Group](#Group) instance. `None` for the root group or [Dataset](#Dataset)
1994 `Group` instance. `None` for the root group or `Dataset`
20181995 instance.
20191996
2020 **`path`**: `path` shows the location of the [Group](#Group) in
2021 the [Dataset](#Dataset) in a unix directory format (the names of groups in the
2022 hierarchy separated by backslashes). A [Dataset](#Dataset) instance is the root
1997 **`path`**: `path` shows the location of the `Group` in
1998 the `Dataset` in a unix directory format (the names of groups in the
1999 hierarchy separated by backslashes). A `Dataset` instance is the root
20232000 group, so the path is simply `'/'`.
20242001
20252002 **`keepweakref`**: If `True`, child Dimension and Variables objects only keep weak
20452022 persist=False, keepweakref=False, memory=None, encoding=None,
20462023 parallel=False, comm=None, info=None, format='NETCDF4')`**
20472024
2048 [Dataset](#Dataset) constructor.
2025 `Dataset` constructor.
20492026
20502027 **`filename`**: Name of netCDF file to hold dataset. Can also
20512028 be a python 3 pathlib instance or the URL of an OpenDAP dataset. When memory is
25092486 """
25102487 **`sync(self)`**
25112488
2512 Writes all buffered data in the [Dataset](#Dataset) to the disk file."""
2489 Writes all buffered data in the `Dataset` to the disk file."""
25132490 _ensure_nc_success(nc_sync(self._grpid))
25142491
25152492 def _redef(self):
25242501 """
25252502 **`set_fill_on(self)`**
25262503
2527 Sets the fill mode for a [Dataset](#Dataset) open for writing to `on`.
2504 Sets the fill mode for a `Dataset` open for writing to `on`.
25282505
25292506 This causes data to be pre-filled with fill values. The fill values can be
25302507 controlled by the variable's `_Fill_Value` attribute, but is usually
25402517 """
25412518 **`set_fill_off(self)`**
25422519
2543 Sets the fill mode for a [Dataset](#Dataset) open for writing to `off`.
2520 Sets the fill mode for a `Dataset` open for writing to `off`.
25442521
25452522 This will prevent the data from being pre-filled with fill values, which
25462523 may result in some performance improvements. However, you must then make
25562533
25572534 `size` must be a positive integer or `None`, which stands for
25582535 "unlimited" (default is `None`). Specifying a size of 0 also
2559 results in an unlimited dimension. The return value is the [Dimension](#Dimension)
2536 results in an unlimited dimension. The return value is the `Dimension`
25602537 class instance describing the new dimension. To determine the current
2561 maximum size of the dimension, use the `len` function on the [Dimension](#Dimension)
2538 maximum size of the dimension, use the `len` function on the `Dimension`
25622539 instance. To determine if a dimension is 'unlimited', use the
2563 [Dimension.isunlimited](#Dimension.isunlimited) method of the [Dimension](#Dimension) instance."""
2540 `Dimension.isunlimited` method of the `Dimension` instance."""
25642541 self.dimensions[dimname] = Dimension(self, dimname, size=size)
25652542 return self.dimensions[dimname]
25662543
25682545 """
25692546 **`renameDimension(self, oldname, newname)`**
25702547
2571 rename a [Dimension](#Dimension) named `oldname` to `newname`."""
2548 rename a `Dimension` named `oldname` to `newname`."""
25722549 cdef char *namstring
25732550 bytestr = _strencode(newname)
25742551 namstring = bytestr
26002577 are homogeneous numeric data types), then the 'inner' compound types **must** be
26012578 created first.
26022579
2603 The return value is the [CompoundType](#CompoundType) class instance describing the new
2580 The return value is the `CompoundType` class instance describing the new
26042581 datatype."""
26052582 self.cmptypes[datatype_name] = CompoundType(self, datatype,\
26062583 datatype_name)
26132590 Creates a new VLEN data type named `datatype_name` from a numpy
26142591 dtype object `datatype`.
26152592
2616 The return value is the [VLType](#VLType) class instance describing the new
2593 The return value is the `VLType` class instance describing the new
26172594 datatype."""
26182595 self.vltypes[datatype_name] = VLType(self, datatype, datatype_name)
26192596 return self.vltypes[datatype_name]
26262603 integer dtype object `datatype`, and a python dictionary
26272604 defining the enum fields and values.
26282605
2629 The return value is the [EnumType](#EnumType) class instance describing the new
2606 The return value is the `EnumType` class instance describing the new
26302607 datatype."""
26312608 self.enumtypes[datatype_name] = EnumType(self, datatype, datatype_name,
26322609 enum_dict)
26572634 (NC_BYTE), 'u1' (NC_UBYTE), 'i2' or 'h' or 's' (NC_SHORT), 'u2'
26582635 (NC_USHORT), 'i4' or 'i' or 'l' (NC_INT), 'u4' (NC_UINT), 'i8' (NC_INT64),
26592636 'u8' (NC_UINT64), 'f4' or 'f' (NC_FLOAT), 'f8' or 'd' (NC_DOUBLE)`.
2660 `datatype` can also be a [CompoundType](#CompoundType) instance
2661 (for a structured, or compound array), a [VLType](#VLType) instance
2637 `datatype` can also be a `CompoundType` instance
2638 (for a structured, or compound array), a `VLType` instance
26622639 (for a variable-length array), or the python `str` builtin
26632640 (for a variable-length string array). Numpy string and unicode datatypes with
26642641 length greater than one are aliases for `str`.
26672644 the corresponding data type.
26682645
26692646 `dimensions` must be a tuple containing dimension names (strings) that
2670 have been defined previously using [Dataset.createDimension](#Dataset.createDimension). The default value
2647 have been defined previously using `Dataset.createDimension`. The default value
26712648 is an empty tuple, which means the variable is a scalar.
26722649
26732650 If the optional keyword `zlib` is `True`, the data will be compressed in
27092686
27102687 The optional keyword `fill_value` can be used to override the default
27112688 netCDF `_FillValue` (the value that the variable gets filled with before
2712 any data is written to it, defaults given in [default_fillvals](#default_fillvals)).
2689 any data is written to it, defaults given in the dict `netCDF4.default_fillvals`).
27132690 If fill_value is set to `False`, then the variable is not pre-filled.
27142691
27152692 If the optional keyword parameter `least_significant_digit` is
27342711 method to change it the next time the Dataset is opened.
27352712 Warning - messing with this parameter can seriously degrade performance.
27362713
2737 The return value is the [Variable](#Variable) class instance describing the new
2714 The return value is the `Variable` class instance describing the new
27382715 variable.
27392716
27402717 A list of names corresponding to netCDF variable attributes can be
2741 obtained with the [Variable](#Variable) method [Variable.ncattrs](#Variable.ncattrs). A dictionary
2718 obtained with the `Variable` method `Variable.ncattrs`. A dictionary
27422719 containing all the netCDF attribute name/value pairs is provided by
2743 the `__dict__` attribute of a [Variable](#Variable) instance.
2744
2745 [Variable](#Variable) instances behave much like array objects. Data can be
2720 the `__dict__` attribute of a `Variable` instance.
2721
2722 `Variable` instances behave much like array objects. Data can be
27462723 assigned to or retrieved from a variable with indexing and slicing
2747 operations on the [Variable](#Variable) instance. A [Variable](#Variable) instance has six
2724 operations on the `Variable` instance. A `Variable` instance has six
27482725 Dataset standard attributes: `dimensions, dtype, shape, ndim, name` and
27492726 `least_significant_digit`. Application programs should never modify
27502727 these attributes. The `dimensions` attribute is a tuple containing the
27552732 string containing the name of the Variable instance.
27562733 The `least_significant_digit`
27572734 attributes describes the power of ten of the smallest decimal place in
2758 the data the contains a reliable value. assigned to the [Variable](#Variable)
2735 the data the contains a reliable value. assigned to the `Variable`
27592736 instance. If `None`, the data is not truncated. The `ndim` attribute
27602737 is the number of variable dimensions."""
27612738 # if varname specified as a path, split out group names.
27782755 """
27792756 **`renameVariable(self, oldname, newname)`**
27802757
2781 rename a [Variable](#Variable) named `oldname` to `newname`"""
2758 rename a `Variable` named `oldname` to `newname`"""
27822759 cdef char *namstring
27832760 try:
27842761 var = self.variables[oldname]
28002777 """
28012778 **`createGroup(self, groupname)`**
28022779
2803 Creates a new [Group](#Group) with the given `groupname`.
2780 Creates a new `Group` with the given `groupname`.
28042781
28052782 If `groupname` is specified as a path, using forward slashes as in unix to
28062783 separate components, then intermediate groups will be created as necessary
28102787 If the specified path describes a group that already exists, no error is
28112788 raised.
28122789
2813 The return value is a [Group](#Group) class instance."""
2790 The return value is a `Group` class instance."""
28142791 # if group specified as a path, split out group names
28152792 groupname = posixpath.normpath(groupname)
28162793 nestedgroups = groupname.split('/')
28302807 """
28312808 **`ncattrs(self)`**
28322809
2833 return netCDF global attribute names for this [Dataset](#Dataset) or [Group](#Group) in a list."""
2810 return netCDF global attribute names for this `Dataset` or `Group` in a list."""
28342811 return _get_att_names(self._grpid, NC_GLOBAL)
28352812
28362813 def setncattr(self,name,value):
29472924 """
29482925 **`renameAttribute(self, oldname, newname)`**
29492926
2950 rename a [Dataset](#Dataset) or [Group](#Group) attribute named `oldname` to `newname`."""
2927 rename a `Dataset` or `Group` attribute named `oldname` to `newname`."""
29512928 cdef char *oldnamec
29522929 cdef char *newnamec
29532930 bytestr = _strencode(oldname)
29602937 """
29612938 **`renameGroup(self, oldname, newname)`**
29622939
2963 rename a [Group](#Group) named `oldname` to `newname` (requires netcdf >= 4.3.1)."""
2940 rename a `Group` named `oldname` to `newname` (requires netcdf >= 4.3.1)."""
29642941 cdef char *newnamec
29652942 IF HAS_RENAME_GRP:
29662943 bytestr = _strencode(newname)
29842961 """
29852962 **`set_auto_chartostring(self, True_or_False)`**
29862963
2987 Call [Variable.set_auto_chartostring](#Variable.set_auto_chartostring) for all variables contained in this [Dataset](#Dataset) or
2988 [Group](#Group), as well as for all variables in all its subgroups.
2964 Call `Variable.set_auto_chartostring` for all variables contained in this `Dataset` or
2965 `Group`, as well as for all variables in all its subgroups.
29892966
29902967 **`True_or_False`**: Boolean determining if automatic conversion of
29912968 all character arrays <--> string arrays should be performed for
30122989 """
30132990 **`set_auto_maskandscale(self, True_or_False)`**
30142991
3015 Call [Variable.set_auto_maskandscale](#Variable.set_auto_maskandscale) for all variables contained in this [Dataset](#Dataset) or
3016 [Group](#Group), as well as for all variables in all its subgroups.
2992 Call `Variable.set_auto_maskandscale` for all variables contained in this `Dataset` or
2993 `Group`, as well as for all variables in all its subgroups.
30172994
30182995 **`True_or_False`**: Boolean determining if automatic conversion to masked arrays
30192996 and variable scaling shall be applied for all variables.
30393016 """
30403017 **`set_auto_mask(self, True_or_False)`**
30413018
3042 Call [Variable.set_auto_mask](#Variable.set_auto_mask) for all variables contained in this [Dataset](#Dataset) or
3043 [Group](#Group), as well as for all variables in all its subgroups.
3019 Call `Variable.set_auto_mask` for all variables contained in this `Dataset` or
3020 `Group`, as well as for all variables in all its subgroups. Only affects
3021 Variables with primitive or enum types (not compound or vlen Variables).
30443022
30453023 **`True_or_False`**: Boolean determining if automatic conversion to masked arrays
30463024 shall be applied for all variables.
30653043 """
30663044 **`set_auto_scale(self, True_or_False)`**
30673045
3068 Call [Variable.set_auto_scale](#Variable.set_auto_scale) for all variables contained in this [Dataset](#Dataset) or
3069 [Group](#Group), as well as for all variables in all its subgroups.
3046 Call `Variable.set_auto_scale` for all variables contained in this `Dataset` or
3047 `Group`, as well as for all variables in all its subgroups.
30703048
30713049 **`True_or_False`**: Boolean determining if automatic variable scaling
30723050 shall be applied for all variables.
30913069 """
30923070 **`set_always_mask(self, True_or_False)`**
30933071
3094 Call [Variable.set_always_mask](#Variable.set_always_mask) for all variables contained in
3095 this [Dataset](#Dataset) or [Group](#Group), as well as for all
3072 Call `Variable.set_always_mask` for all variables contained in
3073 this `Dataset` or `Group`, as well as for all
30963074 variables in all its subgroups.
30973075
30983076 **`True_or_False`**: Boolean determining if automatic conversion of
31223100 """
31233101 **`set_ncstring_attrs(self, True_or_False)`**
31243102
3125 Call [Variable.set_ncstring_attrs](#Variable.set_ncstring_attrs) for all variables contained in
3126 this [Dataset](#Dataset) or [Group](#Group), as well as for all its
3103 Call `Variable.set_ncstring_attrs` for all variables contained in
3104 this `Dataset` or `Group`, as well as for all its
31273105 subgroups and their variables.
31283106
31293107 **`True_or_False`**: Boolean determining if all string attributes are
32243202 """
32253203 **`fromcdl(cdlfilename, ncfilename=None, mode='a',format='NETCDF4')`**
32263204
3227 call `ncgen` via subprocess to create Dataset from [CDL](https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#cdl_guide)
3228 text representation. Requires `ncgen` to be installed and in `$PATH`.
3205 call [ncgen][ncgen] via subprocess to create Dataset from [CDL][cdl]
3206 text representation. Requires [ncgen][ncgen] to be installed and in `$PATH`.
32293207
32303208 **`cdlfilename`**: CDL file.
32313209
32393217 `'NETCDF3_64BIT_DATA'`. Default `'NETCDF4'`.
32403218
32413219 Dataset instance for `ncfilename` is returned.
3220
3221 [ncgen]: https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#ncgen_guide
3222 [cdl]: https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#cdl_guide
32423223 """
32433224 if ncfilename is None:
32443225 filepath = pathlib.Path(cdlfilename)
32593240 """
32603241 **`tocdl(self, coordvars=False, data=False, outfile=None)`**
32613242
3262 call `ncdump` via subprocess to create [CDL](https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#cdl_guide)
3263 text representation of Dataset. Requires `ncdump` to be installed and in `$PATH`.
3243 call [ncdump][ncdump] via subprocess to create [CDL][cdl]
3244 text representation of Dataset. Requires [ncdump][ncdump]
3245 to be installed and in `$PATH`.
32643246
32653247 **`coordvars`**: include coordinate variable data (via `ncdump -c`). Default False
32663248
32673249 **`data`**: if True, write out variable data (Default False).
32683250
32693251 **`outfile`**: If not None, file to output ncdump to. Default is to return a string.
3252
3253 [ncdump]: https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#ncdump_guide
3254 [cdl]: https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#cdl_guide
32703255 """
32713256 self.sync()
32723257 if coordvars:
32873272 cdef class Group(Dataset):
32883273 """
32893274 Groups define a hierarchical namespace within a netCDF file. They are
3290 analogous to directories in a unix filesystem. Each [Group](#Group) behaves like
3291 a [Dataset](#Dataset) within a Dataset, and can contain it's own variables,
3292 dimensions and attributes (and other Groups). See [Group.__init__](#Group.__init__)
3275 analogous to directories in a unix filesystem. Each `Group` behaves like
3276 a `Dataset` within a Dataset, and can contain it's own variables,
3277 dimensions and attributes (and other Groups). See `Group.__init__`
32933278 for more details.
32943279
3295 [Group](#Group) inherits from [Dataset](#Dataset), so all the
3296 [Dataset](#Dataset) class methods and variables are available
3297 to a [Group](#Group) instance (except the `close` method).
3280 `Group` inherits from `Dataset`, so all the
3281 `Dataset` class methods and variables are available
3282 to a `Group` instance (except the `close` method).
32983283
32993284 Additional read-only class variables:
33003285
33033288 def __init__(self, parent, name, **kwargs):
33043289 """
33053290 **`__init__(self, parent, name)`**
3306 [Group](#Group) constructor.
3307
3308 **`parent`**: [Group](#Group) instance for the parent group. If being created
3309 in the root group, use a [Dataset](#Dataset) instance.
3291 `Group` constructor.
3292
3293 **`parent`**: `Group` instance for the parent group. If being created
3294 in the root group, use a `Dataset` instance.
33103295
33113296 **`name`**: - Name of the group.
33123297
3313 ***Note***: [Group](#Group) instances should be created using the
3314 [Dataset.createGroup](#Dataset.createGroup) method of a [Dataset](#Dataset) instance, or
3315 another [Group](#Group) instance, not using this class directly.
3298 ***Note***: `Group` instances should be created using the
3299 `Dataset.createGroup` method of a `Dataset` instance, or
3300 another `Group` instance, not using this class directly.
33163301 """
33173302 cdef char *groupname
33183303 # flag to indicate that Variables in this Group support orthogonal indexing.
33623347 """
33633348 **`close(self)`**
33643349
3365 overrides [Dataset](#Dataset) close method which does not apply to [Group](#Group)
3350 overrides `Dataset` close method which does not apply to `Group`
33663351 instances, raises IOError."""
3367 raise IOError('cannot close a [Group](#Group) (only applies to Dataset)')
3352 raise IOError('cannot close a `Group` (only applies to Dataset)')
33683353
33693354
33703355 cdef class Dimension:
33713356 """
3372 A netCDF [Dimension](#Dimension) is used to describe the coordinates of a [Variable](#Variable).
3373 See [Dimension.__init__](#Dimension.__init__) for more details.
3374
3375 The current maximum size of a [Dimension](#Dimension) instance can be obtained by
3376 calling the python `len` function on the [Dimension](#Dimension) instance. The
3377 [Dimension.isunlimited](#Dimension.isunlimited) method of a [Dimension](#Dimension) instance can be used to
3357 A netCDF `Dimension` is used to describe the coordinates of a `Variable`.
3358 See `Dimension.__init__` for more details.
3359
3360 The current maximum size of a `Dimension` instance can be obtained by
3361 calling the python `len` function on the `Dimension` instance. The
3362 `Dimension.isunlimited` method of a `Dimension` instance can be used to
33783363 determine if the dimension is unlimited.
33793364
33803365 Read-only class variables:
33813366
3382 **`name`**: String name, used when creating a [Variable](#Variable) with
3383 [Dataset.createVariable](#Dataset.createVariable).
3384
3385 **`size`**: Current [Dimension](#Dimension) size (same as `len(d)`, where `d` is a
3386 [Dimension](#Dimension) instance).
3367 **`name`**: String name, used when creating a `Variable` with
3368 `Dataset.createVariable`.
3369
3370 **`size`**: Current `Dimension` size (same as `len(d)`, where `d` is a
3371 `Dimension` instance).
33873372 """
33883373 cdef public int _dimid, _grpid
33893374 cdef public _data_model, _name, _grp
33923377 """
33933378 **`__init__(self, group, name, size=None)`**
33943379
3395 [Dimension](#Dimension) constructor.
3396
3397 **`group`**: [Group](#Group) instance to associate with dimension.
3380 `Dimension` constructor.
3381
3382 **`group`**: `Group` instance to associate with dimension.
33983383
33993384 **`name`**: Name of the dimension.
34003385
34013386 **`size`**: Size of the dimension. `None` or 0 means unlimited. (Default `None`).
34023387
3403 ***Note***: [Dimension](#Dimension) instances should be created using the
3404 [Dataset.createDimension](#Dataset.createDimension) method of a [Group](#Group) or
3405 [Dataset](#Dataset) instance, not using [Dimension.__init__](#Dimension.__init__) directly.
3388 ***Note***: `Dimension` instances should be created using the
3389 `Dataset.createDimension` method of a `Group` or
3390 `Dataset` instance, not using `Dimension.__init__` directly.
34063391 """
34073392 cdef int ierr
34083393 cdef char *dimname
34683453 (type(self), self._name, len(self))
34693454
34703455 def __len__(self):
3471 # len([Dimension](#Dimension) instance) returns current size of dimension
3456 # len(`Dimension` instance) returns current size of dimension
34723457 cdef int ierr
34733458 cdef size_t lengthp
34743459 with nogil:
34803465 """
34813466 **`group(self)`**
34823467
3483 return the group that this [Dimension](#Dimension) is a member of."""
3468 return the group that this `Dimension` is a member of."""
34843469 return self._grp
34853470
34863471 def isunlimited(self):
34873472 """
34883473 **`isunlimited(self)`**
34893474
3490 returns `True` if the [Dimension](#Dimension) instance is unlimited, `False` otherwise."""
3475 returns `True` if the `Dimension` instance is unlimited, `False` otherwise."""
34913476 cdef int ierr, n, numunlimdims, ndims, nvars, ngatts, xdimid
34923477 cdef int *unlimdimids
34933478 if self._data_model == 'NETCDF4':
35203505
35213506 cdef class Variable:
35223507 """
3523 A netCDF [Variable](#Variable) is used to read and write netCDF data. They are
3524 analogous to numpy array objects. See [Variable.__init__](#Variable.__init__) for more
3508 A netCDF `Variable` is used to read and write netCDF data. They are
3509 analogous to numpy array objects. See `Variable.__init__` for more
35253510 details.
35263511
35273512 A list of attribute names corresponding to netCDF attributes defined for
3528 the variable can be obtained with the [Variable.ncattrs](#Variable.ncattrs) method. These
3513 the variable can be obtained with the `Variable.ncattrs` method. These
35293514 attributes can be created by assigning to an attribute of the
3530 [Variable](#Variable) instance. A dictionary containing all the netCDF attribute
3515 `Variable` instance. A dictionary containing all the netCDF attribute
35313516 name/value pairs is provided by the `__dict__` attribute of a
3532 [Variable](#Variable) instance.
3517 `Variable` instance.
35333518
35343519 The following class variables are read-only:
35353520
35463531 **`scale`**: If True, `scale_factor` and `add_offset` are
35473532 applied, and signed integer data is automatically converted to
35483533 unsigned integer data if the `_Unsigned` attribute is set.
3549 Default is `True`, can be reset using [Variable.set_auto_scale](#Variable.set_auto_scale) and
3550 [Variable.set_auto_maskandscale](#Variable.set_auto_maskandscale) methods.
3534 Default is `True`, can be reset using `Variable.set_auto_scale` and
3535 `Variable.set_auto_maskandscale` methods.
35513536
35523537 **`mask`**: If True, data is automatically converted to/from masked
35533538 arrays when missing values or fill values are present. Default is `True`, can be
3554 reset using [Variable.set_auto_mask](#Variable.set_auto_mask) and [Variable.set_auto_maskandscale](#Variable.set_auto_maskandscale)
3555 methods.
3539 reset using `Variable.set_auto_mask` and `Variable.set_auto_maskandscale`
3540 methods. Only relevant for Variables with primitive or enum types (ignored
3541 for compound and vlen Variables).
35563542
35573543 **`chartostring`**: If True, data is automatically converted to/from character
35583544 arrays to string arrays when the `_Encoding` variable attribute is set.
35593545 Default is `True`, can be reset using
3560 [Variable.set_auto_chartostring](#Variable.set_auto_chartostring) method.
3546 `Variable.set_auto_chartostring` method.
35613547
35623548 **`least_significant_digit`**: Describes the power of ten of the
35633549 smallest decimal place in the data the contains a reliable value. Data is
3564 truncated to this decimal place when it is assigned to the [Variable](#Variable)
3550 truncated to this decimal place when it is assigned to the `Variable`
35653551 instance. If `None`, the data is not truncated.
35663552
35673553 **`__orthogonal_indexing__`**: Always `True`. Indicates to client code
35913577 chunksizes=None, endian='native',
35923578 least_significant_digit=None,fill_value=None,chunk_cache=None)`**
35933579
3594 [Variable](#Variable) constructor.
3595
3596 **`group`**: [Group](#Group) or [Dataset](#Dataset) instance to associate with variable.
3580 `Variable` constructor.
3581
3582 **`group`**: `Group` or `Dataset` instance to associate with variable.
35973583
35983584 **`name`**: Name of the variable.
35993585
3600 **`datatype`**: [Variable](#Variable) data type. Can be specified by providing a
3586 **`datatype`**: `Variable` data type. Can be specified by providing a
36013587 numpy dtype object, or a string that describes a numpy dtype object.
36023588 Supported values, corresponding to `str` attribute of numpy dtype
36033589 objects, include `'f4'` (32-bit floating point), `'f8'` (64-bit floating
36103596 typecodes can also be used (`'f'` instead of `'f4'`, `'d'` instead of
36113597 `'f8'`, `'h'` or `'s'` instead of `'i2'`, `'b'` or `'B'` instead of
36123598 `'i1'`, `'c'` instead of `'S1'`, and `'i'` or `'l'` instead of
3613 `'i4'`). `datatype` can also be a [CompoundType](#CompoundType) instance
3614 (for a structured, or compound array), a [VLType](#VLType) instance
3599 `'i4'`). `datatype` can also be a `CompoundType` instance
3600 (for a structured, or compound array), a `VLType` instance
36153601 (for a variable-length array), or the python `str` builtin
36163602 (for a variable-length string array). Numpy string and unicode datatypes with
36173603 length greater than one are aliases for `str`.
36203606 (defined previously with `createDimension`). Default is an empty tuple
36213607 which means the variable is a scalar (and therefore has no dimensions).
36223608
3623 **`zlib`**: if `True`, data assigned to the [Variable](#Variable)
3609 **`zlib`**: if `True`, data assigned to the `Variable`
36243610 instance is compressed on disk. Default `False`.
36253611
36263612 **`complevel`**: the level of zlib compression to use (1 is the fastest,
36693655 value that the variable gets filled with before any data is written to it)
36703656 is replaced with this value. If fill_value is set to `False`, then
36713657 the variable is not pre-filled. The default netCDF fill values can be found
3672 in [default_fillvals](#default_fillvals).
3658 in the dictionary `netCDF4.default_fillvals`.
36733659
36743660 **`chunk_cache`**: If specified, sets the chunk cache size for this variable.
3675 Persists as long as Dataset is open. Use [set_var_chunk_cache](#set_var_chunk_cache) to
3661 Persists as long as Dataset is open. Use `set_var_chunk_cache` to
36763662 change it when Dataset is re-opened.
36773663
3678 ***Note***: [Variable](#Variable) instances should be created using the
3679 [Dataset.createVariable](#Dataset.createVariable) method of a [Dataset](#Dataset) or
3680 [Group](#Group) instance, not using this class directly.
3664 ***Note***: `Variable` instances should be created using the
3665 `Dataset.createVariable` method of a `Dataset` or
3666 `Group` instance, not using this class directly.
36813667 """
36823668 cdef int ierr, ndims, icontiguous, ideflate_level, numdims, _grpid
36833669 cdef char namstring[NC_MAX_NAME+1]
41064092 """
41074093 **`group(self)`**
41084094
4109 return the group that this [Variable](#Variable) is a member of."""
4095 return the group that this `Variable` is a member of."""
41104096 return self._grp
41114097
41124098 def ncattrs(self):
41134099 """
41144100 **`ncattrs(self)`**
41154101
4116 return netCDF attribute names for this [Variable](#Variable) in a list."""
4102 return netCDF attribute names for this `Variable` in a list."""
41174103 return _get_att_names(self._grpid, self._varid)
41184104
41194105 def setncattr(self,name,value):
43744360 """
43754361 **`renameAttribute(self, oldname, newname)`**
43764362
4377 rename a [Variable](#Variable) attribute named `oldname` to `newname`."""
4363 rename a `Variable` attribute named `oldname` to `newname`."""
43784364 cdef int ierr
43794365 cdef char *oldnamec
43804366 cdef char *newnamec
44544440 msg = 'invalid scale_factor or add_offset attribute, no unpacking done...'
44554441 warnings.warn(msg)
44564442
4457 if self.mask and\
4458 (self._isprimitive or self._isenum or\
4459 (self._isvlen and self.dtype != str)):
4443 if self.mask and (self._isprimitive or self._isenum):\
44604444 data = self._toma(data)
44614445 else:
44624446 # if attribute _Unsigned is True, and variable has signed integer
45974581 # type, signed or unsigned, because the byte ranges are too
45984582 # small to assume one of the values should appear as a missing
45994583 # value unless a _FillValue attribute is set explicitly."
4600 if no_fill != 1 or self.dtype.str[1:] not in ['u1','i1']:
4584 # (do this only for non-vlens, since vlens don't have a default _FillValue)
4585 if not self._isvlen and (no_fill != 1 or self.dtype.str[1:] not in ['u1','i1']):
46014586 fillval = numpy.array(default_fillvals[self.dtype.str[1:]],self.dtype)
46024587 has_fillval = data == fillval
46034588 # if data is an array scalar, has_fillval will be a boolean.
48954880 # if auto scaling is to be done, don't cast to an integer yet.
48964881 if self.scale and self.dtype.kind in 'iu' and \
48974882 hasattr(self, 'scale_factor') or hasattr(self, 'add_offset'):
4898 data = numpy.array(data,numpy.float_)
4883 data = numpy.array(data,numpy.float64)
48994884 else:
49004885 data = numpy.array(data,self.dtype)
49014886
50375022 missing_value variable attribute. The fill_value of the masked array
50385023 is set to the missing_value attribute (if it exists), otherwise
50395024 the netCDF _FillValue attribute (which has a default value
5040 for each data type). When data is written to a variable, the masked
5025 for each data type). If the variable has no missing_value attribute, the
5026 _FillValue is used instead. If the variable has valid_min/valid_max and
5027 missing_value attributes, data outside the specified range will be masked.
5028 When data is written to a variable, the masked
50415029 array is converted back to a regular numpy array by replacing all the
50425030 masked values by the missing_value attribute of the variable (if it
50435031 exists). If the variable has no missing_value attribute, the _FillValue
5044 is used instead. If the variable has valid_min/valid_max and
5045 missing_value attributes, data outside the specified range will be
5046 set to missing_value.
5032 is used instead.
50475033
50485034 If `maskandscale` is set to `True`, and the variable has a
50495035 `scale_factor` or an `add_offset` attribute, then data read
51265112 missing_value variable attribute. The fill_value of the masked array
51275113 is set to the missing_value attribute (if it exists), otherwise
51285114 the netCDF _FillValue attribute (which has a default value
5129 for each data type). When data is written to a variable, the masked
5115 for each data type). If the variable has no missing_value attribute, the
5116 _FillValue is used instead. If the variable has valid_min/valid_max and
5117 missing_value attributes, data outside the specified range will be masked.
5118 When data is written to a variable, the masked
51305119 array is converted back to a regular numpy array by replacing all the
51315120 masked values by the missing_value attribute of the variable (if it
51325121 exists). If the variable has no missing_value attribute, the _FillValue
5133 is used instead. If the variable has valid_min/valid_max and
5134 missing_value attributes, data outside the specified range will be
5135 set to missing_value.
5122 is used instead.
51365123
51375124 The default value of `mask` is `True`
51385125 (automatic conversions are performed).
54775464 """
54785465 **`get_dims(self)`**
54795466
5480 return a tuple of [Dimension](#Dimension) instances associated with this
5481 [Variable](#Variable).
5467 return a tuple of `Dimension` instances associated with this
5468 `Variable`.
54825469 """
54835470 return tuple(_find_dim(self._grp, dim) for dim in self.dimensions)
54845471
54905477
54915478 cdef class CompoundType:
54925479 """
5493 A [CompoundType](#CompoundType) instance is used to describe a compound data
5494 type, and can be passed to the the [Dataset.createVariable](#Dataset.createVariable) method of
5495 a [Dataset](#Dataset) or [Group](#Group) instance.
5480 A `CompoundType` instance is used to describe a compound data
5481 type, and can be passed to the the `Dataset.createVariable` method of
5482 a `Dataset` or `Group` instance.
54965483 Compound data types map to numpy structured arrays.
5497 See [CompoundType.__init__](#CompoundType.__init__) for more details.
5484 See `CompoundType.__init__` for more details.
54985485
54995486 The instance variables `dtype` and `name` should not be modified by
55005487 the user.
55075494
55085495 CompoundType constructor.
55095496
5510 **`group`**: [Group](#Group) instance to associate with the compound datatype.
5497 **`group`**: `Group` instance to associate with the compound datatype.
55115498
55125499 **`datatype`**: A numpy dtype object describing a structured (a.k.a record)
55135500 array. Can be composed of homogeneous numeric or character data types, or
55215508 instances (so create CompoundType instances for the innermost structures
55225509 first).
55235510
5524 ***Note 2***: [CompoundType](#CompoundType) instances should be created using the
5525 [Dataset.createCompoundType](#Dataset.createCompoundType)
5526 method of a [Dataset](#Dataset) or [Group](#Group) instance, not using this class directly.
5511 ***Note 2***: `CompoundType` instances should be created using the
5512 `Dataset.createCompoundType` method of a `Dataset` or
5513 `Group` instance, not using this class directly.
55275514 """
55285515 cdef nc_type xtype
55295516 # convert dt to a numpy datatype object
57955782
57965783 cdef class VLType:
57975784 """
5798 A [VLType](#VLType) instance is used to describe a variable length (VLEN) data
5799 type, and can be passed to the the [Dataset.createVariable](#Dataset.createVariable) method of
5800 a [Dataset](#Dataset) or [Group](#Group) instance. See
5801 [VLType.__init__](#VLType.__init__)for more details.
5785 A `VLType` instance is used to describe a variable length (VLEN) data
5786 type, and can be passed to the the `Dataset.createVariable` method of
5787 a `Dataset` or `Group` instance. See
5788 `VLType.__init__` for more details.
58025789
58035790 The instance variables `dtype` and `name` should not be modified by
58045791 the user.
58115798
58125799 VLType constructor.
58135800
5814 **`group`**: [Group](#Group) instance to associate with the VLEN datatype.
5801 **`group`**: `Group` instance to associate with the VLEN datatype.
58155802
58165803 **`datatype`**: An numpy dtype object describing the component type for the
58175804 variable length array.
58195806 **`datatype_name`**: a Python string containing a description of the
58205807 VLEN data type.
58215808
5822 ***`Note`***: [VLType](#VLType) instances should be created using the
5823 [Dataset.createVLType](#Dataset.createVLType)
5824 method of a [Dataset](#Dataset) or [Group](#Group) instance, not using this class directly.
5809 ***`Note`***: `VLType` instances should be created using the
5810 `Dataset.createVLType` method of a `Dataset` or
5811 `Group` instance, not using this class directly.
58255812 """
58265813 cdef nc_type xtype
58275814 if 'typeid' in kwargs:
59045891
59055892 cdef class EnumType:
59065893 """
5907 A [EnumType](#EnumType) instance is used to describe an Enum data
5908 type, and can be passed to the the [Dataset.createVariable](#Dataset.createVariable) method of
5909 a [Dataset](#Dataset) or [Group](#Group) instance. See
5910 [EnumType.__init__](#EnumType.__init__) for more details.
5894 A `EnumType` instance is used to describe an Enum data
5895 type, and can be passed to the the `Dataset.createVariable` method of
5896 a `Dataset` or `Group` instance. See
5897 `EnumType.__init__` for more details.
59115898
59125899 The instance variables `dtype`, `name` and `enum_dict` should not be modified by
59135900 the user.
59205907
59215908 EnumType constructor.
59225909
5923 **`group`**: [Group](#Group) instance to associate with the VLEN datatype.
5910 **`group`**: `Group` instance to associate with the VLEN datatype.
59245911
59255912 **`datatype`**: An numpy integer dtype object describing the base type
59265913 for the Enum.
59315918 **`enum_dict`**: a Python dictionary containing the Enum field/value
59325919 pairs.
59335920
5934 ***`Note`***: [EnumType](#EnumType) instances should be created using the
5935 [Dataset.createEnumType](#Dataset.createEnumType)
5936 method of a [Dataset](#Dataset) or [Group](#Group) instance, not using this class directly.
5921 ***`Note`***: `EnumType` instances should be created using the
5922 `Dataset.createEnumType` method of a `Dataset` or
5923 `Group` instance, not using this class directly.
59375924 """
59385925 cdef nc_type xtype
59395926 if 'typeid' in kwargs:
61226109
61236110 Adapted from [pycdf](http://pysclint.sourceforge.net/pycdf) by Andre Gosselin.
61246111
6125 Example usage (See [MFDataset.__init__](#MFDataset.__init__) for more details):
6112 Example usage (See `MFDataset.__init__` for more details):
61266113
61276114 ```python
61286115 >>> import numpy as np
63976384 # raise error is user tries to pickle a MFDataset object.
63986385 raise NotImplementedError('MFDataset is not picklable')
63996386
6400 class _Dimension(object):
6387 class _Dimension:
64016388 def __init__(self, dimname, dim, dimlens, dimtotlen):
64026389 self.dimlens = dimlens
64036390 self.dimtotlen = dimtotlen
64146401 return "%r: name = '%s', size = %s" %\
64156402 (type(self), self._name, len(self))
64166403
6417 class _Variable(object):
6404 class _Variable:
64186405 def __init__(self, dset, varname, var, recdimname):
64196406 self.dimensions = var.dimensions
64206407 self._dset = dset
65856572 Class providing an interface to a MFDataset time Variable by imposing a unique common
65866573 time unit and/or calendar to all files.
65876574
6588 Example usage (See [MFTime.__init__](#MFTime.__init__) for more details):
6575 Example usage (See `MFTime.__init__` for more details):
65896576
65906577 ```python
6591 >>> import numpy
6578 >>> import numpy as np
65926579 >>> f1 = Dataset("mftest_1.nc","w", format="NETCDF4_CLASSIC")
65936580 >>> f2 = Dataset("mftest_2.nc","w", format="NETCDF4_CLASSIC")
65946581 >>> f1.createDimension("time",None)
65996586 >>> t2.units = "days since 2000-02-01"
66006587 >>> t1.calendar = "standard"
66016588 >>> t2.calendar = "standard"
6602 >>> t1[:] = numpy.arange(31)
6603 >>> t2[:] = numpy.arange(30)
6589 >>> t1[:] = np.arange(31)
6590 >>> t2[:] = np.arange(30)
66046591 >>> f1.close()
66056592 >>> f2.close()
66066593 >>> # Read the two files in at once, in one Dataset.
66236610 Create a time Variable with units consistent across a multifile
66246611 dataset.
66256612
6626 **`time`**: Time variable from a [MFDataset](#MFDataset).
6613 **`time`**: Time variable from a `MFDataset`.
66276614
66286615 **`units`**: Time units, for example, `'days since 1979-01-01'`. If `None`,
66296616 use the units from the master variable.
77 import getopt
88 import os
99
10 python3 = sys.version_info[0] > 2
11 if python3:
12 # no unicode type in python 3, use bytes instead when testing
13 # for a string-like object
14 unicode = str
15 else:
16 range = xrange
1710 try:
1811 bytes
1912 except NameError:
5750 """Iterate through all (sub-) groups of topgrp, similar to os.walktree.
5851
5952 """
60 grps = topgrp.groups.values()
61 yield grps
53 yield topgrp.groups.values()
6254 for grp in topgrp.groups.values():
63 for children in _walk_grps(grp):
64 yield children
55 yield from _walk_grps(grp)
6556
6657 def _quantize(data,least_significant_digit):
6758 """
222213 # string-like object try to cast to int
223214 # needs to be done first, since strings are iterable and
224215 # hard to distinguish from something castable to an iterable numpy array.
225 if type(e) in [str,bytes,unicode]:
216 if type(e) in [str, bytes]:
226217 try:
227218 e = int(e)
228219 except:
379370 # Create the start, count, stride and indices arrays.
380371
381372 sdim.append(max(nDims, 1))
382 start = np.empty(sdim, dtype=int)
383 count = np.empty(sdim, dtype=int)
384 stride = np.empty(sdim, dtype=int)
373 start = np.empty(sdim, dtype=np.intp)
374 count = np.empty(sdim, dtype=np.intp)
375 stride = np.empty(sdim, dtype=np.intp)
385376 indices = np.empty(sdim, dtype=object)
386377
387378 for i, e in enumerate(elem):
55 # can also just run
66 # python -m unittest discover . 'tst*py'
77
8 python3 = sys.version_info[0] > 2
9
108 # Find all test files.
119 test_files = glob.glob('tst_*.py')
12 if python3:
13 test_files.remove('tst_unicode.py')
14 sys.stdout.write('not running tst_unicode.py ...\n')
15 else:
16 test_files.remove('tst_unicode3.py')
17 sys.stdout.write('not running tst_unicode3.py ...\n')
1810 if __netcdf4libversion__ < '4.2.1' or __has_parallel4_support__ or __has_pnetcdf_support__:
1911 test_files.remove('tst_diskless.py')
2012 sys.stdout.write('not running tst_diskless.py ...\n')
55 import tempfile
66 import warnings
77
8 import numpy as NP
8 import numpy as np
99 from collections import OrderedDict
1010 from numpy.random.mtrand import uniform
1111
1212 import netCDF4
1313
1414 # test attribute creation.
15 FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
15 #FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
16 FILE_NAME = 'tst_atts.nc'
1617 VAR_NAME="dummy_var"
1718 GROUP_NAME = "dummy_group"
1819 DIM1_NAME="x"
2526 EMPTYSTRATT = ''
2627 INTATT = 1
2728 FLOATATT = math.pi
28 SEQATT = NP.arange(10)
29 SEQATT = np.arange(10)
2930 STRINGSEQATT = ['mary ','','had ','a ','little ','lamb',]
3031 #ATTDICT = {'stratt':STRATT,'floatatt':FLOATATT,'seqatt':SEQATT,
3132 # 'stringseqatt':''.join(STRINGSEQATT), # changed in issue #770
105106 raise ValueError('This test should have failed.')
106107 # issue #485 (triggers segfault in C lib
107108 # with version 1.2.1 without pull request #486)
108 f.foo = NP.array('bar','S')
109 f.foo = NP.array('bar','U')
109 f.foo = np.array('bar','S')
110 f.foo = np.array('bar','U')
110111 # issue #529 write string attribute as NC_CHAR unless
111112 # it can't be decoded to ascii. Add setncattr_string
112113 # method to force NC_STRING.
113 f.charatt = u'foo' # will be written as NC_CHAR
114 f.charatt = 'foo' # will be written as NC_CHAR
114115 f.setncattr_string('stringatt','bar') # NC_STRING
115 f.cafe = u'caf\xe9' # NC_STRING
116 f.batt = u'caf\xe9'.encode('utf-8') #NC_CHAR
116 f.cafe = 'caf\xe9' # NC_STRING
117 f.batt = 'caf\xe9'.encode('utf-8') #NC_CHAR
117118 v.setncattr_string('stringatt','bar') # NC_STRING
118119 # issue #882 - provide an option to always string attribute
119120 # as NC_STRINGs. Testing various approaches to setting text attributes...
120121 f.set_ncstring_attrs(True)
121 f.stringatt_ncstr = u'foo' # will now be written as NC_STRING
122 f.stringatt_ncstr = 'foo' # will now be written as NC_STRING
122123 f.setncattr_string('stringatt_ncstr','bar') # NC_STRING anyway
123 f.caf_ncstr = u'caf\xe9' # NC_STRING anyway
124 f.bat_ncstr = u'caf\xe9'.encode('utf-8') # now NC_STRING
124 f.caf_ncstr = 'caf\xe9' # NC_STRING anyway
125 f.bat_ncstr = 'caf\xe9'.encode('utf-8') # now NC_STRING
125126 g.stratt_ncstr = STRATT # now NC_STRING
126127 #g.renameAttribute('stratt_tmp','stratt_ncstr')
127128 v.setncattr_string('stringatt_ncstr','bar') # NC_STRING anyway
144145 # global attributes.
145146 # check __dict__ method for accessing all netCDF attributes.
146147 for key,val in ATTDICT.items():
147 if type(val) == NP.ndarray:
148 if type(val) == np.ndarray:
148149 assert f.__dict__[key].tolist() == val.tolist()
149150 else:
150151 assert f.__dict__[key] == val
161162 # variable attributes.
162163 # check __dict__ method for accessing all netCDF attributes.
163164 for key,val in ATTDICT.items():
164 if type(val) == NP.ndarray:
165 if type(val) == np.ndarray:
165166 assert v.__dict__[key].tolist() == val.tolist()
166167 else:
167168 assert v.__dict__[key] == val
177178 assert v.getncattr('foo') == 1
178179 assert v.getncattr('bar') == 2
179180 # check type of attributes using ncdump (issue #529)
180 try: # ncdump may not be on the system PATH
181 nc_proc = subprocess.Popen(
182 ['ncdump', '-h', FILE_NAME], stdout=subprocess.PIPE)
183 except OSError:
184 warnings.warn('"ncdump" not on system path; cannot test '
185 'read of some attributes')
186 pass
187 else: # We do have ncdump output
188 dep = nc_proc.communicate()[0]
189 try: # python 2
190 ncdump_output = dep.split('\n')
191 except TypeError: # python 3
192 ncdump_output = str(dep,encoding='utf-8').split('\n')
181 if not os.getenv('NO_CDL'):
182 ncdump_output = f.tocdl()
193183 for line in ncdump_output:
194184 line = line.strip('\t\n\r')
195185 line = line.strip()# Must be done another time for group variables
201191 # check attributes in subgroup.
202192 # global attributes.
203193 for key,val in ATTDICT.items():
204 if type(val) == NP.ndarray:
194 if type(val) == np.ndarray:
205195 assert g.__dict__[key].tolist() == val.tolist()
206196 else:
207197 assert g.__dict__[key] == val
214204 assert g.stringseqatt == STRINGSEQATT
215205 assert g.stringseqatt_array == STRINGSEQATT
216206 for key,val in ATTDICT.items():
217 if type(val) == NP.ndarray:
207 if type(val) == np.ndarray:
218208 assert v1.__dict__[key].tolist() == val.tolist()
219209 else:
220210 assert v1.__dict__[key] == val
11 import unittest
22 import os
33 import tempfile
4 import numpy as NP
54 from numpy.random.mtrand import uniform
65 import netCDF4
76
99 ENUM_NAME = 'cloud_t'
1010 ENUM_BASETYPE = np.int8
1111 VAR_NAME = 'primary_cloud'
12 ENUM_DICT = {u'Altocumulus': 7, u'Missing': 127, u'Stratus': 2, u'Clear': 0,
13 u'Nimbostratus': 6, u'Cumulus': 4, u'Altostratus': 5, u'Cumulonimbus': 1,
14 u'Stratocumulus': 3}
12 ENUM_DICT = {'Altocumulus': 7, 'Missing': 127, 'Stratus': 2, 'Clear': 0,
13 'Nimbostratus': 6, 'Cumulus': 4, 'Altostratus': 5, 'Cumulonimbus': 1,
14 'Stratocumulus': 3}
1515 datain = np.array([ENUM_DICT['Clear'],ENUM_DICT['Stratus'],ENUM_DICT['Cumulus'],\
1616 ENUM_DICT['Missing'],ENUM_DICT['Cumulonimbus']],dtype=ENUM_BASETYPE)
1717 datain_masked = np.ma.masked_values(datain,ENUM_DICT['Missing'])
11 import unittest
22 import os
33 import tempfile
4 import numpy as NP
54 import netCDF4
65
76 # test group creation.
87
98 FILE_NAME1 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
109 FILE_NAME2 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
11 DYNASTY=u"Tudor"
12 HENRY_VII=u"Henry_VII"
13 MARGARET=u"Margaret"
14 JAMES_V_OF_SCOTLAND=u"James_V_of_Scotland"
15 MARY_I_OF_SCOTLAND=u"Mary_I_of_Scotland"
16 JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND=u"James_VI_of_Scotland_and_I_of_England"
10 DYNASTY = "Tudor"
11 HENRY_VII = "Henry_VII"
12 MARGARET = "Margaret"
13 JAMES_V_OF_SCOTLAND = "James_V_of_Scotland"
14 MARY_I_OF_SCOTLAND = "Mary_I_of_Scotland"
15 JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND = "James_VI_of_Scotland_and_I_of_England"
1716 names = [HENRY_VII,MARGARET,JAMES_V_OF_SCOTLAND,MARY_I_OF_SCOTLAND,JAMES_VI_OF_SCOTLAND_AND_I_OF_ENGLAND]
1817 root = '/'
1918 TREE1 = [root]
3029
3130 # python generator to walk the Group tree.
3231 def walktree(top):
33 values = top.groups.values()
34 yield values
32 yield top.groups.values()
3533 for value in top.groups.values():
36 for children in walktree(value):
37 yield children
34 yield from walktree(value)
3835
3936 class GroupsTestCase(unittest.TestCase):
4037
11 import unittest
22 import os
33 import tempfile
4 import numpy as NP
54 import netCDF4
65
76 # test implicit group creation by using unix-like paths
11 import unittest
22 import os
33 import tempfile
4 import numpy as NP
4 import numpy as np
55 from numpy import ma
66 from numpy.testing import assert_array_equal, assert_array_almost_equal
77 from numpy.random.mtrand import uniform
1818 ranarr = 100.*uniform(size=(ndim))
1919 ranarr2 = 100.*uniform(size=(ndim))
2020 # used for checking vector missing_values
21 arr3 = NP.linspace(0,9,ndim)
22 mask = NP.zeros(ndim,NP.bool); mask[-1]=True; mask[-2]=True
23 marr3 = NP.ma.array(arr3, mask=mask, dtype=NP.int32)
21 arr3 = np.linspace(0,9,ndim)
22 mask = np.zeros(ndim,np.bool_); mask[-1]=True; mask[-2]=True
23 marr3 = np.ma.array(arr3, mask=mask, dtype=np.int32)
2424 packeddata = 10.*uniform(size=(ndim))
2525 missing_value = -9999.
26 missing_value2 = NP.nan
26 missing_value2 = np.nan
2727 missing_value3 = [8,9]
2828 ranarr[::2] = missing_value
2929 ranarr2[::2] = missing_value2
30 NP.seterr(invalid='ignore') # silence warnings from ma.masked_values
30 np.seterr(invalid='ignore') # silence warnings from ma.masked_values
3131 maskedarr = ma.masked_values(ranarr,missing_value)
3232 #maskedarr2 = ma.masked_values(ranarr2,missing_value2)
3333 maskedarr2 = ma.masked_invalid(ranarr2)
3434 scale_factor = (packeddata.max()-packeddata.min())/(2.*32766.)
3535 add_offset = 0.5*(packeddata.max()+packeddata.min())
36 packeddata2 = NP.around((packeddata-add_offset)/scale_factor).astype('i2')
36 packeddata2 = np.around((packeddata-add_offset)/scale_factor).astype('i2')
3737
3838 class PrimitiveTypesTestCase(unittest.TestCase):
3939
7070 doh2[0] = 1.
7171 # added test for issue 515
7272 file.createDimension('x',1)
73 v = file.createVariable('v',NP.float,'x',fill_value=-9999)
73 v = file.createVariable('v',np.float64,'x',fill_value=-9999)
7474 file.close()
7575
7676 # issue #972: when auto_fill off byte arrays (u1,i1) should
118118 assert_array_almost_equal(datamasked[:].filled(),ranarr)
119119 assert_array_almost_equal(datamasked2[:].filled(),ranarr2)
120120 assert_array_almost_equal(datapacked[:],packeddata,decimal=4)
121 assert(datapacked3[:].dtype == NP.float)
121 assert(datapacked3[:].dtype == np.float64)
122122 # added to test fix to issue 46 (result before r865 was 10)
123123 assert_array_equal(datapacked2[0],11)
124124 # added test for issue 515
125 assert(file['v'][0] is NP.ma.masked)
125 assert(file['v'][0] is np.ma.masked)
126126 file.close()
127127 # issue 766
128 NP.seterr(invalid='raise')
128 np.seterr(invalid='raise')
129129 f = netCDF4.Dataset(self.file, 'w')
130130 f.createDimension('dimension', 2)
131 f.createVariable('variable', NP.float32, dimensions=('dimension',))
132 f['variable'][:] = NP.nan
131 f.createVariable('variable', np.float32, dimensions=('dimension',))
132 f['variable'][:] = np.nan
133133 data = f['variable'][:] # should not raise an error
134134 f.close()
135135 # issue #972
1515 FILE_NAME2 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
1616 FILE_NAME3 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
1717 datacheck1 =\
18 ma.array([0,5000.0,4000.0,0],dtype=np.float,mask=[True,False,False,True])
18 ma.array([0,5000.0,4000.0,0],dtype=np.float64,mask=[True,False,False,True])
1919 datacheck2 =\
20 ma.array([3000.0,5000.0,4000.0,0],dtype=np.float,mask=[False,False,False,True])
20 ma.array([3000.0,5000.0,4000.0,0],dtype=np.float64,mask=[False,False,False,True])
2121 datacheck3 =\
22 ma.array([3000.0,5000.0,0,2000.0],dtype=np.float,mask=[False,False,True,False])
22 ma.array([3000.0,5000.0,0,2000.0],dtype=np.float64,mask=[False,False,True,False])
2323 mask = [False,True,False,False]
2424 datacheck4 = ma.array([1.5625,0,3.75,4.125],mask=mask,dtype=np.float32)
2525 fillval = default_fillvals[datacheck4.dtype.str[1:]]
2323 d = f.createDimension('x',6)
2424 v = f.createVariable('v', "i2", 'x')
2525 # issue 730: set fill_value for vlen str vars
26 v2 = f.createVariable('v2',str,'x',fill_value=u'<missing>')
26 v2 = f.createVariable('v2', str, 'x', fill_value='<missing>')
2727
2828 v.missing_value = self.missing_values
2929 v[:] = self.v
5555 # this part fails with netcdf 4.1.3
5656 # a bug in vlen strings?
5757 if __netcdf4libversion__ >= '4.4.0':
58 assert (v2[0]==u'first')
59 assert (v2[1]==u'<missing>')
58 assert v2[0] == 'first'
59 assert v2[1] == '<missing>'
6060
6161
6262 f.close()
11 import unittest
22 import os
33 import tempfile
4 import numpy as NP
54 import netCDF4
65 from netCDF4 import __has_rename_grp__
76
11 import unittest
22 import os
33 import tempfile
4 import numpy as NP
54 from numpy.testing import assert_almost_equal
65 import netCDF4
76 import math
44 file_name = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
55 xdim=None; ydim=121; zdim=169
66 datashape = (ydim,zdim)
7 data = np.ones(datashape,dtype=np.float_)
7 data = np.ones(datashape,dtype=np.float64)
88
99 class ShapeTestCase(unittest.TestCase):
1010
1414 f.createDimension('x',xdim)
1515 f.createDimension('y',ydim)
1616 f.createDimension('z',zdim)
17 v = f.createVariable('data',np.float_,('x','y','z'))
17 v = f.createVariable('data',np.float64,('x','y','z'))
1818 f.close()
1919
2020 def tearDown(self):
11 from numpy.random import seed, randint
22 from numpy.testing import assert_array_equal, assert_equal,\
33 assert_array_almost_equal
4 import tempfile, unittest, os, random
4 import tempfile, unittest, os, random, sys
55 import numpy as np
66
77 file_name = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
1717 f = Dataset(file_name,'w')
1818 f.createDimension('x',xdim)
1919 f.createDimension('xu',None)
20 f.createDimension('xu2',None)
2021 f.createDimension('y',ydim)
2122 f.createDimension('z',zdim)
2223 f.createDimension('zu',None)
2324 v = f.createVariable('data','u1',('x','y','z'))
2425 vu = f.createVariable('datau','u1',('xu','y','zu'))
2526 v1 = f.createVariable('data1d', 'u1', ('x',))
27 v2 = f.createVariable('data1dx', 'u1', ('xu2',))
2628 # variable with no unlimited dim.
2729 # write slice in reverse order
2830 v[:,::-1,:] = data
3234 vu[:,::-1,:] = data
3335
3436 v1[:] = data[:, 0, 0]
37 if sys.maxsize > 2**32:
38 v2[2**31] = 1 # issue 1112 (overflow on windows)
3539 f.close()
3640
3741 def tearDown(self):
7478 def test_1d(self):
7579 f = Dataset(self.file, 'r')
7680 v1 = f.variables['data1d']
81 v2 = f.variables['data1dx']
7782 d = data[:,0,0]
7883 assert_equal(v1[:], d)
84 if sys.maxsize > 2**32:
85 assert_equal(v2[2**31], 1)
7986 assert_equal(v1[4:], d[4:])
8087 # test return of array scalar.
8188 assert_equal(v1[0].shape, ())
128135 nlons = 12; lon = f.createDimension('lon',nlons)
129136 nlevs = 1; lev = f.createDimension('lev',nlevs)
130137 time = f.createDimension('time',None)
131 var = f.createVariable('var',np.float_,('time','lev','lat','lon'))
138 var = f.createVariable('var',np.float64,('time','lev','lat','lon'))
132139 a = np.random.uniform(size=(10,nlevs,nlats,nlons))
133140 var[0:10] = a
134141 f.close()
167174 nlats = 11; lat = f.createDimension('lat',nlats)
168175 nlons = 20; lon = f.createDimension('lon',nlons)
169176 time = f.createDimension('time',None)
170 var = f.createVariable('var',np.float_,('time','lat','lon'))
177 var = f.createVariable('var',np.float64,('time','lat','lon'))
171178 a = np.random.uniform(size=(3,nlats,nlons))
172179 var[[True,True,False,False,False,True]] = a
173180 var[0,2.0,"-1"] = 0 # issue 312
202209 td = nc.createDimension('t',None)
203210 xd = nc.createDimension('x',33)
204211 yd = nc.createDimension('y',4)
205 v = nc.createVariable('v',np.float_,('t','x','y'))
212 v = nc.createVariable('v',np.float64,('t','x','y'))
206213 nc.close()
207214 nc = Dataset(self.file)
208215 data = np.empty(nc['v'].shape, nc['v'].dtype)
215222 f.createDimension('d1',3)
216223 f.createDimension('d2',None)
217224 f.createDimension('d3',5)
218 f.createVariable('v2',np.float_,('d1','d2','d3'))
225 f.createVariable('v2',np.float64,('d1','d2','d3'))
219226 f['v2'][:] = np.zeros((3,4,5))
220227 f['v2'][0,:,0] = np.arange(4)
221228 f['v2'][0,:,:] = np.ones((4,5))
226233 f.createDimension('time',2)
227234 f.createDimension('lat',10)
228235 f.createDimension('lon',9)
229 f.createVariable('v1',np.int,('time', 'lon','lat',))
236 f.createVariable('v1',np.int64,('time', 'lon','lat',))
230237 arr = np.arange(9*10).reshape((9, 10))
231238 f['v1'][:] = arr
232239 assert_array_equal(f['v1'][:],np.broadcast_to(arr,f['v1'].shape))
238245 with Dataset(self.file,'w') as f:
239246 f.createDimension('d1',3)
240247 f.createDimension('d2',None)
241 f.createVariable('v1',np.int,('d2','d1',))
242 f['v1'][0] = np.arange(3,dtype=np.int)
243 f['v1'][1:3] = np.arange(3,dtype=np.int)
248 f.createVariable('v1',np.int64,('d2','d1',))
249 f['v1'][0] = np.arange(3,dtype=np.int64)
250 f['v1'][1:3] = np.arange(3,dtype=np.int64)
244251 assert_array_equal(f['v1'][:], np.broadcast_to(np.arange(3),(3,3)))
245 f.createVariable('v2',np.int,('d1','d2',))
246 f['v2'][:,0] = np.arange(3,dtype=np.int)
247 f['v2'][:,1:3] = np.arange(6,dtype=np.int).reshape(3,2)
248 assert_array_equal(f['v2'][:,1:3],np.arange(6,dtype=np.int).reshape(3,2))
249 assert_array_equal(f['v2'][:,0],np.arange(3,dtype=np.int))
252 f.createVariable('v2',np.int64,('d1','d2',))
253 f['v2'][:,0] = np.arange(3,dtype=np.int64)
254 f['v2'][:,1:3] = np.arange(6,dtype=np.int64).reshape(3,2)
255 assert_array_equal(f['v2'][:,1:3],np.arange(6,dtype=np.int64).reshape(3,2))
256 assert_array_equal(f['v2'][:,0],np.arange(3,dtype=np.int64))
250257
251258 def test_issue1083(self):
252259 with Dataset(self.file, "w") as nc:
7474 # issue 271 (_FillValue should be a byte for character arrays on
7575 # Python 3)
7676 v = f.variables['issue271']
77 if type(v._FillValue) == bytes:
78 assert(v._FillValue == b'Z') # python 3
79 else:
80 assert(v._FillValue == u'Z') # python 2
77 assert type(v._FillValue) == bytes
78 assert v._FillValue == b'Z'
8179 # issue 273 (setting _FillValue to null byte manually)
8280 v2 = f.variables['issue273']
83 if type(v2._FillValue) == bytes:
84 assert(v2._FillValue == b'\x00') # python 3
85 else:
86 assert(v2._FillValue == u'') # python 2
81 assert type(v2._FillValue) == bytes
82 assert v2._FillValue == b'\x00'
8783 assert(str(issue273_data) == str(v2[:]))
88 # isse 707 (don't apply missing_value if cast to variable type is
84 # issue 707 (don't apply missing_value if cast to variable type is
8985 # unsafe)
9086 v3 = f.variables['issue707']
9187 assert_array_equal(v3[:],-1*np.ones(n2dim,v3.dtype))
22 import sys, unittest, os, tempfile
33
44 FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
5 ATT1 = u'\u03a0\u03a3\u03a9'
6 ATT2 = u'x\xb0'
7 ATT3 = [u'\u03a0',u'\u03a3',u'\u03a9']
8 DIM_NAME = u'x\xb0'
9 VAR_NAME = u'Andr\xe9'
5 ATT1 = '\u03a0\u03a3\u03a9'
6 ATT2 = 'x\xb0'
7 ATT3 = ['\u03a0', '\u03a3', '\u03a9']
8 DIM_NAME = 'x\xb0'
9 VAR_NAME = 'Andr\xe9'
1010
1111 class UnicodeTestCase(unittest.TestCase):
1212
1717 f.attribute2 = ATT2
1818 f.attribute3 = ATT3
1919 d = f.createDimension(DIM_NAME, None)
20 v = f.createVariable(VAR_NAME, np.float, (DIM_NAME,))
20 v = f.createVariable(VAR_NAME, np.float64, (DIM_NAME,))
2121 f.close()
2222
2323 def tearDown(self):
3333 assert f.attribute1 == ATT1
3434 assert f.attribute2 == ATT2
3535 #assert f.attribute3 == ''.join(ATT3)
36 assert f.attribute3 == ATT3 # behavior changed issue 770
36 # behavior changed issue 770
37 assert f.attribute3 == ATT3
3738 f.close()
3839
3940 if __name__ == '__main__':
+0
-42
test/tst_unicode3.py less more
0 import netCDF4
1 import numpy as np
2 import sys, unittest, os, tempfile
3
4 FILE_NAME = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
5 ATT1 = '\u03a0\u03a3\u03a9'
6 ATT2 = 'x\xb0'
7 ATT3 = ['\u03a0','\u03a3','\u03a9']
8 DIM_NAME = 'x\xb0'
9 VAR_NAME = 'Andr\xe9'
10
11 class UnicodeTestCase(unittest.TestCase):
12
13 def setUp(self):
14 self.file = FILE_NAME
15 f = netCDF4.Dataset(self.file,'w')
16 f.attribute1 = ATT1
17 f.attribute2 = ATT2
18 f.attribute3 = ATT3
19 d = f.createDimension(DIM_NAME, None)
20 v = f.createVariable(VAR_NAME, np.float_, (DIM_NAME,))
21 f.close()
22
23 def tearDown(self):
24 # Remove the temporary files
25 os.remove(self.file)
26
27 def runTest(self):
28 """testing unicode"""
29 f = netCDF4.Dataset(self.file, 'r')
30 d = f.dimensions[DIM_NAME]
31 v = f.variables[VAR_NAME]
32 # check accessing individual attributes.
33 assert f.attribute1 == ATT1
34 assert f.attribute2 == ATT2
35 #assert f.attribute3 == ''.join(ATT3)
36 # behavior changed pull request #771
37 assert f.attribute3 == ATT3
38 f.close()
39
40 if __name__ == '__main__':
41 unittest.main()
11 import unittest
22 import os
33 import tempfile
4 import numpy as NP
4 import numpy as np
55 from numpy.random.mtrand import uniform
66 from numpy.testing import assert_array_equal, assert_array_almost_equal
77 import netCDF4
5858 self.assertTrue(bar.shape == (n1dim,n2dim,n3dim))
5959 # check data.
6060 #assert_array_almost_equal(bar[:,:,:], ranarr)
61 assert_array_almost_equal(bar[:,:,:], 2.*NP.ones((n1dim,n2dim,n3dim),ranarr.dtype))
61 assert_array_almost_equal(bar[:,:,:], 2.*np.ones((n1dim,n2dim,n3dim),ranarr.dtype))
6262 f.close()
6363
6464 if __name__ == '__main__':
319319 #assert_equal(str(e), "At most one ellipsis allowed in a slicing expression")
320320 assert_equal(str(e), "list index out of range")
321321
322 class FakeGroup(object):
322 class FakeGroup:
323323 """Create a fake group instance by passing a dictionary of booleans
324324 keyed by dimension name."""
325325 def __init__(self, dimensions):
327327 for k,v in dimensions.items():
328328 self.dimensions[k] = FakeDimension(v)
329329
330 class FakeDimension(object):
330 class FakeDimension:
331331 def __init__(self, unlimited=False):
332332 self.unlimited = unlimited
333333
11 import unittest
22 import os
33 import tempfile
4 import numpy as NP
4 import numpy as np
55 from numpy.random.mtrand import uniform
66 from numpy.testing import assert_array_equal, assert_array_almost_equal
77 import netCDF4
6666 assert v1.size == DIM1_LEN * DIM2_LEN * DIM3_LEN
6767 assert len(v1) == DIM1_LEN
6868
69 #assert NP.allclose(v1[:],randomdata)
69 #assert np.allclose(v1[:],randomdata)
7070 assert_array_almost_equal(v1[:],randomdata)
7171 # check variables in sub group.
7272 g = f.groups[GROUP_NAME]
8585 assert v2.dimensions == (DIM2_NAME,DIM3_NAME)
8686 assert v1.shape == (DIM1_LEN,DIM2_LEN,DIM3_LEN)
8787 assert v2.shape == (DIM2_LEN,DIM3_LEN)
88 #assert NP.allclose(v1[:],randomdata)
88 #assert np.allclose(v1[:],randomdata)
8989 assert_array_almost_equal(v1[:],randomdata)
9090 f.close()
9191
203203 n = 0
204204 for nlen in ilen:
205205 data = np.random.uniform(low=0.0, high=1.0, size=nlen)
206 if n==99:
207 # mark last value as missing
208 mask = np.zeros(data.shape,dtype=bool)
209 mask[-1] = True
210 data = np.ma.masked_array(data, mask=mask)
211 self.data = data
212206 v[n] = data
207 if n==99: self.data = data
213208 n += 1
214209 nc.close()
215210 def tearDown(self):
218213 def runTest(self):
219214 """testing packing float vlens as scaled integers (issue #1003)."""
220215 nc = Dataset(self.file)
221 # see if data is masked
222216 data = nc['vl'][-1]
223 assert(data[-1] is np.ma.masked)
224217 # check max error of compression
225218 err = np.abs(data - self.data)
226219 assert(err.max() < nc['vl'].scale_factor)
227220 # turn off auto-scaling
228221 nc.set_auto_maskandscale(False)
229222 data = nc['vl'][-1]
230 assert(data[-1] == 255)
223 assert(data[-1] == np.around(self.data[-1]/nc['vl'].scale_factor))
231224 nc.close()
232225
233226 if __name__ == '__main__':