Skip to content
Draft
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
40 changes: 15 additions & 25 deletions uxarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def to_geodataframe(
f"for face-centered data."
)

if self.values.size == self.uxgrid.n_face:
if self._face_centered():
gdf, non_nan_polygon_indices = self.uxgrid.to_geodataframe(
periodic_elements=periodic_elements,
projection=projection,
Expand Down Expand Up @@ -290,22 +290,11 @@ def to_geodataframe(

gdf[var_name] = _data

elif self.values.size == self.uxgrid.n_node:
raise ValueError(
f"Data Variable with size {self.values.size} does not match the number of faces "
f"({self.uxgrid.n_face}. Current size matches the number of nodes. Consider running "
f"``UxDataArray.topological_mean(destination='face') to aggregate the data onto the faces."
)
elif self.values.size == self.uxgrid.n_edge:
raise ValueError(
f"Data Variable with size {self.values.size} does not match the number of faces "
f"({self.uxgrid.n_face}. Current size matches the number of edges."
)
else:
# data is not mapped to
raise ValueError(
f"Data Variable with size {self.values.size} does not match the number of faces "
f"({self.uxgrid.n_face}."
f"to_geodataframe() expects face_centered data; got {self.data_location} data "
f"(with sizes={dict(**self.sizes)}). Consider running "
"``UxDataArray.topological_mean(destination='face')`` to aggregate the data onto faces."
)

return gdf
Expand Down Expand Up @@ -612,24 +601,25 @@ def integrate(
>>> uxds = ux.open_dataset("grid.ug", "centroid_pressure_data_ug")
>>> integral = uxds["psi"].integrate()
"""
if self.values.shape[-1] == self.uxgrid.n_face:
# TODO: support integration regardless of n_face dimension position,
# and remove the self.dims[-1] == "n_face" check.
# (uxarray/xarray features should be agnostic to dimension positions.)
if self._face_centered() and self.dims[-1] == "n_face":
face_areas = self.uxgrid.face_areas.values

# perform dot product between face areas and last dimension of data
integral = np.einsum("i,...i", face_areas, self.values)

elif self.values.shape[-1] == self.uxgrid.n_node:
raise ValueError("Integrating data mapped to each node not yet supported.")

elif self.values.shape[-1] == self.uxgrid.n_edge:
raise ValueError("Integrating data mapped to each edge not yet supported.")
elif not self._face_centered():
raise ValueError(
"Integration of non-face_centered data is not yet supported. "
f"(Got {self.data_location} data with sizes={dict(**self.sizes)})"
)

else:
raise ValueError(
f"The final dimension of the data variable does not match the number of nodes, edges, "
f"or faces. Expected one of "
f"{self.uxgrid.n_node}, {self.uxgrid.n_edge}, or {self.uxgrid.n_face}, "
f"but received {self.values.shape[-1]}"
"Integration of data with n_face not as the final dimension is not yet supported."
f"Got face_centered data, but the final dimension was {self.dims[-1]}, not 'n_face'."
)

# construct a uxda with integrated quantity
Expand Down