@@ -199,30 +199,35 @@ def _healpix_increase_refinement_level(x, ncells, iaxis, quantity):
199199 """
200200 from dask .array .core import normalize_chunks
201201
202- # Get the Dask array.
202+ # Get the Dask array (e.g. dx.shape is (12, 19, 48))
203203 dx = x .data .to_dask_array (_force_mask_hardness = False )
204204
205205 # Divide extensive data by the number of new cells
206206 if quantity == "extensive" :
207207 dx = dx / ncells
208208
209209 # Add a new size dimension just after the HEALPix dimension
210+ # (e.g. .shape becomes (12, 19, 48, 1))
210211 new_axis = iaxis + 1
211212 dx = da .expand_dims (dx , new_axis )
212213
213- # Work out what the chunks should be for the new dimension
214+ # Modify the size of the new dimension to be the number of cells
215+ # at the new refinement level which are contained in one cell at
216+ # the original refinement level (e.g. size becomes 16)
214217 shape = list (dx .shape )
215218 shape [new_axis ] = ncells
216219
220+ # Work out what the chunks should be for the new dimension
217221 chunks = list (dx .chunks )
218222 chunks [new_axis ] = "auto"
219223 chunks = normalize_chunks (chunks , shape , dtype = dx .dtype )
220224
221- # Broadcast the data along the new dimension
225+ # Broadcast the data along the new dimension (e.g. dx.shape
226+ # becomes (12, 19, 48, 16))
222227 dx = da .broadcast_to (dx , shape , chunks = chunks )
223228
224229 # Reshape the array so that it has a single, larger HEALPix
225- # dimension
230+ # dimension (e.g. dx.shape becomes (12, 19, 768))
226231 dx = dx .reshape (
227232 shape [:iaxis ]
228233 + [shape [iaxis ] * shape [new_axis ]]
@@ -272,7 +277,7 @@ def _healpix_increase_refinement_level_indices(
272277 # Get any cached data values
273278 cached = healpix_index .data ._get_cached_elements ().copy ()
274279
275- # Get the Dask array
280+ # Get the Dask array (e.g. dx.shape is (48,))
276281 dx = healpix_index .data .to_dask_array (_force_mask_hardness = False )
277282
278283 # Set the data type to allow for the largest possible HEALPix
@@ -286,18 +291,23 @@ def _healpix_increase_refinement_level_indices(
286291 dx = dx * ncells
287292
288293 # Add a new size dimension just after the HEALPix dimension
294+ # (e.g. .shape becomes (48, 1))
289295 new_axis = 1
290296 dx = da .expand_dims (dx , new_axis )
291297
292- # Work out what the chunks should be for the new dimension
298+ # Modify the size of the new dimension to be the number of cells
299+ # at the new refinement level which are contained in one cell at
300+ # the original refinement level (e.g. size becomes 16)
293301 shape = list (dx .shape )
294302 shape [new_axis ] = ncells
295303
304+ # Work out what the chunks should be for the new dimension
296305 chunks = list (dx .chunks )
297306 chunks [new_axis ] = "auto"
298307 chunks = normalize_chunks (chunks , shape , dtype = dx .dtype )
299308
300- # Broadcast the data along the new dimension
309+ # Broadcast the data along the new dimension (e.g. dx.shape
310+ # becomes (48, 16))
301311 dx = da .broadcast_to (dx , shape , chunks = chunks )
302312
303313 # Increment the broadcast values along the new dimension, so that
@@ -306,10 +316,12 @@ def _healpix_increase_refinement_level_indices(
306316 # original refinement level.
307317 new_shape = [1 ] * dx .ndim
308318 new_shape [new_axis ] = shape [new_axis ]
319+
309320 dx += da .arange (ncells , chunks = chunks [new_axis ]).reshape (new_shape )
310321
311322 # Reshape the new array to combine the original HEALPix and
312323 # broadcast dimensions into a single new HEALPix dimension
324+ # (e.g. dx.shape becomes (768,))
313325 dx = dx .reshape (shape [0 ] * shape [new_axis ])
314326
315327 healpix_index .set_data (dx , copy = False )
@@ -324,8 +336,6 @@ def _healpix_increase_refinement_level_indices(
324336 x = np .array (cached [- 1 ], dtype = dtype ) * ncells + (ncells - 1 )
325337 data ._set_cached_elements ({- 1 : x })
326338
327- return
328-
329339
330340def _healpix_indexing_scheme (healpix_index , hp , new_indexing_scheme ):
331341 """Change the indexing scheme of HEALPix indices in-place.
0 commit comments