@@ -743,7 +743,7 @@ def indices(self, *mode, **kwargs):
743
743
"""Create indices that define a subspace of the domain
744
744
construct.
745
745
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
747
747
subspace by passing them to the `subspace` method of the
748
748
original domain construct.
749
749
@@ -778,22 +778,34 @@ def indices(self, *mode, **kwargs):
778
778
may still need to be inserted into the field construct's
779
779
data.
780
780
781
- **Halos**
782
-
783
- {{subspace halos}}
784
-
785
781
.. versionadded:: 3.11.0
786
782
787
783
.. seealso:: `subspace`, `where`, `__getitem__`,
788
784
`__setitem__`, `cf.Field.indices`
789
785
790
786
:Parameters:
791
787
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*
797
809
A keyword name is an identity of a metadata construct,
798
810
and the keyword value provides a condition for
799
811
inferring indices that apply to the dimension (or
@@ -845,6 +857,19 @@ def indices(self, *mode, **kwargs):
845
857
: time(1) = [2019-01-01 00:00:00]
846
858
847
859
"""
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
+
848
873
# Get the indices for every domain axis in the domain, without
849
874
# any auxiliary masks.
850
875
domain_indices = self ._indices (mode , None , False , kwargs )
@@ -1095,19 +1120,19 @@ def roll(self, axis, shift, inplace=False):
1095
1120
return d
1096
1121
1097
1122
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.
1099
1125
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.
1105
1129
1106
- **Subspacing by metadata**
1130
+ The subspace is defined by identifying indices based on the
1131
+ metadata constructs.
1107
1132
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.
1111
1136
1112
1137
Metadata constructs and the conditions on their data are defined
1113
1138
by keyword parameters.
@@ -1117,9 +1142,6 @@ def subspace(self, *mode, **kwargs):
1117
1142
* Multiple domain axes may be subspaced simultaneously, and it
1118
1143
doesn't matter which order they are specified in.
1119
1144
1120
- * Subspace criteria may be provided for size 1 domain axes that
1121
- are not spanned by the field construct's data.
1122
-
1123
1145
* Explicit indices may also be assigned to a domain axis
1124
1146
identified by a metadata construct, with either a Python `slice`
1125
1147
object, or a sequence of integers or booleans.
@@ -1134,21 +1156,41 @@ def subspace(self, *mode, **kwargs):
1134
1156
acting along orthogonal dimensions, some missing data may still
1135
1157
need to be inserted into the field construct's data.
1136
1158
1137
- **Halos**
1138
-
1139
- {{subspace halos}}
1140
-
1141
1159
.. versionadded:: 3.11.0
1142
1160
1143
- .. seealso:: `indices`, `cf.Field.subspace`
1161
+ .. seealso:: `indices`
1144
1162
1145
1163
:Parameters:
1146
1164
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.
1148
1184
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
+ ============== ==========================================
1150
1192
1151
- kwargs: optional
1193
+ kwargs: * optional*
1152
1194
A keyword name is an identity of a metadata construct, and
1153
1195
the keyword value provides a condition for inferring
1154
1196
indices that apply to the dimension (or dimensions)
0 commit comments