Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ Grid Accessor

UxDataArray.uxgrid
UxDataArray.data_mapping
UxDataArray.data_location


UxDataset
Expand Down
19 changes: 11 additions & 8 deletions test/core/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ def test_isel_invalid_dim(gridpath, datasetpath):
uxda.isel(level=0)


def test_data_location():
"""Tests data_location for face/node/edge centered data and non-grid data."""
def test_data_mapping():
"""Tests data_mapping for face/node/edge mapped data and non-grid data."""
uxgrid = ux.Grid.from_healpix(zoom=1)

face_da = UxDataArray(
Expand All @@ -155,16 +155,19 @@ def test_data_location():
np.ones(5), dims=["other_dim"], uxgrid=uxgrid
)

assert face_da.data_location == "face_centered"
assert node_da.data_location == "node_centered"
assert edge_da.data_location == "edge_centered"
assert other_da.data_location is None
assert face_da.data_mapping == "faces"
assert node_da.data_mapping == "nodes"
assert edge_da.data_mapping == "edges"
assert other_da.data_mapping is None

# Works when an extra (non-grid) dimension is present
face_time = UxDataArray(
np.ones((3, uxgrid.n_face)), dims=["time", "n_face"], uxgrid=uxgrid
)
assert face_time.data_location == "face_centered"
assert face_time.data_mapping == "faces"

# data_location was folded into data_mapping
assert not hasattr(face_da, "data_location")


class TestNeighborhood:
Expand Down Expand Up @@ -243,7 +246,7 @@ def test_extra_dimension_preserved(self, vortex):
assert filtered.shape == uxda_time.shape
np.testing.assert_allclose(filtered.values, data)

def test_invalid_data_location(self):
def test_invalid_data_mapping(self):
"""Data that is not mapped to a grid element should raise an error."""
uxgrid = ux.Grid.from_healpix(zoom=1)
uxda = UxDataArray(np.ones(5), dims=["other_dim"], uxgrid=uxgrid)
Expand Down
41 changes: 14 additions & 27 deletions uxarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,26 +183,14 @@ def uxgrid(self, ugrid_obj: Grid):

@property
def data_mapping(self):
"""Returns which unstructured grid a data variable is mapped to."""
if self._face_centered():
return "faces"
elif self._edge_centered():
return "edges"
elif self._node_centered():
return "nodes"
else:
return None
"""Returns which grid element a data variable is mapped to.

@property
def data_location(self):
"""Returns where on the grid the data variable is stored.

The location is inferred from the grid dimension present in the data
variable, using UGRID-style names:
The mapping is inferred from the grid dimension present in the data
variable:

- ``"face_centered"`` if the data contains the ``n_face`` dimension
- ``"node_centered"`` if the data contains the ``n_node`` dimension
- ``"edge_centered"`` if the data contains the ``n_edge`` dimension
- ``"faces"`` if the data contains the ``n_face`` dimension
- ``"edges"`` if the data contains the ``n_edge`` dimension
- ``"nodes"`` if the data contains the ``n_node`` dimension
- ``None`` if the data is not mapped to the grid

Notes
Expand All @@ -215,15 +203,14 @@ def data_location(self):
Returns
-------
str or None
One of ``"face_centered"``, ``"node_centered"``,
``"edge_centered"``, or ``None``.
One of ``"faces"``, ``"edges"``, ``"nodes"``, or ``None``.
"""
if self._face_centered():
return "face_centered"
elif self._node_centered():
return "node_centered"
return "faces"
elif self._edge_centered():
return "edge_centered"
return "edges"
elif self._node_centered():
return "nodes"
else:
return None

Expand Down Expand Up @@ -320,7 +307,7 @@ def to_geodataframe(

else:
raise DataCenteringError(
f"to_geodataframe() expects face_centered data; got {self.data_location} data "
f"to_geodataframe() expects data mapped to faces; got data_mapping={self.data_mapping!r} "
f"(with sizes={dict(**self.sizes)}). Consider running "
"``UxDataArray.topological_mean(destination='face')`` to aggregate the data onto faces."
)
Expand Down Expand Up @@ -645,8 +632,8 @@ def integrate(

elif not self._face_centered():
raise DataCenteringError(
"Integration of non-face_centered data is not yet supported. "
f"(Got {self.data_location} data with sizes={dict(**self.sizes)})"
"Integration of data not mapped to faces is not yet supported. "
f"(Got data_mapping={self.data_mapping!r} with sizes={dict(**self.sizes)})"
)

else:
Expand Down
Loading