66Running Python scripts with MPI
77-------------------------------
88
9- Python programs with PnetCDF-Python can be run with the command
10- :program: `mpiexec `. In practice, running Python programs looks like:
9+ Python programs using PnetCDF-Python can be run with the command
10+ :program: `mpiexec `. In practice, running a Python program looks like:
1111
12- $ mpiexec -n 4 Python script.py
12+ $ mpiexec -n 4 python script.py
1313
14- to run the program with 4 processors .
14+ to run the program with 4 MPI processes .
1515
1616Creating/Opening/Closing a netCDF file
1717--------------------------------------
@@ -27,24 +27,24 @@ Creating/Opening/Closing a netCDF file
2727 Closing the netCDF file is accomplished via the :meth: `File.close ` method of
2828 the ``File `` instance.
2929
30- Here's an example:
30+ Here is an example of creating a new file :
3131
3232 .. code-block :: Python
3333
34- from pnetcdf import File
3534 from mpi4py import MPI
36- comm = MPI .COMM_WORLD
37- f = File(filename = " testfile.nc" , mode = ' w' , comm = comm, info = None )
35+ import pnetcdf
36+
37+ f = pnetcdf.File(filename = " testfile.nc" , mode = ' w' , comm = MPI .COMM_WORLD , info = None )
3838 f.close()
3939
40- Equivalent example codes in ``netCDF4-python ``:
40+ Equivalent example codes when using ``netCDF4-python ``:
4141
4242 .. code-block :: Python
4343
4444 from mpi4py import MPI
45- from netCDF4 import Dataset
46- comm = MPI . COMM_WORLD
47- f = Dataset(filename = " testfile.nc" , mode = " w" , comm = comm , parallel = True )
45+ import netCDF4
46+
47+ f = netCDF4. Dataset(filename = " testfile.nc" , mode = " w" , comm = MPI . COMM_WORLD , parallel = True )
4848 f.close()
4949
5050 For the full example program, see ``examples/craete_open.py ``.
@@ -54,11 +54,11 @@ Dimensions
5454
5555 NetCDF variables are multi-dimensional arrays. Before creating any variables,
5656 the dimensions they depend on must be established. To create a dimension, the
57- :meth: `File.def_dim ` method is called on a File instance under define mode.
57+ :meth: `File.def_dim ` method is called on a `` File `` instance under define mode.
5858 The dimension's name is set using a Python string, while the size is defined
5959 using an integer value. To create an unlimited dimension (a dimension that can
60- be expanded), the size can be omitted or assigned as -1. A "Dimension" object
61- will be returned as a handler for this dimension.
60+ be expanded), the parameter size can be omitted or assigned as -1. A
61+ `` Dimension `` instance will be returned as a handler for this dimension.
6262
6363 Here's an example (same if using netcdf4-python):
6464
@@ -70,8 +70,8 @@ Dimensions
7070 lat_dim = f.def_dim(LAT_NAME , LAT_LEN )
7171 time_dim = f.def_dim(TIME_NAME , - 1 )
7272
73- All of the Dimension instances are stored in a dictionary as an Python
74- attribute of File.
73+ All of the `` Dimension `` instances are stored in a Python dictionary as an
74+ attribute of `` File `` .
7575
7676 .. code-block :: Python
7777
@@ -94,13 +94,13 @@ Variables
9494------------
9595
9696 NetCDF variables are similar to multidimensional array objects in Python
97- provided by the numpy module. To define a netCDF variable, you can utilize the
98- :meth: `File.def_var ` method within a File instance under define mode. The
99- mandatory arguments for this methods include the variable name (a string in
100- Python) and dimensions (either a tuple of dimension names or dimension
97+ provided by the `` numpy `` module. To define a netCDF variable, you can utilize
98+ the :meth: `File.def_var ` method within a `` File `` instance under define mode.
99+ The mandatory arguments for this methods include the variable name (a string
100+ in Python) and dimensions (either a tuple of dimension names or dimension
101101 instances). In addition, the user need to specify the datatype of the variable
102- using module-level NC constants (e.g. pnetcdf.NC_INT). The supported
103- data types given each file format can be found :ref: `here<Datatype> `.
102+ using module-level constants (e.g. `` pnetcdf.NC_INT `` ). The supported data
103+ types given each file format can be found :ref: `here<Datatype> `.
104104
105105 Here's an example (same if using netcdf4-python):
106106
@@ -132,7 +132,7 @@ Attributes
132132 In a netCDF file, there are two types of attributes: global attributes and
133133 variable attributes. Global attributes are usually related to the netCDF file
134134 as a whole and may be used for purposes such as providing a title or
135- processing history for a netCDF file. Variable's attributes are used to
135+ processing history for a netCDF file. `` Variable `` 's attributes are used to
136136 specify properties related to the variable, such as units, special values,
137137 maximum and minimum valid values, and annotation.
138138
@@ -144,11 +144,11 @@ Attributes
144144 .. code-block :: Python
145145
146146 # set global attributes
147- f.floatatt = math.pi # Option1 : Python attribute assignment
148- f.put_att(" intatt" , np.int32(1 )) # Option2 : method put_att()
147+ f.floatatt = math.pi # Option 1 : Python attribute assignment
148+ f.put_att(" intatt" , np.int32(1 )) # Option 2 : method put_att()
149149 f.seqatt = np.int32(np.arange(10 ))
150150
151- # set variable attributes
151+ # write variable attributes
152152 var = f.variables[' var' ]
153153 var.floatatt = math.pi
154154 var.put_att(" int_att" , np.int32(1 ))
@@ -159,8 +159,8 @@ Attributes
159159 .. code-block :: Python
160160
161161 # set root group attributes
162- f.floatatt = math.pi # Option1 : Python attribute assignment
163- f.setncattr(" intatt" , np.int32(1 )) # Option2 : method setncattr()
162+ f.floatatt = math.pi # Option 1 : Python attribute assignment
163+ f.setncattr(" intatt" , np.int32(1 )) # Option 2 : method setncattr()
164164 f.seqatt = np.int32(np.arange(10 ))
165165
166166 # set variable attributes
@@ -169,10 +169,10 @@ Attributes
169169 var.setncattr(" int_att" , np.int32(1 ))
170170 var.seqatt = np.int32(np.arange(10 ))
171171
172- The :meth: `File.ncattrs ` method of a File or Variable instance can be used to
173- retrieve the names of all the netCDF attributes. And the __dict__ attribute of
174- a File or Variable instance provides all the netCDF attribute name/value pairs
175- in a python dictionary:
172+ The :meth: `File.ncattrs ` method of a `` File `` or `` Variable `` instance can be
173+ used to retrieve the names of all the netCDF attributes. And the __dict__
174+ attribute of a `` File `` or `` Variable `` instance provides all the netCDF
175+ attribute name/value pairs in a python dictionary:
176176
177177 .. code-block :: Python
178178
@@ -184,14 +184,14 @@ Attributes
184184
185185 For the full example program, see ``examples/global_attributes.py ``.
186186
187- Writing to variable
187+ Writing to a variable
188188--------------------
189189
190190 Once a netCDF variable instance is created, writing the variable must be done
191191 while the file is in data mode. Then for writing, there are two options:
192192
193- Option1 Indexer (or slicing) syntax
194- You can just treat the variable like an numpy array and assign data
193+ Option 1 Indexer (or slicing) syntax
194+ You can just treat the variable like an `` numpy `` array and assign data
195195 to a slice. Slices are specified as a `start:stop:step ` triplet.
196196
197197 .. code-block :: Python
@@ -202,9 +202,9 @@ Option1 Indexer (or slicing) syntax
202202 The indexer syntax is the same as in ``netcdf4-python `` library for writing to
203203 netCDF variable.
204204
205- Option2 Method calls of put_var()/get_var()
206- Alternatively you can also leverage Variable.put/get_var() method of a
207- Variable instance to perform I/O according to specific access pattern needs.
205+ Option 2 Method calls of put_var()/get_var()
206+ Alternatively you can also leverage `` Variable.put/get_var() `` method of a
207+ `` Variable `` instance to perform I/O according to specific access pattern needs.
208208
209209 Here is the example below to write an array to the netCDF variable. The part
210210 of the netCDF variable to write is specified by giving a corner (`start `) and
@@ -218,7 +218,7 @@ Option2 Method calls of put_var()/get_var()
218218 # The above line is equivalent to var[10:20, 0:50] = buff
219219
220220
221- Reading from variable
221+ Reading from a variable
222222----------------------
223223
224224 Symmetrically, users can use two options with different syntaxes to retrieve
@@ -228,10 +228,10 @@ Reading from variable
228228 .. code-block :: Python
229229
230230 var = f.variables[' var' ]
231- # Option1 Indexer: read the topleft 10*10 corner from variable var
231+ # Option 1 Indexer: read the top-left 10*10 corner from variable var
232232 buf = var[:10 , :10 ]
233233
234- # Option2 Method Call: equivalent to var[10:20, 0:50]
234+ # Option 2 Method Call: equivalent to var[10:20, 0:50]
235235 buf = var.get_var_all(start = [10 , 0 ], count = [10 , 50 ])
236236
237237 Similarly, :meth: `Variable.get_var ` takes the same set of optional arguments
0 commit comments