Skip to content

Commit 065f6d0

Browse files
committed
Use OO program terms of 'field' and 'method' to avoid confision of netcdf attribute
1 parent 4ec046e commit 065f6d0

File tree

12 files changed

+95
-84
lines changed

12 files changed

+95
-84
lines changed

docs/source/api/attribute_api.rst

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@
22
Attributes
33
===========
44

5-
NetCDF attributes can be created, accessed, and manipulated using python
6-
dictionary-like syntax. An attribute can be associated to the file, referred to
7-
as ``golbal attribute``, as well as to individual variable, referred to as
8-
``variable's attribute``. Pythonic interfaces for accessing attributes are is
9-
provided both in :class:`pnetcdf.File` (for global attributes) and the
10-
:class:`pnetcdf.Variable` (for variable attributes).
5+
In `object-oriented programming <https://en.wikipedia.org/wiki/Object-oriented_programming>`_,
6+
a class contains fields (state variables containing data) and methods
7+
(subroutines or procedures defining the object's behavior in code). ``Fields``
8+
may also be known as members, attributes, or properties. To avoid confusion
9+
with NetCDF's terminology of ``attribute``, this document uses `field` to refer
10+
to a class's state variable.
11+
12+
NetCDF attributes are small, supplementary metadata that annotates variables or
13+
files. NetCDF attribute is not a Python class by itself. Instead, it is a
14+
field of python dictionary in class :class:`pnetcdf.File` and class
15+
:class:`pnetcdf.Variable`. Their data types can be any allowed by the classic
16+
NetCDF file formats. The most common data type is `text` for annotation
17+
purpose. NetCDF attributes can be created, accessed, and manipulated using
18+
python dictionary-like syntax. An attribute can be associated to a file,
19+
referred to as ``golbal attribute``, as well as to individual variables,
20+
referred to as ``variable's attribute``. Pythonic interfaces for accessing
21+
attributes are is provided both in class :class:`pnetcdf.File` (for global
22+
attributes) and class :class:`pnetcdf.Variable` (for variable attributes).
23+
Example programs are `examples/global_attribute.py` and `examples/put_var.py`.
1124

docs/source/api/dimension_api.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ dimensions objects stored in the file.
1111
:members: getfile, isunlimited
1212
:exclude-members: name, size
1313

14-
Read-only Python Attributes of Dimension Class
15-
The following class members are read-only and should not be modified by the
14+
Read-only python fields of class :class:`pnetcdf.Dimension`
15+
The following class fields are read-only and should not be modified by the
1616
user.
1717

1818
.. attribute:: name
1919

20-
String name of Dimension instance. This class member is read-only and
20+
String name of Dimension instance. This class field is read-only and
2121
should not be modified by the user. To rename a dimension, use
2222
:meth:`File.rename_dim` method.
2323

docs/source/api/file_api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ of data and relations among data objects stored in a netCDF file.
1717
inq_header_size, inq_put_size, inq_header_extent, inq_nreqs
1818
:exclude-members: dimensions, variables, file_format, indep_mode, path
1919

20-
Read-only Python Attributes of File Class
21-
The following class members are read-only and should not be modified by the
20+
Read-only python fields of class :class:`pnetcdf.File`
21+
The following class fields are read-only and should not be modified by the
2222
user.
2323

2424
.. attribute:: dimensions

docs/source/api/function_api.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
================
2-
Other PnetCDF Utility Functions
2+
Other pnetcdf class methods
33
================
44

5+
PnetCDF class methods listed below are not associated with particular
6+
instances of ``File`` or ``Variable``.
7+
58
.. autofunction:: pnetcdf::libver
69
.. autofunction:: pnetcdf::strerror
710
.. autofunction:: pnetcdf::strerrno

docs/source/api/variable_api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ syntax.
2020
chartostring
2121

2222

23-
Read-only Python Attributes of Variable Class
24-
The following class members are read-only and should not be modified
23+
Read-only python fields of class :class:`pnetcdf.Variable`
24+
The following class fields are read-only and should not be modified
2525
directly by the user.
2626

2727
.. attribute:: name

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ netCDF files.
4343

4444
.. toctree::
4545
:maxdepth: 1
46-
:caption: Copyright Statement
46+
:caption: Copyright
4747

4848
copyright
4949

docs/source/tutorial/basic.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ Dimensions
8080
8181
To retrieve the previous defined dimension instance from the file, you can
8282
directly index the dictionary using variable name as the key. The dimension
83-
information can be retrieved using following functions.
83+
information can be retrieved using following python functions or ``Dimension``
84+
class methods.
8485

8586
.. code-block:: Python
8687

docs/source/tutorial/compare_netcdf4.rst

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,21 @@ Difference in Programming Model
2020

2121
Data/Define Mode
2222
NetCDF4-python library automatically switches between data and define mode
23-
for the user by calling ``redef`` and ``enddef`` internally within the
24-
define-mode operation functions. For performance reason, this is **not**
25-
adopted in Pnetcdf-python. A manual call to :meth:`File.redef` is compulsory
26-
to re-enter the define mode, following the C library convention. Similarly,
27-
:meth:`File.enddef` is required before switching to data mode operations.
28-
This design is based on considerations of the following aspects:
23+
by calling ``redef`` and ``enddef`` internally. For performance reason, this
24+
is **not** adopted in Pnetcdf-python. A manual call to :meth:`File.redef` is
25+
compulsory to re-enter the define mode, following the C library convention.
26+
Similarly, :meth:`File.enddef` is required before switching to data mode
27+
operations. This design is based on considerations of the following aspects:
2928

3029
- Minimize overheads during consecutive define operations: Automatically
31-
wrapping all define functions with :meth:`File.redef` and
30+
wrapping all define methods with :meth:`File.redef` and
3231
:meth:`File.enddef` could introduce significant overhead between
3332
consecutive define operations. The netCDF4-python approach results in
3433
unnecessary data/define mode switches, impacting performance.
3534

3635
- Avoid potential hanging when performing independent I/O: if
37-
:meth:`File.enddef` is automatically embedded in all data mode operation
38-
functions, the program will hang when partial processes are performing
36+
:meth:`File.enddef` is automatically embedded in all data mode
37+
methods, the program will hang when partial processes are performing
3938
independent I/O (while others don't) because :meth:`File.enddef` is a
4039
collective call which requires all processes to participate.
4140

src/pnetcdf/_Dimension.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ cdef class Dimension:
8989

9090
def __str__(self):
9191
if not dir(self._file):
92-
return 'Dimension object no longer valid'
92+
return 'Dimension is not valid'
9393
if self.isunlimited():
9494
return "%r (unlimited): name = '%s', size = %s" %\
9595
(type(self), self._name, len(self))
@@ -110,8 +110,7 @@ cdef class Dimension:
110110
"""
111111
getfile(self)
112112
113-
:return: the ``pnetcdf.File`` instance that this ``Dimension`` is a
114-
member of.
113+
:return: the ``pnetcdf.File`` instance that this ``Dimension`` belongs to.
115114
116115
:rtype: :class:`pnetcdf.File`
117116
"""

src/pnetcdf/_File.pyx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cdef class File:
6363
:type comm: mpi4py.MPI.Comm or None
6464
6565
:param info: [Optional]
66-
MPI info object to use for file access. `None` defaults to
66+
MPI info instance to use for file access. `None` defaults to
6767
``MPI_INFO_NULL``.
6868
:type info: mpi4py.MPI.Info or None
6969
@@ -178,7 +178,7 @@ cdef class File:
178178

179179

180180
def __dealloc__(self):
181-
# close file when there are no references to object left
181+
# close file when there are no references to it left
182182
if self._isopen:
183183
self._close(False)
184184

@@ -296,8 +296,8 @@ cdef class File:
296296
must be a positive integer or `-1`, which stands for "unlimited"
297297
(default is `-1`). The return value is the `Dimension` class instance
298298
describing the new dimension. To determine the current maximum size of
299-
the dimension, use the `len` function on the `Dimension` instance. To
300-
determine if a dimension is 'unlimited', use the
299+
the dimension, use the python function `len()` on the `Dimension`
300+
instance. To determine if a dimension is 'unlimited', use the
301301
:meth:`Dimension.isunlimited` method of the `Dimension` instance.
302302
303303
:param str dimname: Name of the new dimension.
@@ -454,7 +454,7 @@ cdef class File:
454454
# # containing all the netCDF attribute name/value pairs is provided by
455455
# # the `__dict__` attribute of a `Variable` instance.
456456

457-
# # `Variable` instances behave much like array objects. Data can be
457+
# # `Variable` instances behave much like arrays. Data can be
458458
# # assigned to or retrieved from a variable with indexing and slicing
459459
# # operations on the `Variable` instance. A `Variable` instance has six
460460
# # Dataset standard attributes: `dimensions, dtype, shape, ndim, name`.
@@ -925,10 +925,10 @@ cdef class File:
925925
"""
926926
set_auto_chartostring(self, value)
927927
928-
Call :meth:`Variable.set_auto_chartostring` for all variables
929-
contained in this `File`. Calling this function only affects existing
930-
variables. Variables defined after calling this function will follow
931-
the default behaviour.
928+
Call :meth:`Variable.set_auto_chartostring` for all variables contained
929+
in this `File`. Calling this method only affects existing variables.
930+
Variables defined after calling this method will follow the default
931+
behaviour.
932932
933933
:param value: True or False
934934
:type value: bool
@@ -1026,7 +1026,7 @@ cdef class File:
10261026
"""
10271027
inq_info(self)
10281028
1029-
Returns an MPI info object containing all the file hints used by
1029+
Returns an MPI info instance containing all the file hints used by
10301030
PnetCDF library.
10311031
10321032
:rtype: mpi4py.MPI.Info
@@ -1106,7 +1106,7 @@ cdef class File:
11061106
return extent
11071107

11081108
cdef _get_dims(file):
1109-
# Private function to create `Dimension` instances for all the
1109+
# Private method to create `Dimension` instances for all the
11101110
# dimensions in a `File`
11111111
cdef int ierr, numdims, n, _file_id
11121112
cdef int *dimids
@@ -1132,7 +1132,7 @@ cdef _get_dims(file):
11321132
return dimensions
11331133

11341134
cdef _get_variables(file):
1135-
# Private function to create `Variable` instances for all the
1135+
# Private method to create `Variable` instances for all the
11361136
# variables in a `File`
11371137
cdef int ierr, numvars, n, nn, numdims, varid, classp, iendian, _file_id
11381138
cdef int *varids

src/pnetcdf/_Variable.pyx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ ctypedef MPI.Datatype Datatype
3434
cdef class Variable:
3535
"""
3636
A PnetCDF variable is used to read and write netCDF data. They are
37-
analogous to numpy array objects. See :meth:`Variable.__init__` for more
38-
details.
37+
analogous to numpy arrays. See :meth:`Variable.__init__` for more details.
3938
4039
.. note:: ``Variable`` instances should be created using the
4140
:meth:`File.def_var` method of a :meth:`File` instance, not using this
@@ -102,7 +101,7 @@ cdef class Variable:
102101
self._file = file
103102
_file_id = self._file_id
104103
#TODO: decide whether we need to check xtype at python-level
105-
if isinstance(datatype, str): # convert to numpy datatype object
104+
if isinstance(datatype, str): # convert to numpy data type object
106105
datatype = np.dtype(datatype)
107106
if isinstance(datatype, np.dtype):
108107
if datatype.str[1:] in _supportedtypes:
@@ -161,7 +160,8 @@ cdef class Variable:
161160

162161
def __array__(self):
163162
# numpy special method that returns a numpy array.
164-
# allows numpy ufuncs to work faster on Variable objects
163+
# This allows numpy Universal functions ufuncs to work faster on
164+
# Variable instances.
165165
return self[...]
166166

167167
def __repr__(self):
@@ -526,11 +526,10 @@ cdef class Variable:
526526
self.chartostring = bool(chartostring)
527527

528528
def __getitem__(self, elem):
529-
# This special method is used to index the netCDF variable
530-
# using the "extended slice syntax". The extended slice syntax
531-
# is a perfect match for the "start", "count" and "stride"
532-
# arguments to the ncmpi_get_var() function, and is much more easy
533-
# to use.
529+
# This special method is used to index the netCDF variable using the
530+
# "extended slice syntax". The extended slice syntax is a perfect match
531+
# for the "start", "count" and "stride" arguments to the C function
532+
# ncmpi_get_var(), and is much more easy to use.
534533
start, count, stride, put_ind =\
535534
_StartCountStride(elem,self.shape,dimensions=self.dimensions,file=self._file)
536535
datashape = _out_array_shape(count)
@@ -593,11 +592,10 @@ cdef class Variable:
593592
return data
594593

595594
def __setitem__(self, elem, data):
596-
# This special method is used to assign to the netCDF variable
597-
# using "extended slice syntax". The extended slice syntax
598-
# is a perfect match for the "start", "count" and "stride"
599-
# arguments to the ncmpi_put_var() function, and is much more easy
600-
# to use.
595+
# This special method is used to assign to the netCDF variable using
596+
# "extended slice syntax". The extended slice syntax is a perfect match
597+
# for the "start", "count" and "stride" arguments to the C function
598+
# ncmpi_put_var(), and is much more easy to use.
601599

602600
# if _Encoding is specified for a character variable, convert
603601
# numpy array of strings to a numpy array of characters with one more

0 commit comments

Comments
 (0)