@@ -33,7 +33,7 @@ a dataset or group. It contains :attr:`~ncdata.NcData.dimensions`,
3333:attr: `~ncdata.NcData.variables `, :attr: `~ncdata.NcData.groups `,
3434and :attr: `~ncdata.NcData.attributes `:
3535
36- .. code-block :: python
36+ .. doctest :: python
3737
3838 >>> from ncdata import NcData, NcDimension, NcVariable
3939 >>> data = NcData(" myname" )
@@ -75,13 +75,12 @@ NetCDF files via the `netcdf4-python package <http://unidata.github.io/netcdf4-p
7575
7676Simple example:
7777
78- .. code-block :: python
78+ .. doctest :: python
7979
8080 >>> from ncdata.netcdf4 import to_nc4, from_nc4
8181 >>> filepath = " ./tmp.nc"
8282 >>> to_nc4(data, filepath)
83-
84- >> > ncdump(" tmp.nc" ) # utility calling 'ncdump -h' (not shown)
83+ >>> ncdump(" tmp.nc" ) # utility which calls 'ncdump' command (not shown)
8584 netcdf tmp {
8685 dimensions:
8786 x = 3 ;
@@ -107,7 +106,7 @@ Variables
107106Variables live in a :attr: `ncdata.NcData.variables ` attribute,
108107which behaves like a dictionary:
109108
110- .. code-block :: python
109+ .. doctest :: python
111110
112111 >>> data.variables
113112 {'vx': <ncdata._core.NcVariable object at ...>}
@@ -131,80 +130,54 @@ which behaves like a dictionary:
131130
132131Attributes
133132^^^^^^^^^^
134- Attributes live in the ``attributes `` property of a :class: `~ncdata.NcData `
135- or :class: `~ncdata.NcVariable `:
133+ Attributes are held in the ``.attributes `` property of a :class: `~ncdata.NcData `
134+ or :class: `~ncdata.NcVariable `. However, they are more easily accessed via the ``.avals ``
135+ property, which provides a simple name:value mapping :
136136
137- .. code-block :: python
137+ .. doctest :: python
138138
139139 >>> var = data.variables[" vx" ]
140- >> > var.set_attrval(' a' , 1 )
141- NcAttribute(' a' , 1 )
142- >> > var.set_attrval(' b' , ' this' )
143- NcAttribute(' b' , ' this' )
140+ >>> var.avals[' a' ] = 1
141+ >>> var.avals[' b' ] = ' this'
144142
145143 >>> print (var)
146144 <NcVariable(float64): vx(x)
147145 vx:a = 1
148146 vx:b = 'this'
149147 >
150148
151- >> > print (var.attributes)
152- {' a' : NcAttribute(' a' , 1 ), ' b' : NcAttribute(' b' , ' this' )}
153-
154- >> > print (data)
155- < NcData: myname
156- dimensions:
157- x = 3
158- < BLANKLINE >
159- variables:
160- < NcVariable(float64): vx(x)
161- vx:a = 1
162- vx:b = ' this'
163- >
149+ >>> var.avals[' b' ] = 7777
150+ >>> print (var)
151+ <NcVariable(float64): vx(x)
152+ vx:a = 1
153+ vx:b = 7777
164154 >
165155
166- For technical reasons, each attribute is represented as an independent python
167- :class: `ncdata.NcAttribute ` object, i.e. they are *not * simply stored as a
168- values in a name/value map.
169-
170- Attribute values are actually :mod: `numpy.ndarray `, and hence have a ``dtype ``.
171- To make this easier, you can use regular python numbers and strings with
172- :meth: `ncdata.NcAttribute.as_python_value ` and the
173- :meth: `~ncdata.NcVariable.set_attrval `
174- and :meth: `~ncdata.NcVariable.get_attrval ` of NcData/NcVariable.
156+ Attribute values are actually stored as :mod: `numpy.ndarray ` arrays, and hence have a
157+ definite ``dtype ``. However, ``.avals `` allows you to treat them mostly as ordinary
158+ python values (numbers and strings).
175159
176160
177161Deletion and Renaming
178162^^^^^^^^^^^^^^^^^^^^^
179- Use python 'del' operation to remove:
163+ Use python 'del' operation to remove items :
180164
181- .. code-block :: python
165+ .. doctest :: python
182166
183167 >>> del var.attributes[' a' ]
184168 >>> print (var)
185169 <NcVariable(float64): vx(x)
186- vx:b = ' this '
170+ vx:b = 7777
187171 >
188172
189173There is also a 'rename' method of variables/attributes/groups:
190174
191- .. code-block :: python
175+ .. doctest :: python
192176
193177 >>> var.attributes.rename(" b" , " qq" )
194178 >>> print (var)
195179 <NcVariable(float64): vx(x)
196- vx:qq = ' this'
197- >
198-
199- >> > print (data)
200- < NcData: myname
201- dimensions:
202- x = 3
203- < BLANKLINE >
204- variables:
205- < NcVariable(float64): vx(x)
206- vx:qq = ' this'
207- >
180+ vx:qq = 7777
208181 >
209182
210183.. warning ::
@@ -246,18 +219,18 @@ at :ref:`interface_support`.
246219
247220Example code snippets :
248221
249- .. code-block :: python
222+ .. doctest :: python
250223
251224 >>> # (make sure that Iris and Ncdata won't conflict over netcdf access)
252225 >>> from ncdata.threadlock_sharing import enable_lockshare
253226 >>> enable_lockshare(iris = True , xarray = True )
254227
255- .. code-block :: python
228+ .. doctest :: python
256229
257230 >>> from ncdata.netcdf4 import from_nc4
258231 >>> data = from_nc4(" tmp.nc" )
259232
260- .. code-block :: python
233+ .. doctest :: python
261234
262235 >>> from ncdata.iris import to_iris, from_iris
263236 >>> from iris import FUTURE
@@ -281,7 +254,7 @@ Example code snippets :
281254 >>> print (vv)
282255 v_mag / (m.s-1) (-- : 3)
283256
284- .. code-block :: python
257+ .. doctest :: python
285258
286259 >>> from ncdata.xarray import to_xarray
287260 >>> xrds = to_xarray(from_iris([vx, vy, vv]))
@@ -296,7 +269,7 @@ Example code snippets :
296269 Attributes:
297270 Conventions: CF-1.7
298271
299- .. code-block :: python
272+ .. doctest :: python
300273
301274 >>> from ncdata.iris_xarray import cubes_from_xarray
302275 >>> readback = cubes_from_xarray(xrds)
@@ -318,7 +291,7 @@ Thread safety
318291 prevent possible errors when computing or saving lazy data.
319292 For example:
320293
321- .. code-block :: python
294+ .. doctest :: python
322295
323296 >>> from ncdata.threadlock_sharing import enable_lockshare
324297 >>> enable_lockshare(iris = True , xarray = True )
0 commit comments