Skip to content

Commit 415a055

Browse files
committed
dev
1 parent 38cb64d commit 415a055

8 files changed

Lines changed: 91 additions & 84 deletions

File tree

cf/data/dask_utils.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ def cf_healpix_bounds(
469469
a,
470470
indexing_scheme,
471471
refinement_level=None,
472-
lat=False,
473-
lon=False,
472+
latitude=False,
473+
longitude=False,
474474
pole_longitude=None,
475475
):
476476
"""Calculate HEALPix cell bounds.
@@ -511,10 +511,10 @@ def cf_healpix_bounds(
511511
``'nested_unique'`` (in which case *refinement_level* may
512512
be `None`).
513513
514-
lat: `bool`, optional
514+
latitude: `bool`, optional
515515
If True then return latitude bounds.
516516
517-
lon: `bool`, optional
517+
longitude: `bool`, optional
518518
If True then return longitude bounds.
519519
520520
pole_longitude: `None` or number
@@ -532,21 +532,21 @@ def cf_healpix_bounds(
532532
**Examples**
533533
534534
>>> cf.data.dask_utils.cf_healpix_bounds(
535-
... np.array([0, 1, 2, 3]), 'nested', 1, lat=True
535+
... np.array([0, 1, 2, 3]), 'nested', 1, latitude=True
536536
)
537537
array([[41.8103149 , 19.47122063, 0. , 19.47122063],
538538
[66.44353569, 41.8103149 , 19.47122063, 41.8103149 ],
539539
[66.44353569, 41.8103149 , 19.47122063, 41.8103149 ],
540540
[90. , 66.44353569, 41.8103149 , 66.44353569]])
541541
>>> cf.data.dask_utils.cf_healpix_bounds(
542-
... np.array([0, 1, 2, 3]), 'nested', 1, lon=True
542+
... np.array([0, 1, 2, 3]), 'nested', 1, longitude=True
543543
)
544544
array([[45. , 22.5, 45. , 67.5],
545545
[90. , 45. , 67.5, 90. ],
546546
[ 0. , 0. , 22.5, 45. ],
547547
[45. , 0. , 45. , 90. ]])
548548
>>> cf.data.dask_utils.cf_healpix_bounds(
549-
... np.array([0, 1, 2, 3]), 'nested', 1, lon=True,
549+
... np.array([0, 1, 2, 3]), 'nested', 1, longitude=True,
550550
... pole_longitude=3.14159
551551
)
552552
array([[45. , 22.5 , 45. , 67.5 ],
@@ -573,9 +573,9 @@ def cf_healpix_bounds(
573573
f"healpix_index array has one dimension. Got shape {a.shape}"
574574
)
575575

576-
if lat:
576+
if latitude:
577577
pos = 1
578-
elif lon:
578+
elif longitude:
579579
pos = 0
580580

581581
if indexing_scheme == "ring":
@@ -639,7 +639,7 @@ def cf_healpix_bounds(
639639

640640

641641
def cf_healpix_coordinates(
642-
a, indexing_scheme, refinement_level=None, lat=False, lon=False
642+
a, indexing_scheme, refinement_level=None, latitude=False, longitude=False
643643
):
644644
"""Calculate HEALPix cell centre coordinates.
645645
@@ -674,10 +674,10 @@ def cf_healpix_coordinates(
674674
``'nested_unique'`` (in which case *refinement_level* may
675675
be `None`).
676676
677-
lat: `bool`, optional
677+
latitude: `bool`, optional
678678
If True then return latitude coordinates.
679679
680-
lon: `bool`, optional
680+
longitude: `bool`, optional
681681
If True then return longitude coordinates.
682682
683683
:Returns:
@@ -688,11 +688,11 @@ def cf_healpix_coordinates(
688688
**Examples**
689689
690690
>>> cf.data.dask_utils.cf_healpix_coordinates(
691-
... np.array([0, 1, 2, 3]), 'nested', 1, lat=True
691+
... np.array([0, 1, 2, 3]), 'nested', 1, latitude=True
692692
)
693693
array([19.47122063, 41.8103149 , 41.8103149 , 66.44353569])
694694
>>> cf.data.dask_utils.cf_healpix_coordinates(
695-
... np.array([0, 1, 2, 3]), 'nested', 1, lon=True
695+
... np.array([0, 1, 2, 3]), 'nested', 1, longitude=True
696696
)
697697
array([45. , 67.5, 22.5, 45. ])
698698
@@ -714,9 +714,9 @@ def cf_healpix_coordinates(
714714
f"healpix_index array has one dimension. Got shape {a.shape}"
715715
)
716716

717-
if lat:
717+
if latitude:
718718
pos = 1
719-
elif lon:
719+
elif longitude:
720720
pos = 0
721721

722722
match indexing_scheme:

cf/docstring/docstring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
M. Reinecke and E. Hivon: Efficient data structures for masks
9999
on 2D grids. A&A, 580 (2015)
100100
A132. https://doi.org/10.1051/0004-6361/201526549""",
101-
# ----------------------------------------------------------------
101+
# ----------------------------------------------------------------
102102
# Method description substitutions (3 levels of indentation)
103103
# ----------------------------------------------------------------
104104
# i: deprecated at version 3.0.0

cf/domain.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ def create_healpix(
273273
HEALPix indices are monotonically increasing.
274274
275275
**References**
276-
276+
277277
{{HEALPix references}}
278-
278+
279279
.. versionadded:: NEXTVERSION
280280
281281
.. seealso:: `cf.Domain.create_regular`,
@@ -404,20 +404,23 @@ def create_healpix(
404404
axis = domain.set_construct(d, copy=False)
405405

406406
# auxiliary_coordinate: healpix_index
407-
c = domain._AuxiliaryCoordinate()
407+
c = domain._DimensionCoordinate()
408408
c.set_properties({"standard_name": "healpix_index"})
409409
c.nc_set_variable("healpix_index")
410410

411411
# Create the healpix_index data
412412
if nested_unique:
413-
index0 = 4 ** (refinement_level + 1)
413+
start = 4 ** (refinement_level + 1)
414414
else:
415-
index0 = 0
415+
start = 0
416416

417-
c.set_data(
418-
Data(da.arange(index0, index0 + ncells), units="1"), copy=False
419-
)
417+
stop = start + ncells
418+
data = Data(da.arange(start, stop), units="1")
419+
420+
# Set cached data elements
421+
data._set_cached_elements({0: start, -1: stop - 1})
420422

423+
c.set_data(data, copy=False)
421424
key = domain.set_construct(c, axes=axis, copy=False)
422425

423426
# coordinate_reference: grid_mapping_name:healpix

cf/field.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@
180180
# --------------------------------------------------------------------
181181
_collapse_ddof_methods = set(("sd", "var"))
182182

183-
# _earth_radius = Data(6371229.0, "m")
184-
185183
_relational_methods = (
186184
"__eq__",
187185
"__ne__",
@@ -4855,7 +4853,7 @@ def healpix_decrease_refinement_level(
48554853
is raised (assuming that *check_healpix_index* is True).
48564854

48574855
**References**
4858-
4856+
48594857
{{HEALPix references}}
48604858

48614859
.. versionadded:: NEXTVERSION
@@ -5227,12 +5225,6 @@ def healpix_decrease_refinement_level(
52275225
# ------------------------------------------------------------
52285226
# Change the refinement level of the healpix_index coordinates
52295227
# ------------------------------------------------------------
5230-
if healpix_index.construct_type == "dimension_coordinate":
5231-
# Ensure that healpix indices are auxiliary coordinates
5232-
healpix_index = f._AuxiliaryCoordinate(
5233-
source=healpix_index, copy=False
5234-
)
5235-
52365228
healpix_index = healpix_index[::ncells] // ncells
52375229
hp_key = f.set_construct(healpix_index, axes=axis, copy=False)
52385230

@@ -5279,7 +5271,7 @@ def healpix_increase_refinement_level(self, refinement_level, quantity):
52795271
values are not changed.
52805272

52815273
**References**
5282-
5274+
52835275
{{HEALPix references}}
52845276

52855277
.. versionadded:: NEXTVERSION
@@ -5536,11 +5528,6 @@ def healpix_increase_refinement_level(self, refinement_level, quantity):
55365528
# Create the healpix_index coordinates for the new refinement
55375529
# level, and put them into the Field.
55385530
healpix_index = hp["healpix_index"]
5539-
if healpix_index.construct_type == "dimension_coordinate":
5540-
# Ensure that healpix indices are auxiliary coordinates
5541-
healpix_index = f._AuxiliaryCoordinate(
5542-
source=healpix_index, copy=False
5543-
)
55445531

55455532
# Save any cached data elements
55465533
data = healpix_index.data
@@ -5589,7 +5576,8 @@ def healpix_increase_refinement_level(self, refinement_level, quantity):
55895576
cr.set_coordinate(hp_key)
55905577

55915578
if create_latlon:
5592-
# Create lat/lon coordinates for the new refinement level
5579+
# Create 1-d lat/lon coordinates for the new refinement
5580+
# level
55935581
f.create_latlon_coordinates(two_d=False, inplace=True)
55945582

55955583
return f
@@ -6025,7 +6013,9 @@ def collapse(
60256013
.. versionadded:: 1.0
60266014

60276015
.. seealso:: `bin`, `cell_area`, `convolution_filter`,
6028-
`moving_window`, `radius`, `weights`
6016+
`moving_window`,
6017+
`healpix_decrease_refinement_level`, `radius`,
6018+
`weights`
60296019

60306020
:Parameters:
60316021

@@ -7621,7 +7611,9 @@ def collapse(
76217611
f.del_coordinate_reference(ref_key)
76227612

76237613
# --------------------------------------------------------
7624-
# Remove a HEALPix coordinate reference
7614+
# Remove a HEALPix Coordinate Reference and Dimension
7615+
# Coordinate. (A HEALPix Auxiliary Coordinate gets removed
7616+
# later with the other 1-d Auxiliary Coordinates.)
76257617
# --------------------------------------------------------
76267618
healpix_axis = f.domain_axis(
76277619
"healpix_index", key=True, default=None
@@ -7632,6 +7624,12 @@ def collapse(
76327624

76337625
del_healpix_coordinate_reference(f)
76347626

7627+
key = f.dimension_coordinate(
7628+
"healpix_index", key=True, default=None
7629+
)
7630+
if key is not None:
7631+
f.del_construct(key)
7632+
76357633
# ---------------------------------------------------------
76367634
# Update dimension coordinates, auxiliary coordinates,
76377635
# cell measures and domain ancillaries

cf/healpix.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _healpix_create_latlon_coordinates(f, pole_longitude):
9696
meta=meta,
9797
indexing_scheme=indexing_scheme,
9898
refinement_level=refinement_level,
99-
lat=True,
99+
latitude=True,
100100
)
101101
lat = f._AuxiliaryCoordinate(
102102
data=f._Data(dy, "degrees_north", copy=False),
@@ -110,7 +110,7 @@ def _healpix_create_latlon_coordinates(f, pole_longitude):
110110
meta=meta,
111111
indexing_scheme=indexing_scheme,
112112
refinement_level=refinement_level,
113-
lon=True,
113+
longitude=True,
114114
)
115115
lon = f._AuxiliaryCoordinate(
116116
data=f._Data(dy, "degrees_east", copy=False),
@@ -128,7 +128,7 @@ def _healpix_create_latlon_coordinates(f, pole_longitude):
128128
meta=meta,
129129
indexing_scheme=indexing_scheme,
130130
refinement_level=refinement_level,
131-
lat=True,
131+
latitude=True,
132132
)
133133
bounds = f._Bounds(data=dy)
134134
lat.set_bounds(bounds)
@@ -143,7 +143,7 @@ def _healpix_create_latlon_coordinates(f, pole_longitude):
143143
meta=meta,
144144
indexing_scheme=indexing_scheme,
145145
refinement_level=refinement_level,
146-
lon=True,
146+
longitude=True,
147147
pole_longitude=pole_longitude,
148148
)
149149
bounds = f._Bounds(data=dy)

0 commit comments

Comments
 (0)