Skip to content

Commit 5d2d970

Browse files
committed
docs: remove words of under construction
1 parent 9246465 commit 5d2d970

File tree

3 files changed

+157
-151
lines changed

3 files changed

+157
-151
lines changed

docs/source/tutorial/basic.rst

Lines changed: 100 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
Basics
44
=========
55

6-
.. warning::
7-
8-
Under construction.
9-
106
Running Python scripts with MPI
117
-------------------------------
128

13-
Python programs with PnetCDF-Python can be run with the command :program:`mpiexec`. In
14-
practice, running Python programs looks like:
9+
Python programs with PnetCDF-Python can be run with the command
10+
:program:`mpiexec`. In practice, running Python programs looks like:
1511

1612
$ mpiexec -n 4 Python script.py
1713

@@ -20,14 +16,16 @@ Running Python scripts with MPI
2016
Creating/Opening/Closing a netCDF file
2117
--------------------------------------
2218

23-
To create a netCDF file from Python, you simply call the ``File`` constructor. This is also
24-
the method used to open an existing netCDF file. If the file is open for write access
25-
(mode='w', 'r+' or 'a'), you may write any type of data including new dimensions, variables
26-
and attributes. Currently, netCDF files can be created in classic formats, specifically the
27-
formats of CDF-1, 2, and 5. When creating a new file, the format may be specified using the
28-
format keyword in the ``File`` constructor. The default format is CDF-1. To see how a given
29-
file is formatted, you can examine the ``file_format`` attribute. Closing the netCDF file is
30-
accomplished via the :meth:`File.close` method of the ``File`` instance.
19+
To create a netCDF file from Python, you simply call the ``File`` constructor.
20+
This is also the method used to open an existing netCDF file. If the file is
21+
open for write access (mode='w', 'r+' or 'a'), you may write any type of data
22+
including new dimensions, variables and attributes. Currently, netCDF files
23+
can be created in classic formats, specifically the formats of CDF-1, 2, and
24+
5. When creating a new file, the format may be specified using the format
25+
keyword in the ``File`` constructor. The default format is CDF-1. To see how a
26+
given file is formatted, you can examine the ``file_format`` attribute.
27+
Closing the netCDF file is accomplished via the :meth:`File.close` method of
28+
the ``File`` instance.
3129

3230
Here's an example:
3331

@@ -40,7 +38,7 @@ Creating/Opening/Closing a netCDF file
4038
f.close()
4139
4240
Equivalent example codes in ``netCDF4-python``:
43-
41+
4442
.. code-block:: Python
4543
4644
from mpi4py import MPI
@@ -51,47 +49,38 @@ Creating/Opening/Closing a netCDF file
5149
5250
For the full example program, see ``examples/craete_open.py``.
5351

54-
Dimensions
52+
Dimensions
5553
-------------
5654

57-
NetCDF specifies the sizes of variables based on dimensions. Therefore, before creating any variables,
58-
the dimensions they depend on must be established. To create a dimension, the :meth:`File.def_dim` method is called
59-
on a File instance under define mode. The dimension's name is set using a Python string, while the size
60-
is defined using an integer value. To create an unlimited dimension (a dimension that can be expanded),
61-
the size can be omitted or assigned as -1. A "Dimension" object will be returned as a handler for this
62-
dimension.
55+
NetCDF variables are multi-dimensional arrays. Before creating any variables,
56+
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.
58+
The dimension's name is set using a Python string, while the size is defined
59+
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.
6362

64-
Here's an example:
63+
Here's an example (same if using netcdf4-python):
6564

6665
.. code-block:: Python
6766
68-
from pnetcdf import File
6967
LAT_NAME="lat"
7068
LAT_LEN = 50
7169
TIME_NAME="time"
7270
lat_dim = f.def_dim(LAT_NAME, LAT_LEN)
7371
time_dim = f.def_dim(TIME_NAME, -1)
7472
75-
Equivalent example codes in ``netCDF4-python``:
76-
77-
.. code-block:: Python
78-
79-
LAT_NAME="lat"
80-
LAT_LEN = 50
81-
TIME_NAME="time"
82-
lat_dim = f.createDimension(LAT_NAME, LAT_LEN)
83-
time_dim = f.createDimension(TIME_NAME, None)
84-
85-
86-
All of the Dimension instances are stored in a dictionary as an Python attribute of File.
73+
All of the Dimension instances are stored in a dictionary as an Python
74+
attribute of File.
8775

8876
.. code-block:: Python
8977
9078
>>> print(f.dimensions)
9179
{'lat': <class 'pnetcdf._Dimension.Dimension'>: name = 'lat', size = 50, 'time': <class 'pnetcdf._Dimension.Dimension'> (unlimited): name = 'time', size = 0}
9280
93-
To retrieve the previous defined dimension instance from the file, you can directly index the dictionary using variable name as the key.
94-
The dimension information can be retrieved using following functions.
81+
To retrieve the previous defined dimension instance from the file, you can
82+
directly index the dictionary using variable name as the key. The dimension
83+
information can be retrieved using following functions.
9584

9685
.. code-block:: Python
9786
@@ -104,26 +93,25 @@ Dimensions
10493
Variables
10594
------------
10695

107-
NetCDF variables are similar to multidimensional array objects in Python provided by the numpy module. To define a netCDF
108-
variable, you can utilize the :meth:`File.def_var` method within a File instance under define mode. The mandatory arguments for
109-
this methods include the variable name (a string in Python) and dimensions (either a tuple of dimension names or dimension
110-
instances). In addition, the user need to specify the datatype of the variable using module-level NC constants (e.g. pnetcdf.NC_INT).
111-
The supported datatypes given each file format can be found :ref:`here<Datatype>`.
112-
113-
Here's an example:
114-
115-
.. code-block:: Python
96+
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
101+
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>`.
116104

117-
var = f.def_var(varname = "var", datatype = pnetcdf.NC_INT, dimensions = ("time", "lat"))
105+
Here's an example (same if using netcdf4-python):
118106

119-
Equivalent example codes in ``netCDF4-python``:
120-
121107
.. code-block:: Python
122108
123-
var = f.createVariable(varname="time", datatype="i4", dimensions = ("time", "lat"))
109+
var = f.createVariable(varname="var", datatype="i4", dimensions = ("time", "lat"))
124110
125-
All of the variables in the file are stored in a Python dictionary, in the same way as the dimensions. To retrieve the previous defined
126-
netCDF variable instance from the file, you can directly index the dictionary using variable name as the key.
111+
All of the variables in the file are stored in a Python dictionary, in the
112+
same way as the dimensions. To retrieve the previous defined netCDF variable
113+
instance from the file, you can directly index the dictionary using variable
114+
name as the key.
127115

128116
.. code-block:: Python
129117
@@ -134,56 +122,60 @@ Variables
134122
unlimited dimensions: time
135123
current shape = (0, 50)
136124
filling off}
137-
138-
139-
Up to this point a netCDF variable is properly defined. To write data to or read from this variable, see later sections for more details.
140125
141-
Attributes
126+
Up to this point a netCDF variable is properly defined. To write data to or
127+
read from this variable, see later sections for more details.
128+
129+
Attributes
142130
------------
143131

144-
In a netCDF file, there are two types of attributes: global attributes and variable attributes.
145-
Global attributes are usually related to the netCDF file as a whole and may be used for purposes
146-
such as providing a title or processing history for a netCDF file.Variable attributes are used to specify
147-
properties as units, special values, maximum and minimum valid values, scaling factors, and offsets.
132+
In a netCDF file, there are two types of attributes: global attributes and
133+
variable attributes. Global attributes are usually related to the netCDF file
134+
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
136+
specify properties related to the variable, such as units, special values,
137+
maximum and minimum valid values, and annotation.
148138

149-
Attributes for a netCDF file are defined when the file is first created, while the netCDF dataset is in
150-
define mode. Additional attributes may be added later by reentering define mode. Attributes can take
151-
the form of strings, numbers, or sequences. Returning to our example,
139+
Attributes for a netCDF file are defined when the file is first created, while
140+
the netCDF dataset is in define mode. Additional attributes may be added later
141+
by reentering define mode. Attributes can take the form of strings, and
142+
numerical values. Returning to our example,
152143

153144
.. code-block:: Python
154145
155146
# set global attributes
156-
f.floatatt = math.pi # Option1: Python attribute assignment
147+
f.floatatt = math.pi # Option1: Python attribute assignment
157148
f.put_att("intatt", np.int32(1)) # Option2: method put_att()
158149
f.seqatt = np.int32(np.arange(10))
159150
160151
# set variable attributes
161-
var = f.variables['var']
162-
var.floatatt = math.pi
163-
var.put_att("int_att", np.int32(1))
152+
var = f.variables['var']
153+
var.floatatt = math.pi
154+
var.put_att("int_att", np.int32(1))
164155
var.seqatt = np.int32(np.arange(10))
165156
166157
Equivalent example codes in ``netCDF4-python``:
167-
158+
168159
.. code-block:: Python
169160
170161
# set root group attributes
171-
f.floatatt = math.pi # Option1: Python attribute assignment
172-
f.setncattr("intatt", np.int32(1)) # Option2: method put_att()
162+
f.floatatt = math.pi # Option1: Python attribute assignment
163+
f.setncattr("intatt", np.int32(1)) # Option2: method setncattr()
173164
f.seqatt = np.int32(np.arange(10))
174165
175166
# set variable attributes
176-
var = f.variables['var']
177-
var.floatatt = math.pi
178-
var.setncattr("int_att", np.int32(1))
167+
var = f.variables['var']
168+
var.floatatt = math.pi
169+
var.setncattr("int_att", np.int32(1))
179170
var.seqatt = np.int32(np.arange(10))
180171
181-
The :meth:`File.ncattrs` method of a File or Variable instance can be used to retrieve the names of all
182-
the netCDF attributes. And the __dict__ attribute of a File or Variable instance provides all the netCDF
183-
attribute name/value pairs in a python dictionary:
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:
184176

185177
.. code-block:: Python
186-
178+
187179
>>> print(var.ncattrs())
188180
['floatatt', 'intatt', 'seqatt', 'int_att']
189181
>>> print(var.__dict__)
@@ -195,10 +187,10 @@ Attributes
195187
Writing to variable
196188
--------------------
197189

198-
Now that you have a netCDF Variable instance, how do you put data into it? Firstly make sure the file is in data mode.
199-
Then for writing, there are currently two options:
190+
Once a netCDF variable instance is created, writing the variable must be done
191+
while the file is in data mode. Then for writing, there are two options:
200192

201-
Option1 Indexer (or slicing) syntax
193+
Option1 Indexer (or slicing) syntax
202194
You can just treat the variable like an numpy array and assign data
203195
to a slice. Slices are specified as a `start:stop:step` triplet.
204196

@@ -207,34 +199,44 @@ Option1 Indexer (or slicing) syntax
207199
buff = np.zeros(shape = (10, 50), dtype = "i4")
208200
var[:] = buff # put values to the variable
209201
210-
The indexer syntax is the same as in ``netcdf4-python`` library for writing to netCDF variable.
202+
The indexer syntax is the same as in ``netcdf4-python`` library for writing to
203+
netCDF variable.
211204

212-
Option2 Method calls of put/get_var()
213-
Alternatively you can also leverage Variable.put/get_var() method of a Variable instance
214-
to perform i/o according to specfic access pattern needs.
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.
215208

216-
Here is an example to write an array to the netCDF variable. The part of the netCDF variable to write is specified by giving a corner (`start`)
217-
and a vector of edge lengths (`count`) that refer to an array section of the netCDF variable.
209+
Here is the example below to write an array to the netCDF variable. The part
210+
of the netCDF variable to write is specified by giving a corner (`start`) and
211+
a vector of edge lengths (`count`) that refer to an array section of the
212+
netCDF variable.
218213

219214
.. code-block:: Python
220215
221216
buff = np.zeros(shape = (10, 50), dtype = "i4")
222-
var.put_var_all(buff, start = [10, 0], count = [10, 50]) # Equivalent to var[10:20, 0:50] = buff
217+
var.put_var_all(buff, start = [10, 0], count = [10, 50])
218+
# The above line is equivalent to var[10:20, 0:50] = buff
223219
224220
225221
Reading from variable
226222
----------------------
227223

228-
Symmetrically, users can use two options with different syntaxes to retreive array values from the variable.
229-
The indexer syntax is the same as in ``netcdf4-python`` library for reading from netCDF variable.
224+
Symmetrically, users can use two options with different syntaxes to retrieve
225+
array values from the variable. The indexer syntax is the same as in
226+
``netcdf4-python`` library for reading from netCDF variable.
230227

231228
.. code-block:: Python
232229
233-
var = f.variables['var']
234-
print(var[:10, :10]) # Option1 Indexer: read the topleft 10*10 corner from variable var
235-
print(var.get_var_all(start = [10, 0], count = [10, 50])) # Option2 Method Call: equivalent to var[10:20, 0:50]
236-
237-
Similarly, :meth:`Variable.get_var` takes the same set of optional arguments and behave differently depending on the pattern of provided
238-
optional arguments.
239-
240-
To learn more about reading and writing, see the :ref:`here<Parallel Read and Write>` page.
230+
var = f.variables['var']
231+
# Option1 Indexer: read the topleft 10*10 corner from variable var
232+
buf = var[:10, :10]
233+
234+
# Option2 Method Call: equivalent to var[10:20, 0:50]
235+
buf = var.get_var_all(start = [10, 0], count = [10, 50])
236+
237+
Similarly, :meth:`Variable.get_var` takes the same set of optional arguments
238+
and behave differently depending on the pattern of provided optional
239+
arguments.
240+
241+
To learn more about reading and writing, see :ref:`here<Parallel Read and Write>`.
242+

docs/source/tutorial/datatypes.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
===========================
2-
Datatype
2+
Data type
33
===========================
4-
.. warning::
54

6-
Under construction.
7-
8-
NetCDF Variable Types
9-
The following table gives the netCDF external data types defined in CDF-1 and CDF-2 and the corresponding type constants for
10-
defining variables in the python interface. All these data types have direct numpy quivalent.
5+
NetCDF Variable Data Types
6+
The following table gives the netCDF external data types defined in CDF-1 and
7+
CDF-2 and the corresponding type constants for defining variables in the
8+
python interface. All these data types have direct numpy quivalent.
119

1210

1311

0 commit comments

Comments
 (0)