Skip to content

Commit

Permalink
fix and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinaHutter committed Sep 16, 2024
1 parent b88bd4a commit de7efe7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def trim_cube(data) -> RasterCube:
other_dims = [d for d in data.dims if d != dim]
available_data = values[(np.isnan(data)).all(dim=other_dims) == 0]
if len(available_data) == 0:
raise ValueError(f"No data was found for spatiotemporal extent! ")
raise ValueError(f"Data contains NaN values only. ")
data = data.sel({dim: available_data})

return data
Expand Down
6 changes: 5 additions & 1 deletion tests/test_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,8 @@ def test_trim_cube(temporal_interval, bounding_box, random_raster_data):
)
input_cube[:, :, :, 2] = np.zeros((30, 30, 20)) * np.nan
output_cube = trim_cube(input_cube)
assert (output_cube.shape == (30, 30, 20, 3)).all()
assert (output_cube.shape == (30, 30, 20, 3))

all_nan = input_cube * np.nan
with pytest.raises(ValueError):
output_cube = trim_cube(all_nan)

0 comments on commit de7efe7

Please sign in to comment.