Skip to content

Commit 3e1e3c7

Browse files
committed
subspace docstring
1 parent 6121429 commit 3e1e3c7

File tree

2 files changed

+87
-33
lines changed

2 files changed

+87
-33
lines changed

cf/field.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13270,8 +13270,6 @@ def subspace(self):
1327013270
``3:-2:-1``) is assumed to "wrap" around, rather then producing
1327113271
a null result.
1327213272

13273-
.. seealso:: `indices`, `squeeze`, `where`, `__getitem__`
13274-
1327513273
**Halos**
1327613274

1327713275
{{subspace halos}}

cf/subspacefield.py

Lines changed: 87 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class SubspaceField(mixin.Subspace):
5-
"""Create a subspace of a field construct.
5+
"""Create a subspace of the field construct.
66
77
Creation of a new field construct which spans a subspace of the
88
domain of an existing field construct is achieved either by
@@ -70,37 +70,86 @@ class SubspaceField(mixin.Subspace):
7070
``3:-2:-1``) is assumed to "wrap" around, rather then producing
7171
a null result.
7272
73-
.. seealso:: `cf.Field.indices`, `cf.Field.squeeze`,
74-
`cf.Field.where`
73+
**Halos**
74+
75+
If a halo is defined via a positional argument, then each
76+
subspaced axis will be extended to include that many extra
77+
elements at each "side" of the axis. The number of extra elements
78+
will be automatically reduced if including the full amount defined
79+
by the halo would extend the subspace beyond the axis limits.
80+
81+
For instance, ``f.subspace(X=slice(10, 20))`` will give identical
82+
results to each of ``f.subspace(0, X=slice(10, 20))``,
83+
``f.subspace(1, X=slice(11, 19))``, ``f.subspace(2, X=slice(12,
84+
18))``, etc.
85+
86+
.. seealso:: `cf.Field.indices`, `cf.Field.where`,
87+
`cf.Field.__getitem__`, `cf.Field.__setitem__`,
88+
`cf.Domain.subspace`
7589
7690
:Parameters:
7791
78-
positional arguments: *optional*
79-
There are three modes of operation, each of which provides
80-
a different type of subspace:
81-
82-
============== ==========================================
83-
*argument* Description
84-
============== ==========================================
85-
``'compress'`` This is the default mode. Unselected
86-
locations are removed to create the
87-
returned subspace. Note that if a
88-
multi-dimensional metadata construct is
89-
being used to define the indices then some
90-
missing data may still be inserted at
91-
unselected locations.
92-
93-
``'envelope'`` The returned subspace is the smallest that
94-
contains all of the selected
95-
indices. Missing data is inserted at
96-
unselected locations within the envelope.
97-
98-
``'full'`` The returned subspace has the same domain
99-
as the original field construct. Missing
100-
data is inserted at unselected locations.
101-
============== ==========================================
102-
103-
keyword parameters: *optional*
92+
mode: optional
93+
Specify the mode of operation (``mode``) and a halo to be
94+
added to the subspaced axes (``halo``) with positional
95+
arguments in format ``mode``, or ``halo``, or ``mode,
96+
halo``, or with no positional arguments at all.
97+
98+
A mode of operation is given as a `str`, and a halo as a
99+
non-negative `int` (or any object that can be converted to
100+
one):
101+
102+
============== ======================================
103+
*mode* Description
104+
============== ======================================
105+
Not provided If no positional arguments are
106+
provided then assume the
107+
``'compress'`` mode of operation with
108+
no halo added to the subspaced axes.
109+
110+
``mode`` Define the mode of operation with no
111+
halo added to the subspaced axes.
112+
113+
``mode, halo`` Define a mode of operation, as well as
114+
a halo to be added to the subspaced
115+
axes.
116+
117+
``halo`` Assume the ``'compress'`` mode of
118+
operation and define a halo to be
119+
added to the subspaced axes.
120+
============== ======================================
121+
122+
Valid modes are:
123+
124+
* ``'compress'`` This is the default.
125+
Unselected locations are removed to create the
126+
subspace. If the result is not hyperrectangular then
127+
the minimum amount of unselected locations required
128+
to make it so will also be specially
129+
selected. Missing data is inserted at the specially
130+
selected locations, unless a halo has been defined
131+
(of any size, including 0).
132+
133+
* ``'envelope'``
134+
The subspace is the smallest hyperrectangular
135+
subspace that contains all of the selected
136+
locations. Missing data is inserted at unselected
137+
locations within the envelope, unless a halo has been
138+
defined (of any size, including 0).
139+
140+
* ``'full'``
141+
The subspace has the same domain as the original
142+
construct. Missing data is inserted at unselected
143+
locations, unless a halo has been defined (of any
144+
size, including 0).
145+
146+
In addition, an extra positional argument of ``'test'`` is
147+
allowed. When provided, the subspace is not returned,
148+
instead `True` or `False` is returned depending on whether
149+
or not it is possible for the requested subspace to be
150+
created.
151+
152+
keyword parameters: optional
104153
A keyword name is an identity of a metadata construct, and
105154
the keyword value provides a condition for inferring
106155
indices that apply to the dimension (or dimensions)
@@ -110,9 +159,12 @@ class SubspaceField(mixin.Subspace):
110159
111160
:Returns:
112161
113-
`Field`
162+
`Field` or `bool`
114163
An independent field construct containing the subspace of
115-
the original field.
164+
the original field. If the ``'test'`` positional argument
165+
has been set then return `True` or `False` depending on
166+
whether or not it is possible to create specified
167+
subspace.
116168
117169
**Examples**
118170
@@ -190,6 +242,10 @@ def __call__(self, *args, **kwargs):
190242
acting along orthogonal dimensions, some missing data may still
191243
need to be inserted into the field construct's data.
192244
245+
**Halos**
246+
247+
{{subspace halos}}
248+
193249
.. seealso:: `cf.Field.indices`, `cf.Field.squeeze`,
194250
`cf.Field.where`
195251

0 commit comments

Comments
 (0)