@@ -24,26 +24,31 @@ reads data in parallel. A simple example of usage is::
2424 u[:] = np.random.random(u.shape)
2525 # Store by first creating output files
2626 fields = {'u': [u], 'v': [v]}
27- f0 = HDF5File('h5test.h5', global_shape=N, mode='w')
28- f1 = NCFile('nctest.nc', global_shape=N, mode='w')
27+ f0 = HDF5File('h5test.h5', mode='w')
28+ f1 = NCFile('nctest.nc', mode='w')
2929 f0.write(0, fields)
3030 f1.write(0, fields)
3131 v[:] = 3
3232 f0.write(1, fields)
3333 f1.write(1, fields)
34- # Alternatively, just use write method of each distributed array
35- u.write('h5test.h5', 'u', step=2)
36- v.write('h5test.h5', 'v', step=2)
37- u.write('nctest.nc', 'u', step=2)
38- v.write('nctest.nc', 'v', step=2)
3934
4035Note that we are here creating two datafiles ``h5test.h5 `` and ``nctest.nc ``,
4136for storing in HDF5 or NetCDF4 formats respectively. Normally, one would be
4237satisfied using only one format, so this is only for illustration. We store
4338the fields ``u `` and ``v `` on three different occasions,
4439so the datafiles will contain three snapshots of each field ``u `` and ``v ``.
4540
46- The stored dataarrays can be retrieved later on::
41+ Also note that an alternative and perhaps simpler approach is to just use
42+ the ``write `` method of each distributed array::
43+
44+ u.write('h5test.h5', 'u', step=2)
45+ v.write('h5test.h5', 'v', step=2)
46+ u.write('nctest.nc', 'u', step=2)
47+ v.write('nctest.nc', 'v', step=2)
48+
49+ The two different approaches can be used on the same output files.
50+
51+ The stored dataarrays can also be retrieved later on::
4752
4853 u0 = newDistArray(T, forward_output=False)
4954 u1 = newDistArray(T, forward_output=False)
@@ -53,26 +58,33 @@ The stored dataarrays can be retrieved later on::
5358 #u0.read('nctest.nc', 'u', 0)
5459 #u1.read('nctest.nc', 'u', 1)
5560
56-
5761Note that one does not have to use the same number of processors when
5862retrieving the data as when they were stored.
5963
6064It is also possible to store only parts of the, potentially large, arrays.
61- Any chosen slice may be stored, using a *global * view of the arrays::
65+ Any chosen slice may be stored, using a *global * view of the arrays. It is
66+ possible to store both complete fields and slices in one single call by
67+ using the following appraoch::
6268
63- f2 = HDF5File('variousfields.h5', global_shape=N, mode='w')
69+ f2 = HDF5File('variousfields.h5', mode='w')
6470 fields = {'u': [u,
6571 (u, [slice(None), slice(None), 4]),
6672 (u, [5, 5, slice(None)])],
6773 'v': [v,
6874 (v, [slice(None), 6, slice(None)])]}
6975 f2.write(0, fields)
7076 f2.write(1, fields)
71- f2.write(2, fields)
72- # or, using write method of field, e.g.
73- #u.write('variousfields.h5', 'u', 0, [slice(None), slice(None), 4])
7477
75- This will lead to an hdf5-file with groups::
78+ Alternatively, one can use the write method of each field with the ``global_slice ``
79+ keyword argument::
80+
81+ u.write('variousfields.h5', 'u', 2)
82+ u.write('variousfields.h5', 'u', 2, global_slice=[slice(None), slice(None), 4])
83+ u.write('variousfields.h5', 'u', 2, global_slice=[5, 5, slice(None)])
84+ v.write('variousfields.h5', 'v', 2)
85+ v.write('variousfields.h5', 'v', 2, global_slice=[slice(None), 6, slice(None)])
86+
87+ In the end this will lead to an hdf5-file with groups::
7688
7789 variousfields.h5/
7890 ├─ u/
@@ -86,41 +98,49 @@ This will lead to an hdf5-file with groups::
8698 | | ├─ 0
8799 | | ├─ 1
88100 | | └─ 2
89- | └─ 3D/
90- | ├─ 0
91- | ├─ 1
92- | └─ 2
93- ├─ v/
94- | ├─ 2D/
95- | | └─ slice_6_slice/
96- | | ├─ 0
97- | | ├─ 1
98- | | └─ 2
99- | └─ 3D/
100- | ├─ 0
101- | ├─ 1
102- | └─ 2
103- └─ mesh/
104- ├─ x0
105- ├─ x1
106- └─ x2
107-
108- Note that a mesh is stored along with all the data. This mesh can be given in
109- two different ways when creating the datafiles:
101+ | ├─ 3D/
102+ | | ├─ 0
103+ | | ├─ 1
104+ | | └─ 2
105+ | └─ mesh/
106+ | ├─ x0
107+ | ├─ x1
108+ | └─ x2
109+ └─ v/
110+ ├─ 2D/
111+ | └─ slice_6_slice/
112+ | ├─ 0
113+ | ├─ 1
114+ | └─ 2
115+ ├─ 3D/
116+ | ├─ 0
117+ | ├─ 1
118+ | └─ 2
119+ └─ mesh/
120+ ├─ x0
121+ ├─ x1
122+ └─ x2
123+
124+ Note that a mesh is stored along with each group of data. This mesh can be
125+ given in two different ways when creating the datafiles:
110126
111127 1) A sequence of 2-tuples, where each 2-tuple contains the (origin, length)
112128 of the domain along its dimension. For example, a uniform mesh that
113129 originates from the origin, with lengths :math: `\pi , 2 \pi , 3 \pi `, can be
114- given as::
130+ given when creating the output file as::
131+
132+ f0 = HDF5File('filename.h5', domain=((0, pi), (0, 2*np.pi), (0, 3*np.pi)))
133+
134+ or, using the write method of the distributed array:
115135
116- f0 = HDF5File ('filename.h5', global_shape=N , domain=((0, pi), (0, 2*np.pi), (0, 3*np.pi)))
136+ u.write ('filename.h5', 'u', 0 , domain=((0, pi), (0, 2*np.pi), (0, 3*np.pi)))
117137
118138 2) A sequence of arrays giving the coordinates for each dimension. For example::
119139
120140 d = (np.arange(N[0], dtype=np.float)*1*np.pi/N[0],
121141 np.arange(N[1], dtype=np.float)*2*np.pi/N[1],
122142 np.arange(N[2], dtype=np.float)*2*np.pi/N[2])
123- f0 = HDF5File('filename.h5', global_shape=N, domain=d)
143+ f0 = HDF5File('filename.h5', domain=d)
124144
125145With NetCDF4 the layout is somewhat different. For ``variousfields `` above,
126146if we were using :class: `.NCFile ` instead of :class: `.HDF5File `,
0 commit comments