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)
| 140 | |
| 141 | |
| 142 | def _trim(x, axes, boundary, _overlap_trim_info): |
| 143 | """Similar to dask.array.chunk.trim but requires one to specify the |
| 144 | boundary condition. |
| 145 | |
| 146 | ``axes``, and ``boundary`` are assumed to have been coerced. |
| 147 | |
| 148 | """ |
| 149 | chunk_location = _overlap_trim_info[0] |
| 150 | num_chunks = _overlap_trim_info[1] |
| 151 | axes = [axes.get(i, 0) for i in range(x.ndim)] |
| 152 | axes_front = (ax[0] if isinstance(ax, tuple) else ax for ax in axes) |
| 153 | axes_back = ( |
| 154 | ( |
| 155 | -ax[1] |
| 156 | if isinstance(ax, tuple) and ax[1] |
| 157 | else -ax if isinstance(ax, Integral) and ax else None |
| 158 | ) |
| 159 | for ax in axes |
| 160 | ) |
| 161 | |
| 162 | trim_front = ( |
| 163 | 0 if (chunk_location == 0 and boundary.get(i, "none") == "none") else ax |
| 164 | for i, (chunk_location, ax) in enumerate(zip(chunk_location, axes_front)) |
| 165 | ) |
| 166 | trim_back = ( |
| 167 | ( |
| 168 | None |
| 169 | if (chunk_location == chunks - 1 and boundary.get(i, "none") == "none") |
| 170 | else ax |
| 171 | ) |
| 172 | for i, (chunks, chunk_location, ax) in enumerate( |
| 173 | zip(num_chunks, chunk_location, axes_back) |
| 174 | ) |
| 175 | ) |
| 176 | ind = tuple(slice(front, back) for front, back in zip(trim_front, trim_back)) |
| 177 | return x[ind] |
| 178 | |
| 179 | |
| 180 | def periodic(x, axis, depth): |