Codebase list netcdf4-python / f3bb634
[ Bas Couwenberg ] [ Debian Janitor ] New upstream snapshot. Debian Janitor 2 years ago
35 changed file(s) with 2574 addition(s) and 4922 deletion(s). Raw diff Collapse all Expand all
+0
-95
.github/workflows/build.yml less more
0 name: Build and Test Linux
1 on: [push, pull_request]
2 jobs:
3 build-linux:
4 name: Python (${{ matrix.python-version }})
5 runs-on: ubuntu-latest
6 env:
7 PNETCDF_VERSION: 1.12.1
8 NETCDF_VERSION: 4.7.4
9 NETCDF_DIR: ${{ github.workspace }}/..
10 NETCDF_EXTRA_CONFIG: --enable-pnetcdf
11 CC: mpicc.mpich
12 # NO_NET: 1
13 strategy:
14 matrix:
15 python-version: ["3.9"]
16 steps:
17
18 - uses: actions/checkout@v2
19
20 - name: Set up Python ${{ matrix.python-version }}
21 uses: actions/setup-python@v2
22 with:
23 python-version: ${{ matrix.python-version }}
24
25 - name: Install Ubuntu Dependencies
26 run: |
27 sudo apt-get update
28 sudo apt-get install mpich libmpich-dev libhdf5-mpich-dev libcurl4-openssl-dev
29 echo "Download and build PnetCDF version ${PNETCDF_VERSION}"
30 wget https://parallel-netcdf.github.io/Release/pnetcdf-${PNETCDF_VERSION}.tar.gz
31 tar -xzf pnetcdf-${PNETCDF_VERSION}.tar.gz
32 pushd pnetcdf-${PNETCDF_VERSION}
33 ./configure --prefix $NETCDF_DIR --enable-shared --disable-fortran --disable-cxx
34 make -j 2
35 make install
36 popd
37 echo "Download and build netCDF version ${NETCDF_VERSION}"
38 wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-c-${NETCDF_VERSION}.tar.gz
39 tar -xzf netcdf-c-${NETCDF_VERSION}.tar.gz
40 pushd netcdf-c-${NETCDF_VERSION}
41 export CPPFLAGS="-I/usr/include/hdf5/mpich -I${NETCDF_DIR}/include"
42 export LDFLAGS="-L${NETCDF_DIR}/lib"
43 export LIBS="-lhdf5_mpich_hl -lhdf5_mpich -lm -lz"
44 ./configure --prefix $NETCDF_DIR --enable-netcdf-4 --enable-shared --enable-dap --enable-parallel4 $NETCDF_EXTRA_CONFIG
45 make -j 2
46 make install
47 popd
48
49 # - name: The job has failed
50 # if: ${{ failure() }}
51 # run: |
52 # cd netcdf-c-${NETCDF_VERSION}
53 # cat config.log
54
55 - name: Install python dependencies via pip
56 run: |
57 python -m pip install --upgrade pip
58 pip install numpy cython cftime pytest twine wheel check-manifest mpi4py
59
60 - name: Install netcdf4-python
61 run: |
62 export PATH=${NETCDF_DIR}/bin:${PATH}
63 python setup.py install
64 - name: Test
65 run: |
66 export PATH=${NETCDF_DIR}/bin:${PATH}
67 python checkversion.py
68 # serial
69 cd test
70 python run_all.py
71 # parallel (hdf5 for netcdf4, pnetcdf for netcdf3)
72 cd ../examples
73 mpirun.mpich -np 4 python mpi_example.py
74 if [ $? -ne 0 ] ; then
75 echo "hdf5 mpi test failed!"
76 exit 1
77 else
78 echo "hdf5 mpi test passed!"
79 fi
80 mpirun.mpich -np 4 python mpi_example.py NETCDF3_64BIT_DATA
81 if [ $? -ne 0 ] ; then
82 echo "pnetcdf mpi test failed!"
83 exit 1
84 else
85 echo "pnetcdf mpi test passed!"
86 fi
87
88 - name: Tarball
89 run: |
90 export PATH=${NETCDF_DIR}/bin:${PATH}
91 python setup.py --version
92 pip wheel . -w dist --no-deps
93 check-manifest --verbose
94 twine check dist/*
+0
-85
.github/workflows/miniconda.yml less more
0 name: Build and Test
1
2 on:
3 pull_request:
4 push:
5 branches: [master]
6
7 jobs:
8 run-serial:
9 runs-on: ${{ matrix.os }}
10 strategy:
11 matrix:
12 python-version: ["3.6", "3.7", "3.8", "3.9"]
13 os: [windows-latest, ubuntu-latest, macos-latest]
14 platform: [x64, x32]
15 exclude:
16 - os: macos-latest
17 platform: x32
18 steps:
19 - uses: actions/checkout@v2
20
21 - name: Setup Conda
22 uses: s-weigand/setup-conda@v1
23 with:
24 activate-conda: false
25 conda-channels: conda-forge
26
27 - name: Python ${{ matrix.python-version }}
28 shell: bash -l {0}
29 run: |
30 conda create --name TEST python=${{ matrix.python-version }} numpy cython pip pytest hdf5 libnetcdf cftime --strict-channel-priority
31 source activate TEST
32 export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH" # so setup.py finds nc-config
33 pip install -e . --no-deps --force-reinstall
34 conda info --all
35 conda list
36
37 - name: Tests
38 shell: bash -l {0}
39 run: |
40 source activate TEST
41 cd test && python run_all.py
42
43 run-mpi:
44 runs-on: ${{ matrix.os }}
45 strategy:
46 matrix:
47 python-version: [ "3.9" ]
48 os: [ubuntu-latest]
49 platform: [x64]
50 steps:
51 - uses: actions/checkout@v2
52
53 - name: Setup Conda
54 uses: s-weigand/setup-conda@v1
55 with:
56 activate-conda: false
57 conda-channels: conda-forge
58
59 - name: Python ${{ matrix.python-version }}
60 shell: bash -l {0}
61 run: |
62 conda create --name TEST python=${{ matrix.python-version }} numpy cython pip pytest mpi4py hdf5=*=mpi* libnetcdf=*=mpi* cftime --strict-channel-priority
63 source activate TEST
64 export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH" # so setup.py finds nc-config
65 pip install -e . --no-deps --force-reinstall
66 conda info --all
67 conda list
68
69 - name: Tests
70 shell: bash -l {0}
71 run: |
72 source activate TEST
73 cd test && python run_all.py
74 cd ../examples
75 export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH"
76 which mpirun
77 mpirun --version
78 mpirun -np 4 python mpi_example.py
79 if [ $? -ne 0 ] ; then
80 echo "hdf5 mpi test failed!"
81 exit 1
82 else
83 echo "hdf5 mpi test passed!"
84 fi
0 version 1.5.7 (not yet released)
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
08 version 1.5.6 (tag v1.5.6rel)
19 ==============================
210 * move CI/CD tests from travis/appveyor to Github Actions (PR #1061).
0 Metadata-Version: 1.1
1 Name: netCDF4
2 Version: 1.5.7
3 Summary: Provides an object-oriented python interface to the netCDF version 4 library.
4 Home-page: http://github.com/Unidata/netcdf4-python
5 Author: Jeff Whitaker
6 Author-email: jeffrey.s.whitaker@noaa.gov
7 License: License :: OSI Approved :: MIT License
8 Download-URL: http://python.org/pypi/netCDF4
9 Description: netCDF version 4 has many features not found in earlier versions of the library, such as hierarchical groups, zlib compression, multiple unlimited dimensions, and new data types. It is implemented on top of HDF5. This module implements most of the new features, and can read and write netCDF files compatible with older versions of the library. The API is modelled after Scientific.IO.NetCDF, and should be familiar to users of that module.
10
11 This project is hosted on a `GitHub repository <https://github.com/Unidata/netcdf4-python>`_ where you may access the most up-to-date source.
12 Keywords: numpy,netcdf,data,science,network,oceanography,meteorology,climate
13 Platform: any
14 Classifier: Development Status :: 3 - Alpha
15 Classifier: Programming Language :: Python :: 3
16 Classifier: Programming Language :: Python :: 3.6
17 Classifier: Programming Language :: Python :: 3.7
18 Classifier: Programming Language :: Python :: 3.8
19 Classifier: Intended Audience :: Science/Research
20 Classifier: License :: OSI Approved :: MIT License
21 Classifier: Topic :: Software Development :: Libraries :: Python Modules
22 Classifier: Topic :: System :: Archiving :: Compression
23 Classifier: Operating System :: OS Independent
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 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.
1213
1314 12/20/2020: Version [1.5.5.1](https://pypi.python.org/pypi/netCDF4/1.5.5.1) released.
1415 Updated binary wheels for OSX and linux that link latest netcdf-c and hdf5 libs.
205206 with `export USE_NCCONFIG=0` will use environment variables to find paths to libraries and include files,
206207 instead of relying exclusively on the nc-config utility.
207208
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).
209 ## Installation
210 The easiest way to install is through pip:
211
212 ```shell
213 pip install netCDF4
214 ```
215
216 or, if you are a user of the Conda package manager,
217
218 ```shell
219 conda install -c conda-forge netCDF4
220 ```
221
222 ## Development installation
223 * Clone GitHub repository (`git clone https://github.com/Unidata/netcdf4-python.git`)
210224
211225 * 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).
226 installed and you have [Python](https://www.python.org) 3.6 or newer.
227
228 * Make sure [HDF5](http://www.h5py.org/) and netcdf-4 are installed,
229 and the `nc-config` utility is in your Unix PATH.
230
231 * Run `python setup.py build`, then `pip install -e .`.
218232
219233 * To run all the tests, execute `cd test && python run_all.py`.
220234
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
0 netcdf4-python (1.5.6-1~exp2) UNRELEASED; urgency=medium
1
0 netcdf4-python (1.5.6rel+git20210522.1.203dcc1-1) UNRELEASED; urgency=medium
1
2 [ Bas Couwenberg ]
23 * Update watch file for GitHub URL changes.
34
4 -- Bas Couwenberg <sebastic@debian.org> Sat, 20 Mar 2021 08:45:38 +0100
5 [ Debian Janitor ]
6 * New upstream snapshot.
7
8 -- Bas Couwenberg <sebastic@debian.org> Wed, 02 Jun 2021 05:04:08 -0000
59
610 netcdf4-python (1.5.6-1~exp1) experimental; urgency=medium
711
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 6.4.3" />
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
1010 <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>
1111 <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>
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 .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, .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>
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>
2318
2419
2520 <h2>Contents</h2>
2621 <ul>
27 <li><a href="#version-156">Version 1.5.6</a></li>
22 <li><a href="#version-157">Version 1.5.7</a></li>
2823 </ul></li>
2924 <li><a href="#introduction">Introduction</a>
3025 <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>
26 <li><a href="#quick-install">Quick Install</a></li>
27 <li><a href="#developer-install">Developer Install</a></li>
3428 </ul></li>
3529 <li><a href="#tutorial">Tutorial</a>
3630 <ul>
197191
198192 </li>
199193 <li>
200 <a class="class" href="#Group">Group</a>
194 <a class="class" href="#Variable">Variable</a>
201195 <ul class="memberlist">
202196 <li>
203 <a class="function" href="#Group.__init__">Group</a>
204 </li>
205 <li>
206 <a class="function" href="#Group.close">close</a>
197 <a class="function" href="#Variable.__init__">Variable</a>
198 </li>
199 <li>
200 <a class="function" href="#Variable.group">group</a>
201 </li>
202 <li>
203 <a class="function" href="#Variable.ncattrs">ncattrs</a>
204 </li>
205 <li>
206 <a class="function" href="#Variable.setncattr">setncattr</a>
207 </li>
208 <li>
209 <a class="function" href="#Variable.setncattr_string">setncattr_string</a>
210 </li>
211 <li>
212 <a class="function" href="#Variable.setncatts">setncatts</a>
213 </li>
214 <li>
215 <a class="function" href="#Variable.getncattr">getncattr</a>
216 </li>
217 <li>
218 <a class="function" href="#Variable.delncattr">delncattr</a>
219 </li>
220 <li>
221 <a class="function" href="#Variable.filters">filters</a>
222 </li>
223 <li>
224 <a class="function" href="#Variable.endian">endian</a>
225 </li>
226 <li>
227 <a class="function" href="#Variable.chunking">chunking</a>
228 </li>
229 <li>
230 <a class="function" href="#Variable.get_var_chunk_cache">get_var_chunk_cache</a>
231 </li>
232 <li>
233 <a class="function" href="#Variable.set_var_chunk_cache">set_var_chunk_cache</a>
234 </li>
235 <li>
236 <a class="function" href="#Variable.renameAttribute">renameAttribute</a>
237 </li>
238 <li>
239 <a class="function" href="#Variable.assignValue">assignValue</a>
240 </li>
241 <li>
242 <a class="function" href="#Variable.getValue">getValue</a>
243 </li>
244 <li>
245 <a class="function" href="#Variable.set_auto_chartostring">set_auto_chartostring</a>
246 </li>
247 <li>
248 <a class="function" href="#Variable.use_nc_get_vars">use_nc_get_vars</a>
249 </li>
250 <li>
251 <a class="function" href="#Variable.set_auto_maskandscale">set_auto_maskandscale</a>
252 </li>
253 <li>
254 <a class="function" href="#Variable.set_auto_scale">set_auto_scale</a>
255 </li>
256 <li>
257 <a class="function" href="#Variable.set_auto_mask">set_auto_mask</a>
258 </li>
259 <li>
260 <a class="function" href="#Variable.set_always_mask">set_always_mask</a>
261 </li>
262 <li>
263 <a class="function" href="#Variable.set_ncstring_attrs">set_ncstring_attrs</a>
264 </li>
265 <li>
266 <a class="function" href="#Variable.set_collective">set_collective</a>
267 </li>
268 <li>
269 <a class="function" href="#Variable.get_dims">get_dims</a>
270 </li>
271 <li>
272 <a class="variable" href="#Variable.name">name</a>
273 </li>
274 <li>
275 <a class="variable" href="#Variable.datatype">datatype</a>
276 </li>
277 <li>
278 <a class="variable" href="#Variable.shape">shape</a>
279 </li>
280 <li>
281 <a class="variable" href="#Variable.size">size</a>
282 </li>
283 <li>
284 <a class="variable" href="#Variable.dimensions">dimensions</a>
285 </li>
286 <li>
287 <a class="variable" href="#Variable.ndim">ndim</a>
288 </li>
289 <li>
290 <a class="variable" href="#Variable.dtype">dtype</a>
291 </li>
292 <li>
293 <a class="variable" href="#Variable.mask">mask</a>
294 </li>
295 <li>
296 <a class="variable" href="#Variable.scale">scale</a>
297 </li>
298 <li>
299 <a class="variable" href="#Variable.always_mask">always_mask</a>
300 </li>
301 <li>
302 <a class="variable" href="#Variable.chartostring">chartostring</a>
207303 </li>
208304 </ul>
209305
230326
231327 </li>
232328 <li>
233 <a class="class" href="#Variable">Variable</a>
329 <a class="class" href="#Group">Group</a>
234330 <ul class="memberlist">
235331 <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>
332 <a class="function" href="#Group.__init__">Group</a>
333 </li>
334 <li>
335 <a class="function" href="#Group.close">close</a>
336 </li>
337 </ul>
338
339 </li>
340 <li>
341 <a class="class" href="#MFDataset">MFDataset</a>
342 <ul class="memberlist">
343 <li>
344 <a class="function" href="#MFDataset.__init__">MFDataset</a>
345 </li>
346 <li>
347 <a class="function" href="#MFDataset.ncattrs">ncattrs</a>
348 </li>
349 <li>
350 <a class="function" href="#MFDataset.close">close</a>
351 </li>
352 </ul>
353
354 </li>
355 <li>
356 <a class="class" href="#MFTime">MFTime</a>
357 <ul class="memberlist">
358 <li>
359 <a class="function" href="#MFTime.__init__">MFTime</a>
342360 </li>
343361 </ul>
344362
377395
378396 </li>
379397 <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
398 <a class="function" href="#date2num">date2num</a>
396399 </li>
397400 <li>
398 <a class="function" href="#getlibversion">getlibversion</a>
401 <a class="function" href="#num2date">num2date</a>
399402 </li>
400403 <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>
404 <a class="function" href="#date2index">date2index</a>
408405 </li>
409406 <li>
410407 <a class="function" href="#stringtochar">stringtochar</a>
413410 <a class="function" href="#chartostring">chartostring</a>
414411 </li>
415412 <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
413 <a class="function" href="#stringtoarr">stringtoarr</a>
429414 </li>
430415 <li>
431 <a class="class" href="#MFTime">MFTime</a>
416 <a class="function" href="#getlibversion">getlibversion</a>
417 </li>
418 <li>
419 <a class="class" href="#EnumType">EnumType</a>
432420 <ul class="memberlist">
433421 <li>
434 <a class="function" href="#MFTime.__init__">MFTime</a>
422 <a class="function" href="#EnumType.__init__">EnumType</a>
423 </li>
424 <li>
425 <a class="variable" href="#EnumType.dtype">dtype</a>
426 </li>
427 <li>
428 <a class="variable" href="#EnumType.name">name</a>
429 </li>
430 <li>
431 <a class="variable" href="#EnumType.enum_dict">enum_dict</a>
435432 </li>
436433 </ul>
437434
435 </li>
436 <li>
437 <a class="function" href="#get_chunk_cache">get_chunk_cache</a>
438 </li>
439 <li>
440 <a class="function" href="#set_chunk_cache">set_chunk_cache</a>
438441 </li>
439442 </ul>
440443
441444
442445 <a class="attribution" title="pdoc: Python API documentation generator" href="https://pdoc.dev">
443 built with <img
444 alt="pdoc"
446 built with <span class="visually-hidden">pdoc</span><img
447 alt="pdoc logo"
445448 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"/>
446449 </a>
447450 </div>
449452 <main class="pdoc">
450453 <section>
451454 <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>
455 netCDF4 </h1>
456
457 <div class="docstring"><h2 id="version-157">Version 1.5.7</h2>
455458
456459 <h1 id="introduction">Introduction</h1>
457460
474477 compound types containing enums, or vlens containing compound
475478 types) are not supported.</p>
476479
477 <h2 id="download">Download</h2>
480 <h2 id="quick-install">Quick Install</h2>
478481
479482 <ul>
480 <li>Latest bleeding-edge code from the
483 <li>the easiest way to get going is to install via <code>pip install netCDF4</code>.
484 (or if you use the <a href="http://conda.io">conda</a> package manager <code>conda install -c conda_forge netCDF4</code>).</li>
485 </ul>
486
487 <h2 id="developer-install">Developer Install</h2>
488
489 <ul>
490 <li>Clone the
481491 <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.
492 <li>Make sure the dependencies are satisfied (Python 3.6 or later,
493 <a href="http://numpy.scipy.org">numpy</a>,
494 <a href="http://cython.org">Cython</a>,
495 <a href="https://github.com/Unidata/cftime">cftime</a>,
496 <a href="https://pypi.python.org/pypi/setuptools">setuptools</a>,
497 the <a href="https://www.hdfgroup.org/solutions/hdf5/">HDF5 C library</a>,
498 and the <a href="https://www.unidata.ucar.edu/software/netcdf/">netCDF C library</a>).
499 For MPI parallel IO support, an MPI-enabled versions of the netcdf library
500 is required, as is <a href="http://mpi4py.scipy.org">mpi4py</a>.
515501 Parallel IO further depends on the existence of MPI-enabled HDF5 or the
516502 <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,
503 <li>By default, the utility <code>nc-config</code> (installed with netcdf-c)
527504 will be run used to determine where all the dependencies live.</li>
528505 <li>If <code>nc-config</code> is not in your default <code>PATH</code>, you can set the <code>NETCDF4_DIR</code>
529506 environment variable and <code>setup.py</code> will look in <code>$NETCDF4_DIR/bin</code>.
535512 As a last resort, the library and include paths can be set via environment variables.
536513 If you go this route, set <code>USE_NCCONFIG</code> and <code>USE_SETUPCFG</code> to 0, and specify
537514 <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
515 If the dependencies are not found
541516 in any of the paths specified by environment variables, then standard locations
542517 (such as <code>/usr</code> and <code>/usr/local</code>) are searched.</li>
543518 <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>
519 necessary).</li>
546520 <li>run the tests in the 'test' directory by running <code>python run_all.py</code>.</li>
547521 </ul>
548522
568542
569543 <h2 id="creatingopeningclosing-a-netcdf-file">Creating/Opening/Closing a netCDF file</h2>
570544
571 <p>To create a netCDF file from python, you simply call the <a href="#Dataset">Dataset</a>
545 <p>To create a netCDF file from python, you simply call the <code><a href="#Dataset">Dataset</a></code>
572546 constructor. This is also the method used to open an existing netCDF
573547 file. If the file is open for write access (<code>mode='w', 'r+'</code> or <code>'a'</code>), you may
574548 write any type of data including new dimensions, groups, variables and
592566 keyword in the <code><a href="#Dataset">Dataset</a></code> constructor. The default format is
593567 <code>NETCDF4</code>. To see how a given file is formatted, you can examine the
594568 <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>
569 accomplished via the <code><a href="#Dataset.close">Dataset.close</a></code> method of the <code><a href="#Dataset">Dataset</a></code>
596570 instance.</p>
597571
598572 <p>Here's an example:</p>
605579 </code></pre></div>
606580
607581 <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
582 reading over http if a URL is provided to the <code><a href="#Dataset">Dataset</a></code> constructor instead of a
609583 filename. However, this requires that the netCDF library be built with
610584 OPenDAP support, via the <code>--enable-dap</code> configure option (added in
611585 version 4.0.1).</p>
615589 <p>netCDF version 4 added support for organizing data in hierarchical
616590 groups, which are analogous to directories in a filesystem. Groups serve
617591 as containers for variables, dimensions and attributes, as well as other
618 groups. A <a href="#Dataset">Dataset</a> creates a special group, called
592 groups. A <code><a href="#Dataset">Dataset</a></code> creates a special group, called
619593 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>
594 filesystem. To create <code><a href="#Group">Group</a></code> instances, use the
595 <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>
596 instance. <code><a href="#Dataset.createGroup">Dataset.createGroup</a></code> takes a single argument, a
597 python string containing the name of the new group. The new <code><a href="#Group">Group</a></code>
624598 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
599 the <code>groups</code> dictionary attribute of the <code><a href="#Dataset">Dataset</a></code> instance. Only
626600 <code>NETCDF4</code> formatted files support Groups, if you try to create a Group
627601 in a netCDF 3 file you will get an error message.</p>
628602
642616 <span class="o">&gt;&gt;&gt;</span>
643617 </code></pre></div>
644618
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
619 <p>Groups can exist within groups in a <code><a href="#Dataset">Dataset</a></code>, just as directories
620 exist within directories in a unix filesystem. Each <code><a href="#Group">Group</a></code> instance
647621 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
622 instances contained within that group. Each <code><a href="#Group">Group</a></code> instance also has a
649623 <code>path</code> attribute that contains a simulated unix directory path to
650624 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>
625 use a unix-like path as an argument to <code><a href="#Dataset.createGroup">Dataset.createGroup</a></code>.</p>
652626
653627 <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>
654628 <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>
660634 returned.</p>
661635
662636 <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>
637 <code><a href="#Dataset">Dataset</a></code>. The function <code>walktree</code> is a Python generator that is used
638 to walk the directory tree. Note that printing the <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code>
665639 object yields summary information about it's contents.</p>
666640
667641 <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>
707681 before any variables can be created the dimensions they use must be
708682 created first. A special case, not often used in practice, is that of a
709683 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
684 the <code><a href="#Dataset.createDimension">Dataset.createDimension</a></code> method of a <code><a href="#Dataset">Dataset</a></code>
685 or <code><a href="#Group">Group</a></code> instance. A Python string is used to set the name of the
712686 dimension, and an integer value is used to set the size. To create an
713687 unlimited dimension (a dimension that can be appended to), the size
714688 value is set to <code>None</code> or 0. In this example, there both the <code>time</code> and
722696 <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>
723697 </code></pre></div>
724698
725 <p>All of the <a href="#Dimension">Dimension</a> instances are stored in a python dictionary.</p>
699 <p>All of the <code><a href="#Dimension">Dimension</a></code> instances are stored in a python dictionary.</p>
726700
727701 <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>
728702 <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>
729703 </code></pre></div>
730704
731 <p>Using the python <code>len</code> function with a <a href="#Dimension">Dimension</a> instance returns
705 <p>Using the python <code>len</code> function with a <code><a href="#Dimension">Dimension</a></code> instance returns
732706 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
707 <code><a href="#Dimension.isunlimited">Dimension.isunlimited</a></code> method of a <code><a href="#Dimension">Dimension</a></code> instance
734708 be used to determine if the dimensions is unlimited, or appendable.</p>
735709
736710 <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>
741715 <span class="kc">True</span>
742716 </code></pre></div>
743717
744 <p>Printing the <a href="#Dimension">Dimension</a> object
718 <p>Printing the <code><a href="#Dimension">Dimension</a></code> object
745719 provides useful summary info, including the name and length of the dimension,
746720 and whether it is unlimited.</p>
747721
753727 <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>
754728 </code></pre></div>
755729
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>
730 <p><code><a href="#Dimension">Dimension</a></code> names can be changed using the
731 <code>Datatset.renameDimension</code> method of a <code><a href="#Dataset">Dataset</a></code> or
732 <code><a href="#Group">Group</a></code> instance.</p>
759733
760734 <h2 id="variables-in-a-netcdf-file">Variables in a netCDF file</h2>
761735
763737 supplied by the <a href="http://numpy.scipy.org">numpy module</a>. However,
764738 unlike numpy arrays, netCDF4 variables can be appended to along one or
765739 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
740 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or
741 <code><a href="#Group">Group</a></code> instance. The <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code>j method
768742 has two mandatory arguments, the variable name (a Python string), and
769743 the variable datatype. The variable's dimensions are given by a tuple
770744 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
745 <code><a href="#Dataset.createDimension">Dataset.createDimension</a></code>). To create a scalar
772746 variable, simply leave out the dimensions keyword. The variable
773747 primitive datatypes correspond to the dtype attribute of a numpy array.
774748 You can specify the datatype as a numpy dtype object, or anything that
786760 can only be used if the file format is <code>NETCDF4</code>.</p>
787761
788762 <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
763 coordinate variables. The <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code>
764 method returns an instance of the <code><a href="#Variable">Variable</a></code> class whose methods can be
791765 used later to access and set variable data and attributes.</p>
792766
793767 <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>
799773 <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>
800774 </code></pre></div>
801775
802 <p>To get summary info on a <a href="#Variable">Variable</a> instance in an interactive session,
776 <p>To get summary info on a <code><a href="#Variable">Variable</a></code> instance in an interactive session,
803777 just print it.</p>
804778
805779 <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>
818792
819793 <p>If the intermediate groups do not yet exist, they will be created.</p>
820794
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>
795 <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
796 <code><a href="#Variable">Variable</a></code> instances using paths.</p>
823797
824798 <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>
825799 <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>
836810 <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>
837811 </code></pre></div>
838812
839 <p>All of the variables in the <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> are stored in a
813 <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
840814 Python dictionary, in the same way as the dimensions:</p>
841815
842816 <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>
864838 <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>
865839 </code></pre></div>
866840
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>
841 <p><code><a href="#Variable">Variable</a></code> names can be changed using the
842 <code><a href="#Dataset.renameVariable">Dataset.renameVariable</a></code> method of a <code><a href="#Dataset">Dataset</a></code>
869843 instance.</p>
870844
871845 <p>Variables can be sliced similar to numpy arrays, but there are some differences. See
875849
876850 <p>There are two types of attributes in a netCDF file, global and variable.
877851 Global attributes provide information about a group, or the entire
878 dataset, as a whole. <a href="#Variable">Variable</a> attributes provide information about
852 dataset, as a whole. <code><a href="#Variable">Variable</a></code> attributes provide information about
879853 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
854 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>
855 attributes are set by assigning values to <code><a href="#Variable">Variable</a></code> instances
882856 variables. Attributes can be strings, numbers or sequences. Returning to
883857 our example,</p>
884858
894868 <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>
895869 </code></pre></div>
896870
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
871 <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
872 <code><a href="#Variable">Variable</a></code> instance can be used to retrieve the names of all the netCDF
899873 attributes. This method is provided as a convenience, since using the
900874 built-in <code>dir</code> Python function will return a bunch of private methods
901875 and attributes that cannot (or should not) be modified by the user.</p>
907881 <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>
908882 </code></pre></div>
909883
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>
884 <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>
911885 instance provides all the netCDF attribute name/value pairs in a python
912886 dictionary:</p>
913887
915889 <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>
916890 </code></pre></div>
917891
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>
892 <p>Attributes can be deleted from a netCDF <code><a href="#Dataset">Dataset</a></code>, <code><a href="#Group">Group</a></code> or
893 <code><a href="#Variable">Variable</a></code> using the python <code>del</code> statement (i.e. <code>del grp.foo</code>
920894 removes the attribute <code>foo</code> the the group <code>grp</code>).</p>
921895
922896 <h2 id="writing-data-to-and-retrieving-data-from-a-netcdf-variable">Writing data to and retrieving data from a netCDF variable</h2>
923897
924 <p>Now that you have a netCDF <a href="#Variable">Variable</a> instance, how do you put data
898 <p>Now that you have a netCDF <code><a href="#Variable">Variable</a></code> instance, how do you put data
925899 into it? You can just treat it like an array and assign data to a slice.</p>
926900
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>
901 <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>
902 <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>
903 <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>
930904 <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>
931905 <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>
932906 <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>
940914 <span class="mf">90.</span> <span class="p">]</span>
941915 </code></pre></div>
942916
943 <p>Unlike NumPy's array objects, netCDF <a href="#Variable">Variable</a>
917 <p>Unlike NumPy's array objects, netCDF <code><a href="#Variable">Variable</a></code>
944918 objects with unlimited dimensions will grow along those dimensions if you
945919 assign data outside the currently defined range of indices.</p>
946920
1012986
1013987 <p>By default, netcdf4-python returns numpy masked arrays with values equal to the
1014988 <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
989 <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>
10501024 <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>
10511025 </code></pre></div>
10521026
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.
1027 <p><code><a href="#num2date">num2date</a></code> converts numeric values of time in the specified <code>units</code>
1028 and <code>calendar</code> to datetime objects, and <code><a href="#date2num">date2num</a></code> does the reverse.
10551029 All the calendars currently defined in the
10561030 <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
1031 A function called <code><a href="#date2index">date2index</a></code> is also provided which returns the indices
10581032 of a netCDF time variable corresponding to a sequence of datetime instances.</p>
10591033
10601034 <h2 id="reading-data-from-a-multi-file-netcdf-dataset">Reading data from a multi-file netCDF dataset</h2>
10611035
10621036 <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
1037 you can use the <code><a href="#MFDataset">MFDataset</a></code> class to read the data as if it were
10641038 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
1039 a <code><a href="#Dataset">Dataset</a></code> instance, create a <code><a href="#MFDataset">MFDataset</a></code> instance with either a list
10661040 of filenames, or a string with a wildcard (which is then converted to
10671041 a sorted list of files using the python glob module).
10681042 Variables in the list of files that share the same unlimited
10771051 <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>
10781052 <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>
10791053 <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>
1054 <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>
1055 </code></pre></div>
1056
1057 <p>Now read all the files back in at once with <code><a href="#MFDataset">MFDataset</a></code></p>
10841058
10851059 <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>
10861060 <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>
10921066 <span class="mi">96</span> <span class="mi">97</span> <span class="mi">98</span> <span class="mi">99</span><span class="p">]</span>
10931067 </code></pre></div>
10941068
1095 <p>Note that <a href="#MFDataset">MFDataset</a> can only be used to read, not write, multi-file
1069 <p>Note that <code><a href="#MFDataset">MFDataset</a></code> can only be used to read, not write, multi-file
10961070 datasets.</p>
10971071
10981072 <h2 id="efficient-compression-of-netcdf-variables">Efficient compression of netCDF variables</h2>
10991073
1100 <p>Data stored in netCDF 4 <a href="#Variable">Variable</a> objects can be compressed and
1074 <p>Data stored in netCDF 4 <code><a href="#Variable">Variable</a></code> objects can be compressed and
11011075 decompressed on the fly. The parameters for the compression are
11021076 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
1077 to the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method. To turn on
11041078 compression, set <code>zlib=True</code>. The <code>complevel</code> keyword regulates the
11051079 speed and efficiency of the compression (1 being fastest, but lowest
11061080 compression ratio, 9 being slowest but best compression ratio). The
11091083 compression by reordering the bytes. The shuffle filter can
11101084 significantly improve compression ratios, and is on by default. Setting
11111085 <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
1086 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> to <code>True</code> (it's <code>False</code> by
11131087 default) enables the Fletcher32 checksum algorithm for error detection.
11141088 It's also possible to set the HDF5 chunking parameters and endian-ness
11151089 of the binary data stored in the HDF5 file with the <code>chunksizes</code>
11161090 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
1091 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code>. These keyword arguments only
11181092 are relevant for <code>NETCDF4</code> and <code>NETCDF4_CLASSIC</code> files (where the
11191093 underlying file format is HDF5) and are silently ignored if the file
11201094 format is <code>NETCDF3_CLASSIC</code>, <code>NETCDF3_64BIT_OFFSET</code> or <code>NETCDF3_64BIT_DATA</code>.</p>
11231097 example, it is temperature data that was measured with a precision of
11241098 0.1 degrees), you can dramatically improve zlib compression by
11251099 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
1100 keyword argument to <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code>. The least
11271101 significant digit is the power of ten of the smallest decimal place in
11281102 the data that is a reliable value. For example if the data has a
11291103 precision of 0.1, then setting <code>least_significant_digit=1</code> will cause
11351109
11361110 <p>In our example, try replacing the line</p>
11371111
1138 <pre><code>```python
1139 &gt;&gt;&gt; temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",))
1140 </code></pre>
1112 <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>
1113 </code></pre></div>
11411114
11421115 <p>with</p>
11431116
11631136 information for a point by reading one variable, instead of reading
11641137 different parameters from different variables. Compound data types
11651138 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.
1139 <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.
11671140 Since there is no native complex data type in netcdf, compound types are handy
11681141 for storing numpy complex arrays. Here's an example:</p>
11691142
11701143 <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>
11711144 <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>
11721145 <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>
1146 <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>
11741147 <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>
1148 <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>
11761149 <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>
11771150 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># create a variable with this data type, write some data to it.</span>
11781151 <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>
11791152 <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>
1153 <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>
11811154 <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>
11821155 <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>
11831156 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># close and reopen the file, check the contents.</span>
11851158 <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>
11861159 <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>
11871160 <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>
1161 <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>
11891162 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># .. fill it with contents of structured array.</span>
11901163 <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>
11911164 <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>
11991172 ones first. All possible numpy structured arrays cannot be
12001173 represented as Compound variables - an error message will be
12011174 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
1175 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
12031176 in a Python dictionary, just like variables and dimensions. As always, printing
12041177 objects gives useful summary information in an interactive session:</p>
12051178
12251198
12261199 <p>NetCDF 4 has support for variable-length or "ragged" arrays. These are arrays
12271200 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>
1201 data type, use the <code><a href="#Dataset.createVLType">Dataset.createVLType</a></code> method
1202 method of a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance.</p>
12301203
12311204 <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>
1205 <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>
12331206 </code></pre></div>
12341207
12351208 <p>The numpy datatype of the variable-length sequences and the name of the
12531226
12541227 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">random</span>
12551228 <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>
1229 <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>
12571230 <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>
1231 <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>
1232 <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>
12601233 <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>
12611234 <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>
12621235 <span class="n">vlen</span> <span class="n">variable</span> <span class="o">=</span>
12891262 variables, For vlen strings, you don't need to create a vlen data type.
12901263 Instead, simply use the python <code>str</code> builtin (or a numpy string datatype
12911264 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>
1265 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method.</p>
12931266
12941267 <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>
12951268 <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>
13001273 array is assigned to the vlen string variable.</p>
13011274
13021275 <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>
1276 <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>
13041277 <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>
13051278 <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>
13061279 <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>
13361309 <p>Here's an example of using an Enum type to hold cloud type data.
13371310 The base integer data type and a python dictionary describing the allowed
13381311 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>
1312 <code><a href="#Dataset.createEnumType">Dataset.createEnumType</a></code>.</p>
13401313
13411314 <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>
13421315 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># python dict with allowed values and their names.</span>
13451318 <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>
13461319 <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>
13471320 <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>
1321 <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>
13491322 <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>
13501323 <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>
13511324 </code></pre></div>
14141387 written to a different variable index on each task</p>
14151388
14161389 <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>
1390 <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>
14181391 <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>
14191392 <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>
14201393
14351408 depend on or be affected by other processes. Collective IO is a way of doing
14361409 IO defined in the MPI-IO standard; unlike independent IO, all processes must
14371410 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
1411 the two types of IO, use the <code><a href="#Variable.set_collective">Variable.set_collective</a></code>
1412 <code><a href="#Variable">Variable</a></code> method. All metadata
14401413 operations (such as creation of groups, types, variables, dimensions, or attributes)
14411414 are collective. There are a couple of important limitations of parallel IO:</p>
14421415
14491422 If the write is done in independent mode, the operation will fail with a
14501423 a generic "HDF Error".</li>
14511424 <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>
1425 and hdf5 &gt;= 1.10.3 (although you can read in parallel with earlier versions). To write
1426 compressed data in parallel, the variable must be in 'collective IO mode'. This is done
1427 automatically on variable creation if compression is turned on, but if you are appending
1428 to a variable in an existing file, you must use <code><a href="#Variable.set_collective">Variable.set_collective</a>(True)</code> before attempting
1429 to write to it.</li>
14531430 <li>You cannot use variable-length (VLEN) data types.</li>
14541431 </ul>
14551432
14661443 To perform the conversion to and from character arrays to fixed-width numpy string arrays, the
14671444 following convention is followed by the python interface.
14681445 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
1446 (dtype <code>S1</code>) variable, the <code><a href="#chartostring">chartostring</a></code> utility function is used to convert the array of
14701447 characters to an array of strings with one less dimension (the last dimension is
14711448 interpreted as the length of each string) when reading the data. The character
14721449 set (usually ascii) is specified by the <code>_Encoding</code> attribute. If <code>_Encoding</code>
14731450 is 'none' or 'bytes', then the character array is converted to a numpy
14741451 fixed-width byte string array (dtype <code>S#</code>), otherwise a numpy unicode (dtype
14751452 <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
1453 <code><a href="#stringtochar">stringtochar</a></code> is used to convert the numpy string array to an array of
14771454 characters with one more dimension. For example,</p>
14781455
14791456 <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>
14811458 <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>
14821459 <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>
14831460 <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>
1461 <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>
14851462 <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>
14861463 <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>
14871464 <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>
14951472
14961473 <p>Even if the <code>_Encoding</code> attribute is set, the automatic conversion of char
14971474 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>
1475 <code><a href="#Variable.set_auto_chartostring">Variable.set_auto_chartostring</a></code>.</p>
14991476
15001477 <p>A similar situation is often encountered with numpy structured arrays with subdtypes
15011478 containing fixed-wdith byte strings (dtype=<code>S#</code>). Since there is no native fixed-length string
15101487 Here's an example:</p>
15111488
15121489 <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>
1490 <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>
15141491 <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>
15151492 <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>
15161493 <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>
15171494 <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>
1495 <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>
15191496 <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>
15201497 <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>
15211498 <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>
15581535 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># and persist the file to disk when it is closed.</span>
15591536 <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>
15601537 <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>
1538 <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>
1539 <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>
15631540 <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>
15641541 <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>
15651542 <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>
15921569 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># (ignored for NETCDF4/HDF5 files).</span>
15931570 <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>
15941571 <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>
1572 <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>
1573 <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>
15971574 <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>
15981575 <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>
15991576 <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>
16161593 the parallel IO example, which is in <code>examples/mpi_example.py</code>.
16171594 Unit tests are in the <code>test</code> directory.</p>
16181595
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>
1596 <p><strong>contact</strong>: Jeffrey Whitaker <a href="&#x6d;a&#x69;&#x6c;&#x74;&#x6f;&#x3a;&#106;&#x65;&#102;&#x66;&#x72;&#101;&#121;&#46;&#x73;.&#119;&#x68;&#105;&#x74;&#97;&#x6b;&#x65;&#x72;&#x40;n&#111;&#x61;&#x61;&#x2e;&#103;&#111;&#x76;">&#106;&#x65;&#102;&#x66;&#x72;&#101;&#121;&#46;&#x73;.&#119;&#x68;&#105;&#x74;&#97;&#x6b;&#x65;&#x72;&#x40;n&#111;&#x61;&#x61;&#x2e;&#103;&#111;&#x76;</a></p>
16201597
16211598 <p><strong>copyright</strong>: 2008 by Jeffrey Whitaker.</p>
16221599
16271604 <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>
16281605 </div>
16291606
1630
1607 <details>
1608 <summary>View Source</summary>
1609 <div class="codehilite"><pre><span></span><span class="c1"># init for netCDF4. package</span>
1610 <span class="c1"># Docstring comes from extension module _netCDF4.</span>
1611 <span class="kn">from</span> <span class="nn">._netCDF4</span> <span class="kn">import</span> <span class="o">*</span>
1612 <span class="c1"># Need explicit imports for names beginning with underscores</span>
1613 <span class="kn">from</span> <span class="nn">._netCDF4</span> <span class="kn">import</span> <span class="vm">__doc__</span>
1614 <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>
1615 <span class="n">__has_rename_grp__</span><span class="p">,</span> <span class="n">__has_nc_inq_path__</span><span class="p">,</span>
1616 <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>
1617 <span class="n">__has_nc_create_mem__</span><span class="p">,</span> <span class="n">__has_cdf5_format__</span><span class="p">,</span>
1618 <span class="n">__has_parallel4_support__</span><span class="p">,</span> <span class="n">__has_pnetcdf_support__</span><span class="p">)</span>
1619 <span class="n">__all__</span> <span class="o">=</span>\
1620 <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>
1621 </pre></div>
1622
1623 </details>
1624
16311625 </section>
16321626 <section id="Dataset">
16331627 <div class="attr class">
16391633 </div>
16401634
16411635
1642 <div class="docstring"><p>A netCDF <a href="#Dataset">Dataset</a> is a collection of dimensions, groups, variables and
1636 <div class="docstring"><p>A netCDF <code><a href="#Dataset">Dataset</a></code> is a collection of dimensions, groups, variables and
16431637 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
1638 data fields stored in a netCDF file. See <code><a href="#Dataset.__init__">Dataset.__init__</a></code> for more
16451639 details.</p>
16461640
16471641 <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.
1642 defined for the <code><a href="#Dataset">Dataset</a></code> can be obtained with the
1643 <code><a href="#Dataset.ncattrs">Dataset.ncattrs</a></code> method.
16501644 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
1645 <code><a href="#Dataset">Dataset</a></code> instance. A dictionary containing all the netCDF attribute
16521646 name/value pairs is provided by the <code>__dict__</code> attribute of a
1653 <a href="#Dataset">Dataset</a> instance.</p>
1647 <code><a href="#Dataset">Dataset</a></code> instance.</p>
16541648
16551649 <p>The following class variables are read-only and should not be
16561650 modified by the user.</p>
16571651
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
1652 <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
1653 dimensions defined for the <code><a href="#Group">Group</a></code> or <code><a href="#Dataset">Dataset</a></code> to instances of the
1654 <code><a href="#Dimension">Dimension</a></code> class.</p>
1655
1656 <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
1657 defined for this <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> to instances of the
1658 <code><a href="#Variable">Variable</a></code> class.</p>
1659
1660 <p><strong><code><a href="#Dataset.groups">groups</a></code></strong>: The groups dictionary maps the names of groups created for
1661 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
1662 <code><a href="#Dataset">Dataset</a></code> class is simply a special case of the <code><a href="#Group">Group</a></code> class which
16691663 describes the root group in the netCDF4 file).</p>
16701664
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
1665 <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
1666 compound types defined for the <code><a href="#Group">Group</a></code> or <code><a href="#Dataset">Dataset</a></code> to instances of the
1667 <code><a href="#CompoundType">CompoundType</a></code> class.</p>
1668
1669 <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
1670 variable-length types defined for the <code><a href="#Group">Group</a></code> or <code><a href="#Dataset">Dataset</a></code> to instances
1671 of the <code><a href="#VLType">VLType</a></code> class.</p>
1672
1673 <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
1674 Enum types defined for the <code><a href="#Group">Group</a></code> or <code><a href="#Dataset">Dataset</a></code> to instances
1675 of the <code><a href="#EnumType">EnumType</a></code> class.</p>
1676
1677 <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
16841678 data model version, one of <code>NETCDF3_CLASSIC</code>, <code>NETCDF4</code>,
16851679 <code>NETCDF4_CLASSIC</code>, <code>NETCDF3_64BIT_OFFSET</code> or <code>NETCDF3_64BIT_DATA</code>.</p>
16861680
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
1681 <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>
1682
1683 <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
16901684 file format, one of <code>NETCDF3</code>, <code>HDF5</code>, <code>HDF4</code>,
16911685 <code>PNETCDF</code>, <code>DAP2</code>, <code>DAP4</code> or <code>UNDEFINED</code>. Only available if using
16921686 netcdf C library version &gt;= 4.3.1, otherwise will always return
16931687 <code>UNDEFINED</code>.</p>
16941688
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>
1689 <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
1690 <code><a href="#Group">Group</a></code> instance. <code>None</code> for the root group or <code><a href="#Dataset">Dataset</a></code>
16971691 instance.</p>
16981692
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
1693 <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
1694 the <code><a href="#Dataset">Dataset</a></code> in a unix directory format (the names of groups in the
1695 hierarchy separated by backslashes). A <code><a href="#Dataset">Dataset</a></code> instance is the root
17021696 group, so the path is simply <code>'/'</code>.</p>
17031697
1704 <p><strong><code>keepweakref</code></strong>: If <code>True</code>, child Dimension and Variables objects only keep weak
1698 <p><strong><code><a href="#Dataset.keepweakref">keepweakref</a></code></strong>: If <code>True</code>, child Dimension and Variables objects only keep weak
17051699 references to the parent Dataset or Group.</p>
17061700
17071701 <p><strong><code>_ncstring_attrs__</code></strong>: If <code>True</code>, all text attributes will be written as variable-length
17131707 <div class="attr function"><a class="headerlink" href="#Dataset.__init__">#&nbsp;&nbsp</a>
17141708
17151709
1716 <span class="name">Dataset</span><span class="signature">(unknown)</span> </div>
1710 <span class="name">Dataset</span><span class="signature">()</span>
1711 </div>
17171712
17181713
17191714 <div class="docstring"><p><strong><code>__init__(self, filename, mode="r", clobber=True, diskless=False,
17201715 persist=False, keepweakref=False, memory=None, encoding=None,
17211716 parallel=False, comm=None, info=None, format='NETCDF4')</code></strong></p>
17221717
1723 <p><a href="#Dataset">Dataset</a> constructor.</p>
1718 <p><code><a href="#Dataset">Dataset</a></code> constructor.</p>
17241719
17251720 <p><strong><code>filename</code></strong>: Name of netCDF file to hold dataset. Can also
17261721 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>
1722 set this is just used to set the <code><a href="#Dataset.filepath">filepath()</a></code>.</p>
17281723
17291724 <p><strong><code>mode</code></strong>: access mode. <code>r</code> means read-only; no data can be
17301725 modified. <code>w</code> means write; a new file is created, an existing file with
17681763 <p><strong><code>persist</code></strong>: if <code>diskless=True</code>, persist file to disk when closed
17691764 (default <code>False</code>).</p>
17701765
1771 <p><strong><code>keepweakref</code></strong>: if <code>True</code>, child Dimension and Variable instances will keep weak
1766 <p><strong><code><a href="#Dataset.keepweakref">keepweakref</a></code></strong>: if <code>True</code>, child Dimension and Variable instances will keep weak
17721767 references to the parent Dataset or Group object. Default is <code>False</code>, which
17731768 means strong references will be kept. Having Dimension and Variable instances
17741769 keep a strong reference to the parent Dataset instance, which in turn keeps a
18721867
18731868 <div class="docstring"><p><strong><code>sync(self)</code></strong></p>
18741869
1875 <p>Writes all buffered data in the <a href="#Dataset">Dataset</a> to the disk file.</p>
1870 <p>Writes all buffered data in the <code><a href="#Dataset">Dataset</a></code> to the disk file.</p>
18761871 </div>
18771872
18781873
18881883
18891884 <div class="docstring"><p><strong><code>set_fill_on(self)</code></strong></p>
18901885
1891 <p>Sets the fill mode for a <a href="#Dataset">Dataset</a> open for writing to <code>on</code>.</p>
1886 <p>Sets the fill mode for a <code><a href="#Dataset">Dataset</a></code> open for writing to <code>on</code>.</p>
18921887
18931888 <p>This causes data to be pre-filled with fill values. The fill values can be
18941889 controlled by the variable's <code>_Fill_Value</code> attribute, but is usually
18951890 sufficient to the use the netCDF default <code>_Fill_Value</code> (defined
18961891 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
1892 library corresponds to <code><a href="#Dataset.set_fill_on">set_fill_on</a></code>. Data which are equal to the
18981893 <code>_Fill_Value</code> indicate that the variable was created, but never written
18991894 to.</p>
19001895 </div>
19121907
19131908 <div class="docstring"><p><strong><code>set_fill_off(self)</code></strong></p>
19141909
1915 <p>Sets the fill mode for a <a href="#Dataset">Dataset</a> open for writing to <code>off</code>.</p>
1910 <p>Sets the fill mode for a <code><a href="#Dataset">Dataset</a></code> open for writing to <code>off</code>.</p>
19161911
19171912 <p>This will prevent the data from being pre-filled with fill values, which
19181913 may result in some performance improvements. However, you must then make
19361931
19371932 <p><code>size</code> must be a positive integer or <code>None</code>, which stands for
19381933 "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>
1934 results in an unlimited dimension. The return value is the <code><a href="#Dimension">Dimension</a></code>
19401935 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>
1936 maximum size of the dimension, use the <code>len</code> function on the <code><a href="#Dimension">Dimension</a></code>
19421937 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>
1938 <code><a href="#Dimension.isunlimited">Dimension.isunlimited</a></code> method of the <code><a href="#Dimension">Dimension</a></code> instance.</p>
19441939 </div>
19451940
19461941
19561951
19571952 <div class="docstring"><p><strong><code>renameDimension(self, oldname, newname)</code></strong></p>
19581953
1959 <p>rename a <a href="#Dimension">Dimension</a> named <code>oldname</code> to <code>newname</code>.</p>
1954 <p>rename a <code><a href="#Dimension">Dimension</a></code> named <code>oldname</code> to <code>newname</code>.</p>
19601955 </div>
19611956
19621957
19801975 are homogeneous numeric data types), then the 'inner' compound types <strong>must</strong> be
19811976 created first.</p>
19821977
1983 <p>The return value is the <a href="#CompoundType">CompoundType</a> class instance describing the new
1978 <p>The return value is the <code><a href="#CompoundType">CompoundType</a></code> class instance describing the new
19841979 datatype.</p>
19851980 </div>
19861981
20001995 <p>Creates a new VLEN data type named <code>datatype_name</code> from a numpy
20011996 dtype object <code>datatype</code>.</p>
20021997
2003 <p>The return value is the <a href="#VLType">VLType</a> class instance describing the new
1998 <p>The return value is the <code><a href="#VLType">VLType</a></code> class instance describing the new
20041999 datatype.</p>
20052000 </div>
20062001
20212016 integer dtype object <code>datatype</code>, and a python dictionary
20222017 defining the enum fields and values.</p>
20232018
2024 <p>The return value is the <a href="#EnumType">EnumType</a> class instance describing the new
2019 <p>The return value is the <code><a href="#EnumType">EnumType</a></code> class instance describing the new
20252020 datatype.</p>
20262021 </div>
20272022
20412036 endian='native', least_significant_digit=None, fill_value=None, chunk_cache=None)</code></strong></p>
20422037
20432038 <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
2039 <code><a href="#Dataset.dimensions">dimensions</a></code>. If dimensions are not given, the variable is assumed to be
20452040 a scalar.</p>
20462041
20472042 <p>If <code>varname</code> is specified as a path, using forward slashes as in unix to
20562051 (NC_BYTE), 'u1' (NC_UBYTE), 'i2' or 'h' or 's' (NC_SHORT), 'u2'
20572052 (NC_USHORT), 'i4' or 'i' or 'l' (NC_INT), 'u4' (NC_UINT), 'i8' (NC_INT64),
20582053 '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
2054 <code>datatype</code> can also be a <code><a href="#CompoundType">CompoundType</a></code> instance
2055 (for a structured, or compound array), a <code><a href="#VLType">VLType</a></code> instance
20612056 (for a variable-length array), or the python <code>str</code> builtin
20622057 (for a variable-length string array). Numpy string and unicode datatypes with
20632058 length greater than one are aliases for <code>str</code>.</p>
20652060 <p>Data from netCDF variables is presented to python as numpy arrays with
20662061 the corresponding data type.</p>
20672062
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
2063 <p><code><a href="#Dataset.dimensions">dimensions</a></code> must be a tuple containing dimension names (strings) that
2064 have been defined previously using <code><a href="#Dataset.createDimension">Dataset.createDimension</a></code>. The default value
20702065 is an empty tuple, which means the variable is a scalar.</p>
20712066
20722067 <p>If the optional keyword <code>zlib</code> is <code>True</code>, the data will be compressed in
21082103
21092104 <p>The optional keyword <code>fill_value</code> can be used to override the default
21102105 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>).
2106 any data is written to it, defaults given in the dict <code><a href="#default_fillvals">netCDF4.default_fillvals</a></code>).
21122107 If fill_value is set to <code>False</code>, then the variable is not pre-filled.</p>
21132108
21142109 <p>If the optional keyword parameter <code>least_significant_digit</code> is
21332128 method to change it the next time the Dataset is opened.
21342129 Warning - messing with this parameter can seriously degrade performance.</p>
21352130
2136 <p>The return value is the <a href="#Variable">Variable</a> class instance describing the new
2131 <p>The return value is the <code><a href="#Variable">Variable</a></code> class instance describing the new
21372132 variable.</p>
21382133
21392134 <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
2135 obtained with the <code><a href="#Variable">Variable</a></code> method <code><a href="#Variable.ncattrs">Variable.ncattrs</a></code>. A dictionary
21412136 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
2137 the <code>__dict__</code> attribute of a <code><a href="#Variable">Variable</a></code> instance.</p>
2138
2139 <p><code><a href="#Variable">Variable</a></code> instances behave much like array objects. Data can be
21452140 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
2141 operations on the <code><a href="#Variable">Variable</a></code> instance. A <code><a href="#Variable">Variable</a></code> instance has six
21472142 Dataset standard attributes: <code>dimensions, dtype, shape, ndim, name</code> and
21482143 <code>least_significant_digit</code>. Application programs should never modify
2149 these attributes. The <code>dimensions</code> attribute is a tuple containing the
2144 these attributes. The <code><a href="#Dataset.dimensions">dimensions</a></code> attribute is a tuple containing the
21502145 names of the dimensions associated with this variable. The <code>dtype</code>
21512146 attribute is a string describing the variable's data type (<code>i4, f8,
21522147 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
2148 sizes of all the variable's dimensions. The <code><a href="#Dataset.name">name</a></code> attribute is a
21542149 string containing the name of the Variable instance.
21552150 The <code>least_significant_digit</code>
21562151 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>
2152 the data the contains a reliable value. assigned to the <code><a href="#Variable">Variable</a></code>
21582153 instance. If <code>None</code>, the data is not truncated. The <code>ndim</code> attribute
21592154 is the number of variable dimensions.</p>
21602155 </div>
21722167
21732168 <div class="docstring"><p><strong><code>renameVariable(self, oldname, newname)</code></strong></p>
21742169
2175 <p>rename a <a href="#Variable">Variable</a> named <code>oldname</code> to <code>newname</code></p>
2170 <p>rename a <code><a href="#Variable">Variable</a></code> named <code>oldname</code> to <code>newname</code></p>
21762171 </div>
21772172
21782173
21882183
21892184 <div class="docstring"><p><strong><code>createGroup(self, groupname)</code></strong></p>
21902185
2191 <p>Creates a new <a href="#Group">Group</a> with the given <code>groupname</code>.</p>
2186 <p>Creates a new <code><a href="#Group">Group</a></code> with the given <code>groupname</code>.</p>
21922187
21932188 <p>If <code>groupname</code> is specified as a path, using forward slashes as in unix to
21942189 separate components, then intermediate groups will be created as necessary
21982193 If the specified path describes a group that already exists, no error is
21992194 raised.</p>
22002195
2201 <p>The return value is a <a href="#Group">Group</a> class instance.</p>
2196 <p>The return value is a <code><a href="#Group">Group</a></code> class instance.</p>
22022197 </div>
22032198
22042199
22142209
22152210 <div class="docstring"><p><strong><code>ncattrs(self)</code></strong></p>
22162211
2217 <p>return netCDF global attribute names for this <a href="#Dataset">Dataset</a> or <a href="#Group">Group</a> in a list.</p>
2212 <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>
22182213 </div>
22192214
22202215
23242319
23252320 <div class="docstring"><p><strong><code>renameAttribute(self, oldname, newname)</code></strong></p>
23262321
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>
2322 <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>
23282323 </div>
23292324
23302325
23402335
23412336 <div class="docstring"><p><strong><code>renameGroup(self, oldname, newname)</code></strong></p>
23422337
2343 <p>rename a <a href="#Group">Group</a> named <code>oldname</code> to <code>newname</code> (requires netcdf &gt;= 4.3.1).</p>
2338 <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>
23442339 </div>
23452340
23462341
23562351
23572352 <div class="docstring"><p><strong><code>set_auto_chartostring(self, True_or_False)</code></strong></p>
23582353
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>
2354 <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
2355 <code><a href="#Group">Group</a></code>, as well as for all variables in all its subgroups.</p>
23612356
23622357 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic conversion of
23632358 all character arrays &lt;--> string arrays should be performed for
23812376
23822377 <div class="docstring"><p><strong><code>set_auto_maskandscale(self, True_or_False)</code></strong></p>
23832378
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>
2379 <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
2380 <code><a href="#Group">Group</a></code>, as well as for all variables in all its subgroups.</p>
23862381
23872382 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic conversion to masked arrays
23882383 and variable scaling shall be applied for all variables.</p>
24042399
24052400 <div class="docstring"><p><strong><code>set_auto_mask(self, True_or_False)</code></strong></p>
24062401
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>
2402 <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
2403 <code><a href="#Group">Group</a></code>, as well as for all variables in all its subgroups.</p>
24092404
24102405 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic conversion to masked arrays
24112406 shall be applied for all variables.</p>
24272422
24282423 <div class="docstring"><p><strong><code>set_auto_scale(self, True_or_False)</code></strong></p>
24292424
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>
2425 <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
2426 <code><a href="#Group">Group</a></code>, as well as for all variables in all its subgroups.</p>
24322427
24332428 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic variable scaling
24342429 shall be applied for all variables.</p>
24502445
24512446 <div class="docstring"><p><strong><code>set_always_mask(self, True_or_False)</code></strong></p>
24522447
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
2448 <p>Call <code><a href="#Variable.set_always_mask">Variable.set_always_mask</a></code> for all variables contained in
2449 this <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code>, as well as for all
24552450 variables in all its subgroups.</p>
24562451
24572452 <p><strong><code>True_or_False</code></strong>: Boolean determining if automatic conversion of
24782473
24792474 <div class="docstring"><p><strong><code>set_ncstring_attrs(self, True_or_False)</code></strong></p>
24802475
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
2476 <p>Call <code><a href="#Variable.set_ncstring_attrs">Variable.set_ncstring_attrs</a></code> for all variables contained in
2477 this <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code>, as well as for all its
24832478 subgroups and their variables.</p>
24842479
24852480 <p><strong><code>True_or_False</code></strong>: Boolean determining if all string attributes are
25412536
25422537 <div class="docstring"><p><strong><code>fromcdl(cdlfilename, ncfilename=None, mode='a',format='NETCDF4')</code></strong></p>
25432538
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>
2539 <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>
2540 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>
25462541
25472542 <p><strong><code>cdlfilename</code></strong>: CDL file.</p>
25482543
25712566
25722567 <div class="docstring"><p><strong><code>tocdl(self, coordvars=False, data=False, outfile=None)</code></strong></p>
25732568
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>
2569 <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>
2570 text representation of Dataset. Requires <a href="https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#ncdump_guide">ncdump</a>
2571 to be installed and in <code>$PATH</code>.</p>
25762572
25772573 <p><strong><code>coordvars</code></strong>: include coordinate variable data (via <code>ncdump -c</code>). Default False</p>
25782574
25862582 <div id="Dataset.name" class="classattr">
25872583 <div class="attr variable"><a class="headerlink" href="#Dataset.name">#&nbsp;&nbsp</a>
25882584
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
2585 <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>
2586 </div>
2587
2588 <div class="docstring"><p>string name of Group instance</p>
2589 </div>
2590
25932591
25942592 </div>
25952593 <div id="Dataset.groups" class="classattr">
25962594 <div class="attr variable"><a class="headerlink" href="#Dataset.groups">#&nbsp;&nbsp</a>
25972595
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>
2596 <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>
25992597 </div>
26002598
26012599
26042602 <div id="Dataset.dimensions" class="classattr">
26052603 <div class="attr variable"><a class="headerlink" href="#Dataset.dimensions">#&nbsp;&nbsp</a>
26062604
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>
2605 <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>
26082606 </div>
26092607
26102608
26132611 <div id="Dataset.variables" class="classattr">
26142612 <div class="attr variable"><a class="headerlink" href="#Dataset.variables">#&nbsp;&nbsp</a>
26152613
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>
2614 <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>
26172615 </div>
26182616
26192617
26222620 <div id="Dataset.disk_format" class="classattr">
26232621 <div class="attr variable"><a class="headerlink" href="#Dataset.disk_format">#&nbsp;&nbsp</a>
26242622
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>
2623 <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>
26262624 </div>
26272625
26282626
26312629 <div id="Dataset.path" class="classattr">
26322630 <div class="attr variable"><a class="headerlink" href="#Dataset.path">#&nbsp;&nbsp</a>
26332631
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>
2632 <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>
26352633 </div>
26362634
26372635
26402638 <div id="Dataset.parent" class="classattr">
26412639 <div class="attr variable"><a class="headerlink" href="#Dataset.parent">#&nbsp;&nbsp</a>
26422640
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>
2641 <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>
26442642 </div>
26452643
26462644
26492647 <div id="Dataset.file_format" class="classattr">
26502648 <div class="attr variable"><a class="headerlink" href="#Dataset.file_format">#&nbsp;&nbsp</a>
26512649
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>
2650 <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>
26532651 </div>
26542652
26552653
26582656 <div id="Dataset.data_model" class="classattr">
26592657 <div class="attr variable"><a class="headerlink" href="#Dataset.data_model">#&nbsp;&nbsp</a>
26602658
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>
2659 <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>
26622660 </div>
26632661
26642662
26672665 <div id="Dataset.cmptypes" class="classattr">
26682666 <div class="attr variable"><a class="headerlink" href="#Dataset.cmptypes">#&nbsp;&nbsp</a>
26692667
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>
2668 <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>
26712669 </div>
26722670
26732671
26762674 <div id="Dataset.vltypes" class="classattr">
26772675 <div class="attr variable"><a class="headerlink" href="#Dataset.vltypes">#&nbsp;&nbsp</a>
26782676
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>
2677 <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>
26802678 </div>
26812679
26822680
26852683 <div id="Dataset.enumtypes" class="classattr">
26862684 <div class="attr variable"><a class="headerlink" href="#Dataset.enumtypes">#&nbsp;&nbsp</a>
26872685
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>
2686 <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>
26892687 </div>
26902688
26912689
26942692 <div id="Dataset.keepweakref" class="classattr">
26952693 <div class="attr variable"><a class="headerlink" href="#Dataset.keepweakref">#&nbsp;&nbsp</a>
26962694
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>
2695 <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>
26982696 </div>
26992697
27002698
2699
2700 </div>
2701 </section>
2702 <section id="Variable">
2703 <div class="attr class">
2704 <a class="headerlink" href="#Variable">#&nbsp;&nbsp</a>
2705
2706
2707 <span class="def">class</span>
2708 <span class="name">Variable</span>:
2709 </div>
2710
2711
2712 <div class="docstring"><p>A netCDF <code><a href="#Variable">Variable</a></code> is used to read and write netCDF data. They are
2713 analogous to numpy array objects. See <code><a href="#Variable.__init__">Variable.__init__</a></code> for more
2714 details.</p>
2715
2716 <p>A list of attribute names corresponding to netCDF attributes defined for
2717 the variable can be obtained with the <code><a href="#Variable.ncattrs">Variable.ncattrs</a></code> method. These
2718 attributes can be created by assigning to an attribute of the
2719 <code><a href="#Variable">Variable</a></code> instance. A dictionary containing all the netCDF attribute
2720 name/value pairs is provided by the <code>__dict__</code> attribute of a
2721 <code><a href="#Variable">Variable</a></code> instance.</p>
2722
2723 <p>The following class variables are read-only:</p>
2724
2725 <p><strong><code><a href="#Variable.dimensions">dimensions</a></code></strong>: A tuple containing the names of the
2726 dimensions associated with this variable.</p>
2727
2728 <p><strong><code><a href="#Variable.dtype">dtype</a></code></strong>: A numpy dtype object describing the
2729 variable's data type.</p>
2730
2731 <p><strong><code><a href="#Variable.ndim">ndim</a></code></strong>: The number of variable dimensions.</p>
2732
2733 <p><strong><code><a href="#Variable.shape">shape</a></code></strong>: A tuple with the current shape (length of all dimensions).</p>
2734
2735 <p><strong><code><a href="#Variable.scale">scale</a></code></strong>: If True, <code>scale_factor</code> and <code>add_offset</code> are
2736 applied, and signed integer data is automatically converted to
2737 unsigned integer data if the <code>_Unsigned</code> attribute is set.
2738 Default is <code>True</code>, can be reset using <code><a href="#Variable.set_auto_scale">Variable.set_auto_scale</a></code> and
2739 <code><a href="#Variable.set_auto_maskandscale">Variable.set_auto_maskandscale</a></code> methods.</p>
2740
2741 <p><strong><code><a href="#Variable.mask">mask</a></code></strong>: If True, data is automatically converted to/from masked
2742 arrays when missing values or fill values are present. Default is <code>True</code>, can be
2743 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>
2744 methods.</p>
2745
2746 <p><strong><code><a href="#Variable.chartostring">chartostring</a></code></strong>: If True, data is automatically converted to/from character
2747 arrays to string arrays when the <code>_Encoding</code> variable attribute is set.
2748 Default is <code>True</code>, can be reset using
2749 <code><a href="#Variable.set_auto_chartostring">Variable.set_auto_chartostring</a></code> method.</p>
2750
2751 <p><strong><code>least_significant_digit</code></strong>: Describes the power of ten of the
2752 smallest decimal place in the data the contains a reliable value. Data is
2753 truncated to this decimal place when it is assigned to the <code><a href="#Variable">Variable</a></code>
2754 instance. If <code>None</code>, the data is not truncated.</p>
2755
2756 <p><strong><code>__orthogonal_indexing__</code></strong>: Always <code>True</code>. Indicates to client code
2757 that the object supports 'orthogonal indexing', which means that slices
2758 that are 1d arrays or lists slice along each dimension independently. This
2759 behavior is similar to Fortran or Matlab, but different than numpy.</p>
2760
2761 <p><strong><code><a href="#Variable.datatype">datatype</a></code></strong>: numpy data type (for primitive data types) or VLType/CompoundType
2762 instance (for compound or vlen data types).</p>
2763
2764 <p><strong><code><a href="#Variable.name">name</a></code></strong>: String name.</p>
2765
2766 <p><strong><code><a href="#Variable.size">size</a></code></strong>: The number of stored elements.</p>
2767 </div>
2768
2769
2770 <div id="Variable.__init__" class="classattr">
2771 <div class="attr function"><a class="headerlink" href="#Variable.__init__">#&nbsp;&nbsp</a>
2772
2773
2774 <span class="name">Variable</span><span class="signature">()</span>
2775 </div>
2776
2777
2778 <div class="docstring"><p><strong><code>__init__(self, group, name, datatype, dimensions=(), zlib=False,
2779 complevel=4, shuffle=True, fletcher32=False, contiguous=False,
2780 chunksizes=None, endian='native',
2781 least_significant_digit=None,fill_value=None,chunk_cache=None)</code></strong></p>
2782
2783 <p><code><a href="#Variable">Variable</a></code> constructor.</p>
2784
2785 <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>
2786
2787 <p><strong><code><a href="#Variable.name">name</a></code></strong>: Name of the variable.</p>
2788
2789 <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
2790 numpy dtype object, or a string that describes a numpy dtype object.
2791 Supported values, corresponding to <code>str</code> attribute of numpy dtype
2792 objects, include <code>'f4'</code> (32-bit floating point), <code>'f8'</code> (64-bit floating
2793 point), <code>'i4'</code> (32-bit signed integer), <code>'i2'</code> (16-bit signed integer),
2794 <code>'i8'</code> (64-bit signed integer), <code>'i4'</code> (8-bit signed integer), <code>'i1'</code>
2795 (8-bit signed integer), <code>'u1'</code> (8-bit unsigned integer), <code>'u2'</code> (16-bit
2796 unsigned integer), <code>'u4'</code> (32-bit unsigned integer), <code>'u8'</code> (64-bit
2797 unsigned integer), or <code>'S1'</code> (single-character string). From
2798 compatibility with Scientific.IO.NetCDF, the old Numeric single character
2799 typecodes can also be used (<code>'f'</code> instead of <code>'f4'</code>, <code>'d'</code> instead of
2800 <code>'f8'</code>, <code>'h'</code> or <code>'s'</code> instead of <code>'i2'</code>, <code>'b'</code> or <code>'B'</code> instead of
2801 <code>'i1'</code>, <code>'c'</code> instead of <code>'S1'</code>, and <code>'i'</code> or <code>'l'</code> instead of
2802 <code>'i4'</code>). <code><a href="#Variable.datatype">datatype</a></code> can also be a <code><a href="#CompoundType">CompoundType</a></code> instance
2803 (for a structured, or compound array), a <code><a href="#VLType">VLType</a></code> instance
2804 (for a variable-length array), or the python <code>str</code> builtin
2805 (for a variable-length string array). Numpy string and unicode datatypes with
2806 length greater than one are aliases for <code>str</code>.</p>
2807
2808 <p><strong><code><a href="#Variable.dimensions">dimensions</a></code></strong>: a tuple containing the variable's dimension names
2809 (defined previously with <code>createDimension</code>). Default is an empty tuple
2810 which means the variable is a scalar (and therefore has no dimensions).</p>
2811
2812 <p><strong><code>zlib</code></strong>: if <code>True</code>, data assigned to the <code><a href="#Variable">Variable</a></code>
2813 instance is compressed on disk. Default <code>False</code>.</p>
2814
2815 <p><strong><code>complevel</code></strong>: the level of zlib compression to use (1 is the fastest,
2816 but poorest compression, 9 is the slowest but best compression). Default 4.
2817 Ignored if <code>zlib=False</code>.</p>
2818
2819 <p><strong><code>shuffle</code></strong>: if <code>True</code>, the HDF5 shuffle filter is applied
2820 to improve compression. Default <code>True</code>. Ignored if <code>zlib=False</code>.</p>
2821
2822 <p><strong><code>fletcher32</code></strong>: if <code>True</code> (default <code>False</code>), the Fletcher32 checksum
2823 algorithm is used for error detection.</p>
2824
2825 <p><strong><code>contiguous</code></strong>: if <code>True</code> (default <code>False</code>), the variable data is
2826 stored contiguously on disk. Default <code>False</code>. Setting to <code>True</code> for
2827 a variable with an unlimited dimension will trigger an error.</p>
2828
2829 <p><strong><code>chunksizes</code></strong>: Can be used to specify the HDF5 chunksizes for each
2830 dimension of the variable. A detailed discussion of HDF chunking and I/O
2831 performance is available
2832 <a href="http://www.hdfgroup.org/HDF5/doc/H5.user/Chunking.html">here</a>.
2833 Basically, you want the chunk size for each dimension to match as
2834 closely as possible the size of the data block that users will read
2835 from the file. <code>chunksizes</code> cannot be set if <code>contiguous=True</code>.</p>
2836
2837 <p><strong><code><a href="#Variable.endian">endian</a></code></strong>: Can be used to control whether the
2838 data is stored in little or big endian format on disk. Possible
2839 values are <code>little, big</code> or <code>native</code> (default). The library
2840 will automatically handle endian conversions when the data is read,
2841 but if the data is always going to be read on a computer with the
2842 opposite format as the one used to create the file, there may be
2843 some performance advantage to be gained by setting the endian-ness.
2844 For netCDF 3 files (that don't use HDF5), only <code>endian='native'</code> is allowed.</p>
2845
2846 <p>The <code>zlib, complevel, shuffle, fletcher32, contiguous</code> and <code>chunksizes</code>
2847 keywords are silently ignored for netCDF 3 files that do not use HDF5.</p>
2848
2849 <p><strong><code>least_significant_digit</code></strong>: If specified, variable data will be
2850 truncated (quantized). In conjunction with <code>zlib=True</code> this produces
2851 'lossy', but significantly more efficient compression. For example, if
2852 <code>least_significant_digit=1</code>, data will be quantized using
2853 around(scale<em>data)/scale, where scale = 2</em>*bits, and bits is determined
2854 so that a precision of 0.1 is retained (in this case bits=4). Default is
2855 <code>None</code>, or no quantization.</p>
2856
2857 <p><strong><code>fill_value</code></strong>: If specified, the default netCDF <code>_FillValue</code> (the
2858 value that the variable gets filled with before any data is written to it)
2859 is replaced with this value. If fill_value is set to <code>False</code>, then
2860 the variable is not pre-filled. The default netCDF fill values can be found
2861 in the dictionary <code><a href="#default_fillvals">netCDF4.default_fillvals</a></code>.</p>
2862
2863 <p><strong><code>chunk_cache</code></strong>: If specified, sets the chunk cache size for this variable.
2864 Persists as long as Dataset is open. Use <code><a href="#Variable.set_var_chunk_cache">set_var_chunk_cache</a></code> to
2865 change it when Dataset is re-opened. </p>
2866
2867 <p><strong><em>Note</em></strong>: <code><a href="#Variable">Variable</a></code> instances should be created using the
2868 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or
2869 <code><a href="#Group">Group</a></code> instance, not using this class directly.</p>
2870 </div>
2871
2872
2873 </div>
2874 <div id="Variable.group" class="classattr">
2875 <div class="attr function"><a class="headerlink" href="#Variable.group">#&nbsp;&nbsp</a>
2876
2877
2878 <span class="def">def</span>
2879 <span class="name">group</span><span class="signature">(unknown)</span>:
2880 </div>
2881
2882
2883 <div class="docstring"><p><strong><code>group(self)</code></strong></p>
2884
2885 <p>return the group that this <code><a href="#Variable">Variable</a></code> is a member of.</p>
2886 </div>
2887
2888
2889 </div>
2890 <div id="Variable.ncattrs" class="classattr">
2891 <div class="attr function"><a class="headerlink" href="#Variable.ncattrs">#&nbsp;&nbsp</a>
2892
2893
2894 <span class="def">def</span>
2895 <span class="name">ncattrs</span><span class="signature">(unknown)</span>:
2896 </div>
2897
2898
2899 <div class="docstring"><p><strong><code>ncattrs(self)</code></strong></p>
2900
2901 <p>return netCDF attribute names for this <code><a href="#Variable">Variable</a></code> in a list.</p>
2902 </div>
2903
2904
2905 </div>
2906 <div id="Variable.setncattr" class="classattr">
2907 <div class="attr function"><a class="headerlink" href="#Variable.setncattr">#&nbsp;&nbsp</a>
2908
2909
2910 <span class="def">def</span>
2911 <span class="name">setncattr</span><span class="signature">(unknown)</span>:
2912 </div>
2913
2914
2915 <div class="docstring"><p><strong><code>setncattr(self,name,value)</code></strong></p>
2916
2917 <p>set a netCDF variable attribute using name,value pair. Use if you need to set a
2918 netCDF attribute with the same name as one of the reserved python
2919 attributes.</p>
2920 </div>
2921
2922
2923 </div>
2924 <div id="Variable.setncattr_string" class="classattr">
2925 <div class="attr function"><a class="headerlink" href="#Variable.setncattr_string">#&nbsp;&nbsp</a>
2926
2927
2928 <span class="def">def</span>
2929 <span class="name">setncattr_string</span><span class="signature">(unknown)</span>:
2930 </div>
2931
2932
2933 <div class="docstring"><p><strong><code>setncattr_string(self,name,value)</code></strong></p>
2934
2935 <p>set a netCDF variable string attribute using name,value pair.
2936 Use if you need to ensure that a netCDF attribute is created with type
2937 <code>NC_STRING</code> if the file format is <code>NETCDF4</code>.
2938 Use if you need to set an attribute to an array of variable-length strings.</p>
2939 </div>
2940
2941
2942 </div>
2943 <div id="Variable.setncatts" class="classattr">
2944 <div class="attr function"><a class="headerlink" href="#Variable.setncatts">#&nbsp;&nbsp</a>
2945
2946
2947 <span class="def">def</span>
2948 <span class="name">setncatts</span><span class="signature">(unknown)</span>:
2949 </div>
2950
2951
2952 <div class="docstring"><p><strong><code>setncatts(self,attdict)</code></strong></p>
2953
2954 <p>set a bunch of netCDF variable attributes at once using a python dictionary.
2955 This may be faster when setting a lot of attributes for a <code>NETCDF3</code>
2956 formatted file, since nc_redef/nc_enddef is not called in between setting
2957 each attribute</p>
2958 </div>
2959
2960
2961 </div>
2962 <div id="Variable.getncattr" class="classattr">
2963 <div class="attr function"><a class="headerlink" href="#Variable.getncattr">#&nbsp;&nbsp</a>
2964
2965
2966 <span class="def">def</span>
2967 <span class="name">getncattr</span><span class="signature">(unknown)</span>:
2968 </div>
2969
2970
2971 <div class="docstring"><p><strong><code>getncattr(self,name)</code></strong></p>
2972
2973 <p>retrieve a netCDF variable attribute. Use if you need to set a
2974 netCDF attribute with the same name as one of the reserved python
2975 attributes.</p>
2976
2977 <p>option kwarg <code>encoding</code> can be used to specify the
2978 character encoding of a string attribute (default is <code>utf-8</code>).</p>
2979 </div>
2980
2981
2982 </div>
2983 <div id="Variable.delncattr" class="classattr">
2984 <div class="attr function"><a class="headerlink" href="#Variable.delncattr">#&nbsp;&nbsp</a>
2985
2986
2987 <span class="def">def</span>
2988 <span class="name">delncattr</span><span class="signature">(unknown)</span>:
2989 </div>
2990
2991
2992 <div class="docstring"><p><strong><code>delncattr(self,name,value)</code></strong></p>
2993
2994 <p>delete a netCDF variable attribute. Use if you need to delete a
2995 netCDF attribute with the same name as one of the reserved python
2996 attributes.</p>
2997 </div>
2998
2999
3000 </div>
3001 <div id="Variable.filters" class="classattr">
3002 <div class="attr function"><a class="headerlink" href="#Variable.filters">#&nbsp;&nbsp</a>
3003
3004
3005 <span class="def">def</span>
3006 <span class="name">filters</span><span class="signature">(unknown)</span>:
3007 </div>
3008
3009
3010 <div class="docstring"><p><strong><code>filters(self)</code></strong></p>
3011
3012 <p>return dictionary containing HDF5 filter parameters.</p>
3013 </div>
3014
3015
3016 </div>
3017 <div id="Variable.endian" class="classattr">
3018 <div class="attr function"><a class="headerlink" href="#Variable.endian">#&nbsp;&nbsp</a>
3019
3020
3021 <span class="def">def</span>
3022 <span class="name">endian</span><span class="signature">(unknown)</span>:
3023 </div>
3024
3025
3026 <div class="docstring"><p><strong><code>endian(self)</code></strong></p>
3027
3028 <p>return endian-ness (<code>little,big,native</code>) of variable (as stored in HDF5 file).</p>
3029 </div>
3030
3031
3032 </div>
3033 <div id="Variable.chunking" class="classattr">
3034 <div class="attr function"><a class="headerlink" href="#Variable.chunking">#&nbsp;&nbsp</a>
3035
3036
3037 <span class="def">def</span>
3038 <span class="name">chunking</span><span class="signature">(unknown)</span>:
3039 </div>
3040
3041
3042 <div class="docstring"><p><strong><code>chunking(self)</code></strong></p>
3043
3044 <p>return variable chunking information. If the dataset is
3045 defined to be contiguous (and hence there is no chunking) the word 'contiguous'
3046 is returned. Otherwise, a sequence with the chunksize for
3047 each dimension is returned.</p>
3048 </div>
3049
3050
3051 </div>
3052 <div id="Variable.get_var_chunk_cache" class="classattr">
3053 <div class="attr function"><a class="headerlink" href="#Variable.get_var_chunk_cache">#&nbsp;&nbsp</a>
3054
3055
3056 <span class="def">def</span>
3057 <span class="name">get_var_chunk_cache</span><span class="signature">(unknown)</span>:
3058 </div>
3059
3060
3061 <div class="docstring"><p><strong><code>get_var_chunk_cache(self)</code></strong></p>
3062
3063 <p>return variable chunk cache information in a tuple (size,nelems,preemption).
3064 See netcdf C library documentation for <code>nc_get_var_chunk_cache</code> for
3065 details.</p>
3066 </div>
3067
3068
3069 </div>
3070 <div id="Variable.set_var_chunk_cache" class="classattr">
3071 <div class="attr function"><a class="headerlink" href="#Variable.set_var_chunk_cache">#&nbsp;&nbsp</a>
3072
3073
3074 <span class="def">def</span>
3075 <span class="name">set_var_chunk_cache</span><span class="signature">(unknown)</span>:
3076 </div>
3077
3078
3079 <div class="docstring"><p><strong><code>set_var_chunk_cache(self,size=None,nelems=None,preemption=None)</code></strong></p>
3080
3081 <p>change variable chunk cache settings.
3082 See netcdf C library documentation for <code>nc_set_var_chunk_cache</code> for
3083 details.</p>
3084 </div>
3085
3086
3087 </div>
3088 <div id="Variable.renameAttribute" class="classattr">
3089 <div class="attr function"><a class="headerlink" href="#Variable.renameAttribute">#&nbsp;&nbsp</a>
3090
3091
3092 <span class="def">def</span>
3093 <span class="name">renameAttribute</span><span class="signature">(unknown)</span>:
3094 </div>
3095
3096
3097 <div class="docstring"><p><strong><code>renameAttribute(self, oldname, newname)</code></strong></p>
3098
3099 <p>rename a <code><a href="#Variable">Variable</a></code> attribute named <code>oldname</code> to <code>newname</code>.</p>
3100 </div>
3101
3102
3103 </div>
3104 <div id="Variable.assignValue" class="classattr">
3105 <div class="attr function"><a class="headerlink" href="#Variable.assignValue">#&nbsp;&nbsp</a>
3106
3107
3108 <span class="def">def</span>
3109 <span class="name">assignValue</span><span class="signature">(unknown)</span>:
3110 </div>
3111
3112
3113 <div class="docstring"><p><strong><code>assignValue(self, val)</code></strong></p>
3114
3115 <p>assign a value to a scalar variable. Provided for compatibility with
3116 Scientific.IO.NetCDF, can also be done by assigning to an Ellipsis slice ([...]).</p>
3117 </div>
3118
3119
3120 </div>
3121 <div id="Variable.getValue" class="classattr">
3122 <div class="attr function"><a class="headerlink" href="#Variable.getValue">#&nbsp;&nbsp</a>
3123
3124
3125 <span class="def">def</span>
3126 <span class="name">getValue</span><span class="signature">(unknown)</span>:
3127 </div>
3128
3129
3130 <div class="docstring"><p><strong><code>getValue(self)</code></strong></p>
3131
3132 <p>get the value of a scalar variable. Provided for compatibility with
3133 Scientific.IO.NetCDF, can also be done by slicing with an Ellipsis ([...]).</p>
3134 </div>
3135
3136
3137 </div>
3138 <div id="Variable.set_auto_chartostring" class="classattr">
3139 <div class="attr function"><a class="headerlink" href="#Variable.set_auto_chartostring">#&nbsp;&nbsp</a>
3140
3141
3142 <span class="def">def</span>
3143 <span class="name">set_auto_chartostring</span><span class="signature">(unknown)</span>:
3144 </div>
3145
3146
3147 <div class="docstring"><p><strong><code>set_auto_chartostring(self,chartostring)</code></strong></p>
3148
3149 <p>turn on or off automatic conversion of character variable data to and
3150 from numpy fixed length string arrays when the <code>_Encoding</code> variable attribute
3151 is set.</p>
3152
3153 <p>If <code><a href="#Variable.chartostring">chartostring</a></code> is set to <code>True</code>, when data is read from a character variable
3154 (dtype = <code>S1</code>) that has an <code>_Encoding</code> attribute, it is converted to a numpy
3155 fixed length unicode string array (dtype = <code>UN</code>, where <code>N</code> is the length
3156 of the the rightmost dimension of the variable). The value of <code>_Encoding</code>
3157 is the unicode encoding that is used to decode the bytes into strings.</p>
3158
3159 <p>When numpy string data is written to a variable it is converted back to
3160 indiviual bytes, with the number of bytes in each string equalling the
3161 rightmost dimension of the variable.</p>
3162
3163 <p>The default value of <code><a href="#Variable.chartostring">chartostring</a></code> is <code>True</code>
3164 (automatic conversions are performed).</p>
3165 </div>
3166
3167
3168 </div>
3169 <div id="Variable.use_nc_get_vars" class="classattr">
3170 <div class="attr function"><a class="headerlink" href="#Variable.use_nc_get_vars">#&nbsp;&nbsp</a>
3171
3172
3173 <span class="def">def</span>
3174 <span class="name">use_nc_get_vars</span><span class="signature">(unknown)</span>:
3175 </div>
3176
3177
3178 <div class="docstring"><p><strong><code>use_nc_get_vars(self,_use_get_vars)</code></strong></p>
3179
3180 <p>enable the use of netcdf library routine <code>nc_get_vars</code>
3181 to retrieve strided variable slices. By default,
3182 <code>nc_get_vars</code> may not used by default (depending on the
3183 version of the netcdf-c library being used) since it may be
3184 slower than multiple calls to the unstrided read routine <code>nc_get_vara</code>.</p>
3185 </div>
3186
3187
3188 </div>
3189 <div id="Variable.set_auto_maskandscale" class="classattr">
3190 <div class="attr function"><a class="headerlink" href="#Variable.set_auto_maskandscale">#&nbsp;&nbsp</a>
3191
3192
3193 <span class="def">def</span>
3194 <span class="name">set_auto_maskandscale</span><span class="signature">(unknown)</span>:
3195 </div>
3196
3197
3198 <div class="docstring"><p><strong><code>set_auto_maskandscale(self,maskandscale)</code></strong></p>
3199
3200 <p>turn on or off automatic conversion of variable data to and
3201 from masked arrays, automatic packing/unpacking of variable
3202 data using <code>scale_factor</code> and <code>add_offset</code> attributes and
3203 automatic conversion of signed integer data to unsigned integer
3204 data if the <code>_Unsigned</code> attribute exists.</p>
3205
3206 <p>If <code>maskandscale</code> is set to <code>True</code>, when data is read from a variable
3207 it is converted to a masked array if any of the values are exactly
3208 equal to the either the netCDF _FillValue or the value specified by the
3209 missing_value variable attribute. The fill_value of the masked array
3210 is set to the missing_value attribute (if it exists), otherwise
3211 the netCDF _FillValue attribute (which has a default value
3212 for each data type). If the variable has no missing_value attribute, the
3213 _FillValue is used instead. If the variable has valid_min/valid_max and
3214 missing_value attributes, data outside the specified range will be masked.
3215 When data is written to a variable, the masked
3216 array is converted back to a regular numpy array by replacing all the
3217 masked values by the missing_value attribute of the variable (if it
3218 exists). If the variable has no missing_value attribute, the _FillValue
3219 is used instead. </p>
3220
3221 <p>If <code>maskandscale</code> is set to <code>True</code>, and the variable has a
3222 <code>scale_factor</code> or an <code>add_offset</code> attribute, then data read
3223 from that variable is unpacked using::</p>
3224
3225 <pre><code>data = self.scale_factor*data + self.add_offset
3226 </code></pre>
3227
3228 <p>When data is written to a variable it is packed using::</p>
3229
3230 <pre><code>data = (data - self.add_offset)/self.scale_factor
3231 </code></pre>
3232
3233 <p>If either scale_factor is present, but add_offset is missing, add_offset
3234 is assumed zero. If add_offset is present, but scale_factor is missing,
3235 scale_factor is assumed to be one.
3236 For more information on how <code>scale_factor</code> and <code>add_offset</code> can be
3237 used to provide simple compression, see the
3238 <a href="http://www.esrl.noaa.gov/psl/data/gridded/conventions/cdc_netcdf_standard.shtml">PSL metadata conventions</a>.</p>
3239
3240 <p>In addition, if <code>maskandscale</code> is set to <code>True</code>, and if the variable has an
3241 attribute <code>_Unsigned</code> set, and the variable has a signed integer data type,
3242 a view to the data is returned with the corresponding unsigned integer data type.
3243 This convention is used by the netcdf-java library to save unsigned integer
3244 data in <code>NETCDF3</code> or <code>NETCDF4_CLASSIC</code> files (since the <code>NETCDF3</code>
3245 data model does not have unsigned integer data types).</p>
3246
3247 <p>The default value of <code>maskandscale</code> is <code>True</code>
3248 (automatic conversions are performed).</p>
3249 </div>
3250
3251
3252 </div>
3253 <div id="Variable.set_auto_scale" class="classattr">
3254 <div class="attr function"><a class="headerlink" href="#Variable.set_auto_scale">#&nbsp;&nbsp</a>
3255
3256
3257 <span class="def">def</span>
3258 <span class="name">set_auto_scale</span><span class="signature">(unknown)</span>:
3259 </div>
3260
3261
3262 <div class="docstring"><p><strong><code>set_auto_scale(self,scale)</code></strong></p>
3263
3264 <p>turn on or off automatic packing/unpacking of variable
3265 data using <code>scale_factor</code> and <code>add_offset</code> attributes.
3266 Also turns on and off automatic conversion of signed integer data
3267 to unsigned integer data if the variable has an <code>_Unsigned</code>
3268 attribute.</p>
3269
3270 <p>If <code><a href="#Variable.scale">scale</a></code> is set to <code>True</code>, and the variable has a
3271 <code>scale_factor</code> or an <code>add_offset</code> attribute, then data read
3272 from that variable is unpacked using::</p>
3273
3274 <pre><code>data = self.scale_factor*data + self.add_offset
3275 </code></pre>
3276
3277 <p>When data is written to a variable it is packed using::</p>
3278
3279 <pre><code>data = (data - self.add_offset)/self.scale_factor
3280 </code></pre>
3281
3282 <p>If either scale_factor is present, but add_offset is missing, add_offset
3283 is assumed zero. If add_offset is present, but scale_factor is missing,
3284 scale_factor is assumed to be one.
3285 For more information on how <code>scale_factor</code> and <code>add_offset</code> can be
3286 used to provide simple compression, see the
3287 <a href="http://www.esrl.noaa.gov/psl/data/gridded/conventions/cdc_netcdf_standard.shtml">PSL metadata conventions</a>.</p>
3288
3289 <p>In addition, if <code><a href="#Variable.scale">scale</a></code> is set to <code>True</code>, and if the variable has an
3290 attribute <code>_Unsigned</code> set, and the variable has a signed integer data type,
3291 a view to the data is returned with the corresponding unsigned integer datatype.
3292 This convention is used by the netcdf-java library to save unsigned integer
3293 data in <code>NETCDF3</code> or <code>NETCDF4_CLASSIC</code> files (since the <code>NETCDF3</code>
3294 data model does not have unsigned integer data types).</p>
3295
3296 <p>The default value of <code><a href="#Variable.scale">scale</a></code> is <code>True</code>
3297 (automatic conversions are performed).</p>
3298 </div>
3299
3300
3301 </div>
3302 <div id="Variable.set_auto_mask" class="classattr">
3303 <div class="attr function"><a class="headerlink" href="#Variable.set_auto_mask">#&nbsp;&nbsp</a>
3304
3305
3306 <span class="def">def</span>
3307 <span class="name">set_auto_mask</span><span class="signature">(unknown)</span>:
3308 </div>
3309
3310
3311 <div class="docstring"><p><strong><code>set_auto_mask(self,mask)</code></strong></p>
3312
3313 <p>turn on or off automatic conversion of variable data to and
3314 from masked arrays .</p>
3315
3316 <p>If <code><a href="#Variable.mask">mask</a></code> is set to <code>True</code>, when data is read from a variable
3317 it is converted to a masked array if any of the values are exactly
3318 equal to the either the netCDF _FillValue or the value specified by the
3319 missing_value variable attribute. The fill_value of the masked array
3320 is set to the missing_value attribute (if it exists), otherwise
3321 the netCDF _FillValue attribute (which has a default value
3322 for each data type). If the variable has no missing_value attribute, the
3323 _FillValue is used instead. If the variable has valid_min/valid_max and
3324 missing_value attributes, data outside the specified range will be masked.
3325 When data is written to a variable, the masked
3326 array is converted back to a regular numpy array by replacing all the
3327 masked values by the missing_value attribute of the variable (if it
3328 exists). If the variable has no missing_value attribute, the _FillValue
3329 is used instead. </p>
3330
3331 <p>The default value of <code><a href="#Variable.mask">mask</a></code> is <code>True</code>
3332 (automatic conversions are performed).</p>
3333 </div>
3334
3335
3336 </div>
3337 <div id="Variable.set_always_mask" class="classattr">
3338 <div class="attr function"><a class="headerlink" href="#Variable.set_always_mask">#&nbsp;&nbsp</a>
3339
3340
3341 <span class="def">def</span>
3342 <span class="name">set_always_mask</span><span class="signature">(unknown)</span>:
3343 </div>
3344
3345
3346 <div class="docstring"><p><strong><code>set_always_mask(self,always_mask)</code></strong></p>
3347
3348 <p>turn on or off conversion of data without missing values to regular
3349 numpy arrays.</p>
3350
3351 <p><code><a href="#Variable.always_mask">always_mask</a></code> is a Boolean determining if automatic conversion of
3352 masked arrays with no missing values to regular numpy arrays shall be
3353 applied. Default is True. Set to False to restore the default behaviour
3354 in versions prior to 1.4.1 (numpy array returned unless missing values are present,
3355 otherwise masked array returned).</p>
3356 </div>
3357
3358
3359 </div>
3360 <div id="Variable.set_ncstring_attrs" class="classattr">
3361 <div class="attr function"><a class="headerlink" href="#Variable.set_ncstring_attrs">#&nbsp;&nbsp</a>
3362
3363
3364 <span class="def">def</span>
3365 <span class="name">set_ncstring_attrs</span><span class="signature">(unknown)</span>:
3366 </div>
3367
3368
3369 <div class="docstring"><p><strong><code>set_always_mask(self,ncstring_attrs)</code></strong></p>
3370
3371 <p>turn on or off creating NC_STRING string attributes.</p>
3372
3373 <p>If <code>ncstring_attrs</code> is set to <code>True</code> then text attributes will be variable-length
3374 NC_STRINGs.</p>
3375
3376 <p>The default value of <code>ncstring_attrs</code> is <code>False</code> (writing ascii text attributes as
3377 NC_CHAR).</p>
3378 </div>
3379
3380
3381 </div>
3382 <div id="Variable.set_collective" class="classattr">
3383 <div class="attr function"><a class="headerlink" href="#Variable.set_collective">#&nbsp;&nbsp</a>
3384
3385
3386 <span class="def">def</span>
3387 <span class="name">set_collective</span><span class="signature">(unknown)</span>:
3388 </div>
3389
3390
3391 <div class="docstring"><p><strong><code>set_collective(self,True_or_False)</code></strong></p>
3392
3393 <p>turn on or off collective parallel IO access. Ignored if file is not
3394 open for parallel access.</p>
3395 </div>
3396
3397
3398 </div>
3399 <div id="Variable.get_dims" class="classattr">
3400 <div class="attr function"><a class="headerlink" href="#Variable.get_dims">#&nbsp;&nbsp</a>
3401
3402
3403 <span class="def">def</span>
3404 <span class="name">get_dims</span><span class="signature">(unknown)</span>:
3405 </div>
3406
3407
3408 <div class="docstring"><p><strong><code>get_dims(self)</code></strong></p>
3409
3410 <p>return a tuple of <code><a href="#Dimension">Dimension</a></code> instances associated with this
3411 <code><a href="#Variable">Variable</a></code>.</p>
3412 </div>
3413
3414
3415 </div>
3416 <div id="Variable.name" class="classattr">
3417 <div class="attr variable"><a class="headerlink" href="#Variable.name">#&nbsp;&nbsp</a>
3418
3419 <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>
3420 </div>
3421
3422 <div class="docstring"><p>string name of Variable instance</p>
3423 </div>
3424
3425
3426 </div>
3427 <div id="Variable.datatype" class="classattr">
3428 <div class="attr variable"><a class="headerlink" href="#Variable.datatype">#&nbsp;&nbsp</a>
3429
3430 <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>
3431 </div>
3432
3433 <div class="docstring"><p>numpy data type (for primitive data types) or
3434 VLType/CompoundType/EnumType instance
3435 (for compound, vlen or enum data types)</p>
3436 </div>
3437
3438
3439 </div>
3440 <div id="Variable.shape" class="classattr">
3441 <div class="attr variable"><a class="headerlink" href="#Variable.shape">#&nbsp;&nbsp</a>
3442
3443 <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>
3444 </div>
3445
3446 <div class="docstring"><p>find current sizes of all variable dimensions</p>
3447 </div>
3448
3449
3450 </div>
3451 <div id="Variable.size" class="classattr">
3452 <div class="attr variable"><a class="headerlink" href="#Variable.size">#&nbsp;&nbsp</a>
3453
3454 <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>
3455 </div>
3456
3457 <div class="docstring"><p>Return the number of stored elements.</p>
3458 </div>
3459
3460
3461 </div>
3462 <div id="Variable.dimensions" class="classattr">
3463 <div class="attr variable"><a class="headerlink" href="#Variable.dimensions">#&nbsp;&nbsp</a>
3464
3465 <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>
3466 </div>
3467
3468 <div class="docstring"><p>get variables's dimension names</p>
3469 </div>
3470
3471
3472 </div>
3473 <div id="Variable.ndim" class="classattr">
3474 <div class="attr variable"><a class="headerlink" href="#Variable.ndim">#&nbsp;&nbsp</a>
3475
3476 <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>
3477 </div>
3478
3479
3480
3481 </div>
3482 <div id="Variable.dtype" class="classattr">
3483 <div class="attr variable"><a class="headerlink" href="#Variable.dtype">#&nbsp;&nbsp</a>
3484
3485 <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>
3486 </div>
3487
3488
3489
3490 </div>
3491 <div id="Variable.mask" class="classattr">
3492 <div class="attr variable"><a class="headerlink" href="#Variable.mask">#&nbsp;&nbsp</a>
3493
3494 <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>
3495 </div>
3496
3497
3498
3499 </div>
3500 <div id="Variable.scale" class="classattr">
3501 <div class="attr variable"><a class="headerlink" href="#Variable.scale">#&nbsp;&nbsp</a>
3502
3503 <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>
3504 </div>
3505
3506
3507
3508 </div>
3509 <div id="Variable.always_mask" class="classattr">
3510 <div class="attr variable"><a class="headerlink" href="#Variable.always_mask">#&nbsp;&nbsp</a>
3511
3512 <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>
3513 </div>
3514
3515
3516
3517 </div>
3518 <div id="Variable.chartostring" class="classattr">
3519 <div class="attr variable"><a class="headerlink" href="#Variable.chartostring">#&nbsp;&nbsp</a>
3520
3521 <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>
3522 </div>
3523
3524
3525
3526 </div>
3527 </section>
3528 <section id="Dimension">
3529 <div class="attr class">
3530 <a class="headerlink" href="#Dimension">#&nbsp;&nbsp</a>
3531
3532
3533 <span class="def">class</span>
3534 <span class="name">Dimension</span>:
3535 </div>
3536
3537
3538 <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>.
3539 See <code><a href="#Dimension.__init__">Dimension.__init__</a></code> for more details.</p>
3540
3541 <p>The current maximum size of a <code><a href="#Dimension">Dimension</a></code> instance can be obtained by
3542 calling the python <code>len</code> function on the <code><a href="#Dimension">Dimension</a></code> instance. The
3543 <code><a href="#Dimension.isunlimited">Dimension.isunlimited</a></code> method of a <code><a href="#Dimension">Dimension</a></code> instance can be used to
3544 determine if the dimension is unlimited.</p>
3545
3546 <p>Read-only class variables:</p>
3547
3548 <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
3549 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code>.</p>
3550
3551 <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
3552 <code><a href="#Dimension">Dimension</a></code> instance).</p>
3553 </div>
3554
3555
3556 <div id="Dimension.__init__" class="classattr">
3557 <div class="attr function"><a class="headerlink" href="#Dimension.__init__">#&nbsp;&nbsp</a>
3558
3559
3560 <span class="name">Dimension</span><span class="signature">()</span>
3561 </div>
3562
3563
3564 <div class="docstring"><p><strong><code>__init__(self, group, name, size=None)</code></strong></p>
3565
3566 <p><code><a href="#Dimension">Dimension</a></code> constructor.</p>
3567
3568 <p><strong><code><a href="#Dimension.group">group</a></code></strong>: <code><a href="#Group">Group</a></code> instance to associate with dimension.</p>
3569
3570 <p><strong><code><a href="#Dimension.name">name</a></code></strong>: Name of the dimension.</p>
3571
3572 <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>
3573
3574 <p><strong><em>Note</em></strong>: <code><a href="#Dimension">Dimension</a></code> instances should be created using the
3575 <code><a href="#Dataset.createDimension">Dataset.createDimension</a></code> method of a <code><a href="#Group">Group</a></code> or
3576 <code><a href="#Dataset">Dataset</a></code> instance, not using <code><a href="#Dimension.__init__">Dimension.__init__</a></code> directly.</p>
3577 </div>
3578
3579
3580 </div>
3581 <div id="Dimension.group" class="classattr">
3582 <div class="attr function"><a class="headerlink" href="#Dimension.group">#&nbsp;&nbsp</a>
3583
3584
3585 <span class="def">def</span>
3586 <span class="name">group</span><span class="signature">(unknown)</span>:
3587 </div>
3588
3589
3590 <div class="docstring"><p><strong><code>group(self)</code></strong></p>
3591
3592 <p>return the group that this <code><a href="#Dimension">Dimension</a></code> is a member of.</p>
3593 </div>
3594
3595
3596 </div>
3597 <div id="Dimension.isunlimited" class="classattr">
3598 <div class="attr function"><a class="headerlink" href="#Dimension.isunlimited">#&nbsp;&nbsp</a>
3599
3600
3601 <span class="def">def</span>
3602 <span class="name">isunlimited</span><span class="signature">(unknown)</span>:
3603 </div>
3604
3605
3606 <div class="docstring"><p><strong><code>isunlimited(self)</code></strong></p>
3607
3608 <p>returns <code>True</code> if the <code><a href="#Dimension">Dimension</a></code> instance is unlimited, <code>False</code> otherwise.</p>
3609 </div>
3610
3611
3612 </div>
3613 <div id="Dimension.name" class="classattr">
3614 <div class="attr variable"><a class="headerlink" href="#Dimension.name">#&nbsp;&nbsp</a>
3615
3616 <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>
3617 </div>
3618
3619 <div class="docstring"><p>string name of Dimension instance</p>
3620 </div>
3621
3622
3623 </div>
3624 <div id="Dimension.size" class="classattr">
3625 <div class="attr variable"><a class="headerlink" href="#Dimension.size">#&nbsp;&nbsp</a>
3626
3627 <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>
3628 </div>
3629
3630 <div class="docstring"><p>current size of Dimension (calls <code>len</code> on Dimension instance)</p>
3631 </div>
3632
27013633
27023634 </div>
27033635 </section>
27073639
27083640
27093641 <span class="def">class</span>
2710 <span class="name">Group</span>(<span class="base"><a href="#Dataset">Dataset</a></span>):
3642 <span class="name">Group</span>(<span class="base"><a href="#Dataset">netCDF4.Dataset</a></span>):
27113643 </div>
27123644
27133645
27143646 <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>
3647 analogous to directories in a unix filesystem. Each <code><a href="#Group">Group</a></code> behaves like
3648 a <code><a href="#Dataset">Dataset</a></code> within a Dataset, and can contain it's own variables,
3649 dimensions and attributes (and other Groups). See <code><a href="#Group.__init__">Group.__init__</a></code>
27183650 for more details.</p>
27193651
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>
3652 <p><code><a href="#Group">Group</a></code> inherits from <code><a href="#Dataset">Dataset</a></code>, so all the
3653 <code><a href="#Dataset">Dataset</a></code> class methods and variables are available
3654 to a <code><a href="#Group">Group</a></code> instance (except the <code><a href="#Group.close">close</a></code> method).</p>
27233655
27243656 <p>Additional read-only class variables:</p>
27253657
2726 <p><strong><code>name</code></strong>: String describing the group name.</p>
3658 <p><strong><code><a href="#Group.name">name</a></code></strong>: String describing the group name.</p>
27273659 </div>
27283660
27293661
27313663 <div class="attr function"><a class="headerlink" href="#Group.__init__">#&nbsp;&nbsp</a>
27323664
27333665
2734 <span class="name">Group</span><span class="signature">(unknown)</span> </div>
3666 <span class="name">Group</span><span class="signature">()</span>
3667 </div>
27353668
27363669
27373670 <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>
3671 <code><a href="#Group">Group</a></code> constructor.</p>
3672
3673 <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
3674 in the root group, use a <code><a href="#Dataset">Dataset</a></code> instance.</p>
3675
3676 <p><strong><code><a href="#Group.name">name</a></code></strong>: - Name of the group.</p>
3677
3678 <p><strong><em>Note</em></strong>: <code><a href="#Group">Group</a></code> instances should be created using the
3679 <code><a href="#Dataset.createGroup">Dataset.createGroup</a></code> method of a <code><a href="#Dataset">Dataset</a></code> instance, or
3680 another <code><a href="#Group">Group</a></code> instance, not using this class directly.</p>
27483681 </div>
27493682
27503683
27603693
27613694 <div class="docstring"><p><strong><code>close(self)</code></strong></p>
27623695
2763 <p>overrides <a href="#Dataset">Dataset</a> close method which does not apply to <a href="#Group">Group</a>
3696 <p>overrides <code><a href="#Dataset">Dataset</a></code> close method which does not apply to <code><a href="#Group">Group</a></code>
27643697 instances, raises IOError.</p>
27653698 </div>
27663699
27693702 <div class="inherited">
27703703 <h5>Inherited Members</h5>
27713704 <dl>
2772 <div><dt><a href="#Dataset">netCDF4._netCDF4.Dataset</a></dt>
3705 <div><dt><a href="#Dataset">Dataset</a></dt>
27733706 <dd id="Group.filepath" class="function"><a href="#Dataset.filepath">filepath</a></dd>
27743707 <dd id="Group.isopen" class="function"><a href="#Dataset.isopen">isopen</a></dd>
27753708 <dd id="Group.sync" class="function"><a href="#Dataset.sync">sync</a></dd>
28183751 </dl>
28193752 </div>
28203753 </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>
40933754 <section id="MFDataset">
40943755 <div class="attr class">
40953756 <a class="headerlink" href="#MFDataset">#&nbsp;&nbsp</a>
40963757
40973758
40983759 <span class="def">class</span>
4099 <span class="name">MFDataset</span>(<span class="base"><a href="#Dataset">Dataset</a></span>):
3760 <span class="name">MFDataset</span>(<span class="base"><a href="#Dataset">netCDF4.Dataset</a></span>):
41003761 </div>
41013762
41023763
41073768
41083769 <p>Adapted from <a href="http://pysclint.sourceforge.net/pycdf">pycdf</a> by Andre Gosselin.</p>
41093770
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>
3771 <p>Example usage (See <code><a href="#MFDataset.__init__">MFDataset.__init__</a></code> for more details):</p>
41113772
41123773 <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>
41133774 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># create a series of netCDF files with a variable sharing</span>
41333794 <div class="attr function"><a class="headerlink" href="#MFDataset.__init__">#&nbsp;&nbsp</a>
41343795
41353796
4136 <span class="name">MFDataset</span><span class="signature">(files, check=False, aggdim=None, exclude=[], master_file=None)</span> </div>
3797 <span class="name">MFDataset</span><span class="signature">(files, check=False, aggdim=None, exclude=[], master_file=None)</span>
3798 </div>
41373799
41383800
41393801 <div class="docstring"><p><strong><code>__init__(self, files, check=False, aggdim=None, exclude=[],
42073869 <div class="inherited">
42083870 <h5>Inherited Members</h5>
42093871 <dl>
4210 <div><dt><a href="#Dataset">netCDF4._netCDF4.Dataset</a></dt>
3872 <div><dt><a href="#Dataset">Dataset</a></dt>
42113873 <dd id="MFDataset.filepath" class="function"><a href="#Dataset.filepath">filepath</a></dd>
42123874 <dd id="MFDataset.isopen" class="function"><a href="#Dataset.isopen">isopen</a></dd>
42133875 <dd id="MFDataset.sync" class="function"><a href="#Dataset.sync">sync</a></dd>
42613923
42623924
42633925 <span class="def">class</span>
4264 <span class="name">MFTime</span>(<span class="base"><a href="#_Variable">_Variable</a></span>):
3926 <span class="name">MFTime</span>(<span class="base">netCDF4._netCDF4._Variable</span>):
42653927 </div>
42663928
42673929
42683930 <div class="docstring"><p>Class providing an interface to a MFDataset time Variable by imposing a unique common
42693931 time unit and/or calendar to all files.</p>
42703932
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>
3933 <p>Example usage (See <code><a href="#MFTime.__init__">MFTime.__init__</a></code> for more details):</p>
3934
3935 <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>
42743936 <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>
42753937 <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>
42763938 <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>
42813943 <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>
42823944 <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>
42833945 <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>
3946 <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>
3947 <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>
42863948 <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>
42873949 <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>
42883950 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># Read the two files in at once, in one Dataset.</span>
43033965 <div class="attr function"><a class="headerlink" href="#MFTime.__init__">#&nbsp;&nbsp</a>
43043966
43053967
4306 <span class="name">MFTime</span><span class="signature">(time, units=None, calendar=None)</span> </div>
3968 <span class="name">MFTime</span><span class="signature">(time, units=None, calendar=None)</span>
3969 </div>
43073970
43083971
43093972 <div class="docstring"><p><strong><code>__init__(self, time, units=None, calendar=None)</code></strong></p>
43113974 <p>Create a time Variable with units consistent across a multifile
43123975 dataset.</p>
43133976
4314 <p><strong><code>time</code></strong>: Time variable from a <a href="#MFDataset">MFDataset</a>.</p>
3977 <p><strong><code>time</code></strong>: Time variable from a <code><a href="#MFDataset">MFDataset</a></code>.</p>
43153978
43163979 <p><strong><code>units</code></strong>: Time units, for example, <code>'days since 1979-01-01'</code>. If <code>None</code>,
43173980 use the units from the master variable.</p>
43273990 <div class="inherited">
43283991 <h5>Inherited Members</h5>
43293992 <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>
3993 <div><dt>netCDF4._netCDF4._Variable</dt>
3994 <dd id="MFTime.typecode" class="function">typecode</dd>
3995 <dd id="MFTime.ncattrs" class="function">ncattrs</dd>
3996 <dd id="MFTime.set_auto_chartostring" class="function">set_auto_chartostring</dd>
3997 <dd id="MFTime.set_auto_maskandscale" class="function">set_auto_maskandscale</dd>
3998 <dd id="MFTime.set_auto_mask" class="function">set_auto_mask</dd>
3999 <dd id="MFTime.set_auto_scale" class="function">set_auto_scale</dd>
4000 <dd id="MFTime.set_always_mask" class="function">set_always_mask</dd>
43384001
43394002 </div>
43404003 </dl>
43414004 </div>
4005 </section>
4006 <section id="CompoundType">
4007 <div class="attr class">
4008 <a class="headerlink" href="#CompoundType">#&nbsp;&nbsp</a>
4009
4010
4011 <span class="def">class</span>
4012 <span class="name">CompoundType</span>:
4013 </div>
4014
4015
4016 <div class="docstring"><p>A <code><a href="#CompoundType">CompoundType</a></code> instance is used to describe a compound data
4017 type, and can be passed to the the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of
4018 a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance.
4019 Compound data types map to numpy structured arrays.
4020 See <code><a href="#CompoundType.__init__">CompoundType.__init__</a></code> for more details.</p>
4021
4022 <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
4023 the user.</p>
4024 </div>
4025
4026
4027 <div id="CompoundType.__init__" class="classattr">
4028 <div class="attr function"><a class="headerlink" href="#CompoundType.__init__">#&nbsp;&nbsp</a>
4029
4030
4031 <span class="name">CompoundType</span><span class="signature">()</span>
4032 </div>
4033
4034
4035 <div class="docstring"><p><strong><em><code>__init__(group, datatype, datatype_name)</code></em></strong></p>
4036
4037 <p>CompoundType constructor.</p>
4038
4039 <p><strong><code>group</code></strong>: <code><a href="#Group">Group</a></code> instance to associate with the compound datatype.</p>
4040
4041 <p><strong><code>datatype</code></strong>: A numpy dtype object describing a structured (a.k.a record)
4042 array. Can be composed of homogeneous numeric or character data types, or
4043 other structured array data types.</p>
4044
4045 <p><strong><code>datatype_name</code></strong>: a Python string containing a description of the
4046 compound data type.</p>
4047
4048 <p><strong><em>Note 1</em></strong>: When creating nested compound data types,
4049 the inner compound data types must already be associated with CompoundType
4050 instances (so create CompoundType instances for the innermost structures
4051 first).</p>
4052
4053 <p><strong><em>Note 2</em></strong>: <code><a href="#CompoundType">CompoundType</a></code> instances should be created using the
4054 <code><a href="#Dataset.createCompoundType">Dataset.createCompoundType</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or
4055 <code><a href="#Group">Group</a></code> instance, not using this class directly.</p>
4056 </div>
4057
4058
4059 </div>
4060 <div id="CompoundType.dtype" class="classattr">
4061 <div class="attr variable"><a class="headerlink" href="#CompoundType.dtype">#&nbsp;&nbsp</a>
4062
4063 <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>
4064 </div>
4065
4066
4067
4068 </div>
4069 <div id="CompoundType.dtype_view" class="classattr">
4070 <div class="attr variable"><a class="headerlink" href="#CompoundType.dtype_view">#&nbsp;&nbsp</a>
4071
4072 <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>
4073 </div>
4074
4075
4076
4077 </div>
4078 <div id="CompoundType.name" class="classattr">
4079 <div class="attr variable"><a class="headerlink" href="#CompoundType.name">#&nbsp;&nbsp</a>
4080
4081 <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>
4082 </div>
4083
4084
4085
4086 </div>
4087 </section>
4088 <section id="VLType">
4089 <div class="attr class">
4090 <a class="headerlink" href="#VLType">#&nbsp;&nbsp</a>
4091
4092
4093 <span class="def">class</span>
4094 <span class="name">VLType</span>:
4095 </div>
4096
4097
4098 <div class="docstring"><p>A <code><a href="#VLType">VLType</a></code> instance is used to describe a variable length (VLEN) data
4099 type, and can be passed to the the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of
4100 a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance. See
4101 <code><a href="#VLType.__init__">VLType.__init__</a></code> for more details.</p>
4102
4103 <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
4104 the user.</p>
4105 </div>
4106
4107
4108 <div id="VLType.__init__" class="classattr">
4109 <div class="attr function"><a class="headerlink" href="#VLType.__init__">#&nbsp;&nbsp</a>
4110
4111
4112 <span class="name">VLType</span><span class="signature">()</span>
4113 </div>
4114
4115
4116 <div class="docstring"><p><strong><code>__init__(group, datatype, datatype_name)</code></strong></p>
4117
4118 <p>VLType constructor.</p>
4119
4120 <p><strong><code>group</code></strong>: <code><a href="#Group">Group</a></code> instance to associate with the VLEN datatype.</p>
4121
4122 <p><strong><code>datatype</code></strong>: An numpy dtype object describing the component type for the
4123 variable length array.</p>
4124
4125 <p><strong><code>datatype_name</code></strong>: a Python string containing a description of the
4126 VLEN data type.</p>
4127
4128 <p><strong><em><code>Note</code></em></strong>: <code><a href="#VLType">VLType</a></code> instances should be created using the
4129 <code><a href="#Dataset.createVLType">Dataset.createVLType</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or
4130 <code><a href="#Group">Group</a></code> instance, not using this class directly.</p>
4131 </div>
4132
4133
4134 </div>
4135 <div id="VLType.dtype" class="classattr">
4136 <div class="attr variable"><a class="headerlink" href="#VLType.dtype">#&nbsp;&nbsp</a>
4137
4138 <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>
4139 </div>
4140
4141
4142
4143 </div>
4144 <div id="VLType.name" class="classattr">
4145 <div class="attr variable"><a class="headerlink" href="#VLType.name">#&nbsp;&nbsp</a>
4146
4147 <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>
4148 </div>
4149
4150
4151
4152 </div>
4153 </section>
4154 <section id="date2num">
4155 <div class="attr function"><a class="headerlink" href="#date2num">#&nbsp;&nbsp</a>
4156
4157
4158 <span class="def">def</span>
4159 <span class="name">date2num</span><span class="signature">(unknown)</span>:
4160 </div>
4161
4162
4163 <div class="docstring"><p>date2num(dates, units, calendar=None, has_year_zero=None)</p>
4164
4165 <p>Return numeric time values given datetime objects. The units
4166 of the numeric time values are described by the <strong>units</strong> argument
4167 and the <strong>calendar</strong> keyword. The datetime objects must
4168 be in UTC with no time-zone offset. If there is a
4169 time-zone offset in <strong>units</strong>, it will be applied to the
4170 returned numeric values.</p>
4171
4172 <p><strong>dates</strong>: A datetime object or a sequence of datetime objects.
4173 The datetime objects should not include a time-zone offset. They
4174 can be either native python datetime instances (which use
4175 the proleptic gregorian calendar) or cftime.datetime instances.</p>
4176
4177 <p><strong>units</strong>: a string of the form <strong><time units> since <reference time></strong>
4178 describing the time units. <strong><time units></strong> can be days, hours, minutes,
4179 seconds, milliseconds or microseconds. <strong><reference time></strong> is the time
4180 origin. <strong>months_since</strong> is allowed <em>only</em> for the <strong>360_day</strong> calendar.</p>
4181
4182 <p><strong>calendar</strong>: describes the calendar to be used in the time calculations.
4183 All the values currently defined in the
4184 <code>CF metadata convention &lt;http://cfconventions.org/cf-conventions/cf-conventions#calendar&gt;</code>__ are supported.
4185 Valid calendars <strong>'standard', 'gregorian', 'proleptic_gregorian'
4186 'noleap', '365_day', '360_day', 'julian', 'all_leap', '366_day'</strong>.
4187 Default is <code>None</code> which means the calendar associated with the first
4188 input datetime instance will be used.</p>
4189
4190 <p><strong>has_year_zero</strong>: If set to True, astronomical year numbering
4191 is used and the year zero exists. If set to False for real-world
4192 calendars, then historical year numbering is used and the year 1 is
4193 preceded by year -1 and no year zero exists.
4194 The defaults are set to conform with
4195 CF version 1.9 conventions (False for 'julian', 'gregorian'/'standard', True
4196 for 'proleptic_gregorian' (ISO 8601) and True for the idealized
4197 calendars 'noleap'/'365_day', '360_day', 366_day'/'all_leap')
4198 The defaults can only be over-ridden for the real-world calendars,
4199 for the the idealized calendars the year zero
4200 always exists and the has_year_zero kwarg is ignored.
4201 This kwarg is not needed to define calendar systems allowed by CF
4202 (the calendar-specific defaults do this).</p>
4203
4204 <p>returns a numeric time value, or an array of numeric time values
4205 with approximately 1 microsecond accuracy.</p>
4206 </div>
4207
4208
4209 </section>
4210 <section id="num2date">
4211 <div class="attr function"><a class="headerlink" href="#num2date">#&nbsp;&nbsp</a>
4212
4213
4214 <span class="def">def</span>
4215 <span class="name">num2date</span><span class="signature">(unknown)</span>:
4216 </div>
4217
4218
4219 <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>
4220
4221 <p>Return datetime objects given numeric time values. The units
4222 of the numeric time values are described by the <strong>units</strong> argument
4223 and the <strong>calendar</strong> keyword. The returned datetime objects represent
4224 UTC with no time-zone offset, even if the specified
4225 <strong>units</strong> contain a time-zone offset.</p>
4226
4227 <p><strong>times</strong>: numeric time values.</p>
4228
4229 <p><strong>units</strong>: a string of the form <strong><time units> since <reference time></strong>
4230 describing the time units. <strong><time units></strong> can be days, hours, minutes,
4231 seconds, milliseconds or microseconds. <strong><reference time></strong> is the time
4232 origin. <strong>months_since</strong> is allowed <em>only</em> for the <strong>360_day</strong> calendar.</p>
4233
4234 <p><strong>calendar</strong>: describes the calendar used in the time calculations.
4235 All the values currently defined in the
4236 <code>CF metadata convention &lt;http://cfconventions.org/cf-conventions/cf-conventions#calendar&gt;</code>__ are supported.
4237 Valid calendars <strong>'standard', 'gregorian', 'proleptic_gregorian'
4238 'noleap', '365_day', '360_day', 'julian', 'all_leap', '366_day'</strong>.
4239 Default is <strong>'standard'</strong>, which is a mixed Julian/Gregorian calendar.</p>
4240
4241 <p><strong>only_use_cftime_datetimes</strong>: if False, python datetime.datetime
4242 objects are returned from num2date where possible; if True dates which
4243 subclass cftime.datetime are returned for all calendars. Default <strong>True</strong>.</p>
4244
4245 <p><strong>only_use_python_datetimes</strong>: always return python datetime.datetime
4246 objects and raise an error if this is not possible. Ignored unless
4247 <strong>only_use_cftime_datetimes=False</strong>. Default <strong>False</strong>.</p>
4248
4249 <p><strong>has_year_zero</strong>: if set to True, astronomical year numbering
4250 is used and the year zero exists. If set to False for real-world
4251 calendars, then historical year numbering is used and the year 1 is
4252 preceded by year -1 and no year zero exists.
4253 The defaults are set to conform with
4254 CF version 1.9 conventions (False for 'julian', 'gregorian'/'standard', True
4255 for 'proleptic_gregorian' (ISO 8601) and True for the idealized
4256 calendars 'noleap'/'365_day', '360_day', 366_day'/'all_leap')
4257 The defaults can only be over-ridden for the real-world calendars,
4258 for the the idealized calendars the year zero
4259 always exists and the has_year_zero kwarg is ignored.
4260 This kwarg is not needed to define calendar systems allowed by CF
4261 (the calendar-specific defaults do this).</p>
4262
4263 <p>returns a datetime instance, or an array of datetime instances with
4264 microsecond accuracy, if possible.</p>
4265
4266 <p><strong><em>Note</em></strong>: If only_use_cftime_datetimes=False and
4267 use_only_python_datetimes=False, the datetime instances
4268 returned are 'real' python datetime
4269 objects if <strong>calendar='proleptic_gregorian'</strong>, or
4270 <strong>calendar='standard'</strong> or <strong>'gregorian'</strong>
4271 and the date is after the breakpoint between the Julian and
4272 Gregorian calendars (1582-10-15). Otherwise, they are ctime.datetime
4273 objects which support some but not all the methods of native python
4274 datetime objects. The datetime instances
4275 do not contain a time-zone offset, even if the specified <strong>units</strong>
4276 contains one.</p>
4277 </div>
4278
4279
4280 </section>
4281 <section id="date2index">
4282 <div class="attr function"><a class="headerlink" href="#date2index">#&nbsp;&nbsp</a>
4283
4284
4285 <span class="def">def</span>
4286 <span class="name">date2index</span><span class="signature">(unknown)</span>:
4287 </div>
4288
4289
4290 <div class="docstring"><p>date2index(dates, nctime, calendar=None, select=u'exact', has_year_zero=None)</p>
4291
4292 <p>Return indices of a netCDF time variable corresponding to the given dates.</p>
4293
4294 <p><strong>dates</strong>: A datetime object or a sequence of datetime objects.
4295 The datetime objects should not include a time-zone offset.</p>
4296
4297 <p><strong>nctime</strong>: A netCDF time variable object. The nctime object must have a
4298 <strong>units</strong> attribute.</p>
4299
4300 <p><strong>calendar</strong>: describes the calendar to be used in the time calculations.
4301 All the values currently defined in the
4302 <code>CF metadata convention &lt;http://cfconventions.org/cf-conventions/cf-conventions#calendar&gt;</code>__ are supported.
4303 Valid calendars <strong>'standard', 'gregorian', 'proleptic_gregorian'
4304 'noleap', '365_day', '360_day', 'julian', 'all_leap', '366_day'</strong>.
4305 Default is <code>None</code> which means the calendar associated with the first
4306 input datetime instance will be used.</p>
4307
4308 <p><strong>select</strong>: <strong>'exact', 'before', 'after', 'nearest'</strong>
4309 The index selection method. <strong>exact</strong> will return the indices perfectly
4310 matching the dates given. <strong>before</strong> and <strong>after</strong> will return the indices
4311 corresponding to the dates just before or just after the given dates if
4312 an exact match cannot be found. <strong>nearest</strong> will return the indices that
4313 correspond to the closest dates.</p>
4314
4315 <p><strong>has_year_zero</strong>: if set to True, astronomical year numbering
4316 is used and the year zero exists. If set to False for real-world
4317 calendars, then historical year numbering is used and the year 1 is
4318 preceded by year -1 and no year zero exists.
4319 The defaults are set to conform with
4320 CF version 1.9 conventions (False for 'julian', 'gregorian'/'standard', True
4321 for 'proleptic_gregorian' (ISO 8601) and True for the idealized
4322 calendars 'noleap'/'365_day', '360_day', 366_day'/'all_leap')
4323 The defaults can only be over-ridden for the real-world calendars,
4324 for the the idealized calendars the year zero
4325 always exists and the has_year_zero kwarg is ignored.
4326 This kwarg is not needed to define calendar systems allowed by CF
4327 (the calendar-specific defaults do this).</p>
4328
4329 <p>returns an index (indices) of the netCDF time variable corresponding
4330 to the given datetime object(s).</p>
4331 </div>
4332
4333
4334 </section>
4335 <section id="stringtochar">
4336 <div class="attr function"><a class="headerlink" href="#stringtochar">#&nbsp;&nbsp</a>
4337
4338
4339 <span class="def">def</span>
4340 <span class="name">stringtochar</span><span class="signature">(unknown)</span>:
4341 </div>
4342
4343
4344 <div class="docstring"><p><strong><code>stringtochar(a,encoding='utf-8')</code></strong></p>
4345
4346 <p>convert a string array to a character array with one extra dimension</p>
4347
4348 <p><strong><code>a</code></strong>: Input numpy string array with numpy datatype <code>'SN'</code> or <code>'UN'</code>, where N
4349 is the number of characters in each string. Will be converted to
4350 an array of characters (datatype <code>'S1'</code> or <code>'U1'</code>) of shape <code>a.shape + (N,)</code>.</p>
4351
4352 <p>optional kwarg <code>encoding</code> can be used to specify character encoding (default
4353 <code>utf-8</code>). If <code>encoding</code> is 'none' or 'bytes', a <code>numpy.string_</code> the input array
4354 is treated a raw byte strings (<code>numpy.string_</code>).</p>
4355
4356 <p>returns a numpy character array with datatype <code>'S1'</code> or <code>'U1'</code>
4357 and shape <code>a.shape + (N,)</code>, where N is the length of each string in a.</p>
4358 </div>
4359
4360
4361 </section>
4362 <section id="chartostring">
4363 <div class="attr function"><a class="headerlink" href="#chartostring">#&nbsp;&nbsp</a>
4364
4365
4366 <span class="def">def</span>
4367 <span class="name">chartostring</span><span class="signature">(unknown)</span>:
4368 </div>
4369
4370
4371 <div class="docstring"><p><strong><code>chartostring(b,encoding='utf-8')</code></strong></p>
4372
4373 <p>convert a character array to a string array with one less dimension.</p>
4374
4375 <p><strong><code>b</code></strong>: Input character array (numpy datatype <code>'S1'</code> or <code>'U1'</code>).
4376 Will be converted to a array of strings, where each string has a fixed
4377 length of <code>b.shape[-1]</code> characters.</p>
4378
4379 <p>optional kwarg <code>encoding</code> can be used to specify character encoding (default
4380 <code>utf-8</code>). If <code>encoding</code> is 'none' or 'bytes', a <code>numpy.string_</code> btye array is
4381 returned.</p>
4382
4383 <p>returns a numpy string array with datatype <code>'UN'</code> (or <code>'SN'</code>) and shape
4384 <code>b.shape[:-1]</code> where where <code>N=b.shape[-1]</code>.</p>
4385 </div>
4386
4387
4388 </section>
4389 <section id="stringtoarr">
4390 <div class="attr function"><a class="headerlink" href="#stringtoarr">#&nbsp;&nbsp</a>
4391
4392
4393 <span class="def">def</span>
4394 <span class="name">stringtoarr</span><span class="signature">(unknown)</span>:
4395 </div>
4396
4397
4398 <div class="docstring"><p><strong><code>stringtoarr(a, NUMCHARS,dtype='S')</code></strong></p>
4399
4400 <p>convert a string to a character array of length <code>NUMCHARS</code></p>
4401
4402 <p><strong><code>a</code></strong>: Input python string.</p>
4403
4404 <p><strong><code>NUMCHARS</code></strong>: number of characters used to represent string
4405 (if len(a) &lt; <code>NUMCHARS</code>, it will be padded on the right with blanks).</p>
4406
4407 <p><strong><code>dtype</code></strong>: type of numpy array to return. Default is <code>'S'</code>, which
4408 means an array of dtype <code>'S1'</code> will be returned. If dtype=<code>'U'</code>, a
4409 unicode array (dtype = <code>'U1'</code>) will be returned.</p>
4410
4411 <p>returns a rank 1 numpy character array of length NUMCHARS with datatype <code>'S1'</code>
4412 (default) or <code>'U1'</code> (if dtype=<code>'U'</code>)</p>
4413 </div>
4414
4415
4416 </section>
4417 <section id="getlibversion">
4418 <div class="attr function"><a class="headerlink" href="#getlibversion">#&nbsp;&nbsp</a>
4419
4420
4421 <span class="def">def</span>
4422 <span class="name">getlibversion</span><span class="signature">(unknown)</span>:
4423 </div>
4424
4425
4426 <div class="docstring"><p><strong><code><a href="#getlibversion">getlibversion()</a></code></strong></p>
4427
4428 <p>returns a string describing the version of the netcdf library
4429 used to build the module, and when it was built.</p>
4430 </div>
4431
4432
4433 </section>
4434 <section id="EnumType">
4435 <div class="attr class">
4436 <a class="headerlink" href="#EnumType">#&nbsp;&nbsp</a>
4437
4438
4439 <span class="def">class</span>
4440 <span class="name">EnumType</span>:
4441 </div>
4442
4443
4444 <div class="docstring"><p>A <code><a href="#EnumType">EnumType</a></code> instance is used to describe an Enum data
4445 type, and can be passed to the the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of
4446 a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance. See
4447 <code><a href="#EnumType.__init__">EnumType.__init__</a></code> for more details.</p>
4448
4449 <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
4450 the user.</p>
4451 </div>
4452
4453
4454 <div id="EnumType.__init__" class="classattr">
4455 <div class="attr function"><a class="headerlink" href="#EnumType.__init__">#&nbsp;&nbsp</a>
4456
4457
4458 <span class="name">EnumType</span><span class="signature">()</span>
4459 </div>
4460
4461
4462 <div class="docstring"><p><strong><code>__init__(group, datatype, datatype_name, enum_dict)</code></strong></p>
4463
4464 <p>EnumType constructor.</p>
4465
4466 <p><strong><code>group</code></strong>: <code><a href="#Group">Group</a></code> instance to associate with the VLEN datatype.</p>
4467
4468 <p><strong><code>datatype</code></strong>: An numpy integer dtype object describing the base type
4469 for the Enum.</p>
4470
4471 <p><strong><code>datatype_name</code></strong>: a Python string containing a description of the
4472 Enum data type.</p>
4473
4474 <p><strong><code><a href="#EnumType.enum_dict">enum_dict</a></code></strong>: a Python dictionary containing the Enum field/value
4475 pairs.</p>
4476
4477 <p><strong><em><code>Note</code></em></strong>: <code><a href="#EnumType">EnumType</a></code> instances should be created using the
4478 <code><a href="#Dataset.createEnumType">Dataset.createEnumType</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or
4479 <code><a href="#Group">Group</a></code> instance, not using this class directly.</p>
4480 </div>
4481
4482
4483 </div>
4484 <div id="EnumType.dtype" class="classattr">
4485 <div class="attr variable"><a class="headerlink" href="#EnumType.dtype">#&nbsp;&nbsp</a>
4486
4487 <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>
4488 </div>
4489
4490
4491
4492 </div>
4493 <div id="EnumType.name" class="classattr">
4494 <div class="attr variable"><a class="headerlink" href="#EnumType.name">#&nbsp;&nbsp</a>
4495
4496 <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>
4497 </div>
4498
4499
4500
4501 </div>
4502 <div id="EnumType.enum_dict" class="classattr">
4503 <div class="attr variable"><a class="headerlink" href="#EnumType.enum_dict">#&nbsp;&nbsp</a>
4504
4505 <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>
4506 </div>
4507
4508
4509
4510 </div>
4511 </section>
4512 <section id="get_chunk_cache">
4513 <div class="attr function"><a class="headerlink" href="#get_chunk_cache">#&nbsp;&nbsp</a>
4514
4515
4516 <span class="def">def</span>
4517 <span class="name">get_chunk_cache</span><span class="signature">(unknown)</span>:
4518 </div>
4519
4520
4521 <div class="docstring"><p><strong><code><a href="#get_chunk_cache">get_chunk_cache()</a></code></strong></p>
4522
4523 <p>return current netCDF chunk cache information in a tuple (size,nelems,preemption).
4524 See netcdf C library documentation for <code>nc_get_chunk_cache</code> for
4525 details. Values can be reset with <code><a href="#set_chunk_cache">set_chunk_cache</a></code>.</p>
4526 </div>
4527
4528
4529 </section>
4530 <section id="set_chunk_cache">
4531 <div class="attr function"><a class="headerlink" href="#set_chunk_cache">#&nbsp;&nbsp</a>
4532
4533
4534 <span class="def">def</span>
4535 <span class="name">set_chunk_cache</span><span class="signature">(unknown)</span>:
4536 </div>
4537
4538
4539 <div class="docstring"><p><strong><code>set_chunk_cache(self,size=None,nelems=None,preemption=None)</code></strong></p>
4540
4541 <p>change netCDF4 chunk cache settings.
4542 See netcdf C library documentation for <code>nc_set_chunk_cache</code> for
4543 details.</p>
4544 </div>
4545
4546
43424547 </section>
43434548 </main>
43444549 </body>
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()
+0
-1293
examples/reading_netCDF.ipynb less more
0 {
1 "cells": [
2 {
3 "cell_type": "markdown",
4 "metadata": {
5 "internals": {
6 "slide_helper": "subslide_end",
7 "slide_type": "subslide"
8 },
9 "slide_helper": "slide_end",
10 "slideshow": {
11 "slide_type": "slide"
12 }
13 },
14 "source": [
15 "# Reading netCDF data\n",
16 "- requires [numpy](http://numpy.scipy.org) and netCDF/HDF5 C libraries.\n",
17 "- Github site: https://github.com/Unidata/netcdf4-python\n",
18 "- Online docs: http://unidata.github.io/netcdf4-python/\n",
19 "- Based on Konrad Hinsen's old [Scientific.IO.NetCDF](http://dirac.cnrs-orleans.fr/plone/software/scientificpython/) API, with lots of added netcdf version 4 features.\n",
20 "- Developed by Jeff Whitaker at NOAA, with many contributions from users."
21 ]
22 },
23 {
24 "cell_type": "markdown",
25 "metadata": {
26 "internals": {
27 "slide_type": "subslide"
28 },
29 "slideshow": {
30 "slide_type": "slide"
31 }
32 },
33 "source": [
34 "## Interactively exploring a netCDF File\n",
35 "\n",
36 "Let's explore a netCDF file from the *Atlantic Real-Time Ocean Forecast System*\n",
37 "\n",
38 "first, import netcdf4-python and numpy"
39 ]
40 },
41 {
42 "cell_type": "code",
43 "execution_count": 5,
44 "metadata": {
45 "collapsed": false,
46 "internals": {
47 "frag_number": 2,
48 "slide_helper": "subslide_end"
49 },
50 "slide_helper": "slide_end",
51 "slideshow": {
52 "slide_type": "fragment"
53 }
54 },
55 "outputs": [],
56 "source": [
57 "import netCDF4\n",
58 "import numpy as np"
59 ]
60 },
61 {
62 "cell_type": "markdown",
63 "metadata": {
64 "internals": {
65 "frag_helper": "fragment_end",
66 "frag_number": 2,
67 "slide_type": "subslide"
68 },
69 "slideshow": {
70 "slide_type": "slide"
71 }
72 },
73 "source": [
74 "## Create a netCDF4.Dataset object\n",
75 "- **`f`** is a `Dataset` object, representing an open netCDF file.\n",
76 "- printing the object gives you summary information, similar to *`ncdump -h`*."
77 ]
78 },
79 {
80 "cell_type": "code",
81 "execution_count": 6,
82 "metadata": {
83 "collapsed": false,
84 "internals": {
85 "frag_helper": "fragment_end",
86 "frag_number": 4,
87 "slide_helper": "subslide_end"
88 },
89 "slide_helper": "slide_end",
90 "slideshow": {
91 "slide_type": "fragment"
92 }
93 },
94 "outputs": [
95 {
96 "name": "stdout",
97 "output_type": "stream",
98 "text": [
99 "<type 'netCDF4._netCDF4.Dataset'>\n",
100 "root group (NETCDF4_CLASSIC data model, file format HDF5):\n",
101 " Conventions: CF-1.0\n",
102 " title: HYCOM ATLb2.00\n",
103 " institution: National Centers for Environmental Prediction\n",
104 " source: HYCOM archive file\n",
105 " experiment: 90.9\n",
106 " history: archv2ncdf3z\n",
107 " dimensions(sizes): MT(1), Y(850), X(712), Depth(10)\n",
108 " variables(dimensions): float64 \u001b[4mMT\u001b[0m(MT), float64 \u001b[4mDate\u001b[0m(MT), float32 \u001b[4mDepth\u001b[0m(Depth), int32 \u001b[4mY\u001b[0m(Y), int32 \u001b[4mX\u001b[0m(X), float32 \u001b[4mLatitude\u001b[0m(Y,X), float32 \u001b[4mLongitude\u001b[0m(Y,X), float32 \u001b[4mu\u001b[0m(MT,Depth,Y,X), float32 \u001b[4mv\u001b[0m(MT,Depth,Y,X), float32 \u001b[4mtemperature\u001b[0m(MT,Depth,Y,X), float32 \u001b[4msalinity\u001b[0m(MT,Depth,Y,X)\n",
109 " groups: \n",
110 "\n"
111 ]
112 }
113 ],
114 "source": [
115 "f = netCDF4.Dataset('data/rtofs_glo_3dz_f006_6hrly_reg3.nc')\n",
116 "print(f) "
117 ]
118 },
119 {
120 "cell_type": "markdown",
121 "metadata": {
122 "internals": {
123 "frag_helper": "fragment_end",
124 "frag_number": 4,
125 "slide_type": "subslide"
126 },
127 "slideshow": {
128 "slide_type": "slide"
129 }
130 },
131 "source": [
132 "## Access a netCDF variable\n",
133 "- variable objects stored by name in **`variables`** dict.\n",
134 "- print the variable yields summary info (including all the attributes).\n",
135 "- no actual data read yet (just have a reference to the variable object with metadata)."
136 ]
137 },
138 {
139 "cell_type": "code",
140 "execution_count": 7,
141 "metadata": {
142 "collapsed": false,
143 "internals": {
144 "frag_helper": "fragment_end",
145 "frag_number": 6,
146 "slide_helper": "subslide_end"
147 },
148 "slide_helper": "slide_end",
149 "slideshow": {
150 "slide_type": "fragment"
151 }
152 },
153 "outputs": [
154 {
155 "name": "stdout",
156 "output_type": "stream",
157 "text": [
158 "[u'MT', u'Date', u'Depth', u'Y', u'X', u'Latitude', u'Longitude', u'u', u'v', u'temperature', u'salinity']\n",
159 "<type 'netCDF4._netCDF4.Variable'>\n",
160 "float32 temperature(MT, Depth, Y, X)\n",
161 " coordinates: Longitude Latitude Date\n",
162 " standard_name: sea_water_potential_temperature\n",
163 " units: degC\n",
164 " _FillValue: 1.26765e+30\n",
165 " valid_range: [ -5.07860279 11.14989948]\n",
166 " long_name: temp [90.9H]\n",
167 "unlimited dimensions: MT\n",
168 "current shape = (1, 10, 850, 712)\n",
169 "filling on\n"
170 ]
171 }
172 ],
173 "source": [
174 "print(f.variables.keys()) # get all variable names\n",
175 "temp = f.variables['temperature'] # temperature variable\n",
176 "print(temp) "
177 ]
178 },
179 {
180 "cell_type": "markdown",
181 "metadata": {
182 "internals": {
183 "frag_helper": "fragment_end",
184 "frag_number": 6,
185 "slide_type": "subslide"
186 },
187 "slideshow": {
188 "slide_type": "slide"
189 }
190 },
191 "source": [
192 "## List the Dimensions\n",
193 "\n",
194 "- All variables in a netCDF file have an associated shape, specified by a list of dimensions.\n",
195 "- Let's list all the dimensions in this netCDF file.\n",
196 "- Note that the **`MT`** dimension is special (*`unlimited`*), which means it can be appended to."
197 ]
198 },
199 {
200 "cell_type": "code",
201 "execution_count": 8,
202 "metadata": {
203 "collapsed": false,
204 "internals": {
205 "frag_helper": "fragment_end",
206 "frag_number": 8
207 },
208 "slideshow": {
209 "slide_type": "fragment"
210 }
211 },
212 "outputs": [
213 {
214 "name": "stdout",
215 "output_type": "stream",
216 "text": [
217 "(u'MT', <type 'netCDF4._netCDF4.Dimension'> (unlimited): name = 'MT', size = 1\n",
218 ")\n",
219 "(u'Y', <type 'netCDF4._netCDF4.Dimension'>: name = 'Y', size = 850\n",
220 ")\n",
221 "(u'X', <type 'netCDF4._netCDF4.Dimension'>: name = 'X', size = 712\n",
222 ")\n",
223 "(u'Depth', <type 'netCDF4._netCDF4.Dimension'>: name = 'Depth', size = 10\n",
224 ")\n"
225 ]
226 }
227 ],
228 "source": [
229 "for d in f.dimensions.items():\n",
230 " print(d)"
231 ]
232 },
233 {
234 "cell_type": "markdown",
235 "metadata": {
236 "internals": {
237 "frag_helper": "fragment_end",
238 "frag_number": 9
239 },
240 "slideshow": {
241 "slide_type": "fragment"
242 }
243 },
244 "source": [
245 "Each variable has a **`dimensions`** and a **`shape`** attribute."
246 ]
247 },
248 {
249 "cell_type": "code",
250 "execution_count": 9,
251 "metadata": {
252 "collapsed": false,
253 "internals": {
254 "frag_helper": "fragment_end",
255 "frag_number": 10
256 },
257 "slideshow": {
258 "slide_type": "fragment"
259 }
260 },
261 "outputs": [
262 {
263 "data": {
264 "text/plain": [
265 "(u'MT', u'Depth', u'Y', u'X')"
266 ]
267 },
268 "execution_count": 9,
269 "metadata": {},
270 "output_type": "execute_result"
271 }
272 ],
273 "source": [
274 "temp.dimensions"
275 ]
276 },
277 {
278 "cell_type": "code",
279 "execution_count": 10,
280 "metadata": {
281 "collapsed": false,
282 "internals": {
283 "frag_helper": "fragment_end",
284 "frag_number": 11,
285 "slide_helper": "subslide_end"
286 },
287 "slide_helper": "slide_end",
288 "slideshow": {
289 "slide_type": "fragment"
290 }
291 },
292 "outputs": [
293 {
294 "data": {
295 "text/plain": [
296 "(1, 10, 850, 712)"
297 ]
298 },
299 "execution_count": 10,
300 "metadata": {},
301 "output_type": "execute_result"
302 }
303 ],
304 "source": [
305 "temp.shape"
306 ]
307 },
308 {
309 "cell_type": "markdown",
310 "metadata": {
311 "internals": {
312 "frag_helper": "fragment_end",
313 "frag_number": 11,
314 "slide_type": "subslide"
315 },
316 "slideshow": {
317 "slide_type": "slide"
318 }
319 },
320 "source": [
321 "### Each dimension typically has a variable associated with it (called a *coordinate* variable).\n",
322 "- *Coordinate variables* are 1D variables that have the same name as dimensions.\n",
323 "- Coordinate variables and *auxiliary coordinate variables* (named by the *coordinates* attribute) locate values in time and space."
324 ]
325 },
326 {
327 "cell_type": "code",
328 "execution_count": 11,
329 "metadata": {
330 "collapsed": false,
331 "internals": {
332 "frag_helper": "fragment_end",
333 "frag_number": 13,
334 "slide_helper": "subslide_end"
335 },
336 "slide_helper": "slide_end",
337 "slideshow": {
338 "slide_type": "fragment"
339 }
340 },
341 "outputs": [
342 {
343 "name": "stdout",
344 "output_type": "stream",
345 "text": [
346 "<type 'netCDF4._netCDF4.Variable'>\n",
347 "float64 MT(MT)\n",
348 " long_name: time\n",
349 " units: days since 1900-12-31 00:00:00\n",
350 " calendar: standard\n",
351 " axis: T\n",
352 "unlimited dimensions: MT\n",
353 "current shape = (1,)\n",
354 "filling on, default _FillValue of 9.96920996839e+36 used\n",
355 "\n",
356 "<type 'netCDF4._netCDF4.Variable'>\n",
357 "int32 X(X)\n",
358 " point_spacing: even\n",
359 " axis: X\n",
360 "unlimited dimensions: \n",
361 "current shape = (712,)\n",
362 "filling on, default _FillValue of -2147483647 used\n",
363 "\n"
364 ]
365 }
366 ],
367 "source": [
368 "mt = f.variables['MT']\n",
369 "depth = f.variables['Depth']\n",
370 "x,y = f.variables['X'], f.variables['Y']\n",
371 "print(mt)\n",
372 "print(x) "
373 ]
374 },
375 {
376 "cell_type": "markdown",
377 "metadata": {
378 "internals": {
379 "frag_helper": "fragment_end",
380 "frag_number": 13,
381 "slide_type": "subslide"
382 },
383 "slideshow": {
384 "slide_type": "slide"
385 }
386 },
387 "source": [
388 "## Accessing data from a netCDF variable object\n",
389 "\n",
390 "- netCDF variables objects behave much like numpy arrays.\n",
391 "- slicing a netCDF variable object returns a numpy array with the data.\n",
392 "- Boolean array and integer sequence indexing behaves differently for netCDF variables than for numpy arrays. Only 1-d boolean arrays and integer sequences are allowed, and these indices work independently along each dimension (similar to the way vector subscripts work in fortran)."
393 ]
394 },
395 {
396 "cell_type": "code",
397 "execution_count": 12,
398 "metadata": {
399 "collapsed": false,
400 "internals": {
401 "frag_helper": "fragment_end",
402 "frag_number": 15
403 },
404 "slideshow": {
405 "slide_type": "fragment"
406 }
407 },
408 "outputs": [
409 {
410 "name": "stdout",
411 "output_type": "stream",
412 "text": [
413 "[ 41023.25]\n"
414 ]
415 }
416 ],
417 "source": [
418 "time = mt[:] # Reads the netCDF variable MT, array of one element\n",
419 "print(time) "
420 ]
421 },
422 {
423 "cell_type": "code",
424 "execution_count": 13,
425 "metadata": {
426 "collapsed": false,
427 "internals": {
428 "frag_helper": "fragment_end",
429 "frag_number": 16
430 },
431 "slideshow": {
432 "slide_type": "fragment"
433 }
434 },
435 "outputs": [
436 {
437 "name": "stdout",
438 "output_type": "stream",
439 "text": [
440 "[ 0. 100. 200. 400. 700. 1000. 2000. 3000. 4000. 5000.]\n"
441 ]
442 }
443 ],
444 "source": [
445 "dpth = depth[:] # examine depth array\n",
446 "print(dpth) "
447 ]
448 },
449 {
450 "cell_type": "code",
451 "execution_count": 14,
452 "metadata": {
453 "collapsed": false,
454 "internals": {
455 "frag_helper": "fragment_end",
456 "frag_number": 17,
457 "slide_helper": "subslide_end"
458 },
459 "slide_helper": "slide_end",
460 "slideshow": {
461 "slide_type": "fragment"
462 }
463 },
464 "outputs": [
465 {
466 "name": "stdout",
467 "output_type": "stream",
468 "text": [
469 "shape of temp variable: (1, 10, 850, 712)\n",
470 "shape of temp slice: (6, 425, 356)\n"
471 ]
472 }
473 ],
474 "source": [
475 "xx,yy = x[:],y[:]\n",
476 "print('shape of temp variable: %s' % repr(temp.shape))\n",
477 "tempslice = temp[0, dpth > 400, yy > yy.max()/2, xx > xx.max()/2]\n",
478 "print('shape of temp slice: %s' % repr(tempslice.shape))"
479 ]
480 },
481 {
482 "cell_type": "markdown",
483 "metadata": {
484 "internals": {
485 "frag_helper": "fragment_end",
486 "frag_number": 17,
487 "slide_type": "subslide"
488 },
489 "slideshow": {
490 "slide_type": "slide"
491 }
492 },
493 "source": [
494 "## What is the sea surface temperature and salinity at 50N, 140W?\n",
495 "### Finding the latitude and longitude indices of 50N, 140W\n",
496 "\n",
497 "- The `X` and `Y` dimensions don't look like longitudes and latitudes\n",
498 "- Use the auxilary coordinate variables named in the `coordinates` variable attribute, `Latitude` and `Longitude`"
499 ]
500 },
501 {
502 "cell_type": "code",
503 "execution_count": 15,
504 "metadata": {
505 "collapsed": false,
506 "internals": {
507 "frag_helper": "fragment_end",
508 "frag_number": 19
509 },
510 "slideshow": {
511 "slide_type": "fragment"
512 }
513 },
514 "outputs": [
515 {
516 "name": "stdout",
517 "output_type": "stream",
518 "text": [
519 "<type 'netCDF4._netCDF4.Variable'>\n",
520 "float32 Latitude(Y, X)\n",
521 " standard_name: latitude\n",
522 " units: degrees_north\n",
523 "unlimited dimensions: \n",
524 "current shape = (850, 712)\n",
525 "filling on, default _FillValue of 9.96920996839e+36 used\n",
526 "\n"
527 ]
528 }
529 ],
530 "source": [
531 "lat, lon = f.variables['Latitude'], f.variables['Longitude']\n",
532 "print(lat)"
533 ]
534 },
535 {
536 "cell_type": "markdown",
537 "metadata": {
538 "internals": {
539 "frag_helper": "fragment_end",
540 "frag_number": 20,
541 "slide_helper": "subslide_end"
542 },
543 "slide_helper": "slide_end",
544 "slideshow": {
545 "slide_type": "fragment"
546 }
547 },
548 "source": [
549 "Aha! So we need to find array indices `iy` and `ix` such that `Latitude[iy, ix]` is close to 50.0 and `Longitude[iy, ix]` is close to -140.0 ..."
550 ]
551 },
552 {
553 "cell_type": "code",
554 "execution_count": 16,
555 "metadata": {
556 "collapsed": false,
557 "internals": {
558 "frag_helper": "fragment_end",
559 "frag_number": 20,
560 "slide_type": "subslide"
561 },
562 "slideshow": {
563 "slide_type": "slide"
564 }
565 },
566 "outputs": [],
567 "source": [
568 "# extract lat/lon values (in degrees) to numpy arrays\n",
569 "latvals = lat[:]; lonvals = lon[:] \n",
570 "# a function to find the index of the point closest pt\n",
571 "# (in squared distance) to give lat/lon value.\n",
572 "def getclosest_ij(lats,lons,latpt,lonpt):\n",
573 " # find squared distance of every point on grid\n",
574 " dist_sq = (lats-latpt)**2 + (lons-lonpt)**2 \n",
575 " # 1D index of minimum dist_sq element\n",
576 " minindex_flattened = dist_sq.argmin() \n",
577 " # Get 2D index for latvals and lonvals arrays from 1D index\n",
578 " return np.unravel_index(minindex_flattened, lats.shape)\n",
579 "iy_min, ix_min = getclosest_ij(latvals, lonvals, 50., -140)"
580 ]
581 },
582 {
583 "cell_type": "markdown",
584 "metadata": {
585 "internals": {
586 "frag_helper": "fragment_end",
587 "frag_number": 22
588 },
589 "slideshow": {
590 "slide_type": "fragment"
591 }
592 },
593 "source": [
594 "### Now we have all the information we need to find our answer.\n"
595 ]
596 },
597 {
598 "cell_type": "markdown",
599 "metadata": {
600 "internals": {
601 "frag_helper": "fragment_end",
602 "frag_number": 23
603 },
604 "slideshow": {
605 "slide_type": "fragment"
606 }
607 },
608 "source": [
609 "```\n",
610 "|----------+--------|\n",
611 "| Variable | Index |\n",
612 "|----------+--------|\n",
613 "| MT | 0 |\n",
614 "| Depth | 0 |\n",
615 "| Y | iy_min |\n",
616 "| X | ix_min |\n",
617 "|----------+--------|\n",
618 "```"
619 ]
620 },
621 {
622 "cell_type": "markdown",
623 "metadata": {
624 "internals": {
625 "frag_helper": "fragment_end",
626 "frag_number": 24
627 },
628 "slideshow": {
629 "slide_type": "fragment"
630 }
631 },
632 "source": [
633 "### What is the sea surface temperature and salinity at the specified point?"
634 ]
635 },
636 {
637 "cell_type": "code",
638 "execution_count": 17,
639 "metadata": {
640 "collapsed": false,
641 "internals": {
642 "frag_helper": "fragment_end",
643 "frag_number": 25,
644 "slide_helper": "subslide_end"
645 },
646 "slide_helper": "slide_end",
647 "slideshow": {
648 "slide_type": "fragment"
649 }
650 },
651 "outputs": [
652 {
653 "name": "stdout",
654 "output_type": "stream",
655 "text": [
656 " 6.4631 degC\n",
657 "32.6572 psu\n"
658 ]
659 }
660 ],
661 "source": [
662 "sal = f.variables['salinity']\n",
663 "# Read values out of the netCDF file for temperature and salinity\n",
664 "print('%7.4f %s' % (temp[0,0,iy_min,ix_min], temp.units))\n",
665 "print('%7.4f %s' % (sal[0,0,iy_min,ix_min], sal.units))"
666 ]
667 },
668 {
669 "cell_type": "markdown",
670 "metadata": {
671 "internals": {
672 "frag_helper": "fragment_end",
673 "frag_number": 25,
674 "slide_type": "subslide"
675 },
676 "slideshow": {
677 "slide_type": "slide"
678 }
679 },
680 "source": [
681 "## Remote data access via openDAP\n",
682 "\n",
683 "- Remote data can be accessed seamlessly with the netcdf4-python API\n",
684 "- Access happens via the DAP protocol and DAP servers, such as TDS.\n",
685 "- many formats supported, like GRIB, are supported \"under the hood\"."
686 ]
687 },
688 {
689 "cell_type": "markdown",
690 "metadata": {
691 "internals": {
692 "frag_helper": "fragment_end",
693 "frag_number": 27
694 },
695 "slideshow": {
696 "slide_type": "fragment"
697 }
698 },
699 "source": [
700 "The following example showcases some nice netCDF features:\n",
701 "\n",
702 "1. We are seamlessly accessing **remote** data, from a TDS server.\n",
703 "2. We are seamlessly accessing **GRIB2** data, as if it were netCDF data.\n",
704 "3. We are generating **metadata** on-the-fly."
705 ]
706 },
707 {
708 "cell_type": "code",
709 "execution_count": 19,
710 "metadata": {
711 "collapsed": false,
712 "internals": {
713 "frag_helper": "fragment_end",
714 "frag_number": 28,
715 "slide_helper": "subslide_end"
716 },
717 "slide_helper": "slide_end",
718 "slideshow": {
719 "slide_type": "fragment"
720 }
721 },
722 "outputs": [
723 {
724 "name": "stdout",
725 "output_type": "stream",
726 "text": [
727 "http://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_0p5deg/GFS_Global_0p5deg_20150711_0600.grib2/GC\n"
728 ]
729 }
730 ],
731 "source": [
732 "import datetime\n",
733 "date = datetime.datetime.now()\n",
734 "# build URL for latest synoptic analysis time\n",
735 "URL = 'http://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_0p5deg/GFS_Global_0p5deg_%04i%02i%02i_%02i%02i.grib2/GC' %\\\n",
736 "(date.year,date.month,date.day,6*(date.hour//6),0)\n",
737 "# keep moving back 6 hours until a valid URL found\n",
738 "validURL = False; ncount = 0\n",
739 "while (not validURL and ncount < 10):\n",
740 " print(URL)\n",
741 " try:\n",
742 " gfs = netCDF4.Dataset(URL)\n",
743 " validURL = True\n",
744 " except RuntimeError:\n",
745 " date -= datetime.timedelta(hours=6)\n",
746 " ncount += 1 "
747 ]
748 },
749 {
750 "cell_type": "code",
751 "execution_count": 20,
752 "metadata": {
753 "collapsed": false,
754 "internals": {
755 "frag_helper": "fragment_end",
756 "frag_number": 28,
757 "slide_helper": "subslide_end",
758 "slide_type": "subslide"
759 },
760 "slide_helper": "slide_end",
761 "slideshow": {
762 "slide_type": "slide"
763 }
764 },
765 "outputs": [
766 {
767 "name": "stdout",
768 "output_type": "stream",
769 "text": [
770 "<type 'netCDF4._netCDF4.Variable'>\n",
771 "float32 Temperature_surface(time2, lat, lon)\n",
772 " long_name: Temperature @ Ground or water surface\n",
773 " units: K\n",
774 " abbreviation: TMP\n",
775 " missing_value: nan\n",
776 " grid_mapping: LatLon_Projection\n",
777 " coordinates: reftime time2 lat lon \n",
778 " Grib_Variable_Id: VAR_0-0-0_L1\n",
779 " Grib2_Parameter: [0 0 0]\n",
780 " Grib2_Parameter_Discipline: Meteorological products\n",
781 " Grib2_Parameter_Category: Temperature\n",
782 " Grib2_Parameter_Name: Temperature\n",
783 " Grib2_Level_Type: Ground or water surface\n",
784 " Grib2_Generating_Process_Type: Forecast\n",
785 "unlimited dimensions: \n",
786 "current shape = (93, 361, 720)\n",
787 "filling off\n",
788 "\n",
789 "<type 'netCDF4._netCDF4.Variable'>\n",
790 "float64 time2(time2)\n",
791 " units: Hour since 2015-07-11T06:00:00Z\n",
792 " standard_name: time\n",
793 " long_name: GRIB forecast or observation time\n",
794 " calendar: proleptic_gregorian\n",
795 " _CoordinateAxisType: Time\n",
796 "unlimited dimensions: \n",
797 "current shape = (93,)\n",
798 "filling off\n",
799 "\n",
800 "<type 'netCDF4._netCDF4.Variable'>\n",
801 "float32 lat(lat)\n",
802 " units: degrees_north\n",
803 " _CoordinateAxisType: Lat\n",
804 "unlimited dimensions: \n",
805 "current shape = (361,)\n",
806 "filling off\n",
807 "\n",
808 "<type 'netCDF4._netCDF4.Variable'>\n",
809 "float32 lon(lon)\n",
810 " units: degrees_east\n",
811 " _CoordinateAxisType: Lon\n",
812 "unlimited dimensions: \n",
813 "current shape = (720,)\n",
814 "filling off\n",
815 "\n"
816 ]
817 }
818 ],
819 "source": [
820 "# Look at metadata for a specific variable\n",
821 "# gfs.variables.keys() will show all available variables.\n",
822 "sfctmp = gfs.variables['Temperature_surface']\n",
823 "# get info about sfctmp\n",
824 "print(sfctmp)\n",
825 "# print coord vars associated with this variable\n",
826 "for dname in sfctmp.dimensions: \n",
827 " print(gfs.variables[dname])"
828 ]
829 },
830 {
831 "cell_type": "markdown",
832 "metadata": {
833 "internals": {
834 "frag_helper": "fragment_end",
835 "frag_number": 28,
836 "slide_type": "subslide"
837 },
838 "slideshow": {
839 "slide_type": "slide"
840 }
841 },
842 "source": [
843 "##Missing values\n",
844 "- when `data == var.missing_value` somewhere, a masked array is returned.\n",
845 "- illustrate with soil moisture data (only defined over land)\n",
846 "- white areas on plot are masked values over water."
847 ]
848 },
849 {
850 "cell_type": "code",
851 "execution_count": 21,
852 "metadata": {
853 "collapsed": false,
854 "internals": {
855 "frag_helper": "fragment_end",
856 "frag_number": 31
857 },
858 "slideshow": {
859 "slide_type": "fragment"
860 }
861 },
862 "outputs": [
863 {
864 "name": "stdout",
865 "output_type": "stream",
866 "text": [
867 "shape=(361, 720), type=<class 'numpy.ma.core.MaskedArray'>, missing_value=nan\n"
868 ]
869 },
870 {
871 "data": {
872 "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD7CAYAAAB37B+tAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnX+MJkeZ378Ptmf5dbPLgM8/N7dWwCc23NhGwr6EO7Fc\nwNhSgi9ShNlVyAlOEQpZQAQns2sHZ+OLHQb5yEm3AkXHDzmEmeCYHwIFDtvEm3CKzE/bY1gc2zpW\nYn322vHCDhd0s177yR/dNVNvvVXV1d3V3VX9Ph9pNO/bb/+o7q769tNPPfUUMTMEQRCEfHnR0AUQ\nBEEQ2iFCLgiCkDki5IIgCJkjQi4IgpA5IuSCIAiZI0IuCIKQOWcPcVAikphHQRCEBjAz2RY6/wC8\nGMB3ADwI4EcADpXLDwE4DuCB8u9abZuDAB4D8AiAqx37Zd9xU/1T55/jn5Rdyj0LZc+13KFld2mn\n1yJn5r8hojcz86+I6GwAf0FE3wDAAD7OzB/X1yei3QCuB7AbwEUA7iWiS5n5hZAnjSAIglCfSh85\nM/+q/DgH4BwUIg4A0+Y9cB2AVWZ+jpmPAXgcwJURyikIgiA4qBRyInoRET0I4ASAu5n5u+VP7yei\nh4jo00S0o1x2IQqXi+I4Cst8LBwZugAtODJ0AVpwZOgCNOTI0AVowZGhC9CQI0MXoAVHmm4YYpG/\nwMyXA7gYwFVE9HcAfBLAJQAuB/AkgD/27aJp4VKDmY8MXYamSNn7J9dyA/mWPddyA+3KHhy1wsyn\niOg+ANcw86ZwE9GnAHyt/PoEgJ3aZheXy6YgokPa1yM53wBBEIQuIKI9APZUrlf2hLp28ioAZ5j5\nF0T0EgDfBPBRAD9k5qfKdT4E4A3MvK/s7FxB4Re/CMC9AF7NxkGIiNkWQiMIgpAg206ub2rYxsI8\nuZZ1jUs7qyzyCwDcQURnoXDDfIGZv05E/5mILkfhNvkpgPcCADMfJaI7ARwFcAbA+0wRFwRBAADa\nB547vN56PzFEtEqozXX1Yy4tLOPm0oW8fHKpN1HX8VrknR1ULHJBmBlo31Y/WQzhNtGF03UsU1xN\n4XaJtsnSwjJuueE24PYt/VrTBjgudqxrLu0UIR8ZekXmFWuIqCB0gl73gK36p0Ty9P75aEKuhLnN\nQ+KZ7ec6f7v9rBs2P9/w/O0Tvx07+3TlvheZ6WbcxDc8fzvmz9rYbIdt3TEi5DOCaVkM8ZonzB5K\nUE0xNeufWs80MlS9fWb7uZhfKoRyfXkOAHDuqWec+9O3A7C5rULtw0aIIMckhrU+GiE3X2PWLHlb\nun69SRnXK6IIutA1Pp/36f3zU8ts637vldsnvle15ZtxEwPAP6bbwgs6ALE0KVshV0KtLoQp5Eq4\nRKgmMS2k0688Vvywd1FcLkJtaB84pN64LHObkAPAR1ZuAjApxKboTblsLiSs+UauJMjMC7nCaXnf\nUC6/fXatcEGIgcvtUWf7qm1NUX5odXp1m5BPuWxu256FmMf2DoxOyGfZfdIUsxFhdQ3Mi3IdhU6x\nWemq47OOK8UUdHPbFHnDs6eieguaxpEngwh3GKZVNSXelvXnDq9PvfqK+2WchLpIYhwHcNejucPr\neGb7uTimLatq47wC2nZyqz7fxTfihudv773TMpTFD/d3rGws8tQZstO1SqxD2PSla4LeVYPvS0yE\nMFyiW3WffGJt1km9foW4U9pia49D8IZnTwGI14eXvWslZYZw+8QQ7ypEbMcD7QP36Urz1c9Tn9s2\nFSYYu4/rZtzEt9yw1YE6pD89ph6IkHdEn6O6dGILuYj2OKmqJzHvu2tA0JCoqLah/Om7zsxNDAhq\nS/Y+8uS4gVh/yncl4n1Y3nWPozfQtpEOQsesrgF7F50/V90/30jhuiGJLqoGEeWGPr5l+7s2wCvd\nH1Ms8oasP7+Nj519uujQqPlaaLNc9AbVl3h3QR1BDzlPeUA0x3V9m9Yxm5Db9ml70NdBRbNEGQlZ\nduYvLSwD6H7g0K4zc9j+rg3MHV7v5IHk0s7KiSUEO2rYsG8IsA2fiNt+19erX8r+Mcsfcm5CN/AK\nyKw3Vd+b7N8n8E1QogsUrpHQhFYuTu+fxy24lZZPLuEuvhF38Y1tdudkkZmULrgGQHXFaCzyIQRw\n/fltfPtZN+AW3Bp0jK6FzBZGOAuk+pDr0z9dlzZvgCFRKm3EXYUmzp+1semiWPwwQH/FzuOHsjkS\nvIMBReoNokt346g7O32VJKVGbitnDFeKHtplG3RhivsYBT/0PvcR+tjqfpaRJURrXCfCpGlHo2sc\ngY8mQu5b14USdKDIRrh8cgmn9883atP6fe9SzHedmcO5p57pzM8/qs7OOg1lCJGv45uMaaWHpvEc\nm4gD9fztXdWJKPdy72KxH/VfZ3Vtcx2FyxBwlUUXbfNcQwTdZWmb1zZU2H2W++n989iOjYnyNWWy\nfPPgC7t5luvpb/skK4u8S9dEVQVVy2wDZ0LwNZKYVrkqW9Ny9kFObwR1LNvOClEReVIH/dqrOuKy\nHl1vkFXr2HA9RNtY7rU61mmt2NfeRXxk5aZonZ6LHwZuvv3GYPdqW7J3rYRUmBgCoVc4s/KFZnTz\nlc01HL5LIUhZ1HOgSzEf+t70+VC11fNQC99Ev261QiBX1/AQLmtS/E2GTBeSrWslpsBVCaarUrle\n6WzLbbOgmBaQuY8if0R3jUkEvB0hVmTM8FFXveqCPutG3XDT0OtYq99j7yJ2fW6udn6WXWfqRaf1\nTfJCXgeXYKrlVbkhYuYsUcedO7zuFHDz+9gF13WOuZ97mxBLX0d0zPkt28Z2d1GONmxO9Yb653Lu\nqWfwPYSP9FTzHtTtwPQZgk07bZ3HSt210mTQiC3uVG8cthviO05Ig9L3rzdOU9irlgvD4xO9kIiN\ntuhuOGA89aOucMXulDaF1TdsP4b7ZNvJdT69f6tjVUXIqMgWoP4o1iwHBOk30mXZ6uvqVrVvail9\nPdoH74CDkMbks7yrGmGXjbSLGcubklJZXLgG0FSJhj4wJmR9E73u6P9P759PR8RX16b/GmC2vabF\nafMGra5pVwODFBsL8zR3eH0qxFElDIuap9xnkRPRiwH8TwDbULhh7mLmQ0S0AOALAH4DwDEA72Dm\nX5TbHATwHgDPA/gAM99t2a/TInf5Gn1pVpt2Mrlm9TY7Jc1j2ywml+D36e80yd1l0Qf6/YnZsEJn\njq+qO643vSa06awHYBdvFU1jiayJ5TqIaZnrkWdLC8vO6JWYHZoqnUeMBFqNLHJm/hsAb2bmywFc\nDuAaIroKwAEA9zDzpQC+VX4HEe0GcD2A3QCuAfAJIgqy+s0nrHnzXBMftH0q+ypzEyu7dWNx7KcJ\nqYt41VtWH8ePhRpKHjqk3OYH93WS20Q+5Pp1fn1bWOcmLis7pi+5al+LH44flTJ/1gYtMlPMLIgm\nlZ2dzPyr8uMcgHNQdC68HcCbyuV3ADiCQsyvA7DKzM8BOEZEjwO4EsD9vmOEirFrIEMTfBXcF6Wi\nW+uhQlnVeVV1vLHieuPpki4y7RVW3vTyKmvchms8gHmN6u67ahwDENAOTevbI+AxB1Y1cVf52FiY\nJ9fDdn15rsP4se6o7OwsLeofAvjbAA4z80Ei+jkzv6L8nQCcZOZXENGfArifmT9f/vYpAN9g5i8a\n+5x4PWib68HXuamvH2optbViXA0mNFwxdH8x6KvTtYuHktkpGSJIVYNgmuKqg1VuFeVCLKYxW596\nC43xhucrw8bCfJwxDJqoN528ou/cNHpmROViuYv7G9zThMadncz8QulauRjAVUT0OuN3hj8EKHpY\nTN1IljoZ1Lp4FW1jcbYRv7qv3V27OroKp1Pf1X02j6Ove3r//KD5rtWbnBJpvV6qcsXs5Ky65m0z\nC26ydxHYu5jVZN68AtpYmKdbcCtdtpdx2V5OWsR9BMeRM/MpIroPwNsAnCCi85n5KSK6AMDT5WpP\nANipbXZxuWwKIjqkfX0z9vJ9QeWwPJX1hqkqZtGgQ/YYH1fcuC+Spsl+ba4J/bPveC6hSM2VY7Oy\nbXVgShCNZP5dJ8qy1UHbOtsOb8Uj07754i1iZXKdybJPjoFQhHSQtiGHvPgxswymlFxPh4j2ANhT\nuV5F1MqrAJxh5l8Q0UsAfBPAR8sdP8vMy0R0AMAOZj5QdnauoPCLXwTgXgCvZuMgtteDqjzdQPVr\ncV3rwvfq28WgjLq4ImNCtnMxpBvHLEOsPg89EgEYfoYZXz1sMxDEPE+1Px9D3e82cd4h+26a7TEn\nNrM0avW56RD9CwDcQURnoXDDfIGZv05E9wO4k4j+EGX4IQAw81EiuhPAUQBnALzPFHEXthth3rDN\nSmdYW1Wjrlwi2KTHP4YPvQ5NHiipDjbyhZA2IVWL0ayLurC3ncihSOfQjBh1V2+TsTupQ98CXNke\nxyjmQNi5eYWcmR8G8HrL8pMA3uLY5jYArVKL+V6ZXB2dIYN6Qmlj0aaALv5mpE0qjLXRuYj1ljD1\nkDi8Fa9uw1YX1PcYuI5b5QoT/Oh6Vtwrf9tNbmTnUFaW2QmVyvDoJg3O1olZtS/z3Ju8wVQRsxNP\n79RM9eG67eQ60z7UztFRB3PfVR3W5u91r531DTlgm1TfnlKlbp1JTshduGJJ9cpkVixdnH0i4sqB\nYvs+BE3FvOp8becdep2aEjMm2IzpHzoixWRjYT5q/LMNZbn5xiK0iWWPSdeCPuaHRVX/X5JJs1QS\neFsoU9XNcg2oCInpNbcfgjox6G2OYRsY00dDiCVsesWOOVAsZ2ydoaF0Ff1SRdsR2iH7zgkz+mpq\nbMErtyP5iSVi53H2WdopEtM378sj49pfVw03ZFRhXcwKnpIl3id6ZIPKtgf4O+pjDTSKQZdCru8/\nB1x1Ws/bg1WyCnkyrpXYN7JuxfS5aOruw+bSGaKh1HGTdFG+0Nd65UtuepxZFXGgOPfQ8+96dG0K\n+xkb6uFcdd+SsMiJ1jjWnIQumligoVZLnY7Rqrj1utuF7qfPeOKQa21bp64gN0n2P3ZsGUN1unhg\ntx081JVVPnfYPvdAqkxY3nBcV4dFPqiQ225cH765VCJSTJqO/jRdSGbfgG9fXVnivjLq6+h+wCYz\nsIglN4kpBn260JrQdVscQ/2Y0MnUhBx73ce1+fFSqnxdYqvYIZ20IftRy6t88XWvdZP+B3V/2wi5\nYCdUzLtoX6HC3KVBoSfJG1udymry5Sr/bRIWtcr21rFLCKjuuFQ0DSF0hVw2cdOEjh7cfGCsVK4q\n1MTWflydnF0fuyuqLO1oycAyITmL3BSRkERRg6DnYu5BzIHq1+SmbimbZWbLh+KaTLaJO0ihLPKx\nWU4poI+QtoVrAsOmc2hybFtKalvdGWNUE+0DJx+1Akze2CYDGTon0kwoMbFZ0+afa11FiPWuRlJW\nNb6QdYR+sHUi6g/qLowhV7u1DQSrGx48d3h9KiV1iIjnjDkXsXO9VCzytlEZvWIKus0ij+R6qftK\n3LaTK3QAlbk/vZyhDXQMVlLqmHOHVrkp24q7+RDXJ85Qy0NT8vr2raiqQ2Ppf9m8ZjlY5FU3MmTA\njEs4msyObtsHr4CYF0kl0rcJNa+AXL/59u0qq0uUQyxiff0qzAbl26aOD95G7g0rR0JCQOsIeEgn\nvBIg3bI03xLNuqzXYf3NssnDpU6cfcq0yn7YF3Vvkm193YI0f1cXwZfjvOr4XYcxFf6vwoonLHpf\nk0JFtO51DWnoIdtWvUWMoWHliK8+NHVjmvsMsex1S91X50IHk+n7bHAK2cArIFq1u1iSda2YQhwy\nWMBVecxp34Dp4a+uY5vb+8oRul4IbV43Q7YLPX7d/fpe3wG3T1PEvRtc/uJQ11nbDnRfO7a1F1+9\nM+uR2YE7diEvclBdln4cucvPanba1PHjhdxcr5ivrk0k7woR8tg5Y2yEhiTGILTz0vSv28ro65wS\nMY9PlaFi3lvbd58VXyfaJGQWMNf+9bqlt7Oxi7eOL2olKSH3WbT6zYst5EB1ha8l0qtrhX88pFNU\nI1aUTmwxb/t2oJiVMLGUsA3Zd4Ws1nkLcz3cQ+qKWkfPuBly7FkQ7coHW2rZD5WQ+26OLtpmAw8R\n1Lo33vcaau7Le3xXmKIm5K7oEFW5QwfddBnFExIvbltXjz0POY5Y5N2h6pKtztSJSqqD603RjGcP\nmbBa37ZRYTKjUtdyiFox4RWQ6tE2YyltkR2+ikn7wCoG1YxFdVG7Iq+u+a1wi8CbZdZnvnGVp7GI\n14iDt4m4q1y2WPY6DW8skQUpYovmCnXdNcUWUaViwM11q9piEuHGQ1BzzMpgUSuuhm5OKmG6NHS/\nWIjFqCySucOWYxluGn0dMwSvsT/OEU9edzBESEhgbHyRQDEQS3xYTCvdFhYY0j/S1CVYZUzNkiXe\nljQtcldstgc1rZYeH+57TXGFRbnis6dQAt1gtKcZJ2uWRy9HcHksx5iiweAk2/F9I/TEuk4LVz03\nqeNG6wsR8XCSiCOfQHUSrjhGSzrEyBfC5qq4TUXSWq4AbC4IszzW/aprYjl3n5slZlSL6fc2O6Y3\n9ytJsJKi8EsX98fmXtHddXXfEhUhoYx1mNW6pLwRAGobXV6LnIh2EtF9RPRjIvoREX2gXH6IiI4T\n0QPl37XaNgeJ6DEieoSIrq53KuXoSctcnUDhbtEFZGNhnkJcDjYBnVhf+bZX1+xWgMX3zbxIdYfh\nVz04JsqpH8+w/qv6A2JgK2eVheTygwrDYrYRV3toWq+6qItijdfDG7VCROcDOJ+ZHySilwP4AYDf\nB/AOAL9k5o8b6+9G8Rx9A4CLANwL4FJmfsFYzzv5srUsDh+13itvDvyJ+npoxJOrY1dts4kh9iHD\nm13bh4RqBe2/Aa57oB8zxLUi/vF+8WWuDBXi0Le+tsxynZiwygFLsIR9QJDXtcLMTwF4qvz810T0\nExQCDcD6xLwOwCozPwfgGBE9DuBKAPdPFThS+GAxqGB+SuQ3FuaJsCXyXmxuC8sy2/B+575t7haP\na8jsWAQAHN6lLa/XYKoaaNPOSz01qlq2lVq0+M3n5hKLfVhsYYjmwJ++BpoJ0yhjcUrQS0OSyK6b\nwT5yItoF4AoUovxGAO8non8K4PsAPszMvwBwISZF+zi2hL8VPlF3/VYsn7f62rayiRmdluYT0OGX\n9lZsVwiixwUTGtrnI6Z15POZVllMIuLpEyLMrqil2GMYmvrmx8yUe9nWZ6gRNCCodKscAfDvmfkr\nRPTrAJ4pf/4jABcw8x8S0Z8CuJ+ZP19u9ykAX2fmLxn7Y+ChSt9yl36yKSH3UTfaI2DSidAKu7Sw\njOWTS/WOH0DdRhiSLyX0d996QneE5iuqGnDWScemhvjHHffK41qpDD8konMAfBHAf2HmrwAAMz/N\nJQA+hcJ9AgBPANipbX5xuczCJ4HVfw48fAg4cWS6wH1M4hB6DK0z1LptwEhOk9CImToibu6vTeii\nKxzNtT8VdugaraeW29YT0qDJ4KG2A4dMRMQNThwpNPLhQ8DrvuRcraqzkwDcAeBZZv6QtvwCZn6y\n/PwhAG9g5n1aZ+eV2OrsfDUbB9m0yG0YOUpcESxtmLDGldjWfXDYRmzqYYKeiBbXIIy21N2fz9ry\nve7KQI28qcrnYcOXT6VtndORejWdH2cy+KFB9kMi+h0A/wvAGrC58xsB7AVwebnspwDey8wnym1u\nBPAeAGcAfJCZv2nZr1vIHbgEXe8UCBV9Z0WusqxdfnS1zLa9R9Rto+dcVK3X9qFQZ9SeCPk4qCvo\nsUZ2uvYz63VqU8uMCLXT++c1bUktjW1NIcfexenEVWbPLsLEvDMh9+3D3Beqc3cPRZWlJW6RceBq\nB02jVprmcJl1AVcQrbHSB/cAwQbhh6mhz6ITYqF70YW3qjMzxOq2LXOIuqsjKYZlHgvfMWQiiJFh\nGCM2N0qMXDsSwljB3kV3u6swENMXciWISnDLyhYs2KGE+MirQhWrsDQUnRCRHlrEhfGgT+zAvEim\nb1YRo0NT6lQYzjQdFaQr5LqAd0FI1InGZqC+/jpqE/aWybRyYGlhGcCtQxdDiACvgKrmiK0TQ25G\nLW25TSbHc7SdRWtsTOmK543eRprZDwH3yMiU8ZXP5n5pcT5tsyM2pRBxYVSsrgXHmPsw66HP/SZ+\n8S3cMeMGHhdwuha5i5ZiXgxzremW2bsIojWe8su7OkGryhjhgTSU9a7i2m9ZGOTwQodUzaHpMxhE\nmJuhd3Bu4rLGPbqRjkXeIFd2E6yCHEJZPj3fuflbG3JxqwjjZajJjGfezRLBhZxe+GHTATo1aGqV\n2zIgKir3V5GUKychl4iVcaInRDNTKlTlFmpiHPmmbpwFmgVsNByi3zlaJEpfVjkQf8To5v7U+diE\nWxAywXxYe3OVN2y3syjeithRd8MLucKM+OhQ1BtdxLJs5rZEa6zPM6pPN8e8OPE3sb+K80s15nZj\nYX7KWhPGievNyxT1NoJsdVUKtRnWtRI5kqMOzry/LfdXB1t+85RRDVsGBM0Oroe2bmiIENejneak\n6loZmAmXSAt0y7xy3X1gWwePaYWnFOonwj2b+CZv7mPKQSGM4SzyveVxB/Qdx7bKzf36sI2iazoK\nrkt3hwi4YE4TZ45AbltHZmnav/Zak6JFnlIHYCSffKiLxZXv24VtsEWsvN7mPiRnuKDDK6A2MwS5\n3kAVUtfak59rJWIn6MTTcYCHSsxp3No2BH3ihzb7EcaHbpHbEmr53gbrxogr0Z/52PKaDCfkDWbV\nmdguoqDH8pPX6fBUVkjosGd9OH5MsdX3JSIuVNG1T3zsPvc2gxF9pGeR15l+LSKxxLwuSjyrJo1Q\n+CIE6gqxvt9tJ9dZwgoFG7wCqnKj2OpOk/q0sTBPekiiqpdSP/2kJ+R9snfRns2wAW0HGOkNpa9Z\nxZvuWxrV7BESYugT3aYhiq52MTMEZkGcbSHHpJg1tcpjjBKtFNXVtaDGYLPKzcZgWuJqO3GtCD6a\ndIK3DVHkFWweU+LV3aSXa6UPLEKtKslENrIaecrbsO3kOsealLbKUraFONYV8FkKFxPc1Hkrk7qy\nxeZMZ74BkS5jcpUyn7MzBo4Z7fXJhEOFPGauFr1BtJ3T0BTZ0MYW2tBExAUTVSdUO1LflxaWN9Me\nm8xq/WkcjVMx+fJwrhVdVG1JpuruoyWhF9iaN6UlMRPwu159Y01CMasNUHDjcn24RBxo1hE601Ro\n5LA+8hABd/1uy5jo25fxm813R/swmavc2Ca2gJt01ZkT0nkqDUuIhTzs+8cr5ES0k4juI6IfE9GP\niOgD5fIFIrqHiB4loruJaIe2zUEieoyIHiGiq2MUspaAOn1LbjdJVWdMF1Z4k3LExHxo1HmISEMV\nqlBW+kxGmgxA1VRvzwH4EDM/SEQvB/ADIroHwLsB3MPMHyOiJQAHABwgot0ArgewG8BFAO4lokuZ\n+QXnEQKmRZuYHDZ0wJBnXZ9gbnZEoHyArPQbVx6bjYV52nZ4ujN17AMvhDQo3C1F3aN94Fmvd7Z8\nNbY35roPQK+QM/NTAJ4qP/81Ef0EhUC/HcCbytXuAHAEhZhfB2CVmZ8DcIyIHgdwJYD7nQep4+f2\nuVkCp0uyVSTzojlnAdJmUKk8UE1U4it9GHTM42wNsLD3BRTXRawnoR9C3+oaT82YKLYEdy5BryPm\nwT5yItoF4AoA3wFwHjOfKH86AeC88vOFAI5rmx1HIfztadKxGTjAZ8pXbk4eMaLcD64GJO4SoWvq\nGibbTq6zGrQ3phwsrtQc+rK6FnmQkJdulS8C+CAz/1L/jYv4Rd/F7efC61OsuaZbq7EvZ8XpMLlW\nV2Jqy26oVxQRcaFvqhJtmalz9f9q5Cjtw+b/Pso8FCHuqCofOYjoHBQi/jlm/kq5+AQRnc/MTxHR\nBQCeLpc/AWCntvnF5bJpHj609fnX9wDn7aksbFt8FyT0adjXa14st4oabGTuj1dAtG9+kFnThdkl\nJHe+q536ltO+eZ47vJ6NUVJ1HZRr5ex3/necWf4L4OFt3v15BwQREaHwgT/LzB/Sln+sXLZMRAcA\n7GBm1dm5gsIvfhGAewG8mo2DTEwsgTAHf9NOANs+XEzs2zbyquFs4XXQ5/+M4ZPvegCPXhlzaUTC\n8Oj1Uk0d6JtWztV2zd9sRkvKKEPL1Xc3pXuOkZ1VrpU3AvgnAN5MRA+Uf9cA+CiAtxLRowB+r/wO\nZj4K4E4ARwF8A8D7TBE30U/A5Tdqkrc7yjRU+mTQPYg4MBnqGKOHX8RVSBF94FpVHa37Jp2bq6Xu\nG4iNwad6M29ELatZI2S70FSxmxj+8L57z3MYDp9DGYU8iDkoLaf6WOe8T79ye2JD9EvqukraWKk5\nDk6IVeY2qWclba3QBzHFN6f6GuO8B7PI9adKrSdSgNXu2842MMYplppFnnssa1NftnlvcrJ0hPzo\nUoBTr7vmudu0LlmLHJiebqyPnCO+ZWPATPDf5DxzsmoEAfDX89Trs6mDei72qjzwSQg5UG9ig6bi\nW9kBasaI9zztW0z0a9Sk88dW6VO3aIRxsbSwXHubqrf11DtCm07wUhlHPgRFTuNELvjexazCmRT6\nNVTxtbRvvrimK/5tRcSFITDrnS8NblPGmooiGYu8DjFiyq14Zg7KEV18Qy0R1+tn6q+lwjhpYpXP\nIkl0dtrwDQ4wCe38dGUcs5GzgJuYMxDZzs0cEm3DnHXIZqWrwR0Rii3MEH0bCrnWUZd2JulaCRFx\n20CAWCkyxyTiodTNtiYIuZKriPvI0rViI2RAkC7QUUZ+ZkLIDEFVYZ1mj3poFkVxyQhV9F1Hxjgu\nIkmL3EabGW1s27ks0DFa42bnsc39EdrBXCceXa0r7hYhRcY0KjlJi7yJSIdMLKx3+M2aG8E836rc\nzjEmarZtb8a3C8LQjKE+JtvZaU4LtZX9q9lUbiGiNEZrXMfs9AQmz9kUdnUdzU5OfVkVIdN7jcEi\nEtqRipDqOpGiHri0M0mLHCguorIKJ0RcF28jO6GJ2k5EvCAkUkf/c60fW3jHYBEJzaF9mJpTdmiK\nHOeJjGUccxLpAAARaUlEQVQJIFmLHHDEPttm6FFzdqrPLjzrzIKQA2GhiF0f14dY57OFemNrmkMp\nNrZ5M1PShuwscsAirqYQq+nc6k6/1uF0banTViibWimhQ49tgj+WuRoFO6lY467orhzqXtJC3giX\nSFuWq5uV0hO3D1RisiHOOyQpmi7m206uy3R0I0bd26Gs8Sn3rbZcJ3VjIn0h91nPum+8QYKrXGcU\niYFqQOYM5VUVNoao1tmHsuJFzIVQQi38qvVsKa9TJX0hB6bF3JWl0CXmeiepcsf49jej9FVRVedW\njBBHIX/0wIa+aBrinCrJDwhiXiSiNQ4SWyXYtomTAbfQZ5yuti2T4Yfzg76Z6BPwyiCi2SRWp6cr\nbUebFNgFaYp5Hha5z5oGqvOIh0SyCBPhh30eR7fGmmRsFPInZp3T02/k5B5pQ/IW+SZKjH3Ca4sx\nn2Fruw9oH1p1Rtq21S1zQWhKLNE2B8alSB4WuaKJ9RzokiFaE+FoQFfWu5rqqot9C4kS4e3Y5ToJ\n7pPJ9A29UsiJ6DNEdIKIHtaWHSKi40T0QPl3rfbbQSJ6jIgeIaKro5fY5V5pup4gCEmgJjiP2fFZ\naz9G35pu0adsjQNhFvlnAVxjLGMAH2fmK8q/bwAAEe0GcD2A3eU2nyCieFZ/E193JDEXf209iNaY\naK0IZ1T/HddQrdt3GYUE0dpxXUG3peQIdq849ENNkxhciIGoFFlm/jaAn1t+sp3cdQBWmfk5Zj4G\n4HEAV7Yp4EQDV3HjNQb9VFJD6EXMBaFblFVeB9eAHpegh8xFkINfXKeNtfx+InqIiD5NRDvKZRcC\nOK6tcxzARS2OUeATb9e6dbapEPOQDH7CFlbrus79EGYbo574kt/pYYamQKtcKepPj2Q5vX9+OpNq\nxq7YpkL+SQCXALgcwJMA/tiz7rBWbEQBETG3s+lGsblIQq592YjEvSK4aDOAxzlPb8bCbdJIyJn5\naS4B8ClsuU+eALBTW/XictkUZYep+tvTpBxebKM3Q0MXhTjINRUawLxIrrbqiguPPTI0lVGcRLRH\n10rXeo2EnIgu0L7+IwAqouWrAN5JRHNEdAmA1wD4rm0fzHxI+zvSpBxBBIqJGeq22UlHa5ybv6xP\n6lrR5voT/Q4i/EJJEzG3/eZaVkUqk5Ez8xFdK13rVQ4IIqJVAG8C8Coi+hmAfwtgDxFdjsJt8lMA\n7y0PepSI7gRwFMAZAO/jIRKeA/aZhBwVwxmvvCks4lIx2RRkVxphV/4bLWbf1rElQ/MFhaofRGts\n1iPbUH7faM6mYp7qkHyTpCeWKNaN4Dd1WHq+ASe6pSgW+TSVQq5wpVTwTNMn11kwcUWM6eJdJ69K\nqLinNigty4kloiERE91RdV1Dk52VpPA6KySIx81iRrX4IlnU8pDkXKmJuI98cq00pYE1Lvip/ZZk\nm9nJtk65vG3+FmGEBPafhGZPNMMUzW1zMyiSt8ibDBBwUgpKHZGQkMMtWo/A9I2+NRKeyWhPwUbs\n9ujaX27tPnkhb4XD8qsSCP13W3rVWWJi1iAluF1GlyjLPPMBGkJkSiNgaWG5schWhSrmlFvFJAsh\nb2SVRxKB3J7MMfE+8ERkhYxQ7djlN9fJza0CZCLkQqI0EfOanc6S30bQWT65BKBbAyvH/pn8hDxU\nPOrmW/GQ4xO6LZVD7dtc25rhiiLmgs7SwnL0fW4szJP6i77zHshPyOuixzk3dAfk+IRuTdV0eVXT\n70VGxFz4yMpNmyIeS8xzFm+dvIS8iXhYrL8qn/vm8ODVtZm0xoHAh5d+D0TMhS4x6pdysQgFecWR\ne0YEOlEWuQo9DOw4jRr2OAv4JsCWwVhCW1bXgJW4uxyDJa7IxiLfFFZbDhUbutUuoWzdEeIr18MJ\nG96LWY4eEgp0K3zqTXnGjYW8LPJQRLT7QX9DsvVDtOyb0JlVF5cwzR/tuxVAOhkKUyAbixwIdHd4\nREPcJQ2oM8uS7drLQ1VoCdEazz27C0CFVY7ZfXPLSsitiPtkOKqud8P7YcuDIQiA582srGuhFvqY\n/ONAhkJutaoDBGMmQwhbEu0Npqb/0pa8KGTCXGEGiDg+ZExkJ+RCz8R4y4lgmQszTM3645useSxx\n4yZZCnld61qs8bywWePA+F6HhQYEhrXOWifoOKNWNETE+yF0tqUQZq0RChWsrgGHd7XezZgNgSwt\n8lBExPuh6jq3vQ+n98+PuhEKflTEygSO4AZXR/nY68/ohJxXQOpv6LKMFf0ah15ntZ5rffGHC0EE\ndHLWmbtzLCQ/+bIwPMo1EuvhaHO1uPzip/fPy5vVjLPt5PrkRC+e0d1jrzcu7RQhFwZBF3PdgrLN\nuTj212LBjS7igGFdV+RemiUhr3StENFniOgEET2sLVsgonuI6FEiupuIdmi/HSSix4joESK6Ot4p\nCGPCbGRq+i1xsQhebHnxHcxStswQH/lnAVxjLDsA4B5mvhTAt8rvIKLdAK4HsLvc5hNENDo/vBAH\nU7Rtvs0u/ZvbTq6zafEJ6aFyj5/eP18rdfIYLXIXleGHzPxtItplLH47gDeVn+8AcASFmF8HYJWZ\nnwNwjIgeB3AlgPsjlVcYIfoADj0RUtcNUR2HELcPQBD6pmkc+XnMfKL8fALAeeXnCzEp2scBXNTw\nGMLI2ViYp+kc0/PR8067MDtYhUzRsmzO6sO49YAgZmYi8r2eyqurkDRzh9elQzVBtp1c59Ap3WY9\ns2lTIT9BROcz81NEdAGAp8vlTwDYqa13cblsCiI6pH09wsxHGpZFEBqxsTBP4iNPm+WTS51MtpwL\nRLQHwJ7K9ULCD0sf+deY+bfK7x8D8CwzLxPRAQA7mPlA2dm5gsIvfhGAewG8mo2DSPih4EIJa5dx\nwOoYSsjFGk8T10PWNjvQrFjkbcIPVwH8bwC/SUQ/I6J3A/gogLcS0aMAfq/8DmY+CuBOAEcBfAPA\n+0wRF4QhMcVBRDxd1L3xWeS8ApoVEfcRErWy1/HTWxzr3wbgtjaFEmYXFbnShTWui7gIeJ5Ix7Qd\nifEWkiN2Y9XjxWfZ3zoGZMCYndGnsRXyouvwseWTS2KNC6NDcq0Io0dcKnni6+yc1Xjxxp2dgiAI\nfSOusHqIa0UYPWKF54cvxr/wk0unp45Y5IIgJItrQJAM5JpELHJBEJJCF2mXa0XesiYRi1wQhKSo\nEmkR8WlEyAVBEDJHwg8FQUgOlw981q1xCT8UBCEbNhbmaWNhnpYWlmuFIM7S9G46YpELgpAsNst8\nlq1yl3ZK1IogCMmzsTBPN+OmUtRvHbYwCSIWuSAIySK+8knERy4IQnYoX/nQ5UgdscgFQRAyQSxy\nQRCEkSJCLgiCkDki5IIgCJkjQi4IgpA5IuSCIAiZI0IuCIKQOa1GdhLRMQDrAJ4H8BwzX0lECwC+\nAOA3ABwD8A5m/kXLcgqCIAgO2lrkDGAPM1/BzFeWyw4AuIeZLwXwrfK7IAiC0BExXCtmcPrbAdxR\nfr4DwO9HOIYgCILgoNXITiL6SwCnULhW/hMz/xkR/ZyZX1H+TgBOqu/adjKyUxCEqKwRTYjZ4gg1\npqvsh29k5ieJ6FwA9xDRI/qPzMxkXFxBEISYmAIOjFPEfbQScmZ+svz/DBF9GcCVAE4Q0fnM/BQR\nXQDgadu2RHRI+3qEmY+0KYuwhV6xVYVeI+JFZrL9Jgi5MnYRJ6I9APZUrtfUtUJELwVwFjP/kohe\nBuBuAP8OwFsAPMvMy0R0AMAOZj5gbJula8VWaRRdVp66x/Wt79uHa7s6xzAfFlXHFISmjF3Ebbi0\ns42QXwLgy+XXswF8npn/Qxl+eCeAvwVH+GFOQl5XFHWUqLWpXG2Onytjb4xCc6raw9jrTnQh76Iw\nqdCHeIZUuFkUcZOxN0yhPkO9GaeACDm2KkAMd0Rs9DINXZYcGHuDFbYw2+0sW+VZC7lPgEO3tSHi\nOR7G3HhnGbNzfpZFHEhQyB/q/ajCrDD2xjwrNDGuxnDvfed9GYAu4sgFITnqRN8IaTIrb8ixzlOE\nXJgZ2kYQCQXyoIxDzIeVCLkgCMH4xCcFKzrFh3Uf10WEXBg9qTXsronlW7aJYuiAr6FI7V73da1E\nyIXRklqj7oJYQuFKOCUpHeozxINOolaEUZKr6KRs7eZG33Wgj3snUSvCzJCjiIuAx2eW3iZEyAWh\nY2wD2kS4+yV2rvLU7p+4VgTBgiQ6E/SO3VQ6eV2uFRFyQRCETHAJeYw5OwVBEIQBESEXBEHIHBFy\nQRCEzBEhFwRByBwRckEQhMwRIRcEQcgcEXJBEITMESEXBEHIHBFyQRCEzOlEyInoGiJ6hIgeI6Kl\nLo4hCIIgFEQXciI6C8BhANcA2A1gLxG9NvZxhuB7QxegBVL2/sm13EC+Zc+13EC7sndhkV8J4HFm\nPsbMzwH4rwCu6+A4vfP9oQvQAil7/+RabiDfsudabqBd2bsQ8osA/Ez7frxcJgiCIHRAF0I+eKpH\nQRCEWSJ6Glsi+m0Ah5j5mvL7QQAvMPOyto6IvSAIQgN6yUdORGcD+D8A/j6AvwLwXQB7mfknUQ8k\nCIIgAOhgqjdmPkNE+wF8E8BZAD4tIi4IgtAdg8wQJAiCIMSj15GdqQ8UIqLPENEJInpYW7ZARPcQ\n0aNEdDcR7dB+O1ieyyNEdPUwpQaIaCcR3UdEPyaiHxHRBzIq+4uJ6DtE9GBZ9kO5lL0sy1lE9AAR\nfa38nku5jxHRWln275bLki87Ee0goruI6CdEdJSIrsqk3L9ZXmv1d4qIPhCt7Mzcyx8KN8vjAHYB\nOAfAgwBe29fxA8v4uwCuAPCwtuxjAP51+XkJwEfLz7vLczinPKfHAbxooHKfD+Dy8vPLUfRRvDaH\nspfleWn5/2wA9wO4KqOy/0sAnwfw1VzqS1menwJYMJYlX3YAdwB4j1ZftudQbuMcXgTgSQA7Y5W9\nz8L/XQB/rn0/AODA0BfVUs5dmBTyRwCcV34+H8Aj5eeDAJa09f4cwG8PXf6yLF8B8Jbcyg7gpQB+\ngGJQWfJlB3AxgHsBvBnA13KqL6WQv9JYlnTZS9H+S8vypMttKe/VAL4ds+x9ulZyHSh0HjOfKD+f\nAHBe+flCFOegSOJ8iGgXireK7yCTshPRi4joQRRlvJuZv4s8yv4fAfwrAC9oy3IoN1CM97iXiL5P\nRP+sXJZ62S8B8AwRfZaIfkhEf0ZEL0P65TZ5J4DV8nOUsvcp5Nn3qnLxaPSdx6DnSEQvB/BFAB9k\n5l/qv6VcdmZ+gZkvR2HhXkVErzN+T67sRPQPADzNzA8AmIrrBdIst8YbmfkKANcC+BdE9Lv6j4mW\n/WwArwfwCWZ+PYD/h+LNfqtQaZZ7EyKaA/APAfw387c2Ze9TyJ9A4RNS7MTkEydVThDR+QBARBcA\neLpcbp7PxeWyQSCic1CI+OeY+Svl4izKrmDmUwDuA/A2pF/2vwfg7UT0UxTW1e8R0eeQfrkBAMz8\nZPn/GQBfRuHOSr3sxwEcZ2aVX+ouFML+VOLl1rkWwA/K6w5EuuZ9Cvn3AbyGiHaVT6XrAXy1x+M3\n5asA/qD8/Aco/M9q+TuJaI6ILgHwGhSDn3qHiAjApwEcZeY/0X7KoeyvUj31RPQSAG8F8BMkXnZm\nvpGZdzLzJShelf8HM78r9XIDABG9lIh+rfz8MhQ+24eReNmZ+SkAPyOiS8tFbwHwYwBfQ8LlNtiL\nLbcKEOua9+zkvxZFRMXjAA4O3elgKd8qitGop1H4898NYAFFh9ajAO4GsENb/8byXB4B8LYBy/07\nKPy0DwJ4oPy7JpOy/xaAHwJ4CIWY/JtyefJl18rzJmxFrSRfbhS+5gfLvx+ptphJ2S9DkfH1IQBf\nQtEBmny5y7K8DMD/BfBr2rIoZZcBQYIgCJkjU70JgiBkjgi5IAhC5oiQC4IgZI4IuSAIQuaIkAuC\nIGSOCLkgCELmiJALgiBkjgi5IAhC5vx/oWJ9OHx0YTwAAAAASUVORK5CYII=\n",
873 "text/plain": [
874 "<matplotlib.figure.Figure at 0x1125c5a90>"
875 ]
876 },
877 "metadata": {},
878 "output_type": "display_data"
879 }
880 ],
881 "source": [
882 "soilmvar = gfs.variables['Volumetric_Soil_Moisture_Content_depth_below_surface_layer']\n",
883 "# flip the data in latitude so North Hemisphere is up on the plot\n",
884 "soilm = soilmvar[0,0,::-1,:] \n",
885 "print('shape=%s, type=%s, missing_value=%s' % \\\n",
886 " (soilm.shape, type(soilm), soilmvar.missing_value))\n",
887 "import matplotlib.pyplot as plt\n",
888 "%matplotlib inline\n",
889 "cs = plt.contourf(soilm)"
890 ]
891 },
892 {
893 "cell_type": "markdown",
894 "metadata": {
895 "internals": {
896 "frag_helper": "fragment_end",
897 "frag_number": 32,
898 "slide_helper": "subslide_end"
899 },
900 "slide_helper": "slide_end",
901 "slideshow": {
902 "slide_type": "fragment"
903 }
904 },
905 "source": [
906 "##Packed integer data\n",
907 "There is a similar feature for variables with `scale_factor` and `add_offset` attributes.\n",
908 "\n",
909 "- short integer data will automatically be returned as float data, with the scale and offset applied. "
910 ]
911 },
912 {
913 "cell_type": "markdown",
914 "metadata": {
915 "internals": {
916 "frag_helper": "fragment_end",
917 "frag_number": 32,
918 "slide_type": "subslide"
919 },
920 "slideshow": {
921 "slide_type": "slide"
922 }
923 },
924 "source": [
925 "## Dealing with dates and times\n",
926 "- time variables usually measure relative to a fixed date using a certain calendar, with units specified like ***`hours since YY:MM:DD hh-mm-ss`***.\n",
927 "- **`num2date`** and **`date2num`** convenience functions provided to convert between these numeric time coordinates and handy python datetime instances. \n",
928 "- **`date2index`** finds the time index corresponding to a datetime instance."
929 ]
930 },
931 {
932 "cell_type": "code",
933 "execution_count": 22,
934 "metadata": {
935 "collapsed": false,
936 "internals": {
937 "frag_helper": "fragment_end",
938 "frag_number": 34
939 },
940 "slideshow": {
941 "slide_type": "fragment"
942 }
943 },
944 "outputs": [
945 {
946 "name": "stdout",
947 "output_type": "stream",
948 "text": [
949 "name of time dimension = time2\n",
950 "units = Hour since 2015-07-11T06:00:00Z, values = [ 0. 3. 6. 9. 12. 15. 18. 21. 24. 27. 30. 33.\n",
951 " 36. 39. 42. 45. 48. 51. 54. 57. 60. 63. 66. 69.\n",
952 " 72. 75. 78. 81. 84. 87. 90. 93. 96. 99. 102. 105.\n",
953 " 108. 111. 114. 117. 120. 123. 126. 129. 132. 135. 138. 141.\n",
954 " 144. 147. 150. 153. 156. 159. 162. 165. 168. 171. 174. 177.\n",
955 " 180. 183. 186. 189. 192. 195. 198. 201. 204. 207. 210. 213.\n",
956 " 216. 219. 222. 225. 228. 231. 234. 237. 240. 252. 264. 276.\n",
957 " 288. 300. 312. 324. 336. 348. 360. 372. 384.]\n"
958 ]
959 }
960 ],
961 "source": [
962 "from netCDF4 import num2date, date2num, date2index\n",
963 "timedim = sfctmp.dimensions[0] # time dim name\n",
964 "print('name of time dimension = %s' % timedim)\n",
965 "times = gfs.variables[timedim] # time coord var\n",
966 "print('units = %s, values = %s' % (times.units, times[:]))"
967 ]
968 },
969 {
970 "cell_type": "code",
971 "execution_count": 23,
972 "metadata": {
973 "collapsed": false,
974 "internals": {
975 "frag_helper": "fragment_end",
976 "frag_number": 35,
977 "slide_helper": "subslide_end"
978 },
979 "slide_helper": "slide_end",
980 "slideshow": {
981 "slide_type": "fragment"
982 }
983 },
984 "outputs": [
985 {
986 "name": "stdout",
987 "output_type": "stream",
988 "text": [
989 "['2015-07-11 06:00:00', '2015-07-11 09:00:00', '2015-07-11 12:00:00', '2015-07-11 15:00:00', '2015-07-11 18:00:00', '2015-07-11 21:00:00', '2015-07-12 00:00:00', '2015-07-12 03:00:00', '2015-07-12 06:00:00', '2015-07-12 09:00:00']\n"
990 ]
991 }
992 ],
993 "source": [
994 "dates = num2date(times[:], times.units)\n",
995 "print([date.strftime('%Y-%m-%d %H:%M:%S') for date in dates[:10]]) # print only first ten..."
996 ]
997 },
998 {
999 "cell_type": "markdown",
1000 "metadata": {
1001 "internals": {
1002 "frag_helper": "fragment_end",
1003 "frag_number": 35,
1004 "slide_type": "subslide"
1005 },
1006 "slideshow": {
1007 "slide_type": "slide"
1008 }
1009 },
1010 "source": [
1011 "###Get index associated with a specified date, extract forecast data for that date."
1012 ]
1013 },
1014 {
1015 "cell_type": "code",
1016 "execution_count": 24,
1017 "metadata": {
1018 "collapsed": false,
1019 "internals": {
1020 "frag_helper": "fragment_end",
1021 "frag_number": 37
1022 },
1023 "slideshow": {
1024 "slide_type": "fragment"
1025 }
1026 },
1027 "outputs": [
1028 {
1029 "name": "stdout",
1030 "output_type": "stream",
1031 "text": [
1032 "2015-07-14 07:22:39.579246\n",
1033 "index = 24, date = 2015-07-14 06:00:00\n"
1034 ]
1035 }
1036 ],
1037 "source": [
1038 "from datetime import datetime, timedelta\n",
1039 "date = datetime.now() + timedelta(days=3)\n",
1040 "print(date)\n",
1041 "ntime = date2index(date,times,select='nearest')\n",
1042 "print('index = %s, date = %s' % (ntime, dates[ntime]))"
1043 ]
1044 },
1045 {
1046 "cell_type": "markdown",
1047 "metadata": {
1048 "internals": {
1049 "frag_helper": "fragment_end",
1050 "frag_number": 38
1051 },
1052 "slideshow": {
1053 "slide_type": "fragment"
1054 }
1055 },
1056 "source": [
1057 "###Get temp forecast for Boulder (near 40N, -105W)\n",
1058 "- use function **`getcloses_ij`** we created before..."
1059 ]
1060 },
1061 {
1062 "cell_type": "code",
1063 "execution_count": 25,
1064 "metadata": {
1065 "collapsed": false,
1066 "internals": {
1067 "frag_helper": "fragment_end",
1068 "frag_number": 39,
1069 "slide_helper": "subslide_end"
1070 },
1071 "slide_helper": "slide_end",
1072 "slideshow": {
1073 "slide_type": "fragment"
1074 }
1075 },
1076 "outputs": [
1077 {
1078 "name": "stdout",
1079 "output_type": "stream",
1080 "text": [
1081 "Boulder forecast valid at 2015-07-14 06:00:00 UTC = 296.8 K\n"
1082 ]
1083 }
1084 ],
1085 "source": [
1086 "lats, lons = gfs.variables['lat'][:], gfs.variables['lon'][:]\n",
1087 "# lats, lons are 1-d. Make them 2-d using numpy.meshgrid.\n",
1088 "lons, lats = np.meshgrid(lons,lats)\n",
1089 "j, i = getclosest_ij(lats,lons,40,-105)\n",
1090 "fcst_temp = sfctmp[ntime,j,i]\n",
1091 "print('Boulder forecast valid at %s UTC = %5.1f %s' % \\\n",
1092 " (dates[ntime],fcst_temp,sfctmp.units))"
1093 ]
1094 },
1095 {
1096 "cell_type": "markdown",
1097 "metadata": {
1098 "internals": {
1099 "frag_helper": "fragment_end",
1100 "frag_number": 39,
1101 "slide_type": "subslide"
1102 },
1103 "slideshow": {
1104 "slide_type": "slide"
1105 }
1106 },
1107 "source": [
1108 "##Simple multi-file aggregation\n",
1109 "\n",
1110 "What if you have a bunch of netcdf files, each with data for a different year, and you want to access all the data as if it were in one file?"
1111 ]
1112 },
1113 {
1114 "cell_type": "code",
1115 "execution_count": 26,
1116 "metadata": {
1117 "collapsed": false,
1118 "internals": {
1119 "frag_helper": "fragment_end",
1120 "frag_number": 41
1121 },
1122 "slideshow": {
1123 "slide_type": "fragment"
1124 }
1125 },
1126 "outputs": [
1127 {
1128 "name": "stdout",
1129 "output_type": "stream",
1130 "text": [
1131 "-rw-r--r-- 1 jwhitaker staff 8985332 Jul 10 06:43 data/prmsl.2000.nc\r\n",
1132 "-rw-r--r-- 1 jwhitaker staff 8968789 Jul 10 06:43 data/prmsl.2001.nc\r\n",
1133 "-rw-r--r-- 1 jwhitaker staff 8972796 Jul 10 06:43 data/prmsl.2002.nc\r\n",
1134 "-rw-r--r-- 1 jwhitaker staff 8974435 Jul 10 06:43 data/prmsl.2003.nc\r\n",
1135 "-rw-r--r-- 1 jwhitaker staff 8997438 Jul 10 06:43 data/prmsl.2004.nc\r\n",
1136 "-rw-r--r-- 1 jwhitaker staff 8976678 Jul 10 06:43 data/prmsl.2005.nc\r\n",
1137 "-rw-r--r-- 1 jwhitaker staff 8969714 Jul 10 06:43 data/prmsl.2006.nc\r\n",
1138 "-rw-r--r-- 1 jwhitaker staff 8974360 Jul 10 06:43 data/prmsl.2007.nc\r\n",
1139 "-rw-r--r-- 1 jwhitaker staff 8994260 Jul 10 06:43 data/prmsl.2008.nc\r\n",
1140 "-rw-r--r-- 1 jwhitaker staff 8974678 Jul 10 06:43 data/prmsl.2009.nc\r\n",
1141 "-rw-r--r-- 1 jwhitaker staff 8970732 Jul 10 06:43 data/prmsl.2010.nc\r\n",
1142 "-rw-r--r-- 1 jwhitaker staff 8976285 Jul 10 06:43 data/prmsl.2011.nc\r\n"
1143 ]
1144 }
1145 ],
1146 "source": [
1147 "!ls -l data/prmsl*nc"
1148 ]
1149 },
1150 {
1151 "cell_type": "markdown",
1152 "metadata": {
1153 "internals": {
1154 "frag_helper": "fragment_end",
1155 "frag_number": 42
1156 },
1157 "slideshow": {
1158 "slide_type": "fragment"
1159 }
1160 },
1161 "source": [
1162 "**`MFDataset`** uses file globbing to patch together all the files into one big Dataset.\n",
1163 "You can also pass it a list of specific files.\n",
1164 "\n",
1165 "Limitations:\n",
1166 "\n",
1167 "- It can only aggregate the data along the leftmost dimension of each variable.\n",
1168 "- only works with `NETCDF3`, or `NETCDF4_CLASSIC` formatted files.\n",
1169 "- kind of slow."
1170 ]
1171 },
1172 {
1173 "cell_type": "code",
1174 "execution_count": 27,
1175 "metadata": {
1176 "collapsed": false,
1177 "internals": {
1178 "frag_helper": "fragment_end",
1179 "frag_number": 43,
1180 "slide_helper": "subslide_end"
1181 },
1182 "slide_helper": "slide_end",
1183 "slideshow": {
1184 "slide_type": "fragment"
1185 }
1186 },
1187 "outputs": [
1188 {
1189 "name": "stdout",
1190 "output_type": "stream",
1191 "text": [
1192 "starting date = 2000-01-01 00:00:00\n",
1193 "ending date = 2011-12-31 00:00:00\n",
1194 "times shape = 4383\n",
1195 "prmsl dimensions = (u'time', u'lat', u'lon'), prmsl shape = (4383, 91, 180)\n"
1196 ]
1197 }
1198 ],
1199 "source": [
1200 "mf = netCDF4.MFDataset('data/prmsl*nc')\n",
1201 "times = mf.variables['time']\n",
1202 "dates = num2date(times[:],times.units)\n",
1203 "print('starting date = %s' % dates[0])\n",
1204 "print('ending date = %s'% dates[-1])\n",
1205 "prmsl = mf.variables['prmsl']\n",
1206 "print('times shape = %s' % times.shape)\n",
1207 "print('prmsl dimensions = %s, prmsl shape = %s' %\\\n",
1208 " (prmsl.dimensions, prmsl.shape))"
1209 ]
1210 },
1211 {
1212 "cell_type": "markdown",
1213 "metadata": {
1214 "internals": {
1215 "frag_helper": "fragment_end",
1216 "frag_number": 43,
1217 "slide_type": "subslide"
1218 },
1219 "slideshow": {
1220 "slide_type": "slide"
1221 }
1222 },
1223 "source": [
1224 "## Closing your netCDF file\n",
1225 "\n",
1226 "It's good to close netCDF files, but not actually necessary when Dataset is open for read access only.\n"
1227 ]
1228 },
1229 {
1230 "cell_type": "code",
1231 "execution_count": 28,
1232 "metadata": {
1233 "collapsed": false,
1234 "internals": {
1235 "frag_helper": "fragment_end",
1236 "frag_number": 45
1237 },
1238 "slideshow": {
1239 "slide_type": "fragment"
1240 }
1241 },
1242 "outputs": [],
1243 "source": [
1244 "f.close()\n",
1245 "gfs.close()"
1246 ]
1247 },
1248 {
1249 "cell_type": "markdown",
1250 "metadata": {
1251 "internals": {
1252 "frag_helper": "fragment_end",
1253 "frag_number": 45,
1254 "slide_helper": "subslide_end"
1255 },
1256 "slide_helper": "slide_end",
1257 "slideshow": {
1258 "slide_type": "-"
1259 }
1260 },
1261 "source": [
1262 "##That's it!\n",
1263 "\n",
1264 "Now you're ready to start exploring your data interactively.\n",
1265 "\n",
1266 "To be continued with **Writing netCDF data** ...."
1267 ]
1268 }
1269 ],
1270 "metadata": {
1271 "celltoolbar": "Raw Cell Format",
1272 "kernelspec": {
1273 "display_name": "Python 2",
1274 "language": "python",
1275 "name": "python2"
1276 },
1277 "language_info": {
1278 "codemirror_mode": {
1279 "name": "ipython",
1280 "version": 2
1281 },
1282 "file_extension": ".py",
1283 "mimetype": "text/x-python",
1284 "name": "python",
1285 "nbconvert_exporter": "python",
1286 "pygments_lexer": "ipython2",
1287 "version": "2.7.9"
1288 }
1289 },
1290 "nbformat": 4,
1291 "nbformat_minor": 0
1292 }
7979
8080 print(rootgrp.variables)
8181
82 import numpy
82 import numpy as np
8383 # no unlimited dimension, just assign to slice.
84 lats = numpy.arange(-90,91,2.5)
85 lons = numpy.arange(-180,180,2.5)
84 lats = np.arange(-90,91,2.5)
85 lons = np.arange(-180,180,2.5)
8686 latitudes[:] = lats
8787 longitudes[:] = lons
8888 print('latitudes =\n',latitudes[:])
122122 f = Dataset('mftest'+repr(nfile)+'.nc','w',format='NETCDF4_CLASSIC')
123123 f.createDimension('x',None)
124124 x = f.createVariable('x','i',('x',))
125 x[0:10] = numpy.arange(nfile*10,10*(nfile+1))
125 x[0:10] = np.arange(nfile*10,10*(nfile+1))
126126 f.close()
127127 # now read all those files in at once, in one Dataset.
128128 from netCDF4 import MFDataset
133133 f = Dataset('complex.nc','w')
134134 size = 3 # length of 1-d complex array
135135 # create sample complex data.
136 datac = numpy.exp(1j*(1.+numpy.linspace(0, numpy.pi, size)))
136 datac = np.exp(1j*(1.+np.linspace(0, np.pi, size)))
137137 print(datac.dtype)
138138 # create complex128 compound data type.
139 complex128 = numpy.dtype([('real',numpy.float64),('imag',numpy.float64)])
139 complex128 = np.dtype([('real',np.float64),('imag',np.float64)])
140140 complex128_t = f.createCompoundType(complex128,'complex128')
141141 # create a variable with this data type, write some data to it.
142142 f.createDimension('x_dim',None)
143143 v = f.createVariable('cmplx_var',complex128_t,'x_dim')
144 data = numpy.empty(size,complex128) # numpy structured array
144 data = np.empty(size,complex128) # numpy structured array
145145 data['real'] = datac.real; data['imag'] = datac.imag
146146 v[:] = data
147147 # close and reopen the file, check the contents.
155155 print(v.shape)
156156 datain = v[:] # read in all the data into a numpy structured array
157157 # create an empty numpy complex array
158 datac2 = numpy.empty(datain.shape,numpy.complex128)
158 datac2 = np.empty(datain.shape,np.complex128)
159159 # .. fill it with contents of structured array.
160160 datac2.real = datain['real']
161161 datac2.imag = datain['imag']
167167 # create an unlimited dimension call 'station'
168168 f.createDimension('station',None)
169169 # 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')])
170 winddtype = np.dtype([('speed','f4'),('direction','i4')])
171 statdtype = np.dtype([('latitude', 'f4'), ('longitude', 'f4'),
172 ('surface_wind',winddtype),
173 ('temp_sounding','f4',10),('press_sounding','i4',10),
174 ('location_name','S12')])
175175 # use this data type definitions to create a compound data types
176176 # called using the createCompoundType Dataset method.
177177 # create a compound type for vector wind which will be nested inside
180180 # now that wind_data_t is defined, create the station data type.
181181 station_data_t = f.createCompoundType(statdtype,'station_data')
182182 # 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')])
183 winddtype_units = np.dtype([('speed','S12'),('direction','S12')])
184 statdtype_units = np.dtype([('latitude', 'S12'), ('longitude', 'S12'),
185 ('surface_wind',winddtype_units),
186 ('temp_sounding','S12'),
187 ('location_name','S12'),
188 ('press_sounding','S12')])
189189 # create the wind_data_units type first, since it will nested inside
190190 # the station_data_units data type.
191191 wind_data_units_t = f.createCompoundType(winddtype_units,'wind_data_units')
194194 # create a variable of of type 'station_data_t'
195195 statdat = f.createVariable('station_obs', station_data_t, ('station',))
196196 # create a numpy structured array, assign data to it.
197 data = numpy.empty(1,statdtype)
197 data = np.empty(1,statdtype)
198198 data['latitude'] = 40.
199199 data['longitude'] = -105.
200200 data['surface_wind']['speed'] = 12.5
206206 statdat[0] = data
207207 # or just assign a tuple of values to variable slice
208208 # (will automatically be converted to a structured array).
209 statdat[1] = numpy.array((40.78,-73.99,(-12.5,90),
209 statdat[1] = np.array((40.78,-73.99,(-12.5,90),
210210 (290.2,282.5,279.,277.9,276.,266.,264.1,260.,255.5,243.),
211211 range(900,400,-50),'New York, NY'),data.dtype)
212212 print(f.cmptypes)
213 windunits = numpy.empty(1,winddtype_units)
214 stationobs_units = numpy.empty(1,statdtype_units)
213 windunits = np.empty(1,winddtype_units)
214 stationobs_units = np.empty(1,statdtype_units)
215215 windunits['speed'] = 'm/s'
216216 windunits['direction'] = 'degrees'
217217 stationobs_units['latitude'] = 'degrees N'
234234 f.close()
235235
236236 f = Dataset('tst_vlen.nc','w')
237 vlen_t = f.createVLType(numpy.int32, 'phony_vlen')
237 vlen_t = f.createVLType(np.int32, 'phony_vlen')
238238 x = f.createDimension('x',3)
239239 y = f.createDimension('y',4)
240240 vlvar = f.createVariable('phony_vlen_var', vlen_t, ('y','x'))
241241 import random
242 data = numpy.empty(len(y)*len(x),object)
242 data = np.empty(len(y)*len(x),object)
243243 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)))
244 data[n] = np.arange(random.randint(1,10),dtype='int32')+1
245 data = np.reshape(data,(len(y),len(x)))
246246 vlvar[:] = data
247247 print(vlvar)
248248 print('vlen variable =\n',vlvar[:])
252252 z = f.createDimension('z', 10)
253253 strvar = f.createVariable('strvar',str,'z')
254254 chars = '1234567890aabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
255 data = numpy.empty(10,object)
255 data = np.empty(10,object)
256256 for n in range(10):
257257 stringlen = random.randint(2,12)
258258 data[n] = ''.join([random.choice(chars) for i in range(stringlen)])
269269 u'Nimbostratus': 6, u'Cumulus': 4, u'Altostratus': 5, u'Cumulonimbus': 1,
270270 u'Stratocumulus': 3}
271271 # create the Enum type called 'cloud_t'.
272 cloud_type = f.createEnumType(numpy.uint8,'cloud_t',enum_dict)
272 cloud_type = f.createEnumType(np.uint8,'cloud_t',enum_dict)
273273 print(cloud_type)
274274 time = f.createDimension('time',None)
275275 # create a 1d variable of type 'cloud_type' called 'primary_clouds'.
294294 nc.createDimension('nchars',3)
295295 nc.createDimension('nstrings',None)
296296 v = nc.createVariable('strings','S1',('nstrings','nchars'))
297 datain = numpy.array(['foo','bar'],dtype='S3')
297 datain = np.array(['foo','bar'],dtype='S3')
298298 v[:] = stringtochar(datain) # manual conversion to char array
299299 print(v[:]) # data returned as char array
300300 v._Encoding = 'ascii' # this enables automatic conversion
303303 nc.close()
304304 # strings in compound types
305305 nc = Dataset('compoundstring_example.nc','w')
306 dtype = numpy.dtype([('observation', 'f4'),
307 ('station_name','S12')])
306 dtype = np.dtype([('observation', 'f4'),
307 ('station_name','S12')])
308308 station_data_t = nc.createCompoundType(dtype,'station_data')
309309 nc.createDimension('station',None)
310310 statdat = nc.createVariable('station_obs', station_data_t, ('station',))
311 data = numpy.empty(2,station_data_t.dtype_view)
311 data = np.empty(2,station_data_t.dtype_view)
312312 data['observation'][:] = (123.,3.14)
313313 data['station_name'][:] = ('Boulder','New York')
314314 print(statdat.dtype) # strings actually stored as character arrays
324324 # to disk when it is closed.
325325 nc = Dataset('diskless_example.nc','w',diskless=True,persist=True)
326326 d = nc.createDimension('x',None)
327 v = nc.createVariable('v',numpy.int32,'x')
328 v[0:5] = numpy.arange(5)
327 v = nc.createVariable('v',np.int32,'x')
328 v[0:5] = np.arange(5)
329329 print(nc)
330330 print(nc['v'][:])
331331 nc.close() # file saved to disk
344344 # used if format is NETCDF3 (ignored for NETCDF4/HDF5 files).
345345 nc = Dataset('inmemory.nc', mode='w',memory=1028)
346346 d = nc.createDimension('x',None)
347 v = nc.createVariable('v',numpy.int32,'x')
348 v[0:5] = numpy.arange(5)
347 v = nc.createVariable('v',np.int32,'x')
348 v[0:5] = np.arange(5)
349349 nc_buf = nc.close() # close returns memoryview
350350 print(type(nc_buf))
351351 # save nc_buf to disk, read it back in and check.
+0
-1206
examples/writing_netCDF.ipynb less more
0 {
1 "cells": [
2 {
3 "cell_type": "markdown",
4 "metadata": {
5 "internals": {
6 "slide_type": "subslide"
7 },
8 "slideshow": {
9 "slide_type": "slide"
10 }
11 },
12 "source": [
13 "# Writing netCDF data\n",
14 "\n",
15 "**Important Note**: when running this notebook interactively in a browser, you probably will not be able to execute individual cells out of order without getting an error. Instead, choose \"Run All\" from the Cell menu after you modify a cell."
16 ]
17 },
18 {
19 "cell_type": "code",
20 "execution_count": 25,
21 "metadata": {
22 "collapsed": false,
23 "internals": {
24 "frag_number": 1,
25 "slide_helper": "subslide_end"
26 },
27 "slide_helper": "slide_end",
28 "slideshow": {
29 "slide_type": "fragment"
30 }
31 },
32 "outputs": [],
33 "source": [
34 "import netCDF4 # Note: python is case-sensitive!\n",
35 "import numpy as np"
36 ]
37 },
38 {
39 "cell_type": "markdown",
40 "metadata": {
41 "internals": {
42 "frag_helper": "fragment_end",
43 "frag_number": 1,
44 "slide_type": "subslide"
45 },
46 "slideshow": {
47 "slide_type": "slide"
48 }
49 },
50 "source": [
51 "## Opening a file, creating a new Dataset\n",
52 "\n",
53 "Let's create a new, empty netCDF file named 'data/new.nc', opened for writing.\n",
54 "\n",
55 "Be careful, opening a file with 'w' will clobber any existing data (unless `clobber=False` is used, in which case an exception is raised if the file already exists).\n",
56 "\n",
57 "- `mode='r'` is the default.\n",
58 "- `mode='a'` opens an existing file and allows for appending (does not clobber existing data)\n",
59 "- `format` can be one of `NETCDF3_CLASSIC`, `NETCDF3_64BIT`, `NETCDF4_CLASSIC` or `NETCDF4` (default). `NETCDF4_CLASSIC` uses HDF5 for the underlying storage layer (as does `NETCDF4`) but enforces the classic netCDF 3 data model so data can be read with older clients. "
60 ]
61 },
62 {
63 "cell_type": "code",
64 "execution_count": 26,
65 "metadata": {
66 "collapsed": false,
67 "internals": {
68 "frag_helper": "fragment_end",
69 "frag_number": 3,
70 "slide_helper": "subslide_end"
71 },
72 "slide_helper": "slide_end",
73 "slideshow": {
74 "slide_type": "fragment"
75 }
76 },
77 "outputs": [
78 {
79 "name": "stdout",
80 "output_type": "stream",
81 "text": [
82 "<type 'netCDF4._netCDF4.Dataset'>\n",
83 "root group (NETCDF4_CLASSIC data model, file format HDF5):\n",
84 " dimensions(sizes): \n",
85 " variables(dimensions): \n",
86 " groups: \n",
87 "\n"
88 ]
89 }
90 ],
91 "source": [
92 "try: ncfile.close() # just to be safe, make sure dataset is not already open.\n",
93 "except: pass\n",
94 "ncfile = netCDF4.Dataset('data/new.nc',mode='w',format='NETCDF4_CLASSIC') \n",
95 "print(ncfile)"
96 ]
97 },
98 {
99 "cell_type": "markdown",
100 "metadata": {
101 "internals": {
102 "frag_helper": "fragment_end",
103 "frag_number": 3,
104 "slide_type": "subslide"
105 },
106 "slideshow": {
107 "slide_type": "slide"
108 }
109 },
110 "source": [
111 "## Creating dimensions\n",
112 "\n",
113 "The **ncfile** object we created is a container for _dimensions_, _variables_, and _attributes_. First, let's create some dimensions using the [`createDimension`](http://unidata.github.io/netcdf4-python/netCDF4.Dataset-class.html#createDimension) method. \n",
114 "\n",
115 "- Every dimension has a name and a length. \n",
116 "- The name is a string that is used to specify the dimension to be used when creating a variable, and as a key to access the dimension object in the `ncfile.dimensions` dictionary.\n",
117 "\n",
118 "Setting the dimension length to `0` or `None` makes it unlimited, so it can grow. \n",
119 "\n",
120 "- For `NETCDF4` files, any variable's dimension can be unlimited. \n",
121 "- For `NETCDF4_CLASSIC` and `NETCDF3*` files, only one per variable can be unlimited, and it must be the leftmost (fastest varying) dimension."
122 ]
123 },
124 {
125 "cell_type": "code",
126 "execution_count": 27,
127 "metadata": {
128 "collapsed": false,
129 "internals": {
130 "frag_helper": "fragment_end",
131 "frag_number": 5,
132 "slide_helper": "subslide_end"
133 },
134 "slide_helper": "slide_end",
135 "slideshow": {
136 "slide_type": "fragment"
137 }
138 },
139 "outputs": [
140 {
141 "name": "stdout",
142 "output_type": "stream",
143 "text": [
144 "('lat', <type 'netCDF4._netCDF4.Dimension'>: name = 'lat', size = 73\n",
145 ")\n",
146 "('lon', <type 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 144\n",
147 ")\n",
148 "('time', <type 'netCDF4._netCDF4.Dimension'> (unlimited): name = 'time', size = 0\n",
149 ")\n"
150 ]
151 }
152 ],
153 "source": [
154 "lat_dim = ncfile.createDimension('lat', 73) # latitude axis\n",
155 "lon_dim = ncfile.createDimension('lon', 144) # longitude axis\n",
156 "time_dim = ncfile.createDimension('time', None) # unlimited axis (can be appended to).\n",
157 "for dim in ncfile.dimensions.items():\n",
158 " print(dim)"
159 ]
160 },
161 {
162 "cell_type": "markdown",
163 "metadata": {
164 "internals": {
165 "frag_helper": "fragment_end",
166 "frag_number": 5,
167 "slide_type": "subslide"
168 },
169 "slideshow": {
170 "slide_type": "slide"
171 }
172 },
173 "source": [
174 "## Creating attributes\n",
175 "\n",
176 "netCDF attributes can be created just like you would for any python object. \n",
177 "\n",
178 "- Best to adhere to established conventions (like the [CF](http://cfconventions.org/) conventions)\n",
179 "- We won't try to adhere to any specific convention here though."
180 ]
181 },
182 {
183 "cell_type": "code",
184 "execution_count": 28,
185 "metadata": {
186 "collapsed": false,
187 "internals": {
188 "frag_helper": "fragment_end",
189 "frag_number": 7
190 },
191 "slideshow": {
192 "slide_type": "fragment"
193 }
194 },
195 "outputs": [
196 {
197 "name": "stdout",
198 "output_type": "stream",
199 "text": [
200 "My model data\n"
201 ]
202 }
203 ],
204 "source": [
205 "ncfile.title='My model data'\n",
206 "print(ncfile.title)"
207 ]
208 },
209 {
210 "cell_type": "markdown",
211 "metadata": {
212 "internals": {
213 "frag_helper": "fragment_end",
214 "frag_number": 8,
215 "slide_helper": "subslide_end"
216 },
217 "slide_helper": "slide_end",
218 "slideshow": {
219 "slide_type": "fragment"
220 }
221 },
222 "source": [
223 "Try adding some more attributes..."
224 ]
225 },
226 {
227 "cell_type": "markdown",
228 "metadata": {
229 "internals": {
230 "frag_helper": "fragment_end",
231 "frag_number": 8,
232 "slide_type": "subslide"
233 },
234 "slideshow": {
235 "slide_type": "slide"
236 }
237 },
238 "source": [
239 "## Creating variables\n",
240 "\n",
241 "Now let's add some variables and store some data in them. \n",
242 "\n",
243 "- A variable has a name, a type, a shape, and some data values. \n",
244 "- The shape of a variable is specified by a tuple of dimension names. \n",
245 "- A variable should also have some named attributes, such as 'units', that describe the data.\n",
246 "\n",
247 "The [`createVariable`](http://unidata.github.io/netcdf4-python/netCDF4.Dataset-class.html#createVariable) method takes 3 mandatory args.\n",
248 "\n",
249 "- the 1st argument is the variable name (a string). This is used as the key to access the variable object from the `variables` dictionary.\n",
250 "- the 2nd argument is the datatype (most numpy datatypes supported). \n",
251 "- the third argument is a tuple containing the dimension names (the dimensions must be created first). Unless this is a `NETCDF4` file, any unlimited dimension must be the leftmost one.\n",
252 "- there are lots of optional arguments (many of which are only relevant when `format='NETCDF4'`) to control compression, chunking, fill_value, etc.\n"
253 ]
254 },
255 {
256 "cell_type": "code",
257 "execution_count": 29,
258 "metadata": {
259 "collapsed": false,
260 "internals": {
261 "frag_helper": "fragment_end",
262 "frag_number": 10,
263 "slide_helper": "subslide_end"
264 },
265 "slide_helper": "slide_end",
266 "slideshow": {
267 "slide_type": "fragment"
268 }
269 },
270 "outputs": [
271 {
272 "name": "stdout",
273 "output_type": "stream",
274 "text": [
275 "<type 'netCDF4._netCDF4.Variable'>\n",
276 "float64 temp(time, lat, lon)\n",
277 " units: K\n",
278 " standard_name: air_temperature\n",
279 "unlimited dimensions: time\n",
280 "current shape = (0, 73, 144)\n",
281 "filling on, default _FillValue of 9.96920996839e+36 used\n",
282 "\n"
283 ]
284 }
285 ],
286 "source": [
287 "# Define two variables with the same names as dimensions,\n",
288 "# a conventional way to define \"coordinate variables\".\n",
289 "lat = ncfile.createVariable('lat', np.float32, ('lat',))\n",
290 "lat.units = 'degrees_north'\n",
291 "lat.long_name = 'latitude'\n",
292 "lon = ncfile.createVariable('lon', np.float32, ('lon',))\n",
293 "lon.units = 'degrees_east'\n",
294 "lon.long_name = 'longitude'\n",
295 "time = ncfile.createVariable('time', np.float64, ('time',))\n",
296 "time.units = 'hours since 1800-01-01'\n",
297 "time.long_name = 'time'\n",
298 "# Define a 3D variable to hold the data\n",
299 "temp = ncfile.createVariable('temp',np.float64,('time','lat','lon')) # note: unlimited dimension is leftmost\n",
300 "temp.units = 'K' # degrees Kelvin\n",
301 "temp.standard_name = 'air_temperature' # this is a CF standard name\n",
302 "print(temp)"
303 ]
304 },
305 {
306 "cell_type": "markdown",
307 "metadata": {
308 "internals": {
309 "frag_helper": "fragment_end",
310 "frag_number": 10,
311 "slide_type": "subslide"
312 },
313 "slideshow": {
314 "slide_type": "slide"
315 }
316 },
317 "source": [
318 "## Pre-defined variable attributes (read only)\n",
319 "\n",
320 "The netCDF4 module provides some useful pre-defined Python attributes for netCDF variables, such as dimensions, shape, dtype, ndim. \n",
321 "\n",
322 "Note: since no data has been written yet, the length of the 'time' dimension is 0."
323 ]
324 },
325 {
326 "cell_type": "code",
327 "execution_count": 30,
328 "metadata": {
329 "collapsed": false,
330 "internals": {
331 "frag_helper": "fragment_end",
332 "frag_number": 12,
333 "slide_helper": "subslide_end"
334 },
335 "slide_helper": "slide_end",
336 "slideshow": {
337 "slide_type": "fragment"
338 }
339 },
340 "outputs": [
341 {
342 "name": "stdout",
343 "output_type": "stream",
344 "text": [
345 "-- Some pre-defined attributes for variable temp:\n",
346 "('temp.dimensions:', (u'time', u'lat', u'lon'))\n",
347 "('temp.shape:', (0, 73, 144))\n",
348 "('temp.dtype:', dtype('float64'))\n",
349 "('temp.ndim:', 3)\n"
350 ]
351 }
352 ],
353 "source": [
354 "print(\"-- Some pre-defined attributes for variable temp:\")\n",
355 "print(\"temp.dimensions:\", temp.dimensions)\n",
356 "print(\"temp.shape:\", temp.shape)\n",
357 "print(\"temp.dtype:\", temp.dtype)\n",
358 "print(\"temp.ndim:\", temp.ndim)"
359 ]
360 },
361 {
362 "cell_type": "markdown",
363 "metadata": {
364 "internals": {
365 "frag_helper": "fragment_end",
366 "frag_number": 12,
367 "slide_type": "subslide"
368 },
369 "slideshow": {
370 "slide_type": "slide"
371 }
372 },
373 "source": [
374 "## Writing data\n",
375 "\n",
376 "To write data to a netCDF variable object, just treat it like a numpy array and assign values to a slice."
377 ]
378 },
379 {
380 "cell_type": "code",
381 "execution_count": 31,
382 "metadata": {
383 "collapsed": false,
384 "internals": {
385 "frag_helper": "fragment_end",
386 "frag_number": 14
387 },
388 "slideshow": {
389 "slide_type": "fragment"
390 }
391 },
392 "outputs": [
393 {
394 "name": "stdout",
395 "output_type": "stream",
396 "text": [
397 "('-- Wrote data, temp.shape is now ', (3, 73, 144))\n",
398 "('-- Min/Max values:', 280.00283562143028, 329.99987991477548)\n"
399 ]
400 }
401 ],
402 "source": [
403 "nlats = len(lat_dim); nlons = len(lon_dim); ntimes = 3\n",
404 "# Write latitudes, longitudes.\n",
405 "# Note: the \":\" is necessary in these \"write\" statements\n",
406 "lat[:] = -90. + (180./nlats)*np.arange(nlats) # south pole to north pole\n",
407 "lon[:] = (180./nlats)*np.arange(nlons) # Greenwich meridian eastward\n",
408 "# create a 3D array of random numbers\n",
409 "data_arr = np.random.uniform(low=280,high=330,size=(ntimes,nlats,nlons))\n",
410 "# Write the data. This writes the whole 3D netCDF variable all at once.\n",
411 "temp[:,:,:] = data_arr # Appends data along unlimited dimension\n",
412 "print(\"-- Wrote data, temp.shape is now \", temp.shape)\n",
413 "# read data back from variable (by slicing it), print min and max\n",
414 "print(\"-- Min/Max values:\", temp[:,:,:].min(), temp[:,:,:].max())"
415 ]
416 },
417 {
418 "cell_type": "markdown",
419 "metadata": {
420 "internals": {
421 "frag_helper": "fragment_end",
422 "frag_number": 15,
423 "slide_helper": "subslide_end"
424 },
425 "slide_helper": "slide_end",
426 "slideshow": {
427 "slide_type": "fragment"
428 }
429 },
430 "source": [
431 "- You can just treat a netCDF Variable object like a numpy array and assign values to it.\n",
432 "- Variables automatically grow along unlimited dimensions (unlike numpy arrays)\n",
433 "- The above writes the whole 3D variable all at once, but you can write it a slice at a time instead.\n",
434 "\n",
435 "Let's add another time slice....\n"
436 ]
437 },
438 {
439 "cell_type": "code",
440 "execution_count": 32,
441 "metadata": {
442 "collapsed": false,
443 "internals": {
444 "frag_helper": "fragment_end",
445 "frag_number": 15,
446 "slide_type": "subslide"
447 },
448 "slideshow": {
449 "slide_type": "slide"
450 }
451 },
452 "outputs": [
453 {
454 "name": "stdout",
455 "output_type": "stream",
456 "text": [
457 "('-- Wrote more data, temp.shape is now ', (4, 73, 144))\n"
458 ]
459 }
460 ],
461 "source": [
462 "# create a 2D array of random numbers\n",
463 "data_slice = np.random.uniform(low=280,high=330,size=(nlats,nlons))\n",
464 "temp[3,:,:] = data_slice # Appends the 4th time slice\n",
465 "print(\"-- Wrote more data, temp.shape is now \", temp.shape)"
466 ]
467 },
468 {
469 "cell_type": "markdown",
470 "metadata": {
471 "internals": {
472 "frag_helper": "fragment_end",
473 "frag_number": 17
474 },
475 "slideshow": {
476 "slide_type": "fragment"
477 }
478 },
479 "source": [
480 "Note that we have not yet written any data to the time variable. It automatically grew as we appended data along the time dimension to the variable `temp`, but the data is missing."
481 ]
482 },
483 {
484 "cell_type": "code",
485 "execution_count": 33,
486 "metadata": {
487 "collapsed": false,
488 "internals": {
489 "frag_helper": "fragment_end",
490 "frag_number": 18,
491 "slide_helper": "subslide_end"
492 },
493 "slide_helper": "slide_end",
494 "slideshow": {
495 "slide_type": "fragment"
496 }
497 },
498 "outputs": [
499 {
500 "name": "stdout",
501 "output_type": "stream",
502 "text": [
503 "<type 'netCDF4._netCDF4.Variable'>\n",
504 "float64 time(time)\n",
505 " units: hours since 1800-01-01\n",
506 " long_name: time\n",
507 "unlimited dimensions: time\n",
508 "current shape = (4,)\n",
509 "filling on, default _FillValue of 9.96920996839e+36 used\n",
510 "\n",
511 "(<class 'numpy.ma.core.MaskedArray'>, masked_array(data = [-- -- -- --],\n",
512 " mask = [ True True True True],\n",
513 " fill_value = 9.96920996839e+36)\n",
514 ")\n"
515 ]
516 }
517 ],
518 "source": [
519 "print(time)\n",
520 "times_arr = time[:]\n",
521 "print(type(times_arr),times_arr) # dashes indicate masked values (where data has not yet been written)"
522 ]
523 },
524 {
525 "cell_type": "markdown",
526 "metadata": {
527 "internals": {
528 "frag_helper": "fragment_end",
529 "frag_number": 18,
530 "slide_type": "subslide"
531 },
532 "slideshow": {
533 "slide_type": "slide"
534 }
535 },
536 "source": [
537 "Let's add write some data into the time variable. \n",
538 "\n",
539 "- Given a set of datetime instances, use date2num to convert to numeric time values and then write that data to the variable."
540 ]
541 },
542 {
543 "cell_type": "code",
544 "execution_count": 34,
545 "metadata": {
546 "collapsed": false,
547 "internals": {
548 "frag_helper": "fragment_end",
549 "frag_number": 20,
550 "slide_helper": "subslide_end"
551 },
552 "slide_helper": "slide_end",
553 "slideshow": {
554 "slide_type": "fragment"
555 }
556 },
557 "outputs": [
558 {
559 "name": "stdout",
560 "output_type": "stream",
561 "text": [
562 "[datetime.datetime(2014, 10, 1, 0, 0), datetime.datetime(2014, 10, 2, 0, 0), datetime.datetime(2014, 10, 3, 0, 0), datetime.datetime(2014, 10, 4, 0, 0)]\n",
563 "(array([ 1882440., 1882464., 1882488., 1882512.]), u'hours since 1800-01-01')\n",
564 "[datetime.datetime(2014, 10, 1, 0, 0) datetime.datetime(2014, 10, 2, 0, 0)\n",
565 " datetime.datetime(2014, 10, 3, 0, 0) datetime.datetime(2014, 10, 4, 0, 0)]\n"
566 ]
567 }
568 ],
569 "source": [
570 "from datetime import datetime\n",
571 "from netCDF4 import date2num,num2date\n",
572 "# 1st 4 days of October.\n",
573 "dates = [datetime(2014,10,1,0),datetime(2014,10,2,0),datetime(2014,10,3,0),datetime(2014,10,4,0)]\n",
574 "print(dates)\n",
575 "times = date2num(dates, time.units)\n",
576 "print(times, time.units) # numeric values\n",
577 "time[:] = times\n",
578 "# read time data back, convert to datetime instances, check values.\n",
579 "print(num2date(time[:],time.units))"
580 ]
581 },
582 {
583 "cell_type": "markdown",
584 "metadata": {
585 "internals": {
586 "frag_helper": "fragment_end",
587 "frag_number": 20,
588 "slide_type": "subslide"
589 },
590 "slideshow": {
591 "slide_type": "slide"
592 }
593 },
594 "source": [
595 "## Closing a netCDF file\n",
596 "\n",
597 "It's **important** to close a netCDF file you opened for writing:\n",
598 "\n",
599 "- flushes buffers to make sure all data gets written\n",
600 "- releases memory resources used by open netCDF files"
601 ]
602 },
603 {
604 "cell_type": "code",
605 "execution_count": 35,
606 "metadata": {
607 "collapsed": false,
608 "internals": {
609 "frag_helper": "fragment_end",
610 "frag_number": 22,
611 "slide_helper": "subslide_end"
612 },
613 "slide_helper": "slide_end",
614 "slideshow": {
615 "slide_type": "fragment"
616 }
617 },
618 "outputs": [
619 {
620 "name": "stdout",
621 "output_type": "stream",
622 "text": [
623 "<type 'netCDF4._netCDF4.Dataset'>\n",
624 "root group (NETCDF4_CLASSIC data model, file format HDF5):\n",
625 " title: My model data\n",
626 " dimensions(sizes): lat(73), lon(144), time(4)\n",
627 " variables(dimensions): float32 \u001b[4mlat\u001b[0m(lat), float32 \u001b[4mlon\u001b[0m(lon), float64 \u001b[4mtime\u001b[0m(time), float64 \u001b[4mtemp\u001b[0m(time,lat,lon)\n",
628 " groups: \n",
629 "\n",
630 "Dataset is closed!\n"
631 ]
632 }
633 ],
634 "source": [
635 "# first print the Dataset object to see what we've got\n",
636 "print(ncfile)\n",
637 "# close the Dataset.\n",
638 "ncfile.close(); print('Dataset is closed!')"
639 ]
640 },
641 {
642 "cell_type": "markdown",
643 "metadata": {
644 "internals": {
645 "frag_helper": "fragment_end",
646 "frag_number": 22,
647 "slide_type": "subslide"
648 },
649 "slideshow": {
650 "slide_type": "slide"
651 }
652 },
653 "source": [
654 "# Advanced features\n",
655 "\n",
656 "So far we've only exercised features associated with the old netCDF version 3 data model. netCDF version 4 adds a lot of new functionality that comes with the more flexible HDF5 storage layer. \n",
657 "\n",
658 "Let's create a new file with `format='NETCDF4'` so we can try out some of these features."
659 ]
660 },
661 {
662 "cell_type": "code",
663 "execution_count": 36,
664 "metadata": {
665 "collapsed": false,
666 "internals": {
667 "frag_helper": "fragment_end",
668 "frag_number": 25,
669 "slide_helper": "subslide_end"
670 },
671 "slide_helper": "slide_end",
672 "slideshow": {
673 "slide_type": "fragment"
674 }
675 },
676 "outputs": [
677 {
678 "name": "stdout",
679 "output_type": "stream",
680 "text": [
681 "<type 'netCDF4._netCDF4.Dataset'>\n",
682 "root group (NETCDF4 data model, file format HDF5):\n",
683 " dimensions(sizes): \n",
684 " variables(dimensions): \n",
685 " groups: \n",
686 "\n"
687 ]
688 }
689 ],
690 "source": [
691 "ncfile = netCDF4.Dataset('data/new2.nc','w',format='NETCDF4')\n",
692 "print(ncfile)"
693 ]
694 },
695 {
696 "cell_type": "markdown",
697 "metadata": {
698 "internals": {
699 "frag_helper": "fragment_end",
700 "frag_number": 25,
701 "slide_type": "subslide"
702 },
703 "slideshow": {
704 "slide_type": "slide"
705 }
706 },
707 "source": [
708 "## Creating Groups\n",
709 "\n",
710 "netCDF version 4 added support for organizing data in hierarchical groups.\n",
711 "\n",
712 "- analagous to directories in a filesystem. \n",
713 "- Groups serve as containers for variables, dimensions and attributes, as well as other groups. \n",
714 "- A `netCDF4.Dataset` creates a special group, called the 'root group', which is similar to the root directory in a unix filesystem. \n",
715 "\n",
716 "- groups are created using the [`createGroup`](http://unidata.github.io/netcdf4-python/netCDF4.Dataset-class.html#createGroup) method.\n",
717 "- takes a single argument (a string, which is the name of the Group instance). This string is used as a key to access the group instances in the `groups` dictionary.\n",
718 "\n",
719 "Here we create two groups to hold data for two different model runs."
720 ]
721 },
722 {
723 "cell_type": "code",
724 "execution_count": 37,
725 "metadata": {
726 "collapsed": false,
727 "internals": {
728 "frag_helper": "fragment_end",
729 "frag_number": 27,
730 "slide_helper": "subslide_end"
731 },
732 "slide_helper": "slide_end",
733 "slideshow": {
734 "slide_type": "fragment"
735 }
736 },
737 "outputs": [
738 {
739 "name": "stdout",
740 "output_type": "stream",
741 "text": [
742 "('model_run1', <type 'netCDF4._netCDF4.Group'>\n",
743 "group /model_run1:\n",
744 " dimensions(sizes): \n",
745 " variables(dimensions): \n",
746 " groups: \n",
747 ")\n",
748 "('model_run2', <type 'netCDF4._netCDF4.Group'>\n",
749 "group /model_run2:\n",
750 " dimensions(sizes): \n",
751 " variables(dimensions): \n",
752 " groups: \n",
753 ")\n"
754 ]
755 }
756 ],
757 "source": [
758 "grp1 = ncfile.createGroup('model_run1')\n",
759 "grp2 = ncfile.createGroup('model_run2')\n",
760 "for grp in ncfile.groups.items():\n",
761 " print(grp)"
762 ]
763 },
764 {
765 "cell_type": "markdown",
766 "metadata": {
767 "internals": {
768 "frag_helper": "fragment_end",
769 "frag_number": 27,
770 "slide_type": "subslide"
771 },
772 "slideshow": {
773 "slide_type": "slide"
774 }
775 },
776 "source": [
777 "Create some dimensions in the root group."
778 ]
779 },
780 {
781 "cell_type": "code",
782 "execution_count": 38,
783 "metadata": {
784 "collapsed": false,
785 "internals": {
786 "frag_helper": "fragment_end",
787 "frag_number": 29
788 },
789 "slideshow": {
790 "slide_type": "fragment"
791 }
792 },
793 "outputs": [],
794 "source": [
795 "lat_dim = ncfile.createDimension('lat', 73) # latitude axis\n",
796 "lon_dim = ncfile.createDimension('lon', 144) # longitude axis\n",
797 "time_dim = ncfile.createDimension('time', None) # unlimited axis (can be appended to)."
798 ]
799 },
800 {
801 "cell_type": "markdown",
802 "metadata": {
803 "internals": {
804 "frag_helper": "fragment_end",
805 "frag_number": 30
806 },
807 "slideshow": {
808 "slide_type": "fragment"
809 }
810 },
811 "source": [
812 "Now create a variable in grp1 and grp2. The library will search recursively upwards in the group tree to find the dimensions (which in this case are defined one level up).\n",
813 "\n",
814 "- These variables are create with **zlib compression**, another nifty feature of netCDF 4. \n",
815 "- The data are automatically compressed when data is written to the file, and uncompressed when the data is read. \n",
816 "- This can really save disk space, especially when used in conjunction with the [**least_significant_digit**](http://unidata.github.io/netcdf4-python/netCDF4.Dataset-class.html#createVariable) keyword argument, which causes the data to be quantized (truncated) before compression. This makes the compression lossy, but more efficient."
817 ]
818 },
819 {
820 "cell_type": "code",
821 "execution_count": 39,
822 "metadata": {
823 "collapsed": false,
824 "internals": {
825 "frag_helper": "fragment_end",
826 "frag_number": 31,
827 "slide_helper": "subslide_end"
828 },
829 "slide_helper": "slide_end",
830 "slideshow": {
831 "slide_type": "fragment"
832 }
833 },
834 "outputs": [
835 {
836 "name": "stdout",
837 "output_type": "stream",
838 "text": [
839 "('model_run1', <type 'netCDF4._netCDF4.Group'>\n",
840 "group /model_run1:\n",
841 " dimensions(sizes): \n",
842 " variables(dimensions): float64 \u001b[4mtemp\u001b[0m(time,lat,lon)\n",
843 " groups: \n",
844 ")\n",
845 "('model_run2', <type 'netCDF4._netCDF4.Group'>\n",
846 "group /model_run2:\n",
847 " dimensions(sizes): \n",
848 " variables(dimensions): float64 \u001b[4mtemp\u001b[0m(time,lat,lon)\n",
849 " groups: \n",
850 ")\n"
851 ]
852 }
853 ],
854 "source": [
855 "temp1 = grp1.createVariable('temp',np.float64,('time','lat','lon'),zlib=True)\n",
856 "temp2 = grp2.createVariable('temp',np.float64,('time','lat','lon'),zlib=True)\n",
857 "for grp in ncfile.groups.items(): # shows that each group now contains 1 variable\n",
858 " print(grp)"
859 ]
860 },
861 {
862 "cell_type": "markdown",
863 "metadata": {
864 "internals": {
865 "frag_helper": "fragment_end",
866 "frag_number": 31,
867 "slide_type": "subslide"
868 },
869 "slideshow": {
870 "slide_type": "slide"
871 }
872 },
873 "source": [
874 "##Creating a variable with a compound data type\n",
875 "\n",
876 "- Compound data types map directly to numpy structured (a.k.a 'record' arrays). \n",
877 "- Structured arrays are akin to C structs, or derived types in Fortran. \n",
878 "- They allow for the construction of table-like structures composed of combinations of other data types, including other compound types. \n",
879 "- Might be useful for representing multiple parameter values at each point on a grid, or at each time and space location for scattered (point) data. \n",
880 "\n",
881 "Here we create a variable with a compound data type to represent complex data (there is no native complex data type in netCDF). \n",
882 "\n",
883 "- The compound data type is created with the [`createCompoundType`](http://unidata.github.io/netcdf4-python/netCDF4.Dataset-class.html#createCompoundType) method."
884 ]
885 },
886 {
887 "cell_type": "code",
888 "execution_count": 40,
889 "metadata": {
890 "collapsed": false,
891 "internals": {
892 "frag_helper": "fragment_end",
893 "frag_number": 33,
894 "slide_helper": "subslide_end"
895 },
896 "slide_helper": "slide_end",
897 "slideshow": {
898 "slide_type": "fragment"
899 }
900 },
901 "outputs": [
902 {
903 "name": "stdout",
904 "output_type": "stream",
905 "text": [
906 "<type 'netCDF4._netCDF4.Variable'>\n",
907 "compound cmplx_var(time, lat, lon)\n",
908 "compound data type: [('real', '<f8'), ('imag', '<f8')]\n",
909 "path = /model_run1\n",
910 "unlimited dimensions: time\n",
911 "current shape = (1, 73, 144)\n",
912 "\n",
913 "(dtype([('real', '<f8'), ('imag', '<f8')]), (73, 144), (0.578177705604801, 0.18086070805676357))\n"
914 ]
915 }
916 ],
917 "source": [
918 "# create complex128 numpy structured data type\n",
919 "complex128 = np.dtype([('real',np.float64),('imag',np.float64)])\n",
920 "# using this numpy dtype, create a netCDF compound data type object\n",
921 "# the string name can be used as a key to access the datatype from the cmptypes dictionary.\n",
922 "complex128_t = ncfile.createCompoundType(complex128,'complex128')\n",
923 "# create a variable with this data type, write some data to it.\n",
924 "cmplxvar = grp1.createVariable('cmplx_var',complex128_t,('time','lat','lon'))\n",
925 "# write some data to this variable\n",
926 "# first create some complex random data\n",
927 "nlats = len(lat_dim); nlons = len(lon_dim)\n",
928 "data_arr_cmplx = np.random.uniform(size=(nlats,nlons))+1.j*np.random.uniform(size=(nlats,nlons))\n",
929 "# write this complex data to a numpy complex128 structured array\n",
930 "data_arr = np.empty((nlats,nlons),complex128)\n",
931 "data_arr['real'] = data_arr_cmplx.real; data_arr['imag'] = data_arr_cmplx.imag\n",
932 "cmplxvar[0] = data_arr # write the data to the variable (appending to time dimension)\n",
933 "print(cmplxvar)\n",
934 "data_out = cmplxvar[0] # read one value of data back from variable\n",
935 "print(data_out.dtype, data_out.shape, data_out[0,0])"
936 ]
937 },
938 {
939 "cell_type": "markdown",
940 "metadata": {
941 "internals": {
942 "frag_helper": "fragment_end",
943 "frag_number": 33,
944 "slide_type": "subslide"
945 },
946 "slideshow": {
947 "slide_type": "slide"
948 }
949 },
950 "source": [
951 "##Creating a variable with a variable-length (vlen) data type\n",
952 "\n",
953 "netCDF 4 has support for variable-length or \"ragged\" arrays. These are arrays of variable length sequences having the same type. \n",
954 "\n",
955 "- To create a variable-length data type, use the [`createVLType`](http://unidata.github.io/netcdf4-python/netCDF4.Dataset-class.html#createVLType) method.\n",
956 "- The numpy datatype of the variable-length sequences and the name of the new datatype must be specified. "
957 ]
958 },
959 {
960 "cell_type": "code",
961 "execution_count": 41,
962 "metadata": {
963 "collapsed": false,
964 "internals": {
965 "frag_helper": "fragment_end",
966 "frag_number": 35
967 },
968 "slideshow": {
969 "slide_type": "fragment"
970 }
971 },
972 "outputs": [],
973 "source": [
974 "vlen_t = ncfile.createVLType(np.int64, 'phony_vlen')"
975 ]
976 },
977 {
978 "cell_type": "markdown",
979 "metadata": {
980 "internals": {
981 "frag_helper": "fragment_end",
982 "frag_number": 36
983 },
984 "slideshow": {
985 "slide_type": "fragment"
986 }
987 },
988 "source": [
989 "A new variable can then be created using this datatype."
990 ]
991 },
992 {
993 "cell_type": "code",
994 "execution_count": 42,
995 "metadata": {
996 "collapsed": false,
997 "internals": {
998 "frag_helper": "fragment_end",
999 "frag_number": 37,
1000 "slide_helper": "subslide_end"
1001 },
1002 "slide_helper": "slide_end",
1003 "slideshow": {
1004 "slide_type": "fragment"
1005 }
1006 },
1007 "outputs": [],
1008 "source": [
1009 "vlvar = grp2.createVariable('phony_vlen_var', vlen_t, ('time','lat','lon'))"
1010 ]
1011 },
1012 {
1013 "cell_type": "markdown",
1014 "metadata": {
1015 "internals": {
1016 "frag_helper": "fragment_end",
1017 "frag_number": 37,
1018 "slide_type": "subslide"
1019 },
1020 "slideshow": {
1021 "slide_type": "slide"
1022 }
1023 },
1024 "source": [
1025 "Since there is no native vlen datatype in numpy, vlen arrays are represented in python as object arrays (arrays of dtype `object`). \n",
1026 "\n",
1027 "- These are arrays whose elements are Python object pointers, and can contain any type of python object. \n",
1028 "- For this application, they must contain 1-D numpy arrays all of the same type but of varying length. \n",
1029 "- Fill with 1-D random numpy int64 arrays of random length between 1 and 10."
1030 ]
1031 },
1032 {
1033 "cell_type": "code",
1034 "execution_count": 43,
1035 "metadata": {
1036 "collapsed": false,
1037 "internals": {
1038 "frag_helper": "fragment_end",
1039 "frag_number": 39,
1040 "slide_helper": "subslide_end"
1041 },
1042 "slide_helper": "slide_end",
1043 "slideshow": {
1044 "slide_type": "fragment"
1045 }
1046 },
1047 "outputs": [
1048 {
1049 "name": "stdout",
1050 "output_type": "stream",
1051 "text": [
1052 "<type 'netCDF4._netCDF4.Variable'>\n",
1053 "vlen phony_vlen_var(time, lat, lon)\n",
1054 "vlen data type: int64\n",
1055 "path = /model_run2\n",
1056 "unlimited dimensions: time\n",
1057 "current shape = (1, 73, 144)\n",
1058 "\n",
1059 "('data =\\n', array([[[array([0, 4, 0, 9, 2, 2, 2, 4, 2]), array([7, 5, 4, 4, 9, 8, 0]),\n",
1060 " array([3, 6, 6, 8, 2, 7]), ..., array([5, 0, 0, 8, 8, 1, 5, 3]),\n",
1061 " array([4, 2, 7]), array([0])],\n",
1062 " [array([5, 6, 6, 6, 1, 0, 7]), array([7]),\n",
1063 " array([7, 5, 8, 9, 6, 9, 3]), ..., array([0, 6, 5, 4]),\n",
1064 " array([7, 1, 9, 7, 7, 2]), array([1, 4, 0])],\n",
1065 " [array([4, 3, 1]), array([6, 3, 9, 7, 8]), array([8]), ...,\n",
1066 " array([6, 5, 8, 0]), array([0]), array([0, 9, 6, 2, 4])],\n",
1067 " ..., \n",
1068 " [array([8, 4, 4]), array([4, 1, 6]), array([1, 4, 2, 3, 9]), ...,\n",
1069 " array([9, 1]), array([7, 2, 5, 1, 5, 8, 2]),\n",
1070 " array([2, 9, 9, 1, 4, 6, 3, 5, 2])],\n",
1071 " [array([4, 7, 9, 8, 2, 3, 6, 6]),\n",
1072 " array([1, 4, 1, 6, 1, 1, 2, 3, 9]),\n",
1073 " array([9, 5, 6, 2, 4, 3, 8, 2, 9]), ..., array([9, 5, 7]),\n",
1074 " array([3, 9]), array([4, 2, 6, 9])],\n",
1075 " [array([8, 9, 9, 2, 2, 8, 8, 5]), array([3]),\n",
1076 " array([8, 8, 0, 2, 9, 2, 3, 0, 9]), ..., array([7]),\n",
1077 " array([5, 1, 0, 6, 8, 6]), array([8, 6, 3, 6, 9, 8, 4, 2, 5])]]], dtype=object))\n"
1078 ]
1079 }
1080 ],
1081 "source": [
1082 "vlen_data = np.empty((nlats,nlons),object)\n",
1083 "for i in range(nlons):\n",
1084 " for j in range(nlats):\n",
1085 " size = np.random.randint(1,10,size=1) # random length of sequence\n",
1086 " vlen_data[j,i] = np.random.randint(0,10,size=size)# generate random sequence\n",
1087 "vlvar[0] = vlen_data # append along unlimited dimension (time)\n",
1088 "print(vlvar)\n",
1089 "print('data =\\n',vlvar[:])"
1090 ]
1091 },
1092 {
1093 "cell_type": "markdown",
1094 "metadata": {
1095 "internals": {
1096 "frag_helper": "fragment_end",
1097 "frag_number": 39,
1098 "slide_type": "subslide"
1099 },
1100 "slideshow": {
1101 "slide_type": "slide"
1102 }
1103 },
1104 "source": [
1105 "Close the Dataset and examine the contents with ncdump."
1106 ]
1107 },
1108 {
1109 "cell_type": "code",
1110 "execution_count": 44,
1111 "metadata": {
1112 "collapsed": false,
1113 "internals": {
1114 "frag_helper": "fragment_end",
1115 "frag_number": 41,
1116 "slide_helper": "subslide_end"
1117 },
1118 "slide_helper": "slide_end",
1119 "slideshow": {
1120 "slide_type": "fragment"
1121 }
1122 },
1123 "outputs": [
1124 {
1125 "name": "stdout",
1126 "output_type": "stream",
1127 "text": [
1128 "netcdf new2 {\r\n",
1129 "types:\r\n",
1130 " compound complex128 {\r\n",
1131 " double real ;\r\n",
1132 " double imag ;\r\n",
1133 " }; // complex128\r\n",
1134 " int64(*) phony_vlen ;\r\n",
1135 "dimensions:\r\n",
1136 "\tlat = 73 ;\r\n",
1137 "\tlon = 144 ;\r\n",
1138 "\ttime = UNLIMITED ; // (1 currently)\r\n",
1139 "\r\n",
1140 "group: model_run1 {\r\n",
1141 " variables:\r\n",
1142 " \tdouble temp(time, lat, lon) ;\r\n",
1143 " \tcomplex128 cmplx_var(time, lat, lon) ;\r\n",
1144 " } // group model_run1\r\n",
1145 "\r\n",
1146 "group: model_run2 {\r\n",
1147 " variables:\r\n",
1148 " \tdouble temp(time, lat, lon) ;\r\n",
1149 " \tphony_vlen phony_vlen_var(time, lat, lon) ;\r\n",
1150 " } // group model_run2\r\n",
1151 "}\r\n"
1152 ]
1153 }
1154 ],
1155 "source": [
1156 "ncfile.close()\n",
1157 "!ncdump -h data/new2.nc"
1158 ]
1159 },
1160 {
1161 "cell_type": "markdown",
1162 "metadata": {
1163 "internals": {
1164 "frag_helper": "fragment_end",
1165 "frag_number": 41,
1166 "slide_helper": "subslide_end",
1167 "slide_type": "subslide"
1168 },
1169 "slide_helper": "slide_end",
1170 "slideshow": {
1171 "slide_type": "slide"
1172 }
1173 },
1174 "source": [
1175 "##Other interesting and useful projects using netcdf4-python\n",
1176 "\n",
1177 "- [xarray](https://xarray.pydata.org/en/stable/): N-dimensional variant of the core [pandas](https://pandas.pydata.org) data structure that can operate on netcdf variables.\n",
1178 "- [Iris](https://scitools.org.uk/iris/docs/latest/): a data model to create a data abstraction layer which isolates analysis and visualisation code from data format specifics. Uses netcdf4-python to access netcdf data (can also handle GRIB).\n",
1179 "- [Dask](https://dask.org/): Virtual large arrays (from netcdf variables) with lazy evaluation.\n",
1180 "- [cf-python](https://cfpython.bitbucket.io/): Implements the [CF](http://cfconventions.org) data model for the reading, writing and processing of data and metadata. "
1181 ]
1182 }
1183 ],
1184 "metadata": {
1185 "kernelspec": {
1186 "display_name": "Python 2",
1187 "language": "python",
1188 "name": "python2"
1189 },
1190 "language_info": {
1191 "codemirror_mode": {
1192 "name": "ipython",
1193 "version": 2
1194 },
1195 "file_extension": ".py",
1196 "mimetype": "text/x-python",
1197 "name": "python",
1198 "nbconvert_exporter": "python",
1199 "pygments_lexer": "ipython2",
1200 "version": "2.7.9"
1201 }
1202 },
1203 "nbformat": 4,
1204 "nbformat_minor": 0
1205 }
0 # Rename this file to setup.cfg to set build options.
1 # Follow instructions below for editing.
20 [options]
3 # if true, the nc-config script (installed with netcdf 4.1.2 and higher)
4 # will be used to determine the locations of required libraries.
5 # Usually, nothing else is needed.
6 use_ncconfig=True
7 # path to nc-config script (use if not found in unix PATH).
8 #ncconfig=/usr/local/bin/nc-config
1 use_ncconfig = True
2
93 [directories]
10 #
11 # If nc-config doesn't do the trick, you can specify the locations
12 # of the libraries and headers manually below
13 #
14 # uncomment and set to netCDF install location.
15 # Include files should be located in netCDF4_dir/include and
16 # the library should be located in netCDF4_dir/lib.
17 # If the libraries and include files are installed in separate locations,
18 # use netCDF4_libdir and netCDF4_incdir to specify the locations
19 # separately.
20 #netCDF4_dir = /usr/local
21 # uncomment and set to HDF5 install location.
22 # Include files should be located in HDF5_dir/include and
23 # the library should be located in HDF5_dir/lib.
24 # If the libraries and include files are installed in separate locations,
25 # use HDF5_libdir and HDF5_incdir to specify the locations
26 # separately.
27 #HDF5_dir = /usr/local
28 # if HDF5 was built with szip support as a static lib,
29 # uncomment and set to szip lib install location.
30 # If the libraries and include files are installed in separate locations,
31 # use szip_libdir and szip_incdir.
32 #szip_dir = /usr/local
33 # if netcdf lib was build statically with HDF4 support,
34 # uncomment and set to hdf4 lib (libmfhdf and libdf) nstall location.
35 # If the libraries and include files are installed in separate locations,
36 # use hdf4_libdir and hdf4_incdir.
37 #hdf4_dir = /usr/local
38 # if netcdf lib was build statically with HDF4 support,
39 # uncomment and set to jpeg lib install location (hdf4 needs jpeg).
40 # If the libraries and include files are installed in separate locations,
41 # use jpeg_libdir and jpeg_incdir.
42 #jpeg_dir = /usr/local
43 # if netcdf lib was build statically with OpenDAP support,
44 # uncomment and set to curl lib install location.
45 # If the libraries and include files are installed in separate locations,
46 # use curl_libdir and curl_incdir.
47 #curl_dir = /usr/local
48 # location of mpi.h (needed for parallel support)
49 #mpi_incdir=/opt/local/include/mpich-mp
4
505 [check-manifest]
51 ignore =
52 .gitignore
53 README.gh-pages
54 README.release
55 examples/data/*nc
56 examples/*ipynb
6 ignore =
7 .gitignore
8 README.gh-pages
9 README.release
10 examples/data/*nc
11 examples/*ipynb
12
13 [egg_info]
14 tag_build =
15 tag_date = 0
16
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
253225 before any variables can be created the dimensions they use must be
254226 created first. A special case, not often used in practice, is that of a
255227 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
228 the `Dataset.createDimension` method of a `Dataset`
229 or `Group` instance. A Python string is used to set the name of the
258230 dimension, and an integer value is used to set the size. To create an
259231 unlimited dimension (a dimension that can be appended to), the size
260232 value is set to `None` or 0. In this example, there both the `time` and
270242 ```
271243
272244
273 All of the [Dimension](#Dimension) instances are stored in a python dictionary.
245 All of the `Dimension` instances are stored in a python dictionary.
274246
275247 ```python
276248 >>> print(rootgrp.dimensions)
277249 {'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}
278250 ```
279251
280 Using the python `len` function with a [Dimension](#Dimension) instance returns
252 Using the python `len` function with a `Dimension` instance returns
281253 current size of that dimension.
282 [Dimension.isunlimited](#Dimension.isunlimited) method of a [Dimension](#Dimension) instance
254 `Dimension.isunlimited` method of a `Dimension` instance
283255 be used to determine if the dimensions is unlimited, or appendable.
284256
285257 ```python
291263 True
292264 ```
293265
294 Printing the [Dimension](#Dimension) object
266 Printing the `Dimension` object
295267 provides useful summary info, including the name and length of the dimension,
296268 and whether it is unlimited.
297269
304276 <class 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 144
305277 ```
306278
307 [Dimension](#Dimension) names can be changed using the
308 [Datatset.renameDimension](#Datatset.renameDimension) method of a [Dataset](#Dataset) or
309 [Group](#Group) instance.
279 `Dimension` names can be changed using the
280 `Datatset.renameDimension` method of a `Dataset` or
281 `Group` instance.
310282
311283 ## Variables in a netCDF file
312284
314286 supplied by the [numpy module](http://numpy.scipy.org). However,
315287 unlike numpy arrays, netCDF4 variables can be appended to along one or
316288 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
289 `Dataset.createVariable` method of a `Dataset` or
290 `Group` instance. The `Dataset.createVariable`j method
319291 has two mandatory arguments, the variable name (a Python string), and
320292 the variable datatype. The variable's dimensions are given by a tuple
321293 containing the dimension names (defined previously with
322 [Dataset.createDimension](#Dataset.createDimension)). To create a scalar
294 `Dataset.createDimension`). To create a scalar
323295 variable, simply leave out the dimensions keyword. The variable
324296 primitive datatypes correspond to the dtype attribute of a numpy array.
325297 You can specify the datatype as a numpy dtype object, or anything that
337309 can only be used if the file format is `NETCDF4`.
338310
339311 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
312 coordinate variables. The `Dataset.createVariable`
313 method returns an instance of the `Variable` class whose methods can be
342314 used later to access and set variable data and attributes.
343315
344316 ```python
351323 >>> temp.units = "K"
352324 ```
353325
354 To get summary info on a [Variable](#Variable) instance in an interactive session,
326 To get summary info on a `Variable` instance in an interactive session,
355327 just print it.
356328
357329 ```python
372344
373345 If the intermediate groups do not yet exist, they will be created.
374346
375 You can also query a [Dataset](#Dataset) or [Group](#Group) instance directly to obtain [Group](#Group) or
376 [Variable](#Variable) instances using paths.
347 You can also query a `Dataset` or `Group` instance directly to obtain `Group` or
348 `Variable` instances using paths.
377349
378350 ```python
379351 >>> print(rootgrp["/forecasts/model1"]) # a Group instance
392364 ```
393365
394366
395 All of the variables in the [Dataset](#Dataset) or [Group](#Group) are stored in a
367 All of the variables in the `Dataset` or `Group` are stored in a
396368 Python dictionary, in the same way as the dimensions:
397369
398370 ```python
421393 filling on, default _FillValue of 9.969209968386869e+36 used}
422394 ```
423395
424 [Variable](#Variable) names can be changed using the
425 [Dataset.renameVariable](#Dataset.renameVariable) method of a [Dataset](#Dataset)
396 `Variable` names can be changed using the
397 `Dataset.renameVariable` method of a `Dataset`
426398 instance.
427399
428400 Variables can be sliced similar to numpy arrays, but there are some differences. See
433405
434406 There are two types of attributes in a netCDF file, global and variable.
435407 Global attributes provide information about a group, or the entire
436 dataset, as a whole. [Variable](#Variable) attributes provide information about
408 dataset, as a whole. `Variable` attributes provide information about
437409 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
410 values to `Dataset` or `Group` instance variables. `Variable`
411 attributes are set by assigning values to `Variable` instances
440412 variables. Attributes can be strings, numbers or sequences. Returning to
441413 our example,
442414
453425 >>> times.calendar = "gregorian"
454426 ```
455427
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
428 The `Dataset.ncattrs` method of a `Dataset`, `Group` or
429 `Variable` instance can be used to retrieve the names of all the netCDF
458430 attributes. This method is provided as a convenience, since using the
459431 built-in `dir` Python function will return a bunch of private methods
460432 and attributes that cannot (or should not) be modified by the user.
467439 Global attr source = netCDF4 python module tutorial
468440 ```
469441
470 The `__dict__` attribute of a [Dataset](#Dataset), [Group](#Group) or [Variable](#Variable)
442 The `__dict__` attribute of a `Dataset`, `Group` or `Variable`
471443 instance provides all the netCDF attribute name/value pairs in a python
472444 dictionary:
473445
476448 {'description': 'bogus example script', 'history': 'Created Mon Jul 8 14:19:41 2019', 'source': 'netCDF4 python module tutorial'}
477449 ```
478450
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`
451 Attributes can be deleted from a netCDF `Dataset`, `Group` or
452 `Variable` using the python `del` statement (i.e. `del grp.foo`
481453 removes the attribute `foo` the the group `grp`).
482454
483455 ## Writing data to and retrieving data from a netCDF variable
484456
485 Now that you have a netCDF [Variable](#Variable) instance, how do you put data
457 Now that you have a netCDF `Variable` instance, how do you put data
486458 into it? You can just treat it like an array and assign data to a slice.
487459
488460 ```python
489 >>> import numpy
490 >>> lats = numpy.arange(-90,91,2.5)
491 >>> lons = numpy.arange(-180,180,2.5)
461 >>> import numpy as np
462 >>> lats = np.arange(-90,91,2.5)
463 >>> lons = np.arange(-180,180,2.5)
492464 >>> latitudes[:] = lats
493465 >>> longitudes[:] = lons
494466 >>> print("latitudes =\\n{}".format(latitudes[:]))
502474 90. ]
503475 ```
504476
505 Unlike NumPy's array objects, netCDF [Variable](#Variable)
477 Unlike NumPy's array objects, netCDF `Variable`
506478 objects with unlimited dimensions will grow along those dimensions if you
507479 assign data outside the currently defined range of indices.
508480
579551
580552 By default, netcdf4-python returns numpy masked arrays with values equal to the
581553 `missing_value` or `_FillValue` variable attributes masked. The
582 [Dataset.set_auto_mask](#Dataset.set_auto_mask) [Dataset](#Dataset) and [Variable](#Variable) methods
554 `Dataset.set_auto_mask` `Dataset` and `Variable` methods
583555 can be used to disable this feature so that
584556 numpy arrays are always returned, with the missing values included. Prior to
585557 version 1.4.0 the default behavior was to only return masked arrays when the
586558 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
559 using the `Dataset.set_always_mask` method. If a masked array is
588560 written to a netCDF variable, the masked elements are filled with the
589561 value specified by the `missing_value` attribute. If the variable has
590562 no `missing_value`, the `_FillValue` is used instead.
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.
30443021
30453022 **`True_or_False`**: Boolean determining if automatic conversion to masked arrays
30463023 shall be applied for all variables.
30653042 """
30663043 **`set_auto_scale(self, True_or_False)`**
30673044
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.
3045 Call `Variable.set_auto_scale` for all variables contained in this `Dataset` or
3046 `Group`, as well as for all variables in all its subgroups.
30703047
30713048 **`True_or_False`**: Boolean determining if automatic variable scaling
30723049 shall be applied for all variables.
30913068 """
30923069 **`set_always_mask(self, True_or_False)`**
30933070
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
3071 Call `Variable.set_always_mask` for all variables contained in
3072 this `Dataset` or `Group`, as well as for all
30963073 variables in all its subgroups.
30973074
30983075 **`True_or_False`**: Boolean determining if automatic conversion of
31223099 """
31233100 **`set_ncstring_attrs(self, True_or_False)`**
31243101
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
3102 Call `Variable.set_ncstring_attrs` for all variables contained in
3103 this `Dataset` or `Group`, as well as for all its
31273104 subgroups and their variables.
31283105
31293106 **`True_or_False`**: Boolean determining if all string attributes are
32243201 """
32253202 **`fromcdl(cdlfilename, ncfilename=None, mode='a',format='NETCDF4')`**
32263203
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`.
3204 call [ncgen][ncgen] via subprocess to create Dataset from [CDL][cdl]
3205 text representation. Requires [ncgen][ncgen] to be installed and in `$PATH`.
32293206
32303207 **`cdlfilename`**: CDL file.
32313208
32393216 `'NETCDF3_64BIT_DATA'`. Default `'NETCDF4'`.
32403217
32413218 Dataset instance for `ncfilename` is returned.
3219
3220 [ncgen]: https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#ncgen_guide
3221 [cdl]: https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#cdl_guide
32423222 """
32433223 if ncfilename is None:
32443224 filepath = pathlib.Path(cdlfilename)
32593239 """
32603240 **`tocdl(self, coordvars=False, data=False, outfile=None)`**
32613241
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`.
3242 call [ncdump][ncdump] via subprocess to create [CDL][cdl]
3243 text representation of Dataset. Requires [ncdump][ncdump]
3244 to be installed and in `$PATH`.
32643245
32653246 **`coordvars`**: include coordinate variable data (via `ncdump -c`). Default False
32663247
32673248 **`data`**: if True, write out variable data (Default False).
32683249
32693250 **`outfile`**: If not None, file to output ncdump to. Default is to return a string.
3251
3252 [ncdump]: https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#ncdump_guide
3253 [cdl]: https://www.unidata.ucar.edu/software/netcdf/docs/netcdf_utilities_guide.html#cdl_guide
32703254 """
32713255 self.sync()
32723256 if coordvars:
32873271 cdef class Group(Dataset):
32883272 """
32893273 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__)
3274 analogous to directories in a unix filesystem. Each `Group` behaves like
3275 a `Dataset` within a Dataset, and can contain it's own variables,
3276 dimensions and attributes (and other Groups). See `Group.__init__`
32933277 for more details.
32943278
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).
3279 `Group` inherits from `Dataset`, so all the
3280 `Dataset` class methods and variables are available
3281 to a `Group` instance (except the `close` method).
32983282
32993283 Additional read-only class variables:
33003284
33033287 def __init__(self, parent, name, **kwargs):
33043288 """
33053289 **`__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.
3290 `Group` constructor.
3291
3292 **`parent`**: `Group` instance for the parent group. If being created
3293 in the root group, use a `Dataset` instance.
33103294
33113295 **`name`**: - Name of the group.
33123296
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.
3297 ***Note***: `Group` instances should be created using the
3298 `Dataset.createGroup` method of a `Dataset` instance, or
3299 another `Group` instance, not using this class directly.
33163300 """
33173301 cdef char *groupname
33183302 # flag to indicate that Variables in this Group support orthogonal indexing.
33623346 """
33633347 **`close(self)`**
33643348
3365 overrides [Dataset](#Dataset) close method which does not apply to [Group](#Group)
3349 overrides `Dataset` close method which does not apply to `Group`
33663350 instances, raises IOError."""
3367 raise IOError('cannot close a [Group](#Group) (only applies to Dataset)')
3351 raise IOError('cannot close a `Group` (only applies to Dataset)')
33683352
33693353
33703354 cdef class Dimension:
33713355 """
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
3356 A netCDF `Dimension` is used to describe the coordinates of a `Variable`.
3357 See `Dimension.__init__` for more details.
3358
3359 The current maximum size of a `Dimension` instance can be obtained by
3360 calling the python `len` function on the `Dimension` instance. The
3361 `Dimension.isunlimited` method of a `Dimension` instance can be used to
33783362 determine if the dimension is unlimited.
33793363
33803364 Read-only class variables:
33813365
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).
3366 **`name`**: String name, used when creating a `Variable` with
3367 `Dataset.createVariable`.
3368
3369 **`size`**: Current `Dimension` size (same as `len(d)`, where `d` is a
3370 `Dimension` instance).
33873371 """
33883372 cdef public int _dimid, _grpid
33893373 cdef public _data_model, _name, _grp
33923376 """
33933377 **`__init__(self, group, name, size=None)`**
33943378
3395 [Dimension](#Dimension) constructor.
3396
3397 **`group`**: [Group](#Group) instance to associate with dimension.
3379 `Dimension` constructor.
3380
3381 **`group`**: `Group` instance to associate with dimension.
33983382
33993383 **`name`**: Name of the dimension.
34003384
34013385 **`size`**: Size of the dimension. `None` or 0 means unlimited. (Default `None`).
34023386
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.
3387 ***Note***: `Dimension` instances should be created using the
3388 `Dataset.createDimension` method of a `Group` or
3389 `Dataset` instance, not using `Dimension.__init__` directly.
34063390 """
34073391 cdef int ierr
34083392 cdef char *dimname
34683452 (type(self), self._name, len(self))
34693453
34703454 def __len__(self):
3471 # len([Dimension](#Dimension) instance) returns current size of dimension
3455 # len(`Dimension` instance) returns current size of dimension
34723456 cdef int ierr
34733457 cdef size_t lengthp
34743458 with nogil:
34803464 """
34813465 **`group(self)`**
34823466
3483 return the group that this [Dimension](#Dimension) is a member of."""
3467 return the group that this `Dimension` is a member of."""
34843468 return self._grp
34853469
34863470 def isunlimited(self):
34873471 """
34883472 **`isunlimited(self)`**
34893473
3490 returns `True` if the [Dimension](#Dimension) instance is unlimited, `False` otherwise."""
3474 returns `True` if the `Dimension` instance is unlimited, `False` otherwise."""
34913475 cdef int ierr, n, numunlimdims, ndims, nvars, ngatts, xdimid
34923476 cdef int *unlimdimids
34933477 if self._data_model == 'NETCDF4':
35203504
35213505 cdef class Variable:
35223506 """
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
3507 A netCDF `Variable` is used to read and write netCDF data. They are
3508 analogous to numpy array objects. See `Variable.__init__` for more
35253509 details.
35263510
35273511 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
3512 the variable can be obtained with the `Variable.ncattrs` method. These
35293513 attributes can be created by assigning to an attribute of the
3530 [Variable](#Variable) instance. A dictionary containing all the netCDF attribute
3514 `Variable` instance. A dictionary containing all the netCDF attribute
35313515 name/value pairs is provided by the `__dict__` attribute of a
3532 [Variable](#Variable) instance.
3516 `Variable` instance.
35333517
35343518 The following class variables are read-only:
35353519
35463530 **`scale`**: If True, `scale_factor` and `add_offset` are
35473531 applied, and signed integer data is automatically converted to
35483532 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.
3533 Default is `True`, can be reset using `Variable.set_auto_scale` and
3534 `Variable.set_auto_maskandscale` methods.
35513535
35523536 **`mask`**: If True, data is automatically converted to/from masked
35533537 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)
3538 reset using `Variable.set_auto_mask` and `Variable.set_auto_maskandscale`
35553539 methods.
35563540
35573541 **`chartostring`**: If True, data is automatically converted to/from character
35583542 arrays to string arrays when the `_Encoding` variable attribute is set.
35593543 Default is `True`, can be reset using
3560 [Variable.set_auto_chartostring](#Variable.set_auto_chartostring) method.
3544 `Variable.set_auto_chartostring` method.
35613545
35623546 **`least_significant_digit`**: Describes the power of ten of the
35633547 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)
3548 truncated to this decimal place when it is assigned to the `Variable`
35653549 instance. If `None`, the data is not truncated.
35663550
35673551 **`__orthogonal_indexing__`**: Always `True`. Indicates to client code
35913575 chunksizes=None, endian='native',
35923576 least_significant_digit=None,fill_value=None,chunk_cache=None)`**
35933577
3594 [Variable](#Variable) constructor.
3595
3596 **`group`**: [Group](#Group) or [Dataset](#Dataset) instance to associate with variable.
3578 `Variable` constructor.
3579
3580 **`group`**: `Group` or `Dataset` instance to associate with variable.
35973581
35983582 **`name`**: Name of the variable.
35993583
3600 **`datatype`**: [Variable](#Variable) data type. Can be specified by providing a
3584 **`datatype`**: `Variable` data type. Can be specified by providing a
36013585 numpy dtype object, or a string that describes a numpy dtype object.
36023586 Supported values, corresponding to `str` attribute of numpy dtype
36033587 objects, include `'f4'` (32-bit floating point), `'f8'` (64-bit floating
36103594 typecodes can also be used (`'f'` instead of `'f4'`, `'d'` instead of
36113595 `'f8'`, `'h'` or `'s'` instead of `'i2'`, `'b'` or `'B'` instead of
36123596 `'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
3597 `'i4'`). `datatype` can also be a `CompoundType` instance
3598 (for a structured, or compound array), a `VLType` instance
36153599 (for a variable-length array), or the python `str` builtin
36163600 (for a variable-length string array). Numpy string and unicode datatypes with
36173601 length greater than one are aliases for `str`.
36203604 (defined previously with `createDimension`). Default is an empty tuple
36213605 which means the variable is a scalar (and therefore has no dimensions).
36223606
3623 **`zlib`**: if `True`, data assigned to the [Variable](#Variable)
3607 **`zlib`**: if `True`, data assigned to the `Variable`
36243608 instance is compressed on disk. Default `False`.
36253609
36263610 **`complevel`**: the level of zlib compression to use (1 is the fastest,
36693653 value that the variable gets filled with before any data is written to it)
36703654 is replaced with this value. If fill_value is set to `False`, then
36713655 the variable is not pre-filled. The default netCDF fill values can be found
3672 in [default_fillvals](#default_fillvals).
3656 in the dictionary `netCDF4.default_fillvals`.
36733657
36743658 **`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
3659 Persists as long as Dataset is open. Use `set_var_chunk_cache` to
36763660 change it when Dataset is re-opened.
36773661
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.
3662 ***Note***: `Variable` instances should be created using the
3663 `Dataset.createVariable` method of a `Dataset` or
3664 `Group` instance, not using this class directly.
36813665 """
36823666 cdef int ierr, ndims, icontiguous, ideflate_level, numdims, _grpid
36833667 cdef char namstring[NC_MAX_NAME+1]
41064090 """
41074091 **`group(self)`**
41084092
4109 return the group that this [Variable](#Variable) is a member of."""
4093 return the group that this `Variable` is a member of."""
41104094 return self._grp
41114095
41124096 def ncattrs(self):
41134097 """
41144098 **`ncattrs(self)`**
41154099
4116 return netCDF attribute names for this [Variable](#Variable) in a list."""
4100 return netCDF attribute names for this `Variable` in a list."""
41174101 return _get_att_names(self._grpid, self._varid)
41184102
41194103 def setncattr(self,name,value):
43744358 """
43754359 **`renameAttribute(self, oldname, newname)`**
43764360
4377 rename a [Variable](#Variable) attribute named `oldname` to `newname`."""
4361 rename a `Variable` attribute named `oldname` to `newname`."""
43784362 cdef int ierr
43794363 cdef char *oldnamec
43804364 cdef char *newnamec
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
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.
0 Metadata-Version: 1.1
1 Name: netCDF4
2 Version: 1.5.7
3 Summary: Provides an object-oriented python interface to the netCDF version 4 library.
4 Home-page: http://github.com/Unidata/netcdf4-python
5 Author: Jeff Whitaker
6 Author-email: jeffrey.s.whitaker@noaa.gov
7 License: License :: OSI Approved :: MIT License
8 Download-URL: http://python.org/pypi/netCDF4
9 Description: netCDF version 4 has many features not found in earlier versions of the library, such as hierarchical groups, zlib compression, multiple unlimited dimensions, and new data types. It is implemented on top of HDF5. This module implements most of the new features, and can read and write netCDF files compatible with older versions of the library. The API is modelled after Scientific.IO.NetCDF, and should be familiar to users of that module.
10
11 This project is hosted on a `GitHub repository <https://github.com/Unidata/netcdf4-python>`_ where you may access the most up-to-date source.
12 Keywords: numpy,netcdf,data,science,network,oceanography,meteorology,climate
13 Platform: any
14 Classifier: Development Status :: 3 - Alpha
15 Classifier: Programming Language :: Python :: 3
16 Classifier: Programming Language :: Python :: 3.6
17 Classifier: Programming Language :: Python :: 3.7
18 Classifier: Programming Language :: Python :: 3.8
19 Classifier: Intended Audience :: Science/Research
20 Classifier: License :: OSI Approved :: MIT License
21 Classifier: Topic :: Software Development :: Libraries :: Python Modules
22 Classifier: Topic :: System :: Archiving :: Compression
23 Classifier: Operating System :: OS Independent
0 Changelog
1 LICENSE
2 MANIFEST.in
3 README.htmldocs
4 README.md
5 README.release
6 README.wheels.md
7 checkversion.py
8 create_docs.sh
9 setup.cfg
10 setup.py
11 docs/index.html
12 examples/README.md
13 examples/bench.py
14 examples/bench_compress.py
15 examples/bench_compress2.py
16 examples/bench_compress3.py
17 examples/bench_diskless.py
18 examples/json_att.py
19 examples/mpi_example.py
20 examples/mpi_example_compressed.py
21 examples/subset.py
22 examples/test_stringarr.py
23 examples/threaded_read.py
24 examples/tutorial.py
25 include/membuf.pyx
26 include/mpi-compat.h
27 include/netCDF4.pxi
28 man/nc3tonc4.1
29 man/nc4tonc3.1
30 man/ncinfo.1
31 src/netCDF4/__init__.py
32 src/netCDF4/_netCDF4.pyx
33 src/netCDF4/utils.py
34 src/netCDF4.egg-info/PKG-INFO
35 src/netCDF4.egg-info/SOURCES.txt
36 src/netCDF4.egg-info/dependency_links.txt
37 src/netCDF4.egg-info/entry_points.txt
38 src/netCDF4.egg-info/requires.txt
39 src/netCDF4.egg-info/top_level.txt
40 test/20171025_2056.Cloud_Top_Height.nc
41 test/CRM032_test1.nc
42 test/issue671.nc
43 test/issue672.nc
44 test/netcdf_dummy_file.nc
45 test/run_all.py
46 test/test_gold.nc
47 test/tst_Unsigned.py
48 test/tst_atts.py
49 test/tst_cdf5.py
50 test/tst_cdl.py
51 test/tst_chunk_cache.py
52 test/tst_compound_alignment.py
53 test/tst_compoundatt.py
54 test/tst_compoundvar.py
55 test/tst_compression.py
56 test/tst_create_mem.py
57 test/tst_dap.py
58 test/tst_dims.py
59 test/tst_diskless.py
60 test/tst_endian.py
61 test/tst_enum.py
62 test/tst_fancyslicing.py
63 test/tst_filepath.py
64 test/tst_get_variables_by_attributes.py
65 test/tst_grps.py
66 test/tst_grps2.py
67 test/tst_issue908.py
68 test/tst_masked.py
69 test/tst_masked2.py
70 test/tst_masked3.py
71 test/tst_masked4.py
72 test/tst_masked5.py
73 test/tst_masked6.py
74 test/tst_multifile.py
75 test/tst_multifile2.py
76 test/tst_open_mem.py
77 test/tst_refcount.py
78 test/tst_rename.py
79 test/tst_scalarvar.py
80 test/tst_scaled.py
81 test/tst_shape.py
82 test/tst_slicing.py
83 test/tst_stringarr.py
84 test/tst_types.py
85 test/tst_unicode.py
86 test/tst_unicode3.py
87 test/tst_unicodeatt.py
88 test/tst_unlimdim.py
89 test/tst_utils.py
90 test/tst_vars.py
91 test/tst_vlen.py
92 test/ubyte.nc
0 [console_scripts]
1 nc3tonc4 = netCDF4.utils:nc3tonc4
2 nc4tonc3 = netCDF4.utils:nc4tonc3
3 ncinfo = netCDF4.utils:ncinfo
4
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.
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
11 import unittest
22 import os
33 import tempfile
4 import numpy as NP
54 import netCDF4
65
76 # test group creation.
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:]]
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):
128128 nlons = 12; lon = f.createDimension('lon',nlons)
129129 nlevs = 1; lev = f.createDimension('lev',nlevs)
130130 time = f.createDimension('time',None)
131 var = f.createVariable('var',np.float_,('time','lev','lat','lon'))
131 var = f.createVariable('var',np.float64,('time','lev','lat','lon'))
132132 a = np.random.uniform(size=(10,nlevs,nlats,nlons))
133133 var[0:10] = a
134134 f.close()
167167 nlats = 11; lat = f.createDimension('lat',nlats)
168168 nlons = 20; lon = f.createDimension('lon',nlons)
169169 time = f.createDimension('time',None)
170 var = f.createVariable('var',np.float_,('time','lat','lon'))
170 var = f.createVariable('var',np.float64,('time','lat','lon'))
171171 a = np.random.uniform(size=(3,nlats,nlons))
172172 var[[True,True,False,False,False,True]] = a
173173 var[0,2.0,"-1"] = 0 # issue 312
202202 td = nc.createDimension('t',None)
203203 xd = nc.createDimension('x',33)
204204 yd = nc.createDimension('y',4)
205 v = nc.createVariable('v',np.float_,('t','x','y'))
205 v = nc.createVariable('v',np.float64,('t','x','y'))
206206 nc.close()
207207 nc = Dataset(self.file)
208208 data = np.empty(nc['v'].shape, nc['v'].dtype)
215215 f.createDimension('d1',3)
216216 f.createDimension('d2',None)
217217 f.createDimension('d3',5)
218 f.createVariable('v2',np.float_,('d1','d2','d3'))
218 f.createVariable('v2',np.float64,('d1','d2','d3'))
219219 f['v2'][:] = np.zeros((3,4,5))
220220 f['v2'][0,:,0] = np.arange(4)
221221 f['v2'][0,:,:] = np.ones((4,5))
226226 f.createDimension('time',2)
227227 f.createDimension('lat',10)
228228 f.createDimension('lon',9)
229 f.createVariable('v1',np.int,('time', 'lon','lat',))
229 f.createVariable('v1',np.int64,('time', 'lon','lat',))
230230 arr = np.arange(9*10).reshape((9, 10))
231231 f['v1'][:] = arr
232232 assert_array_equal(f['v1'][:],np.broadcast_to(arr,f['v1'].shape))
238238 with Dataset(self.file,'w') as f:
239239 f.createDimension('d1',3)
240240 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)
241 f.createVariable('v1',np.int64,('d2','d1',))
242 f['v1'][0] = np.arange(3,dtype=np.int64)
243 f['v1'][1:3] = np.arange(3,dtype=np.int64)
244244 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))
245 f.createVariable('v2',np.int64,('d1','d2',))
246 f['v2'][:,0] = np.arange(3,dtype=np.int64)
247 f['v2'][:,1:3] = np.arange(6,dtype=np.int64).reshape(3,2)
248 assert_array_equal(f['v2'][:,1:3],np.arange(6,dtype=np.int64).reshape(3,2))
249 assert_array_equal(f['v2'][:,0],np.arange(3,dtype=np.int64))
250250
251251 def test_issue1083(self):
252252 with Dataset(self.file, "w") as nc:
8585 else:
8686 assert(v2._FillValue == u'') # python 2
8787 assert(str(issue273_data) == str(v2[:]))
88 # isse 707 (don't apply missing_value if cast to variable type is
88 # issue 707 (don't apply missing_value if cast to variable type is
8989 # unsafe)
9090 v3 = f.variables['issue707']
9191 assert_array_equal(v3[:],-1*np.ones(n2dim,v3.dtype))
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):
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):
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__':
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