Skip to content

Commit 5e7f526

Browse files
authored
Add pixels_only parameter to UxDataset.from_healpix() (#1235)
1 parent 8fe4143 commit 5e7f526

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

test/test_healpix.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def test_dataset():
4242
assert uxds.uxgrid.source_grid_spec == "HEALPix"
4343
assert "n_face" in uxds.dims
4444

45+
uxds = ux.UxDataset.from_healpix(ds_path, pixels_only=False)
46+
assert "face_node_connectivity" in uxds.uxgrid._ds
47+
4548

4649

4750
def test_number_of_boundary_nodes():

uxarray/core/dataset.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ def from_xarray(cls, ds: xr.Dataset, uxgrid: Grid = None, ugrid_dims: dict = Non
282282
return cls(ds, uxgrid=uxgrid)
283283

284284
@classmethod
285-
def from_healpix(cls, ds: Union[str, os.PathLike, xr.Dataset], **kwargs):
285+
def from_healpix(
286+
cls, ds: Union[str, os.PathLike, xr.Dataset], pixels_only: bool = True, **kwargs
287+
):
286288
"""
287289
Loads a dataset represented in the HEALPix format into a ``ux.UxDataSet``, paired
288290
with a ``Grid`` containing information about the HEALPix definition.
@@ -291,6 +293,8 @@ def from_healpix(cls, ds: Union[str, os.PathLike, xr.Dataset], **kwargs):
291293
----------
292294
ds: str, os.PathLike, xr.Dataset
293295
Reference to a HEALPix Dataset
296+
pixels_only : bool
297+
Whether to only compute pixels (`face_lon`, `face_lat`) or to also construct boundaries (`face_node_connectivity`, `node_lon`, `node_lat`)
294298
295299
Returns
296300
-------
@@ -308,7 +312,7 @@ def from_healpix(cls, ds: Union[str, os.PathLike, xr.Dataset], **kwargs):
308312
zoom = np.emath.logn(4, (ds.sizes["cell"] / 12)).astype(int)
309313

310314
# Attach a HEALPix Grid
311-
uxgrid = Grid.from_healpix(zoom)
315+
uxgrid = Grid.from_healpix(zoom, pixels_only=pixels_only, **kwargs)
312316

313317
return cls.from_xarray(ds, uxgrid, {"cell": "n_face"})
314318

0 commit comments

Comments
 (0)