Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore axis if dim is given #149

Merged
merged 1 commit into from
May 16, 2022
Merged
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
6 changes: 4 additions & 2 deletions stackstac/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ def mosaic(
dim:
The dimension name to mosaic. Default: None.
axis:
The axis number to mosaic. Default: 0. Only one of
``dim`` and ``axis`` can be given.
The axis number to mosaic. Default: 0. If ``dim`` is given, ``axis``
is ignored.
reverse:
If False (default), the last item along the dimension is on top.
If True, the first item in the dimension is on top.
Expand Down Expand Up @@ -207,6 +207,8 @@ def mosaic(
f"since {nodata} cannot exist in that dtype. "
)

axis = None if dim is not None else axis

func = (
partial(_mosaic_dask, split_every=split_every)
if isinstance(arr.data, da.Array)
Expand Down
10 changes: 8 additions & 2 deletions stackstac/tests/test_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ def test_mosaic_dtype_error(dtype: np.dtype):
st_stc.raster_dtypes,
st_np.array_shapes(max_dims=4, max_side=5),
st.booleans(),
st.booleans(),
)
def test_fuzz_mosaic(
data: st.DataObject, dtype: np.dtype, shape: Tuple[int, ...], reverse: bool
data: st.DataObject, dtype: np.dtype, shape: Tuple[int, ...], reverse: bool, use_dim: bool,
):
"""
See if we can break mosaic.
Expand All @@ -73,8 +74,13 @@ def test_fuzz_mosaic(
split_every = data.draw(st.integers(1, darr.numblocks[axis]), label="split_every")
xarr = xr.DataArray(darr)

if use_dim:
kwargs = dict(dim=xarr.dims[axis])
else:
kwargs = dict(axis=axis)

result = mosaic(
xarr, axis=axis, reverse=reverse, nodata=fill_value, split_every=split_every
xarr, reverse=reverse, nodata=fill_value, split_every=split_every, **kwargs
)
assert result.dtype == arr.dtype
result_np = mosaic(xr.DataArray(arr), axis=axis, reverse=reverse, nodata=fill_value)
Expand Down