Skip to content

Commit df183dd

Browse files
committed
Revert "Allow a halo to be added by indices and subspace"
This reverts commit 3c54287.
1 parent 3c54287 commit df183dd

File tree

13 files changed

+1084
-649
lines changed

13 files changed

+1084
-649
lines changed

cf/docstring/docstring.py

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@
8080
Whether `esmpy` logging is enabled or not is determined by
8181
`cf.regrid_logging`. If it is enabled then logging takes place
8282
after every call. By default logging is disabled.""",
83-
# subspace halos
84-
"{{subspace halos}}": """
85-
If a halo is defined via a positional argument, then each
86-
subspaced axis will be extended to include that many extra
87-
elements at each "side" of the axis. The number of extra
88-
elements will be automatically reduced if including the full
89-
amount defined by the halo would extend the subspace beyond
90-
the axis limits.""",
9183
# ----------------------------------------------------------------
9284
# Method description substitutions (3 levels of indentation)
9385
# ----------------------------------------------------------------
@@ -621,40 +613,6 @@
621613
"{{to_size: `int`, optional}}": """to_size: `int`, optional
622614
Pad the axis after so that the new axis has the given
623615
size.""",
624-
# subspace mode options
625-
"{{mode: optional}}": """mode: optional
626-
Specify the mode of operation (``mode``) and a halo to
627-
be added to the subspaced axes (``halo``) with
628-
positional arguments in format ``mode``, or ``halo``,
629-
or ``mode, halo``, or with no positional arguments at
630-
all.
631-
632-
A mode of operation is given as a `str`, and a halo as
633-
a non-negative `int` (or any object that can be
634-
converted to one):
635-
636-
============== ======================================
637-
*mode* Description
638-
============== ======================================
639-
```` If no positional arguments are
640-
provided then assume the
641-
``'compress'`` mode of operation with
642-
no halo added to the subspaced
643-
axes.
644-
645-
``mode`` Define the mode of operation with no
646-
halo added to the subspaced axes.
647-
648-
``mode, halo`` Define a mode of operation, as well as
649-
a halo to be added to the subspaced
650-
axes.
651-
652-
``halo`` Assume the ``'compress'`` mode of
653-
operation and define a halo to be
654-
added to the subspaced axes. Note that
655-
``halo`` is equivalent to
656-
``'compress', halo``.
657-
============== ======================================""",
658616
# ----------------------------------------------------------------
659617
# Method description substitutions (4 levels of indentation)
660618
# ----------------------------------------------------------------
@@ -705,42 +663,4 @@
705663
The removed CFA-netCDF file name substitution. If the
706664
substitution was not defined then an empty dictionary
707665
is returned.""",
708-
# subspace valid modes Field
709-
"{{subspace valid modes Field}}": """Valid modes are:
710-
711-
* ``'compress'`` This the default.
712-
Unselected locations are removed to create the
713-
subspace. If the result is not hyperrectangular
714-
then the minimum amount of unselected locations
715-
required to make it so will also be specially
716-
selected. Missing data is inserted at the
717-
specially selected locations, unless a halo has
718-
been defined (of any size, including 0).
719-
720-
* ``'envelope'``
721-
The subspace is the smallest hyperrectangular
722-
subspace that contains all of the selected
723-
locations. Missing data is inserted at unselected
724-
locations within the envelope, unless a halo has
725-
been defined (of any size, including 0).
726-
727-
* ``'full'``
728-
The subspace has the same domain as the original
729-
construct. Missing data is inserted at unselected
730-
locations, unless a halo has been defined (of any
731-
size, including 0).""",
732-
# subspace valid modes Domain
733-
"{{subspace valid modes Domain}}": """Valid modes are:
734-
735-
* ``'compress'`` This the default.
736-
Unselected locations are removed to create the
737-
subspace. If the result is not hyperrectangular
738-
then the minimum amount of unselected locations
739-
required to make it so will also be specially
740-
selected.
741-
742-
* ``'envelope'``
743-
The subspace is the smallest hyperrectangular
744-
subspace that contains all of the selected
745-
locations.""",
746666
}

cf/domain.py

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ def indices(self, *mode, **kwargs):
743743
"""Create indices that define a subspace of the domain
744744
construct.
745745
746-
The indices returned by this method may be used to create the
746+
The indices returned by this method be used to create the
747747
subspace by passing them to the `subspace` method of the
748748
original domain construct.
749749
@@ -778,22 +778,34 @@ def indices(self, *mode, **kwargs):
778778
may still need to be inserted into the field construct's
779779
data.
780780
781-
**Halos**
782-
783-
{{subspace halos}}
784-
785781
.. versionadded:: 3.11.0
786782
787783
.. seealso:: `subspace`, `where`, `__getitem__`,
788784
`__setitem__`, `cf.Field.indices`
789785
790786
:Parameters:
791787
792-
{{mode: optional}}
793-
794-
{{subspace valid modes Domain}}
795-
796-
kwargs: optional
788+
mode: `str`, *optional*
789+
There are two modes of operation, each of which provides
790+
indices for a different type of subspace:
791+
792+
============== ======================================
793+
*mode* Description
794+
============== ======================================
795+
``'compress'`` This is the default mode. Unselected
796+
locations are removed to create the
797+
returned subspace. Note that if a
798+
multi-dimensional metadata construct
799+
is being used to define the indices
800+
then some missing data may still be
801+
inserted at unselected locations.
802+
803+
``'envelope'`` The returned subspace is the smallest
804+
that contains all of the selected
805+
indices.
806+
============== ======================================
807+
808+
kwargs: *optional*
797809
A keyword name is an identity of a metadata construct,
798810
and the keyword value provides a condition for
799811
inferring indices that apply to the dimension (or
@@ -845,6 +857,19 @@ def indices(self, *mode, **kwargs):
845857
: time(1) = [2019-01-01 00:00:00]
846858
847859
"""
860+
if len(mode) > 1:
861+
raise ValueError(
862+
"Can't provide more than one positional argument. "
863+
f"Got: {', '.join(repr(x) for x in mode)}"
864+
)
865+
866+
if not mode or "compress" in mode:
867+
mode = "compress"
868+
elif "envelope" in mode:
869+
mode = "envelope"
870+
else:
871+
raise ValueError(f"Invalid value for 'mode' argument: {mode[0]!r}")
872+
848873
# Get the indices for every domain axis in the domain, without
849874
# any auxiliary masks.
850875
domain_indices = self._indices(mode, None, False, kwargs)
@@ -1095,19 +1120,19 @@ def roll(self, axis, shift, inplace=False):
10951120
return d
10961121

10971122
def subspace(self, *mode, **kwargs):
1098-
"""Create a subspace of the field construct.
1123+
"""Create indices that define a subspace of the domain
1124+
construct.
10991125
1100-
Creation of a new domain construct which spans a subspace of
1101-
the domain of an existing domain construct is achieved by
1102-
identifying indices based on the metadata constructs
1103-
(subspacing by metadata). The new domain construct is created
1104-
with the same properties as the original domain construct.
1126+
The indices returned by this method be used to create the subspace
1127+
by passing them to the `subspace` method of the original domain
1128+
construct.
11051129
1106-
**Subspacing by metadata**
1130+
The subspace is defined by identifying indices based on the
1131+
metadata constructs.
11071132
1108-
Subspacing by metadata selects metadata constructs and
1109-
specifies conditions on their data. Indices for subspacing are
1110-
then automatically inferred from where the conditions are met.
1133+
Metadata constructs are selected conditions are specified on their
1134+
data. Indices for subspacing are then automatically inferred from
1135+
where the conditions are met.
11111136
11121137
Metadata constructs and the conditions on their data are defined
11131138
by keyword parameters.
@@ -1117,9 +1142,6 @@ def subspace(self, *mode, **kwargs):
11171142
* Multiple domain axes may be subspaced simultaneously, and it
11181143
doesn't matter which order they are specified in.
11191144
1120-
* Subspace criteria may be provided for size 1 domain axes that
1121-
are not spanned by the field construct's data.
1122-
11231145
* Explicit indices may also be assigned to a domain axis
11241146
identified by a metadata construct, with either a Python `slice`
11251147
object, or a sequence of integers or booleans.
@@ -1134,21 +1156,41 @@ def subspace(self, *mode, **kwargs):
11341156
acting along orthogonal dimensions, some missing data may still
11351157
need to be inserted into the field construct's data.
11361158
1137-
**Halos**
1138-
1139-
{{subspace halos}}
1140-
11411159
.. versionadded:: 3.11.0
11421160
1143-
.. seealso:: `indices`, `cf.Field.subspace`
1161+
.. seealso:: `indices`
11441162
11451163
:Parameters:
11461164
1147-
{{mode: optional}}
1165+
mode: `str`, *optional*
1166+
There are two modes of operation, each of which provides
1167+
indices for a different type of subspace:
1168+
1169+
============== ==========================================
1170+
*mode* Description
1171+
============== ==========================================
1172+
``'compress'`` Return indices that identify only the
1173+
requested locations.
1174+
1175+
This is the default mode.
1176+
1177+
Note that if a multi-dimensional metadata
1178+
construct is being used to define the
1179+
indices then some unrequested locations
1180+
may also be selected.
1181+
1182+
``'envelope'`` The returned subspace is the smallest that
1183+
contains all of the requested locations.
11481184
1149-
{{subspace valid modes Domain}}
1185+
``'test'`` May be used on its own or in addition to
1186+
one of the other positional arguments. Do
1187+
not create a subspace, but return `True`
1188+
or `False` depending on whether or not it
1189+
is possible to create the specified
1190+
subspace.
1191+
============== ==========================================
11501192
1151-
kwargs: optional
1193+
kwargs: *optional*
11521194
A keyword name is an identity of a metadata construct, and
11531195
the keyword value provides a condition for inferring
11541196
indices that apply to the dimension (or dimensions)

0 commit comments

Comments
 (0)