Skip to content
Snippets Groups Projects
Commit a724e7b3 authored by Martin Lange's avatar Martin Lange
Browse files

check axes equality in structured grids instead of points, check for arg type in has_time_axis

parent 63fbd79a
No related branches found
No related tags found
1 merge request!237Optimize units etc.
......@@ -585,7 +585,6 @@ class Grid(GridBase):
if isinstance(self, StructuredGrid) != isinstance(other, StructuredGrid):
return False
# Might comparison of data_points be sufficient here?
return (
self.dim == other.dim
and self.crs == other.crs
......@@ -765,6 +764,22 @@ class StructuredGrid(Grid):
np.maximum(dims - 1, 1) if self.data_location == Location.CELLS else dims
)
def __eq__(self, other):
if not isinstance(other, Grid):
return False
if not isinstance(other, StructuredGrid):
return False
return (
self.dim == other.dim
and self.crs == other.crs
and self.order == other.order
and self.data_location == other.data_location
and self.data_shape == other.data_shape
and all(np.allclose(a, b) for a, b in zip(self.axes, other.axes))
)
def export_vtk(
self,
path,
......
......@@ -146,7 +146,17 @@ def has_time_axis(xdata, grid):
bool
Whether the data has a time axis.
"""
grid_dim = len(grid.data_shape) if isinstance(grid, Grid) else grid.dim
grid_dim = None
if isinstance(grid, Grid):
grid_dim = len(grid.data_shape)
elif isinstance(grid, grid_spec.NoGrid):
grid_dim = grid.dim
else:
raise ValueError(
f"Expected type Grid or NoGrid, got {grid.__class__.__name__}."
)
if xdata.ndim == grid_dim:
return False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment