Similar to dask.array.chunk.trim but requires one to specify the boundary condition. ``axes``, and ``boundary`` are assumed to have been coerced.
(x, axes, boundary, _overlap_trim_info)
| 154 | |
| 155 | |
| 156 | def _trim(x, axes, boundary, _overlap_trim_info): |
| 157 | """Similar to dask.array.chunk.trim but requires one to specify the |
| 158 | boundary condition. |
| 159 | |
| 160 | ``axes``, and ``boundary`` are assumed to have been coerced. |
| 161 | |
| 162 | """ |
| 163 | chunk_location = _overlap_trim_info[0] |
| 164 | num_chunks = _overlap_trim_info[1] |
| 165 | axes = [axes.get(i, 0) for i in range(x.ndim)] |
| 166 | axes_front = (ax[0] if isinstance(ax, tuple) else ax for ax in axes) |
| 167 | axes_back = ( |
| 168 | ( |
| 169 | -ax[1] |
| 170 | if isinstance(ax, tuple) and ax[1] |
| 171 | else -ax if isinstance(ax, Integral) and ax else None |
| 172 | ) |
| 173 | for ax in axes |
| 174 | ) |
| 175 | |
| 176 | trim_front = ( |
| 177 | 0 if (chunk_location == 0 and boundary.get(i, "none") == "none") else ax |
| 178 | for i, (chunk_location, ax) in enumerate(zip(chunk_location, axes_front)) |
| 179 | ) |
| 180 | trim_back = ( |
| 181 | ( |
| 182 | None |
| 183 | if (chunk_location == chunks - 1 and boundary.get(i, "none") == "none") |
| 184 | else ax |
| 185 | ) |
| 186 | for i, (chunks, chunk_location, ax) in enumerate( |
| 187 | zip(num_chunks, chunk_location, axes_back) |
| 188 | ) |
| 189 | ) |
| 190 | ind = tuple(slice(front, back) for front, back in zip(trim_front, trim_back)) |
| 191 | return x[ind] |
| 192 | |
| 193 | |
| 194 | def periodic(x, axis, depth): |