Skip to content

Commit da72ae5

Browse files
committed
dev
1 parent 34652f4 commit da72ae5

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

cf/data/dask_utils.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -919,10 +919,7 @@ def cf_healpix_increase_refinement_indices(a, refinement_level, ncells):
919919
def cf_healpix_indexing_scheme(
920920
a, indexing_scheme, new_indexing_scheme, refinement_level=None
921921
):
922-
"""Change the ordering of HEALPix indices.
923-
924-
Does not change the position of each cell in the array, but
925-
redefines their indices according to the new ordering scheme.
922+
"""Change the indexing scheme of HEALPix indices.
926923
927924
K. Gorski, Eric Hivon, A. Banday, B. Wandelt, M. Bartelmann, et
928925
al.. HEALPix: A Framework for High-Resolution Discretization and
@@ -989,7 +986,7 @@ def cf_healpix_indexing_scheme(
989986
except ImportError as e:
990987
raise ImportError(
991988
f"{e}. Must install healpix (https://pypi.org/project/healpix) "
992-
"to allow the changing of the HEALPix index scheme"
989+
"for changing the HEALPix indexing scheme"
993990
)
994991

995992
a = cfdm_to_memory(a)
@@ -1094,34 +1091,36 @@ def cf_healpix_weights(a, indexing_scheme, measure=False, radius=None):
10941091
1.06263432e+13, 1.06263432e+13])
10951092
10961093
"""
1094+
if indexing_scheme != "nested_unique":
1095+
raise ValueError(
1096+
"cf_healpix_weights: Can only calulate weights for the "
1097+
"'nested_unique' indexing scheme"
1098+
)
1099+
10971100
try:
10981101
import healpix
10991102
except ImportError as e:
11001103
raise ImportError(
11011104
f"{e}. Must install healpix (https://pypi.org/project/healpix) "
1102-
"to allow the calculation of cell area weights for a HEALPix grid"
1103-
)
1104-
1105-
if indexing_scheme != "nested_unique":
1106-
raise ValueError(
1107-
"cf_healpix_weights: Can only calulate weights for the "
1108-
"'nested_unique' indexing scheme"
1105+
"for the calculation of cell area weights of a HEALPix grid"
11091106
)
11101107

11111108
a = cfdm_to_memory(a)
11121109

11131110
if a.ndim != 1:
11141111
raise ValueError(
11151112
"Can only calculate HEALPix cell area weights when the "
1116-
f"healpix_index array has one dimension. Got shape {a.shape}"
1113+
f"healpix_index array has one dimension. Got shape: {a.shape}"
11171114
)
11181115

1116+
# Each cell at refinement level N has weight x/(4**N), where ...
11191117
if measure:
1120-
# Surface area of sphere is 4*pi*(r**2)
1121-
# Number of HEALPix cells at refinement level N is 12*(4**N)
1122-
# => Area of one cell is pi*(r**2)/(3* (4**N))
1118+
# Cell weights equal cell areas. Surface area of a sphere is
1119+
# 4*pi*(r**2), number of HEALPix cells at refinement level N
1120+
# is 12*(4**N) => Area of each cell is (pi*(r**2)/3.0)/(4**N)
11231121
x = np.pi * (radius**2) / 3.0
11241122
else:
1123+
# Normalised weights
11251124
x = 1.0
11261125

11271126
orders = healpix.uniq2pix(a, nest=True)[0]
@@ -1133,8 +1132,8 @@ def cf_healpix_weights(a, indexing_scheme, measure=False, radius=None):
11331132
w = np.empty(a.shape, dtype="float64")
11341133

11351134
# For each refinement level N, put the weights (= x/4**N) into 'w'
1136-
# at the correct locations
1137-
for order, i in zip(orders, index):
1138-
w = np.where(inverse == inverse[i], x / (4**order), w)
1135+
# at the correct locations.
1136+
for N, i in zip(orders, index):
1137+
w = np.where(inverse == inverse[i], x / (4**N), w)
11391138

11401139
return w

0 commit comments

Comments
 (0)