@@ -4824,7 +4824,7 @@ def healpix_decrease_refinement_level(
48244824 refinement level either
48254825
48264826 * contains no original cells, in which case that larger cell
4827- is not included in the output,
4827+ is not included in the output;
48284828
48294829 or
48304830
@@ -4868,20 +4868,24 @@ def healpix_decrease_refinement_level(
48684868 ``'root_mean_square'``, ``'standard_deviation'``,
48694869 ``'sum'``, ``'sum_of_squares'``, ``'variance'``.
48704870
4871- The method should be appropriate to nature of the
4872- Field quantity, which is either intensive (i.e. that
4873- does not depend on the size of the cells, such as
4874- "sea_ice_amount" with units of kg m-2), or extensive
4875- (i.e. that depends on the size of the cells, such as
4876- "sea_ice_mass" with units of kg).
4871+ .. note:: The method should be appropriate to nature
4872+ of the Field quantity, which is either
4873+ intensive (i.e. that does not depend on the
4874+ size of the cells, such as "sea_ice_amount"
4875+ with units of kg m-2), or extensive
4876+ (i.e. that depends on the size of the cells,
4877+ such as "sea_ice_mass" with units of kg).
48774878
48784879 reduction: function or `None`, optional
48794880 The function used to calculate the values in the new
48804881 larger cells, from the data on the original cells. The
4881- function must i) calculate the quantity defined by the
4882- *method* parameter, ii) take an array of values as its
4883- first argument, and iii) have an *axis* keyword that
4884- specifies which of the array axes is the HEALPix axis.
4882+ function must:
4883+
4884+ * calculate the quantity defined by the *method*
4885+ parameter,
4886+ * take an array of values as its first argument,
4887+ * have an *axis* keyword that specifies which of the
4888+ array axes is the HEALPix axis.
48854889
48864890 For some methods there are default *reduction*
48874891 functions, which are only used when *reduction* is
@@ -4907,11 +4911,11 @@ def healpix_decrease_refinement_level(
49074911 If True (the default) then the HEALPix grid is
49084912 automatically converted to a form suitable for having
49094913 its refinement level changed, i.e. the indexing scheme
4910- is changed to ' nested' and the HEALPix axis is sorted
4911- so that the nested HEALPix indices are monotonically
4912- increasing. If False then either an exception is
4913- raised if the HEALPix indexing scheme is not already
4914- 'nested', or else the HEALPix axis is not sorted.
4914+ is changed to nested and the HEALPix axis is sorted so
4915+ that the nested HEALPix indices are monotonically
4916+ increasing. If False then an exception is raised if
4917+ the HEALPix indexing scheme is not already nested and
4918+ the HEALPix axis is not sorted.
49154919
49164920 .. note:: Setting to False will speed up the operation
49174921 when the HEALPix indexing scheme is already
@@ -4924,12 +4928,12 @@ def healpix_decrease_refinement_level(
49244928 (but after the HEALPix grid has been conformed, when
49254929 *conform* is True):
49264930
4927- 1. The nested HEALPix indices are strictly
4928- monotonically increasing.
4931+ * The nested HEALPix indices are strictly
4932+ monotonically increasing.
49294933
4930- 2. Every cell at the new lower refinement level
4931- contains zero or the maximum possible number of
4932- cells at the original refinement level.
4934+ * Every cell at the new lower refinement level
4935+ contains zero or the maximum possible number of
4936+ cells at the original refinement level.
49334937
49344938 If False then these checks are not carried out.
49354939
@@ -4938,14 +4942,16 @@ def healpix_decrease_refinement_level(
49384942 advance that these conditions are
49394943 satisfied. If set to False and any of the
49404944 conditions are not met then either an
4941- exception may be raised or, **much
4945+ exception will be raised or, **much
49424946 worse**, the operation could complete and
49434947 return incorrect data values.
49444948
49454949 :Returns:
49464950
49474951 `Field`
4948- A new Field with the new HEALPix grid.
4952+ A new Field with the new HEALPix grid. The HEALPix
4953+ indices of this field will follow the nested indexing
4954+ scheme.
49494955
49504956 **Examples**
49514957
@@ -5084,6 +5090,7 @@ def healpix_decrease_refinement_level(
50845090
50855091 # Re-get the HEALPix info
50865092 hp = f.healpix_info()
5093+
50875094 elif indexing_scheme != "nested":
50885095 raise ValueError(
50895096 f"Can't decrease HEALPix refinement level of {f!r}: "
@@ -5149,7 +5156,13 @@ def healpix_decrease_refinement_level(
51495156
51505157 # Get the HEALPix axis
51515158 axis = hp["domain_axis_key"]
5152- iaxis = f.get_data_axes().index(axis)
5159+ try:
5160+ iaxis = f.get_data_axes().index(axis)
5161+ except ValueError:
5162+ # The Field data doesn't span the size 1 HEALPix axis, so
5163+ # insert it on the left hand side.
5164+ f.insert_dimmension(axis, -1, inplace=True)
5165+ iaxis = f.ndim - 1
51535166
51545167 # Whether or not to create lat/lon coordinates for the new
51555168 # refinement level. Only do so if the original grid has
@@ -5169,7 +5182,7 @@ def healpix_decrease_refinement_level(
51695182 # ------------------------------------------------------------
51705183
51715184 # Note: Using 'Data.coarsen' works because a) the HEALPix
5172- # indexing scheme is now " nested" , and b) we know that
5185+ # indexing scheme is now nested, and b) we know that
51735186 # each new coarser cell contains the maximum possible
51745187 # number (i.e. 'ncells') of original cells.
51755188 f.data.coarsen(
@@ -5263,7 +5276,7 @@ def healpix_increase_refinement_level(self, refinement_level, quantity):
52635276 extensive or intensive quantity. An intensive quantity does
52645277 not depend on the size of the cells (such as "sea_ice_amount"
52655278 with units of kg m-2, or "air_temperature" with units of K),
5266- and an extensive quantity depends on the size of the cells
5279+ and an extensive quantity does depend on the size of the cells
52675280 (such as "sea_ice_mass" with units of kg, or "cell_area" with
52685281 units of m2). For an extensive quantity only, the broadcast
52695282 values are reduced to be consistent with the new smaller cell
@@ -5294,7 +5307,9 @@ def healpix_increase_refinement_level(self, refinement_level, quantity):
52945307 :Returns:
52955308
52965309 `Field`
5297- A new Field with the new HEALPix grid.
5310+ A new Field with the new HEALPix grid. The HEALPix
5311+ indices of this field will follow the nested indexing
5312+ scheme.
52985313
52995314 **Examples**
53005315
0 commit comments