Skip to content
Draft
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
33 changes: 14 additions & 19 deletions uxarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@ def to_geodataframe(
same name as the ``UxDataArray`` (or named ``var`` if no name exists)
"""

if self.values.ndim > 1:
if self.ndim > 1:
# data is multidimensional, must be a 1D slice
raise ValueError(
f"Data Variable must be 1-dimensional, with shape {self.uxgrid.n_face} "
f"for face-centered data."
)

if self.values.size == self.uxgrid.n_face:
if self.size == self.uxgrid.n_face:
gdf, non_nan_polygon_indices = self.uxgrid.to_geodataframe(
periodic_elements=periodic_elements,
projection=projection,
Expand Down Expand Up @@ -289,21 +289,21 @@ def to_geodataframe(

gdf[var_name] = _data

elif self.values.size == self.uxgrid.n_node:
elif self.size == self.uxgrid.n_node:
raise ValueError(
f"Data Variable with size {self.values.size} does not match the number of faces "
f"Data Variable with size {self.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:
elif self.size == self.uxgrid.n_edge:
raise ValueError(
f"Data Variable with size {self.values.size} does not match the number of faces "
f"Data Variable with size {self.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"Data Variable with size {self.size} does not match the number of faces "
f"({self.uxgrid.n_face}."
)

Expand Down Expand Up @@ -339,7 +339,7 @@ def to_polycollection(
Flag to indicate whether to override a cached PolyCollection, if it exists
"""
# data is multidimensional, must be a 1D slice
if self.values.ndim > 1:
if self.ndim > 1:
raise ValueError(
f"Data Variable must be 1-dimensional, with shape {self.uxgrid.n_face} "
f"for face-centered data."
Expand Down Expand Up @@ -609,24 +609,22 @@ 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:
face_areas = self.uxgrid.face_areas.values

if self.shape[-1] == self.uxgrid.n_face:
# perform dot product between face areas and last dimension of data
integral = np.einsum("i,...i", face_areas, self.values)
integral = xr.dot(self, self.uxgrid.face_areas, dim="n_face")

elif self.values.shape[-1] == self.uxgrid.n_node:
elif self.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:
elif self.shape[-1] == self.uxgrid.n_edge:
raise ValueError("Integrating data mapped to each edge not yet supported.")

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]}"
f"but received {self.shape[-1]}"
)

# construct a uxda with integrated quantity
Expand Down Expand Up @@ -2177,11 +2175,8 @@ def get_dual(self):
# Get correct dimensions for the dual
dims = [dim_map.get(dim, dim) for dim in self.dims]

# Get the values from the data array
data = np.array(self.values)

# Construct the new data array
uxda = uxarray.UxDataArray(uxgrid=dual, data=data, dims=dims, name=self.name)
uxda = uxarray.UxDataArray(uxgrid=dual, data=self.data, dims=dims, name=self.name)

return uxda

Expand Down
5 changes: 1 addition & 4 deletions uxarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,8 @@ def get_dual(self):
# Get correct dimensions for the dual
dims = [dim_map.get(dim, dim) for dim in self[var].dims]

# Get the values from the data array
data = np.array(self[var].values)

# Construct the new data array
uxda = uxarray.UxDataArray(uxgrid=dual, data=data, dims=dims, name=var)
uxda = uxarray.UxDataArray(uxgrid=dual, data=self[var].data, dims=dims, name=var)

# Add data array to dataset
dataset[var] = uxda
Expand Down
Loading