Codebase list netcdf4-python / 490997f
Update upstream source from tag 'upstream/1.6.0' Update to upstream version '1.6.0' with Debian dir 807c033155033571a21551a61c44a32296eed437 Bas Couwenberg 1 year, 10 months ago
25 changed file(s) with 1775 addition(s) and 505 deletion(s). Raw diff Collapse all Expand all
55 runs-on: ubuntu-latest
66 env:
77 PNETCDF_VERSION: 1.12.1
8 NETCDF_VERSION: 4.8.0
8 NETCDF_VERSION: 4.9.0
99 NETCDF_DIR: ${{ github.workspace }}/..
1010 NETCDF_EXTRA_CONFIG: --enable-pnetcdf
1111 CC: mpicc.mpich
2525 - name: Install Ubuntu Dependencies
2626 run: |
2727 sudo apt-get update
28 sudo apt-get install mpich libmpich-dev libhdf5-mpich-dev libcurl4-openssl-dev
28 sudo apt-get install mpich libmpich-dev libhdf5-mpich-dev libcurl4-openssl-dev bzip2 libsnappy-dev libblosc-dev libzstd-dev
2929 echo "Download and build PnetCDF version ${PNETCDF_VERSION}"
3030 wget https://parallel-netcdf.github.io/Release/pnetcdf-${PNETCDF_VERSION}.tar.gz
3131 tar -xzf pnetcdf-${PNETCDF_VERSION}.tar.gz
3535 make install
3636 popd
3737 echo "Download and build netCDF version ${NETCDF_VERSION}"
38 wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-c-${NETCDF_VERSION}.tar.gz
38 wget https://downloads.unidata.ucar.edu/netcdf-c/4.9.0/netcdf-c-${NETCDF_VERSION}.tar.gz
3939 tar -xzf netcdf-c-${NETCDF_VERSION}.tar.gz
4040 pushd netcdf-c-${NETCDF_VERSION}
4141 export CPPFLAGS="-I/usr/include/hdf5/mpich -I${NETCDF_DIR}/include"
6060 - name: Install netcdf4-python
6161 run: |
6262 export PATH=${NETCDF_DIR}/bin:${PATH}
63 export NETCDF_PLUGIN_DIR=${{ github.workspace }}/netcdf-c-${NETCDF_VERSION}/plugins/plugindir
6364 python setup.py install
6465 - name: Test
6566 run: |
9697 run: |
9798 export PATH=${NETCDF_DIR}/bin:${PATH}
9899 python setup.py --version
100 check-manifest --version
101 check-manifest --verbose
99102 pip wheel . -w dist --no-deps
100 check-manifest --verbose
101103 twine check dist/*
0 name: Build and Test on Linux with netcdf-c github master
1 on: [push, pull_request]
2 jobs:
3 build-linux:
4 name: Python (${{ matrix.python-version }})
5 runs-on: ubuntu-latest
6 env:
7 NETCDF_DIR: ${{ github.workspace }}/..
8 CC: mpicc.mpich
9 #NO_NET: 1
10 strategy:
11 matrix:
12 python-version: ["3.9"]
13 steps:
14
15 - uses: actions/checkout@v2
16
17 - name: Set up Python ${{ matrix.python-version }}
18 uses: actions/setup-python@v2
19 with:
20 python-version: ${{ matrix.python-version }}
21
22 - name: Install Ubuntu Dependencies
23 run: |
24 sudo apt-get update
25 sudo apt-get install mpich libmpich-dev libhdf5-mpich-dev libcurl4-openssl-dev bzip2 libsnappy-dev libblosc-dev libzstd-dev
26 echo "Download and build netCDF github master"
27 git clone https://github.com/Unidata/netcdf-c
28 pushd netcdf-c
29 export CPPFLAGS="-I/usr/include/hdf5/mpich -I${NETCDF_DIR}/include"
30 export LDFLAGS="-L${NETCDF_DIR}/lib"
31 export LIBS="-lhdf5_mpich_hl -lhdf5_mpich -lm -lz"
32 autoreconf -i
33 ./configure --prefix $NETCDF_DIR --enable-netcdf-4 --enable-shared --enable-dap --enable-parallel4
34 make -j 2
35 make install
36 popd
37
38 # - name: The job has failed
39 # if: ${{ failure() }}
40 # run: |
41 # cd netcdf-c-${NETCDF_VERSION}
42 # cat config.log
43
44 - name: Install python dependencies via pip
45 run: |
46 python -m pip install --upgrade pip
47 pip install numpy cython cftime pytest twine wheel check-manifest mpi4py
48
49 - name: Install netcdf4-python
50 run: |
51 export PATH=${NETCDF_DIR}/bin:${PATH}
52 export NETCDF_PLUGIN_DIR=${{ github.workspace }}/netcdf-c/plugins/plugindir
53 python setup.py install
54 - name: Test
55 run: |
56 export PATH=${NETCDF_DIR}/bin:${PATH}
57 #export HDF5_PLUGIN_PATH=${NETCDF_DIR}/plugins/plugindir
58 python checkversion.py
59 # serial
60 cd test
61 python run_all.py
62 # parallel
63 cd ../examples
64 mpirun.mpich -np 4 python mpi_example.py
65 if [ $? -ne 0 ] ; then
66 echo "hdf5 mpi test failed!"
67 exit 1
68 else
69 echo "hdf5 mpi test passed!"
70 fi
71 mpirun.mpich -np 4 python mpi_example_compressed.py
72 if [ $? -ne 0 ] ; then
73 echo "hdf5 compressed mpi test failed!"
74 exit 1
75 else
76 echo "hdf5 compressed mpi test passed!"
77 fi
7777 export PATH="${CONDA_PREFIX}/bin:${CONDA_PREFIX}/Library/bin:$PATH"
7878 which mpirun
7979 mpirun --version
80 #mpirun -np 4 --oversubscribe python mpi_example.py # for openmpi
8081 mpirun -np 4 python mpi_example.py
8182 if [ $? -ne 0 ] ; then
8283 echo "hdf5 mpi test failed!"
0 version 1.6.0 (tag v1.6.0rel)
1 ==============================
2 * add support for new quantization functionality in netcdf-c 4.9.0 via "signficant_digits"
3 and "quantize_mode" kwargs in Dataset.createVariable. Default quantization_mode is "BitGroom",
4 but alternate methods "BitRound" and GranularBitRound" also supported.
5 * opening a Dataset in append mode (mode = 'a' or 'r+') creates a Dataset
6 if one does not already exist (similar to python open builtin). Issue #1144.
7 Added a mode='x' option (as in python open) which is the same as mode='w' with
8 clobber=False.
9 * allow createVariable to accept either Dimension instances or Dimension
10 names in "dimensions" tuple kwarg (issue #1145).
11 * remove all vestiges of python 2 in _netCDF4.pyx and set cython language_level
12 directive to 3 in setup.py.
13 * add 'compression' kwarg to createVariable to enable new compression
14 functionality in netcdf-c 4.9.0. 'None','zlib','szip','zstd','bzip2'
15 'blosc_lz','blosc_lz4','blosc_lz4hc','blosc_zlib' and 'blosc_zstd'
16 are currently supported. 'blosc_shuffle',
17 'szip_mask' and 'szip_pixels_per_block' kwargs also added.
18 compression='zlib' is equivalent to (the now deprecated) zlib=True.
19 If the environment variable NETCDF_PLUGIN_DIR is set to point to the
20 directory with the compression plugin lib__nc* files, then the compression plugins will
21 be installed within the package and be automatically available (the binary
22 wheels have this). Otherwise, the environment variable HDF5_PLUGIN_PATH
23 needs to be set at runtime to point to plugins in order to use the new compression
24 options.
25 * MFDataset did not aggregate 'name' variable attribute (issue #1153).
26 * issue warning instead of raising an exception if missing_value or
27 _FillValue can't be cast to the variable type when creating a
28 masked array (issue #1152).
29 * Define MPI_Session for compatibility with current mpi4py (PR #1156).
30
031 version 1.5.8 (tag v1.5.8rel)
132 ==============================
233 * Fix Enum bug (issue #1128): the enum_dict member of an EnumType read from a file
55 include setup.cfg
66 include examples/*py
77 include examples/README.md
8 exclude examples/data
89 include test/*py
910 include test/*nc
1011 include src/netCDF4/__init__.py
1112 include src/netCDF4/_netCDF4.pyx
13 exclude src/netCDF4/_netCDF4.c
1214 include src/netCDF4/utils.py
15 include src/netCDF4/plugins/empty.txt
1316 include include/netCDF4.pxi
1417 include include/mpi-compat.h
1518 include include/membuf.pyx
88
99 ## News
1010 For details on the latest updates, see the [Changelog](https://github.com/Unidata/netcdf4-python/blob/master/Changelog).
11
12 ??/??/2022: Version [1.6.0](https://pypi.python.org/pypi/netCDF4/1.6.0) released. Support
13 for quantization (bit-grooming and bit-rounding) functionality in netcdf-c 4.9.0 which can
14 dramatically improve compression. Dataset.createVariable now accepts dimension instances (instead
15 of just dimension names). 'compression' kwarg added to Dataset.createVariable to support szip as
16 well as new compression algorithms available in netcdf-c 4.9.0 through compression plugins (such
17 as zstd, bzip2 and blosc). Working arm64 wheels for Apple M1 Silicon now available on pypi.
1118
1219 10/31/2021: Version [1.5.8](https://pypi.python.org/pypi/netCDF4/1.5.8) released. Fix Enum bug, add binary wheels for aarch64 and python 3.10.
1320
22 <head>
33 <meta charset="utf-8">
44 <meta name="viewport" content="width=device-width, initial-scale=1">
5 <meta name="generator" content="pdoc 7.1.0" />
5 <meta name="generator" content="pdoc 10.0.1"/>
66 <title>netCDF4 API documentation</title>
7 <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"/>
8
9
10 <style type="text/css">/*! * Bootstrap Reboot v5.0.0 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors * Copyright 2011-2021 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;background-color:#fff;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important}</style>
11 <style>/*! pygments syntax highlighting */pre{line-height:125%;}td.linenos pre{color:#000000; background-color:#f0f0f0; padding-left:5px; padding-right:5px;}span.linenos{color:#000000; background-color:#f0f0f0; padding-left:5px; padding-right:5px;}td.linenos pre.special{color:#000000; background-color:#ffffc0; padding-left:5px; padding-right:5px;}span.linenos.special{color:#000000; background-color:#ffffc0; padding-left:5px; padding-right:5px;}.pdoc .hll{background-color:#ffffcc}.pdoc{background:#f8f8f8;}.pdoc .c{color:#408080; font-style:italic}.pdoc .err{border:1px solid #FF0000}.pdoc .k{color:#008000; font-weight:bold}.pdoc .o{color:#666666}.pdoc .ch{color:#408080; font-style:italic}.pdoc .cm{color:#408080; font-style:italic}.pdoc .cp{color:#BC7A00}.pdoc .cpf{color:#408080; font-style:italic}.pdoc .c1{color:#408080; font-style:italic}.pdoc .cs{color:#408080; font-style:italic}.pdoc .gd{color:#A00000}.pdoc .ge{font-style:italic}.pdoc .gr{color:#FF0000}.pdoc .gh{color:#000080; font-weight:bold}.pdoc .gi{color:#00A000}.pdoc .go{color:#888888}.pdoc .gp{color:#000080; font-weight:bold}.pdoc .gs{font-weight:bold}.pdoc .gu{color:#800080; font-weight:bold}.pdoc .gt{color:#0044DD}.pdoc .kc{color:#008000; font-weight:bold}.pdoc .kd{color:#008000; font-weight:bold}.pdoc .kn{color:#008000; font-weight:bold}.pdoc .kp{color:#008000}.pdoc .kr{color:#008000; font-weight:bold}.pdoc .kt{color:#B00040}.pdoc .m{color:#666666}.pdoc .s{color:#BA2121}.pdoc .na{color:#7D9029}.pdoc .nb{color:#008000}.pdoc .nc{color:#0000FF; font-weight:bold}.pdoc .no{color:#880000}.pdoc .nd{color:#AA22FF}.pdoc .ni{color:#999999; font-weight:bold}.pdoc .ne{color:#D2413A; font-weight:bold}.pdoc .nf{color:#0000FF}.pdoc .nl{color:#A0A000}.pdoc .nn{color:#0000FF; font-weight:bold}.pdoc .nt{color:#008000; font-weight:bold}.pdoc .nv{color:#19177C}.pdoc .ow{color:#AA22FF; font-weight:bold}.pdoc .w{color:#bbbbbb}.pdoc .mb{color:#666666}.pdoc .mf{color:#666666}.pdoc .mh{color:#666666}.pdoc .mi{color:#666666}.pdoc .mo{color:#666666}.pdoc .sa{color:#BA2121}.pdoc .sb{color:#BA2121}.pdoc .sc{color:#BA2121}.pdoc .dl{color:#BA2121}.pdoc .sd{color:#BA2121; font-style:italic}.pdoc .s2{color:#BA2121}.pdoc .se{color:#BB6622; font-weight:bold}.pdoc .sh{color:#BA2121}.pdoc .si{color:#BB6688; font-weight:bold}.pdoc .sx{color:#008000}.pdoc .sr{color:#BB6688}.pdoc .s1{color:#BA2121}.pdoc .ss{color:#19177C}.pdoc .bp{color:#008000}.pdoc .fm{color:#0000FF}.pdoc .vc{color:#19177C}.pdoc .vg{color:#19177C}.pdoc .vi{color:#19177C}.pdoc .vm{color:#19177C}.pdoc .il{color:#666666}</style>
12 <style>/*! pdoc */:root{--pdoc-background:#fff;}.pdoc{--text:#212529;--muted:#6c757d;--link:#3660a5;--link-hover:#1659c5;--code:#f7f7f7;--active:#fff598;--accent:#eee;--accent2:#c1c1c1;--nav-hover:rgba(255, 255, 255, 0.5);--name:#0066BB;--def:#008800;--annotation:#007020;}body{background-color:var(--pdoc-background);}html, body{width:100%;height:100%;}@media (max-width:769px){#navtoggle{cursor:pointer;position:absolute;width:50px;height:40px;top:1rem;right:1rem;border-color:var(--text);color:var(--text);display:flex;opacity:0.8;}#navtoggle:hover{opacity:1;}#togglestate + div{display:none;}#togglestate:checked + div{display:inherit;}main, header{padding:2rem 3vw;}.git-button{display:none !important;}nav input[type="search"]:valid ~ *{display:none !important;}}@media (min-width:770px){:root{--sidebar-width:clamp(12.5rem, 28vw, 22rem);}nav{position:fixed;overflow:auto;height:100vh;width:var(--sidebar-width);}main, header{padding:3rem 2rem 3rem calc(var(--sidebar-width) + 3rem);width:calc(54rem + var(--sidebar-width));max-width:100%;}#navtoggle{display:none;}}#togglestate{display:none;}nav.pdoc{--pad:1.75rem;--indent:1.5rem;background-color:var(--accent);border-right:1px solid var(--accent2);box-shadow:0 0 20px rgba(50, 50, 50, .2) inset;padding:0 0 0 var(--pad);overflow-wrap:anywhere;scrollbar-width:thin; scrollbar-color:var(--accent2) transparent }nav.pdoc::-webkit-scrollbar{width:.4rem; }nav.pdoc::-webkit-scrollbar-thumb{background-color:var(--accent2); }nav.pdoc > div{padding:var(--pad) 0;}nav.pdoc .module-list-button{display:inline-flex;align-items:center;color:var(--text);border-color:var(--muted);margin-bottom:1rem;}nav.pdoc .module-list-button:hover{border-color:var(--text);}nav.pdoc input[type=search]{display:block;outline-offset:0;width:calc(100% - var(--pad));}nav.pdoc ul{list-style:none;padding-left:0;}nav.pdoc li{display:block;margin:0;padding:.2rem 0 .2rem var(--indent);transition:all 100ms;}nav.pdoc > div > ul > li{padding-left:0;}nav.pdoc li:hover{background-color:var(--nav-hover);}nav.pdoc a, nav.pdoc a:hover{color:var(--text);}nav.pdoc a{display:block;}nav.pdoc > h2:first-of-type{margin-top:1.5rem;}nav.pdoc .class:before{content:"class ";color:var(--muted);}nav.pdoc .function:after{content:"()";color:var(--muted);}html, main{scroll-behavior:smooth;}.pdoc{color:var(--text);box-sizing:border-box;line-height:1.5;background:none;}.pdoc .pdoc-button{display:inline-block;border:solid black 1px;border-radius:2px;font-size:.75rem;padding:calc(0.5em - 1px) 1em;transition:100ms all;}.pdoc .visually-hidden{position:absolute !important;width:1px !important;height:1px !important;padding:0 !important;margin:-1px !important;overflow:hidden !important;clip:rect(0, 0, 0, 0) !important;white-space:nowrap !important;border:0 !important;}.pdoc h1, .pdoc h2, .pdoc h3{font-weight:300;margin:.3em 0;padding:.2em 0;}.pdoc a{text-decoration:none;color:var(--link);}.pdoc a:hover{color:var(--link-hover);}.pdoc blockquote{margin-left:2rem;}.pdoc pre{background-color:var(--code);border-top:1px solid var(--accent2);border-bottom:1px solid var(--accent2);margin-bottom:1em;padding:.5rem 0 .5rem .5rem;overflow-x:auto;}.pdoc code{color:var(--text);padding:.2em .4em;margin:0;font-size:85%;background-color:var(--code);border-radius:6px;}.pdoc a > code{color:inherit;}.pdoc pre > code{display:inline-block;font-size:inherit;background:none;border:none;padding:0;}.pdoc .modulename{margin-top:0;font-weight:bold;}.pdoc .modulename a{color:var(--link);transition:100ms all;}.pdoc .git-button{float:right;border:solid var(--link) 1px;}.pdoc .git-button:hover{background-color:var(--link);color:var(--pdoc-background);}.pdoc details{--shift:-40px;text-align:right;margin-top:var(--shift);margin-bottom:calc(0px - var(--shift));clear:both;filter:opacity(1);}.pdoc details:not([open]){height:0;overflow:visible;}.pdoc details > summary{font-size:.75rem;cursor:pointer;color:var(--muted);border-width:0;padding:0 .7em;display:inline-block;display:inline list-item;user-select:none;}.pdoc details > summary:focus{outline:0;}.pdoc details > div{margin-top:calc(0px - var(--shift) / 2);text-align:left;}.pdoc .docstring{margin-bottom:1.5rem;}.pdoc > section:first-of-type > .docstring{margin-bottom:3rem;}.pdoc .docstring pre{margin-left:1em;margin-right:1em;}.pdoc h1:target,.pdoc h2:target,.pdoc h3:target,.pdoc h4:target,.pdoc h5:target,.pdoc h6:target{background-color:var(--active);box-shadow:-1rem 0 0 0 var(--active);}.pdoc div:target > .attr,.pdoc section:target > .attr,.pdoc dd:target > a{background-color:var(--active);}.pdoc .attr:hover{filter:contrast(0.95);}.pdoc .headerlink{position:absolute;width:0;margin-left:-1.5rem;line-height:1.4rem;font-size:1.5rem;font-weight:normal;transition:all 100ms ease-in-out;opacity:0;}.pdoc .attr > .headerlink{margin-left:-2.5rem;}.pdoc *:hover > .headerlink,.pdoc *:target > .attr > .headerlink{opacity:1;}.pdoc .attr{display:block;color:var(--text);margin:1rem 0 .5rem;padding:.4rem 5rem .4rem 1rem;background-color:var(--accent);}.pdoc .classattr{margin-left:2rem;}.pdoc .name{color:var(--name);font-weight:bold;}.pdoc .def{color:var(--def);font-weight:bold;}.pdoc .signature{white-space:pre-wrap;}.pdoc .annotation{color:var(--annotation);}.pdoc .inherited{margin-left:2rem;}.pdoc .inherited dt{font-weight:700;}.pdoc .inherited dt, .pdoc .inherited dd{display:inline;margin-left:0;margin-bottom:.5rem;}.pdoc .inherited dd:not(:last-child):after{content:", ";}.pdoc .inherited .class:before{content:"class ";}.pdoc .inherited .function a:after{content:"()";}.pdoc .search-result .docstring{overflow:auto;max-height:25vh;}.pdoc .search-result.focused > .attr{background-color:var(--active);}.pdoc .attribution{margin-top:2rem;display:block;opacity:0.5;transition:all 200ms;filter:grayscale(100%);}.pdoc .attribution:hover{opacity:1;filter:grayscale(0%);}.pdoc .attribution img{margin-left:5px;height:35px;vertical-align:middle;width:70px;transition:all 200ms;}</style>
13 </head>
14 <body> <nav class="pdoc">
15 <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>
16 <input id="togglestate" type="checkbox">
17 <div>
18
19
20
21 <h2>Contents</h2>
22 <ul>
23 <li><a href="#version-157">Version 1.5.7</a></li>
7
8 <style>/*! * Bootstrap Reboot v5.0.0 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors * Copyright 2011-2021 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;background-color:#fff;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important}</style>
9 <style>/*! syntax-highlighting.css */pre{line-height:125%;}span.linenos{color:inherit; background-color:transparent; padding-left:5px; padding-right:20px;}.pdoc-code .hll{background-color:#ffffcc}.pdoc-code{background:#f8f8f8;}.pdoc-code .c{color:#3D7B7B; font-style:italic}.pdoc-code .err{border:1px solid #FF0000}.pdoc-code .k{color:#008000; font-weight:bold}.pdoc-code .o{color:#666666}.pdoc-code .ch{color:#3D7B7B; font-style:italic}.pdoc-code .cm{color:#3D7B7B; font-style:italic}.pdoc-code .cp{color:#9C6500}.pdoc-code .cpf{color:#3D7B7B; font-style:italic}.pdoc-code .c1{color:#3D7B7B; font-style:italic}.pdoc-code .cs{color:#3D7B7B; font-style:italic}.pdoc-code .gd{color:#A00000}.pdoc-code .ge{font-style:italic}.pdoc-code .gr{color:#E40000}.pdoc-code .gh{color:#000080; font-weight:bold}.pdoc-code .gi{color:#008400}.pdoc-code .go{color:#717171}.pdoc-code .gp{color:#000080; font-weight:bold}.pdoc-code .gs{font-weight:bold}.pdoc-code .gu{color:#800080; font-weight:bold}.pdoc-code .gt{color:#0044DD}.pdoc-code .kc{color:#008000; font-weight:bold}.pdoc-code .kd{color:#008000; font-weight:bold}.pdoc-code .kn{color:#008000; font-weight:bold}.pdoc-code .kp{color:#008000}.pdoc-code .kr{color:#008000; font-weight:bold}.pdoc-code .kt{color:#B00040}.pdoc-code .m{color:#666666}.pdoc-code .s{color:#BA2121}.pdoc-code .na{color:#687822}.pdoc-code .nb{color:#008000}.pdoc-code .nc{color:#0000FF; font-weight:bold}.pdoc-code .no{color:#880000}.pdoc-code .nd{color:#AA22FF}.pdoc-code .ni{color:#717171; font-weight:bold}.pdoc-code .ne{color:#CB3F38; font-weight:bold}.pdoc-code .nf{color:#0000FF}.pdoc-code .nl{color:#767600}.pdoc-code .nn{color:#0000FF; font-weight:bold}.pdoc-code .nt{color:#008000; font-weight:bold}.pdoc-code .nv{color:#19177C}.pdoc-code .ow{color:#AA22FF; font-weight:bold}.pdoc-code .w{color:#bbbbbb}.pdoc-code .mb{color:#666666}.pdoc-code .mf{color:#666666}.pdoc-code .mh{color:#666666}.pdoc-code .mi{color:#666666}.pdoc-code .mo{color:#666666}.pdoc-code .sa{color:#BA2121}.pdoc-code .sb{color:#BA2121}.pdoc-code .sc{color:#BA2121}.pdoc-code .dl{color:#BA2121}.pdoc-code .sd{color:#BA2121; font-style:italic}.pdoc-code .s2{color:#BA2121}.pdoc-code .se{color:#AA5D1F; font-weight:bold}.pdoc-code .sh{color:#BA2121}.pdoc-code .si{color:#A45A77; font-weight:bold}.pdoc-code .sx{color:#008000}.pdoc-code .sr{color:#A45A77}.pdoc-code .s1{color:#BA2121}.pdoc-code .ss{color:#19177C}.pdoc-code .bp{color:#008000}.pdoc-code .fm{color:#0000FF}.pdoc-code .vc{color:#19177C}.pdoc-code .vg{color:#19177C}.pdoc-code .vi{color:#19177C}.pdoc-code .vm{color:#19177C}.pdoc-code .il{color:#666666}</style>
10 <style>/*! theme.css */:root{--pdoc-background:#fff;}.pdoc{--text:#212529;--muted:#6c757d;--link:#3660a5;--link-hover:#1659c5;--code:#f8f8f8;--active:#fff598;--accent:#eee;--accent2:#c1c1c1;--nav-hover:rgba(255, 255, 255, 0.5);--name:#0066BB;--def:#008800;--annotation:#007020;}</style>
11 <style>/*! layout.css */html, body{width:100%;height:100%;}html, main{scroll-behavior:smooth;}body{background-color:var(--pdoc-background);}@media (max-width:769px){#navtoggle{cursor:pointer;position:absolute;width:50px;height:40px;top:1rem;right:1rem;border-color:var(--text);color:var(--text);display:flex;opacity:0.8;}#navtoggle:hover{opacity:1;}#togglestate + div{display:none;}#togglestate:checked + div{display:inherit;}main, header{padding:2rem 3vw;}header + main{margin-top:-3rem;}.git-button{display:none !important;}nav input[type="search"]{max-width:77%;}nav input[type="search"]:first-child{margin-top:-6px;}nav input[type="search"]:valid ~ *{display:none !important;}}@media (min-width:770px){:root{--sidebar-width:clamp(12.5rem, 28vw, 22rem);}nav{position:fixed;overflow:auto;height:100vh;width:var(--sidebar-width);}main, header{padding:3rem 2rem 3rem calc(var(--sidebar-width) + 3rem);width:calc(54rem + var(--sidebar-width));max-width:100%;}header + main{margin-top:-4rem;}#navtoggle{display:none;}}#togglestate{position:absolute;height:0;}nav.pdoc{--pad:1.75rem;--indent:1.5rem;background-color:var(--accent);border-right:1px solid var(--accent2);box-shadow:0 0 20px rgba(50, 50, 50, .2) inset;padding:0 0 0 var(--pad);overflow-wrap:anywhere;scrollbar-width:thin; scrollbar-color:var(--accent2) transparent }nav.pdoc::-webkit-scrollbar{width:.4rem; }nav.pdoc::-webkit-scrollbar-thumb{background-color:var(--accent2); }nav.pdoc > div{padding:var(--pad) 0;}nav.pdoc .module-list-button{display:inline-flex;align-items:center;color:var(--text);border-color:var(--muted);margin-bottom:1rem;}nav.pdoc .module-list-button:hover{border-color:var(--text);}nav.pdoc input[type=search]{display:block;outline-offset:0;width:calc(100% - var(--pad));}nav.pdoc .logo{max-width:calc(100% - var(--pad));max-height:35vh;display:block;margin:0 auto 1rem;transform:translate(calc(-.5 * var(--pad)), 0);}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);}nav.pdoc footer:before{content:"";display:block;width:calc(100% - var(--pad));border-top:solid var(--accent2) 1px;margin-top:1.5rem;padding-top:.5rem;}nav.pdoc footer{font-size:small;}</style>
12 <style>/*! content.css */.pdoc{color:var(--text);box-sizing:border-box;line-height:1.5;background:none;}.pdoc .pdoc-button{display:inline-block;border:solid black 1px;border-radius:2px;font-size:.75rem;padding:calc(0.5em - 1px) 1em;transition:100ms all;}.pdoc .visually-hidden{position:absolute !important;width:1px !important;height:1px !important;padding:0 !important;margin:-1px !important;overflow:hidden !important;clip:rect(0, 0, 0, 0) !important;white-space:nowrap !important;border:0 !important;}.pdoc h1, .pdoc h2, .pdoc h3{font-weight:300;margin:.3em 0;padding:.2em 0;}.pdoc a{text-decoration:none;color:var(--link);}.pdoc a:hover{color:var(--link-hover);}.pdoc blockquote{margin-left:2rem;}.pdoc pre{border-top:1px solid var(--accent2);border-bottom:1px solid var(--accent2);margin-top:0;margin-bottom:1em;padding:.5rem 0 .5rem .5rem;overflow-x:auto;background-color:var(--code);}.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{filter:opacity(1);}.pdoc details:not([open]){height:0;}.pdoc details > summary{position:absolute;top:-35px;right:0;font-size:.75rem;color:var(--muted);padding:0 .7em;user-select:none;cursor:pointer;}.pdoc details > summary:focus{outline:0;}.pdoc .docstring{margin-bottom:1.5rem;}.pdoc > section:first-of-type > .docstring{margin-bottom:2.5rem;}.pdoc .docstring .pdoc-code{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;user-select:none;}.pdoc .attr > .headerlink{margin-left:-2.5rem;}.pdoc *:hover > .headerlink,.pdoc *:target > .attr > .headerlink{opacity:1;}.pdoc .attr{display:block;color:var(--text);margin:.5rem 0 .5rem;padding:.4rem 5rem .4rem 1rem;background-color:var(--accent);}.pdoc .classattr{margin-left:2rem;}.pdoc .name{color:var(--name);font-weight:bold;}.pdoc .def{color:var(--def);font-weight:bold;}.pdoc .signature{white-space:pre-wrap;}.pdoc .annotation{color:var(--annotation);}.pdoc .inherited{margin-left:2rem;}.pdoc .inherited dt{font-weight:700;}.pdoc .inherited dt, .pdoc .inherited dd{display:inline;margin-left:0;margin-bottom:.5rem;}.pdoc .inherited dd:not(:last-child):after{content:", ";}.pdoc .inherited .class:before{content:"class ";}.pdoc .inherited .function a:after{content:"()";}.pdoc .search-result .docstring{overflow:auto;max-height:25vh;}.pdoc .search-result.focused > .attr{background-color:var(--active);}.pdoc .attribution{margin-top:2rem;display:block;opacity:0.5;transition:all 200ms;filter:grayscale(100%);}.pdoc .attribution:hover{opacity:1;filter:grayscale(0%);}.pdoc .attribution img{margin-left:5px;height:35px;vertical-align:middle;width:70px;transition:all 200ms;}.pdoc table{display:block;width:max-content;max-width:100%;overflow:auto;margin-bottom:1rem;}.pdoc table th{font-weight:600;}.pdoc table th, .pdoc table td{padding:6px 13px;border:1px solid var(--accent2);}</style>
13 <style>/*! custom.css */</style></head>
14 <body>
15 <nav class="pdoc">
16 <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>
17 <input id="togglestate" type="checkbox" aria-hidden="true" tabindex="-1">
18 <div>
19
20
21 <h2>Contents</h2>
22 <ul>
23 <li><a href="#version-160">Version 1.6.0</a></li>
2424 </ul></li>
2525 <li><a href="#introduction">Introduction</a>
2626 <ul>
4848
4949
5050
51 <h2>API Documentation</h2>
52 <ul class="memberlist">
51 <h2>API Documentation</h2>
52 <ul class="memberlist">
5353 <li>
5454 <a class="class" href="#Dataset">Dataset</a>
5555 <ul class="memberlist">
220220 </li>
221221 <li>
222222 <a class="function" href="#Variable.filters">filters</a>
223 </li>
224 <li>
225 <a class="function" href="#Variable.quantization">quantization</a>
223226 </li>
224227 <li>
225228 <a class="function" href="#Variable.endian">endian</a>
443446 </ul>
444447
445448
446 <a class="attribution" title="pdoc: Python API documentation generator" href="https://pdoc.dev">
447 built with <span class="visually-hidden">pdoc</span><img
448 alt="pdoc logo"
449 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"/>
450 </a>
451 </div>
452 </nav>
449
450 <a class="attribution" title="pdoc: Python API documentation generator" href="https://pdoc.dev">
451 built with <span class="visually-hidden">pdoc</span><img
452 alt="pdoc logo"
453 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"/>
454 </a>
455 </div>
456 </nav>
453457 <main class="pdoc">
454458 <section>
455459 <h1 class="modulename">
456460 netCDF4 </h1>
457461
458 <div class="docstring"><h2 id="version-157">Version 1.5.7</h2>
462 <div class="docstring"><h2 id="version-160">Version 1.6.0</h2>
459463
460464 <h1 id="introduction">Introduction</h1>
461465
470474 and should be familiar to users of that module.</p>
471475
472476 <p>Most new features of netCDF 4 are implemented, such as multiple
473 unlimited dimensions, groups and zlib data compression. All the new
477 unlimited dimensions, groups and data compression. All the new
474478 numeric data types (such as 64 bit and unsigned integer types) are
475479 implemented. Compound (struct), variable length (vlen) and
476480 enumerated (enum) data types are supported, but not the opaque data type.
516520 If the dependencies are not found
517521 in any of the paths specified by environment variables, then standard locations
518522 (such as <code>/usr</code> and <code>/usr/local</code>) are searched.</li>
523 <li>if the env var <code>NETCDF_PLUGIN_DIR</code> is set to point to the location netcdf-c compression
524 plugin shared objects, they will be installed inside the package. In this
525 case <code>HDF5_PLUGIN_PATH</code> will be set to the package installation path on import,
526 so the extra compression algorithms available in netcdf-c 4.9.0 will automatically
527 be available. Otherwise, the user will have to set <code>HDF5_PLUGIN_PATH</code> explicitly
528 to have access to the extra compression plugins.</li>
519529 <li>run <code>python setup.py build</code>, then <code>python setup.py install</code> (as root if
520530 necessary).</li>
521531 <li>run the tests in the 'test' directory by running <code>python run_all.py</code>.</li>
572582
573583 <p>Here's an example:</p>
574584
575 <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">Dataset</span>
585 <div class="pdoc-code 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">Dataset</span>
576586 <span class="o">&gt;&gt;&gt;</span> <span class="n">rootgrp</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="s2">&quot;test.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&quot;</span><span class="p">)</span>
577587 <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">data_model</span><span class="p">)</span>
578588 <span class="n">NETCDF4</span>
601611 <code>NETCDF4</code> formatted files support Groups, if you try to create a Group
602612 in a netCDF 3 file you will get an error message.</p>
603613
604 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">rootgrp</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="s2">&quot;test.nc&quot;</span><span class="p">,</span> <span class="s2">&quot;a&quot;</span><span class="p">)</span>
614 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">rootgrp</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="s2">&quot;test.nc&quot;</span><span class="p">,</span> <span class="s2">&quot;a&quot;</span><span class="p">)</span>
605615 <span class="o">&gt;&gt;&gt;</span> <span class="n">fcstgrp</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&quot;</span><span class="p">)</span>
606616 <span class="o">&gt;&gt;&gt;</span> <span class="n">analgrp</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;analyses&quot;</span><span class="p">)</span>
607617 <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">groups</span><span class="p">)</span>
625635 that group. To simplify the creation of nested groups, you can
626636 use a unix-like path as an argument to <code><a href="#Dataset.createGroup">Dataset.createGroup</a></code>.</p>
627637
628 <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>
638 <div class="pdoc-code 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>
629639 <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>
630640 </code></pre></div>
631641
639649 to walk the directory tree. Note that printing the <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code>
640650 object yields summary information about it's contents.</p>
641651
642 <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>
652 <div class="pdoc-code 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>
643653 <span class="o">...</span> <span class="k">yield</span> <span class="n">top</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">values</span><span class="p">()</span>
644654 <span class="o">...</span> <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">top</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
645655 <span class="o">...</span> <span class="k">yield from</span> <span class="n">walktree</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
689699 dimension is a new netCDF 4 feature, in netCDF 3 files there may be only
690700 one, and it must be the first (leftmost) dimension of the variable.</p>
691701
692 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">level</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;level&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
702 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">level</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;level&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
693703 <span class="o">&gt;&gt;&gt;</span> <span class="n">time</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;time&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
694704 <span class="o">&gt;&gt;&gt;</span> <span class="n">lat</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;lat&quot;</span><span class="p">,</span> <span class="mi">73</span><span class="p">)</span>
695705 <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>
697707
698708 <p>All of the <code><a href="#Dimension">Dimension</a></code> instances are stored in a python dictionary.</p>
699709
700 <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>
710 <div class="pdoc-code 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>
701711 <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>
702712 </code></pre></div>
703713
706716 <code><a href="#Dimension.isunlimited">Dimension.isunlimited</a></code> method of a <code><a href="#Dimension">Dimension</a></code> instance
707717 be used to determine if the dimensions is unlimited, or appendable.</p>
708718
709 <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>
719 <div class="pdoc-code 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>
710720 <span class="mi">144</span>
711721 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">lon</span><span class="o">.</span><span class="n">isunlimited</span><span class="p">())</span>
712722 <span class="kc">False</span>
718728 provides useful summary info, including the name and length of the dimension,
719729 and whether it is unlimited.</p>
720730
721 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">dimobj</span> <span class="ow">in</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">dimensions</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
731 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">dimobj</span> <span class="ow">in</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">dimensions</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
722732 <span class="o">...</span> <span class="nb">print</span><span class="p">(</span><span class="n">dimobj</span><span class="p">)</span>
723733 <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</span>
724734 <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">time</span><span class="s1">&#39;, size = 0</span>
763773 method returns an instance of the <code><a href="#Variable">Variable</a></code> class whose methods can be
764774 used later to access and set variable data and attributes.</p>
765775
766 <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>
776 <div class="pdoc-code 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>
767777 <span class="o">&gt;&gt;&gt;</span> <span class="n">levels</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;level&quot;</span><span class="p">,</span><span class="s2">&quot;i4&quot;</span><span class="p">,(</span><span class="s2">&quot;level&quot;</span><span class="p">,))</span>
768778 <span class="o">&gt;&gt;&gt;</span> <span class="n">latitudes</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;lat&quot;</span><span class="p">,</span><span class="s2">&quot;f4&quot;</span><span class="p">,(</span><span class="s2">&quot;lat&quot;</span><span class="p">,))</span>
769779 <span class="o">&gt;&gt;&gt;</span> <span class="n">longitudes</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;lon&quot;</span><span class="p">,</span><span class="s2">&quot;f4&quot;</span><span class="p">,(</span><span class="s2">&quot;lon&quot;</span><span class="p">,))</span>
775785 <p>To get summary info on a <code><a href="#Variable">Variable</a></code> instance in an interactive session,
776786 just print it.</p>
777787
778 <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>
788 <div class="pdoc-code 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>
779789 <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">Variable</span><span class="s1">&#39;&gt;</span>
780790 <span class="n">float32</span> <span class="n">temp</span><span class="p">(</span><span class="n">time</span><span class="p">,</span> <span class="n">level</span><span class="p">,</span> <span class="n">lat</span><span class="p">,</span> <span class="n">lon</span><span class="p">)</span>
781791 <span class="n">units</span><span class="p">:</span> <span class="n">K</span>
786796
787797 <p>You can use a path to create a Variable inside a hierarchy of groups.</p>
788798
789 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">ftemp</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;/forecasts/model1/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>
799 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">ftemp</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;/forecasts/model1/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>
790800 </code></pre></div>
791801
792802 <p>If the intermediate groups do not yet exist, they will be created.</p>
794804 <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
795805 <code><a href="#Variable">Variable</a></code> instances using paths.</p>
796806
797 <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>
807 <div class="pdoc-code 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>
798808 <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>
799809 <span class="n">group</span> <span class="o">/</span><span class="n">forecasts</span><span class="o">/</span><span class="n">model1</span><span class="p">:</span>
800810 <span class="n">dimensions</span><span class="p">(</span><span class="n">sizes</span><span class="p">):</span>
812822 <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
813823 Python dictionary, in the same way as the dimensions:</p>
814824
815 <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>
825 <div class="pdoc-code 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>
816826 <span class="p">{</span><span class="s1">&#39;time&#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">Variable</span><span class="s1">&#39;&gt;</span>
817827 <span class="n">float64</span> <span class="n">time</span><span class="p">(</span><span class="n">time</span><span class="p">)</span>
818828 <span class="n">unlimited</span> <span class="n">dimensions</span><span class="p">:</span> <span class="n">time</span>
855865 variables. Attributes can be strings, numbers or sequences. Returning to
856866 our example,</p>
857867
858 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">time</span>
868 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">time</span>
859869 <span class="o">&gt;&gt;&gt;</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">description</span> <span class="o">=</span> <span class="s2">&quot;bogus example script&quot;</span>
860870 <span class="o">&gt;&gt;&gt;</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">history</span> <span class="o">=</span> <span class="s2">&quot;Created &quot;</span> <span class="o">+</span> <span class="n">time</span><span class="o">.</span><span class="n">ctime</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span>
861871 <span class="o">&gt;&gt;&gt;</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">source</span> <span class="o">=</span> <span class="s2">&quot;netCDF4 python module tutorial&quot;</span>
873883 built-in <code>dir</code> Python function will return a bunch of private methods
874884 and attributes that cannot (or should not) be modified by the user.</p>
875885
876 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">ncattrs</span><span class="p">():</span>
886 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">ncattrs</span><span class="p">():</span>
877887 <span class="o">...</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Global attr </span><span class="si">{}</span><span class="s2"> = </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">name</span><span class="p">,</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">rootgrp</span><span class="p">,</span> <span class="n">name</span><span class="p">)))</span>
878888 <span class="n">Global</span> <span class="n">attr</span> <span class="n">description</span> <span class="o">=</span> <span class="n">bogus</span> <span class="n">example</span> <span class="n">script</span>
879889 <span class="n">Global</span> <span class="n">attr</span> <span class="n">history</span> <span class="o">=</span> <span class="n">Created</span> <span class="n">Mon</span> <span class="n">Jul</span> <span class="mi">8</span> <span class="mi">14</span><span class="p">:</span><span class="mi">19</span><span class="p">:</span><span class="mi">41</span> <span class="mi">2019</span>
884894 instance provides all the netCDF attribute name/value pairs in a python
885895 dictionary:</p>
886896
887 <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="vm">__dict__</span><span class="p">)</span>
897 <div class="pdoc-code 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="vm">__dict__</span><span class="p">)</span>
888898 <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>
889899 </code></pre></div>
890900
897907 <p>Now that you have a netCDF <code><a href="#Variable">Variable</a></code> instance, how do you put data
898908 into it? You can just treat it like an array and assign data to a slice.</p>
899909
900 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
910 <div class="pdoc-code 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>
901911 <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>
902912 <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>
903913 <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>
917927 objects with unlimited dimensions will grow along those dimensions if you
918928 assign data outside the currently defined range of indices.</p>
919929
920 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="c1"># append along two unlimited dimensions by assigning to slice.</span>
930 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="c1"># append along two unlimited dimensions by assigning to slice.</span>
921931 <span class="o">&gt;&gt;&gt;</span> <span class="n">nlats</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">rootgrp</span><span class="o">.</span><span class="n">dimensions</span><span class="p">[</span><span class="s2">&quot;lat&quot;</span><span class="p">])</span>
922932 <span class="o">&gt;&gt;&gt;</span> <span class="n">nlons</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">rootgrp</span><span class="o">.</span><span class="n">dimensions</span><span class="p">[</span><span class="s2">&quot;lon&quot;</span><span class="p">])</span>
923933 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;temp shape before adding data = </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">temp</span><span class="o">.</span><span class="n">shape</span><span class="p">))</span>
937947 along the <code>level</code> dimension of the variable <code>temp</code>, even though no
938948 data has yet been assigned to levels.</p>
939949
940 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="c1"># now, assign data to levels dimension variable.</span>
950 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="c1"># now, assign data to levels dimension variable.</span>
941951 <span class="o">&gt;&gt;&gt;</span> <span class="n">levels</span><span class="p">[:]</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1000.</span><span class="p">,</span><span class="mf">850.</span><span class="p">,</span><span class="mf">700.</span><span class="p">,</span><span class="mf">500.</span><span class="p">,</span><span class="mf">300.</span><span class="p">,</span><span class="mf">250.</span><span class="p">,</span><span class="mf">200.</span><span class="p">,</span><span class="mf">150.</span><span class="p">,</span><span class="mf">100.</span><span class="p">,</span><span class="mf">50.</span><span class="p">]</span>
942952 </code></pre></div>
943953
950960 allowed, and these indices work independently along each dimension (similar
951961 to the way vector subscripts work in fortran). This means that</p>
952962
953 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">temp</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">]]</span><span class="o">.</span><span class="n">shape</span>
963 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">temp</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">]]</span><span class="o">.</span><span class="n">shape</span>
954964 <span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
955965 </code></pre></div>
956966
968978
969979 <p>For example,</p>
970980
971 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">tempdat</span> <span class="o">=</span> <span class="n">temp</span><span class="p">[::</span><span class="mi">2</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">6</span><span class="p">],</span> <span class="n">lats</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">,</span> <span class="n">lons</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">]</span>
981 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">tempdat</span> <span class="o">=</span> <span class="n">temp</span><span class="p">[::</span><span class="mi">2</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">6</span><span class="p">],</span> <span class="n">lats</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">,</span> <span class="n">lons</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">]</span>
972982 </code></pre></div>
973983
974984 <p>will extract time indices 0,2 and 4, pressure levels
975985 850, 500 and 200 hPa, all Northern Hemisphere latitudes and Eastern
976986 Hemisphere longitudes, resulting in a numpy array of shape (3, 3, 36, 71).</p>
977987
978 <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="s2">&quot;shape of fancy temp slice = </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">tempdat</span><span class="o">.</span><span class="n">shape</span><span class="p">))</span>
988 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;shape of fancy temp slice = </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">tempdat</span><span class="o">.</span><span class="n">shape</span><span class="p">))</span>
979989 <span class="n">shape</span> <span class="n">of</span> <span class="n">fancy</span> <span class="n">temp</span> <span class="nb">slice</span> <span class="o">=</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">36</span><span class="p">,</span> <span class="mi">71</span><span class="p">)</span>
980990 </code></pre></div>
981991
10081018 provided by <a href="https://unidata.github.io/cftime">cftime</a> to do just that.
10091019 Here's an example of how they can be used:</p>
10101020
1011 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="c1"># fill in times.</span>
1021 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="c1"># fill in times.</span>
10121022 <span class="o">&gt;&gt;&gt;</span> <span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timedelta</span>
10131023 <span class="o">&gt;&gt;&gt;</span> <span class="kn">from</span> <span class="nn">cftime</span> <span class="kn">import</span> <span class="n">num2date</span><span class="p">,</span> <span class="n">date2num</span>
10141024 <span class="o">&gt;&gt;&gt;</span> <span class="n">dates</span> <span class="o">=</span> <span class="p">[</span><span class="n">datetime</span><span class="p">(</span><span class="mi">2001</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span><span class="o">+</span><span class="n">n</span><span class="o">*</span><span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="mi">12</span><span class="p">)</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="n">temp</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])]</span>
10481058 <code>NETCDF4_CLASSIC</code> format (<code>NETCDF4</code> formatted multi-file
10491059 datasets are not supported).</p>
10501060
1051 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">nf</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>
1061 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">nf</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>
10521062 <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>
10531063 <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>
10541064 <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>
10571067
10581068 <p>Now read all the files back in at once with <code><a href="#MFDataset">MFDataset</a></code></p>
10591069
1060 <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>
1070 <div class="pdoc-code 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>
10611071 <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>
10621072 <span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s2">&quot;x&quot;</span><span class="p">][:])</span>
10631073 <span class="p">[</span> <span class="mi">0</span> <span class="mi">1</span> <span class="mi">2</span> <span class="mi">3</span> <span class="mi">4</span> <span class="mi">5</span> <span class="mi">6</span> <span class="mi">7</span> <span class="mi">8</span> <span class="mi">9</span> <span class="mi">10</span> <span class="mi">11</span> <span class="mi">12</span> <span class="mi">13</span> <span class="mi">14</span> <span class="mi">15</span> <span class="mi">16</span> <span class="mi">17</span> <span class="mi">18</span> <span class="mi">19</span> <span class="mi">20</span> <span class="mi">21</span> <span class="mi">22</span> <span class="mi">23</span>
10721082
10731083 <h2 id="efficient-compression-of-netcdf-variables">Efficient compression of netCDF variables</h2>
10741084
1075 <p>Data stored in netCDF 4 <code><a href="#Variable">Variable</a></code> objects can be compressed and
1076 decompressed on the fly. The parameters for the compression are
1077 determined by the <code>zlib</code>, <code>complevel</code> and <code>shuffle</code> keyword arguments
1078 to the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method. To turn on
1079 compression, set <code>zlib=True</code>. The <code>complevel</code> keyword regulates the
1080 speed and efficiency of the compression (1 being fastest, but lowest
1085 <p>Data stored in netCDF <code><a href="#Variable">Variable</a></code> objects can be compressed and
1086 decompressed on the fly. The compression algorithm used is determined
1087 by the <code>compression</code> keyword argument to the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method.
1088 <code>zlib</code> compression is always available, <code>szip</code> is available if the linked HDF5
1089 library supports it, and <code>zstd</code>, <code>bzip2</code>, <code>blosc_lz</code>,<code>blosc_lz4</code>,<code>blosc_lz4hc</code>,
1090 <code>blosc_zlib</code> and <code>blosc_zstd</code> are available via optional external plugins.
1091 The <code>complevel</code> keyword regulates the
1092 speed and efficiency of the compression for <code>zlib</code>, <code>bzip</code> and <code>zstd</code> (1 being fastest, but lowest
10811093 compression ratio, 9 being slowest but best compression ratio). The
10821094 default value of <code>complevel</code> is 4. Setting <code>shuffle=False</code> will turn
10831095 off the HDF5 shuffle filter, which de-interlaces a block of data before
1084 compression by reordering the bytes. The shuffle filter can
1085 significantly improve compression ratios, and is on by default. Setting
1096 <code>zlib</code> compression by reordering the bytes. The shuffle filter can
1097 significantly improve compression ratios, and is on by default if <code>compression=zlib</code>. Setting
10861098 <code>fletcher32</code> keyword argument to
10871099 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> to <code>True</code> (it's <code>False</code> by
10881100 default) enables the Fletcher32 checksum algorithm for error detection.
10921104 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code>. These keyword arguments only
10931105 are relevant for <code>NETCDF4</code> and <code>NETCDF4_CLASSIC</code> files (where the
10941106 underlying file format is HDF5) and are silently ignored if the file
1095 format is <code>NETCDF3_CLASSIC</code>, <code>NETCDF3_64BIT_OFFSET</code> or <code>NETCDF3_64BIT_DATA</code>.</p>
1107 format is <code>NETCDF3_CLASSIC</code>, <code>NETCDF3_64BIT_OFFSET</code> or <code>NETCDF3_64BIT_DATA</code>.
1108 If the HDF5 library is built with szip support, compression=<code>szip</code> can also
1109 be used (in conjunction with the <code>szip_coding</code> and <code>szip_pixels_per_block</code> keyword
1110 arguments). </p>
10961111
10971112 <p>If your data only has a certain number of digits of precision (say for
10981113 example, it is temperature data that was measured with a precision of
1099 0.1 degrees), you can dramatically improve zlib compression by
1100 quantizing (or truncating) the data using the <code>least_significant_digit</code>
1101 keyword argument to <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code>. The least
1102 significant digit is the power of ten of the smallest decimal place in
1114 0.1 degrees), you can dramatically improve compression by
1115 quantizing (or truncating) the data. There are two methods supplied for
1116 doing this. You can use the <code>least_significant_digit</code>
1117 keyword argument to <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> to specify
1118 the power of ten of the smallest decimal place in
11031119 the data that is a reliable value. For example if the data has a
11041120 precision of 0.1, then setting <code>least_significant_digit=1</code> will cause
11051121 data the data to be quantized using <code>numpy.around(scale*data)/scale</code>, where
11061122 scale = 2**bits, and bits is determined so that a precision of 0.1 is
1107 retained (in this case bits=4). Effectively, this makes the compression
1123 retained (in this case bits=4). This is done at the python level and is
1124 not a part of the underlying C library. Starting with netcdf-c version 4.9.0,
1125 a quantization capability is provided in the library. This can be
1126 used via the <code>significant_digits</code> <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> kwarg (new in
1127 version 1.6.0).
1128 The interpretation of <code>significant_digits</code> is different than <code>least_signficant_digit</code>
1129 in that it specifies the absolute number of significant digits independent
1130 of the magnitude of the variable (the floating point exponent).
1131 Either of these approaches makes the compression
11081132 'lossy' instead of 'lossless', that is some precision in the data is
11091133 sacrificed for the sake of disk space.</p>
11101134
11111135 <p>In our example, try replacing the line</p>
11121136
1113 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">temp</span> <span class="o">=</span> <span class="n">rootgrp</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s2">&quot;temp&quot;</span><span class="p">,</span><span class="s2">&quot;f4&quot;</span><span class="p">,(</span><span class="s2">&quot;time&quot;</span><span class="p">,</span><span class="s2">&quot;level&quot;</span><span class="p">,</span><span class="s2">&quot;lat&quot;</span><span class="p">,</span><span class="s2">&quot;lon&quot;</span><span class="p">,))</span>
1137 <div class="pdoc-code 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>
11141138 </code></pre></div>
11151139
11161140 <p>with</p>
11171141
1118 <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><span class="n">zlib</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
1142 <div class="pdoc-code 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><span class="n">compression</span><span class="o">=</span><span class="s1">&#39;zlib&#39;</span><span class="p">)</span>
11191143 </code></pre></div>
11201144
11211145 <p>and then</p>
11221146
1123 <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><span class="n">zlib</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span><span class="n">least_significant_digit</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
1147 <div class="pdoc-code 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><span class="n">compression</span><span class="o">=</span><span class="s1">&#39;zlib&#39;</span><span class="p">,</span><span class="n">least_significant_digit</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
1148 </code></pre></div>
1149
1150 <p>or with netcdf-c &gt;= 4.9.0</p>
1151
1152 <div class="pdoc-code 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><span class="n">compression</span><span class="o">=</span><span class="s1">&#39;zlib&#39;</span><span class="p">,</span><span class="n">significant_digits</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
11241153 </code></pre></div>
11251154
11261155 <p>and see how much smaller the resulting files are.</p>
11411170 Since there is no native complex data type in netcdf, compound types are handy
11421171 for storing numpy complex arrays. Here's an example:</p>
11431172
1144 <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>
1173 <div class="pdoc-code 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>
11451174 <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>
11461175 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># create sample complex data.</span>
11471176 <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>
11771206 in a Python dictionary, just like variables and dimensions. As always, printing
11781207 objects gives useful summary information in an interactive session:</p>
11791208
1180 <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">f</span><span class="p">)</span>
1209 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="nb">print</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
11811210 <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>
11821211 <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>
11831212 <span class="n">dimensions</span><span class="p">(</span><span class="n">sizes</span><span class="p">):</span> <span class="n">x_dim</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
12021231 data type, use the <code><a href="#Dataset.createVLType">Dataset.createVLType</a></code> method
12031232 method of a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance.</p>
12041233
1205 <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>
1234 <div class="pdoc-code 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>
12061235 <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>
12071236 </code></pre></div>
12081237
12121241 but compound data types cannot.
12131242 A new variable can then be created using this datatype.</p>
12141243
1215 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">x</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="mi">3</span><span class="p">)</span>
1244 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">x</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="mi">3</span><span class="p">)</span>
12161245 <span class="o">&gt;&gt;&gt;</span> <span class="n">y</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;y&quot;</span><span class="p">,</span><span class="mi">4</span><span class="p">)</span>
12171246 <span class="o">&gt;&gt;&gt;</span> <span class="n">vlvar</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;phony_vlen_var&quot;</span><span class="p">,</span> <span class="n">vlen_t</span><span class="p">,</span> <span class="p">(</span><span class="s2">&quot;y&quot;</span><span class="p">,</span><span class="s2">&quot;x&quot;</span><span class="p">))</span>
12181247 </code></pre></div>
12251254 In this case, they contain 1-D numpy <code>int32</code> arrays of random length between
12261255 1 and 10.</p>
12271256
1228 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">random</span>
1257 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">random</span>
12291258 <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>
12301259 <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>
12311260 <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>
12651294 with fixed length greater than 1) when calling the
12661295 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method.</p>
12671296
1268 <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>
1297 <div class="pdoc-code 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>
12691298 <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>
12701299 </code></pre></div>
12711300
12731302 random lengths between 2 and 12 characters, and the data in the object
12741303 array is assigned to the vlen string variable.</p>
12751304
1276 <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>
1305 <div class="pdoc-code 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>
12771306 <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>
12781307 <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>
12791308 <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>
13121341 values and their names are used to define an Enum data type using
13131342 <code><a href="#Dataset.createEnumType">Dataset.createEnumType</a></code>.</p>
13141343
1315 <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>
1344 <div class="pdoc-code 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>
13161345 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># python dict with allowed values and their names.</span>
13171346 <span class="o">&gt;&gt;&gt;</span> <span class="n">enum_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;Altocumulus&#39;</span><span class="p">:</span> <span class="mi">7</span><span class="p">,</span> <span class="s1">&#39;Missing&#39;</span><span class="p">:</span> <span class="mi">255</span><span class="p">,</span>
13181347 <span class="o">...</span> <span class="s1">&#39;Stratus&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;Clear&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
13301359 is made to write an integer value not associated with one of the
13311360 specified names.</p>
13321361
1333 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">time</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;time&#39;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
1362 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">time</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;time&#39;</span><span class="p">,</span><span class="kc">None</span><span class="p">)</span>
13341363 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># create a 1d variable of type &#39;cloud_type&#39;.</span>
13351364 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># The fill_value is set to the &#39;Missing&#39; named value.</span>
13361365 <span class="o">&gt;&gt;&gt;</span> <span class="n">cloud_var</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;primary_cloud&#39;</span><span class="p">,</span><span class="n">cloud_type</span><span class="p">,</span><span class="s1">&#39;time&#39;</span><span class="p">,</span>
13671396 available. To use parallel IO, your program must be running in an MPI
13681397 environment using <a href="https://mpi4py.scipy.org">mpi4py</a>.</p>
13691398
1370 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">from</span> <span class="nn">mpi4py</span> <span class="kn">import</span> <span class="n">MPI</span>
1399 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">from</span> <span class="nn">mpi4py</span> <span class="kn">import</span> <span class="n">MPI</span>
13711400 <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>
13721401 <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">Dataset</span>
13731402 <span class="o">&gt;&gt;&gt;</span> <span class="n">rank</span> <span class="o">=</span> <span class="n">MPI</span><span class="o">.</span><span class="n">COMM_WORLD</span><span class="o">.</span><span class="n">rank</span> <span class="c1"># The process ID (integer 0-3 for 4-process run)</span>
13791408 when a new dataset is created or an existing dataset is opened,
13801409 use the <code>parallel</code> keyword to enable parallel access.</p>
13811410
1382 <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;parallel_test.nc&#39;</span><span class="p">,</span><span class="s1">&#39;w&#39;</span><span class="p">,</span><span class="n">parallel</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
1411 <div class="pdoc-code 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;parallel_test.nc&#39;</span><span class="p">,</span><span class="s1">&#39;w&#39;</span><span class="p">,</span><span class="n">parallel</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
13831412 </code></pre></div>
13841413
13851414 <p>The optional <code>comm</code> keyword may be used to specify a particular
13871416 can now write to the file indepedently. In this example the process rank is
13881417 written to a different variable index on each task</p>
13891418
1390 <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>
1419 <div class="pdoc-code 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>
13911420 <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>
13921421 <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>
13931422 <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>
14541483 <code><a href="#stringtochar">stringtochar</a></code> is used to convert the numpy string array to an array of
14551484 characters with one more dimension. For example,</p>
14561485
1457 <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>
1486 <div class="pdoc-code 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>
14581487 <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;stringtest.nc&#39;</span><span class="p">,</span><span class="s1">&#39;w&#39;</span><span class="p">,</span><span class="nb">format</span><span class="o">=</span><span class="s1">&#39;NETCDF4_CLASSIC&#39;</span><span class="p">)</span>
14591488 <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>
14601489 <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>
14871516 character array dtype under the hood when creating the netcdf compound type.
14881517 Here's an example:</p>
14891518
1490 <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>
1519 <div class="pdoc-code 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>
14911520 <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>
14921521 <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>
14931522 <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>
15321561 object representing the Dataset. Below are examples illustrating both
15331562 approaches.</p>
15341563
1535 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="c1"># create a diskless (in-memory) Dataset,</span>
1564 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="c1"># create a diskless (in-memory) Dataset,</span>
15361565 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># and persist the file to disk when it is closed.</span>
15371566 <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>
15381567 <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>
15941623 the parallel IO example, which is in <code>examples/mpi_example.py</code>.
15951624 Unit tests are in the <code>test</code> directory.</p>
15961625
1597 <p><strong>contact</strong>: Jeffrey Whitaker <a href="&#x6d;&#x61;&#105;&#x6c;&#116;&#111;&#58;&#106;&#101;&#x66;&#x66;&#114;&#x65;&#x79;&#x2e;&#115;&#46;&#x77;&#x68;&#x69;t&#x61;&#107;&#x65;&#x72;&#64;&#110;oa&#97;&#46;&#103;&#x6f;&#x76;">&#106;&#101;&#x66;&#x66;&#114;&#x65;&#x79;&#x2e;&#115;&#46;&#x77;&#x68;&#x69;t&#x61;&#107;&#x65;&#x72;&#64;&#110;oa&#97;&#46;&#103;&#x6f;&#x76;</a></p>
1626 <p><strong>contact</strong>: Jeffrey Whitaker <a href="&#x6d;&#x61;&#105;&#108;&#x74;&#x6f;&#x3a;&#x6a;&#x65;&#102;&#102;&#114;e&#x79;&#46;&#x73;&#46;&#119;&#x68;&#x69;&#116;&#x61;&#x6b;&#101;&#x72;&#64;&#x6e;&#x6f;&#x61;&#x61;&#46;&#x67;o&#x76;">&#x6a;&#x65;&#102;&#102;&#114;e&#x79;&#46;&#x73;&#46;&#119;&#x68;&#x69;&#116;&#x61;&#x6b;&#101;&#x72;&#64;&#x6e;&#x6f;&#x61;&#x61;&#46;&#x67;o&#x76;</a></p>
15981627
15991628 <p><strong>copyright</strong>: 2008 by Jeffrey Whitaker.</p>
16001629
16071636
16081637 <details>
16091638 <summary>View Source</summary>
1610 <div class="codehilite"><pre><span></span><span class="c1"># init for netCDF4. package</span>
1639 <div class="pdoc-code codehilite"><pre><span></span><span class="c1"># init for netCDF4. package</span>
16111640 <span class="c1"># Docstring comes from extension module _netCDF4.</span>
16121641 <span class="kn">from</span> <span class="nn">._netCDF4</span> <span class="kn">import</span> <span class="o">*</span>
16131642 <span class="c1"># Need explicit imports for names beginning with underscores</span>
16161645 <span class="n">__has_rename_grp__</span><span class="p">,</span> <span class="n">__has_nc_inq_path__</span><span class="p">,</span>
16171646 <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>
16181647 <span class="n">__has_nc_create_mem__</span><span class="p">,</span> <span class="n">__has_cdf5_format__</span><span class="p">,</span>
1619 <span class="n">__has_parallel4_support__</span><span class="p">,</span> <span class="n">__has_pnetcdf_support__</span><span class="p">)</span>
1648 <span class="n">__has_parallel4_support__</span><span class="p">,</span> <span class="n">__has_pnetcdf_support__</span><span class="p">,</span>
1649 <span class="n">__has_quantization_support__</span><span class="p">,</span> <span class="n">__has_zstandard_support__</span><span class="p">,</span>
1650 <span class="n">__has_bzip2_support__</span><span class="p">,</span> <span class="n">__has_blosc_support__</span><span class="p">,</span> <span class="n">__has_szip_support__</span><span class="p">)</span>
1651 <span class="kn">import</span> <span class="nn">os</span>
16201652 <span class="n">__all__</span> <span class="o">=</span>\
16211653 <span class="p">[</span><span class="s1">&#39;Dataset&#39;</span><span class="p">,</span><span class="s1">&#39;Variable&#39;</span><span class="p">,</span><span class="s1">&#39;Dimension&#39;</span><span class="p">,</span><span class="s1">&#39;Group&#39;</span><span class="p">,</span><span class="s1">&#39;MFDataset&#39;</span><span class="p">,</span><span class="s1">&#39;MFTime&#39;</span><span class="p">,</span><span class="s1">&#39;CompoundType&#39;</span><span class="p">,</span><span class="s1">&#39;VLType&#39;</span><span class="p">,</span><span class="s1">&#39;date2num&#39;</span><span class="p">,</span><span class="s1">&#39;num2date&#39;</span><span class="p">,</span><span class="s1">&#39;date2index&#39;</span><span class="p">,</span><span class="s1">&#39;stringtochar&#39;</span><span class="p">,</span><span class="s1">&#39;chartostring&#39;</span><span class="p">,</span><span class="s1">&#39;stringtoarr&#39;</span><span class="p">,</span><span class="s1">&#39;getlibversion&#39;</span><span class="p">,</span><span class="s1">&#39;EnumType&#39;</span><span class="p">,</span><span class="s1">&#39;get_chunk_cache&#39;</span><span class="p">,</span><span class="s1">&#39;set_chunk_cache&#39;</span><span class="p">]</span>
1654 <span class="c1"># if HDF5_PLUGIN_PATH not set, point to package path if libh5noop.so exists there</span>
1655 <span class="k">if</span> <span class="s1">&#39;HDF5_PLUGIN_PATH&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span> <span class="ow">and</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">__path__</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="s1">&#39;libh5noop.so&#39;</span><span class="p">)):</span>
1656 <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;HDF5_PLUGIN_PATH&#39;</span><span class="p">]</span><span class="o">=</span><span class="n">__path__</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
16221657 </pre></div>
16231658
16241659 </details>
16331668 <span class="name">Dataset</span>:
16341669 </div>
16351670
1636
1671
16371672 <div class="docstring"><p>A netCDF <code><a href="#Dataset">Dataset</a></code> is a collection of dimensions, groups, variables and
16381673 attributes. Together they describe the meaning of data and relations among
16391674 data fields stored in a netCDF file. See <code><a href="#Dataset.__init__">Dataset.__init__</a></code> for more
17111746 <span class="name">Dataset</span><span class="signature">()</span>
17121747 </div>
17131748
1714
1749
17151750 <div class="docstring"><p><strong><code>__init__(self, filename, mode="r", clobber=True, diskless=False,
17161751 persist=False, keepweakref=False, memory=None, encoding=None,
17171752 parallel=False, comm=None, info=None, format='NETCDF4')</code></strong></p>
17241759
17251760 <p><strong><code>mode</code></strong>: access mode. <code>r</code> means read-only; no data can be
17261761 modified. <code>w</code> means write; a new file is created, an existing file with
1727 the same name is deleted. <code>a</code> and <code>r+</code> mean append (in analogy with
1728 serial files); an existing file is opened for reading and writing.
1762 the same name is deleted. <code>x</code> means write, but fail if an existing
1763 file with the same name already exists. <code>a</code> and <code>r+</code> mean append;
1764 an existing file is opened for reading and writing, if
1765 file does not exist already, one is created.
17291766 Appending <code>s</code> to modes <code>r</code>, <code>w</code>, <code>r+</code> or <code>a</code> will enable unbuffered shared
17301767 access to <code>NETCDF3_CLASSIC</code>, <code>NETCDF3_64BIT_OFFSET</code> or
17311768 <code>NETCDF3_64BIT_DATA</code> formatted files.
17361773
17371774 <p><strong><code>clobber</code></strong>: if <code>True</code> (default), opening a file with <code>mode='w'</code>
17381775 will clobber an existing file with the same name. if <code>False</code>, an
1739 exception will be raised if a file with the same name already exists.</p>
1776 exception will be raised if a file with the same name already exists.
1777 mode=<code>x</code> is identical to mode=<code>w</code> with clobber=False.</p>
17401778
17411779 <p><strong><code>format</code></strong>: underlying file format (one of <code>'NETCDF4',
17421780 'NETCDF4_CLASSIC', 'NETCDF3_CLASSIC'</code>, <code>'NETCDF3_64BIT_OFFSET'</code> or
17791817 rendered unusable when the parent Dataset instance is garbage collected.</p>
17801818
17811819 <p><strong><code>memory</code></strong>: if not <code>None</code>, create or open an in-memory Dataset.
1782 If mode = 'r', the memory kwarg must contain a memory buffer object
1820 If mode = <code>r</code>, the memory kwarg must contain a memory buffer object
17831821 (an object that supports the python buffer interface).
17841822 The Dataset will then be created with contents taken from this block of memory.
1785 If mode = 'w', the memory kwarg should contain the anticipated size
1823 If mode = <code>w</code>, the memory kwarg should contain the anticipated size
17861824 of the Dataset in bytes (used only for NETCDF3 files). A memory
17871825 buffer containing a copy of the Dataset is returned by the
1788 <code><a href="#Dataset.close">Dataset.close</a></code> method. Requires netcdf-c version 4.4.1 for mode='r,
1789 netcdf-c 4.6.2 for mode='w'. To persist the file to disk, the raw
1826 <code><a href="#Dataset.close">Dataset.close</a></code> method. Requires netcdf-c version 4.4.1 for mode=<code>r</code>
1827 netcdf-c 4.6.2 for mode=<code>w</code>. To persist the file to disk, the raw
17901828 bytes from the returned buffer can be written into a binary file.
17911829 The Dataset can also be re-opened using this memory buffer.</p>
17921830
18141852 <span class="name">filepath</span><span class="signature">(unknown)</span>:
18151853 </div>
18161854
1817
1855
18181856 <div class="docstring"><p><strong><code>filepath(self,encoding=None)</code></strong></p>
18191857
18201858 <p>Get the file system path (or the opendap URL) which was used to
18331871 <span class="name">close</span><span class="signature">(unknown)</span>:
18341872 </div>
18351873
1836
1874
18371875 <div class="docstring"><p><strong><code>close(self)</code></strong></p>
18381876
18391877 <p>Close the Dataset.</p>
18491887 <span class="name">isopen</span><span class="signature">(unknown)</span>:
18501888 </div>
18511889
1852
1853 <div class="docstring"><p><strong><code>close(self)</code></strong></p>
1854
1855 <p>is the Dataset open or closed?</p>
1890
1891 <div class="docstring"><p><strong><code>isopen(self)</code></strong></p>
1892
1893 <p>Is the Dataset open or closed?</p>
18561894 </div>
18571895
18581896
18651903 <span class="name">sync</span><span class="signature">(unknown)</span>:
18661904 </div>
18671905
1868
1906
18691907 <div class="docstring"><p><strong><code>sync(self)</code></strong></p>
18701908
18711909 <p>Writes all buffered data in the <code><a href="#Dataset">Dataset</a></code> to the disk file.</p>
18811919 <span class="name">set_fill_on</span><span class="signature">(unknown)</span>:
18821920 </div>
18831921
1884
1922
18851923 <div class="docstring"><p><strong><code>set_fill_on(self)</code></strong></p>
18861924
18871925 <p>Sets the fill mode for a <code><a href="#Dataset">Dataset</a></code> open for writing to <code>on</code>.</p>
19051943 <span class="name">set_fill_off</span><span class="signature">(unknown)</span>:
19061944 </div>
19071945
1908
1946
19091947 <div class="docstring"><p><strong><code>set_fill_off(self)</code></strong></p>
19101948
19111949 <p>Sets the fill mode for a <code><a href="#Dataset">Dataset</a></code> open for writing to <code>off</code>.</p>
19251963 <span class="name">createDimension</span><span class="signature">(unknown)</span>:
19261964 </div>
19271965
1928
1966
19291967 <div class="docstring"><p><strong><code>createDimension(self, dimname, size=None)</code></strong></p>
19301968
19311969 <p>Creates a new dimension with the given <code>dimname</code> and <code>size</code>.</p>
19491987 <span class="name">renameDimension</span><span class="signature">(unknown)</span>:
19501988 </div>
19511989
1952
1990
19531991 <div class="docstring"><p><strong><code>renameDimension(self, oldname, newname)</code></strong></p>
19541992
19551993 <p>rename a <code><a href="#Dimension">Dimension</a></code> named <code>oldname</code> to <code>newname</code>.</p>
19652003 <span class="name">createCompoundType</span><span class="signature">(unknown)</span>:
19662004 </div>
19672005
1968
2006
19692007 <div class="docstring"><p><strong><code>createCompoundType(self, datatype, datatype_name)</code></strong></p>
19702008
19712009 <p>Creates a new compound data type named <code>datatype_name</code> from the numpy
19902028 <span class="name">createVLType</span><span class="signature">(unknown)</span>:
19912029 </div>
19922030
1993
2031
19942032 <div class="docstring"><p><strong><code>createVLType(self, datatype, datatype_name)</code></strong></p>
19952033
19962034 <p>Creates a new VLEN data type named <code>datatype_name</code> from a numpy
20102048 <span class="name">createEnumType</span><span class="signature">(unknown)</span>:
20112049 </div>
20122050
2013
2051
20142052 <div class="docstring"><p><strong><code>createEnumType(self, datatype, datatype_name, enum_dict)</code></strong></p>
20152053
20162054 <p>Creates a new Enum data type named <code>datatype_name</code> from a numpy
20312069 <span class="name">createVariable</span><span class="signature">(unknown)</span>:
20322070 </div>
20332071
2034
2035 <div class="docstring"><p><strong><code>createVariable(self, varname, datatype, dimensions=(), zlib=False,
2072
2073 <div class="docstring"><p><strong><code>createVariable(self, varname, datatype, dimensions=(), compression=None, zlib=False,
20362074 complevel=4, shuffle=True, fletcher32=False, contiguous=False, chunksizes=None,
2037 endian='native', least_significant_digit=None, fill_value=None, chunk_cache=None)</code></strong></p>
2075 szip_coding='nn', szip_pixels_per_block=8, blosc_shuffle=1,
2076 endian='native', least_significant_digit=None, significant_digits=None, quantize_mode='BitGroom',
2077 fill_value=None, chunk_cache=None)</code></strong></p>
20382078
20392079 <p>Creates a new variable with the given <code>varname</code>, <code>datatype</code>, and
20402080 <code><a href="#Dataset.dimensions">dimensions</a></code>. If dimensions are not given, the variable is assumed to be
20612101 <p>Data from netCDF variables is presented to python as numpy arrays with
20622102 the corresponding data type.</p>
20632103
2064 <p><code><a href="#Dataset.dimensions">dimensions</a></code> must be a tuple containing dimension names (strings) that
2065 have been defined previously using <code><a href="#Dataset.createDimension">Dataset.createDimension</a></code>. The default value
2104 <p><code><a href="#Dataset.dimensions">dimensions</a></code> must be a tuple containing <code><a href="#Dimension">Dimension</a></code> instances and/or
2105 dimension names (strings) that have been defined
2106 previously using <code><a href="#Dataset.createDimension">Dataset.createDimension</a></code>. The default value
20662107 is an empty tuple, which means the variable is a scalar.</p>
20672108
2109 <p>If the optional keyword argument <code>compression</code> is set, the data will be
2110 compressed in the netCDF file using the specified compression algorithm.
2111 Currently <code>zlib</code>,<code>szip</code>,<code>zstd</code>,<code>bzip2</code>,<code>blosc_lz</code>,<code>blosc_lz4</code>,<code>blosc_lz4hc</code>,
2112 <code>blosc_zlib</code> and <code>blosc_zstd</code> are supported.
2113 Default is <code>None</code> (no compression). All of the compressors except
2114 <code>zlib</code> and <code>szip</code> use the HDF5 plugin architecture.</p>
2115
20682116 <p>If the optional keyword <code>zlib</code> is <code>True</code>, the data will be compressed in
2069 the netCDF file using gzip compression (default <code>False</code>).</p>
2070
2071 <p>The optional keyword <code>complevel</code> is an integer between 1 and 9 describing
2072 the level of compression desired (default 4). Ignored if <code>zlib=False</code>.</p>
2117 the netCDF file using zlib compression (default <code>False</code>). The use of this option is
2118 deprecated in favor of <code>compression='zlib'</code>.</p>
2119
2120 <p>The optional keyword <code>complevel</code> is an integer between 0 and 9 describing
2121 the level of compression desired (default 4). Ignored if <code>compression=None</code>.
2122 A value of zero disables compression.</p>
20732123
20742124 <p>If the optional keyword <code>shuffle</code> is <code>True</code>, the HDF5 shuffle filter
2075 will be applied before compressing the data (default <code>True</code>). This
2125 will be applied before compressing the data with zlib (default <code>True</code>). This
20762126 significantly improves compression. Default is <code>True</code>. Ignored if
20772127 <code>zlib=False</code>.</p>
20782128
2129 <p>The optional kwarg <code>blosc_shuffle</code>is ignored
2130 unless the blosc compressor is used. <code>blosc_shuffle</code> can be 0 (no shuffle),
2131 1 (byte-wise shuffle) or 2 (bit-wise shuffle). Default is 1.</p>
2132
2133 <p>The optional kwargs <code>szip_coding</code> and <code>szip_pixels_per_block</code> are ignored
2134 unless the szip compressor is used. <code>szip_coding</code> can be <code>ec</code> (entropy coding)
2135 or <code>nn</code> (nearest neighbor coding). Default is <code>nn</code>. <code>szip_pixels_per_block</code>
2136 can be 4, 8, 16 or 32 (default 8).</p>
2137
20792138 <p>If the optional keyword <code>fletcher32</code> is <code>True</code>, the Fletcher32 HDF5
20802139 checksum algorithm is activated to detect errors. Default <code>False</code>.</p>
20812140
20822141 <p>If the optional keyword <code>contiguous</code> is <code>True</code>, the variable data is
20832142 stored contiguously on disk. Default <code>False</code>. Setting to <code>True</code> for
2084 a variable with an unlimited dimension will trigger an error.</p>
2143 a variable with an unlimited dimension will trigger an error.
2144 Fixed size variables (with no unlimited dimension) with no compression filters
2145 are contiguous by default.</p>
20852146
20862147 <p>The optional keyword <code>chunksizes</code> can be used to manually specify the
2087 HDF5 chunksizes for each dimension of the variable. A detailed
2088 discussion of HDF chunking and I/O performance is available
2089 <a href="http://www.hdfgroup.org/HDF5/doc/H5.user/Chunking.html">here</a>.
2148 HDF5 chunksizes for each dimension of the variable.
2149 A detailed discussion of HDF chunking and I/O performance is available
2150 <a href="https://support.hdfgroup.org/HDF5/doc/Advanced/Chunking">here</a>.
2151 The default chunking scheme in the netcdf-c library is discussed
2152 <a href="https://www.unidata.ucar.edu/software/netcdf/documentation/NUG/netcdf_perf_chunking.html">here</a>.
20902153 Basically, you want the chunk size for each dimension to match as
20912154 closely as possible the size of the data block that users will read
2092 from the file. <code>chunksizes</code> cannot be set if <code>contiguous=True</code>.</p>
2155 from the file. <code>chunksizes</code> cannot be set if <code>contiguous=True</code>.</p>
20932156
20942157 <p>The optional keyword <code>endian</code> can be used to control whether the
20952158 data is stored in little or big endian format on disk. Possible
20992162 opposite format as the one used to create the file, there may be
21002163 some performance advantage to be gained by setting the endian-ness.</p>
21012164
2102 <p>The <code>zlib, complevel, shuffle, fletcher32, contiguous, chunksizes</code> and <code>endian</code>
2103 keywords are silently ignored for netCDF 3 files that do not use HDF5.</p>
2104
21052165 <p>The optional keyword <code>fill_value</code> can be used to override the default
21062166 netCDF <code>_FillValue</code> (the value that the variable gets filled with before
2107 any data is written to it, defaults given in the dict <code><a href="#default_fillvals">netCDF4.default_fillvals</a></code>).
2167 any data is written to it, defaults given in the dict <code>netCDF4.default_fillvals</code>).
21082168 If fill_value is set to <code>False</code>, then the variable is not pre-filled.</p>
21092169
2110 <p>If the optional keyword parameter <code>least_significant_digit</code> is
2170 <p>If the optional keyword parameters <code>least_significant_digit</code> or <code>significant_digits</code> are
21112171 specified, variable data will be truncated (quantized). In conjunction
2112 with <code>zlib=True</code> this produces 'lossy', but significantly more
2172 with <code>compression='zlib'</code> this produces 'lossy', but significantly more
21132173 efficient compression. For example, if <code>least_significant_digit=1</code>,
21142174 data will be quantized using <code>numpy.around(scale*data)/scale</code>, where
21152175 scale = 2**bits, and bits is determined so that a precision of 0.1 is
21172177 <a href="http://www.esrl.noaa.gov/psl/data/gridded/conventions/cdc_netcdf_standard.shtml">PSL metadata conventions</a>:
21182178 "least_significant_digit -- power of ten of the smallest decimal place
21192179 in unpacked data that is a reliable value." Default is <code>None</code>, or no
2120 quantization, or 'lossless' compression.</p>
2180 quantization, or 'lossless' compression. If <code>significant_digits=3</code>
2181 then the data will be quantized so that three significant digits are retained, independent
2182 of the floating point exponent. The keyword argument <code>quantize_mode</code> controls
2183 the quantization algorithm (default 'BitGroom', 'BitRound' and
2184 'GranularBitRound' also available). The 'GranularBitRound'
2185 algorithm may result in better compression for typical geophysical datasets.
2186 This <code>significant_digits</code> kwarg is only available with netcdf-c &gt;= 4.9.0, and
2187 only works with <code>NETCDF4</code> or <code>NETCDF4_CLASSIC</code> formatted files.</p>
21212188
21222189 <p>When creating variables in a <code>NETCDF4</code> or <code>NETCDF4_CLASSIC</code> formatted file,
21232190 HDF5 creates something called a 'chunk cache' for each variable. The
21512218 The <code>least_significant_digit</code>
21522219 attributes describes the power of ten of the smallest decimal place in
21532220 the data the contains a reliable value. assigned to the <code><a href="#Variable">Variable</a></code>
2154 instance. If <code>None</code>, the data is not truncated. The <code>ndim</code> attribute
2221 instance. The <code>ndim</code> attribute
21552222 is the number of variable dimensions.</p>
21562223 </div>
21572224
21652232 <span class="name">renameVariable</span><span class="signature">(unknown)</span>:
21662233 </div>
21672234
2168
2235
21692236 <div class="docstring"><p><strong><code>renameVariable(self, oldname, newname)</code></strong></p>
21702237
21712238 <p>rename a <code><a href="#Variable">Variable</a></code> named <code>oldname</code> to <code>newname</code></p>
21812248 <span class="name">createGroup</span><span class="signature">(unknown)</span>:
21822249 </div>
21832250
2184
2251
21852252 <div class="docstring"><p><strong><code>createGroup(self, groupname)</code></strong></p>
21862253
21872254 <p>Creates a new <code><a href="#Group">Group</a></code> with the given <code>groupname</code>.</p>
22072274 <span class="name">ncattrs</span><span class="signature">(unknown)</span>:
22082275 </div>
22092276
2210
2277
22112278 <div class="docstring"><p><strong><code>ncattrs(self)</code></strong></p>
22122279
22132280 <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>
22232290 <span class="name">setncattr</span><span class="signature">(unknown)</span>:
22242291 </div>
22252292
2226
2293
22272294 <div class="docstring"><p><strong><code>setncattr(self,name,value)</code></strong></p>
22282295
22292296 <p>set a netCDF dataset or group attribute using name,value pair.
22412308 <span class="name">setncattr_string</span><span class="signature">(unknown)</span>:
22422309 </div>
22432310
2244
2311
22452312 <div class="docstring"><p><strong><code>setncattr_string(self,name,value)</code></strong></p>
22462313
22472314 <p>set a netCDF dataset or group string attribute using name,value pair.
22592326 <span class="name">setncatts</span><span class="signature">(unknown)</span>:
22602327 </div>
22612328
2262
2329
22632330 <div class="docstring"><p><strong><code>setncatts(self,attdict)</code></strong></p>
22642331
22652332 <p>set a bunch of netCDF dataset or group attributes at once using a python dictionary.
22782345 <span class="name">getncattr</span><span class="signature">(unknown)</span>:
22792346 </div>
22802347
2281
2348
22822349 <div class="docstring"><p><strong><code>getncattr(self,name)</code></strong></p>
22832350
22842351 <p>retrieve a netCDF dataset or group attribute.
22992366 <span class="name">delncattr</span><span class="signature">(unknown)</span>:
23002367 </div>
23012368
2302
2369
23032370 <div class="docstring"><p><strong><code>delncattr(self,name,value)</code></strong></p>
23042371
23052372 <p>delete a netCDF dataset or group attribute. Use if you need to delete a
23172384 <span class="name">renameAttribute</span><span class="signature">(unknown)</span>:
23182385 </div>
23192386
2320
2387
23212388 <div class="docstring"><p><strong><code>renameAttribute(self, oldname, newname)</code></strong></p>
23222389
23232390 <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>
23332400 <span class="name">renameGroup</span><span class="signature">(unknown)</span>:
23342401 </div>
23352402
2336
2403
23372404 <div class="docstring"><p><strong><code>renameGroup(self, oldname, newname)</code></strong></p>
23382405
23392406 <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>
23492416 <span class="name">set_auto_chartostring</span><span class="signature">(unknown)</span>:
23502417 </div>
23512418
2352
2419
23532420 <div class="docstring"><p><strong><code>set_auto_chartostring(self, True_or_False)</code></strong></p>
23542421
23552422 <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
23742441 <span class="name">set_auto_maskandscale</span><span class="signature">(unknown)</span>:
23752442 </div>
23762443
2377
2444
23782445 <div class="docstring"><p><strong><code>set_auto_maskandscale(self, True_or_False)</code></strong></p>
23792446
23802447 <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
23972464 <span class="name">set_auto_mask</span><span class="signature">(unknown)</span>:
23982465 </div>
23992466
2400
2467
24012468 <div class="docstring"><p><strong><code>set_auto_mask(self, True_or_False)</code></strong></p>
24022469
24032470 <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
24212488 <span class="name">set_auto_scale</span><span class="signature">(unknown)</span>:
24222489 </div>
24232490
2424
2491
24252492 <div class="docstring"><p><strong><code>set_auto_scale(self, True_or_False)</code></strong></p>
24262493
24272494 <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
24442511 <span class="name">set_always_mask</span><span class="signature">(unknown)</span>:
24452512 </div>
24462513
2447
2514
24482515 <div class="docstring"><p><strong><code>set_always_mask(self, True_or_False)</code></strong></p>
24492516
24502517 <p>Call <code><a href="#Variable.set_always_mask">Variable.set_always_mask</a></code> for all variables contained in
24722539 <span class="name">set_ncstring_attrs</span><span class="signature">(unknown)</span>:
24732540 </div>
24742541
2475
2542
24762543 <div class="docstring"><p><strong><code>set_ncstring_attrs(self, True_or_False)</code></strong></p>
24772544
24782545 <p>Call <code><a href="#Variable.set_ncstring_attrs">Variable.set_ncstring_attrs</a></code> for all variables contained in
24972564 <span class="name">get_variables_by_attributes</span><span class="signature">(unknown)</span>:
24982565 </div>
24992566
2500
2567
25012568 <div class="docstring"><p><strong><code>get_variables_by_attribute(self, **kwargs)</code></strong></p>
25022569
25032570 <p>Returns a list of variables that match specific conditions.</p>
25052572 <p>Can pass in key=value parameters and variables are returned that
25062573 contain all of the matches. For example,</p>
25072574
2508 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="c1"># Get variables with x-axis attribute.</span>
2575 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="c1"># Get variables with x-axis attribute.</span>
25092576 <span class="o">&gt;&gt;&gt;</span> <span class="n">vs</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">get_variables_by_attributes</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="s1">&#39;X&#39;</span><span class="p">)</span>
25102577 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># Get variables with matching &quot;standard_name&quot; attribute</span>
25112578 <span class="o">&gt;&gt;&gt;</span> <span class="n">vs</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">get_variables_by_attributes</span><span class="p">(</span><span class="n">standard_name</span><span class="o">=</span><span class="s1">&#39;northward_sea_water_velocity&#39;</span><span class="p">)</span>
25162583 the attribute value. None is given as the attribute value when the
25172584 attribute does not exist on the variable. For example,</p>
25182585
2519 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="c1"># Get Axis variables</span>
2586 <div class="pdoc-code codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="c1"># Get Axis variables</span>
25202587 <span class="o">&gt;&gt;&gt;</span> <span class="n">vs</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">get_variables_by_attributes</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="k">lambda</span> <span class="n">v</span><span class="p">:</span> <span class="n">v</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;X&#39;</span><span class="p">,</span> <span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="s1">&#39;Z&#39;</span><span class="p">,</span> <span class="s1">&#39;T&#39;</span><span class="p">])</span>
25212588 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># Get variables that don&#39;t have an &quot;axis&quot; attribute</span>
25222589 <span class="o">&gt;&gt;&gt;</span> <span class="n">vs</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">get_variables_by_attributes</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="k">lambda</span> <span class="n">v</span><span class="p">:</span> <span class="n">v</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">)</span>
25352602 <span class="name">fromcdl</span><span class="signature">(unknown)</span>:
25362603 </div>
25372604
2538
2605
25392606 <div class="docstring"><p><strong><code>fromcdl(cdlfilename, ncfilename=None, mode='a',format='NETCDF4')</code></strong></p>
25402607
25412608 <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>
25652632 <span class="name">tocdl</span><span class="signature">(unknown)</span>:
25662633 </div>
25672634
2568
2635
25692636 <div class="docstring"><p><strong><code>tocdl(self, coordvars=False, data=False, outfile=None)</code></strong></p>
25702637
25712638 <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>
25842651 <div id="Dataset.name" class="classattr">
25852652 <div class="attr variable"><a class="headerlink" href="#Dataset.name">#&nbsp;&nbsp</a>
25862653
2587 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2588 </div>
2589
2654 <span class="name">name</span>
2655 </div>
2656
2657
25902658 <div class="docstring"><p>string name of Group instance</p>
25912659 </div>
25922660
25952663 <div id="Dataset.groups" class="classattr">
25962664 <div class="attr variable"><a class="headerlink" href="#Dataset.groups">#&nbsp;&nbsp</a>
25972665
2598 <span class="name">groups</span><span class="default_value"> = &lt;attribute &#39;groups&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2599 </div>
2600
2666 <span class="name">groups</span>
2667 </div>
2668
2669
26012670
26022671
26032672 </div>
26042673 <div id="Dataset.dimensions" class="classattr">
26052674 <div class="attr variable"><a class="headerlink" href="#Dataset.dimensions">#&nbsp;&nbsp</a>
26062675
2607 <span class="name">dimensions</span><span class="default_value"> = &lt;attribute &#39;dimensions&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2608 </div>
2609
2676 <span class="name">dimensions</span>
2677 </div>
2678
2679
26102680
26112681
26122682 </div>
26132683 <div id="Dataset.variables" class="classattr">
26142684 <div class="attr variable"><a class="headerlink" href="#Dataset.variables">#&nbsp;&nbsp</a>
26152685
2616 <span class="name">variables</span><span class="default_value"> = &lt;attribute &#39;variables&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2617 </div>
2618
2686 <span class="name">variables</span>
2687 </div>
2688
2689
26192690
26202691
26212692 </div>
26222693 <div id="Dataset.disk_format" class="classattr">
26232694 <div class="attr variable"><a class="headerlink" href="#Dataset.disk_format">#&nbsp;&nbsp</a>
26242695
2625 <span class="name">disk_format</span><span class="default_value"> = &lt;attribute &#39;disk_format&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2626 </div>
2627
2696 <span class="name">disk_format</span>
2697 </div>
2698
2699
26282700
26292701
26302702 </div>
26312703 <div id="Dataset.path" class="classattr">
26322704 <div class="attr variable"><a class="headerlink" href="#Dataset.path">#&nbsp;&nbsp</a>
26332705
2634 <span class="name">path</span><span class="default_value"> = &lt;attribute &#39;path&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2635 </div>
2636
2706 <span class="name">path</span>
2707 </div>
2708
2709
26372710
26382711
26392712 </div>
26402713 <div id="Dataset.parent" class="classattr">
26412714 <div class="attr variable"><a class="headerlink" href="#Dataset.parent">#&nbsp;&nbsp</a>
26422715
2643 <span class="name">parent</span><span class="default_value"> = &lt;attribute &#39;parent&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2644 </div>
2645
2716 <span class="name">parent</span>
2717 </div>
2718
2719
26462720
26472721
26482722 </div>
26492723 <div id="Dataset.file_format" class="classattr">
26502724 <div class="attr variable"><a class="headerlink" href="#Dataset.file_format">#&nbsp;&nbsp</a>
26512725
2652 <span class="name">file_format</span><span class="default_value"> = &lt;attribute &#39;file_format&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2653 </div>
2654
2726 <span class="name">file_format</span>
2727 </div>
2728
2729
26552730
26562731
26572732 </div>
26582733 <div id="Dataset.data_model" class="classattr">
26592734 <div class="attr variable"><a class="headerlink" href="#Dataset.data_model">#&nbsp;&nbsp</a>
26602735
2661 <span class="name">data_model</span><span class="default_value"> = &lt;attribute &#39;data_model&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2662 </div>
2663
2736 <span class="name">data_model</span>
2737 </div>
2738
2739
26642740
26652741
26662742 </div>
26672743 <div id="Dataset.cmptypes" class="classattr">
26682744 <div class="attr variable"><a class="headerlink" href="#Dataset.cmptypes">#&nbsp;&nbsp</a>
26692745
2670 <span class="name">cmptypes</span><span class="default_value"> = &lt;attribute &#39;cmptypes&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2671 </div>
2672
2746 <span class="name">cmptypes</span>
2747 </div>
2748
2749
26732750
26742751
26752752 </div>
26762753 <div id="Dataset.vltypes" class="classattr">
26772754 <div class="attr variable"><a class="headerlink" href="#Dataset.vltypes">#&nbsp;&nbsp</a>
26782755
2679 <span class="name">vltypes</span><span class="default_value"> = &lt;attribute &#39;vltypes&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2680 </div>
2681
2756 <span class="name">vltypes</span>
2757 </div>
2758
2759
26822760
26832761
26842762 </div>
26852763 <div id="Dataset.enumtypes" class="classattr">
26862764 <div class="attr variable"><a class="headerlink" href="#Dataset.enumtypes">#&nbsp;&nbsp</a>
26872765
2688 <span class="name">enumtypes</span><span class="default_value"> = &lt;attribute &#39;enumtypes&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2689 </div>
2690
2766 <span class="name">enumtypes</span>
2767 </div>
2768
2769
26912770
26922771
26932772 </div>
26942773 <div id="Dataset.keepweakref" class="classattr">
26952774 <div class="attr variable"><a class="headerlink" href="#Dataset.keepweakref">#&nbsp;&nbsp</a>
26962775
2697 <span class="name">keepweakref</span><span class="default_value"> = &lt;attribute &#39;keepweakref&#39; of &#39;<a href="#_netCDF4.Dataset">netCDF4._netCDF4.Dataset</a>&#39; objects&gt;</span>
2698 </div>
2699
2776 <span class="name">keepweakref</span>
2777 </div>
2778
2779
27002780
27012781
27022782 </div>
27102790 <span class="name">Variable</span>:
27112791 </div>
27122792
2713
2793
27142794 <div class="docstring"><p>A netCDF <code><a href="#Variable">Variable</a></code> is used to read and write netCDF data. They are
27152795 analogous to numpy array objects. See <code><a href="#Variable.__init__">Variable.__init__</a></code> for more
27162796 details.</p>
27562836 truncated to this decimal place when it is assigned to the <code><a href="#Variable">Variable</a></code>
27572837 instance. If <code>None</code>, the data is not truncated.</p>
27582838
2839 <p><strong><code>significant_digits</code></strong>: New in version 1.6.0. Describes the number of significant
2840 digits in the data the contains a reliable value. Data is
2841 truncated to retain this number of significant digits when it is assigned to the
2842 <code><a href="#Variable">Variable</a></code> instance. If <code>None</code>, the data is not truncated.
2843 Only available with netcdf-c &gt;= 4.9.0,
2844 and only works with <code>NETCDF4</code> or <code>NETCDF4_CLASSIC</code> formatted files.
2845 The number of significant digits used in the quantization of variable data can be
2846 obtained using the <code>Variable.significant_digits</code> method. Default <code>None</code> -
2847 no quantization done.</p>
2848
2849 <p><strong><code>quantize_mode</code></strong>: New in version 1.6.0. Controls
2850 the quantization algorithm (default 'BitGroom', 'BitRound' and
2851 'GranularBitRound' also available). The 'GranularBitRound'
2852 algorithm may result in better compression for typical geophysical datasets.
2853 Ignored if <code>significant_digits</code> not specified. If 'BitRound' is used, then
2854 <code>significant_digits</code> is interpreted as binary (not decimal) digits.</p>
2855
27592856 <p><strong><code>__orthogonal_indexing__</code></strong>: Always <code>True</code>. Indicates to client code
27602857 that the object supports 'orthogonal indexing', which means that slices
27612858 that are 1d arrays or lists slice along each dimension independently. This
27772874 <span class="name">Variable</span><span class="signature">()</span>
27782875 </div>
27792876
2780
2781 <div class="docstring"><p><strong><code>__init__(self, group, name, datatype, dimensions=(), zlib=False,
2782 complevel=4, shuffle=True, fletcher32=False, contiguous=False,
2877
2878 <div class="docstring"><p><strong><code>__init__(self, group, name, datatype, dimensions=(), compression=None, zlib=False,
2879 complevel=4, shuffle=True, szip_coding='nn', szip_pixels_per_block=8,
2880 blosc_shuffle=1, fletcher32=False, contiguous=False,
27832881 chunksizes=None, endian='native',
27842882 least_significant_digit=None,fill_value=None,chunk_cache=None)</code></strong></p>
27852883
28082906 (for a variable-length string array). Numpy string and unicode datatypes with
28092907 length greater than one are aliases for <code>str</code>.</p>
28102908
2811 <p><strong><code><a href="#Variable.dimensions">dimensions</a></code></strong>: a tuple containing the variable's dimension names
2909 <p><strong><code><a href="#Variable.dimensions">dimensions</a></code></strong>: a tuple containing the variable's Dimension instances
28122910 (defined previously with <code>createDimension</code>). Default is an empty tuple
28132911 which means the variable is a scalar (and therefore has no dimensions).</p>
28142912
2913 <p><strong><code>compression</code></strong>: compression algorithm to use.
2914 Currently <code>zlib</code>,<code>szip</code>,<code>zstd</code>,<code>bzip2</code>,<code>blosc_lz</code>,<code>blosc_lz4</code>,<code>blosc_lz4hc</code>,
2915 <code>blosc_zlib</code> and <code>blosc_zstd</code> are supported.
2916 Default is <code>None</code> (no compression). All of the compressors except
2917 <code>zlib</code> and <code>szip</code> use the HDF5 plugin architecture.</p>
2918
28152919 <p><strong><code>zlib</code></strong>: if <code>True</code>, data assigned to the <code><a href="#Variable">Variable</a></code>
2816 instance is compressed on disk. Default <code>False</code>.</p>
2817
2818 <p><strong><code>complevel</code></strong>: the level of zlib compression to use (1 is the fastest,
2920 instance is compressed on disk. Default <code>False</code>. Deprecated - use
2921 <code>compression='zlib'</code> instead.</p>
2922
2923 <p><strong><code>complevel</code></strong>: the level of compression to use (1 is the fastest,
28192924 but poorest compression, 9 is the slowest but best compression). Default 4.
2820 Ignored if <code>zlib=False</code>.</p>
2925 Ignored if <code>compression=None</code> or <code>szip</code>. A value of 0 disables compression.</p>
28212926
28222927 <p><strong><code>shuffle</code></strong>: if <code>True</code>, the HDF5 shuffle filter is applied
2823 to improve compression. Default <code>True</code>. Ignored if <code>zlib=False</code>.</p>
2928 to improve zlib compression. Default <code>True</code>. Ignored unless <code>compression = 'zlib'</code>.</p>
2929
2930 <p><strong><code>blosc_shuffle</code></strong>: shuffle filter inside blosc compressor (only
2931 relevant if compression kwarg set to one of the blosc compressors).
2932 Can be 0 (no blosc shuffle), 1 (bytewise shuffle) or 2 (bitwise
2933 shuffle)). Default is 1. Ignored if blosc compressor not used.</p>
2934
2935 <p><strong><code>szip_coding</code></strong>: szip coding method. Can be <code>ec</code> (entropy coding)
2936 or <code>nn</code> (nearest neighbor coding). Default is <code>nn</code>.
2937 Ignored if szip compressor not used.</p>
2938
2939 <p><strong><code>szip_pixels_per_block</code></strong>: Can be 4,8,16 or 32 (Default 8).
2940 Ignored if szip compressor not used.</p>
28242941
28252942 <p><strong><code>fletcher32</code></strong>: if <code>True</code> (default <code>False</code>), the Fletcher32 checksum
28262943 algorithm is used for error detection.</p>
28272944
28282945 <p><strong><code>contiguous</code></strong>: if <code>True</code> (default <code>False</code>), the variable data is
28292946 stored contiguously on disk. Default <code>False</code>. Setting to <code>True</code> for
2830 a variable with an unlimited dimension will trigger an error.</p>
2947 a variable with an unlimited dimension will trigger an error. Fixed
2948 size variables (with no unlimited dimension) with no compression
2949 filters are contiguous by default.</p>
28312950
28322951 <p><strong><code>chunksizes</code></strong>: Can be used to specify the HDF5 chunksizes for each
28332952 dimension of the variable. A detailed discussion of HDF chunking and I/O
28342953 performance is available
2835 <a href="http://www.hdfgroup.org/HDF5/doc/H5.user/Chunking.html">here</a>.
2954 <a href="https://support.hdfgroup.org/HDF5/doc/Advanced/Chunking">here</a>.
2955 The default chunking scheme in the netcdf-c library is discussed
2956 <a href="https://www.unidata.ucar.edu/software/netcdf/documentation/NUG/netcdf_perf_chunking.html">here</a>.
28362957 Basically, you want the chunk size for each dimension to match as
28372958 closely as possible the size of the data block that users will read
28382959 from the file. <code>chunksizes</code> cannot be set if <code>contiguous=True</code>.</p>
28462967 some performance advantage to be gained by setting the endian-ness.
28472968 For netCDF 3 files (that don't use HDF5), only <code>endian='native'</code> is allowed.</p>
28482969
2849 <p>The <code>zlib, complevel, shuffle, fletcher32, contiguous</code> and <code>chunksizes</code>
2970 <p>The <code>compression, zlib, complevel, shuffle, fletcher32, contiguous</code> and <code>chunksizes</code>
28502971 keywords are silently ignored for netCDF 3 files that do not use HDF5.</p>
28512972
2852 <p><strong><code>least_significant_digit</code></strong>: If specified, variable data will be
2853 truncated (quantized). In conjunction with <code>zlib=True</code> this produces
2973 <p><strong><code>least_significant_digit</code></strong>: If this or <code>significant_digits</code> are specified,
2974 variable data will be truncated (quantized).
2975 In conjunction with <code>compression='zlib'</code> this produces
28542976 'lossy', but significantly more efficient compression. For example, if
28552977 <code>least_significant_digit=1</code>, data will be quantized using
28562978 around(scale<em>data)/scale, where scale = 2</em>*bits, and bits is determined
28572979 so that a precision of 0.1 is retained (in this case bits=4). Default is
28582980 <code>None</code>, or no quantization.</p>
28592981
2982 <p><strong><code>significant_digits</code></strong>: New in version 1.6.0.
2983 As described for <code>least_significant_digit</code>
2984 except the number of significant digits retained is prescribed independent
2985 of the floating point exponent. Default <code>None</code> - no quantization done.</p>
2986
2987 <p><strong><code>quantize_mode</code></strong>: New in version 1.6.0. Controls
2988 the quantization algorithm (default 'BitGroom', 'BitRound' and
2989 'GranularBitRound' also available). The 'GranularBitRound'
2990 algorithm may result in better compression for typical geophysical datasets.
2991 Ignored if <code>significant_digts</code> not specified. If 'BitRound' is used, then
2992 <code>significant_digits</code> is interpreted as binary (not decimal) digits.</p>
2993
28602994 <p><strong><code>fill_value</code></strong>: If specified, the default netCDF <code>_FillValue</code> (the
28612995 value that the variable gets filled with before any data is written to it)
28622996 is replaced with this value. If fill_value is set to <code>False</code>, then
28632997 the variable is not pre-filled. The default netCDF fill values can be found
2864 in the dictionary <code><a href="#default_fillvals">netCDF4.default_fillvals</a></code>.</p>
2998 in the dictionary <code>netCDF4.default_fillvals</code>.</p>
28652999
28663000 <p><strong><code>chunk_cache</code></strong>: If specified, sets the chunk cache size for this variable.
2867 Persists as long as Dataset is open. Use <code><a href="#Variable.set_var_chunk_cache">set_var_chunk_cache</a></code> to
2868 change it when Dataset is re-opened. </p>
3001 Persists as long as Dataset is open. Use <code><a href="#Variable.set_var_chunk_cache">set_var_chunk_cache</a></code> to
3002 change it when Dataset is re-opened.</p>
28693003
28703004 <p><strong><em>Note</em></strong>: <code><a href="#Variable">Variable</a></code> instances should be created using the
28713005 <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of a <code><a href="#Dataset">Dataset</a></code> or
28823016 <span class="name">group</span><span class="signature">(unknown)</span>:
28833017 </div>
28843018
2885
3019
28863020 <div class="docstring"><p><strong><code>group(self)</code></strong></p>
28873021
28883022 <p>return the group that this <code><a href="#Variable">Variable</a></code> is a member of.</p>
28983032 <span class="name">ncattrs</span><span class="signature">(unknown)</span>:
28993033 </div>
29003034
2901
3035
29023036 <div class="docstring"><p><strong><code>ncattrs(self)</code></strong></p>
29033037
29043038 <p>return netCDF attribute names for this <code><a href="#Variable">Variable</a></code> in a list.</p>
29143048 <span class="name">setncattr</span><span class="signature">(unknown)</span>:
29153049 </div>
29163050
2917
3051
29183052 <div class="docstring"><p><strong><code>setncattr(self,name,value)</code></strong></p>
29193053
29203054 <p>set a netCDF variable attribute using name,value pair. Use if you need to set a
29323066 <span class="name">setncattr_string</span><span class="signature">(unknown)</span>:
29333067 </div>
29343068
2935
3069
29363070 <div class="docstring"><p><strong><code>setncattr_string(self,name,value)</code></strong></p>
29373071
29383072 <p>set a netCDF variable string attribute using name,value pair.
29513085 <span class="name">setncatts</span><span class="signature">(unknown)</span>:
29523086 </div>
29533087
2954
3088
29553089 <div class="docstring"><p><strong><code>setncatts(self,attdict)</code></strong></p>
29563090
29573091 <p>set a bunch of netCDF variable attributes at once using a python dictionary.
29703104 <span class="name">getncattr</span><span class="signature">(unknown)</span>:
29713105 </div>
29723106
2973
3107
29743108 <div class="docstring"><p><strong><code>getncattr(self,name)</code></strong></p>
29753109
29763110 <p>retrieve a netCDF variable attribute. Use if you need to set a
29913125 <span class="name">delncattr</span><span class="signature">(unknown)</span>:
29923126 </div>
29933127
2994
3128
29953129 <div class="docstring"><p><strong><code>delncattr(self,name,value)</code></strong></p>
29963130
29973131 <p>delete a netCDF variable attribute. Use if you need to delete a
30093143 <span class="name">filters</span><span class="signature">(unknown)</span>:
30103144 </div>
30113145
3012
3146
30133147 <div class="docstring"><p><strong><code>filters(self)</code></strong></p>
30143148
30153149 <p>return dictionary containing HDF5 filter parameters.</p>
3150 </div>
3151
3152
3153 </div>
3154 <div id="Variable.quantization" class="classattr">
3155 <div class="attr function"><a class="headerlink" href="#Variable.quantization">#&nbsp;&nbsp</a>
3156
3157
3158 <span class="def">def</span>
3159 <span class="name">quantization</span><span class="signature">(unknown)</span>:
3160 </div>
3161
3162
3163 <div class="docstring"><p><strong><code>quantization(self)</code></strong></p>
3164
3165 <p>return number of significant digits and the algorithm used in quantization.
3166 Returns None if quantization not active.</p>
30163167 </div>
30173168
30183169
30253176 <span class="name">endian</span><span class="signature">(unknown)</span>:
30263177 </div>
30273178
3028
3179
30293180 <div class="docstring"><p><strong><code>endian(self)</code></strong></p>
30303181
30313182 <p>return endian-ness (<code>little,big,native</code>) of variable (as stored in HDF5 file).</p>
30413192 <span class="name">chunking</span><span class="signature">(unknown)</span>:
30423193 </div>
30433194
3044
3195
30453196 <div class="docstring"><p><strong><code>chunking(self)</code></strong></p>
30463197
30473198 <p>return variable chunking information. If the dataset is
30603211 <span class="name">get_var_chunk_cache</span><span class="signature">(unknown)</span>:
30613212 </div>
30623213
3063
3214
30643215 <div class="docstring"><p><strong><code>get_var_chunk_cache(self)</code></strong></p>
30653216
30663217 <p>return variable chunk cache information in a tuple (size,nelems,preemption).
30783229 <span class="name">set_var_chunk_cache</span><span class="signature">(unknown)</span>:
30793230 </div>
30803231
3081
3232
30823233 <div class="docstring"><p><strong><code>set_var_chunk_cache(self,size=None,nelems=None,preemption=None)</code></strong></p>
30833234
30843235 <p>change variable chunk cache settings.
30963247 <span class="name">renameAttribute</span><span class="signature">(unknown)</span>:
30973248 </div>
30983249
3099
3250
31003251 <div class="docstring"><p><strong><code>renameAttribute(self, oldname, newname)</code></strong></p>
31013252
31023253 <p>rename a <code><a href="#Variable">Variable</a></code> attribute named <code>oldname</code> to <code>newname</code>.</p>
31123263 <span class="name">assignValue</span><span class="signature">(unknown)</span>:
31133264 </div>
31143265
3115
3266
31163267 <div class="docstring"><p><strong><code>assignValue(self, val)</code></strong></p>
31173268
31183269 <p>assign a value to a scalar variable. Provided for compatibility with
31293280 <span class="name">getValue</span><span class="signature">(unknown)</span>:
31303281 </div>
31313282
3132
3283
31333284 <div class="docstring"><p><strong><code>getValue(self)</code></strong></p>
31343285
31353286 <p>get the value of a scalar variable. Provided for compatibility with
31463297 <span class="name">set_auto_chartostring</span><span class="signature">(unknown)</span>:
31473298 </div>
31483299
3149
3300
31503301 <div class="docstring"><p><strong><code>set_auto_chartostring(self,chartostring)</code></strong></p>
31513302
31523303 <p>turn on or off automatic conversion of character variable data to and
31773328 <span class="name">use_nc_get_vars</span><span class="signature">(unknown)</span>:
31783329 </div>
31793330
3180
3331
31813332 <div class="docstring"><p><strong><code>use_nc_get_vars(self,_use_get_vars)</code></strong></p>
31823333
31833334 <p>enable the use of netcdf library routine <code>nc_get_vars</code>
31973348 <span class="name">set_auto_maskandscale</span><span class="signature">(unknown)</span>:
31983349 </div>
31993350
3200
3351
32013352 <div class="docstring"><p><strong><code>set_auto_maskandscale(self,maskandscale)</code></strong></p>
32023353
32033354 <p>turn on or off automatic conversion of variable data to and
32613412 <span class="name">set_auto_scale</span><span class="signature">(unknown)</span>:
32623413 </div>
32633414
3264
3415
32653416 <div class="docstring"><p><strong><code>set_auto_scale(self,scale)</code></strong></p>
32663417
32673418 <p>turn on or off automatic packing/unpacking of variable
33103461 <span class="name">set_auto_mask</span><span class="signature">(unknown)</span>:
33113462 </div>
33123463
3313
3464
33143465 <div class="docstring"><p><strong><code>set_auto_mask(self,mask)</code></strong></p>
33153466
33163467 <p>turn on or off automatic conversion of variable data to and
33453496 <span class="name">set_always_mask</span><span class="signature">(unknown)</span>:
33463497 </div>
33473498
3348
3499
33493500 <div class="docstring"><p><strong><code>set_always_mask(self,always_mask)</code></strong></p>
33503501
33513502 <p>turn on or off conversion of data without missing values to regular
33683519 <span class="name">set_ncstring_attrs</span><span class="signature">(unknown)</span>:
33693520 </div>
33703521
3371
3522
33723523 <div class="docstring"><p><strong><code>set_always_mask(self,ncstring_attrs)</code></strong></p>
33733524
33743525 <p>turn on or off creating NC_STRING string attributes.</p>
33903541 <span class="name">set_collective</span><span class="signature">(unknown)</span>:
33913542 </div>
33923543
3393
3544
33943545 <div class="docstring"><p><strong><code>set_collective(self,True_or_False)</code></strong></p>
33953546
33963547 <p>turn on or off collective parallel IO access. Ignored if file is not
34073558 <span class="name">get_dims</span><span class="signature">(unknown)</span>:
34083559 </div>
34093560
3410
3561
34113562 <div class="docstring"><p><strong><code>get_dims(self)</code></strong></p>
34123563
34133564 <p>return a tuple of <code><a href="#Dimension">Dimension</a></code> instances associated with this
34193570 <div id="Variable.name" class="classattr">
34203571 <div class="attr variable"><a class="headerlink" href="#Variable.name">#&nbsp;&nbsp</a>
34213572
3422 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3423 </div>
3424
3573 <span class="name">name</span>
3574 </div>
3575
3576
34253577 <div class="docstring"><p>string name of Variable instance</p>
34263578 </div>
34273579
34303582 <div id="Variable.datatype" class="classattr">
34313583 <div class="attr variable"><a class="headerlink" href="#Variable.datatype">#&nbsp;&nbsp</a>
34323584
3433 <span class="name">datatype</span><span class="default_value"> = &lt;attribute &#39;datatype&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3434 </div>
3435
3585 <span class="name">datatype</span>
3586 </div>
3587
3588
34363589 <div class="docstring"><p>numpy data type (for primitive data types) or
34373590 VLType/CompoundType/EnumType instance
34383591 (for compound, vlen or enum data types)</p>
34433596 <div id="Variable.shape" class="classattr">
34443597 <div class="attr variable"><a class="headerlink" href="#Variable.shape">#&nbsp;&nbsp</a>
34453598
3446 <span class="name">shape</span><span class="default_value"> = &lt;attribute &#39;shape&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3447 </div>
3448
3599 <span class="name">shape</span>
3600 </div>
3601
3602
34493603 <div class="docstring"><p>find current sizes of all variable dimensions</p>
34503604 </div>
34513605
34543608 <div id="Variable.size" class="classattr">
34553609 <div class="attr variable"><a class="headerlink" href="#Variable.size">#&nbsp;&nbsp</a>
34563610
3457 <span class="name">size</span><span class="default_value"> = &lt;attribute &#39;size&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3458 </div>
3459
3611 <span class="name">size</span>
3612 </div>
3613
3614
34603615 <div class="docstring"><p>Return the number of stored elements.</p>
34613616 </div>
34623617
34653620 <div id="Variable.dimensions" class="classattr">
34663621 <div class="attr variable"><a class="headerlink" href="#Variable.dimensions">#&nbsp;&nbsp</a>
34673622
3468 <span class="name">dimensions</span><span class="default_value"> = &lt;attribute &#39;dimensions&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3469 </div>
3470
3623 <span class="name">dimensions</span>
3624 </div>
3625
3626
34713627 <div class="docstring"><p>get variables's dimension names</p>
34723628 </div>
34733629
34763632 <div id="Variable.ndim" class="classattr">
34773633 <div class="attr variable"><a class="headerlink" href="#Variable.ndim">#&nbsp;&nbsp</a>
34783634
3479 <span class="name">ndim</span><span class="default_value"> = &lt;attribute &#39;ndim&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3480 </div>
3481
3635 <span class="name">ndim</span>
3636 </div>
3637
3638
34823639
34833640
34843641 </div>
34853642 <div id="Variable.dtype" class="classattr">
34863643 <div class="attr variable"><a class="headerlink" href="#Variable.dtype">#&nbsp;&nbsp</a>
34873644
3488 <span class="name">dtype</span><span class="default_value"> = &lt;attribute &#39;dtype&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3489 </div>
3490
3645 <span class="name">dtype</span>
3646 </div>
3647
3648
34913649
34923650
34933651 </div>
34943652 <div id="Variable.mask" class="classattr">
34953653 <div class="attr variable"><a class="headerlink" href="#Variable.mask">#&nbsp;&nbsp</a>
34963654
3497 <span class="name">mask</span><span class="default_value"> = &lt;attribute &#39;mask&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3498 </div>
3499
3655 <span class="name">mask</span>
3656 </div>
3657
3658
35003659
35013660
35023661 </div>
35033662 <div id="Variable.scale" class="classattr">
35043663 <div class="attr variable"><a class="headerlink" href="#Variable.scale">#&nbsp;&nbsp</a>
35053664
3506 <span class="name">scale</span><span class="default_value"> = &lt;attribute &#39;scale&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3507 </div>
3508
3665 <span class="name">scale</span>
3666 </div>
3667
3668
35093669
35103670
35113671 </div>
35123672 <div id="Variable.always_mask" class="classattr">
35133673 <div class="attr variable"><a class="headerlink" href="#Variable.always_mask">#&nbsp;&nbsp</a>
35143674
3515 <span class="name">always_mask</span><span class="default_value"> = &lt;attribute &#39;always_mask&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3516 </div>
3517
3675 <span class="name">always_mask</span>
3676 </div>
3677
3678
35183679
35193680
35203681 </div>
35213682 <div id="Variable.chartostring" class="classattr">
35223683 <div class="attr variable"><a class="headerlink" href="#Variable.chartostring">#&nbsp;&nbsp</a>
35233684
3524 <span class="name">chartostring</span><span class="default_value"> = &lt;attribute &#39;chartostring&#39; of &#39;<a href="#_netCDF4.Variable">netCDF4._netCDF4.Variable</a>&#39; objects&gt;</span>
3525 </div>
3526
3685 <span class="name">chartostring</span>
3686 </div>
3687
3688
35273689
35283690
35293691 </div>
35373699 <span class="name">Dimension</span>:
35383700 </div>
35393701
3540
3702
35413703 <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>.
35423704 See <code><a href="#Dimension.__init__">Dimension.__init__</a></code> for more details.</p>
35433705
35633725 <span class="name">Dimension</span><span class="signature">()</span>
35643726 </div>
35653727
3566
3728
35673729 <div class="docstring"><p><strong><code>__init__(self, group, name, size=None)</code></strong></p>
35683730
35693731 <p><code><a href="#Dimension">Dimension</a></code> constructor.</p>
35893751 <span class="name">group</span><span class="signature">(unknown)</span>:
35903752 </div>
35913753
3592
3754
35933755 <div class="docstring"><p><strong><code>group(self)</code></strong></p>
35943756
35953757 <p>return the group that this <code><a href="#Dimension">Dimension</a></code> is a member of.</p>
36053767 <span class="name">isunlimited</span><span class="signature">(unknown)</span>:
36063768 </div>
36073769
3608
3770
36093771 <div class="docstring"><p><strong><code>isunlimited(self)</code></strong></p>
36103772
36113773 <p>returns <code>True</code> if the <code><a href="#Dimension">Dimension</a></code> instance is unlimited, <code>False</code> otherwise.</p>
36163778 <div id="Dimension.name" class="classattr">
36173779 <div class="attr variable"><a class="headerlink" href="#Dimension.name">#&nbsp;&nbsp</a>
36183780
3619 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#_netCDF4.Dimension">netCDF4._netCDF4.Dimension</a>&#39; objects&gt;</span>
3620 </div>
3621
3781 <span class="name">name</span>
3782 </div>
3783
3784
36223785 <div class="docstring"><p>string name of Dimension instance</p>
36233786 </div>
36243787
36273790 <div id="Dimension.size" class="classattr">
36283791 <div class="attr variable"><a class="headerlink" href="#Dimension.size">#&nbsp;&nbsp</a>
36293792
3630 <span class="name">size</span><span class="default_value"> = &lt;attribute &#39;size&#39; of &#39;<a href="#_netCDF4.Dimension">netCDF4._netCDF4.Dimension</a>&#39; objects&gt;</span>
3631 </div>
3632
3793 <span class="name">size</span>
3794 </div>
3795
3796
36333797 <div class="docstring"><p>current size of Dimension (calls <code>len</code> on Dimension instance)</p>
36343798 </div>
36353799
36453809 <span class="name">Group</span><wbr>(<span class="base"><a href="#Dataset">netCDF4.Dataset</a></span>):
36463810 </div>
36473811
3648
3812
36493813 <div class="docstring"><p>Groups define a hierarchical namespace within a netCDF file. They are
36503814 analogous to directories in a unix filesystem. Each <code><a href="#Group">Group</a></code> behaves like
36513815 a <code><a href="#Dataset">Dataset</a></code> within a Dataset, and can contain it's own variables,
36693833 <span class="name">Group</span><span class="signature">()</span>
36703834 </div>
36713835
3672
3836
36733837 <div class="docstring"><p><strong><code>__init__(self, parent, name)</code></strong>
36743838 <code><a href="#Group">Group</a></code> constructor.</p>
36753839
36933857 <span class="name">close</span><span class="signature">(unknown)</span>:
36943858 </div>
36953859
3696
3860
36973861 <div class="docstring"><p><strong><code>close(self)</code></strong></p>
36983862
36993863 <p>overrides <code><a href="#Dataset">Dataset</a></code> close method which does not apply to <code><a href="#Group">Group</a></code>
37633927 <span class="name">MFDataset</span><wbr>(<span class="base"><a href="#Dataset">netCDF4.Dataset</a></span>):
37643928 </div>
37653929
3766
3930
37673931 <div class="docstring"><p>Class for reading multi-file netCDF Datasets, making variables
37683932 spanning multiple files appear as if they were in one file.
37693933 Datasets must be in <code>NETCDF4_CLASSIC, NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET
37733937
37743938 <p>Example usage (See <code><a href="#MFDataset.__init__">MFDataset.__init__</a></code> for more details):</p>
37753939
3776 <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>
3940 <div class="pdoc-code 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>
37773941 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># create a series of netCDF files with a variable sharing</span>
37783942 <span class="o">&gt;&gt;&gt;</span> <span class="c1"># the same unlimited dimension.</span>
37793943 <span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">nf</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>
38003964 <span class="name">MFDataset</span><span class="signature">(files, check=False, aggdim=None, exclude=[], master_file=None)</span>
38013965 </div>
38023966
3803
3967
38043968 <div class="docstring"><p><strong><code>__init__(self, files, check=False, aggdim=None, exclude=[],
38053969 master_file=None)</code></strong></p>
38063970
38454009 <span class="name">ncattrs</span><span class="signature">(self)</span>:
38464010 </div>
38474011
3848
4012
38494013 <div class="docstring"><p><strong><code>ncattrs(self)</code></strong></p>
38504014
38514015 <p>return the netcdf attribute names from the master file.</p>
38614025 <span class="name">close</span><span class="signature">(self)</span>:
38624026 </div>
38634027
3864
4028
38654029 <div class="docstring"><p><strong><code>close(self)</code></strong></p>
38664030
38674031 <p>close all the open files.</p>
39294093 <span class="name">MFTime</span><wbr>(<span class="base">netCDF4._netCDF4._Variable</span>):
39304094 </div>
39314095
3932
4096
39334097 <div class="docstring"><p>Class providing an interface to a MFDataset time Variable by imposing a unique common
39344098 time unit and/or calendar to all files.</p>
39354099
39364100 <p>Example usage (See <code><a href="#MFTime.__init__">MFTime.__init__</a></code> for more details):</p>
39374101
3938 <div class="codehilite"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
4102 <div class="pdoc-code 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>
39394103 <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>
39404104 <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>
39414105 <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>
39714135 <span class="name">MFTime</span><span class="signature">(time, units=None, calendar=None)</span>
39724136 </div>
39734137
3974
4138
39754139 <div class="docstring"><p><strong><code>__init__(self, time, units=None, calendar=None)</code></strong></p>
39764140
39774141 <p>Create a time Variable with units consistent across a multifile
40154179 <span class="name">CompoundType</span>:
40164180 </div>
40174181
4018
4182
40194183 <div class="docstring"><p>A <code><a href="#CompoundType">CompoundType</a></code> instance is used to describe a compound data
40204184 type, and can be passed to the the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of
40214185 a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance.
40344198 <span class="name">CompoundType</span><span class="signature">()</span>
40354199 </div>
40364200
4037
4201
40384202 <div class="docstring"><p><strong><em><code>__init__(group, datatype, datatype_name)</code></em></strong></p>
40394203
40404204 <p>CompoundType constructor.</p>
40634227 <div id="CompoundType.dtype" class="classattr">
40644228 <div class="attr variable"><a class="headerlink" href="#CompoundType.dtype">#&nbsp;&nbsp</a>
40654229
4066 <span class="name">dtype</span><span class="default_value"> = &lt;attribute &#39;dtype&#39; of &#39;<a href="#_netCDF4.CompoundType">netCDF4._netCDF4.CompoundType</a>&#39; objects&gt;</span>
4067 </div>
4068
4230 <span class="name">dtype</span>
4231 </div>
4232
4233
40694234
40704235
40714236 </div>
40724237 <div id="CompoundType.dtype_view" class="classattr">
40734238 <div class="attr variable"><a class="headerlink" href="#CompoundType.dtype_view">#&nbsp;&nbsp</a>
40744239
4075 <span class="name">dtype_view</span><span class="default_value"> = &lt;attribute &#39;dtype_view&#39; of &#39;<a href="#_netCDF4.CompoundType">netCDF4._netCDF4.CompoundType</a>&#39; objects&gt;</span>
4076 </div>
4077
4240 <span class="name">dtype_view</span>
4241 </div>
4242
4243
40784244
40794245
40804246 </div>
40814247 <div id="CompoundType.name" class="classattr">
40824248 <div class="attr variable"><a class="headerlink" href="#CompoundType.name">#&nbsp;&nbsp</a>
40834249
4084 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#_netCDF4.CompoundType">netCDF4._netCDF4.CompoundType</a>&#39; objects&gt;</span>
4085 </div>
4086
4250 <span class="name">name</span>
4251 </div>
4252
4253
40874254
40884255
40894256 </div>
40974264 <span class="name">VLType</span>:
40984265 </div>
40994266
4100
4267
41014268 <div class="docstring"><p>A <code><a href="#VLType">VLType</a></code> instance is used to describe a variable length (VLEN) data
41024269 type, and can be passed to the the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of
41034270 a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance. See
41154282 <span class="name">VLType</span><span class="signature">()</span>
41164283 </div>
41174284
4118
4285
41194286 <div class="docstring"><p><strong><code>__init__(group, datatype, datatype_name)</code></strong></p>
41204287
41214288 <p>VLType constructor.</p>
41384305 <div id="VLType.dtype" class="classattr">
41394306 <div class="attr variable"><a class="headerlink" href="#VLType.dtype">#&nbsp;&nbsp</a>
41404307
4141 <span class="name">dtype</span><span class="default_value"> = &lt;attribute &#39;dtype&#39; of &#39;<a href="#_netCDF4.VLType">netCDF4._netCDF4.VLType</a>&#39; objects&gt;</span>
4142 </div>
4143
4308 <span class="name">dtype</span>
4309 </div>
4310
4311
41444312
41454313
41464314 </div>
41474315 <div id="VLType.name" class="classattr">
41484316 <div class="attr variable"><a class="headerlink" href="#VLType.name">#&nbsp;&nbsp</a>
41494317
4150 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#_netCDF4.VLType">netCDF4._netCDF4.VLType</a>&#39; objects&gt;</span>
4151 </div>
4152
4318 <span class="name">name</span>
4319 </div>
4320
4321
41534322
41544323
41554324 </div>
41624331 <span class="name">date2num</span><span class="signature">(unknown)</span>:
41634332 </div>
41644333
4165
4334
41664335 <div class="docstring"><p>date2num(dates, units, calendar=None, has_year_zero=None)</p>
41674336
41684337 <p>Return numeric time values given datetime objects. The units
41804349 <p><strong>units</strong>: a string of the form <strong><time units> since <reference time></strong>
41814350 describing the time units. <strong><time units></strong> can be days, hours, minutes,
41824351 seconds, milliseconds or microseconds. <strong><reference time></strong> is the time
4183 origin. <strong>months_since</strong> is allowed <em>only</em> for the <strong>360_day</strong> calendar.</p>
4352 origin. <strong>months since</strong> is allowed <em>only</em> for the <strong>360_day</strong> calendar
4353 and <strong>common_years since</strong> is allowed <em>only</em> for the <strong>365_day</strong> calendar.</p>
41844354
41854355 <p><strong>calendar</strong>: describes the calendar to be used in the time calculations.
41864356 All the values currently defined in the
4187 <code>CF metadata convention &lt;http://cfconventions.org&gt;</code>__ are supported.
4357 <code>CF metadata convention &lt;http://cfconventions.org/cf-conventions/cf-conventions#calendar&gt;</code>__ are supported.
41884358 Valid calendars <strong>'standard', 'gregorian', 'proleptic_gregorian'
41894359 'noleap', '365_day', '360_day', 'julian', 'all_leap', '366_day'</strong>.
41904360 Default is <code>None</code> which means the calendar associated with the first
41944364 is used and the year zero exists. If set to False for real-world
41954365 calendars, then historical year numbering is used and the year 1 is
41964366 preceded by year -1 and no year zero exists.
4197 The defaults are False for real-world calendars
4198 and True for idealized calendars.
4367 The defaults are set to conform with
4368 CF version 1.9 conventions (False for 'julian', 'gregorian'/'standard', True
4369 for 'proleptic_gregorian' (ISO 8601) and True for the idealized
4370 calendars 'noleap'/'365_day', '360_day', 366_day'/'all_leap')
4371 Note that CF v1.9 does not specifically mention whether year zero
4372 is allowed in the proleptic_gregorian calendar, but ISO-8601 has
4373 a year zero so we have adopted this as the default.
41994374 The defaults can only be over-ridden for the real-world calendars,
42004375 for the the idealized calendars the year zero
42014376 always exists and the has_year_zero kwarg is ignored.
42164391 <span class="name">num2date</span><span class="signature">(unknown)</span>:
42174392 </div>
42184393
4219
4394
42204395 <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>
42214396
42224397 <p>Return datetime objects given numeric time values. The units
42304405 <p><strong>units</strong>: a string of the form <strong><time units> since <reference time></strong>
42314406 describing the time units. <strong><time units></strong> can be days, hours, minutes,
42324407 seconds, milliseconds or microseconds. <strong><reference time></strong> is the time
4233 origin. <strong>months_since</strong> is allowed <em>only</em> for the <strong>360_day</strong> calendar.</p>
4408 origin. <strong>months since</strong> is allowed <em>only</em> for the <strong>360_day</strong> calendar
4409 and <strong>common_years since</strong> is allowed <em>only</em> for the <strong>365_day</strong> calendar.</p>
42344410
42354411 <p><strong>calendar</strong>: describes the calendar used in the time calculations.
42364412 All the values currently defined in the
4237 <code>CF metadata convention &lt;http://cfconventions.org&gt;</code>__ are supported.
4413 <code>CF metadata convention &lt;http://cfconventions.org/cf-conventions/cf-conventions#calendar&gt;</code>__ are supported.
42384414 Valid calendars <strong>'standard', 'gregorian', 'proleptic_gregorian'
42394415 'noleap', '365_day', '360_day', 'julian', 'all_leap', '366_day'</strong>.
42404416 Default is <strong>'standard'</strong>, which is a mixed Julian/Gregorian calendar.</p>
42514427 is used and the year zero exists. If set to False for real-world
42524428 calendars, then historical year numbering is used and the year 1 is
42534429 preceded by year -1 and no year zero exists.
4254 The defaults are False for real-world calendars
4255 and True for idealized calendars.
4430 The defaults are set to conform with
4431 CF version 1.9 conventions (False for 'julian', 'gregorian'/'standard', True
4432 for 'proleptic_gregorian' (ISO 8601) and True for the idealized
4433 calendars 'noleap'/'365_day', '360_day', 366_day'/'all_leap')
42564434 The defaults can only be over-ridden for the real-world calendars,
42574435 for the the idealized calendars the year zero
42584436 always exists and the has_year_zero kwarg is ignored.
42854463 <span class="name">date2index</span><span class="signature">(unknown)</span>:
42864464 </div>
42874465
4288
4466
42894467 <div class="docstring"><p>date2index(dates, nctime, calendar=None, select=u'exact', has_year_zero=None)</p>
42904468
42914469 <p>Return indices of a netCDF time variable corresponding to the given dates.</p>
42984476
42994477 <p><strong>calendar</strong>: describes the calendar to be used in the time calculations.
43004478 All the values currently defined in the
4301 <code>CF metadata convention &lt;http://cfconventions.org&gt;</code>__ are supported.
4479 <code>CF metadata convention &lt;http://cfconventions.org/cf-conventions/cf-conventions#calendar&gt;</code>__ are supported.
43024480 Valid calendars <strong>'standard', 'gregorian', 'proleptic_gregorian'
43034481 'noleap', '365_day', '360_day', 'julian', 'all_leap', '366_day'</strong>.
43044482 Default is <code>None</code> which means the calendar associated with the first
43154493 is used and the year zero exists. If set to False for real-world
43164494 calendars, then historical year numbering is used and the year 1 is
43174495 preceded by year -1 and no year zero exists.
4318 The defaults are False for real-world calendars
4319 and True for idealized calendars.
4496 The defaults are set to conform with
4497 CF version 1.9 conventions (False for 'julian', 'gregorian'/'standard', True
4498 for 'proleptic_gregorian' (ISO 8601) and True for the idealized
4499 calendars 'noleap'/'365_day', '360_day', 366_day'/'all_leap')
43204500 The defaults can only be over-ridden for the real-world calendars,
43214501 for the the idealized calendars the year zero
43224502 always exists and the has_year_zero kwarg is ignored.
43374517 <span class="name">stringtochar</span><span class="signature">(unknown)</span>:
43384518 </div>
43394519
4340
4520
43414521 <div class="docstring"><p><strong><code>stringtochar(a,encoding='utf-8')</code></strong></p>
43424522
43434523 <p>convert a string array to a character array with one extra dimension</p>
43644544 <span class="name">chartostring</span><span class="signature">(unknown)</span>:
43654545 </div>
43664546
4367
4547
43684548 <div class="docstring"><p><strong><code>chartostring(b,encoding='utf-8')</code></strong></p>
43694549
43704550 <p>convert a character array to a string array with one less dimension.</p>
43914571 <span class="name">stringtoarr</span><span class="signature">(unknown)</span>:
43924572 </div>
43934573
4394
4574
43954575 <div class="docstring"><p><strong><code>stringtoarr(a, NUMCHARS,dtype='S')</code></strong></p>
43964576
43974577 <p>convert a string to a character array of length <code>NUMCHARS</code></p>
44194599 <span class="name">getlibversion</span><span class="signature">(unknown)</span>:
44204600 </div>
44214601
4422
4602
44234603 <div class="docstring"><p><strong><code><a href="#getlibversion">getlibversion()</a></code></strong></p>
44244604
44254605 <p>returns a string describing the version of the netcdf library
44374617 <span class="name">EnumType</span>:
44384618 </div>
44394619
4440
4620
44414621 <div class="docstring"><p>A <code><a href="#EnumType">EnumType</a></code> instance is used to describe an Enum data
44424622 type, and can be passed to the the <code><a href="#Dataset.createVariable">Dataset.createVariable</a></code> method of
44434623 a <code><a href="#Dataset">Dataset</a></code> or <code><a href="#Group">Group</a></code> instance. See
44554635 <span class="name">EnumType</span><span class="signature">()</span>
44564636 </div>
44574637
4458
4638
44594639 <div class="docstring"><p><strong><code>__init__(group, datatype, datatype_name, enum_dict)</code></strong></p>
44604640
44614641 <p>EnumType constructor.</p>
44814661 <div id="EnumType.dtype" class="classattr">
44824662 <div class="attr variable"><a class="headerlink" href="#EnumType.dtype">#&nbsp;&nbsp</a>
44834663
4484 <span class="name">dtype</span><span class="default_value"> = &lt;attribute &#39;dtype&#39; of &#39;<a href="#_netCDF4.EnumType">netCDF4._netCDF4.EnumType</a>&#39; objects&gt;</span>
4485 </div>
4486
4664 <span class="name">dtype</span>
4665 </div>
4666
4667
44874668
44884669
44894670 </div>
44904671 <div id="EnumType.name" class="classattr">
44914672 <div class="attr variable"><a class="headerlink" href="#EnumType.name">#&nbsp;&nbsp</a>
44924673
4493 <span class="name">name</span><span class="default_value"> = &lt;attribute &#39;name&#39; of &#39;<a href="#_netCDF4.EnumType">netCDF4._netCDF4.EnumType</a>&#39; objects&gt;</span>
4494 </div>
4495
4674 <span class="name">name</span>
4675 </div>
4676
4677
44964678
44974679
44984680 </div>
44994681 <div id="EnumType.enum_dict" class="classattr">
45004682 <div class="attr variable"><a class="headerlink" href="#EnumType.enum_dict">#&nbsp;&nbsp</a>
45014683
4502 <span class="name">enum_dict</span><span class="default_value"> = &lt;attribute &#39;enum_dict&#39; of &#39;<a href="#_netCDF4.EnumType">netCDF4._netCDF4.EnumType</a>&#39; objects&gt;</span>
4503 </div>
4504
4684 <span class="name">enum_dict</span>
4685 </div>
4686
4687
45054688
45064689
45074690 </div>
45144697 <span class="name">get_chunk_cache</span><span class="signature">(unknown)</span>:
45154698 </div>
45164699
4517
4700
45184701 <div class="docstring"><p><strong><code><a href="#get_chunk_cache">get_chunk_cache()</a></code></strong></p>
45194702
45204703 <p>return current netCDF chunk cache information in a tuple (size,nelems,preemption).
45324715 <span class="name">set_chunk_cache</span><span class="signature">(unknown)</span>:
45334716 </div>
45344717
4535
4718
45364719 <div class="docstring"><p><strong><code>set_chunk_cache(self,size=None,nelems=None,preemption=None)</code></strong></p>
45374720
45384721 <p>change netCDF4 chunk cache settings.
0 from __future__ import print_function
1 # benchmark reads and writes, with and without compression.
2 # tests all four supported file formats.
3 from numpy.random.mtrand import uniform
4 import netCDF4
5 from timeit import Timer
6 import os, sys
7
8 # use real data.
9 URL="http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis/pressure/hgt.1990.nc"
10 nc = netCDF4.Dataset(URL)
11
12 # use real 500 hPa geopotential height data.
13 n1dim = 100
14 n3dim = 73
15 n4dim = 144
16 ntrials = 10
17 sys.stdout.write('reading and writing a %s by %s by %s random array ..\n'%(n1dim,n3dim,n4dim))
18 sys.stdout.write('(average of %s trials)\n\n' % ntrials)
19 array = nc.variables['hgt'][0:n1dim,5,:,:]
20
21
22 def write_netcdf(filename,nsd,quantize_mode='BitGroom'):
23 file = netCDF4.Dataset(filename,'w',format='NETCDF4')
24 file.createDimension('n1', None)
25 file.createDimension('n3', n3dim)
26 file.createDimension('n4', n4dim)
27 foo = file.createVariable('data',\
28 'f4',('n1','n3','n4'),\
29 zlib=True,shuffle=True,\
30 quantize_mode=quantize_mode,\
31 significant_digits=nsd)
32 foo[:] = array
33 file.close()
34
35 def read_netcdf(filename):
36 file = netCDF4.Dataset(filename)
37 data = file.variables['data'][:]
38 file.close()
39
40 for sigdigits in range(1,5,1):
41 sys.stdout.write('testing compression with significant_digits=%s...\n' %\
42 sigdigits)
43 write_netcdf('test.nc',sigdigits)
44 read_netcdf('test.nc')
45 # print out size of resulting files with standard quantization.
46 sys.stdout.write('size of test.nc = %s\n'%repr(os.stat('test.nc').st_size))
47 sys.stdout.write("testing compression with significant_digits=%s and 'GranularBitRound'...\n" %\
48 sigdigits)
49 write_netcdf('test.nc',sigdigits,quantize_mode='GranularBitRound')
50 read_netcdf('test.nc')
51 # print out size of resulting files with alternate quantization.
52 sys.stdout.write('size of test.nc = %s\n'%repr(os.stat('test.nc').st_size))
1010 #define MPI_Message PyMPI_MPI_Message
1111 #endif
1212
13 #if (MPI_VERSION < 4) && !defined(PyMPI_HAVE_MPI_Session)
14 typedef void *PyMPI_MPI_Session;
15 #define MPI_Session PyMPI_MPI_Session
16 #endif
17
1318 #endif/*MPI_COMPAT_H*/
215215 NC_ENDIAN_NATIVE
216216 NC_ENDIAN_LITTLE
217217 NC_ENDIAN_BIG
218 NC_SZIP_EC_OPTION_MASK # entropy encoding
219 NC_SZIP_NN_OPTION_MASK # nearest neighbor encoding
220218 const_char_ptr *nc_inq_libvers() nogil
221219 const_char_ptr *nc_strerror(int ncerr)
222220 int nc_create(char *path, int cmode, int *ncidp)
690688 int nc_inq_enum_ident(int ncid, nc_type xtype, long long value, char *identifier) nogil
691689
692690
691 IF HAS_QUANTIZATION_SUPPORT:
692 cdef extern from "netcdf.h":
693 cdef enum:
694 NC_NOQUANTIZE
695 NC_QUANTIZE_BITGROOM
696 NC_QUANTIZE_GRANULARBR
697 NC_QUANTIZE_BITROUND
698 int nc_def_var_quantize(int ncid, int varid, int quantize_mode, int nsd)
699 int nc_inq_var_quantize(int ncid, int varid, int *quantize_modep, int *nsdp) nogil
700
701 IF HAS_SZIP_SUPPORT:
702 cdef extern from "netcdf.h":
703 int nc_def_var_quantize(int ncid, int varid, int quantize_mode, int nsd)
704 int nc_inq_var_quantize(int ncid, int varid, int *quantize_modep, int *nsdp) nogil
705 int nc_def_var_szip(int ncid, int varid, int options_mask, int pixels_per_bloc)
706 int nc_inq_var_szip(int ncid, int varid, int *options_maskp, int *pixels_per_blockp)
707
708 IF HAS_ZSTANDARD_SUPPORT:
709 cdef extern from "netcdf_filter.h":
710 cdef enum:
711 H5Z_FILTER_ZSTANDARD
712 int nc_def_var_zstandard(int ncid, int varid, int level)
713 int nc_inq_var_zstandard(int ncid, int varid, int* hasfilterp, int *levelp)
714 int nc_inq_filter_avail(int ncid, unsigned id)
715
716 IF HAS_BZIP2_SUPPORT:
717 cdef extern from "netcdf_filter.h":
718 cdef enum:
719 H5Z_FILTER_BZIP2
720 int nc_def_var_bzip2(int ncid, int varid, int level)
721 int nc_inq_var_bzip2(int ncid, int varid, int* hasfilterp, int *levelp)
722
723 IF HAS_BLOSC_SUPPORT:
724 cdef extern from "netcdf_filter.h":
725 int nc_def_var_blosc(int ncid, int varid, unsigned subcompressor, unsigned level, unsigned blocksize, unsigned addshuffle)
726 int nc_inq_var_blosc(int ncid, int varid, int* hasfilterp, unsigned* subcompressorp, unsigned* levelp, unsigned* blocksizep, unsigned* addshufflep)
727
693728 IF HAS_NC_OPEN_MEM:
694729 cdef extern from "netcdf_mem.h":
695730 int nc_open_mem(const char *path, int mode, size_t size, void* memory, int *ncidp)
0 import os, sys, subprocess
0 import os, sys, subprocess, glob
11 import os.path as osp
2 import shutil
23 import configparser
3 from setuptools import setup, Extension
4 from setuptools import setup, Extension, find_namespace_packages
45 from distutils.dist import Distribution
56
67 setuptools_extra_kwargs = {
6465 has_parallel_support = False
6566 has_parallel4_support = False
6667 has_pnetcdf_support = False
68 has_szip_support = False
69 has_quantize = False
70 has_zstandard = False
71 has_bzip2 = False
72 has_blosc = False
6773
6874 for d in inc_dirs:
6975 try:
7278 continue
7379
7480 has_nc_open_mem = os.path.exists(os.path.join(d, 'netcdf_mem.h'))
81 has_nc_filter = os.path.exists(os.path.join(d, 'netcdf_filter.h'))
7582
7683 for line in f:
7784 if line.startswith('nc_rename_grp'):
8289 has_nc_inq_format_extended = True
8390 if line.startswith('#define NC_FORMAT_64BIT_DATA'):
8491 has_cdf5_format = True
92 if line.startswith('nc_def_var_quantize'):
93 has_quantize = True
8594
8695 if has_nc_open_mem:
8796 try:
91100 for line in f:
92101 if line.startswith('EXTERNL int nc_create_mem'):
93102 has_nc_create_mem = True
103
104 if has_nc_filter:
105 try:
106 f = open(os.path.join(d, 'netcdf_filter.h'), **open_kwargs)
107 except IOError:
108 continue
109 for line in f:
110 if line.startswith('EXTERNL int nc_def_var_zstandard'):
111 has_zstandard = True
112 if line.startswith('EXTERNL int nc_def_var_bzip2'):
113 has_bzip2 = True
114 if line.startswith('EXTERNL int nc_def_var_blosc'):
115 has_blosc = True
94116
95117 ncmetapath = os.path.join(d,'netcdf_meta.h')
96118 if os.path.exists(ncmetapath):
103125 has_parallel4_support = bool(int(line.split()[2]))
104126 if line.startswith('#define NC_HAS_PNETCDF'):
105127 has_pnetcdf_support = bool(int(line.split()[2]))
128 if line.startswith('#define NC_HAS_SZIP_WRITE'):
129 has_szip_support = bool(int(line.split()[2]))
106130 # NC_HAS_PARALLEL4 missing in 4.6.1 (issue #964)
107131 if not has_parallel4_support and has_parallel_support and not has_pnetcdf_support:
108132 has_parallel4_support = True
115139
116140 return has_rename_grp, has_nc_inq_path, has_nc_inq_format_extended, \
117141 has_cdf5_format, has_nc_open_mem, has_nc_create_mem, \
118 has_parallel4_support, has_pnetcdf_support
142 has_parallel4_support, has_pnetcdf_support, has_szip_support, has_quantize, \
143 has_zstandard, has_bzip2, has_blosc
119144
120145
121146 def getnetcdfvers(libdirs):
381406 dirstosearch.append(os.environ["CONDA_PREFIX"]) # linux,macosx
382407 dirstosearch.append(os.path.join(os.environ["CONDA_PREFIX"],'Library')) # windows
383408 dirstosearch += [os.path.expanduser('~'), '/usr/local', '/sw', '/opt',
384 '/opt/local', '/usr']
409 '/opt/local', '/opt/homebrew', '/usr']
385410
386411 # try nc-config first
387412 if USE_NCCONFIG and HAS_NCCONFIG: # Try nc-config.
528553 # this determines whether renameGroup and filepath methods will work.
529554 has_rename_grp, has_nc_inq_path, has_nc_inq_format_extended, \
530555 has_cdf5_format, has_nc_open_mem, has_nc_create_mem, \
531 has_parallel4_support, has_pnetcdf_support = \
556 has_parallel4_support, has_pnetcdf_support, has_szip_support, has_quantize, \
557 has_zstandard, has_bzip2, has_blosc = \
532558 check_api(inc_dirs,netcdf_lib_version)
533559 # for netcdf 4.4.x CDF5 format is always enabled.
534560 if netcdf_lib_version is not None and\
599625 else:
600626 sys.stdout.write('netcdf lib does not have pnetcdf parallel functions\n')
601627 f.write('DEF HAS_PNETCDF_SUPPORT = 0\n')
628
629 if has_quantize:
630 sys.stdout.write('netcdf lib has bit-grooming/quantization functions\n')
631 f.write('DEF HAS_QUANTIZATION_SUPPORT = 1\n')
632 else:
633 sys.stdout.write('netcdf lib does not have bit-grooming/quantization functions\n')
634 f.write('DEF HAS_QUANTIZATION_SUPPORT = 0\n')
635
636 if has_zstandard:
637 sys.stdout.write('netcdf lib has zstandard compression functions\n')
638 f.write('DEF HAS_ZSTANDARD_SUPPORT = 1\n')
639 else:
640 sys.stdout.write('netcdf lib does not have zstandard compression functions\n')
641 f.write('DEF HAS_ZSTANDARD_SUPPORT = 0\n')
642
643 if has_bzip2:
644 sys.stdout.write('netcdf lib has bzip2 compression functions\n')
645 f.write('DEF HAS_BZIP2_SUPPORT = 1\n')
646 else:
647 sys.stdout.write('netcdf lib does not have bzip2 compression functions\n')
648 f.write('DEF HAS_BZIP2_SUPPORT = 0\n')
649
650 if has_blosc:
651 sys.stdout.write('netcdf lib has blosc compression functions\n')
652 f.write('DEF HAS_BLOSC_SUPPORT = 1\n')
653 else:
654 sys.stdout.write('netcdf lib does not have blosc compression functions\n')
655 f.write('DEF HAS_BLOSC_SUPPORT = 0\n')
656
657 if has_szip_support:
658 sys.stdout.write('netcdf lib has szip compression functions\n')
659 f.write('DEF HAS_SZIP_SUPPORT = 1\n')
660 else:
661 sys.stdout.write('netcdf lib does not have szip compression functions\n')
662 f.write('DEF HAS_SZIP_SUPPORT = 0\n')
602663
603664 f.close()
604665
615676 library_dirs=lib_dirs,
616677 include_dirs=inc_dirs + ['include'],
617678 runtime_library_dirs=runtime_lib_dirs)]
679 # set language_level directive to 3
680 for e in ext_modules:
681 e.cython_directives = {'language_level': "3"} #
618682 else:
619683 ext_modules = None
684
685 # if NETCDF_PLUGIN_DIR set, install netcdf-c compression plugins inside package
686 # (should point to location of lib__nc* files built by netcdf-c)
687 copied_plugins=False
688 if os.environ.get("NETCDF_PLUGIN_DIR"):
689 plugin_dir = os.environ.get("NETCDF_PLUGIN_DIR")
690 plugins = glob.glob(os.path.join(plugin_dir, "lib__nc*"))
691 if not plugins:
692 sys.stdout.write('no plugin files in NETCDF_PLUGIN_DIR, not installing..\n')
693 data_files = []
694 else:
695 data_files = plugins
696 sys.stdout.write('installing netcdf compression plugins from %s ...\n' % plugin_dir)
697 sofiles = [os.path.basename(sofilepath) for sofilepath in data_files]
698 sys.stdout.write(repr(sofiles)+'\n')
699 if 'sdist' not in sys.argv[1:] and 'clean' not in sys.argv[1:] and '--version' not in sys.argv[1:]:
700 for f in data_files:
701 shutil.copy(f, osp.join(os.getcwd(),osp.join(osp.join('src','netCDF4'),'plugins')))
702 copied_plugins=True
703 else:
704 sys.stdout.write('NETCDF_PLUGIN_DIR not set, no netcdf compression plugins installed\n')
705 data_files = []
620706
621707 setup(name="netCDF4",
622708 cmdclass=cmdclass,
641727 "Topic :: Software Development :: Libraries :: Python Modules",
642728 "Topic :: System :: Archiving :: Compression",
643729 "Operating System :: OS Independent"],
644 packages=['netCDF4'],
730 packages=find_namespace_packages(where="src"),
645731 package_dir={'':'src'},
732 package_data={"netCDF4.plugins": ["lib__nc*"]},
646733 ext_modules=ext_modules,
647734 **setuptools_extra_kwargs)
735
736 # remove plugin files copied from outside source tree
737 if copied_plugins:
738 for f in sofiles:
739 filepath = osp.join(osp.join(osp.join('src','netCDF4'),'plugins'),f)
740 if os.path.exists(filepath):
741 os.remove(filepath)
66 __has_rename_grp__, __has_nc_inq_path__,
77 __has_nc_inq_format_extended__, __has_nc_open_mem__,
88 __has_nc_create_mem__, __has_cdf5_format__,
9 __has_parallel4_support__, __has_pnetcdf_support__)
9 __has_parallel4_support__, __has_pnetcdf_support__,
10 __has_quantization_support__, __has_zstandard_support__,
11 __has_bzip2_support__, __has_blosc_support__, __has_szip_support__)
12 import os
1013 __all__ =\
1114 ['Dataset','Variable','Dimension','Group','MFDataset','MFTime','CompoundType','VLType','date2num','num2date','date2index','stringtochar','chartostring','stringtoarr','getlibversion','EnumType','get_chunk_cache','set_chunk_cache']
15 # if HDF5_PLUGIN_PATH not set, point to package path if plugins live there
16 pluginpath = os.path.join(__path__[0],'plugins')
17 if 'HDF5_PLUGIN_PATH' not in os.environ and\
18 (os.path.exists(os.path.join(pluginpath,'lib__nczhdf5filters.so')) or\
19 os.path.exists(os.path.join(pluginpath,'lib__nczhdf5filters.dylib'))):
20 os.environ['HDF5_PLUGIN_PATH']=pluginpath
00 """
1 Version 1.5.8
1 Version 1.6.0
22 -------------
33
44 # Introduction
1414 and should be familiar to users of that module.
1515
1616 Most new features of netCDF 4 are implemented, such as multiple
17 unlimited dimensions, groups and zlib data compression. All the new
17 unlimited dimensions, groups and data compression. All the new
1818 numeric data types (such as 64 bit and unsigned integer types) are
1919 implemented. Compound (struct), variable length (vlen) and
2020 enumerated (enum) data types are supported, but not the opaque data type.
5757 If the dependencies are not found
5858 in any of the paths specified by environment variables, then standard locations
5959 (such as `/usr` and `/usr/local`) are searched.
60 - if the env var `NETCDF_PLUGIN_DIR` is set to point to the location of the netcdf-c compression
61 plugins built by netcdf >= 4.9.0, they will be installed inside the package. In this
62 case `HDF5_PLUGIN_PATH` will be set to the package installation path on import,
63 so the extra compression algorithms available in netcdf-c >= 4.9.0 will automatically
64 be available. Otherwise, the user will have to set `HDF5_PLUGIN_PATH` explicitly
65 to have access to the extra compression plugins.
6066 - run `python setup.py build`, then `python setup.py install` (as root if
6167 necessary).
6268 - run the tests in the 'test' directory by running `python run_all.py`.
640646
641647 ## Efficient compression of netCDF variables
642648
643 Data stored in netCDF 4 `Variable` objects can be compressed and
644 decompressed on the fly. The parameters for the compression are
645 determined by the `zlib`, `complevel` and `shuffle` keyword arguments
646 to the `Dataset.createVariable` method. To turn on
647 compression, set `zlib=True`. The `complevel` keyword regulates the
648 speed and efficiency of the compression (1 being fastest, but lowest
649 Data stored in netCDF `Variable` objects can be compressed and
650 decompressed on the fly. The compression algorithm used is determined
651 by the `compression` keyword argument to the `Dataset.createVariable` method.
652 `zlib` compression is always available, `szip` is available if the linked HDF5
653 library supports it, and `zstd`, `bzip2`, `blosc_lz`,`blosc_lz4`,`blosc_lz4hc`,
654 `blosc_zlib` and `blosc_zstd` are available via optional external plugins.
655 The `complevel` keyword regulates the
656 speed and efficiency of the compression for `zlib`, `bzip` and `zstd` (1 being fastest, but lowest
649657 compression ratio, 9 being slowest but best compression ratio). The
650658 default value of `complevel` is 4. Setting `shuffle=False` will turn
651659 off the HDF5 shuffle filter, which de-interlaces a block of data before
652 compression by reordering the bytes. The shuffle filter can
653 significantly improve compression ratios, and is on by default. Setting
660 `zlib` compression by reordering the bytes. The shuffle filter can
661 significantly improve compression ratios, and is on by default if `compression=zlib`. Setting
654662 `fletcher32` keyword argument to
655663 `Dataset.createVariable` to `True` (it's `False` by
656664 default) enables the Fletcher32 checksum algorithm for error detection.
661669 are relevant for `NETCDF4` and `NETCDF4_CLASSIC` files (where the
662670 underlying file format is HDF5) and are silently ignored if the file
663671 format is `NETCDF3_CLASSIC`, `NETCDF3_64BIT_OFFSET` or `NETCDF3_64BIT_DATA`.
672 If the HDF5 library is built with szip support, compression=`szip` can also
673 be used (in conjunction with the `szip_coding` and `szip_pixels_per_block` keyword
674 arguments).
664675
665676 If your data only has a certain number of digits of precision (say for
666677 example, it is temperature data that was measured with a precision of
667 0.1 degrees), you can dramatically improve zlib compression by
668 quantizing (or truncating) the data using the `least_significant_digit`
669 keyword argument to `Dataset.createVariable`. The least
670 significant digit is the power of ten of the smallest decimal place in
678 0.1 degrees), you can dramatically improve compression by
679 quantizing (or truncating) the data. There are two methods supplied for
680 doing this. You can use the `least_significant_digit`
681 keyword argument to `Dataset.createVariable` to specify
682 the power of ten of the smallest decimal place in
671683 the data that is a reliable value. For example if the data has a
672684 precision of 0.1, then setting `least_significant_digit=1` will cause
673685 data the data to be quantized using `numpy.around(scale*data)/scale`, where
674686 scale = 2**bits, and bits is determined so that a precision of 0.1 is
675 retained (in this case bits=4). Effectively, this makes the compression
687 retained (in this case bits=4). This is done at the python level and is
688 not a part of the underlying C library. Starting with netcdf-c version 4.9.0,
689 a quantization capability is provided in the library. This can be
690 used via the `significant_digits` `Dataset.createVariable` kwarg (new in
691 version 1.6.0).
692 The interpretation of `significant_digits` is different than `least_signficant_digit`
693 in that it specifies the absolute number of significant digits independent
694 of the magnitude of the variable (the floating point exponent).
695 Either of these approaches makes the compression
676696 'lossy' instead of 'lossless', that is some precision in the data is
677697 sacrificed for the sake of disk space.
678698
685705 with
686706
687707 ```python
688 >>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",),zlib=True)
708 >>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",),compression='zlib')
689709 ```
690710
691711 and then
692712
693713 ```python
694 >>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",),zlib=True,least_significant_digit=3)
714 >>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",),compression='zlib',least_significant_digit=3)
715 ```
716
717 or with netcdf-c >= 4.9.0
718
719 ```python
720 >>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",),compression='zlib',significant_digits=4)
695721 ```
696722
697723 and see how much smaller the resulting files are.
12031229 # Python 3.7+ guarantees order; older versions need OrderedDict
12041230 from collections import OrderedDict
12051231
1206 __version__ = "1.5.8"
1232 __version__ = "1.6.0"
12071233
12081234 # Initialize numpy
12091235 import posixpath
12131239 import warnings
12141240 import subprocess
12151241 import pathlib
1242 import os
12161243 from glob import glob
12171244 from numpy import ma
12181245 from libc.string cimport memcpy, memset
13031330 __has_nc_create_mem__ = HAS_NC_CREATE_MEM
13041331 __has_parallel4_support__ = HAS_PARALLEL4_SUPPORT
13051332 __has_pnetcdf_support__ = HAS_PNETCDF_SUPPORT
1333 __has_quantization_support__ = HAS_QUANTIZATION_SUPPORT
1334 __has_zstandard_support__ = HAS_ZSTANDARD_SUPPORT
1335 __has_bzip2_support__ = HAS_BZIP2_SUPPORT
1336 __has_blosc_support__ = HAS_BLOSC_SUPPORT
1337 __has_szip_support__ = HAS_SZIP_SUPPORT
13061338 _needsworkaround_issue485 = __netcdf4libversion__ < "4.4.0" or \
13071339 (__netcdf4libversion__.startswith("4.4.0") and \
13081340 "-development" in __netcdf4libversion__)
13481380 _cmode_dict = {'NETCDF3_CLASSIC' : NC_CLASSIC_MODEL,
13491381 'NETCDF4_CLASSIC' : NC_CLASSIC_MODEL | NC_NETCDF4,
13501382 'NETCDF4' : NC_NETCDF4}
1383 # dicts for blosc, szip compressors.
1384 _blosc_dict={'blosc_lz':0,'blosc_lz4':1,'blosc_lz4hc':2,'blosc_snappy':3,'blosc_zlib':4,'blosc_zstd':5}
1385 _blosc_dict_inv = {v: k for k, v in _blosc_dict.items()}
1386 _szip_dict = {'ec': 4, 'nn': 32}
1387 _szip_dict_inv = {v: k for k, v in _szip_dict.items()}
13511388 IF HAS_CDF5_FORMAT:
13521389 # NETCDF3_64BIT deprecated, saved for compatibility.
13531390 # use NETCDF3_64BIT_OFFSET instead.
19071944 grp = grp.parent
19081945 free(dimids)
19091946 # create new variable instance.
1947 dimensions = tuple(_find_dim(group,d) for d in dimensions)
19101948 if endianness == '>':
19111949 variables[name] = Variable(group, name, datatype, dimensions, id=varid, endian='big')
19121950 elif endianness == '<':
20302068
20312069 **`mode`**: access mode. `r` means read-only; no data can be
20322070 modified. `w` means write; a new file is created, an existing file with
2033 the same name is deleted. `a` and `r+` mean append (in analogy with
2034 serial files); an existing file is opened for reading and writing.
2071 the same name is deleted. `x` means write, but fail if an existing
2072 file with the same name already exists. `a` and `r+` mean append;
2073 an existing file is opened for reading and writing, if
2074 file does not exist already, one is created.
20352075 Appending `s` to modes `r`, `w`, `r+` or `a` will enable unbuffered shared
20362076 access to `NETCDF3_CLASSIC`, `NETCDF3_64BIT_OFFSET` or
20372077 `NETCDF3_64BIT_DATA` formatted files.
20432083 **`clobber`**: if `True` (default), opening a file with `mode='w'`
20442084 will clobber an existing file with the same name. if `False`, an
20452085 exception will be raised if a file with the same name already exists.
2086 mode=`x` is identical to mode=`w` with clobber=False.
20462087
20472088 **`format`**: underlying file format (one of `'NETCDF4',
20482089 'NETCDF4_CLASSIC', 'NETCDF3_CLASSIC'`, `'NETCDF3_64BIT_OFFSET'` or
20852126 rendered unusable when the parent Dataset instance is garbage collected.
20862127
20872128 **`memory`**: if not `None`, create or open an in-memory Dataset.
2088 If mode = 'r', the memory kwarg must contain a memory buffer object
2129 If mode = `r`, the memory kwarg must contain a memory buffer object
20892130 (an object that supports the python buffer interface).
20902131 The Dataset will then be created with contents taken from this block of memory.
2091 If mode = 'w', the memory kwarg should contain the anticipated size
2132 If mode = `w`, the memory kwarg should contain the anticipated size
20922133 of the Dataset in bytes (used only for NETCDF3 files). A memory
20932134 buffer containing a copy of the Dataset is returned by the
2094 `Dataset.close` method. Requires netcdf-c version 4.4.1 for mode='r,
2095 netcdf-c 4.6.2 for mode='w'. To persist the file to disk, the raw
2135 `Dataset.close` method. Requires netcdf-c version 4.4.1 for mode=`r`
2136 netcdf-c 4.6.2 for mode=`w`. To persist the file to disk, the raw
20962137 bytes from the returned buffer can be written into a binary file.
20972138 The Dataset can also be re-opened using this memory buffer.
20982139
21632204 cmode = NC_MPIIO | _cmode_dict[format]
21642205
21652206 self._inmemory = False
2166 if mode == 'w':
2207
2208 # mode='x' is the same as mode='w' with clobber=False
2209 if mode == 'x':
2210 mode = 'w'; clobber = False
2211
2212 if mode == 'w' or (mode in ['a','r+'] and not os.path.exists(filename)):
21672213 _set_default_format(format=format)
21682214 if memory is not None:
21692215 # if memory is not None and mode='w', memory
22452291 ierr = nc_open(path, NC_NOWRITE | NC_SHARE, &grpid)
22462292 else:
22472293 ierr = nc_open(path, NC_NOWRITE, &grpid)
2248 elif mode == 'r+' or mode == 'a':
2294 elif mode in ['a','r+'] and os.path.exists(filename):
22492295 if parallel:
22502296 IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT:
22512297 ierr = nc_open_par(path, NC_WRITE | NC_MPIIO, \
22562302 ierr = nc_open(path, NC_WRITE | NC_DISKLESS, &grpid)
22572303 else:
22582304 ierr = nc_open(path, NC_WRITE, &grpid)
2259 elif mode == 'as' or mode == 'r+s':
2305 elif mode in ['as','r+s'] and os.path.exists(filename):
22602306 if parallel:
22612307 # NC_SHARE ignored
22622308 IF HAS_PARALLEL4_SUPPORT or HAS_PNETCDF_SUPPORT:
22682314 ierr = nc_open(path, NC_SHARE | NC_DISKLESS, &grpid)
22692315 else:
22702316 ierr = nc_open(path, NC_SHARE, &grpid)
2271 elif mode == 'ws':
2317 elif mode == 'ws' or (mode in ['as','r+s'] and not os.path.exists(filename)):
22722318 _set_default_format(format=format)
22732319 if clobber:
22742320 if parallel:
23012347 else:
23022348 ierr = nc_create(path, NC_SHARE | NC_NOCLOBBER, &grpid)
23032349 else:
2304 raise ValueError("mode must be 'w', 'r', 'a' or 'r+', got '%s'" % mode)
2350 raise ValueError("mode must be 'w', 'x', 'r', 'a' or 'r+', got '%s'" % mode)
23052351
23062352 _ensure_nc_success(ierr, err_cls=IOError, filename=path)
23072353
23982444 raise ValueError(msg)
23992445
24002446 def __repr__(self):
2401 return self.__unicode__()
2402
2403 def __unicode__(self):
2447 return self.__str__()
2448
2449 def __str__(self):
24042450 ncdump = [repr(type(self))]
24052451 dimnames = tuple(_tostr(dimname)+'(%s)'%len(self.dimensions[dimname])\
24062452 for dimname in self.dimensions.keys())
26092655 enum_dict)
26102656 return self.enumtypes[datatype_name]
26112657
2612 def createVariable(self, varname, datatype, dimensions=(), zlib=False,
2613 complevel=4, shuffle=True, fletcher32=False, contiguous=False,
2658 def createVariable(self, varname, datatype, dimensions=(),
2659 compression=None, zlib=False,
2660 complevel=4, shuffle=True,
2661 szip_coding='nn',szip_pixels_per_block=8,
2662 blosc_shuffle=1,fletcher32=False, contiguous=False,
26142663 chunksizes=None, endian='native', least_significant_digit=None,
2615 fill_value=None, chunk_cache=None):
2616 """
2617 **`createVariable(self, varname, datatype, dimensions=(), zlib=False,
2664 significant_digits=None,quantize_mode='BitGroom',fill_value=None, chunk_cache=None):
2665 """
2666 **`createVariable(self, varname, datatype, dimensions=(), compression=None, zlib=False,
26182667 complevel=4, shuffle=True, fletcher32=False, contiguous=False, chunksizes=None,
2619 endian='native', least_significant_digit=None, fill_value=None, chunk_cache=None)`**
2668 szip_coding='nn', szip_pixels_per_block=8, blosc_shuffle=1,
2669 endian='native', least_significant_digit=None, significant_digits=None, quantize_mode='BitGroom',
2670 fill_value=None, chunk_cache=None)`**
26202671
26212672 Creates a new variable with the given `varname`, `datatype`, and
26222673 `dimensions`. If dimensions are not given, the variable is assumed to be
26432694 Data from netCDF variables is presented to python as numpy arrays with
26442695 the corresponding data type.
26452696
2646 `dimensions` must be a tuple containing dimension names (strings) that
2647 have been defined previously using `Dataset.createDimension`. The default value
2697 `dimensions` must be a tuple containing `Dimension` instances and/or
2698 dimension names (strings) that have been defined
2699 previously using `Dataset.createDimension`. The default value
26482700 is an empty tuple, which means the variable is a scalar.
26492701
2702 If the optional keyword argument `compression` is set, the data will be
2703 compressed in the netCDF file using the specified compression algorithm.
2704 Currently `zlib`,`szip`,`zstd`,`bzip2`,`blosc_lz`,`blosc_lz4`,`blosc_lz4hc`,
2705 `blosc_zlib` and `blosc_zstd` are supported.
2706 Default is `None` (no compression). All of the compressors except
2707 `zlib` and `szip` use the HDF5 plugin architecture.
2708
26502709 If the optional keyword `zlib` is `True`, the data will be compressed in
2651 the netCDF file using gzip compression (default `False`).
2652
2653 The optional keyword `complevel` is an integer between 1 and 9 describing
2654 the level of compression desired (default 4). Ignored if `zlib=False`.
2710 the netCDF file using zlib compression (default `False`). The use of this option is
2711 deprecated in favor of `compression='zlib'`.
2712
2713 The optional keyword `complevel` is an integer between 0 and 9 describing
2714 the level of compression desired (default 4). Ignored if `compression=None`.
2715 A value of zero disables compression.
26552716
26562717 If the optional keyword `shuffle` is `True`, the HDF5 shuffle filter
2657 will be applied before compressing the data (default `True`). This
2718 will be applied before compressing the data with zlib (default `True`). This
26582719 significantly improves compression. Default is `True`. Ignored if
26592720 `zlib=False`.
2721
2722 The optional kwarg `blosc_shuffle`is ignored
2723 unless the blosc compressor is used. `blosc_shuffle` can be 0 (no shuffle),
2724 1 (byte-wise shuffle) or 2 (bit-wise shuffle). Default is 1.
2725
2726 The optional kwargs `szip_coding` and `szip_pixels_per_block` are ignored
2727 unless the szip compressor is used. `szip_coding` can be `ec` (entropy coding)
2728 or `nn` (nearest neighbor coding). Default is `nn`. `szip_pixels_per_block`
2729 can be 4, 8, 16 or 32 (default 8).
26602730
26612731 If the optional keyword `fletcher32` is `True`, the Fletcher32 HDF5
26622732 checksum algorithm is activated to detect errors. Default `False`.
26642734 If the optional keyword `contiguous` is `True`, the variable data is
26652735 stored contiguously on disk. Default `False`. Setting to `True` for
26662736 a variable with an unlimited dimension will trigger an error.
2737 Fixed size variables (with no unlimited dimension) with no compression filters
2738 are contiguous by default.
26672739
26682740 The optional keyword `chunksizes` can be used to manually specify the
2669 HDF5 chunksizes for each dimension of the variable. A detailed
2670 discussion of HDF chunking and I/O performance is available
2671 [here](http://www.hdfgroup.org/HDF5/doc/H5.user/Chunking.html).
2741 HDF5 chunksizes for each dimension of the variable.
2742 A detailed discussion of HDF chunking and I/O performance is available
2743 [here](https://support.hdfgroup.org/HDF5/doc/Advanced/Chunking).
2744 The default chunking scheme in the netcdf-c library is discussed
2745 [here](https://www.unidata.ucar.edu/software/netcdf/documentation/NUG/netcdf_perf_chunking.html).
26722746 Basically, you want the chunk size for each dimension to match as
26732747 closely as possible the size of the data block that users will read
2674 from the file. `chunksizes` cannot be set if `contiguous=True`.
2748 from the file. `chunksizes` cannot be set if `contiguous=True`.
26752749
26762750 The optional keyword `endian` can be used to control whether the
26772751 data is stored in little or big endian format on disk. Possible
26812755 opposite format as the one used to create the file, there may be
26822756 some performance advantage to be gained by setting the endian-ness.
26832757
2684 The `zlib, complevel, shuffle, fletcher32, contiguous, chunksizes` and `endian`
2685 keywords are silently ignored for netCDF 3 files that do not use HDF5.
2686
26872758 The optional keyword `fill_value` can be used to override the default
26882759 netCDF `_FillValue` (the value that the variable gets filled with before
26892760 any data is written to it, defaults given in the dict `netCDF4.default_fillvals`).
26902761 If fill_value is set to `False`, then the variable is not pre-filled.
26912762
2692 If the optional keyword parameter `least_significant_digit` is
2763 If the optional keyword parameters `least_significant_digit` or `significant_digits` are
26932764 specified, variable data will be truncated (quantized). In conjunction
2694 with `zlib=True` this produces 'lossy', but significantly more
2765 with `compression='zlib'` this produces 'lossy', but significantly more
26952766 efficient compression. For example, if `least_significant_digit=1`,
26962767 data will be quantized using `numpy.around(scale*data)/scale`, where
26972768 scale = 2**bits, and bits is determined so that a precision of 0.1 is
26992770 [PSL metadata conventions](http://www.esrl.noaa.gov/psl/data/gridded/conventions/cdc_netcdf_standard.shtml):
27002771 "least_significant_digit -- power of ten of the smallest decimal place
27012772 in unpacked data that is a reliable value." Default is `None`, or no
2702 quantization, or 'lossless' compression.
2773 quantization, or 'lossless' compression. If `significant_digits=3`
2774 then the data will be quantized so that three significant digits are retained, independent
2775 of the floating point exponent. The keyword argument `quantize_mode` controls
2776 the quantization algorithm (default 'BitGroom', 'BitRound' and
2777 'GranularBitRound' also available). The 'GranularBitRound'
2778 algorithm may result in better compression for typical geophysical datasets.
2779 This `significant_digits` kwarg is only available with netcdf-c >= 4.9.0, and
2780 only works with `NETCDF4` or `NETCDF4_CLASSIC` formatted files.
27032781
27042782 When creating variables in a `NETCDF4` or `NETCDF4_CLASSIC` formatted file,
27052783 HDF5 creates something called a 'chunk cache' for each variable. The
27332811 The `least_significant_digit`
27342812 attributes describes the power of ten of the smallest decimal place in
27352813 the data the contains a reliable value. assigned to the `Variable`
2736 instance. If `None`, the data is not truncated. The `ndim` attribute
2814 instance. The `ndim` attribute
27372815 is the number of variable dimensions."""
27382816 # if varname specified as a path, split out group names.
27392817 varname = posixpath.normpath(varname)
27432821 group = self
27442822 else:
27452823 group = self.createGroup(dirname)
2824 # if dimensions is a single string or Dimension instance,
2825 # convert to a tuple.
2826 # This prevents a common error that occurs when
2827 # dimensions = 'lat' instead of ('lat',)
2828 if isinstance(dimensions, (str, bytes, Dimension)):
2829 dimensions = dimensions,
2830 # convert elements of dimensions tuple to Dimension
2831 # instances if they are strings.
2832 # _find_dim looks for dimension in this group, and if not
2833 # found there, looks in parent (and it's parent, etc, back to root).
2834 dimensions =\
2835 tuple(_find_dim(group,d) if isinstance(d,(str,bytes)) else d for d in dimensions)
27462836 # create variable.
27472837 group.variables[varname] = Variable(group, varname, datatype,
2748 dimensions=dimensions, zlib=zlib, complevel=complevel, shuffle=shuffle,
2838 dimensions=dimensions, compression=compression, zlib=zlib, complevel=complevel, shuffle=shuffle,
2839 szip_coding=szip_coding, szip_pixels_per_block=szip_pixels_per_block,
2840 blosc_shuffle=blosc_shuffle,
27492841 fletcher32=fletcher32, contiguous=contiguous, chunksizes=chunksizes,
27502842 endian=endian, least_significant_digit=least_significant_digit,
2751 fill_value=fill_value, chunk_cache=chunk_cache)
2843 significant_digits=significant_digits,quantize_mode=quantize_mode,fill_value=fill_value, chunk_cache=chunk_cache)
27522844 return group.variables[varname]
27532845
27542846 def renameVariable(self, oldname, newname):
34403532 raise AttributeError("size cannot be altered")
34413533
34423534 def __repr__(self):
3443 return self.__unicode__()
3444
3445 def __unicode__(self):
3535 return self.__str__()
3536
3537 def __str__(self):
34463538 if not dir(self._grp):
34473539 return 'Dimension object no longer valid'
34483540 if self.isunlimited():
35503642 truncated to this decimal place when it is assigned to the `Variable`
35513643 instance. If `None`, the data is not truncated.
35523644
3645 **`significant_digits`**: New in version 1.6.0. Describes the number of significant
3646 digits in the data the contains a reliable value. Data is
3647 truncated to retain this number of significant digits when it is assigned to the
3648 `Variable` instance. If `None`, the data is not truncated.
3649 Only available with netcdf-c >= 4.9.0,
3650 and only works with `NETCDF4` or `NETCDF4_CLASSIC` formatted files.
3651 The number of significant digits used in the quantization of variable data can be
3652 obtained using the `Variable.significant_digits` method. Default `None` -
3653 no quantization done.
3654
3655 **`quantize_mode`**: New in version 1.6.0. Controls
3656 the quantization algorithm (default 'BitGroom', 'BitRound' and
3657 'GranularBitRound' also available). The 'GranularBitRound'
3658 algorithm may result in better compression for typical geophysical datasets.
3659 Ignored if `significant_digits` not specified. If 'BitRound' is used, then
3660 `significant_digits` is interpreted as binary (not decimal) digits.
3661
35533662 **`__orthogonal_indexing__`**: Always `True`. Indicates to client code
35543663 that the object supports 'orthogonal indexing', which means that slices
35553664 that are 1d arrays or lists slice along each dimension independently. This
35673676 _iscompound, _isvlen, _isenum, _grp, _cmptype, _vltype, _enumtype,\
35683677 __orthogonal_indexing__, _has_lsd, _use_get_vars, _ncstring_attrs__
35693678
3570 def __init__(self, grp, name, datatype, dimensions=(), zlib=False,
3571 complevel=4, shuffle=True, fletcher32=False, contiguous=False,
3679 def __init__(self, grp, name, datatype, dimensions=(),
3680 compression=None, zlib=False,
3681 complevel=4, shuffle=True, szip_coding='nn', szip_pixels_per_block=8,
3682 blosc_shuffle=1,
3683 fletcher32=False, contiguous=False,
35723684 chunksizes=None, endian='native', least_significant_digit=None,
3573 fill_value=None, chunk_cache=None, **kwargs):
3574 """
3575 **`__init__(self, group, name, datatype, dimensions=(), zlib=False,
3576 complevel=4, shuffle=True, fletcher32=False, contiguous=False,
3685 significant_digits=None,quantize_mode='BitGroom',fill_value=None, chunk_cache=None, **kwargs):
3686 """
3687 **`__init__(self, group, name, datatype, dimensions=(), compression=None, zlib=False,
3688 complevel=4, shuffle=True, szip_coding='nn', szip_pixels_per_block=8,
3689 blosc_shuffle=1, fletcher32=False, contiguous=False,
35773690 chunksizes=None, endian='native',
35783691 least_significant_digit=None,fill_value=None,chunk_cache=None)`**
35793692
36023715 (for a variable-length string array). Numpy string and unicode datatypes with
36033716 length greater than one are aliases for `str`.
36043717
3605 **`dimensions`**: a tuple containing the variable's dimension names
3718 **`dimensions`**: a tuple containing the variable's Dimension instances
36063719 (defined previously with `createDimension`). Default is an empty tuple
36073720 which means the variable is a scalar (and therefore has no dimensions).
36083721
3722 **`compression`**: compression algorithm to use.
3723 Currently `zlib`,`szip`,`zstd`,`bzip2`,`blosc_lz`,`blosc_lz4`,`blosc_lz4hc`,
3724 `blosc_zlib` and `blosc_zstd` are supported.
3725 Default is `None` (no compression). All of the compressors except
3726 `zlib` and `szip` use the HDF5 plugin architecture.
3727
36093728 **`zlib`**: if `True`, data assigned to the `Variable`
3610 instance is compressed on disk. Default `False`.
3611
3612 **`complevel`**: the level of zlib compression to use (1 is the fastest,
3729 instance is compressed on disk. Default `False`. Deprecated - use
3730 `compression='zlib'` instead.
3731
3732 **`complevel`**: the level of compression to use (1 is the fastest,
36133733 but poorest compression, 9 is the slowest but best compression). Default 4.
3614 Ignored if `zlib=False`.
3734 Ignored if `compression=None` or `szip`. A value of 0 disables compression.
36153735
36163736 **`shuffle`**: if `True`, the HDF5 shuffle filter is applied
3617 to improve compression. Default `True`. Ignored if `zlib=False`.
3737 to improve zlib compression. Default `True`. Ignored unless `compression = 'zlib'`.
3738
3739 **`blosc_shuffle`**: shuffle filter inside blosc compressor (only
3740 relevant if compression kwarg set to one of the blosc compressors).
3741 Can be 0 (no blosc shuffle), 1 (bytewise shuffle) or 2 (bitwise
3742 shuffle)). Default is 1. Ignored if blosc compressor not used.
3743
3744 **`szip_coding`**: szip coding method. Can be `ec` (entropy coding)
3745 or `nn` (nearest neighbor coding). Default is `nn`.
3746 Ignored if szip compressor not used.
3747
3748 **`szip_pixels_per_block`**: Can be 4,8,16 or 32 (Default 8).
3749 Ignored if szip compressor not used.
36183750
36193751 **`fletcher32`**: if `True` (default `False`), the Fletcher32 checksum
36203752 algorithm is used for error detection.
36213753
36223754 **`contiguous`**: if `True` (default `False`), the variable data is
36233755 stored contiguously on disk. Default `False`. Setting to `True` for
3624 a variable with an unlimited dimension will trigger an error.
3756 a variable with an unlimited dimension will trigger an error. Fixed
3757 size variables (with no unlimited dimension) with no compression
3758 filters are contiguous by default.
36253759
36263760 **`chunksizes`**: Can be used to specify the HDF5 chunksizes for each
36273761 dimension of the variable. A detailed discussion of HDF chunking and I/O
36283762 performance is available
3629 [here](http://www.hdfgroup.org/HDF5/doc/H5.user/Chunking.html).
3763 [here](https://support.hdfgroup.org/HDF5/doc/Advanced/Chunking).
3764 The default chunking scheme in the netcdf-c library is discussed
3765 [here](https://www.unidata.ucar.edu/software/netcdf/documentation/NUG/netcdf_perf_chunking.html).
36303766 Basically, you want the chunk size for each dimension to match as
36313767 closely as possible the size of the data block that users will read
36323768 from the file. `chunksizes` cannot be set if `contiguous=True`.
36403776 some performance advantage to be gained by setting the endian-ness.
36413777 For netCDF 3 files (that don't use HDF5), only `endian='native'` is allowed.
36423778
3643 The `zlib, complevel, shuffle, fletcher32, contiguous` and `chunksizes`
3779 The `compression, zlib, complevel, shuffle, fletcher32, contiguous` and `chunksizes`
36443780 keywords are silently ignored for netCDF 3 files that do not use HDF5.
36453781
3646 **`least_significant_digit`**: If specified, variable data will be
3647 truncated (quantized). In conjunction with `zlib=True` this produces
3782 **`least_significant_digit`**: If this or `significant_digits` are specified,
3783 variable data will be truncated (quantized).
3784 In conjunction with `compression='zlib'` this produces
36483785 'lossy', but significantly more efficient compression. For example, if
36493786 `least_significant_digit=1`, data will be quantized using
36503787 around(scale*data)/scale, where scale = 2**bits, and bits is determined
36513788 so that a precision of 0.1 is retained (in this case bits=4). Default is
36523789 `None`, or no quantization.
36533790
3791 **`significant_digits`**: New in version 1.6.0.
3792 As described for `least_significant_digit`
3793 except the number of significant digits retained is prescribed independent
3794 of the floating point exponent. Default `None` - no quantization done.
3795
3796 **`quantize_mode`**: New in version 1.6.0. Controls
3797 the quantization algorithm (default 'BitGroom', 'BitRound' and
3798 'GranularBitRound' also available). The 'GranularBitRound'
3799 algorithm may result in better compression for typical geophysical datasets.
3800 Ignored if `significant_digts` not specified. If 'BitRound' is used, then
3801 `significant_digits` is interpreted as binary (not decimal) digits.
3802
36543803 **`fill_value`**: If specified, the default netCDF `_FillValue` (the
36553804 value that the variable gets filled with before any data is written to it)
36563805 is replaced with this value. If fill_value is set to `False`, then
36573806 the variable is not pre-filled. The default netCDF fill values can be found
36583807 in the dictionary `netCDF4.default_fillvals`.
3659
3808
36603809 **`chunk_cache`**: If specified, sets the chunk cache size for this variable.
3661 Persists as long as Dataset is open. Use `set_var_chunk_cache` to
3662 change it when Dataset is re-opened.
3810 Persists as long as Dataset is open. Use `set_var_chunk_cache` to
3811 change it when Dataset is re-opened.
36633812
36643813 ***Note***: `Variable` instances should be created using the
36653814 `Dataset.createVariable` method of a `Dataset` or
36663815 `Group` instance, not using this class directly.
36673816 """
3668 cdef int ierr, ndims, icontiguous, ideflate_level, numdims, _grpid
3817 cdef int ierr, ndims, icontiguous, icomplevel, numdims, _grpid, nsd,
3818 cdef unsigned int iblosc_complevel,iblosc_blocksize,iblosc_compressor,iblosc_shuffle
3819 cdef int iszip_coding, iszip_pixels_per_block
36693820 cdef char namstring[NC_MAX_NAME+1]
36703821 cdef char *varname
36713822 cdef nc_type xtype
36753826 cdef float preemptionp
36763827 # flag to indicate that orthogonal indexing is supported
36773828 self.__orthogonal_indexing__ = True
3678 # if complevel is set to zero, set zlib to False.
3829 # For backwards compatibility, deprecated zlib kwarg takes
3830 # precedence if compression kwarg not set.
3831 if zlib and not compression:
3832 compression = 'zlib'
3833 # if complevel is set to zero, turn off compression
36793834 if not complevel:
3680 zlib = False
3681 # if dimensions is a string, convert to a tuple
3682 # this prevents a common error that occurs when
3683 # dimensions = 'lat' instead of ('lat',)
3684 if type(dimensions) == str or type(dimensions) == bytes or type(dimensions) == unicode:
3685 dimensions = dimensions,
3835 compression = None
3836 zlib = False
3837 szip = False
3838 zstd = False
3839 bzip2 = False
3840 blosc_lz = False
3841 blosc_lz4 = False
3842 blosc_lz4hc = False
3843 #blosc_snappy = False
3844 blosc_zlib = False
3845 blosc_zstd = False
3846 if compression == 'zlib':
3847 zlib = True
3848 elif compression == 'szip':
3849 szip = True
3850 elif compression == 'zstd':
3851 zstd = True
3852 elif compression == 'bzip2':
3853 bzip2 = True
3854 elif compression == 'blosc_lz':
3855 blosc_lz = True
3856 elif compression == 'blosc_lz4':
3857 blosc_lz4 = True
3858 elif compression == 'blosc_lz4hc':
3859 blosc_lz4hc = True
3860 #elif compression == 'blosc_snappy':
3861 # blosc_snappy = True
3862 elif compression == 'blosc_zlib':
3863 blosc_zlib = True
3864 elif compression == 'blosc_zstd':
3865 blosc_zstd = True
3866 elif not compression:
3867 compression = None # if compression evaluates to False, set to None.
3868 pass
3869 else:
3870 raise ValueError("Unsupported value for compression kwarg")
36863871 self._grpid = grp._grpid
36873872 # make a weakref to group to avoid circular ref (issue 218)
36883873 # keep strong reference the default behaviour (issue 251)
37663951 ndims = len(dimensions)
37673952 # find dimension ids.
37683953 if ndims:
3769 dims = []
37703954 dimids = <int *>malloc(sizeof(int) * ndims)
37713955 for n from 0 <= n < ndims:
3772 dimname = dimensions[n]
3773 # look for dimension in this group, and if not
3774 # found there, look in parent (and it's parent, etc, back to root).
3775 dim = _find_dim(grp, dimname)
3776 if dim is None:
3777 raise KeyError("dimension %s not defined in group %s or any group in it's family tree" % (dimname, grp.path))
3778 dimids[n] = dim._dimid
3779 dims.append(dim)
3956 dimids[n] = dimensions[n]._dimid
37803957 # go into define mode if it's a netCDF 3 compatible
37813958 # file format. Be careful to exit define mode before
37823959 # any exceptions are raised.
38053982 if ierr != NC_NOERR:
38063983 if grp.data_model != 'NETCDF4': grp._enddef()
38073984 _ensure_nc_success(ierr)
3808 # set zlib, shuffle, chunking, fletcher32 and endian
3985 # set compression, shuffle, chunking, fletcher32 and endian
38093986 # variable settings.
38103987 # don't bother for NETCDF3* formats.
3811 # for NETCDF3* formats, the zlib,shuffle,chunking,
3812 # and fletcher32 are silently ignored. Only
3988 # for NETCDF3* formats, the comopression,zlib,shuffle,chunking,
3989 # and fletcher32 flags are silently ignored. Only
38133990 # endian='native' allowed for NETCDF3.
38143991 if grp.data_model in ['NETCDF4','NETCDF4_CLASSIC']:
3815 # set zlib and shuffle parameters.
3816 if zlib and ndims: # don't bother for scalar variable
3817 ideflate_level = complevel
3818 if shuffle:
3819 ierr = nc_def_var_deflate(self._grpid, self._varid, 1, 1, ideflate_level)
3820 else:
3821 ierr = nc_def_var_deflate(self._grpid, self._varid, 0, 1, ideflate_level)
3822 if ierr != NC_NOERR:
3823 if grp.data_model != 'NETCDF4': grp._enddef()
3824 _ensure_nc_success(ierr)
3992 # set compression and shuffle parameters.
3993 if compression is not None and ndims: # don't bother for scalar variable
3994 if zlib:
3995 icomplevel = complevel
3996 if shuffle:
3997 ierr = nc_def_var_deflate(self._grpid, self._varid, 1, 1, icomplevel)
3998 else:
3999 ierr = nc_def_var_deflate(self._grpid, self._varid, 0, 1, icomplevel)
4000 if ierr != NC_NOERR:
4001 if grp.data_model != 'NETCDF4': grp._enddef()
4002 _ensure_nc_success(ierr)
4003 if szip:
4004 IF HAS_SZIP_SUPPORT:
4005 try:
4006 iszip_coding = _szip_dict[szip_coding]
4007 except KeyError:
4008 msg="unknown szip coding ('ec' or 'nn' supported)"
4009 raise ValueError(msg)
4010 iszip_pixels_per_block = szip_pixels_per_block
4011 ierr = nc_def_var_szip(self._grpid, self._varid, iszip_coding, iszip_pixels_per_block)
4012 if ierr != NC_NOERR:
4013 if grp.data_model != 'NETCDF4': grp._enddef()
4014 _ensure_nc_success(ierr)
4015 ELSE:
4016 msg = """
4017 compression='szip' only works if linked version of hdf5 has szip functionality enabled"""
4018 raise ValueError(msg)
4019 if zstd:
4020 IF HAS_ZSTANDARD_SUPPORT:
4021 icomplevel = complevel
4022 ierr = nc_def_var_zstandard(self._grpid, self._varid, icomplevel)
4023 if ierr != NC_NOERR:
4024 if grp.data_model != 'NETCDF4': grp._enddef()
4025 _ensure_nc_success(ierr)
4026 ELSE:
4027 msg = """
4028 compression='zstd' only works with netcdf-c >= 4.9.0. To enable, install Cython, make sure you have
4029 version 4.9.0 or higher netcdf-c with zstandard support, and rebuild netcdf4-python."""
4030 raise ValueError(msg)
4031 if bzip2:
4032 IF HAS_BZIP2_SUPPORT:
4033 icomplevel = complevel
4034 ierr = nc_def_var_bzip2(self._grpid, self._varid, icomplevel)
4035 if ierr != NC_NOERR:
4036 if grp.data_model != 'NETCDF4': grp._enddef()
4037 _ensure_nc_success(ierr)
4038 ELSE:
4039 msg = """
4040 compression='bzip2' only works with netcdf-c >= 4.9.0. To enable, install Cython, make sure you have
4041 version 4.9.0 or higher netcdf-c with bzip2 support, and rebuild netcdf4-python."""
4042 raise ValueError(msg)
4043 if blosc_zstd or blosc_lz or blosc_lz4 or blosc_lz4hc or blosc_zlib:
4044 IF HAS_BLOSC_SUPPORT:
4045 iblosc_compressor = _blosc_dict[compression]
4046 iblosc_shuffle = blosc_shuffle
4047 iblosc_blocksize = 0 # not currently used by c lib
4048 iblosc_complevel = complevel
4049 ierr = nc_def_var_blosc(self._grpid, self._varid,\
4050 iblosc_compressor,\
4051 iblosc_complevel,iblosc_blocksize,\
4052 iblosc_shuffle)
4053 if ierr != NC_NOERR:
4054 if grp.data_model != 'NETCDF4': grp._enddef()
4055 _ensure_nc_success(ierr)
4056 ELSE:
4057 msg = """
4058 compression='blosc_*' only works with netcdf-c >= 4.9.0. To enable, install Cython, make sure you have
4059 version 4.9.0 or higher netcdf-c with blosc support, and rebuild netcdf4-python."""
4060 raise ValueError(msg)
38254061 # set checksum.
38264062 if fletcher32 and ndims: # don't bother for scalar variable
38274063 ierr = nc_def_var_fletcher32(self._grpid, self._varid, 1)
38444080 raise ValueError('chunksizes must be a sequence with the same length as dimensions')
38454081 chunksizesp = <size_t *>malloc(sizeof(size_t) * ndims)
38464082 for n from 0 <= n < ndims:
3847 if not dims[n].isunlimited() and \
3848 chunksizes[n] > dims[n].size:
4083 if not dimensions[n].isunlimited() and \
4084 chunksizes[n] > dimensions[n].size:
38494085 msg = 'chunksize cannot exceed dimension size'
38504086 raise ValueError(msg)
38514087 chunksizesp[n] = chunksizes[n]
38644100 pass # this is the default format.
38654101 else:
38664102 raise ValueError("'endian' keyword argument must be 'little','big' or 'native', got '%s'" % endian)
4103 # set quantization
4104 IF HAS_QUANTIZATION_SUPPORT:
4105 if significant_digits is not None:
4106 nsd = significant_digits
4107 if quantize_mode == 'BitGroom':
4108 ierr = nc_def_var_quantize(self._grpid,
4109 self._varid, NC_QUANTIZE_BITGROOM, nsd)
4110 elif quantize_mode == 'GranularBitRound':
4111 ierr = nc_def_var_quantize(self._grpid,
4112 self._varid, NC_QUANTIZE_GRANULARBR, nsd)
4113 elif quantize_mode == 'BitRound':
4114 ierr = nc_def_var_quantize(self._grpid,
4115 self._varid, NC_QUANTIZE_BITROUND, nsd)
4116 else:
4117 raise ValueError("'quantize_mode' keyword argument must be 'BitGroom','GranularBitRound' or 'BitRound', got '%s'" % quantize_mode)
4118
4119 ELSE:
4120 if significant_digits is not None:
4121 msg = """
4122 significant_digits kwarg only works with netcdf-c >= 4.9.0. To enable, install Cython, make sure you have
4123 version 4.9.0 or higher netcdf-c, and rebuild netcdf4-python. Otherwise, use least_significant_digit
4124 kwarg for quantization."""
4125 raise ValueError(msg)
38674126 if ierr != NC_NOERR:
38684127 if grp.data_model != 'NETCDF4': grp._enddef()
38694128 _ensure_nc_success(ierr)
39054164 if grp.data_model != 'NETCDF4': grp._enddef()
39064165 # count how many unlimited dimensions there are.
39074166 self._nunlimdim = 0
3908 for dimname in dimensions:
3909 # look in current group, and parents for dim.
3910 dim = _find_dim(self._grp, dimname)
4167 for dim in dimensions:
39114168 if dim.isunlimited(): self._nunlimdim = self._nunlimdim + 1
39124169 # set ndim attribute (number of dimensions).
39134170 with nogil:
39464203 return self[...]
39474204
39484205 def __repr__(self):
3949 return self.__unicode__()
3950
3951 def __unicode__(self):
4206 return self.__str__()
4207
4208 def __str__(self):
39524209 cdef int ierr, no_fill
39534210 if not dir(self._grp):
39544211 return 'Variable object no longer valid'
41824439 **`filters(self)`**
41834440
41844441 return dictionary containing HDF5 filter parameters."""
4185 cdef int ierr,ideflate,ishuffle,ideflate_level,ifletcher32
4186 filtdict = {'zlib':False,'shuffle':False,'complevel':0,'fletcher32':False}
4442 cdef int ierr,ideflate,ishuffle,icomplevel,icomplevel_zstd,icomplevel_bzip2,ifletcher32
4443 cdef int izstd=0
4444 cdef int ibzip2=0
4445 cdef int iblosc=0
4446 cdef int iszip=0
4447 cdef unsigned int iblosc_complevel,iblosc_blocksize,iblosc_compressor,iblosc_shuffle
4448 cdef int iszip_coding, iszip_pixels_per_block
4449 filtdict = {'zlib':False,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':False,'complevel':0,'fletcher32':False}
41874450 if self._grp.data_model not in ['NETCDF4_CLASSIC','NETCDF4']: return
41884451 with nogil:
4189 ierr = nc_inq_var_deflate(self._grpid, self._varid, &ishuffle, &ideflate, &ideflate_level)
4452 ierr = nc_inq_var_deflate(self._grpid, self._varid, &ishuffle, &ideflate, &icomplevel)
41904453 _ensure_nc_success(ierr)
41914454 with nogil:
41924455 ierr = nc_inq_var_fletcher32(self._grpid, self._varid, &ifletcher32)
41934456 _ensure_nc_success(ierr)
4457 IF HAS_ZSTANDARD_SUPPORT:
4458 ierr = nc_inq_var_zstandard(self._grpid, self._varid, &izstd,\
4459 &icomplevel_zstd)
4460 if ierr != 0: izstd=0
4461 # _ensure_nc_success(ierr)
4462 IF HAS_BZIP2_SUPPORT:
4463 ierr = nc_inq_var_bzip2(self._grpid, self._varid, &ibzip2,\
4464 &icomplevel_bzip2)
4465 if ierr != 0: ibzip2=0
4466 #_ensure_nc_success(ierr)
4467 IF HAS_BLOSC_SUPPORT:
4468 ierr = nc_inq_var_blosc(self._grpid, self._varid, &iblosc,\
4469 &iblosc_compressor,&iblosc_complevel,&iblosc_blocksize,&iblosc_shuffle)
4470 if ierr != 0: iblosc=0
4471 #_ensure_nc_success(ierr)
4472 IF HAS_SZIP_SUPPORT:
4473 ierr = nc_inq_var_szip(self._grpid, self._varid, &iszip_coding,\
4474 &iszip_pixels_per_block)
4475 if ierr != 0:
4476 iszip=0
4477 else:
4478 if iszip_coding:
4479 iszip=1
4480 else:
4481 iszip=0
4482 #_ensure_nc_success(ierr)
41944483 if ideflate:
41954484 filtdict['zlib']=True
4196 filtdict['complevel']=ideflate_level
4485 filtdict['complevel']=icomplevel
4486 if izstd:
4487 filtdict['zstd']=True
4488 filtdict['complevel']=icomplevel_zstd
4489 if ibzip2:
4490 filtdict['bzip2']=True
4491 filtdict['complevel']=icomplevel_bzip2
4492 if iblosc:
4493 blosc_compressor = iblosc_compressor
4494 filtdict['blosc']={'compressor':_blosc_dict_inv[blosc_compressor],'shuffle':iblosc_shuffle}
4495 filtdict['complevel']=iblosc_complevel
4496 if iszip:
4497 szip_coding = iszip_coding
4498 filtdict['szip']={'coding':_szip_dict_inv[szip_coding],'pixels_per_block':iszip_pixels_per_block}
41974499 if ishuffle:
41984500 filtdict['shuffle']=True
41994501 if ifletcher32:
42004502 filtdict['fletcher32']=True
42014503 return filtdict
4504
4505 def quantization(self):
4506 """
4507 **`quantization(self)`**
4508
4509 return number of significant digits and the algorithm used in quantization.
4510 Returns None if quantization not active.
4511 """
4512 IF HAS_QUANTIZATION_SUPPORT:
4513 cdef int ierr, nsd, quantize_mode
4514 if self._grp.data_model not in ['NETCDF4_CLASSIC','NETCDF4']:
4515 return None
4516 else:
4517 with nogil:
4518 ierr = nc_inq_var_quantize(self._grpid, self._varid, &quantize_mode, &nsd)
4519 _ensure_nc_success(ierr)
4520 if quantize_mode == NC_NOQUANTIZE:
4521 return None
4522 else:
4523 if quantize_mode == NC_QUANTIZE_GRANULARBR:
4524 sig_digits = nsd
4525 quant_mode = 'GranularBitRound'
4526 elif quantize_mode == NC_QUANTIZE_BITROUND:
4527 sig_digits = nsd # interpreted as bits, not decimal
4528 quant_mode = 'BitRound'
4529 else:
4530 sig_digits = nsd
4531 quant_mode = 'BitGroom'
4532 return sig_digits, quant_mode
4533 ELSE:
4534 return None
42024535
42034536 def endian(self):
42044537 """
47935126 def _check_safecast(self, attname):
47945127 # check to see that variable attribute exists
47955128 # can can be safely cast to variable data type.
5129 msg="""WARNING: %s not used since it
5130 cannot be safely cast to variable data type""" % attname
47965131 if hasattr(self, attname):
47975132 att = numpy.array(self.getncattr(attname))
47985133 else:
47995134 return False
4800 atta = numpy.array(att, self.dtype)
5135 try:
5136 atta = numpy.array(att, self.dtype)
5137 except ValueError:
5138 is_safe = False
5139 warnings.warn(msg)
5140 return is_safe
48015141 is_safe = _safecast(att,atta)
48025142 if not is_safe:
4803 msg="""WARNING: %s not used since it
4804 cannot be safely cast to variable data type""" % attname
48055143 warnings.warn(msg)
48065144 return is_safe
48075145
55415879 self.name = dtype_name
55425880
55435881 def __repr__(self):
5544 return self.__unicode__()
5545
5546 def __unicode__(self):
5882 return self.__str__()
5883
5884 def __str__(self):
55475885 return "%r: name = '%s', numpy dtype = %s" %\
55485886 (type(self), self.name, self.dtype)
55495887
58236161 self.name = dtype_name
58246162
58256163 def __repr__(self):
5826 return self.__unicode__()
5827
5828 def __unicode__(self):
6164 return self.__str__()
6165
6166 def __str__(self):
58296167 if self.dtype == str:
58306168 return '%r: string type' % (type(self),)
58316169 else:
59336271 self.enum_dict = enum_dict
59346272
59356273 def __repr__(self):
5936 return self.__unicode__()
5937
5938 def __unicode__(self):
6274 return self.__str__()
6275
6276 def __str__(self):
59396277 return "%r: name = '%s', numpy dtype = %s, fields/values =%s" %\
59406278 (type(self), self.name, self.dtype, self.enum_dict)
59416279
64236761 def __getattr__(self,name):
64246762 if name == 'shape': return self._shape()
64256763 if name == 'ndim': return len(self._shape())
6764 if name == 'name': return self._name
64266765 try:
64276766 return self.__dict__[name]
64286767 except:
4444 group = group.parent
4545 except:
4646 raise ValueError("cannot find dimension %s in this group or parent groups" % dimname)
47 return dim
47 if dim is None:
48 raise KeyError("dimension %s not defined in group %s or any group in it's family tree" % (dimname, grp.path))
49 else:
50 return dim
4851
4952 def _walk_grps(topgrp):
5053 """Iterate through all (sub-) groups of topgrp, similar to os.walktree.
Binary diff not shown
00 import glob, os, sys, unittest, struct
11 from netCDF4 import getlibversion,__hdf5libversion__,__netcdf4libversion__,__version__
22 from netCDF4 import __has_cdf5_format__, __has_nc_inq_path__, __has_nc_create_mem__, \
3 __has_parallel4_support__, __has_pnetcdf_support__
3 __has_parallel4_support__, __has_pnetcdf_support__, \
4 __has_zstandard_support__, __has_bzip2_support__, \
5 __has_blosc_support__,__has_quantization_support__,\
6 __has_szip_support__
47
58 # can also just run
69 # python -m unittest discover . 'tst*py'
1922 if not __has_cdf5_format__ or struct.calcsize("P") < 8:
2023 test_files.remove('tst_cdf5.py')
2124 sys.stdout.write('not running tst_cdf5.py ...\n')
25 if not __has_quantization_support__:
26 test_files.remove('tst_compression_quant.py')
27 sys.stdout.write('not running tst_compression_quant.py ...\n')
28 if not __has_zstandard_support__ or os.getenv('NO_PLUGINS'):
29 test_files.remove('tst_compression_zstd.py')
30 sys.stdout.write('not running tst_compression_zstd.py ...\n')
31 if not __has_bzip2_support__ or os.getenv('NO_PLUGINS'):
32 test_files.remove('tst_compression_bzip2.py')
33 sys.stdout.write('not running tst_compression_bzip2.py ...\n')
34 if not __has_blosc_support__ or os.getenv('NO_PLUGINS'):
35 test_files.remove('tst_compression_blosc.py')
36 sys.stdout.write('not running tst_compression_blosc.py ...\n')
37 if not __has_szip_support__:
38 test_files.remove('tst_compression_szip.py')
39 sys.stdout.write('not running tst_compression_szip.py ...\n')
2240
2341 # Don't run tests that require network connectivity
2442 if os.getenv('NO_NET'):
1919 foo = file.createVariable('data',\
2020 dtype,('n'),zlib=zlib,least_significant_digit=least_significant_digit,\
2121 shuffle=shuffle,contiguous=contiguous,complevel=complevel,fletcher32=fletcher32,chunksizes=chunksizes)
22 # use compression kwarg instead of deprecated zlib
23 if zlib:
24 compression='zlib'
25 else:
26 compression=None
27 # anything that evaluates to False is same as None
28 #compression=False
29 #compression=''
30 #compression=0
31 #compression='gzip' # should fail
32 foo2 = file.createVariable('data2',\
33 dtype,('n'),compression=compression,least_significant_digit=least_significant_digit,\
34 shuffle=shuffle,contiguous=contiguous,complevel=complevel,fletcher32=fletcher32,chunksizes=chunksizes)
2235 foo[:] = data
36 foo2[:] = data
2337 file.close()
2438 file = Dataset(filename)
2539 data = file.variables['data'][:]
40 data2 = file.variables['data2'][:]
2641 file.close()
2742
2843 def write_netcdf2(filename,zlib,least_significant_digit,data,dtype='f8',shuffle=False,contiguous=False,\
6782 def runTest(self):
6883 """testing zlib and shuffle compression filters"""
6984 uncompressed_size = os.stat(self.files[0]).st_size
85 # check uncompressed data
86 f = Dataset(self.files[0])
87 size = os.stat(self.files[0]).st_size
88 assert_almost_equal(array,f.variables['data'][:])
89 assert_almost_equal(array,f.variables['data2'][:])
90 assert f.variables['data'].filters() ==\
91 {'zlib':False,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':False,'complevel':0,'fletcher32':False}
92 assert f.variables['data2'].filters() ==\
93 {'zlib':False,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':False,'complevel':0,'fletcher32':False}
94 assert_almost_equal(size,uncompressed_size)
95 f.close()
7096 # check compressed data.
7197 f = Dataset(self.files[1])
7298 size = os.stat(self.files[1]).st_size
7399 assert_almost_equal(array,f.variables['data'][:])
74 assert f.variables['data'].filters() == {'zlib':True,'shuffle':False,'complevel':6,'fletcher32':False}
100 assert_almost_equal(array,f.variables['data2'][:])
101 assert f.variables['data'].filters() ==\
102 {'zlib':True,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':False,'complevel':6,'fletcher32':False}
103 assert f.variables['data2'].filters() ==\
104 {'zlib':True,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':False,'complevel':6,'fletcher32':False}
75105 assert(size < 0.95*uncompressed_size)
76106 f.close()
77107 # check compression with shuffle
78108 f = Dataset(self.files[2])
79109 size = os.stat(self.files[2]).st_size
80110 assert_almost_equal(array,f.variables['data'][:])
81 assert f.variables['data'].filters() == {'zlib':True,'shuffle':True,'complevel':6,'fletcher32':False}
111 assert_almost_equal(array,f.variables['data2'][:])
112 assert f.variables['data'].filters() ==\
113 {'zlib':True,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':True,'complevel':6,'fletcher32':False}
114 assert f.variables['data2'].filters() ==\
115 {'zlib':True,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':True,'complevel':6,'fletcher32':False}
82116 assert(size < 0.85*uncompressed_size)
83117 f.close()
84118 # check lossy compression without shuffle
86120 size = os.stat(self.files[3]).st_size
87121 checkarray = _quantize(array,lsd)
88122 assert_almost_equal(checkarray,f.variables['data'][:])
123 assert_almost_equal(checkarray,f.variables['data2'][:])
89124 assert(size < 0.27*uncompressed_size)
90125 f.close()
91126 # check lossy compression with shuffle
92127 f = Dataset(self.files[4])
93128 size = os.stat(self.files[4]).st_size
94129 assert_almost_equal(checkarray,f.variables['data'][:])
130 assert_almost_equal(checkarray,f.variables['data2'][:])
95131 assert(size < 0.20*uncompressed_size)
96132 size_save = size
97133 f.close()
99135 f = Dataset(self.files[5])
100136 size = os.stat(self.files[5]).st_size
101137 assert_almost_equal(checkarray,f.variables['data'][:])
102 assert f.variables['data'].filters() == {'zlib':True,'shuffle':True,'complevel':6,'fletcher32':True}
138 assert_almost_equal(checkarray,f.variables['data2'][:])
139 assert f.variables['data'].filters() ==\
140 {'zlib':True,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':True,'complevel':6,'fletcher32':True}
141 assert f.variables['data2'].filters() ==\
142 {'zlib':True,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':True,'complevel':6,'fletcher32':True}
103143 assert(size < 0.20*uncompressed_size)
104144 # should be slightly larger than without fletcher32
105145 assert(size > size_save)
108148 f = Dataset(self.files[6])
109149 checkarray2 = _quantize(array2,lsd)
110150 assert_almost_equal(checkarray2,f.variables['data2'][:])
111 assert f.variables['data2'].filters() == {'zlib':True,'shuffle':True,'complevel':6,'fletcher32':True}
151 assert f.variables['data2'].filters() ==\
152 {'zlib':True,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':True,'complevel':6,'fletcher32':True}
112153 assert f.variables['data2'].chunking() == [chunk1,chunk2]
113154 f.close()
114155
0 from numpy.random.mtrand import uniform
1 from netCDF4 import Dataset
2 from numpy.testing import assert_almost_equal
3 import os, tempfile, unittest
4
5 ndim = 100000
6 iblosc_shuffle=2
7 iblosc_complevel=4
8 filename = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
9 datarr = uniform(size=(ndim,))
10
11 def write_netcdf(filename,dtype='f8',blosc_shuffle=1,complevel=6):
12 nc = Dataset(filename,'w')
13 nc.createDimension('n', ndim)
14 foo = nc.createVariable('data',\
15 dtype,('n'),compression=None)
16 foo_lz = nc.createVariable('data_lz',\
17 dtype,('n'),compression='blosc_lz',blosc_shuffle=blosc_shuffle,complevel=complevel)
18 foo_lz4 = nc.createVariable('data_lz4',\
19 dtype,('n'),compression='blosc_lz4',blosc_shuffle=blosc_shuffle,complevel=complevel)
20 foo_lz4hc = nc.createVariable('data_lz4hc',\
21 dtype,('n'),compression='blosc_lz4hc',blosc_shuffle=blosc_shuffle,complevel=complevel)
22 foo_zlib = nc.createVariable('data_zlib',\
23 dtype,('n'),compression='blosc_zlib',blosc_shuffle=blosc_shuffle,complevel=complevel)
24 foo_zstd = nc.createVariable('data_zstd',\
25 dtype,('n'),compression='blosc_zstd',blosc_shuffle=blosc_shuffle,complevel=complevel)
26 foo_lz[:] = datarr
27 foo_lz4[:] = datarr
28 foo_lz4hc[:] = datarr
29 foo_zlib[:] = datarr
30 foo_zstd[:] = datarr
31 nc.close()
32
33 class CompressionTestCase(unittest.TestCase):
34
35 def setUp(self):
36 self.filename = filename
37 write_netcdf(self.filename,complevel=iblosc_complevel,blosc_shuffle=iblosc_shuffle)
38
39 def tearDown(self):
40 # Remove the temporary files
41 os.remove(self.filename)
42
43 def runTest(self):
44 f = Dataset(self.filename)
45 assert_almost_equal(datarr,f.variables['data'][:])
46 assert f.variables['data'].filters() ==\
47 {'zlib':False,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':False,'complevel':0,'fletcher32':False}
48 assert_almost_equal(datarr,f.variables['data_lz'][:])
49 dtest = {'zlib': False, 'szip':False, 'zstd': False, 'bzip2': False, 'blosc':
50 {'compressor': 'blosc_lz', 'shuffle': iblosc_shuffle},
51 'shuffle': False, 'complevel': iblosc_complevel, 'fletcher32': False}
52 assert f.variables['data_lz'].filters() == dtest
53 assert_almost_equal(datarr,f.variables['data_lz4'][:])
54 dtest = {'zlib': False, 'szip':False, 'zstd': False, 'bzip2': False, 'blosc':
55 {'compressor': 'blosc_lz4', 'shuffle': iblosc_shuffle},
56 'shuffle': False, 'complevel': iblosc_complevel, 'fletcher32': False}
57 assert f.variables['data_lz4'].filters() == dtest
58 assert_almost_equal(datarr,f.variables['data_lz4hc'][:])
59 dtest = {'zlib': False, 'szip':False, 'zstd': False, 'bzip2': False, 'blosc':
60 {'compressor': 'blosc_lz4hc', 'shuffle': iblosc_shuffle},
61 'shuffle': False, 'complevel': iblosc_complevel, 'fletcher32': False}
62 assert f.variables['data_lz4hc'].filters() == dtest
63 assert_almost_equal(datarr,f.variables['data_zlib'][:])
64 dtest = {'zlib': False, 'szip':False, 'zstd': False, 'bzip2': False, 'blosc':
65 {'compressor': 'blosc_zlib', 'shuffle': iblosc_shuffle},
66 'shuffle': False, 'complevel': iblosc_complevel, 'fletcher32': False}
67 assert f.variables['data_zlib'].filters() == dtest
68 assert_almost_equal(datarr,f.variables['data_zstd'][:])
69 dtest = {'zlib': False, 'szip':False, 'zstd': False, 'bzip2': False, 'blosc':
70 {'compressor': 'blosc_zstd', 'shuffle': iblosc_shuffle},
71 'shuffle': False, 'complevel': iblosc_complevel, 'fletcher32': False}
72 assert f.variables['data_zstd'].filters() == dtest
73 f.close()
74
75 if __name__ == '__main__':
76 unittest.main()
0 from numpy.random.mtrand import uniform
1 from netCDF4 import Dataset
2 from numpy.testing import assert_almost_equal
3 import os, tempfile, unittest
4
5 ndim = 100000
6 filename1 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
7 filename2 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
8 array = uniform(size=(ndim,))
9
10 def write_netcdf(filename,dtype='f8',complevel=6):
11 nc = Dataset(filename,'w')
12 nc.createDimension('n', ndim)
13 foo = nc.createVariable('data',\
14 dtype,('n'),compression='bzip2',complevel=complevel)
15 foo[:] = array
16 nc.close()
17
18 class CompressionTestCase(unittest.TestCase):
19
20 def setUp(self):
21 self.filename1 = filename1
22 self.filename2 = filename2
23 write_netcdf(self.filename1,complevel=0) # no compression
24 write_netcdf(self.filename2,complevel=4) # with compression
25
26 def tearDown(self):
27 # Remove the temporary files
28 os.remove(self.filename1)
29 os.remove(self.filename2)
30
31 def runTest(self):
32 uncompressed_size = os.stat(self.filename1).st_size
33 # check uncompressed data
34 f = Dataset(self.filename1)
35 size = os.stat(self.filename1).st_size
36 assert_almost_equal(array,f.variables['data'][:])
37 assert f.variables['data'].filters() ==\
38 {'zlib':False,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':False,'complevel':0,'fletcher32':False}
39 assert_almost_equal(size,uncompressed_size)
40 f.close()
41 # check compressed data.
42 f = Dataset(self.filename2)
43 size = os.stat(self.filename2).st_size
44 assert_almost_equal(array,f.variables['data'][:])
45 assert f.variables['data'].filters() ==\
46 {'zlib':False,'szip':False,'zstd':False,'bzip2':True,'blosc':False,'shuffle':False,'complevel':4,'fletcher32':False}
47 assert(size < 0.96*uncompressed_size)
48 f.close()
49
50 if __name__ == '__main__':
51 unittest.main()
0 from numpy.random.mtrand import uniform
1 from netCDF4 import Dataset
2 from numpy.testing import assert_almost_equal
3 import numpy as np
4 import os, tempfile, unittest
5
6 ndim = 100000
7 nfiles = 7
8 files = [tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name for nfile in range(nfiles)]
9 data_array = uniform(size=(ndim,))
10 nsd = 3
11 nsb = 10 # for BitRound, use significant bits (~3.32 sig digits)
12 complevel = 6
13
14 def write_netcdf(filename,zlib,significant_digits,data,dtype='f8',shuffle=False,\
15 complevel=6,quantize_mode="BitGroom"):
16 file = Dataset(filename,'w')
17 file.createDimension('n', ndim)
18 foo = file.createVariable('data',\
19 dtype,('n'),zlib=zlib,significant_digits=significant_digits,\
20 shuffle=shuffle,complevel=complevel,quantize_mode=quantize_mode)
21 foo[:] = data
22 file.close()
23 file = Dataset(filename)
24 data = file.variables['data'][:]
25 file.close()
26
27 class CompressionTestCase(unittest.TestCase):
28
29 def setUp(self):
30 self.files = files
31 # no compression
32 write_netcdf(self.files[0],False,None,data_array)
33 # compressed, lossless, no shuffle.
34 write_netcdf(self.files[1],True,None,data_array)
35 # compressed, lossless, with shuffle.
36 write_netcdf(self.files[2],True,None,data_array,shuffle=True)
37 # compressed, lossy, no shuffle.
38 write_netcdf(self.files[3],True,nsd,data_array)
39 # compressed, lossy, with shuffle.
40 write_netcdf(self.files[4],True,nsd,data_array,shuffle=True)
41 # compressed, lossy, with shuffle, and alternate quantization.
42 write_netcdf(self.files[5],True,nsd,data_array,quantize_mode='GranularBitRound',shuffle=True)
43 # compressed, lossy, with shuffle, and alternate quantization.
44 write_netcdf(self.files[6],True,nsb,data_array,quantize_mode='BitRound',shuffle=True)
45
46 def tearDown(self):
47 # Remove the temporary files
48 for file in self.files:
49 os.remove(file)
50
51 def runTest(self):
52 """testing zlib and shuffle compression filters"""
53 uncompressed_size = os.stat(self.files[0]).st_size
54 #print('uncompressed size = ',uncompressed_size)
55 # check compressed data.
56 f = Dataset(self.files[1])
57 size = os.stat(self.files[1]).st_size
58 #print('compressed lossless no shuffle = ',size)
59 assert_almost_equal(data_array,f.variables['data'][:])
60 assert f.variables['data'].filters() ==\
61 {'zlib':True,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':False,'complevel':complevel,'fletcher32':False}
62 assert(size < 0.95*uncompressed_size)
63 f.close()
64 # check compression with shuffle
65 f = Dataset(self.files[2])
66 size = os.stat(self.files[2]).st_size
67 #print('compressed lossless with shuffle ',size)
68 assert_almost_equal(data_array,f.variables['data'][:])
69 assert f.variables['data'].filters() ==\
70 {'zlib':True,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':True,'complevel':complevel,'fletcher32':False}
71 assert(size < 0.85*uncompressed_size)
72 f.close()
73 # check lossy compression without shuffle
74 f = Dataset(self.files[3])
75 size = os.stat(self.files[3]).st_size
76 errmax = (np.abs(data_array-f.variables['data'][:])).max()
77 #print('compressed lossy no shuffle = ',size,' max err = ',errmax)
78 assert(f.variables['data'].quantization() == (nsd,'BitGroom'))
79 assert(errmax < 1.e-3)
80 assert(size < 0.35*uncompressed_size)
81 f.close()
82 # check lossy compression with shuffle
83 f = Dataset(self.files[4])
84 size = os.stat(self.files[4]).st_size
85 errmax = (np.abs(data_array-f.variables['data'][:])).max()
86 print('compressed lossy with shuffle and standard quantization = ',size,' max err = ',errmax)
87 assert(f.variables['data'].quantization() == (nsd,'BitGroom'))
88 assert(errmax < 1.e-3)
89 assert(size < 0.24*uncompressed_size)
90 f.close()
91 # check lossy compression with shuffle and alternate quantization
92 f = Dataset(self.files[5])
93 size = os.stat(self.files[5]).st_size
94 errmax = (np.abs(data_array-f.variables['data'][:])).max()
95 print('compressed lossy with shuffle and alternate quantization = ',size,' max err = ',errmax)
96 assert(f.variables['data'].quantization() == (nsd,'GranularBitRound'))
97 assert(errmax < 1.e-3)
98 assert(size < 0.24*uncompressed_size)
99 f.close()
100 # check lossy compression with shuffle and alternate quantization
101 f = Dataset(self.files[6])
102 size = os.stat(self.files[6]).st_size
103 errmax = (np.abs(data_array-f.variables['data'][:])).max()
104 print('compressed lossy with shuffle and alternate quantization = ',size,' max err = ',errmax)
105 assert(f.variables['data'].quantization() == (nsb,'BitRound'))
106 assert(errmax < 1.e-3)
107 assert(size < 0.24*uncompressed_size)
108 f.close()
109
110 if __name__ == '__main__':
111 unittest.main()
0 from numpy.random.mtrand import uniform
1 from netCDF4 import Dataset
2 from numpy.testing import assert_almost_equal
3 import os, tempfile, unittest
4
5 ndim = 100000
6 filename = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
7 datarr = uniform(size=(ndim,))
8
9 def write_netcdf(filename,dtype='f8'):
10 nc = Dataset(filename,'w')
11 nc.createDimension('n', ndim)
12 foo = nc.createVariable('data',\
13 dtype,('n'),compression=None)
14 foo_szip = nc.createVariable('data_szip',\
15 dtype,('n'),compression='szip',szip_coding='ec',szip_pixels_per_block=32)
16 foo[:] = datarr
17 foo_szip[:] = datarr
18 nc.close()
19
20 class CompressionTestCase(unittest.TestCase):
21
22 def setUp(self):
23 self.filename = filename
24 write_netcdf(self.filename)
25
26 def tearDown(self):
27 # Remove the temporary files
28 os.remove(self.filename)
29
30 def runTest(self):
31 f = Dataset(self.filename)
32 assert_almost_equal(datarr,f.variables['data'][:])
33 assert f.variables['data'].filters() ==\
34 {'zlib':False,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':False,'complevel':0,'fletcher32':False}
35 assert_almost_equal(datarr,f.variables['data_szip'][:])
36 dtest = {'zlib': False, 'szip': {'coding': 'ec', 'pixels_per_block': 32}, 'zstd': False, 'bzip2': False, 'blosc': False, 'shuffle': False, 'complevel': 0, 'fletcher32': False}
37 assert f.variables['data_szip'].filters() == dtest
38 f.close()
39
40 if __name__ == '__main__':
41 unittest.main()
0 from numpy.random.mtrand import uniform
1 from netCDF4 import Dataset
2 from numpy.testing import assert_almost_equal
3 import os, tempfile, unittest
4
5 ndim = 100000
6 filename1 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
7 filename2 = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
8 array = uniform(size=(ndim,))
9
10 def write_netcdf(filename,dtype='f8',complevel=6):
11 nc = Dataset(filename,'w')
12 nc.createDimension('n', ndim)
13 foo = nc.createVariable('data',\
14 dtype,('n'),compression='zstd',complevel=complevel)
15 foo[:] = array
16 nc.close()
17
18 class CompressionTestCase(unittest.TestCase):
19
20 def setUp(self):
21 self.filename1 = filename1
22 self.filename2 = filename2
23 write_netcdf(self.filename1,complevel=0) # no compression
24 write_netcdf(self.filename2,complevel=4) # with compression
25
26 def tearDown(self):
27 # Remove the temporary files
28 os.remove(self.filename1)
29 os.remove(self.filename2)
30
31 def runTest(self):
32 uncompressed_size = os.stat(self.filename1).st_size
33 # check uncompressed data
34 f = Dataset(self.filename1)
35 size = os.stat(self.filename1).st_size
36 assert_almost_equal(array,f.variables['data'][:])
37 assert f.variables['data'].filters() ==\
38 {'zlib':False,'szip':False,'zstd':False,'bzip2':False,'blosc':False,'shuffle':False,'complevel':0,'fletcher32':False}
39 assert_almost_equal(size,uncompressed_size)
40 f.close()
41 # check compressed data.
42 f = Dataset(self.filename2)
43 size = os.stat(self.filename2).st_size
44 assert_almost_equal(array,f.variables['data'][:])
45 assert f.variables['data'].filters() ==\
46 {'zlib':False,'szip':False,'zstd':True,'bzip2':False,'blosc':False,'shuffle':False,'complevel':4,'fletcher32':False}
47 assert(size < 0.96*uncompressed_size)
48 f.close()
49
50 if __name__ == '__main__':
51 unittest.main()
1818 TIME_LEN = None
1919 TIME_LENG = None
2020 GROUP_NAME='forecasts'
21 VAR_NAME='temp'
21 VAR_NAME1='temp1'
22 VAR_NAME2='temp2'
23 VAR_NAME3='temp3'
24 VAR_NAME4='temp4'
25 VAR_NAME5='temp5'
2226 VAR_TYPE='f8'
2327
2428
2731 def setUp(self):
2832 self.file = FILE_NAME
2933 f = netCDF4.Dataset(self.file, 'w')
30 f.createDimension(LAT_NAME,LAT_LEN)
31 f.createDimension(LON_NAME,LON_LEN)
32 f.createDimension(LEVEL_NAME,LEVEL_LEN)
33 f.createDimension(TIME_NAME,TIME_LEN)
34 f.createVariable(VAR_NAME,VAR_TYPE,(LEVEL_NAME, LAT_NAME, LON_NAME, TIME_NAME))
34 lat_dim=f.createDimension(LAT_NAME,LAT_LEN)
35 lon_dim=f.createDimension(LON_NAME,LON_LEN)
36 lev_dim=f.createDimension(LEVEL_NAME,LEVEL_LEN)
37 time_dim=f.createDimension(TIME_NAME,TIME_LEN)
38 # specify dimensions with names
39 fv1 = f.createVariable(VAR_NAME1,VAR_TYPE,(LEVEL_NAME, LAT_NAME, LON_NAME, TIME_NAME))
40 # specify dimensions with instances
41 fv2 = f.createVariable(VAR_NAME2,VAR_TYPE,(lev_dim,lat_dim,lon_dim,time_dim))
42 # specify dimensions using a mix of names and instances
43 fv3 = f.createVariable(VAR_NAME3,VAR_TYPE,(lev_dim, LAT_NAME, lon_dim, TIME_NAME))
44 # single dim instance for name (not in a tuple)
45 fv4 = f.createVariable(VAR_NAME4,VAR_TYPE,time_dim)
46 fv5 = f.createVariable(VAR_NAME5,VAR_TYPE,TIME_NAME)
3547 g = f.createGroup(GROUP_NAME)
3648 g.createDimension(LAT_NAME,LAT_LENG)
3749 g.createDimension(LON_NAME,LON_LENG)
3951 # (did not work prior to alpha 18)
4052 #g.createDimension(LEVEL_NAME,LEVEL_LENG)
4153 #g.createDimension(TIME_NAME,TIME_LENG)
42 g.createVariable(VAR_NAME,VAR_TYPE,(LEVEL_NAME, LAT_NAME, LON_NAME, TIME_NAME))
54 gv = g.createVariable(VAR_NAME1,VAR_TYPE,(LEVEL_NAME, LAT_NAME, LON_NAME, TIME_NAME))
4355 f.close()
4456
4557 def tearDown(self):
5062 """testing dimensions"""
5163 # check dimensions in root group.
5264 f = netCDF4.Dataset(self.file, 'r+')
53 v = f.variables[VAR_NAME]
65 v1 = f.variables[VAR_NAME1]
66 v2 = f.variables[VAR_NAME2]
67 v3 = f.variables[VAR_NAME3]
68 v4 = f.variables[VAR_NAME4]
69 v5 = f.variables[VAR_NAME5]
5470 isunlim = [dim.isunlimited() for dim in f.dimensions.values()]
5571 dimlens = [len(dim) for dim in f.dimensions.values()]
5672 names_check = [LAT_NAME, LON_NAME, LEVEL_NAME, TIME_NAME]
6480 # check that dimension names are correct.
6581 for name in f.dimensions.keys():
6682 self.assertTrue(name in names_check)
83 for name in v1.dimensions:
84 self.assertTrue(name in names_check)
85 for name in v2.dimensions:
86 self.assertTrue(name in names_check)
87 for name in v3.dimensions:
88 self.assertTrue(name in names_check)
89 self.assertTrue(v4.dimensions[0] == TIME_NAME)
90 self.assertTrue(v5.dimensions[0] == TIME_NAME)
91 # check that dimension lengths are correct.
6792 # check that dimension lengths are correct.
6893 for name,dim in f.dimensions.items():
6994 self.assertTrue(len(dim) == lensdict[name])
7499 # make sure length of dimensions change correctly.
75100 nadd1 = 2
76101 nadd2 = 4
77 v[0:nadd1,:,:,0:nadd2] = uniform(size=(nadd1,LAT_LEN,LON_LEN,nadd2))
102 v1[0:nadd1,:,:,0:nadd2] = uniform(size=(nadd1,LAT_LEN,LON_LEN,nadd2))
78103 lensdict[LEVEL_NAME]=nadd1
79104 lensdict[TIME_NAME]=nadd2
80105 # check that dimension lengths are correct.
82107 self.assertTrue(len(dim) == lensdict[name])
83108 # check dimensions in subgroup.
84109 g = f.groups[GROUP_NAME]
85 vg = g.variables[VAR_NAME]
110 vg = g.variables[VAR_NAME1]
86111 isunlim = [dim.isunlimited() for dim in g.dimensions.values()]
87112 dimlens = [len(dim) for dim in g.dimensions.values()]
88113 names_check = [LAT_NAME, LON_NAME, LEVEL_NAME, TIME_NAME]
8484 var2[:] = masked_all((10,), "u1")
8585 dataset.close()
8686
87 # issue #1152: if missing_value is a string that can't
88 # be cast to the variable type, issue a warning instead
89 # of raising an exception when auto-converted slice to a
90 # masked array
91 dataset = netCDF4.Dataset('issue1152.nc')
92 data = dataset['v'][:]
93 dataset.close()
94
8795 def tearDown(self):
8896 # Remove the temporary files
8997 os.remove(self.file)