(self: Field, resolution: Shape, bounds: Box, threshold=1e-5, max_padding=20)
| 339 | |
| 340 | |
| 341 | def _shift_resample(self: Field, resolution: Shape, bounds: Box, threshold=1e-5, max_padding=20): |
| 342 | assert math.all_available(bounds.lower, bounds.upper), "Shift resampling requires 'bounds' to be available." |
| 343 | lower = math.to_int32(math.ceil(math.maximum(0, self.bounds.lower - bounds.lower) / self.dx - threshold)) |
| 344 | upper = math.to_int32(math.ceil(math.maximum(0, bounds.upper - self.bounds.upper) / self.dx - threshold)) |
| 345 | if math.close(*math.unstack(lower, batch)) and math.close(*math.unstack(upper, batch)): # incompatible resolutions |
| 346 | lower = math.unstack(lower, batch)[0] |
| 347 | upper = math.unstack(upper, batch)[0] |
| 348 | else: |
| 349 | return NotImplemented |
| 350 | total_padding = int(math.sum(lower) + math.sum(upper)) |
| 351 | if total_padding > max_padding and self.extrapolation.native_grid_sample_mode: |
| 352 | return NotImplemented |
| 353 | elif total_padding > 0: |
| 354 | from phi.field import pad |
| 355 | padded = pad(self, {dim: (int(lower[i]), int(upper[i])) for i, dim in enumerate(self.shape.spatial.names)}) |
| 356 | grid_box, grid_resolution, grid_values = padded.bounds, padded.resolution, padded.values |
| 357 | else: |
| 358 | grid_box, grid_resolution, grid_values = self.bounds, self.resolution, self.values |
| 359 | origin_in_local = grid_box.global_to_local(bounds.lower) * grid_resolution |
| 360 | if batch(origin_in_local): |
| 361 | math.assert_close(*math.unstack(origin_in_local, batch), msg=f"sample_subgrid requires equal start but got varying values along batch dim {batch(origin_in_local)}") |
| 362 | origin_in_local = math.unstack(origin_in_local, batch)[0] |
| 363 | data = math.sample_subgrid(grid_values, origin_in_local, resolution) |
| 364 | return data |
| 365 | |
| 366 | |
| 367 | def centroid_to_faces(u: Field, boundary: Extrapolation, order=2, upwind: Field = None, ignore_skew=False, gradient: Field = None): |
no test coverage detected